1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5 Largely rewritten by Alan Modra.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_vma opd_entry_value
57 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bfd_boolean
);
59 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM powerpc_elf64_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_TARGET_ID PPC64_ELF_DATA
65 #define ELF_MACHINE_CODE EM_PPC64
66 #define ELF_MAXPAGESIZE 0x10000
67 #define ELF_COMMONPAGESIZE 0x10000
68 #define elf_info_to_howto ppc64_elf_info_to_howto
70 #define elf_backend_want_got_sym 0
71 #define elf_backend_want_plt_sym 0
72 #define elf_backend_plt_alignment 3
73 #define elf_backend_plt_not_loaded 1
74 #define elf_backend_got_header_size 8
75 #define elf_backend_want_dynrelro 1
76 #define elf_backend_can_gc_sections 1
77 #define elf_backend_can_refcount 1
78 #define elf_backend_rela_normal 1
79 #define elf_backend_dtrel_excludes_plt 1
80 #define elf_backend_default_execstack 0
82 #define bfd_elf64_mkobject ppc64_elf_mkobject
83 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
84 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
85 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
86 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
87 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
88 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
89 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
90 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
91 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
93 #define elf_backend_object_p ppc64_elf_object_p
94 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
95 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
96 #define elf_backend_write_core_note ppc64_elf_write_core_note
97 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
98 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
99 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
100 #define elf_backend_check_directives ppc64_elf_before_check_relocs
101 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
102 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
103 #define elf_backend_check_relocs ppc64_elf_check_relocs
104 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
105 #define elf_backend_gc_keep ppc64_elf_gc_keep
106 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
107 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
108 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
109 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
110 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
111 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
112 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
113 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
114 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
115 #define elf_backend_action_discarded ppc64_elf_action_discarded
116 #define elf_backend_relocate_section ppc64_elf_relocate_section
117 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
118 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
119 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
120 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
121 #define elf_backend_special_sections ppc64_elf_special_sections
122 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
123 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
124 #define elf_backend_get_reloc_section bfd_get_section_by_name
126 /* The name of the dynamic interpreter. This is put in the .interp
128 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
130 /* The size in bytes of an entry in the procedure linkage table. */
131 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
133 /* The initial size of the plt reserved for the dynamic linker. */
134 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
136 /* Offsets to some stack save slots. */
138 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
139 /* This one is dodgy. ELFv2 does not have a linker word, so use the
140 CR save slot. Used only by optimised __tls_get_addr call stub,
141 relying on __tls_get_addr_opt not saving CR.. */
142 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
144 /* TOC base pointers offset from start of TOC. */
145 #define TOC_BASE_OFF 0x8000
146 /* TOC base alignment. */
147 #define TOC_BASE_ALIGN 256
149 /* Offset of tp and dtp pointers from start of TLS block. */
150 #define TP_OFFSET 0x7000
151 #define DTP_OFFSET 0x8000
153 /* .plt call stub instructions. The normal stub is like this, but
154 sometimes the .plt entry crosses a 64k boundary and we need to
155 insert an addi to adjust r11. */
156 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
157 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
158 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
159 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
160 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
161 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
162 #define BCTR 0x4e800420 /* bctr */
164 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
165 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
166 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
168 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
169 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
170 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
171 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
172 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
173 #define BNECTR 0x4ca20420 /* bnectr+ */
174 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
176 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
177 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
178 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
180 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
181 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
182 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
184 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
185 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
186 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
187 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
188 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
190 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
191 #define GLINK_PLTRESOLVE_SIZE(htab) \
192 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
196 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
197 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
199 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
200 /* ld %2,(0b-1b)(%11) */
201 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
202 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
208 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
209 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
210 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
211 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
212 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
215 #define NOP 0x60000000
217 /* Some other nops. */
218 #define CROR_151515 0x4def7b82
219 #define CROR_313131 0x4ffffb82
221 /* .glink entries for the first 32k functions are two instructions. */
222 #define LI_R0_0 0x38000000 /* li %r0,0 */
223 #define B_DOT 0x48000000 /* b . */
225 /* After that, we need two instructions to load the index, followed by
227 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
228 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
230 /* Instructions used by the save and restore reg functions. */
231 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
232 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
233 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
234 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
235 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
236 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
237 #define LI_R12_0 0x39800000 /* li %r12,0 */
238 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
239 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
240 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
241 #define BLR 0x4e800020 /* blr */
243 /* Since .opd is an array of descriptors and each entry will end up
244 with identical R_PPC64_RELATIVE relocs, there is really no need to
245 propagate .opd relocs; The dynamic linker should be taught to
246 relocate .opd without reloc entries. */
247 #ifndef NO_OPD_RELOCS
248 #define NO_OPD_RELOCS 0
252 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
256 abiversion (bfd
*abfd
)
258 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
262 set_abiversion (bfd
*abfd
, int ver
)
264 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
265 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
268 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
270 /* Relocation HOWTO's. */
271 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
273 static reloc_howto_type ppc64_elf_howto_raw
[] =
275 /* This reloc does nothing. */
276 HOWTO (R_PPC64_NONE
, /* type */
278 3, /* size (0 = byte, 1 = short, 2 = long) */
280 FALSE
, /* pc_relative */
282 complain_overflow_dont
, /* complain_on_overflow */
283 bfd_elf_generic_reloc
, /* special_function */
284 "R_PPC64_NONE", /* name */
285 FALSE
, /* partial_inplace */
288 FALSE
), /* pcrel_offset */
290 /* A standard 32 bit relocation. */
291 HOWTO (R_PPC64_ADDR32
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 FALSE
, /* pc_relative */
297 complain_overflow_bitfield
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_PPC64_ADDR32", /* name */
300 FALSE
, /* partial_inplace */
302 0xffffffff, /* dst_mask */
303 FALSE
), /* pcrel_offset */
305 /* An absolute 26 bit branch; the lower two bits must be zero.
306 FIXME: we don't check that, we just clear them. */
307 HOWTO (R_PPC64_ADDR24
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 FALSE
, /* pc_relative */
313 complain_overflow_bitfield
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_PPC64_ADDR24", /* name */
316 FALSE
, /* partial_inplace */
318 0x03fffffc, /* dst_mask */
319 FALSE
), /* pcrel_offset */
321 /* A standard 16 bit relocation. */
322 HOWTO (R_PPC64_ADDR16
, /* type */
324 1, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE
, /* pc_relative */
328 complain_overflow_bitfield
, /* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_PPC64_ADDR16", /* name */
331 FALSE
, /* partial_inplace */
333 0xffff, /* dst_mask */
334 FALSE
), /* pcrel_offset */
336 /* A 16 bit relocation without overflow. */
337 HOWTO (R_PPC64_ADDR16_LO
, /* type */
339 1, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE
, /* pc_relative */
343 complain_overflow_dont
,/* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_PPC64_ADDR16_LO", /* name */
346 FALSE
, /* partial_inplace */
348 0xffff, /* dst_mask */
349 FALSE
), /* pcrel_offset */
351 /* Bits 16-31 of an address. */
352 HOWTO (R_PPC64_ADDR16_HI
, /* type */
354 1, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE
, /* pc_relative */
358 complain_overflow_signed
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_PPC64_ADDR16_HI", /* name */
361 FALSE
, /* partial_inplace */
363 0xffff, /* dst_mask */
364 FALSE
), /* pcrel_offset */
366 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
367 bits, treated as a signed number, is negative. */
368 HOWTO (R_PPC64_ADDR16_HA
, /* type */
370 1, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE
, /* pc_relative */
374 complain_overflow_signed
, /* complain_on_overflow */
375 ppc64_elf_ha_reloc
, /* special_function */
376 "R_PPC64_ADDR16_HA", /* name */
377 FALSE
, /* partial_inplace */
379 0xffff, /* dst_mask */
380 FALSE
), /* pcrel_offset */
382 /* An absolute 16 bit branch; the lower two bits must be zero.
383 FIXME: we don't check that, we just clear them. */
384 HOWTO (R_PPC64_ADDR14
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 FALSE
, /* pc_relative */
390 complain_overflow_signed
, /* complain_on_overflow */
391 ppc64_elf_branch_reloc
, /* special_function */
392 "R_PPC64_ADDR14", /* name */
393 FALSE
, /* partial_inplace */
395 0x0000fffc, /* dst_mask */
396 FALSE
), /* pcrel_offset */
398 /* An absolute 16 bit branch, for which bit 10 should be set to
399 indicate that the branch is expected to be taken. The lower two
400 bits must be zero. */
401 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_signed
, /* complain_on_overflow */
408 ppc64_elf_brtaken_reloc
, /* special_function */
409 "R_PPC64_ADDR14_BRTAKEN",/* name */
410 FALSE
, /* partial_inplace */
412 0x0000fffc, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* An absolute 16 bit branch, for which bit 10 should be set to
416 indicate that the branch is not expected to be taken. The lower
417 two bits must be zero. */
418 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 ppc64_elf_brtaken_reloc
, /* special_function */
426 "R_PPC64_ADDR14_BRNTAKEN",/* name */
427 FALSE
, /* partial_inplace */
429 0x0000fffc, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* A relative 26 bit branch; the lower two bits must be zero. */
433 HOWTO (R_PPC64_REL24
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE
, /* pc_relative */
439 complain_overflow_signed
, /* complain_on_overflow */
440 ppc64_elf_branch_reloc
, /* special_function */
441 "R_PPC64_REL24", /* name */
442 FALSE
, /* partial_inplace */
444 0x03fffffc, /* dst_mask */
445 TRUE
), /* pcrel_offset */
447 /* A relative 16 bit branch; the lower two bits must be zero. */
448 HOWTO (R_PPC64_REL14
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 TRUE
, /* pc_relative */
454 complain_overflow_signed
, /* complain_on_overflow */
455 ppc64_elf_branch_reloc
, /* special_function */
456 "R_PPC64_REL14", /* name */
457 FALSE
, /* partial_inplace */
459 0x0000fffc, /* dst_mask */
460 TRUE
), /* pcrel_offset */
462 /* A relative 16 bit branch. Bit 10 should be set to indicate that
463 the branch is expected to be taken. The lower two bits must be
465 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_signed
, /* complain_on_overflow */
472 ppc64_elf_brtaken_reloc
, /* special_function */
473 "R_PPC64_REL14_BRTAKEN", /* name */
474 FALSE
, /* partial_inplace */
476 0x0000fffc, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 /* A relative 16 bit branch. Bit 10 should be set to indicate that
480 the branch is not expected to be taken. The lower two bits must
482 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 TRUE
, /* pc_relative */
488 complain_overflow_signed
, /* complain_on_overflow */
489 ppc64_elf_brtaken_reloc
, /* special_function */
490 "R_PPC64_REL14_BRNTAKEN",/* name */
491 FALSE
, /* partial_inplace */
493 0x0000fffc, /* dst_mask */
494 TRUE
), /* pcrel_offset */
496 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
498 HOWTO (R_PPC64_GOT16
, /* type */
500 1, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_signed
, /* complain_on_overflow */
505 ppc64_elf_unhandled_reloc
, /* special_function */
506 "R_PPC64_GOT16", /* name */
507 FALSE
, /* partial_inplace */
509 0xffff, /* dst_mask */
510 FALSE
), /* pcrel_offset */
512 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
514 HOWTO (R_PPC64_GOT16_LO
, /* type */
516 1, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE
, /* pc_relative */
520 complain_overflow_dont
, /* complain_on_overflow */
521 ppc64_elf_unhandled_reloc
, /* special_function */
522 "R_PPC64_GOT16_LO", /* name */
523 FALSE
, /* partial_inplace */
525 0xffff, /* dst_mask */
526 FALSE
), /* pcrel_offset */
528 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
530 HOWTO (R_PPC64_GOT16_HI
, /* type */
532 1, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE
, /* pc_relative */
536 complain_overflow_signed
,/* complain_on_overflow */
537 ppc64_elf_unhandled_reloc
, /* special_function */
538 "R_PPC64_GOT16_HI", /* name */
539 FALSE
, /* partial_inplace */
541 0xffff, /* dst_mask */
542 FALSE
), /* pcrel_offset */
544 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
546 HOWTO (R_PPC64_GOT16_HA
, /* type */
548 1, /* size (0 = byte, 1 = short, 2 = long) */
550 FALSE
, /* pc_relative */
552 complain_overflow_signed
,/* complain_on_overflow */
553 ppc64_elf_unhandled_reloc
, /* special_function */
554 "R_PPC64_GOT16_HA", /* name */
555 FALSE
, /* partial_inplace */
557 0xffff, /* dst_mask */
558 FALSE
), /* pcrel_offset */
560 /* This is used only by the dynamic linker. The symbol should exist
561 both in the object being run and in some shared library. The
562 dynamic linker copies the data addressed by the symbol from the
563 shared library into the object, because the object being
564 run has to have the data at some particular address. */
565 HOWTO (R_PPC64_COPY
, /* type */
567 0, /* this one is variable size */
569 FALSE
, /* pc_relative */
571 complain_overflow_dont
, /* complain_on_overflow */
572 ppc64_elf_unhandled_reloc
, /* special_function */
573 "R_PPC64_COPY", /* name */
574 FALSE
, /* partial_inplace */
577 FALSE
), /* pcrel_offset */
579 /* Like R_PPC64_ADDR64, but used when setting global offset table
581 HOWTO (R_PPC64_GLOB_DAT
, /* type */
583 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
585 FALSE
, /* pc_relative */
587 complain_overflow_dont
, /* complain_on_overflow */
588 ppc64_elf_unhandled_reloc
, /* special_function */
589 "R_PPC64_GLOB_DAT", /* name */
590 FALSE
, /* partial_inplace */
592 ONES (64), /* dst_mask */
593 FALSE
), /* pcrel_offset */
595 /* Created by the link editor. Marks a procedure linkage table
596 entry for a symbol. */
597 HOWTO (R_PPC64_JMP_SLOT
, /* type */
599 0, /* size (0 = byte, 1 = short, 2 = long) */
601 FALSE
, /* pc_relative */
603 complain_overflow_dont
, /* complain_on_overflow */
604 ppc64_elf_unhandled_reloc
, /* special_function */
605 "R_PPC64_JMP_SLOT", /* name */
606 FALSE
, /* partial_inplace */
609 FALSE
), /* pcrel_offset */
611 /* Used only by the dynamic linker. When the object is run, this
612 doubleword64 is set to the load address of the object, plus the
614 HOWTO (R_PPC64_RELATIVE
, /* type */
616 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
618 FALSE
, /* pc_relative */
620 complain_overflow_dont
, /* complain_on_overflow */
621 bfd_elf_generic_reloc
, /* special_function */
622 "R_PPC64_RELATIVE", /* name */
623 FALSE
, /* partial_inplace */
625 ONES (64), /* dst_mask */
626 FALSE
), /* pcrel_offset */
628 /* Like R_PPC64_ADDR32, but may be unaligned. */
629 HOWTO (R_PPC64_UADDR32
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 FALSE
, /* pc_relative */
635 complain_overflow_bitfield
, /* complain_on_overflow */
636 bfd_elf_generic_reloc
, /* special_function */
637 "R_PPC64_UADDR32", /* name */
638 FALSE
, /* partial_inplace */
640 0xffffffff, /* dst_mask */
641 FALSE
), /* pcrel_offset */
643 /* Like R_PPC64_ADDR16, but may be unaligned. */
644 HOWTO (R_PPC64_UADDR16
, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 FALSE
, /* pc_relative */
650 complain_overflow_bitfield
, /* complain_on_overflow */
651 bfd_elf_generic_reloc
, /* special_function */
652 "R_PPC64_UADDR16", /* name */
653 FALSE
, /* partial_inplace */
655 0xffff, /* dst_mask */
656 FALSE
), /* pcrel_offset */
658 /* 32-bit PC relative. */
659 HOWTO (R_PPC64_REL32
, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 TRUE
, /* pc_relative */
665 complain_overflow_signed
, /* complain_on_overflow */
666 bfd_elf_generic_reloc
, /* special_function */
667 "R_PPC64_REL32", /* name */
668 FALSE
, /* partial_inplace */
670 0xffffffff, /* dst_mask */
671 TRUE
), /* pcrel_offset */
673 /* 32-bit relocation to the symbol's procedure linkage table. */
674 HOWTO (R_PPC64_PLT32
, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 FALSE
, /* pc_relative */
680 complain_overflow_bitfield
, /* complain_on_overflow */
681 ppc64_elf_unhandled_reloc
, /* special_function */
682 "R_PPC64_PLT32", /* name */
683 FALSE
, /* partial_inplace */
685 0xffffffff, /* dst_mask */
686 FALSE
), /* pcrel_offset */
688 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
689 FIXME: R_PPC64_PLTREL32 not supported. */
690 HOWTO (R_PPC64_PLTREL32
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 TRUE
, /* pc_relative */
696 complain_overflow_signed
, /* complain_on_overflow */
697 ppc64_elf_unhandled_reloc
, /* special_function */
698 "R_PPC64_PLTREL32", /* name */
699 FALSE
, /* partial_inplace */
701 0xffffffff, /* dst_mask */
702 TRUE
), /* pcrel_offset */
704 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
706 HOWTO (R_PPC64_PLT16_LO
, /* type */
708 1, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 ppc64_elf_unhandled_reloc
, /* special_function */
714 "R_PPC64_PLT16_LO", /* name */
715 FALSE
, /* partial_inplace */
717 0xffff, /* dst_mask */
718 FALSE
), /* pcrel_offset */
720 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
722 HOWTO (R_PPC64_PLT16_HI
, /* type */
724 1, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE
, /* pc_relative */
728 complain_overflow_signed
, /* complain_on_overflow */
729 ppc64_elf_unhandled_reloc
, /* special_function */
730 "R_PPC64_PLT16_HI", /* name */
731 FALSE
, /* partial_inplace */
733 0xffff, /* dst_mask */
734 FALSE
), /* pcrel_offset */
736 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
738 HOWTO (R_PPC64_PLT16_HA
, /* type */
740 1, /* size (0 = byte, 1 = short, 2 = long) */
742 FALSE
, /* pc_relative */
744 complain_overflow_signed
, /* complain_on_overflow */
745 ppc64_elf_unhandled_reloc
, /* special_function */
746 "R_PPC64_PLT16_HA", /* name */
747 FALSE
, /* partial_inplace */
749 0xffff, /* dst_mask */
750 FALSE
), /* pcrel_offset */
752 /* 16-bit section relative relocation. */
753 HOWTO (R_PPC64_SECTOFF
, /* type */
755 1, /* size (0 = byte, 1 = short, 2 = long) */
757 FALSE
, /* pc_relative */
759 complain_overflow_signed
, /* complain_on_overflow */
760 ppc64_elf_sectoff_reloc
, /* special_function */
761 "R_PPC64_SECTOFF", /* name */
762 FALSE
, /* partial_inplace */
764 0xffff, /* dst_mask */
765 FALSE
), /* pcrel_offset */
767 /* Like R_PPC64_SECTOFF, but no overflow warning. */
768 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
770 1, /* size (0 = byte, 1 = short, 2 = long) */
772 FALSE
, /* pc_relative */
774 complain_overflow_dont
, /* complain_on_overflow */
775 ppc64_elf_sectoff_reloc
, /* special_function */
776 "R_PPC64_SECTOFF_LO", /* name */
777 FALSE
, /* partial_inplace */
779 0xffff, /* dst_mask */
780 FALSE
), /* pcrel_offset */
782 /* 16-bit upper half section relative relocation. */
783 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
785 1, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE
, /* pc_relative */
789 complain_overflow_signed
, /* complain_on_overflow */
790 ppc64_elf_sectoff_reloc
, /* special_function */
791 "R_PPC64_SECTOFF_HI", /* name */
792 FALSE
, /* partial_inplace */
794 0xffff, /* dst_mask */
795 FALSE
), /* pcrel_offset */
797 /* 16-bit upper half adjusted section relative relocation. */
798 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
800 1, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE
, /* pc_relative */
804 complain_overflow_signed
, /* complain_on_overflow */
805 ppc64_elf_sectoff_ha_reloc
, /* special_function */
806 "R_PPC64_SECTOFF_HA", /* name */
807 FALSE
, /* partial_inplace */
809 0xffff, /* dst_mask */
810 FALSE
), /* pcrel_offset */
812 /* Like R_PPC64_REL24 without touching the two least significant bits. */
813 HOWTO (R_PPC64_REL30
, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 TRUE
, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 "R_PPC64_REL30", /* name */
822 FALSE
, /* partial_inplace */
824 0xfffffffc, /* dst_mask */
825 TRUE
), /* pcrel_offset */
827 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
829 /* A standard 64-bit relocation. */
830 HOWTO (R_PPC64_ADDR64
, /* type */
832 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
834 FALSE
, /* pc_relative */
836 complain_overflow_dont
, /* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_PPC64_ADDR64", /* name */
839 FALSE
, /* partial_inplace */
841 ONES (64), /* dst_mask */
842 FALSE
), /* pcrel_offset */
844 /* The bits 32-47 of an address. */
845 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
847 1, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 "R_PPC64_ADDR16_HIGHER", /* name */
854 FALSE
, /* partial_inplace */
856 0xffff, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* The bits 32-47 of an address, plus 1 if the contents of the low
860 16 bits, treated as a signed number, is negative. */
861 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
863 1, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE
, /* pc_relative */
867 complain_overflow_dont
, /* complain_on_overflow */
868 ppc64_elf_ha_reloc
, /* special_function */
869 "R_PPC64_ADDR16_HIGHERA", /* name */
870 FALSE
, /* partial_inplace */
872 0xffff, /* dst_mask */
873 FALSE
), /* pcrel_offset */
875 /* The bits 48-63 of an address. */
876 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
878 1, /* size (0 = byte, 1 = short, 2 = long) */
880 FALSE
, /* pc_relative */
882 complain_overflow_dont
, /* complain_on_overflow */
883 bfd_elf_generic_reloc
, /* special_function */
884 "R_PPC64_ADDR16_HIGHEST", /* name */
885 FALSE
, /* partial_inplace */
887 0xffff, /* dst_mask */
888 FALSE
), /* pcrel_offset */
890 /* The bits 48-63 of an address, plus 1 if the contents of the low
891 16 bits, treated as a signed number, is negative. */
892 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
894 1, /* size (0 = byte, 1 = short, 2 = long) */
896 FALSE
, /* pc_relative */
898 complain_overflow_dont
, /* complain_on_overflow */
899 ppc64_elf_ha_reloc
, /* special_function */
900 "R_PPC64_ADDR16_HIGHESTA", /* name */
901 FALSE
, /* partial_inplace */
903 0xffff, /* dst_mask */
904 FALSE
), /* pcrel_offset */
906 /* Like ADDR64, but may be unaligned. */
907 HOWTO (R_PPC64_UADDR64
, /* type */
909 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
911 FALSE
, /* pc_relative */
913 complain_overflow_dont
, /* complain_on_overflow */
914 bfd_elf_generic_reloc
, /* special_function */
915 "R_PPC64_UADDR64", /* name */
916 FALSE
, /* partial_inplace */
918 ONES (64), /* dst_mask */
919 FALSE
), /* pcrel_offset */
921 /* 64-bit relative relocation. */
922 HOWTO (R_PPC64_REL64
, /* type */
924 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
926 TRUE
, /* pc_relative */
928 complain_overflow_dont
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* special_function */
930 "R_PPC64_REL64", /* name */
931 FALSE
, /* partial_inplace */
933 ONES (64), /* dst_mask */
934 TRUE
), /* pcrel_offset */
936 /* 64-bit relocation to the symbol's procedure linkage table. */
937 HOWTO (R_PPC64_PLT64
, /* type */
939 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
941 FALSE
, /* pc_relative */
943 complain_overflow_dont
, /* complain_on_overflow */
944 ppc64_elf_unhandled_reloc
, /* special_function */
945 "R_PPC64_PLT64", /* name */
946 FALSE
, /* partial_inplace */
948 ONES (64), /* dst_mask */
949 FALSE
), /* pcrel_offset */
951 /* 64-bit PC relative relocation to the symbol's procedure linkage
953 /* FIXME: R_PPC64_PLTREL64 not supported. */
954 HOWTO (R_PPC64_PLTREL64
, /* type */
956 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
958 TRUE
, /* pc_relative */
960 complain_overflow_dont
, /* complain_on_overflow */
961 ppc64_elf_unhandled_reloc
, /* special_function */
962 "R_PPC64_PLTREL64", /* name */
963 FALSE
, /* partial_inplace */
965 ONES (64), /* dst_mask */
966 TRUE
), /* pcrel_offset */
968 /* 16 bit TOC-relative relocation. */
970 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
971 HOWTO (R_PPC64_TOC16
, /* type */
973 1, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_signed
, /* complain_on_overflow */
978 ppc64_elf_toc_reloc
, /* special_function */
979 "R_PPC64_TOC16", /* name */
980 FALSE
, /* partial_inplace */
982 0xffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 /* 16 bit TOC-relative relocation without overflow. */
987 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
988 HOWTO (R_PPC64_TOC16_LO
, /* type */
990 1, /* size (0 = byte, 1 = short, 2 = long) */
992 FALSE
, /* pc_relative */
994 complain_overflow_dont
, /* complain_on_overflow */
995 ppc64_elf_toc_reloc
, /* special_function */
996 "R_PPC64_TOC16_LO", /* name */
997 FALSE
, /* partial_inplace */
999 0xffff, /* dst_mask */
1000 FALSE
), /* pcrel_offset */
1002 /* 16 bit TOC-relative relocation, high 16 bits. */
1004 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1005 HOWTO (R_PPC64_TOC16_HI
, /* type */
1006 16, /* rightshift */
1007 1, /* size (0 = byte, 1 = short, 2 = long) */
1009 FALSE
, /* pc_relative */
1011 complain_overflow_signed
, /* complain_on_overflow */
1012 ppc64_elf_toc_reloc
, /* special_function */
1013 "R_PPC64_TOC16_HI", /* name */
1014 FALSE
, /* partial_inplace */
1016 0xffff, /* dst_mask */
1017 FALSE
), /* pcrel_offset */
1019 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1020 contents of the low 16 bits, treated as a signed number, is
1023 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1024 HOWTO (R_PPC64_TOC16_HA
, /* type */
1025 16, /* rightshift */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE
, /* pc_relative */
1030 complain_overflow_signed
, /* complain_on_overflow */
1031 ppc64_elf_toc_ha_reloc
, /* special_function */
1032 "R_PPC64_TOC16_HA", /* name */
1033 FALSE
, /* partial_inplace */
1035 0xffff, /* dst_mask */
1036 FALSE
), /* pcrel_offset */
1038 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1040 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1041 HOWTO (R_PPC64_TOC
, /* type */
1043 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1045 FALSE
, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 ppc64_elf_toc64_reloc
, /* special_function */
1049 "R_PPC64_TOC", /* name */
1050 FALSE
, /* partial_inplace */
1052 ONES (64), /* dst_mask */
1053 FALSE
), /* pcrel_offset */
1055 /* Like R_PPC64_GOT16, but also informs the link editor that the
1056 value to relocate may (!) refer to a PLT entry which the link
1057 editor (a) may replace with the symbol value. If the link editor
1058 is unable to fully resolve the symbol, it may (b) create a PLT
1059 entry and store the address to the new PLT entry in the GOT.
1060 This permits lazy resolution of function symbols at run time.
1061 The link editor may also skip all of this and just (c) emit a
1062 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1063 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1064 HOWTO (R_PPC64_PLTGOT16
, /* type */
1066 1, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE
, /* pc_relative */
1070 complain_overflow_signed
, /* complain_on_overflow */
1071 ppc64_elf_unhandled_reloc
, /* special_function */
1072 "R_PPC64_PLTGOT16", /* name */
1073 FALSE
, /* partial_inplace */
1075 0xffff, /* dst_mask */
1076 FALSE
), /* pcrel_offset */
1078 /* Like R_PPC64_PLTGOT16, but without overflow. */
1079 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1080 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1082 1, /* size (0 = byte, 1 = short, 2 = long) */
1084 FALSE
, /* pc_relative */
1086 complain_overflow_dont
, /* complain_on_overflow */
1087 ppc64_elf_unhandled_reloc
, /* special_function */
1088 "R_PPC64_PLTGOT16_LO", /* name */
1089 FALSE
, /* partial_inplace */
1091 0xffff, /* dst_mask */
1092 FALSE
), /* pcrel_offset */
1094 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1095 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1096 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1097 16, /* rightshift */
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1100 FALSE
, /* pc_relative */
1102 complain_overflow_signed
, /* complain_on_overflow */
1103 ppc64_elf_unhandled_reloc
, /* special_function */
1104 "R_PPC64_PLTGOT16_HI", /* name */
1105 FALSE
, /* partial_inplace */
1107 0xffff, /* dst_mask */
1108 FALSE
), /* pcrel_offset */
1110 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1111 1 if the contents of the low 16 bits, treated as a signed number,
1113 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1114 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1115 16, /* rightshift */
1116 1, /* size (0 = byte, 1 = short, 2 = long) */
1118 FALSE
, /* pc_relative */
1120 complain_overflow_signed
, /* complain_on_overflow */
1121 ppc64_elf_unhandled_reloc
, /* special_function */
1122 "R_PPC64_PLTGOT16_HA", /* name */
1123 FALSE
, /* partial_inplace */
1125 0xffff, /* dst_mask */
1126 FALSE
), /* pcrel_offset */
1128 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1129 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1131 1, /* size (0 = byte, 1 = short, 2 = long) */
1133 FALSE
, /* pc_relative */
1135 complain_overflow_signed
, /* complain_on_overflow */
1136 bfd_elf_generic_reloc
, /* special_function */
1137 "R_PPC64_ADDR16_DS", /* name */
1138 FALSE
, /* partial_inplace */
1140 0xfffc, /* dst_mask */
1141 FALSE
), /* pcrel_offset */
1143 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1144 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1146 1, /* size (0 = byte, 1 = short, 2 = long) */
1148 FALSE
, /* pc_relative */
1150 complain_overflow_dont
,/* complain_on_overflow */
1151 bfd_elf_generic_reloc
, /* special_function */
1152 "R_PPC64_ADDR16_LO_DS",/* name */
1153 FALSE
, /* partial_inplace */
1155 0xfffc, /* dst_mask */
1156 FALSE
), /* pcrel_offset */
1158 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1159 HOWTO (R_PPC64_GOT16_DS
, /* type */
1161 1, /* size (0 = byte, 1 = short, 2 = long) */
1163 FALSE
, /* pc_relative */
1165 complain_overflow_signed
, /* complain_on_overflow */
1166 ppc64_elf_unhandled_reloc
, /* special_function */
1167 "R_PPC64_GOT16_DS", /* name */
1168 FALSE
, /* partial_inplace */
1170 0xfffc, /* dst_mask */
1171 FALSE
), /* pcrel_offset */
1173 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1174 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1176 1, /* size (0 = byte, 1 = short, 2 = long) */
1178 FALSE
, /* pc_relative */
1180 complain_overflow_dont
, /* complain_on_overflow */
1181 ppc64_elf_unhandled_reloc
, /* special_function */
1182 "R_PPC64_GOT16_LO_DS", /* name */
1183 FALSE
, /* partial_inplace */
1185 0xfffc, /* dst_mask */
1186 FALSE
), /* pcrel_offset */
1188 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1189 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1191 1, /* size (0 = byte, 1 = short, 2 = long) */
1193 FALSE
, /* pc_relative */
1195 complain_overflow_dont
, /* complain_on_overflow */
1196 ppc64_elf_unhandled_reloc
, /* special_function */
1197 "R_PPC64_PLT16_LO_DS", /* name */
1198 FALSE
, /* partial_inplace */
1200 0xfffc, /* dst_mask */
1201 FALSE
), /* pcrel_offset */
1203 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1204 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1206 1, /* size (0 = byte, 1 = short, 2 = long) */
1208 FALSE
, /* pc_relative */
1210 complain_overflow_signed
, /* complain_on_overflow */
1211 ppc64_elf_sectoff_reloc
, /* special_function */
1212 "R_PPC64_SECTOFF_DS", /* name */
1213 FALSE
, /* partial_inplace */
1215 0xfffc, /* dst_mask */
1216 FALSE
), /* pcrel_offset */
1218 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1219 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1221 1, /* size (0 = byte, 1 = short, 2 = long) */
1223 FALSE
, /* pc_relative */
1225 complain_overflow_dont
, /* complain_on_overflow */
1226 ppc64_elf_sectoff_reloc
, /* special_function */
1227 "R_PPC64_SECTOFF_LO_DS",/* name */
1228 FALSE
, /* partial_inplace */
1230 0xfffc, /* dst_mask */
1231 FALSE
), /* pcrel_offset */
1233 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1234 HOWTO (R_PPC64_TOC16_DS
, /* type */
1236 1, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE
, /* pc_relative */
1240 complain_overflow_signed
, /* complain_on_overflow */
1241 ppc64_elf_toc_reloc
, /* special_function */
1242 "R_PPC64_TOC16_DS", /* name */
1243 FALSE
, /* partial_inplace */
1245 0xfffc, /* dst_mask */
1246 FALSE
), /* pcrel_offset */
1248 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1249 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1251 1, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_dont
, /* complain_on_overflow */
1256 ppc64_elf_toc_reloc
, /* special_function */
1257 "R_PPC64_TOC16_LO_DS", /* name */
1258 FALSE
, /* partial_inplace */
1260 0xfffc, /* dst_mask */
1261 FALSE
), /* pcrel_offset */
1263 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1264 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1265 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1267 1, /* size (0 = byte, 1 = short, 2 = long) */
1269 FALSE
, /* pc_relative */
1271 complain_overflow_signed
, /* complain_on_overflow */
1272 ppc64_elf_unhandled_reloc
, /* special_function */
1273 "R_PPC64_PLTGOT16_DS", /* name */
1274 FALSE
, /* partial_inplace */
1276 0xfffc, /* dst_mask */
1277 FALSE
), /* pcrel_offset */
1279 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1280 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1281 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1283 1, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_dont
, /* complain_on_overflow */
1288 ppc64_elf_unhandled_reloc
, /* special_function */
1289 "R_PPC64_PLTGOT16_LO_DS",/* name */
1290 FALSE
, /* partial_inplace */
1292 0xfffc, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 /* Marker relocs for TLS. */
1298 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 FALSE
, /* pc_relative */
1302 complain_overflow_dont
, /* complain_on_overflow */
1303 bfd_elf_generic_reloc
, /* special_function */
1304 "R_PPC64_TLS", /* name */
1305 FALSE
, /* partial_inplace */
1308 FALSE
), /* pcrel_offset */
1310 HOWTO (R_PPC64_TLSGD
,
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 FALSE
, /* pc_relative */
1316 complain_overflow_dont
, /* complain_on_overflow */
1317 bfd_elf_generic_reloc
, /* special_function */
1318 "R_PPC64_TLSGD", /* name */
1319 FALSE
, /* partial_inplace */
1322 FALSE
), /* pcrel_offset */
1324 HOWTO (R_PPC64_TLSLD
,
1326 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 FALSE
, /* pc_relative */
1330 complain_overflow_dont
, /* complain_on_overflow */
1331 bfd_elf_generic_reloc
, /* special_function */
1332 "R_PPC64_TLSLD", /* name */
1333 FALSE
, /* partial_inplace */
1336 FALSE
), /* pcrel_offset */
1338 HOWTO (R_PPC64_TOCSAVE
,
1340 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE
, /* pc_relative */
1344 complain_overflow_dont
, /* complain_on_overflow */
1345 bfd_elf_generic_reloc
, /* special_function */
1346 "R_PPC64_TOCSAVE", /* name */
1347 FALSE
, /* partial_inplace */
1350 FALSE
), /* pcrel_offset */
1352 /* Computes the load module index of the load module that contains the
1353 definition of its TLS sym. */
1354 HOWTO (R_PPC64_DTPMOD64
,
1356 4, /* size (0 = byte, 1 = short, 2 = long) */
1358 FALSE
, /* pc_relative */
1360 complain_overflow_dont
, /* complain_on_overflow */
1361 ppc64_elf_unhandled_reloc
, /* special_function */
1362 "R_PPC64_DTPMOD64", /* name */
1363 FALSE
, /* partial_inplace */
1365 ONES (64), /* dst_mask */
1366 FALSE
), /* pcrel_offset */
1368 /* Computes a dtv-relative displacement, the difference between the value
1369 of sym+add and the base address of the thread-local storage block that
1370 contains the definition of sym, minus 0x8000. */
1371 HOWTO (R_PPC64_DTPREL64
,
1373 4, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE
, /* pc_relative */
1377 complain_overflow_dont
, /* complain_on_overflow */
1378 ppc64_elf_unhandled_reloc
, /* special_function */
1379 "R_PPC64_DTPREL64", /* name */
1380 FALSE
, /* partial_inplace */
1382 ONES (64), /* dst_mask */
1383 FALSE
), /* pcrel_offset */
1385 /* A 16 bit dtprel reloc. */
1386 HOWTO (R_PPC64_DTPREL16
,
1388 1, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE
, /* pc_relative */
1392 complain_overflow_signed
, /* complain_on_overflow */
1393 ppc64_elf_unhandled_reloc
, /* special_function */
1394 "R_PPC64_DTPREL16", /* name */
1395 FALSE
, /* partial_inplace */
1397 0xffff, /* dst_mask */
1398 FALSE
), /* pcrel_offset */
1400 /* Like DTPREL16, but no overflow. */
1401 HOWTO (R_PPC64_DTPREL16_LO
,
1403 1, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE
, /* pc_relative */
1407 complain_overflow_dont
, /* complain_on_overflow */
1408 ppc64_elf_unhandled_reloc
, /* special_function */
1409 "R_PPC64_DTPREL16_LO", /* name */
1410 FALSE
, /* partial_inplace */
1412 0xffff, /* dst_mask */
1413 FALSE
), /* pcrel_offset */
1415 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1416 HOWTO (R_PPC64_DTPREL16_HI
,
1417 16, /* rightshift */
1418 1, /* size (0 = byte, 1 = short, 2 = long) */
1420 FALSE
, /* pc_relative */
1422 complain_overflow_signed
, /* complain_on_overflow */
1423 ppc64_elf_unhandled_reloc
, /* special_function */
1424 "R_PPC64_DTPREL16_HI", /* name */
1425 FALSE
, /* partial_inplace */
1427 0xffff, /* dst_mask */
1428 FALSE
), /* pcrel_offset */
1430 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1431 HOWTO (R_PPC64_DTPREL16_HA
,
1432 16, /* rightshift */
1433 1, /* size (0 = byte, 1 = short, 2 = long) */
1435 FALSE
, /* pc_relative */
1437 complain_overflow_signed
, /* complain_on_overflow */
1438 ppc64_elf_unhandled_reloc
, /* special_function */
1439 "R_PPC64_DTPREL16_HA", /* name */
1440 FALSE
, /* partial_inplace */
1442 0xffff, /* dst_mask */
1443 FALSE
), /* pcrel_offset */
1445 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1446 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1447 32, /* rightshift */
1448 1, /* size (0 = byte, 1 = short, 2 = long) */
1450 FALSE
, /* pc_relative */
1452 complain_overflow_dont
, /* complain_on_overflow */
1453 ppc64_elf_unhandled_reloc
, /* special_function */
1454 "R_PPC64_DTPREL16_HIGHER", /* name */
1455 FALSE
, /* partial_inplace */
1457 0xffff, /* dst_mask */
1458 FALSE
), /* pcrel_offset */
1460 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1461 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1462 32, /* rightshift */
1463 1, /* size (0 = byte, 1 = short, 2 = long) */
1465 FALSE
, /* pc_relative */
1467 complain_overflow_dont
, /* complain_on_overflow */
1468 ppc64_elf_unhandled_reloc
, /* special_function */
1469 "R_PPC64_DTPREL16_HIGHERA", /* name */
1470 FALSE
, /* partial_inplace */
1472 0xffff, /* dst_mask */
1473 FALSE
), /* pcrel_offset */
1475 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1476 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1477 48, /* rightshift */
1478 1, /* size (0 = byte, 1 = short, 2 = long) */
1480 FALSE
, /* pc_relative */
1482 complain_overflow_dont
, /* complain_on_overflow */
1483 ppc64_elf_unhandled_reloc
, /* special_function */
1484 "R_PPC64_DTPREL16_HIGHEST", /* name */
1485 FALSE
, /* partial_inplace */
1487 0xffff, /* dst_mask */
1488 FALSE
), /* pcrel_offset */
1490 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1491 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1492 48, /* rightshift */
1493 1, /* size (0 = byte, 1 = short, 2 = long) */
1495 FALSE
, /* pc_relative */
1497 complain_overflow_dont
, /* complain_on_overflow */
1498 ppc64_elf_unhandled_reloc
, /* special_function */
1499 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1500 FALSE
, /* partial_inplace */
1502 0xffff, /* dst_mask */
1503 FALSE
), /* pcrel_offset */
1505 /* Like DTPREL16, but for insns with a DS field. */
1506 HOWTO (R_PPC64_DTPREL16_DS
,
1508 1, /* size (0 = byte, 1 = short, 2 = long) */
1510 FALSE
, /* pc_relative */
1512 complain_overflow_signed
, /* complain_on_overflow */
1513 ppc64_elf_unhandled_reloc
, /* special_function */
1514 "R_PPC64_DTPREL16_DS", /* name */
1515 FALSE
, /* partial_inplace */
1517 0xfffc, /* dst_mask */
1518 FALSE
), /* pcrel_offset */
1520 /* Like DTPREL16_DS, but no overflow. */
1521 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1523 1, /* size (0 = byte, 1 = short, 2 = long) */
1525 FALSE
, /* pc_relative */
1527 complain_overflow_dont
, /* complain_on_overflow */
1528 ppc64_elf_unhandled_reloc
, /* special_function */
1529 "R_PPC64_DTPREL16_LO_DS", /* name */
1530 FALSE
, /* partial_inplace */
1532 0xfffc, /* dst_mask */
1533 FALSE
), /* pcrel_offset */
1535 /* Computes a tp-relative displacement, the difference between the value of
1536 sym+add and the value of the thread pointer (r13). */
1537 HOWTO (R_PPC64_TPREL64
,
1539 4, /* size (0 = byte, 1 = short, 2 = long) */
1541 FALSE
, /* pc_relative */
1543 complain_overflow_dont
, /* complain_on_overflow */
1544 ppc64_elf_unhandled_reloc
, /* special_function */
1545 "R_PPC64_TPREL64", /* name */
1546 FALSE
, /* partial_inplace */
1548 ONES (64), /* dst_mask */
1549 FALSE
), /* pcrel_offset */
1551 /* A 16 bit tprel reloc. */
1552 HOWTO (R_PPC64_TPREL16
,
1554 1, /* size (0 = byte, 1 = short, 2 = long) */
1556 FALSE
, /* pc_relative */
1558 complain_overflow_signed
, /* complain_on_overflow */
1559 ppc64_elf_unhandled_reloc
, /* special_function */
1560 "R_PPC64_TPREL16", /* name */
1561 FALSE
, /* partial_inplace */
1563 0xffff, /* dst_mask */
1564 FALSE
), /* pcrel_offset */
1566 /* Like TPREL16, but no overflow. */
1567 HOWTO (R_PPC64_TPREL16_LO
,
1569 1, /* size (0 = byte, 1 = short, 2 = long) */
1571 FALSE
, /* pc_relative */
1573 complain_overflow_dont
, /* complain_on_overflow */
1574 ppc64_elf_unhandled_reloc
, /* special_function */
1575 "R_PPC64_TPREL16_LO", /* name */
1576 FALSE
, /* partial_inplace */
1578 0xffff, /* dst_mask */
1579 FALSE
), /* pcrel_offset */
1581 /* Like TPREL16_LO, but next higher group of 16 bits. */
1582 HOWTO (R_PPC64_TPREL16_HI
,
1583 16, /* rightshift */
1584 1, /* size (0 = byte, 1 = short, 2 = long) */
1586 FALSE
, /* pc_relative */
1588 complain_overflow_signed
, /* complain_on_overflow */
1589 ppc64_elf_unhandled_reloc
, /* special_function */
1590 "R_PPC64_TPREL16_HI", /* name */
1591 FALSE
, /* partial_inplace */
1593 0xffff, /* dst_mask */
1594 FALSE
), /* pcrel_offset */
1596 /* Like TPREL16_HI, but adjust for low 16 bits. */
1597 HOWTO (R_PPC64_TPREL16_HA
,
1598 16, /* rightshift */
1599 1, /* size (0 = byte, 1 = short, 2 = long) */
1601 FALSE
, /* pc_relative */
1603 complain_overflow_signed
, /* complain_on_overflow */
1604 ppc64_elf_unhandled_reloc
, /* special_function */
1605 "R_PPC64_TPREL16_HA", /* name */
1606 FALSE
, /* partial_inplace */
1608 0xffff, /* dst_mask */
1609 FALSE
), /* pcrel_offset */
1611 /* Like TPREL16_HI, but next higher group of 16 bits. */
1612 HOWTO (R_PPC64_TPREL16_HIGHER
,
1613 32, /* rightshift */
1614 1, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE
, /* pc_relative */
1618 complain_overflow_dont
, /* complain_on_overflow */
1619 ppc64_elf_unhandled_reloc
, /* special_function */
1620 "R_PPC64_TPREL16_HIGHER", /* name */
1621 FALSE
, /* partial_inplace */
1623 0xffff, /* dst_mask */
1624 FALSE
), /* pcrel_offset */
1626 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1627 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1628 32, /* rightshift */
1629 1, /* size (0 = byte, 1 = short, 2 = long) */
1631 FALSE
, /* pc_relative */
1633 complain_overflow_dont
, /* complain_on_overflow */
1634 ppc64_elf_unhandled_reloc
, /* special_function */
1635 "R_PPC64_TPREL16_HIGHERA", /* name */
1636 FALSE
, /* partial_inplace */
1638 0xffff, /* dst_mask */
1639 FALSE
), /* pcrel_offset */
1641 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1642 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1643 48, /* rightshift */
1644 1, /* size (0 = byte, 1 = short, 2 = long) */
1646 FALSE
, /* pc_relative */
1648 complain_overflow_dont
, /* complain_on_overflow */
1649 ppc64_elf_unhandled_reloc
, /* special_function */
1650 "R_PPC64_TPREL16_HIGHEST", /* name */
1651 FALSE
, /* partial_inplace */
1653 0xffff, /* dst_mask */
1654 FALSE
), /* pcrel_offset */
1656 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1657 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1658 48, /* rightshift */
1659 1, /* size (0 = byte, 1 = short, 2 = long) */
1661 FALSE
, /* pc_relative */
1663 complain_overflow_dont
, /* complain_on_overflow */
1664 ppc64_elf_unhandled_reloc
, /* special_function */
1665 "R_PPC64_TPREL16_HIGHESTA", /* name */
1666 FALSE
, /* partial_inplace */
1668 0xffff, /* dst_mask */
1669 FALSE
), /* pcrel_offset */
1671 /* Like TPREL16, but for insns with a DS field. */
1672 HOWTO (R_PPC64_TPREL16_DS
,
1674 1, /* size (0 = byte, 1 = short, 2 = long) */
1676 FALSE
, /* pc_relative */
1678 complain_overflow_signed
, /* complain_on_overflow */
1679 ppc64_elf_unhandled_reloc
, /* special_function */
1680 "R_PPC64_TPREL16_DS", /* name */
1681 FALSE
, /* partial_inplace */
1683 0xfffc, /* dst_mask */
1684 FALSE
), /* pcrel_offset */
1686 /* Like TPREL16_DS, but no overflow. */
1687 HOWTO (R_PPC64_TPREL16_LO_DS
,
1689 1, /* size (0 = byte, 1 = short, 2 = long) */
1691 FALSE
, /* pc_relative */
1693 complain_overflow_dont
, /* complain_on_overflow */
1694 ppc64_elf_unhandled_reloc
, /* special_function */
1695 "R_PPC64_TPREL16_LO_DS", /* name */
1696 FALSE
, /* partial_inplace */
1698 0xfffc, /* dst_mask */
1699 FALSE
), /* pcrel_offset */
1701 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1702 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1703 to the first entry relative to the TOC base (r2). */
1704 HOWTO (R_PPC64_GOT_TLSGD16
,
1706 1, /* size (0 = byte, 1 = short, 2 = long) */
1708 FALSE
, /* pc_relative */
1710 complain_overflow_signed
, /* complain_on_overflow */
1711 ppc64_elf_unhandled_reloc
, /* special_function */
1712 "R_PPC64_GOT_TLSGD16", /* name */
1713 FALSE
, /* partial_inplace */
1715 0xffff, /* dst_mask */
1716 FALSE
), /* pcrel_offset */
1718 /* Like GOT_TLSGD16, but no overflow. */
1719 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1721 1, /* size (0 = byte, 1 = short, 2 = long) */
1723 FALSE
, /* pc_relative */
1725 complain_overflow_dont
, /* complain_on_overflow */
1726 ppc64_elf_unhandled_reloc
, /* special_function */
1727 "R_PPC64_GOT_TLSGD16_LO", /* name */
1728 FALSE
, /* partial_inplace */
1730 0xffff, /* dst_mask */
1731 FALSE
), /* pcrel_offset */
1733 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1734 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1735 16, /* rightshift */
1736 1, /* size (0 = byte, 1 = short, 2 = long) */
1738 FALSE
, /* pc_relative */
1740 complain_overflow_signed
, /* complain_on_overflow */
1741 ppc64_elf_unhandled_reloc
, /* special_function */
1742 "R_PPC64_GOT_TLSGD16_HI", /* name */
1743 FALSE
, /* partial_inplace */
1745 0xffff, /* dst_mask */
1746 FALSE
), /* pcrel_offset */
1748 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1749 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1750 16, /* rightshift */
1751 1, /* size (0 = byte, 1 = short, 2 = long) */
1753 FALSE
, /* pc_relative */
1755 complain_overflow_signed
, /* complain_on_overflow */
1756 ppc64_elf_unhandled_reloc
, /* special_function */
1757 "R_PPC64_GOT_TLSGD16_HA", /* name */
1758 FALSE
, /* partial_inplace */
1760 0xffff, /* dst_mask */
1761 FALSE
), /* pcrel_offset */
1763 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1764 with values (sym+add)@dtpmod and zero, and computes the offset to the
1765 first entry relative to the TOC base (r2). */
1766 HOWTO (R_PPC64_GOT_TLSLD16
,
1768 1, /* size (0 = byte, 1 = short, 2 = long) */
1770 FALSE
, /* pc_relative */
1772 complain_overflow_signed
, /* complain_on_overflow */
1773 ppc64_elf_unhandled_reloc
, /* special_function */
1774 "R_PPC64_GOT_TLSLD16", /* name */
1775 FALSE
, /* partial_inplace */
1777 0xffff, /* dst_mask */
1778 FALSE
), /* pcrel_offset */
1780 /* Like GOT_TLSLD16, but no overflow. */
1781 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1783 1, /* size (0 = byte, 1 = short, 2 = long) */
1785 FALSE
, /* pc_relative */
1787 complain_overflow_dont
, /* complain_on_overflow */
1788 ppc64_elf_unhandled_reloc
, /* special_function */
1789 "R_PPC64_GOT_TLSLD16_LO", /* name */
1790 FALSE
, /* partial_inplace */
1792 0xffff, /* dst_mask */
1793 FALSE
), /* pcrel_offset */
1795 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1796 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1797 16, /* rightshift */
1798 1, /* size (0 = byte, 1 = short, 2 = long) */
1800 FALSE
, /* pc_relative */
1802 complain_overflow_signed
, /* complain_on_overflow */
1803 ppc64_elf_unhandled_reloc
, /* special_function */
1804 "R_PPC64_GOT_TLSLD16_HI", /* name */
1805 FALSE
, /* partial_inplace */
1807 0xffff, /* dst_mask */
1808 FALSE
), /* pcrel_offset */
1810 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1811 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1812 16, /* rightshift */
1813 1, /* size (0 = byte, 1 = short, 2 = long) */
1815 FALSE
, /* pc_relative */
1817 complain_overflow_signed
, /* complain_on_overflow */
1818 ppc64_elf_unhandled_reloc
, /* special_function */
1819 "R_PPC64_GOT_TLSLD16_HA", /* name */
1820 FALSE
, /* partial_inplace */
1822 0xffff, /* dst_mask */
1823 FALSE
), /* pcrel_offset */
1825 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1826 the offset to the entry relative to the TOC base (r2). */
1827 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1829 1, /* size (0 = byte, 1 = short, 2 = long) */
1831 FALSE
, /* pc_relative */
1833 complain_overflow_signed
, /* complain_on_overflow */
1834 ppc64_elf_unhandled_reloc
, /* special_function */
1835 "R_PPC64_GOT_DTPREL16_DS", /* name */
1836 FALSE
, /* partial_inplace */
1838 0xfffc, /* dst_mask */
1839 FALSE
), /* pcrel_offset */
1841 /* Like GOT_DTPREL16_DS, but no overflow. */
1842 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1844 1, /* size (0 = byte, 1 = short, 2 = long) */
1846 FALSE
, /* pc_relative */
1848 complain_overflow_dont
, /* complain_on_overflow */
1849 ppc64_elf_unhandled_reloc
, /* special_function */
1850 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1851 FALSE
, /* partial_inplace */
1853 0xfffc, /* dst_mask */
1854 FALSE
), /* pcrel_offset */
1856 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1857 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1858 16, /* rightshift */
1859 1, /* size (0 = byte, 1 = short, 2 = long) */
1861 FALSE
, /* pc_relative */
1863 complain_overflow_signed
, /* complain_on_overflow */
1864 ppc64_elf_unhandled_reloc
, /* special_function */
1865 "R_PPC64_GOT_DTPREL16_HI", /* name */
1866 FALSE
, /* partial_inplace */
1868 0xffff, /* dst_mask */
1869 FALSE
), /* pcrel_offset */
1871 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1872 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1873 16, /* rightshift */
1874 1, /* size (0 = byte, 1 = short, 2 = long) */
1876 FALSE
, /* pc_relative */
1878 complain_overflow_signed
, /* complain_on_overflow */
1879 ppc64_elf_unhandled_reloc
, /* special_function */
1880 "R_PPC64_GOT_DTPREL16_HA", /* name */
1881 FALSE
, /* partial_inplace */
1883 0xffff, /* dst_mask */
1884 FALSE
), /* pcrel_offset */
1886 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1887 offset to the entry relative to the TOC base (r2). */
1888 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1890 1, /* size (0 = byte, 1 = short, 2 = long) */
1892 FALSE
, /* pc_relative */
1894 complain_overflow_signed
, /* complain_on_overflow */
1895 ppc64_elf_unhandled_reloc
, /* special_function */
1896 "R_PPC64_GOT_TPREL16_DS", /* name */
1897 FALSE
, /* partial_inplace */
1899 0xfffc, /* dst_mask */
1900 FALSE
), /* pcrel_offset */
1902 /* Like GOT_TPREL16_DS, but no overflow. */
1903 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1905 1, /* size (0 = byte, 1 = short, 2 = long) */
1907 FALSE
, /* pc_relative */
1909 complain_overflow_dont
, /* complain_on_overflow */
1910 ppc64_elf_unhandled_reloc
, /* special_function */
1911 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1912 FALSE
, /* partial_inplace */
1914 0xfffc, /* dst_mask */
1915 FALSE
), /* pcrel_offset */
1917 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1918 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1919 16, /* rightshift */
1920 1, /* size (0 = byte, 1 = short, 2 = long) */
1922 FALSE
, /* pc_relative */
1924 complain_overflow_signed
, /* complain_on_overflow */
1925 ppc64_elf_unhandled_reloc
, /* special_function */
1926 "R_PPC64_GOT_TPREL16_HI", /* name */
1927 FALSE
, /* partial_inplace */
1929 0xffff, /* dst_mask */
1930 FALSE
), /* pcrel_offset */
1932 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1933 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1934 16, /* rightshift */
1935 1, /* size (0 = byte, 1 = short, 2 = long) */
1937 FALSE
, /* pc_relative */
1939 complain_overflow_signed
, /* complain_on_overflow */
1940 ppc64_elf_unhandled_reloc
, /* special_function */
1941 "R_PPC64_GOT_TPREL16_HA", /* name */
1942 FALSE
, /* partial_inplace */
1944 0xffff, /* dst_mask */
1945 FALSE
), /* pcrel_offset */
1947 HOWTO (R_PPC64_JMP_IREL
, /* type */
1949 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1951 FALSE
, /* pc_relative */
1953 complain_overflow_dont
, /* complain_on_overflow */
1954 ppc64_elf_unhandled_reloc
, /* special_function */
1955 "R_PPC64_JMP_IREL", /* name */
1956 FALSE
, /* partial_inplace */
1959 FALSE
), /* pcrel_offset */
1961 HOWTO (R_PPC64_IRELATIVE
, /* type */
1963 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1965 FALSE
, /* pc_relative */
1967 complain_overflow_dont
, /* complain_on_overflow */
1968 bfd_elf_generic_reloc
, /* special_function */
1969 "R_PPC64_IRELATIVE", /* name */
1970 FALSE
, /* partial_inplace */
1972 ONES (64), /* dst_mask */
1973 FALSE
), /* pcrel_offset */
1975 /* A 16 bit relative relocation. */
1976 HOWTO (R_PPC64_REL16
, /* type */
1978 1, /* size (0 = byte, 1 = short, 2 = long) */
1980 TRUE
, /* pc_relative */
1982 complain_overflow_signed
, /* complain_on_overflow */
1983 bfd_elf_generic_reloc
, /* special_function */
1984 "R_PPC64_REL16", /* name */
1985 FALSE
, /* partial_inplace */
1987 0xffff, /* dst_mask */
1988 TRUE
), /* pcrel_offset */
1990 /* A 16 bit relative relocation without overflow. */
1991 HOWTO (R_PPC64_REL16_LO
, /* type */
1993 1, /* size (0 = byte, 1 = short, 2 = long) */
1995 TRUE
, /* pc_relative */
1997 complain_overflow_dont
,/* complain_on_overflow */
1998 bfd_elf_generic_reloc
, /* special_function */
1999 "R_PPC64_REL16_LO", /* name */
2000 FALSE
, /* partial_inplace */
2002 0xffff, /* dst_mask */
2003 TRUE
), /* pcrel_offset */
2005 /* The high order 16 bits of a relative address. */
2006 HOWTO (R_PPC64_REL16_HI
, /* type */
2007 16, /* rightshift */
2008 1, /* size (0 = byte, 1 = short, 2 = long) */
2010 TRUE
, /* pc_relative */
2012 complain_overflow_signed
, /* complain_on_overflow */
2013 bfd_elf_generic_reloc
, /* special_function */
2014 "R_PPC64_REL16_HI", /* name */
2015 FALSE
, /* partial_inplace */
2017 0xffff, /* dst_mask */
2018 TRUE
), /* pcrel_offset */
2020 /* The high order 16 bits of a relative address, plus 1 if the contents of
2021 the low 16 bits, treated as a signed number, is negative. */
2022 HOWTO (R_PPC64_REL16_HA
, /* type */
2023 16, /* rightshift */
2024 1, /* size (0 = byte, 1 = short, 2 = long) */
2026 TRUE
, /* pc_relative */
2028 complain_overflow_signed
, /* complain_on_overflow */
2029 ppc64_elf_ha_reloc
, /* special_function */
2030 "R_PPC64_REL16_HA", /* name */
2031 FALSE
, /* partial_inplace */
2033 0xffff, /* dst_mask */
2034 TRUE
), /* pcrel_offset */
2036 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2037 HOWTO (R_PPC64_REL16DX_HA
, /* type */
2038 16, /* rightshift */
2039 2, /* size (0 = byte, 1 = short, 2 = long) */
2041 TRUE
, /* pc_relative */
2043 complain_overflow_signed
, /* complain_on_overflow */
2044 ppc64_elf_ha_reloc
, /* special_function */
2045 "R_PPC64_REL16DX_HA", /* name */
2046 FALSE
, /* partial_inplace */
2048 0x1fffc1, /* dst_mask */
2049 TRUE
), /* pcrel_offset */
2051 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
2052 HOWTO (R_PPC64_16DX_HA
, /* type */
2053 16, /* rightshift */
2054 2, /* size (0 = byte, 1 = short, 2 = long) */
2056 FALSE
, /* pc_relative */
2058 complain_overflow_signed
, /* complain_on_overflow */
2059 ppc64_elf_ha_reloc
, /* special_function */
2060 "R_PPC64_16DX_HA", /* name */
2061 FALSE
, /* partial_inplace */
2063 0x1fffc1, /* dst_mask */
2064 FALSE
), /* pcrel_offset */
2066 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2067 HOWTO (R_PPC64_ADDR16_HIGH
, /* type */
2068 16, /* rightshift */
2069 1, /* size (0 = byte, 1 = short, 2 = long) */
2071 FALSE
, /* pc_relative */
2073 complain_overflow_dont
, /* complain_on_overflow */
2074 bfd_elf_generic_reloc
, /* special_function */
2075 "R_PPC64_ADDR16_HIGH", /* name */
2076 FALSE
, /* partial_inplace */
2078 0xffff, /* dst_mask */
2079 FALSE
), /* pcrel_offset */
2081 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2082 HOWTO (R_PPC64_ADDR16_HIGHA
, /* type */
2083 16, /* rightshift */
2084 1, /* size (0 = byte, 1 = short, 2 = long) */
2086 FALSE
, /* pc_relative */
2088 complain_overflow_dont
, /* complain_on_overflow */
2089 ppc64_elf_ha_reloc
, /* special_function */
2090 "R_PPC64_ADDR16_HIGHA", /* name */
2091 FALSE
, /* partial_inplace */
2093 0xffff, /* dst_mask */
2094 FALSE
), /* pcrel_offset */
2096 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2097 HOWTO (R_PPC64_DTPREL16_HIGH
,
2098 16, /* rightshift */
2099 1, /* size (0 = byte, 1 = short, 2 = long) */
2101 FALSE
, /* pc_relative */
2103 complain_overflow_dont
, /* complain_on_overflow */
2104 ppc64_elf_unhandled_reloc
, /* special_function */
2105 "R_PPC64_DTPREL16_HIGH", /* name */
2106 FALSE
, /* partial_inplace */
2108 0xffff, /* dst_mask */
2109 FALSE
), /* pcrel_offset */
2111 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2112 HOWTO (R_PPC64_DTPREL16_HIGHA
,
2113 16, /* rightshift */
2114 1, /* size (0 = byte, 1 = short, 2 = long) */
2116 FALSE
, /* pc_relative */
2118 complain_overflow_dont
, /* complain_on_overflow */
2119 ppc64_elf_unhandled_reloc
, /* special_function */
2120 "R_PPC64_DTPREL16_HIGHA", /* name */
2121 FALSE
, /* partial_inplace */
2123 0xffff, /* dst_mask */
2124 FALSE
), /* pcrel_offset */
2126 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2127 HOWTO (R_PPC64_TPREL16_HIGH
,
2128 16, /* rightshift */
2129 1, /* size (0 = byte, 1 = short, 2 = long) */
2131 FALSE
, /* pc_relative */
2133 complain_overflow_dont
, /* complain_on_overflow */
2134 ppc64_elf_unhandled_reloc
, /* special_function */
2135 "R_PPC64_TPREL16_HIGH", /* name */
2136 FALSE
, /* partial_inplace */
2138 0xffff, /* dst_mask */
2139 FALSE
), /* pcrel_offset */
2141 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2142 HOWTO (R_PPC64_TPREL16_HIGHA
,
2143 16, /* rightshift */
2144 1, /* size (0 = byte, 1 = short, 2 = long) */
2146 FALSE
, /* pc_relative */
2148 complain_overflow_dont
, /* complain_on_overflow */
2149 ppc64_elf_unhandled_reloc
, /* special_function */
2150 "R_PPC64_TPREL16_HIGHA", /* name */
2151 FALSE
, /* partial_inplace */
2153 0xffff, /* dst_mask */
2154 FALSE
), /* pcrel_offset */
2156 /* Marker reloc on ELFv2 large-model function entry. */
2157 HOWTO (R_PPC64_ENTRY
,
2159 2, /* size (0 = byte, 1 = short, 2 = long) */
2161 FALSE
, /* pc_relative */
2163 complain_overflow_dont
, /* complain_on_overflow */
2164 bfd_elf_generic_reloc
, /* special_function */
2165 "R_PPC64_ENTRY", /* name */
2166 FALSE
, /* partial_inplace */
2169 FALSE
), /* pcrel_offset */
2171 /* Like ADDR64, but use local entry point of function. */
2172 HOWTO (R_PPC64_ADDR64_LOCAL
, /* type */
2174 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2176 FALSE
, /* pc_relative */
2178 complain_overflow_dont
, /* complain_on_overflow */
2179 bfd_elf_generic_reloc
, /* special_function */
2180 "R_PPC64_ADDR64_LOCAL", /* name */
2181 FALSE
, /* partial_inplace */
2183 ONES (64), /* dst_mask */
2184 FALSE
), /* pcrel_offset */
2186 /* GNU extension to record C++ vtable hierarchy. */
2187 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
2189 0, /* size (0 = byte, 1 = short, 2 = long) */
2191 FALSE
, /* pc_relative */
2193 complain_overflow_dont
, /* complain_on_overflow */
2194 NULL
, /* special_function */
2195 "R_PPC64_GNU_VTINHERIT", /* name */
2196 FALSE
, /* partial_inplace */
2199 FALSE
), /* pcrel_offset */
2201 /* GNU extension to record C++ vtable member usage. */
2202 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
2204 0, /* size (0 = byte, 1 = short, 2 = long) */
2206 FALSE
, /* pc_relative */
2208 complain_overflow_dont
, /* complain_on_overflow */
2209 NULL
, /* special_function */
2210 "R_PPC64_GNU_VTENTRY", /* name */
2211 FALSE
, /* partial_inplace */
2214 FALSE
), /* pcrel_offset */
2218 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2222 ppc_howto_init (void)
2224 unsigned int i
, type
;
2226 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2228 type
= ppc64_elf_howto_raw
[i
].type
;
2229 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
2230 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2234 static reloc_howto_type
*
2235 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
2236 bfd_reloc_code_real_type code
)
2238 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2240 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2241 /* Initialize howto table if needed. */
2247 /* xgettext:c-format */
2248 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, (int) code
);
2249 bfd_set_error (bfd_error_bad_value
);
2252 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2254 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2256 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2258 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2260 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2262 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2264 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
2266 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2268 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
2270 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2272 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2274 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2276 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2278 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2280 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2282 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2284 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2286 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2288 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2290 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2292 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2294 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2296 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2298 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2300 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2302 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2304 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2306 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2308 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2310 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2312 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2314 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2316 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2318 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2320 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2322 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2324 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2326 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2328 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2330 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2332 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2334 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2336 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2338 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2340 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2342 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2344 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2346 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2348 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2350 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2352 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2354 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2356 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2358 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2360 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2362 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2364 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2366 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2368 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2370 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2372 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2374 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2376 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2378 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2380 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2382 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2384 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2386 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2388 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
2390 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2392 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
2394 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2396 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2398 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2400 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2402 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
2404 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2406 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
2408 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2410 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2412 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2414 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2416 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2418 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2420 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2422 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2424 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2426 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2428 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2430 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2432 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2434 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2436 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2438 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2440 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2442 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2444 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2446 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2448 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2450 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2452 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2454 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2456 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2458 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2460 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2462 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2464 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2466 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2468 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2470 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2472 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2474 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
2476 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
2478 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
2480 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
2482 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2484 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2488 return ppc64_elf_howto_table
[r
];
2491 static reloc_howto_type
*
2492 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2497 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2498 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2499 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2500 return &ppc64_elf_howto_raw
[i
];
2506 /* Set the howto pointer for a PowerPC ELF reloc. */
2509 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
2510 Elf_Internal_Rela
*dst
)
2514 /* Initialize howto table if needed. */
2515 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2518 type
= ELF64_R_TYPE (dst
->r_info
);
2519 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
2521 /* xgettext:c-format */
2522 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2524 bfd_set_error (bfd_error_bad_value
);
2527 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2528 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
2530 /* xgettext:c-format */
2531 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2533 bfd_set_error (bfd_error_bad_value
);
2540 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2542 static bfd_reloc_status_type
2543 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2544 void *data
, asection
*input_section
,
2545 bfd
*output_bfd
, char **error_message
)
2547 enum elf_ppc64_reloc_type r_type
;
2549 bfd_size_type octets
;
2552 /* If this is a relocatable link (output_bfd test tells us), just
2553 call the generic function. Any adjustment will be done at final
2555 if (output_bfd
!= NULL
)
2556 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2557 input_section
, output_bfd
, error_message
);
2559 /* Adjust the addend for sign extension of the low 16 bits.
2560 We won't actually be using the low 16 bits, so trashing them
2562 reloc_entry
->addend
+= 0x8000;
2563 r_type
= reloc_entry
->howto
->type
;
2564 if (r_type
!= R_PPC64_REL16DX_HA
)
2565 return bfd_reloc_continue
;
2568 if (!bfd_is_com_section (symbol
->section
))
2569 value
= symbol
->value
;
2570 value
+= (reloc_entry
->addend
2571 + symbol
->section
->output_offset
2572 + symbol
->section
->output_section
->vma
);
2573 value
-= (reloc_entry
->address
2574 + input_section
->output_offset
2575 + input_section
->output_section
->vma
);
2576 value
= (bfd_signed_vma
) value
>> 16;
2578 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2579 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2581 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2582 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2583 if (value
+ 0x8000 > 0xffff)
2584 return bfd_reloc_overflow
;
2585 return bfd_reloc_ok
;
2588 static bfd_reloc_status_type
2589 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2590 void *data
, asection
*input_section
,
2591 bfd
*output_bfd
, char **error_message
)
2593 if (output_bfd
!= NULL
)
2594 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2595 input_section
, output_bfd
, error_message
);
2597 if (strcmp (symbol
->section
->name
, ".opd") == 0
2598 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2600 bfd_vma dest
= opd_entry_value (symbol
->section
,
2601 symbol
->value
+ reloc_entry
->addend
,
2603 if (dest
!= (bfd_vma
) -1)
2604 reloc_entry
->addend
= dest
- (symbol
->value
2605 + symbol
->section
->output_section
->vma
2606 + symbol
->section
->output_offset
);
2610 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
2612 if (symbol
->section
->owner
!= abfd
2613 && symbol
->section
->owner
!= NULL
2614 && abiversion (symbol
->section
->owner
) >= 2)
2618 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
2620 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
2622 if (strcmp (symdef
->name
, symbol
->name
) == 0)
2624 elfsym
= (elf_symbol_type
*) symdef
;
2630 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
2632 return bfd_reloc_continue
;
2635 static bfd_reloc_status_type
2636 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2637 void *data
, asection
*input_section
,
2638 bfd
*output_bfd
, char **error_message
)
2641 enum elf_ppc64_reloc_type r_type
;
2642 bfd_size_type octets
;
2643 /* Assume 'at' branch hints. */
2644 bfd_boolean is_isa_v2
= TRUE
;
2646 /* If this is a relocatable link (output_bfd test tells us), just
2647 call the generic function. Any adjustment will be done at final
2649 if (output_bfd
!= NULL
)
2650 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2651 input_section
, output_bfd
, error_message
);
2653 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2654 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2655 insn
&= ~(0x01 << 21);
2656 r_type
= reloc_entry
->howto
->type
;
2657 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2658 || r_type
== R_PPC64_REL14_BRTAKEN
)
2659 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2663 /* Set 'a' bit. This is 0b00010 in BO field for branch
2664 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2665 for branch on CTR insns (BO == 1a00t or 1a01t). */
2666 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2668 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2678 if (!bfd_is_com_section (symbol
->section
))
2679 target
= symbol
->value
;
2680 target
+= symbol
->section
->output_section
->vma
;
2681 target
+= symbol
->section
->output_offset
;
2682 target
+= reloc_entry
->addend
;
2684 from
= (reloc_entry
->address
2685 + input_section
->output_offset
2686 + input_section
->output_section
->vma
);
2688 /* Invert 'y' bit if not the default. */
2689 if ((bfd_signed_vma
) (target
- from
) < 0)
2692 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2694 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2695 input_section
, output_bfd
, error_message
);
2698 static bfd_reloc_status_type
2699 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2700 void *data
, asection
*input_section
,
2701 bfd
*output_bfd
, char **error_message
)
2703 /* If this is a relocatable link (output_bfd test tells us), just
2704 call the generic function. Any adjustment will be done at final
2706 if (output_bfd
!= NULL
)
2707 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2708 input_section
, output_bfd
, error_message
);
2710 /* Subtract the symbol section base address. */
2711 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2712 return bfd_reloc_continue
;
2715 static bfd_reloc_status_type
2716 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2717 void *data
, asection
*input_section
,
2718 bfd
*output_bfd
, char **error_message
)
2720 /* If this is a relocatable link (output_bfd test tells us), just
2721 call the generic function. Any adjustment will be done at final
2723 if (output_bfd
!= NULL
)
2724 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2725 input_section
, output_bfd
, error_message
);
2727 /* Subtract the symbol section base address. */
2728 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2730 /* Adjust the addend for sign extension of the low 16 bits. */
2731 reloc_entry
->addend
+= 0x8000;
2732 return bfd_reloc_continue
;
2735 static bfd_reloc_status_type
2736 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2737 void *data
, asection
*input_section
,
2738 bfd
*output_bfd
, char **error_message
)
2742 /* If this is a relocatable link (output_bfd test tells us), just
2743 call the generic function. Any adjustment will be done at final
2745 if (output_bfd
!= NULL
)
2746 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2747 input_section
, output_bfd
, error_message
);
2749 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2751 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2753 /* Subtract the TOC base address. */
2754 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2755 return bfd_reloc_continue
;
2758 static bfd_reloc_status_type
2759 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2760 void *data
, asection
*input_section
,
2761 bfd
*output_bfd
, char **error_message
)
2765 /* If this is a relocatable link (output_bfd test tells us), just
2766 call the generic function. Any adjustment will be done at final
2768 if (output_bfd
!= NULL
)
2769 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2770 input_section
, output_bfd
, error_message
);
2772 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2774 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2776 /* Subtract the TOC base address. */
2777 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2779 /* Adjust the addend for sign extension of the low 16 bits. */
2780 reloc_entry
->addend
+= 0x8000;
2781 return bfd_reloc_continue
;
2784 static bfd_reloc_status_type
2785 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2786 void *data
, asection
*input_section
,
2787 bfd
*output_bfd
, char **error_message
)
2790 bfd_size_type octets
;
2792 /* If this is a relocatable link (output_bfd test tells us), just
2793 call the generic function. Any adjustment will be done at final
2795 if (output_bfd
!= NULL
)
2796 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2797 input_section
, output_bfd
, error_message
);
2799 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2801 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2803 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2804 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2805 return bfd_reloc_ok
;
2808 static bfd_reloc_status_type
2809 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2810 void *data
, asection
*input_section
,
2811 bfd
*output_bfd
, char **error_message
)
2813 /* If this is a relocatable link (output_bfd test tells us), just
2814 call the generic function. Any adjustment will be done at final
2816 if (output_bfd
!= NULL
)
2817 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2818 input_section
, output_bfd
, error_message
);
2820 if (error_message
!= NULL
)
2822 static char buf
[60];
2823 sprintf (buf
, "generic linker can't handle %s",
2824 reloc_entry
->howto
->name
);
2825 *error_message
= buf
;
2827 return bfd_reloc_dangerous
;
2830 /* Track GOT entries needed for a given symbol. We might need more
2831 than one got entry per symbol. */
2834 struct got_entry
*next
;
2836 /* The symbol addend that we'll be placing in the GOT. */
2839 /* Unlike other ELF targets, we use separate GOT entries for the same
2840 symbol referenced from different input files. This is to support
2841 automatic multiple TOC/GOT sections, where the TOC base can vary
2842 from one input file to another. After partitioning into TOC groups
2843 we merge entries within the group.
2845 Point to the BFD owning this GOT entry. */
2848 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2849 TLS_TPREL or TLS_DTPREL for tls entries. */
2850 unsigned char tls_type
;
2852 /* Non-zero if got.ent points to real entry. */
2853 unsigned char is_indirect
;
2855 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2858 bfd_signed_vma refcount
;
2860 struct got_entry
*ent
;
2864 /* The same for PLT. */
2867 struct plt_entry
*next
;
2873 bfd_signed_vma refcount
;
2878 struct ppc64_elf_obj_tdata
2880 struct elf_obj_tdata elf
;
2882 /* Shortcuts to dynamic linker sections. */
2886 /* Used during garbage collection. We attach global symbols defined
2887 on removed .opd entries to this section so that the sym is removed. */
2888 asection
*deleted_section
;
2890 /* TLS local dynamic got entry handling. Support for multiple GOT
2891 sections means we potentially need one of these for each input bfd. */
2892 struct got_entry tlsld_got
;
2895 /* A copy of relocs before they are modified for --emit-relocs. */
2896 Elf_Internal_Rela
*relocs
;
2898 /* Section contents. */
2902 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2903 the reloc to be in the range -32768 to 32767. */
2904 unsigned int has_small_toc_reloc
: 1;
2906 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2907 instruction not one we handle. */
2908 unsigned int unexpected_toc_insn
: 1;
2911 #define ppc64_elf_tdata(bfd) \
2912 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2914 #define ppc64_tlsld_got(bfd) \
2915 (&ppc64_elf_tdata (bfd)->tlsld_got)
2917 #define is_ppc64_elf(bfd) \
2918 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2919 && elf_object_id (bfd) == PPC64_ELF_DATA)
2921 /* Override the generic function because we store some extras. */
2924 ppc64_elf_mkobject (bfd
*abfd
)
2926 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2930 /* Fix bad default arch selected for a 64 bit input bfd when the
2931 default is 32 bit. Also select arch based on apuinfo. */
2934 ppc64_elf_object_p (bfd
*abfd
)
2936 if (!abfd
->arch_info
->the_default
)
2939 if (abfd
->arch_info
->bits_per_word
== 32)
2941 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2943 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2945 /* Relies on arch after 32 bit default being 64 bit default. */
2946 abfd
->arch_info
= abfd
->arch_info
->next
;
2947 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2950 return _bfd_elf_ppc_set_arch (abfd
);
2953 /* Support for core dump NOTE sections. */
2956 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2958 size_t offset
, size
;
2960 if (note
->descsz
!= 504)
2964 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2967 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2973 /* Make a ".reg/999" section. */
2974 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2975 size
, note
->descpos
+ offset
);
2979 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2981 if (note
->descsz
!= 136)
2984 elf_tdata (abfd
)->core
->pid
2985 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2986 elf_tdata (abfd
)->core
->program
2987 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2988 elf_tdata (abfd
)->core
->command
2989 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2995 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
3008 va_start (ap
, note_type
);
3009 memset (data
, 0, sizeof (data
));
3010 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
3011 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
3013 return elfcore_write_note (abfd
, buf
, bufsiz
,
3014 "CORE", note_type
, data
, sizeof (data
));
3025 va_start (ap
, note_type
);
3026 memset (data
, 0, 112);
3027 pid
= va_arg (ap
, long);
3028 bfd_put_32 (abfd
, pid
, data
+ 32);
3029 cursig
= va_arg (ap
, int);
3030 bfd_put_16 (abfd
, cursig
, data
+ 12);
3031 greg
= va_arg (ap
, const void *);
3032 memcpy (data
+ 112, greg
, 384);
3033 memset (data
+ 496, 0, 8);
3035 return elfcore_write_note (abfd
, buf
, bufsiz
,
3036 "CORE", note_type
, data
, sizeof (data
));
3041 /* Add extra PPC sections. */
3043 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
3045 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
3046 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3047 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3048 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3049 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3050 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3051 { NULL
, 0, 0, 0, 0 }
3054 enum _ppc64_sec_type
{
3060 struct _ppc64_elf_section_data
3062 struct bfd_elf_section_data elf
;
3066 /* An array with one entry for each opd function descriptor,
3067 and some spares since opd entries may be either 16 or 24 bytes. */
3068 #define OPD_NDX(OFF) ((OFF) >> 4)
3069 struct _opd_sec_data
3071 /* Points to the function code section for local opd entries. */
3072 asection
**func_sec
;
3074 /* After editing .opd, adjust references to opd local syms. */
3078 /* An array for toc sections, indexed by offset/8. */
3079 struct _toc_sec_data
3081 /* Specifies the relocation symbol index used at a given toc offset. */
3084 /* And the relocation addend. */
3089 enum _ppc64_sec_type sec_type
:2;
3091 /* Flag set when small branches are detected. Used to
3092 select suitable defaults for the stub group size. */
3093 unsigned int has_14bit_branch
:1;
3096 #define ppc64_elf_section_data(sec) \
3097 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3100 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
3102 if (!sec
->used_by_bfd
)
3104 struct _ppc64_elf_section_data
*sdata
;
3105 bfd_size_type amt
= sizeof (*sdata
);
3107 sdata
= bfd_zalloc (abfd
, amt
);
3110 sec
->used_by_bfd
= sdata
;
3113 return _bfd_elf_new_section_hook (abfd
, sec
);
3116 static struct _opd_sec_data
*
3117 get_opd_info (asection
* sec
)
3120 && ppc64_elf_section_data (sec
) != NULL
3121 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
3122 return &ppc64_elf_section_data (sec
)->u
.opd
;
3126 /* Parameters for the qsort hook. */
3127 static bfd_boolean synthetic_relocatable
;
3128 static asection
*synthetic_opd
;
3130 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3133 compare_symbols (const void *ap
, const void *bp
)
3135 const asymbol
*a
= * (const asymbol
**) ap
;
3136 const asymbol
*b
= * (const asymbol
**) bp
;
3138 /* Section symbols first. */
3139 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
3141 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
3144 /* then .opd symbols. */
3145 if (synthetic_opd
!= NULL
)
3147 if (strcmp (a
->section
->name
, ".opd") == 0
3148 && strcmp (b
->section
->name
, ".opd") != 0)
3150 if (strcmp (a
->section
->name
, ".opd") != 0
3151 && strcmp (b
->section
->name
, ".opd") == 0)
3155 /* then other code symbols. */
3156 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3157 == (SEC_CODE
| SEC_ALLOC
)
3158 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3159 != (SEC_CODE
| SEC_ALLOC
))
3162 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3163 != (SEC_CODE
| SEC_ALLOC
)
3164 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3165 == (SEC_CODE
| SEC_ALLOC
))
3168 if (synthetic_relocatable
)
3170 if (a
->section
->id
< b
->section
->id
)
3173 if (a
->section
->id
> b
->section
->id
)
3177 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
3180 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
3183 /* For syms with the same value, prefer strong dynamic global function
3184 syms over other syms. */
3185 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
3188 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
3191 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
3194 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
3197 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
3200 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
3203 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
3206 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
3212 /* Search SYMS for a symbol of the given VALUE. */
3215 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
3219 if (id
== (unsigned) -1)
3223 mid
= (lo
+ hi
) >> 1;
3224 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
3226 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
3236 mid
= (lo
+ hi
) >> 1;
3237 if (syms
[mid
]->section
->id
< id
)
3239 else if (syms
[mid
]->section
->id
> id
)
3241 else if (syms
[mid
]->value
< value
)
3243 else if (syms
[mid
]->value
> value
)
3253 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
3255 bfd_vma vma
= *(bfd_vma
*) ptr
;
3256 return ((section
->flags
& SEC_ALLOC
) != 0
3257 && section
->vma
<= vma
3258 && vma
< section
->vma
+ section
->size
);
3261 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3262 entry syms. Also generate @plt symbols for the glink branch table.
3263 Returns count of synthetic symbols in RET or -1 on error. */
3266 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
3267 long static_count
, asymbol
**static_syms
,
3268 long dyn_count
, asymbol
**dyn_syms
,
3274 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
3275 asection
*opd
= NULL
;
3276 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
3278 int abi
= abiversion (abfd
);
3284 opd
= bfd_get_section_by_name (abfd
, ".opd");
3285 if (opd
== NULL
&& abi
== 1)
3297 symcount
= static_count
;
3299 symcount
+= dyn_count
;
3303 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3307 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3309 /* Use both symbol tables. */
3310 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3311 memcpy (syms
+ static_count
, dyn_syms
,
3312 (dyn_count
+ 1) * sizeof (*syms
));
3314 else if (!relocatable
&& static_count
== 0)
3315 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3317 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3319 /* Trim uninteresting symbols. Interesting symbols are section,
3320 function, and notype symbols. */
3321 for (i
= 0, j
= 0; i
< symcount
; ++i
)
3322 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
3323 | BSF_RELC
| BSF_SRELC
)) == 0)
3324 syms
[j
++] = syms
[i
];
3327 synthetic_relocatable
= relocatable
;
3328 synthetic_opd
= opd
;
3329 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3331 if (!relocatable
&& symcount
> 1)
3333 /* Trim duplicate syms, since we may have merged the normal and
3334 dynamic symbols. Actually, we only care about syms that have
3335 different values, so trim any with the same value. */
3336 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3337 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3338 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3339 syms
[j
++] = syms
[i
];
3344 /* Note that here and in compare_symbols we can't compare opd and
3345 sym->section directly. With separate debug info files, the
3346 symbols will be extracted from the debug file while abfd passed
3347 to this function is the real binary. */
3348 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3352 for (; i
< symcount
; ++i
)
3353 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
3354 | SEC_THREAD_LOCAL
))
3355 != (SEC_CODE
| SEC_ALLOC
))
3356 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3360 for (; i
< symcount
; ++i
)
3361 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3365 for (; i
< symcount
; ++i
)
3366 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3370 for (; i
< symcount
; ++i
)
3371 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3372 != (SEC_CODE
| SEC_ALLOC
))
3380 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3385 if (opdsymend
== secsymend
)
3388 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3389 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3393 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3400 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3404 while (r
< opd
->relocation
+ relcount
3405 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3408 if (r
== opd
->relocation
+ relcount
)
3411 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3414 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3417 sym
= *r
->sym_ptr_ptr
;
3418 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3419 sym
->section
->id
, sym
->value
+ r
->addend
))
3422 size
+= sizeof (asymbol
);
3423 size
+= strlen (syms
[i
]->name
) + 2;
3429 s
= *ret
= bfd_malloc (size
);
3436 names
= (char *) (s
+ count
);
3438 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3442 while (r
< opd
->relocation
+ relcount
3443 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3446 if (r
== opd
->relocation
+ relcount
)
3449 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3452 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3455 sym
= *r
->sym_ptr_ptr
;
3456 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3457 sym
->section
->id
, sym
->value
+ r
->addend
))
3462 s
->flags
|= BSF_SYNTHETIC
;
3463 s
->section
= sym
->section
;
3464 s
->value
= sym
->value
+ r
->addend
;
3467 len
= strlen (syms
[i
]->name
);
3468 memcpy (names
, syms
[i
]->name
, len
+ 1);
3470 /* Have udata.p point back to the original symbol this
3471 synthetic symbol was derived from. */
3472 s
->udata
.p
= syms
[i
];
3479 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3480 bfd_byte
*contents
= NULL
;
3482 size_t plt_count
= 0;
3483 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3484 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3487 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3489 free_contents_and_exit_err
:
3491 free_contents_and_exit
:
3498 for (i
= secsymend
; i
< opdsymend
; ++i
)
3502 /* Ignore bogus symbols. */
3503 if (syms
[i
]->value
> opd
->size
- 8)
3506 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3507 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3510 size
+= sizeof (asymbol
);
3511 size
+= strlen (syms
[i
]->name
) + 2;
3515 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3517 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3519 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3521 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3523 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3524 goto free_contents_and_exit_err
;
3526 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3527 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3530 extdynend
= extdyn
+ dynamic
->size
;
3531 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3533 Elf_Internal_Dyn dyn
;
3534 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3536 if (dyn
.d_tag
== DT_NULL
)
3539 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3541 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
3542 See comment in ppc64_elf_finish_dynamic_sections. */
3543 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
3544 /* The .glink section usually does not survive the final
3545 link; search for the section (usually .text) where the
3546 glink stubs now reside. */
3547 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3558 /* Determine __glink trampoline by reading the relative branch
3559 from the first glink stub. */
3561 unsigned int off
= 0;
3563 while (bfd_get_section_contents (abfd
, glink
, buf
,
3564 glink_vma
+ off
- glink
->vma
, 4))
3566 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3568 if ((insn
& ~0x3fffffc) == 0)
3570 resolv_vma
= glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
3579 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3581 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3584 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3585 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3586 goto free_contents_and_exit_err
;
3588 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3589 size
+= plt_count
* sizeof (asymbol
);
3591 p
= relplt
->relocation
;
3592 for (i
= 0; i
< plt_count
; i
++, p
++)
3594 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3596 size
+= sizeof ("+0x") - 1 + 16;
3602 goto free_contents_and_exit
;
3603 s
= *ret
= bfd_malloc (size
);
3605 goto free_contents_and_exit_err
;
3607 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3609 for (i
= secsymend
; i
< opdsymend
; ++i
)
3613 if (syms
[i
]->value
> opd
->size
- 8)
3616 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3617 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3621 asection
*sec
= abfd
->sections
;
3628 size_t mid
= (lo
+ hi
) >> 1;
3629 if (syms
[mid
]->section
->vma
< ent
)
3631 else if (syms
[mid
]->section
->vma
> ent
)
3635 sec
= syms
[mid
]->section
;
3640 if (lo
>= hi
&& lo
> codesecsym
)
3641 sec
= syms
[lo
- 1]->section
;
3643 for (; sec
!= NULL
; sec
= sec
->next
)
3647 /* SEC_LOAD may not be set if SEC is from a separate debug
3649 if ((sec
->flags
& SEC_ALLOC
) == 0)
3651 if ((sec
->flags
& SEC_CODE
) != 0)
3654 s
->flags
|= BSF_SYNTHETIC
;
3655 s
->value
= ent
- s
->section
->vma
;
3658 len
= strlen (syms
[i
]->name
);
3659 memcpy (names
, syms
[i
]->name
, len
+ 1);
3661 /* Have udata.p point back to the original symbol this
3662 synthetic symbol was derived from. */
3663 s
->udata
.p
= syms
[i
];
3669 if (glink
!= NULL
&& relplt
!= NULL
)
3673 /* Add a symbol for the main glink trampoline. */
3674 memset (s
, 0, sizeof *s
);
3676 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3678 s
->value
= resolv_vma
- glink
->vma
;
3680 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3681 names
+= sizeof ("__glink_PLTresolve");
3686 /* FIXME: It would be very much nicer to put sym@plt on the
3687 stub rather than on the glink branch table entry. The
3688 objdump disassembler would then use a sensible symbol
3689 name on plt calls. The difficulty in doing so is
3690 a) finding the stubs, and,
3691 b) matching stubs against plt entries, and,
3692 c) there can be multiple stubs for a given plt entry.
3694 Solving (a) could be done by code scanning, but older
3695 ppc64 binaries used different stubs to current code.
3696 (b) is the tricky one since you need to known the toc
3697 pointer for at least one function that uses a pic stub to
3698 be able to calculate the plt address referenced.
3699 (c) means gdb would need to set multiple breakpoints (or
3700 find the glink branch itself) when setting breakpoints
3701 for pending shared library loads. */
3702 p
= relplt
->relocation
;
3703 for (i
= 0; i
< plt_count
; i
++, p
++)
3707 *s
= **p
->sym_ptr_ptr
;
3708 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3709 we are defining a symbol, ensure one of them is set. */
3710 if ((s
->flags
& BSF_LOCAL
) == 0)
3711 s
->flags
|= BSF_GLOBAL
;
3712 s
->flags
|= BSF_SYNTHETIC
;
3714 s
->value
= glink_vma
- glink
->vma
;
3717 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3718 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3722 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3723 names
+= sizeof ("+0x") - 1;
3724 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3725 names
+= strlen (names
);
3727 memcpy (names
, "@plt", sizeof ("@plt"));
3728 names
+= sizeof ("@plt");
3748 /* The following functions are specific to the ELF linker, while
3749 functions above are used generally. Those named ppc64_elf_* are
3750 called by the main ELF linker code. They appear in this file more
3751 or less in the order in which they are called. eg.
3752 ppc64_elf_check_relocs is called early in the link process,
3753 ppc64_elf_finish_dynamic_sections is one of the last functions
3756 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3757 functions have both a function code symbol and a function descriptor
3758 symbol. A call to foo in a relocatable object file looks like:
3765 The function definition in another object file might be:
3769 . .quad .TOC.@tocbase
3775 When the linker resolves the call during a static link, the branch
3776 unsurprisingly just goes to .foo and the .opd information is unused.
3777 If the function definition is in a shared library, things are a little
3778 different: The call goes via a plt call stub, the opd information gets
3779 copied to the plt, and the linker patches the nop.
3787 . std 2,40(1) # in practice, the call stub
3788 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3789 . addi 11,11,Lfoo@toc@l # this is the general idea
3797 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3799 The "reloc ()" notation is supposed to indicate that the linker emits
3800 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3803 What are the difficulties here? Well, firstly, the relocations
3804 examined by the linker in check_relocs are against the function code
3805 sym .foo, while the dynamic relocation in the plt is emitted against
3806 the function descriptor symbol, foo. Somewhere along the line, we need
3807 to carefully copy dynamic link information from one symbol to the other.
3808 Secondly, the generic part of the elf linker will make .foo a dynamic
3809 symbol as is normal for most other backends. We need foo dynamic
3810 instead, at least for an application final link. However, when
3811 creating a shared library containing foo, we need to have both symbols
3812 dynamic so that references to .foo are satisfied during the early
3813 stages of linking. Otherwise the linker might decide to pull in a
3814 definition from some other object, eg. a static library.
3816 Update: As of August 2004, we support a new convention. Function
3817 calls may use the function descriptor symbol, ie. "bl foo". This
3818 behaves exactly as "bl .foo". */
3820 /* Of those relocs that might be copied as dynamic relocs, this
3821 function selects those that must be copied when linking a shared
3822 library or PIE, even when the symbol is local. */
3825 must_be_dyn_reloc (struct bfd_link_info
*info
,
3826 enum elf_ppc64_reloc_type r_type
)
3831 /* Only relative relocs can be resolved when the object load
3832 address isn't fixed. DTPREL64 is excluded because the
3833 dynamic linker needs to differentiate global dynamic from
3834 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
3842 case R_PPC64_TPREL16
:
3843 case R_PPC64_TPREL16_LO
:
3844 case R_PPC64_TPREL16_HI
:
3845 case R_PPC64_TPREL16_HA
:
3846 case R_PPC64_TPREL16_DS
:
3847 case R_PPC64_TPREL16_LO_DS
:
3848 case R_PPC64_TPREL16_HIGH
:
3849 case R_PPC64_TPREL16_HIGHA
:
3850 case R_PPC64_TPREL16_HIGHER
:
3851 case R_PPC64_TPREL16_HIGHERA
:
3852 case R_PPC64_TPREL16_HIGHEST
:
3853 case R_PPC64_TPREL16_HIGHESTA
:
3854 case R_PPC64_TPREL64
:
3855 /* These relocations are relative but in a shared library the
3856 linker doesn't know the thread pointer base. */
3857 return bfd_link_dll (info
);
3861 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3862 copying dynamic variables from a shared lib into an app's dynbss
3863 section, and instead use a dynamic relocation to point into the
3864 shared lib. With code that gcc generates, it's vital that this be
3865 enabled; In the PowerPC64 ABI, the address of a function is actually
3866 the address of a function descriptor, which resides in the .opd
3867 section. gcc uses the descriptor directly rather than going via the
3868 GOT as some other ABI's do, which means that initialized function
3869 pointers must reference the descriptor. Thus, a function pointer
3870 initialized to the address of a function in a shared library will
3871 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3872 redefines the function descriptor symbol to point to the copy. This
3873 presents a problem as a plt entry for that function is also
3874 initialized from the function descriptor symbol and the copy reloc
3875 may not be initialized first. */
3876 #define ELIMINATE_COPY_RELOCS 1
3878 /* Section name for stubs is the associated section name plus this
3880 #define STUB_SUFFIX ".stub"
3883 ppc_stub_long_branch:
3884 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3885 destination, but a 24 bit branch in a stub section will reach.
3888 ppc_stub_plt_branch:
3889 Similar to the above, but a 24 bit branch in the stub section won't
3890 reach its destination.
3891 . addis %r11,%r2,xxx@toc@ha
3892 . ld %r12,xxx@toc@l(%r11)
3897 Used to call a function in a shared library. If it so happens that
3898 the plt entry referenced crosses a 64k boundary, then an extra
3899 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3901 . addis %r11,%r2,xxx@toc@ha
3902 . ld %r12,xxx+0@toc@l(%r11)
3904 . ld %r2,xxx+8@toc@l(%r11)
3905 . ld %r11,xxx+16@toc@l(%r11)
3908 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3909 code to adjust the value and save r2 to support multiple toc sections.
3910 A ppc_stub_long_branch with an r2 offset looks like:
3912 . addis %r2,%r2,off@ha
3913 . addi %r2,%r2,off@l
3916 A ppc_stub_plt_branch with an r2 offset looks like:
3918 . addis %r11,%r2,xxx@toc@ha
3919 . ld %r12,xxx@toc@l(%r11)
3920 . addis %r2,%r2,off@ha
3921 . addi %r2,%r2,off@l
3925 In cases where the "addis" instruction would add zero, the "addis" is
3926 omitted and following instructions modified slightly in some cases.
3929 enum ppc_stub_type
{
3931 ppc_stub_long_branch
,
3932 ppc_stub_long_branch_r2off
,
3933 ppc_stub_plt_branch
,
3934 ppc_stub_plt_branch_r2off
,
3936 ppc_stub_plt_call_r2save
,
3937 ppc_stub_global_entry
,
3941 /* Information on stub grouping. */
3944 /* The stub section. */
3946 /* This is the section to which stubs in the group will be attached. */
3949 struct map_stub
*next
;
3950 /* Whether to emit a copy of register save/restore functions in this
3953 /* The offset of the __tls_get_addr_opt plt stub bctrl in this group,
3954 or -1u if no such stub with bctrl exists. */
3955 unsigned int tls_get_addr_opt_bctrl
;
3958 struct ppc_stub_hash_entry
{
3960 /* Base hash table entry structure. */
3961 struct bfd_hash_entry root
;
3963 enum ppc_stub_type stub_type
;
3965 /* Group information. */
3966 struct map_stub
*group
;
3968 /* Offset within stub_sec of the beginning of this stub. */
3969 bfd_vma stub_offset
;
3971 /* Given the symbol's value and its section we can determine its final
3972 value when building the stubs (so the stub knows where to jump. */
3973 bfd_vma target_value
;
3974 asection
*target_section
;
3976 /* The symbol table entry, if any, that this was derived from. */
3977 struct ppc_link_hash_entry
*h
;
3978 struct plt_entry
*plt_ent
;
3980 /* Symbol st_other. */
3981 unsigned char other
;
3984 struct ppc_branch_hash_entry
{
3986 /* Base hash table entry structure. */
3987 struct bfd_hash_entry root
;
3989 /* Offset within branch lookup table. */
3990 unsigned int offset
;
3992 /* Generation marker. */
3996 /* Used to track dynamic relocations for local symbols. */
3997 struct ppc_dyn_relocs
3999 struct ppc_dyn_relocs
*next
;
4001 /* The input section of the reloc. */
4004 /* Total number of relocs copied for the input section. */
4005 unsigned int count
: 31;
4007 /* Whether this entry is for STT_GNU_IFUNC symbols. */
4008 unsigned int ifunc
: 1;
4011 struct ppc_link_hash_entry
4013 struct elf_link_hash_entry elf
;
4016 /* A pointer to the most recently used stub hash entry against this
4018 struct ppc_stub_hash_entry
*stub_cache
;
4020 /* A pointer to the next symbol starting with a '.' */
4021 struct ppc_link_hash_entry
*next_dot_sym
;
4024 /* Track dynamic relocs copied for this symbol. */
4025 struct elf_dyn_relocs
*dyn_relocs
;
4027 /* Link between function code and descriptor symbols. */
4028 struct ppc_link_hash_entry
*oh
;
4030 /* Flag function code and descriptor symbols. */
4031 unsigned int is_func
:1;
4032 unsigned int is_func_descriptor
:1;
4033 unsigned int fake
:1;
4035 /* Whether global opd/toc sym has been adjusted or not.
4036 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
4037 should be set for all globals defined in any opd/toc section. */
4038 unsigned int adjust_done
:1;
4040 /* Set if this is an out-of-line register save/restore function,
4041 with non-standard calling convention. */
4042 unsigned int save_res
:1;
4044 /* Set if a duplicate symbol with non-zero localentry is detected,
4045 even when the duplicate symbol does not provide a definition. */
4046 unsigned int non_zero_localentry
:1;
4048 /* Contexts in which symbol is used in the GOT (or TOC).
4049 Bits are or'd into the mask as the corresponding relocs are
4050 encountered during check_relocs, with TLS_TLS being set when any
4051 of the other TLS bits are set. tls_optimize clears bits when
4052 optimizing to indicate the corresponding GOT entry type is not
4053 needed. If set, TLS_TLS is never cleared. tls_optimize may also
4054 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
4055 separate flag rather than setting TPREL just for convenience in
4056 distinguishing the two cases.
4057 These flags are also kept for local symbols. */
4058 #define TLS_TLS 1 /* Any TLS reloc. */
4059 #define TLS_GD 2 /* GD reloc. */
4060 #define TLS_LD 4 /* LD reloc. */
4061 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
4062 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
4063 #define TLS_MARK 32 /* __tls_get_addr call marked. */
4064 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4065 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
4066 unsigned char tls_mask
;
4068 /* The above field is also used to mark function symbols. In which
4069 case TLS_TLS will be 0. */
4070 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
4071 #define NON_GOT 256 /* local symbol plt, not stored. */
4074 /* ppc64 ELF linker hash table. */
4076 struct ppc_link_hash_table
4078 struct elf_link_hash_table elf
;
4080 /* The stub hash table. */
4081 struct bfd_hash_table stub_hash_table
;
4083 /* Another hash table for plt_branch stubs. */
4084 struct bfd_hash_table branch_hash_table
;
4086 /* Hash table for function prologue tocsave. */
4087 htab_t tocsave_htab
;
4089 /* Various options and other info passed from the linker. */
4090 struct ppc64_elf_params
*params
;
4092 /* The size of sec_info below. */
4093 unsigned int sec_info_arr_size
;
4095 /* Per-section array of extra section info. Done this way rather
4096 than as part of ppc64_elf_section_data so we have the info for
4097 non-ppc64 sections. */
4100 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4105 /* The section group that this section belongs to. */
4106 struct map_stub
*group
;
4107 /* A temp section list pointer. */
4112 /* Linked list of groups. */
4113 struct map_stub
*group
;
4115 /* Temp used when calculating TOC pointers. */
4118 asection
*toc_first_sec
;
4120 /* Used when adding symbols. */
4121 struct ppc_link_hash_entry
*dot_syms
;
4123 /* Shortcuts to get to dynamic linker sections. */
4125 asection
*global_entry
;
4129 asection
*glink_eh_frame
;
4131 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4132 struct ppc_link_hash_entry
*tls_get_addr
;
4133 struct ppc_link_hash_entry
*tls_get_addr_fd
;
4135 /* The size of reliplt used by got entry relocs. */
4136 bfd_size_type got_reli_size
;
4139 unsigned long stub_count
[ppc_stub_global_entry
];
4141 /* Number of stubs against global syms. */
4142 unsigned long stub_globals
;
4144 /* Set if we're linking code with function descriptors. */
4145 unsigned int opd_abi
:1;
4147 /* Support for multiple toc sections. */
4148 unsigned int do_multi_toc
:1;
4149 unsigned int multi_toc_needed
:1;
4150 unsigned int second_toc_pass
:1;
4151 unsigned int do_toc_opt
:1;
4153 /* Set if tls optimization is enabled. */
4154 unsigned int do_tls_opt
:1;
4157 unsigned int stub_error
:1;
4159 /* Whether func_desc_adjust needs to be run over symbols. */
4160 unsigned int need_func_desc_adj
:1;
4162 /* Whether there exist local gnu indirect function resolvers,
4163 referenced by dynamic relocations. */
4164 unsigned int local_ifunc_resolver
:1;
4165 unsigned int maybe_local_ifunc_resolver
:1;
4167 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
4168 unsigned int has_plt_localentry0
:1;
4170 /* Incremented every time we size stubs. */
4171 unsigned int stub_iteration
;
4173 /* Small local sym cache. */
4174 struct sym_cache sym_cache
;
4177 /* Rename some of the generic section flags to better document how they
4180 /* Nonzero if this section has TLS related relocations. */
4181 #define has_tls_reloc sec_flg0
4183 /* Nonzero if this section has a call to __tls_get_addr. */
4184 #define has_tls_get_addr_call sec_flg1
4186 /* Nonzero if this section has any toc or got relocs. */
4187 #define has_toc_reloc sec_flg2
4189 /* Nonzero if this section has a call to another section that uses
4191 #define makes_toc_func_call sec_flg3
4193 /* Recursion protection when determining above flag. */
4194 #define call_check_in_progress sec_flg4
4195 #define call_check_done sec_flg5
4197 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4199 #define ppc_hash_table(p) \
4200 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4201 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4203 #define ppc_stub_hash_lookup(table, string, create, copy) \
4204 ((struct ppc_stub_hash_entry *) \
4205 bfd_hash_lookup ((table), (string), (create), (copy)))
4207 #define ppc_branch_hash_lookup(table, string, create, copy) \
4208 ((struct ppc_branch_hash_entry *) \
4209 bfd_hash_lookup ((table), (string), (create), (copy)))
4211 /* Create an entry in the stub hash table. */
4213 static struct bfd_hash_entry
*
4214 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
4215 struct bfd_hash_table
*table
,
4218 /* Allocate the structure if it has not already been allocated by a
4222 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
4227 /* Call the allocation method of the superclass. */
4228 entry
= bfd_hash_newfunc (entry
, table
, string
);
4231 struct ppc_stub_hash_entry
*eh
;
4233 /* Initialize the local fields. */
4234 eh
= (struct ppc_stub_hash_entry
*) entry
;
4235 eh
->stub_type
= ppc_stub_none
;
4237 eh
->stub_offset
= 0;
4238 eh
->target_value
= 0;
4239 eh
->target_section
= NULL
;
4248 /* Create an entry in the branch hash table. */
4250 static struct bfd_hash_entry
*
4251 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
4252 struct bfd_hash_table
*table
,
4255 /* Allocate the structure if it has not already been allocated by a
4259 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
4264 /* Call the allocation method of the superclass. */
4265 entry
= bfd_hash_newfunc (entry
, table
, string
);
4268 struct ppc_branch_hash_entry
*eh
;
4270 /* Initialize the local fields. */
4271 eh
= (struct ppc_branch_hash_entry
*) entry
;
4279 /* Create an entry in a ppc64 ELF linker hash table. */
4281 static struct bfd_hash_entry
*
4282 link_hash_newfunc (struct bfd_hash_entry
*entry
,
4283 struct bfd_hash_table
*table
,
4286 /* Allocate the structure if it has not already been allocated by a
4290 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
4295 /* Call the allocation method of the superclass. */
4296 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
4299 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
4301 memset (&eh
->u
.stub_cache
, 0,
4302 (sizeof (struct ppc_link_hash_entry
)
4303 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
4305 /* When making function calls, old ABI code references function entry
4306 points (dot symbols), while new ABI code references the function
4307 descriptor symbol. We need to make any combination of reference and
4308 definition work together, without breaking archive linking.
4310 For a defined function "foo" and an undefined call to "bar":
4311 An old object defines "foo" and ".foo", references ".bar" (possibly
4313 A new object defines "foo" and references "bar".
4315 A new object thus has no problem with its undefined symbols being
4316 satisfied by definitions in an old object. On the other hand, the
4317 old object won't have ".bar" satisfied by a new object.
4319 Keep a list of newly added dot-symbols. */
4321 if (string
[0] == '.')
4323 struct ppc_link_hash_table
*htab
;
4325 htab
= (struct ppc_link_hash_table
*) table
;
4326 eh
->u
.next_dot_sym
= htab
->dot_syms
;
4327 htab
->dot_syms
= eh
;
4334 struct tocsave_entry
{
4340 tocsave_htab_hash (const void *p
)
4342 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
4343 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
4347 tocsave_htab_eq (const void *p1
, const void *p2
)
4349 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
4350 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
4351 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
4354 /* Destroy a ppc64 ELF linker hash table. */
4357 ppc64_elf_link_hash_table_free (bfd
*obfd
)
4359 struct ppc_link_hash_table
*htab
;
4361 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
4362 if (htab
->tocsave_htab
)
4363 htab_delete (htab
->tocsave_htab
);
4364 bfd_hash_table_free (&htab
->branch_hash_table
);
4365 bfd_hash_table_free (&htab
->stub_hash_table
);
4366 _bfd_elf_link_hash_table_free (obfd
);
4369 /* Create a ppc64 ELF linker hash table. */
4371 static struct bfd_link_hash_table
*
4372 ppc64_elf_link_hash_table_create (bfd
*abfd
)
4374 struct ppc_link_hash_table
*htab
;
4375 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
4377 htab
= bfd_zmalloc (amt
);
4381 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
4382 sizeof (struct ppc_link_hash_entry
),
4389 /* Init the stub hash table too. */
4390 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
4391 sizeof (struct ppc_stub_hash_entry
)))
4393 _bfd_elf_link_hash_table_free (abfd
);
4397 /* And the branch hash table. */
4398 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
4399 sizeof (struct ppc_branch_hash_entry
)))
4401 bfd_hash_table_free (&htab
->stub_hash_table
);
4402 _bfd_elf_link_hash_table_free (abfd
);
4406 htab
->tocsave_htab
= htab_try_create (1024,
4410 if (htab
->tocsave_htab
== NULL
)
4412 ppc64_elf_link_hash_table_free (abfd
);
4415 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
4417 /* Initializing two fields of the union is just cosmetic. We really
4418 only care about glist, but when compiled on a 32-bit host the
4419 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4420 debugger inspection of these fields look nicer. */
4421 htab
->elf
.init_got_refcount
.refcount
= 0;
4422 htab
->elf
.init_got_refcount
.glist
= NULL
;
4423 htab
->elf
.init_plt_refcount
.refcount
= 0;
4424 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4425 htab
->elf
.init_got_offset
.offset
= 0;
4426 htab
->elf
.init_got_offset
.glist
= NULL
;
4427 htab
->elf
.init_plt_offset
.offset
= 0;
4428 htab
->elf
.init_plt_offset
.glist
= NULL
;
4430 return &htab
->elf
.root
;
4433 /* Create sections for linker generated code. */
4436 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4438 struct ppc_link_hash_table
*htab
;
4441 htab
= ppc_hash_table (info
);
4443 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4444 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4445 if (htab
->params
->save_restore_funcs
)
4447 /* Create .sfpr for code to save and restore fp regs. */
4448 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4450 if (htab
->sfpr
== NULL
4451 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4455 if (bfd_link_relocatable (info
))
4458 /* Create .glink for lazy dynamic linking support. */
4459 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4461 if (htab
->glink
== NULL
4462 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4465 /* The part of .glink used by global entry stubs, separate so that
4466 it can be aligned appropriately without affecting htab->glink. */
4467 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4469 if (htab
->global_entry
== NULL
4470 || ! bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
4473 if (!info
->no_ld_generated_unwind_info
)
4475 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4476 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4477 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4480 if (htab
->glink_eh_frame
== NULL
4481 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
4485 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4486 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4487 if (htab
->elf
.iplt
== NULL
4488 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
4491 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4492 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4494 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
4495 if (htab
->elf
.irelplt
== NULL
4496 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
4499 /* Create branch lookup table for plt_branch stubs. */
4500 flags
= (SEC_ALLOC
| SEC_LOAD
4501 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4502 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4504 if (htab
->brlt
== NULL
4505 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4508 if (!bfd_link_pic (info
))
4511 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4512 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4513 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4516 if (htab
->relbrlt
== NULL
4517 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4523 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4526 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
4527 struct ppc64_elf_params
*params
)
4529 struct ppc_link_hash_table
*htab
;
4531 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4533 /* Always hook our dynamic sections into the first bfd, which is the
4534 linker created stub bfd. This ensures that the GOT header is at
4535 the start of the output TOC section. */
4536 htab
= ppc_hash_table (info
);
4537 htab
->elf
.dynobj
= params
->stub_bfd
;
4538 htab
->params
= params
;
4540 return create_linkage_sections (htab
->elf
.dynobj
, info
);
4543 /* Build a name for an entry in the stub hash table. */
4546 ppc_stub_name (const asection
*input_section
,
4547 const asection
*sym_sec
,
4548 const struct ppc_link_hash_entry
*h
,
4549 const Elf_Internal_Rela
*rel
)
4554 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4555 offsets from a sym as a branch target? In fact, we could
4556 probably assume the addend is always zero. */
4557 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4561 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4562 stub_name
= bfd_malloc (len
);
4563 if (stub_name
== NULL
)
4566 len
= sprintf (stub_name
, "%08x.%s+%x",
4567 input_section
->id
& 0xffffffff,
4568 h
->elf
.root
.root
.string
,
4569 (int) rel
->r_addend
& 0xffffffff);
4573 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4574 stub_name
= bfd_malloc (len
);
4575 if (stub_name
== NULL
)
4578 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
4579 input_section
->id
& 0xffffffff,
4580 sym_sec
->id
& 0xffffffff,
4581 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4582 (int) rel
->r_addend
& 0xffffffff);
4584 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4585 stub_name
[len
- 2] = 0;
4589 /* Look up an entry in the stub hash. Stub entries are cached because
4590 creating the stub name takes a bit of time. */
4592 static struct ppc_stub_hash_entry
*
4593 ppc_get_stub_entry (const asection
*input_section
,
4594 const asection
*sym_sec
,
4595 struct ppc_link_hash_entry
*h
,
4596 const Elf_Internal_Rela
*rel
,
4597 struct ppc_link_hash_table
*htab
)
4599 struct ppc_stub_hash_entry
*stub_entry
;
4600 struct map_stub
*group
;
4602 /* If this input section is part of a group of sections sharing one
4603 stub section, then use the id of the first section in the group.
4604 Stub names need to include a section id, as there may well be
4605 more than one stub used to reach say, printf, and we need to
4606 distinguish between them. */
4607 group
= htab
->sec_info
[input_section
->id
].u
.group
;
4611 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4612 && h
->u
.stub_cache
->h
== h
4613 && h
->u
.stub_cache
->group
== group
)
4615 stub_entry
= h
->u
.stub_cache
;
4621 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
4622 if (stub_name
== NULL
)
4625 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4626 stub_name
, FALSE
, FALSE
);
4628 h
->u
.stub_cache
= stub_entry
;
4636 /* Add a new stub entry to the stub hash. Not all fields of the new
4637 stub entry are initialised. */
4639 static struct ppc_stub_hash_entry
*
4640 ppc_add_stub (const char *stub_name
,
4642 struct bfd_link_info
*info
)
4644 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4645 struct map_stub
*group
;
4648 struct ppc_stub_hash_entry
*stub_entry
;
4650 group
= htab
->sec_info
[section
->id
].u
.group
;
4651 link_sec
= group
->link_sec
;
4652 stub_sec
= group
->stub_sec
;
4653 if (stub_sec
== NULL
)
4659 namelen
= strlen (link_sec
->name
);
4660 len
= namelen
+ sizeof (STUB_SUFFIX
);
4661 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
4665 memcpy (s_name
, link_sec
->name
, namelen
);
4666 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4667 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
4668 if (stub_sec
== NULL
)
4670 group
->stub_sec
= stub_sec
;
4673 /* Enter this entry into the linker stub hash table. */
4674 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4676 if (stub_entry
== NULL
)
4678 /* xgettext:c-format */
4679 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
4680 section
->owner
, stub_name
);
4684 stub_entry
->group
= group
;
4685 stub_entry
->stub_offset
= 0;
4689 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4690 not already done. */
4693 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4695 asection
*got
, *relgot
;
4697 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4699 if (!is_ppc64_elf (abfd
))
4705 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4708 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4709 | SEC_LINKER_CREATED
);
4711 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4713 || !bfd_set_section_alignment (abfd
, got
, 3))
4716 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4717 flags
| SEC_READONLY
);
4719 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4722 ppc64_elf_tdata (abfd
)->got
= got
;
4723 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4727 /* Follow indirect and warning symbol links. */
4729 static inline struct bfd_link_hash_entry
*
4730 follow_link (struct bfd_link_hash_entry
*h
)
4732 while (h
->type
== bfd_link_hash_indirect
4733 || h
->type
== bfd_link_hash_warning
)
4738 static inline struct elf_link_hash_entry
*
4739 elf_follow_link (struct elf_link_hash_entry
*h
)
4741 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4744 static inline struct ppc_link_hash_entry
*
4745 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4747 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4750 /* Merge PLT info on FROM with that on TO. */
4753 move_plt_plist (struct ppc_link_hash_entry
*from
,
4754 struct ppc_link_hash_entry
*to
)
4756 if (from
->elf
.plt
.plist
!= NULL
)
4758 if (to
->elf
.plt
.plist
!= NULL
)
4760 struct plt_entry
**entp
;
4761 struct plt_entry
*ent
;
4763 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4765 struct plt_entry
*dent
;
4767 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4768 if (dent
->addend
== ent
->addend
)
4770 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4777 *entp
= to
->elf
.plt
.plist
;
4780 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4781 from
->elf
.plt
.plist
= NULL
;
4785 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4788 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4789 struct elf_link_hash_entry
*dir
,
4790 struct elf_link_hash_entry
*ind
)
4792 struct ppc_link_hash_entry
*edir
, *eind
;
4794 edir
= (struct ppc_link_hash_entry
*) dir
;
4795 eind
= (struct ppc_link_hash_entry
*) ind
;
4797 edir
->is_func
|= eind
->is_func
;
4798 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4799 edir
->tls_mask
|= eind
->tls_mask
;
4800 if (eind
->oh
!= NULL
)
4801 edir
->oh
= ppc_follow_link (eind
->oh
);
4803 if (edir
->elf
.versioned
!= versioned_hidden
)
4804 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4805 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4806 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4807 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4808 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4809 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4811 /* If we were called to copy over info for a weak sym, don't copy
4812 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4813 in order to simplify readonly_dynrelocs and save a field in the
4814 symbol hash entry, but that means dyn_relocs can't be used in any
4815 tests about a specific symbol, or affect other symbol flags which
4817 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4820 /* Copy over any dynamic relocs we may have on the indirect sym. */
4821 if (eind
->dyn_relocs
!= NULL
)
4823 if (edir
->dyn_relocs
!= NULL
)
4825 struct elf_dyn_relocs
**pp
;
4826 struct elf_dyn_relocs
*p
;
4828 /* Add reloc counts against the indirect sym to the direct sym
4829 list. Merge any entries against the same section. */
4830 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4832 struct elf_dyn_relocs
*q
;
4834 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4835 if (q
->sec
== p
->sec
)
4837 q
->pc_count
+= p
->pc_count
;
4838 q
->count
+= p
->count
;
4845 *pp
= edir
->dyn_relocs
;
4848 edir
->dyn_relocs
= eind
->dyn_relocs
;
4849 eind
->dyn_relocs
= NULL
;
4852 /* Copy over got entries that we may have already seen to the
4853 symbol which just became indirect. */
4854 if (eind
->elf
.got
.glist
!= NULL
)
4856 if (edir
->elf
.got
.glist
!= NULL
)
4858 struct got_entry
**entp
;
4859 struct got_entry
*ent
;
4861 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4863 struct got_entry
*dent
;
4865 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4866 if (dent
->addend
== ent
->addend
4867 && dent
->owner
== ent
->owner
4868 && dent
->tls_type
== ent
->tls_type
)
4870 dent
->got
.refcount
+= ent
->got
.refcount
;
4877 *entp
= edir
->elf
.got
.glist
;
4880 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4881 eind
->elf
.got
.glist
= NULL
;
4884 /* And plt entries. */
4885 move_plt_plist (eind
, edir
);
4887 if (eind
->elf
.dynindx
!= -1)
4889 if (edir
->elf
.dynindx
!= -1)
4890 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4891 edir
->elf
.dynstr_index
);
4892 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4893 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4894 eind
->elf
.dynindx
= -1;
4895 eind
->elf
.dynstr_index
= 0;
4899 /* Find the function descriptor hash entry from the given function code
4900 hash entry FH. Link the entries via their OH fields. */
4902 static struct ppc_link_hash_entry
*
4903 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4905 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4909 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4911 fdh
= (struct ppc_link_hash_entry
*)
4912 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4916 fdh
->is_func_descriptor
= 1;
4922 fdh
= ppc_follow_link (fdh
);
4923 fdh
->is_func_descriptor
= 1;
4928 /* Make a fake function descriptor sym for the undefined code sym FH. */
4930 static struct ppc_link_hash_entry
*
4931 make_fdh (struct bfd_link_info
*info
,
4932 struct ppc_link_hash_entry
*fh
)
4934 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4935 struct bfd_link_hash_entry
*bh
= NULL
;
4936 struct ppc_link_hash_entry
*fdh
;
4937 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4941 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4942 fh
->elf
.root
.root
.string
+ 1,
4943 flags
, bfd_und_section_ptr
, 0,
4944 NULL
, FALSE
, FALSE
, &bh
))
4947 fdh
= (struct ppc_link_hash_entry
*) bh
;
4948 fdh
->elf
.non_elf
= 0;
4950 fdh
->is_func_descriptor
= 1;
4957 /* Fix function descriptor symbols defined in .opd sections to be
4961 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4962 struct bfd_link_info
*info
,
4963 Elf_Internal_Sym
*isym
,
4965 flagword
*flags ATTRIBUTE_UNUSED
,
4969 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4970 && (ibfd
->flags
& DYNAMIC
) == 0
4971 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
4972 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
4975 && strcmp ((*sec
)->name
, ".opd") == 0)
4979 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4980 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4981 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4983 /* If the symbol is a function defined in .opd, and the function
4984 code is in a discarded group, let it appear to be undefined. */
4985 if (!bfd_link_relocatable (info
)
4986 && (*sec
)->reloc_count
!= 0
4987 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4988 FALSE
) != (bfd_vma
) -1
4989 && discarded_section (code_sec
))
4991 *sec
= bfd_und_section_ptr
;
4992 isym
->st_shndx
= SHN_UNDEF
;
4995 else if (*sec
!= NULL
4996 && strcmp ((*sec
)->name
, ".toc") == 0
4997 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4999 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5001 htab
->params
->object_in_toc
= 1;
5004 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5006 if (abiversion (ibfd
) == 0)
5007 set_abiversion (ibfd
, 2);
5008 else if (abiversion (ibfd
) == 1)
5010 _bfd_error_handler (_("symbol '%s' has invalid st_other"
5011 " for ABI version 1"), *name
);
5012 bfd_set_error (bfd_error_bad_value
);
5020 /* Merge non-visibility st_other attributes: local entry point. */
5023 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
5024 const Elf_Internal_Sym
*isym
,
5025 bfd_boolean definition
,
5026 bfd_boolean dynamic
)
5028 if (definition
&& (!dynamic
|| !h
->def_regular
))
5029 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
5030 | ELF_ST_VISIBILITY (h
->other
));
5033 /* Hook called on merging a symbol. We use this to clear "fake" since
5034 we now have a real symbol. */
5037 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
5038 const Elf_Internal_Sym
*isym
,
5039 asection
**psec ATTRIBUTE_UNUSED
,
5040 bfd_boolean newdef ATTRIBUTE_UNUSED
,
5041 bfd_boolean olddef ATTRIBUTE_UNUSED
,
5042 bfd
*oldbfd ATTRIBUTE_UNUSED
,
5043 const asection
*oldsec ATTRIBUTE_UNUSED
)
5045 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
5046 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5047 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
5051 /* This function makes an old ABI object reference to ".bar" cause the
5052 inclusion of a new ABI object archive that defines "bar".
5053 NAME is a symbol defined in an archive. Return a symbol in the hash
5054 table that might be satisfied by the archive symbols. */
5056 static struct elf_link_hash_entry
*
5057 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
5058 struct bfd_link_info
*info
,
5061 struct elf_link_hash_entry
*h
;
5065 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
5067 /* Don't return this sym if it is a fake function descriptor
5068 created by add_symbol_adjust. */
5069 && !((struct ppc_link_hash_entry
*) h
)->fake
)
5075 len
= strlen (name
);
5076 dot_name
= bfd_alloc (abfd
, len
+ 2);
5077 if (dot_name
== NULL
)
5078 return (struct elf_link_hash_entry
*) -1;
5080 memcpy (dot_name
+ 1, name
, len
+ 1);
5081 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
5082 bfd_release (abfd
, dot_name
);
5086 /* This function satisfies all old ABI object references to ".bar" if a
5087 new ABI object defines "bar". Well, at least, undefined dot symbols
5088 are made weak. This stops later archive searches from including an
5089 object if we already have a function descriptor definition. It also
5090 prevents the linker complaining about undefined symbols.
5091 We also check and correct mismatched symbol visibility here. The
5092 most restrictive visibility of the function descriptor and the
5093 function entry symbol is used. */
5096 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
5098 struct ppc_link_hash_table
*htab
;
5099 struct ppc_link_hash_entry
*fdh
;
5101 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5102 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5104 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
5107 if (eh
->elf
.root
.root
.string
[0] != '.')
5110 htab
= ppc_hash_table (info
);
5114 fdh
= lookup_fdh (eh
, htab
);
5116 && !bfd_link_relocatable (info
)
5117 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
5118 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5119 && eh
->elf
.ref_regular
)
5121 /* Make an undefined function descriptor sym, in order to
5122 pull in an --as-needed shared lib. Archives are handled
5124 fdh
= make_fdh (info
, eh
);
5131 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
5132 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
5134 /* Make both descriptor and entry symbol have the most
5135 constraining visibility of either symbol. */
5136 if (entry_vis
< descr_vis
)
5137 fdh
->elf
.other
+= entry_vis
- descr_vis
;
5138 else if (entry_vis
> descr_vis
)
5139 eh
->elf
.other
+= descr_vis
- entry_vis
;
5141 /* Propagate reference flags from entry symbol to function
5142 descriptor symbol. */
5143 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
5144 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
5145 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
5146 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
5148 if (!fdh
->elf
.forced_local
5149 && fdh
->elf
.dynindx
== -1
5150 && fdh
->elf
.versioned
!= versioned_hidden
5151 && (bfd_link_dll (info
)
5152 || fdh
->elf
.def_dynamic
5153 || fdh
->elf
.ref_dynamic
)
5154 && (eh
->elf
.ref_regular
5155 || eh
->elf
.def_regular
))
5157 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5165 /* Set up opd section info and abiversion for IBFD, and process list
5166 of dot-symbols we made in link_hash_newfunc. */
5169 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
5171 struct ppc_link_hash_table
*htab
;
5172 struct ppc_link_hash_entry
**p
, *eh
;
5173 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
5175 if (opd
!= NULL
&& opd
->size
!= 0)
5177 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
5178 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
5180 if (abiversion (ibfd
) == 0)
5181 set_abiversion (ibfd
, 1);
5182 else if (abiversion (ibfd
) >= 2)
5184 /* xgettext:c-format */
5185 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
5186 ibfd
, abiversion (ibfd
));
5187 bfd_set_error (bfd_error_bad_value
);
5192 if (is_ppc64_elf (info
->output_bfd
))
5194 /* For input files without an explicit abiversion in e_flags
5195 we should have flagged any with symbol st_other bits set
5196 as ELFv1 and above flagged those with .opd as ELFv2.
5197 Set the output abiversion if not yet set, and for any input
5198 still ambiguous, take its abiversion from the output.
5199 Differences in ABI are reported later. */
5200 if (abiversion (info
->output_bfd
) == 0)
5201 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
5202 else if (abiversion (ibfd
) == 0)
5203 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
5206 htab
= ppc_hash_table (info
);
5210 if (opd
!= NULL
&& opd
->size
!= 0
5211 && (ibfd
->flags
& DYNAMIC
) == 0
5212 && (opd
->flags
& SEC_RELOC
) != 0
5213 && opd
->reloc_count
!= 0
5214 && !bfd_is_abs_section (opd
->output_section
)
5215 && info
->gc_sections
)
5217 /* Garbage collection needs some extra help with .opd sections.
5218 We don't want to necessarily keep everything referenced by
5219 relocs in .opd, as that would keep all functions. Instead,
5220 if we reference an .opd symbol (a function descriptor), we
5221 want to keep the function code symbol's section. This is
5222 easy for global symbols, but for local syms we need to keep
5223 information about the associated function section. */
5225 asection
**opd_sym_map
;
5226 Elf_Internal_Shdr
*symtab_hdr
;
5227 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
5229 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
5230 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
5231 if (opd_sym_map
== NULL
)
5233 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
5234 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
5238 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5239 rel_end
= relocs
+ opd
->reloc_count
- 1;
5240 for (rel
= relocs
; rel
< rel_end
; rel
++)
5242 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
5243 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
5245 if (r_type
== R_PPC64_ADDR64
5246 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
5247 && r_symndx
< symtab_hdr
->sh_info
)
5249 Elf_Internal_Sym
*isym
;
5252 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
5255 if (elf_section_data (opd
)->relocs
!= relocs
)
5260 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
5261 if (s
!= NULL
&& s
!= opd
)
5262 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
5265 if (elf_section_data (opd
)->relocs
!= relocs
)
5269 p
= &htab
->dot_syms
;
5270 while ((eh
= *p
) != NULL
)
5273 if (&eh
->elf
== htab
->elf
.hgot
)
5275 else if (htab
->elf
.hgot
== NULL
5276 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
5277 htab
->elf
.hgot
= &eh
->elf
;
5278 else if (abiversion (ibfd
) <= 1)
5280 htab
->need_func_desc_adj
= 1;
5281 if (!add_symbol_adjust (eh
, info
))
5284 p
= &eh
->u
.next_dot_sym
;
5289 /* Undo hash table changes when an --as-needed input file is determined
5290 not to be needed. */
5293 ppc64_elf_notice_as_needed (bfd
*ibfd
,
5294 struct bfd_link_info
*info
,
5295 enum notice_asneeded_action act
)
5297 if (act
== notice_not_needed
)
5299 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5304 htab
->dot_syms
= NULL
;
5306 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
5309 /* If --just-symbols against a final linked binary, then assume we need
5310 toc adjusting stubs when calling functions defined there. */
5313 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
5315 if ((sec
->flags
& SEC_CODE
) != 0
5316 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
5317 && is_ppc64_elf (sec
->owner
))
5319 if (abiversion (sec
->owner
) >= 2
5320 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
5321 sec
->has_toc_reloc
= 1;
5323 _bfd_elf_link_just_syms (sec
, info
);
5326 static struct plt_entry
**
5327 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
5328 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
5330 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
5331 struct plt_entry
**local_plt
;
5332 unsigned char *local_got_tls_masks
;
5334 if (local_got_ents
== NULL
)
5336 bfd_size_type size
= symtab_hdr
->sh_info
;
5338 size
*= (sizeof (*local_got_ents
)
5339 + sizeof (*local_plt
)
5340 + sizeof (*local_got_tls_masks
));
5341 local_got_ents
= bfd_zalloc (abfd
, size
);
5342 if (local_got_ents
== NULL
)
5344 elf_local_got_ents (abfd
) = local_got_ents
;
5347 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
5349 struct got_entry
*ent
;
5351 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
5352 if (ent
->addend
== r_addend
5353 && ent
->owner
== abfd
5354 && ent
->tls_type
== tls_type
)
5358 bfd_size_type amt
= sizeof (*ent
);
5359 ent
= bfd_alloc (abfd
, amt
);
5362 ent
->next
= local_got_ents
[r_symndx
];
5363 ent
->addend
= r_addend
;
5365 ent
->tls_type
= tls_type
;
5366 ent
->is_indirect
= FALSE
;
5367 ent
->got
.refcount
= 0;
5368 local_got_ents
[r_symndx
] = ent
;
5370 ent
->got
.refcount
+= 1;
5373 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
5374 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
5375 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
5377 return local_plt
+ r_symndx
;
5381 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
5383 struct plt_entry
*ent
;
5385 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
5386 if (ent
->addend
== addend
)
5390 bfd_size_type amt
= sizeof (*ent
);
5391 ent
= bfd_alloc (abfd
, amt
);
5395 ent
->addend
= addend
;
5396 ent
->plt
.refcount
= 0;
5399 ent
->plt
.refcount
+= 1;
5404 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
5406 return (r_type
== R_PPC64_REL24
5407 || r_type
== R_PPC64_REL14
5408 || r_type
== R_PPC64_REL14_BRTAKEN
5409 || r_type
== R_PPC64_REL14_BRNTAKEN
5410 || r_type
== R_PPC64_ADDR24
5411 || r_type
== R_PPC64_ADDR14
5412 || r_type
== R_PPC64_ADDR14_BRTAKEN
5413 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
5416 /* Look through the relocs for a section during the first phase, and
5417 calculate needed space in the global offset table, procedure
5418 linkage table, and dynamic reloc sections. */
5421 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5422 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5424 struct ppc_link_hash_table
*htab
;
5425 Elf_Internal_Shdr
*symtab_hdr
;
5426 struct elf_link_hash_entry
**sym_hashes
;
5427 const Elf_Internal_Rela
*rel
;
5428 const Elf_Internal_Rela
*rel_end
;
5430 struct elf_link_hash_entry
*tga
, *dottga
;
5433 if (bfd_link_relocatable (info
))
5436 /* Don't do anything special with non-loaded, non-alloced sections.
5437 In particular, any relocs in such sections should not affect GOT
5438 and PLT reference counting (ie. we don't allow them to create GOT
5439 or PLT entries), there's no possibility or desire to optimize TLS
5440 relocs, and there's not much point in propagating relocs to shared
5441 libs that the dynamic linker won't relocate. */
5442 if ((sec
->flags
& SEC_ALLOC
) == 0)
5445 BFD_ASSERT (is_ppc64_elf (abfd
));
5447 htab
= ppc_hash_table (info
);
5451 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
5452 FALSE
, FALSE
, TRUE
);
5453 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
5454 FALSE
, FALSE
, TRUE
);
5455 symtab_hdr
= &elf_symtab_hdr (abfd
);
5456 sym_hashes
= elf_sym_hashes (abfd
);
5458 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
5459 rel_end
= relocs
+ sec
->reloc_count
;
5460 for (rel
= relocs
; rel
< rel_end
; rel
++)
5462 unsigned long r_symndx
;
5463 struct elf_link_hash_entry
*h
;
5464 enum elf_ppc64_reloc_type r_type
;
5466 struct _ppc64_elf_section_data
*ppc64_sec
;
5467 struct plt_entry
**ifunc
, **plt_list
;
5469 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5470 if (r_symndx
< symtab_hdr
->sh_info
)
5474 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5475 h
= elf_follow_link (h
);
5477 if (h
== htab
->elf
.hgot
)
5478 sec
->has_toc_reloc
= 1;
5485 if (h
->type
== STT_GNU_IFUNC
)
5488 ifunc
= &h
->plt
.plist
;
5493 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5498 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5500 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5502 NON_GOT
| PLT_IFUNC
);
5508 r_type
= ELF64_R_TYPE (rel
->r_info
);
5513 /* These special tls relocs tie a call to __tls_get_addr with
5514 its parameter symbol. */
5516 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
5518 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5520 NON_GOT
| TLS_TLS
| TLS_MARK
))
5522 sec
->has_tls_reloc
= 1;
5525 case R_PPC64_GOT_TLSLD16
:
5526 case R_PPC64_GOT_TLSLD16_LO
:
5527 case R_PPC64_GOT_TLSLD16_HI
:
5528 case R_PPC64_GOT_TLSLD16_HA
:
5529 tls_type
= TLS_TLS
| TLS_LD
;
5532 case R_PPC64_GOT_TLSGD16
:
5533 case R_PPC64_GOT_TLSGD16_LO
:
5534 case R_PPC64_GOT_TLSGD16_HI
:
5535 case R_PPC64_GOT_TLSGD16_HA
:
5536 tls_type
= TLS_TLS
| TLS_GD
;
5539 case R_PPC64_GOT_TPREL16_DS
:
5540 case R_PPC64_GOT_TPREL16_LO_DS
:
5541 case R_PPC64_GOT_TPREL16_HI
:
5542 case R_PPC64_GOT_TPREL16_HA
:
5543 if (bfd_link_dll (info
))
5544 info
->flags
|= DF_STATIC_TLS
;
5545 tls_type
= TLS_TLS
| TLS_TPREL
;
5548 case R_PPC64_GOT_DTPREL16_DS
:
5549 case R_PPC64_GOT_DTPREL16_LO_DS
:
5550 case R_PPC64_GOT_DTPREL16_HI
:
5551 case R_PPC64_GOT_DTPREL16_HA
:
5552 tls_type
= TLS_TLS
| TLS_DTPREL
;
5554 sec
->has_tls_reloc
= 1;
5558 case R_PPC64_GOT16_DS
:
5559 case R_PPC64_GOT16_HA
:
5560 case R_PPC64_GOT16_HI
:
5561 case R_PPC64_GOT16_LO
:
5562 case R_PPC64_GOT16_LO_DS
:
5563 /* This symbol requires a global offset table entry. */
5564 sec
->has_toc_reloc
= 1;
5565 if (r_type
== R_PPC64_GOT_TLSLD16
5566 || r_type
== R_PPC64_GOT_TLSGD16
5567 || r_type
== R_PPC64_GOT_TPREL16_DS
5568 || r_type
== R_PPC64_GOT_DTPREL16_DS
5569 || r_type
== R_PPC64_GOT16
5570 || r_type
== R_PPC64_GOT16_DS
)
5572 htab
->do_multi_toc
= 1;
5573 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5576 if (ppc64_elf_tdata (abfd
)->got
== NULL
5577 && !create_got_section (abfd
, info
))
5582 struct ppc_link_hash_entry
*eh
;
5583 struct got_entry
*ent
;
5585 eh
= (struct ppc_link_hash_entry
*) h
;
5586 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5587 if (ent
->addend
== rel
->r_addend
5588 && ent
->owner
== abfd
5589 && ent
->tls_type
== tls_type
)
5593 bfd_size_type amt
= sizeof (*ent
);
5594 ent
= bfd_alloc (abfd
, amt
);
5597 ent
->next
= eh
->elf
.got
.glist
;
5598 ent
->addend
= rel
->r_addend
;
5600 ent
->tls_type
= tls_type
;
5601 ent
->is_indirect
= FALSE
;
5602 ent
->got
.refcount
= 0;
5603 eh
->elf
.got
.glist
= ent
;
5605 ent
->got
.refcount
+= 1;
5606 eh
->tls_mask
|= tls_type
;
5609 /* This is a global offset table entry for a local symbol. */
5610 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5611 rel
->r_addend
, tls_type
))
5614 /* We may also need a plt entry if the symbol turns out to be
5616 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
5618 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5623 case R_PPC64_PLT16_HA
:
5624 case R_PPC64_PLT16_HI
:
5625 case R_PPC64_PLT16_LO
:
5626 case R_PPC64_PLT16_LO_DS
:
5629 /* This symbol requires a procedure linkage table entry. */
5634 if (h
->root
.root
.string
[0] == '.'
5635 && h
->root
.root
.string
[1] != '\0')
5636 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5637 plt_list
= &h
->plt
.plist
;
5639 if (plt_list
== NULL
)
5641 /* It does not make sense to have a procedure linkage
5642 table entry for a non-ifunc local symbol. */
5643 info
->callbacks
->einfo
5644 /* xgettext:c-format */
5645 (_("%H: %s reloc against local symbol\n"),
5646 abfd
, sec
, rel
->r_offset
,
5647 ppc64_elf_howto_table
[r_type
]->name
);
5648 bfd_set_error (bfd_error_bad_value
);
5651 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5655 /* The following relocations don't need to propagate the
5656 relocation if linking a shared object since they are
5657 section relative. */
5658 case R_PPC64_SECTOFF
:
5659 case R_PPC64_SECTOFF_LO
:
5660 case R_PPC64_SECTOFF_HI
:
5661 case R_PPC64_SECTOFF_HA
:
5662 case R_PPC64_SECTOFF_DS
:
5663 case R_PPC64_SECTOFF_LO_DS
:
5664 case R_PPC64_DTPREL16
:
5665 case R_PPC64_DTPREL16_LO
:
5666 case R_PPC64_DTPREL16_HI
:
5667 case R_PPC64_DTPREL16_HA
:
5668 case R_PPC64_DTPREL16_DS
:
5669 case R_PPC64_DTPREL16_LO_DS
:
5670 case R_PPC64_DTPREL16_HIGH
:
5671 case R_PPC64_DTPREL16_HIGHA
:
5672 case R_PPC64_DTPREL16_HIGHER
:
5673 case R_PPC64_DTPREL16_HIGHERA
:
5674 case R_PPC64_DTPREL16_HIGHEST
:
5675 case R_PPC64_DTPREL16_HIGHESTA
:
5680 case R_PPC64_REL16_LO
:
5681 case R_PPC64_REL16_HI
:
5682 case R_PPC64_REL16_HA
:
5683 case R_PPC64_REL16DX_HA
:
5686 /* Not supported as a dynamic relocation. */
5687 case R_PPC64_ADDR64_LOCAL
:
5688 if (bfd_link_pic (info
))
5690 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5692 /* xgettext:c-format */
5693 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5694 "in shared libraries and PIEs\n"),
5695 abfd
, sec
, rel
->r_offset
,
5696 ppc64_elf_howto_table
[r_type
]->name
);
5697 bfd_set_error (bfd_error_bad_value
);
5703 case R_PPC64_TOC16_DS
:
5704 htab
->do_multi_toc
= 1;
5705 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5707 case R_PPC64_TOC16_LO
:
5708 case R_PPC64_TOC16_HI
:
5709 case R_PPC64_TOC16_HA
:
5710 case R_PPC64_TOC16_LO_DS
:
5711 sec
->has_toc_reloc
= 1;
5718 /* This relocation describes the C++ object vtable hierarchy.
5719 Reconstruct it for later use during GC. */
5720 case R_PPC64_GNU_VTINHERIT
:
5721 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5725 /* This relocation describes which C++ vtable entries are actually
5726 used. Record for later use during GC. */
5727 case R_PPC64_GNU_VTENTRY
:
5728 BFD_ASSERT (h
!= NULL
);
5730 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5735 case R_PPC64_REL14_BRTAKEN
:
5736 case R_PPC64_REL14_BRNTAKEN
:
5738 asection
*dest
= NULL
;
5740 /* Heuristic: If jumping outside our section, chances are
5741 we are going to need a stub. */
5744 /* If the sym is weak it may be overridden later, so
5745 don't assume we know where a weak sym lives. */
5746 if (h
->root
.type
== bfd_link_hash_defined
)
5747 dest
= h
->root
.u
.def
.section
;
5751 Elf_Internal_Sym
*isym
;
5753 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5758 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5762 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5771 if (h
->root
.root
.string
[0] == '.'
5772 && h
->root
.root
.string
[1] != '\0')
5773 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5775 if (h
== tga
|| h
== dottga
)
5777 sec
->has_tls_reloc
= 1;
5779 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5780 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5781 /* We have a new-style __tls_get_addr call with
5785 /* Mark this section as having an old-style call. */
5786 sec
->has_tls_get_addr_call
= 1;
5788 plt_list
= &h
->plt
.plist
;
5791 /* We may need a .plt entry if the function this reloc
5792 refers to is in a shared lib. */
5794 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5798 case R_PPC64_ADDR14
:
5799 case R_PPC64_ADDR14_BRNTAKEN
:
5800 case R_PPC64_ADDR14_BRTAKEN
:
5801 case R_PPC64_ADDR24
:
5804 case R_PPC64_TPREL64
:
5805 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5806 if (bfd_link_dll (info
))
5807 info
->flags
|= DF_STATIC_TLS
;
5810 case R_PPC64_DTPMOD64
:
5811 if (rel
+ 1 < rel_end
5812 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5813 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5814 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5816 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5819 case R_PPC64_DTPREL64
:
5820 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5822 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5823 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5824 /* This is the second reloc of a dtpmod, dtprel pair.
5825 Don't mark with TLS_DTPREL. */
5829 sec
->has_tls_reloc
= 1;
5832 struct ppc_link_hash_entry
*eh
;
5833 eh
= (struct ppc_link_hash_entry
*) h
;
5834 eh
->tls_mask
|= tls_type
;
5837 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5838 rel
->r_addend
, tls_type
))
5841 ppc64_sec
= ppc64_elf_section_data (sec
);
5842 if (ppc64_sec
->sec_type
!= sec_toc
)
5846 /* One extra to simplify get_tls_mask. */
5847 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5848 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5849 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5851 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5852 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5853 if (ppc64_sec
->u
.toc
.add
== NULL
)
5855 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5856 ppc64_sec
->sec_type
= sec_toc
;
5858 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5859 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5860 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5862 /* Mark the second slot of a GD or LD entry.
5863 -1 to indicate GD and -2 to indicate LD. */
5864 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5865 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5866 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5867 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5870 case R_PPC64_TPREL16
:
5871 case R_PPC64_TPREL16_LO
:
5872 case R_PPC64_TPREL16_HI
:
5873 case R_PPC64_TPREL16_HA
:
5874 case R_PPC64_TPREL16_DS
:
5875 case R_PPC64_TPREL16_LO_DS
:
5876 case R_PPC64_TPREL16_HIGH
:
5877 case R_PPC64_TPREL16_HIGHA
:
5878 case R_PPC64_TPREL16_HIGHER
:
5879 case R_PPC64_TPREL16_HIGHERA
:
5880 case R_PPC64_TPREL16_HIGHEST
:
5881 case R_PPC64_TPREL16_HIGHESTA
:
5882 if (bfd_link_dll (info
))
5883 info
->flags
|= DF_STATIC_TLS
;
5886 case R_PPC64_ADDR64
:
5888 && rel
+ 1 < rel_end
5889 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5892 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5896 case R_PPC64_ADDR16
:
5897 case R_PPC64_ADDR16_DS
:
5898 case R_PPC64_ADDR16_HA
:
5899 case R_PPC64_ADDR16_HI
:
5900 case R_PPC64_ADDR16_HIGH
:
5901 case R_PPC64_ADDR16_HIGHA
:
5902 case R_PPC64_ADDR16_HIGHER
:
5903 case R_PPC64_ADDR16_HIGHERA
:
5904 case R_PPC64_ADDR16_HIGHEST
:
5905 case R_PPC64_ADDR16_HIGHESTA
:
5906 case R_PPC64_ADDR16_LO
:
5907 case R_PPC64_ADDR16_LO_DS
:
5908 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5909 && rel
->r_addend
== 0)
5911 /* We may need a .plt entry if this reloc refers to a
5912 function in a shared lib. */
5913 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5915 h
->pointer_equality_needed
= 1;
5922 case R_PPC64_ADDR32
:
5923 case R_PPC64_UADDR16
:
5924 case R_PPC64_UADDR32
:
5925 case R_PPC64_UADDR64
:
5927 if (h
!= NULL
&& !bfd_link_pic (info
))
5928 /* We may need a copy reloc. */
5931 /* Don't propagate .opd relocs. */
5932 if (NO_OPD_RELOCS
&& is_opd
)
5935 /* If we are creating a shared library, and this is a reloc
5936 against a global symbol, or a non PC relative reloc
5937 against a local symbol, then we need to copy the reloc
5938 into the shared library. However, if we are linking with
5939 -Bsymbolic, we do not need to copy a reloc against a
5940 global symbol which is defined in an object we are
5941 including in the link (i.e., DEF_REGULAR is set). At
5942 this point we have not seen all the input files, so it is
5943 possible that DEF_REGULAR is not set now but will be set
5944 later (it is never cleared). In case of a weak definition,
5945 DEF_REGULAR may be cleared later by a strong definition in
5946 a shared library. We account for that possibility below by
5947 storing information in the dyn_relocs field of the hash
5948 table entry. A similar situation occurs when creating
5949 shared libraries and symbol visibility changes render the
5952 If on the other hand, we are creating an executable, we
5953 may need to keep relocations for symbols satisfied by a
5954 dynamic library if we manage to avoid copy relocs for the
5957 if ((bfd_link_pic (info
)
5958 && (must_be_dyn_reloc (info
, r_type
)
5960 && (!SYMBOLIC_BIND (info
, h
)
5961 || h
->root
.type
== bfd_link_hash_defweak
5962 || !h
->def_regular
))))
5963 || (ELIMINATE_COPY_RELOCS
5964 && !bfd_link_pic (info
)
5966 && (h
->root
.type
== bfd_link_hash_defweak
5967 || !h
->def_regular
))
5968 || (!bfd_link_pic (info
)
5971 /* We must copy these reloc types into the output file.
5972 Create a reloc section in dynobj and make room for
5976 sreloc
= _bfd_elf_make_dynamic_reloc_section
5977 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5983 /* If this is a global symbol, we count the number of
5984 relocations we need for this symbol. */
5987 struct elf_dyn_relocs
*p
;
5988 struct elf_dyn_relocs
**head
;
5990 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5992 if (p
== NULL
|| p
->sec
!= sec
)
5994 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6004 if (!must_be_dyn_reloc (info
, r_type
))
6009 /* Track dynamic relocs needed for local syms too.
6010 We really need local syms available to do this
6012 struct ppc_dyn_relocs
*p
;
6013 struct ppc_dyn_relocs
**head
;
6014 bfd_boolean is_ifunc
;
6017 Elf_Internal_Sym
*isym
;
6019 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6024 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6028 vpp
= &elf_section_data (s
)->local_dynrel
;
6029 head
= (struct ppc_dyn_relocs
**) vpp
;
6030 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
6032 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
6034 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
6036 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6042 p
->ifunc
= is_ifunc
;
6058 /* Merge backend specific data from an object file to the output
6059 object file when linking. */
6062 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6064 bfd
*obfd
= info
->output_bfd
;
6065 unsigned long iflags
, oflags
;
6067 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
6070 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
6073 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6076 iflags
= elf_elfheader (ibfd
)->e_flags
;
6077 oflags
= elf_elfheader (obfd
)->e_flags
;
6079 if (iflags
& ~EF_PPC64_ABI
)
6082 /* xgettext:c-format */
6083 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
6084 bfd_set_error (bfd_error_bad_value
);
6087 else if (iflags
!= oflags
&& iflags
!= 0)
6090 /* xgettext:c-format */
6091 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
6092 ibfd
, iflags
, oflags
);
6093 bfd_set_error (bfd_error_bad_value
);
6097 _bfd_elf_ppc_merge_fp_attributes (ibfd
, info
);
6099 /* Merge Tag_compatibility attributes and any common GNU ones. */
6100 _bfd_elf_merge_object_attributes (ibfd
, info
);
6106 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6108 /* Print normal ELF private data. */
6109 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6111 if (elf_elfheader (abfd
)->e_flags
!= 0)
6115 fprintf (file
, _("private flags = 0x%lx:"),
6116 elf_elfheader (abfd
)->e_flags
);
6118 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
6119 fprintf (file
, _(" [abiv%ld]"),
6120 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
6127 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6128 of the code entry point, and its section, which must be in the same
6129 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6132 opd_entry_value (asection
*opd_sec
,
6134 asection
**code_sec
,
6136 bfd_boolean in_code_sec
)
6138 bfd
*opd_bfd
= opd_sec
->owner
;
6139 Elf_Internal_Rela
*relocs
;
6140 Elf_Internal_Rela
*lo
, *hi
, *look
;
6143 /* No relocs implies we are linking a --just-symbols object, or looking
6144 at a final linked executable with addr2line or somesuch. */
6145 if (opd_sec
->reloc_count
== 0)
6147 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
6149 if (contents
== NULL
)
6151 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
6152 return (bfd_vma
) -1;
6153 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
6156 /* PR 17512: file: 64b9dfbb. */
6157 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
6158 return (bfd_vma
) -1;
6160 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
6161 if (code_sec
!= NULL
)
6163 asection
*sec
, *likely
= NULL
;
6169 && val
< sec
->vma
+ sec
->size
)
6175 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6177 && (sec
->flags
& SEC_LOAD
) != 0
6178 && (sec
->flags
& SEC_ALLOC
) != 0)
6183 if (code_off
!= NULL
)
6184 *code_off
= val
- likely
->vma
;
6190 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
6192 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
6194 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
6195 /* PR 17512: file: df8e1fd6. */
6197 return (bfd_vma
) -1;
6199 /* Go find the opd reloc at the sym address. */
6201 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
6205 look
= lo
+ (hi
- lo
) / 2;
6206 if (look
->r_offset
< offset
)
6208 else if (look
->r_offset
> offset
)
6212 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
6214 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
6215 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
6217 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
6218 asection
*sec
= NULL
;
6220 if (symndx
>= symtab_hdr
->sh_info
6221 && elf_sym_hashes (opd_bfd
) != NULL
)
6223 struct elf_link_hash_entry
**sym_hashes
;
6224 struct elf_link_hash_entry
*rh
;
6226 sym_hashes
= elf_sym_hashes (opd_bfd
);
6227 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
6230 rh
= elf_follow_link (rh
);
6231 if (rh
->root
.type
!= bfd_link_hash_defined
6232 && rh
->root
.type
!= bfd_link_hash_defweak
)
6234 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
6236 val
= rh
->root
.u
.def
.value
;
6237 sec
= rh
->root
.u
.def
.section
;
6244 Elf_Internal_Sym
*sym
;
6246 if (symndx
< symtab_hdr
->sh_info
)
6248 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6251 size_t symcnt
= symtab_hdr
->sh_info
;
6252 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6257 symtab_hdr
->contents
= (bfd_byte
*) sym
;
6263 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6269 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
6272 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
6273 val
= sym
->st_value
;
6276 val
+= look
->r_addend
;
6277 if (code_off
!= NULL
)
6279 if (code_sec
!= NULL
)
6281 if (in_code_sec
&& *code_sec
!= sec
)
6286 if (sec
->output_section
!= NULL
)
6287 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
6296 /* If the ELF symbol SYM might be a function in SEC, return the
6297 function size and set *CODE_OFF to the function's entry point,
6298 otherwise return zero. */
6300 static bfd_size_type
6301 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
6306 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
6307 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
6311 if (!(sym
->flags
& BSF_SYNTHETIC
))
6312 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
6314 if (strcmp (sym
->section
->name
, ".opd") == 0)
6316 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
6317 bfd_vma symval
= sym
->value
;
6320 && opd
->adjust
!= NULL
6321 && elf_section_data (sym
->section
)->relocs
!= NULL
)
6323 /* opd_entry_value will use cached relocs that have been
6324 adjusted, but with raw symbols. That means both local
6325 and global symbols need adjusting. */
6326 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
6332 if (opd_entry_value (sym
->section
, symval
,
6333 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
6335 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6336 symbol. This size has nothing to do with the code size of the
6337 function, which is what we're supposed to return, but the
6338 code size isn't available without looking up the dot-sym.
6339 However, doing that would be a waste of time particularly
6340 since elf_find_function will look at the dot-sym anyway.
6341 Now, elf_find_function will keep the largest size of any
6342 function sym found at the code address of interest, so return
6343 1 here to avoid it incorrectly caching a larger function size
6344 for a small function. This does mean we return the wrong
6345 size for a new-ABI function of size 24, but all that does is
6346 disable caching for such functions. */
6352 if (sym
->section
!= sec
)
6354 *code_off
= sym
->value
;
6361 /* Return true if symbol is a strong function defined in an ELFv2
6362 object with st_other localentry bits of zero, ie. its local entry
6363 point coincides with its global entry point. */
6366 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
6369 && h
->type
== STT_FUNC
6370 && h
->root
.type
== bfd_link_hash_defined
6371 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
6372 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
6373 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
6374 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
6377 /* Return true if symbol is defined in a regular object file. */
6380 is_static_defined (struct elf_link_hash_entry
*h
)
6382 return ((h
->root
.type
== bfd_link_hash_defined
6383 || h
->root
.type
== bfd_link_hash_defweak
)
6384 && h
->root
.u
.def
.section
!= NULL
6385 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6388 /* If FDH is a function descriptor symbol, return the associated code
6389 entry symbol if it is defined. Return NULL otherwise. */
6391 static struct ppc_link_hash_entry
*
6392 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
6394 if (fdh
->is_func_descriptor
)
6396 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
6397 if (fh
->elf
.root
.type
== bfd_link_hash_defined
6398 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6404 /* If FH is a function code entry symbol, return the associated
6405 function descriptor symbol if it is defined. Return NULL otherwise. */
6407 static struct ppc_link_hash_entry
*
6408 defined_func_desc (struct ppc_link_hash_entry
*fh
)
6411 && fh
->oh
->is_func_descriptor
)
6413 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
6414 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
6415 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6421 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
6423 /* Garbage collect sections, after first dealing with dot-symbols. */
6426 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6428 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6430 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
6432 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6433 htab
->need_func_desc_adj
= 0;
6435 return bfd_elf_gc_sections (abfd
, info
);
6438 /* Mark all our entry sym sections, both opd and code section. */
6441 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
6443 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6444 struct bfd_sym_chain
*sym
;
6449 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
6451 struct ppc_link_hash_entry
*eh
, *fh
;
6454 eh
= (struct ppc_link_hash_entry
*)
6455 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
6458 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
6459 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6462 fh
= defined_code_entry (eh
);
6465 sec
= fh
->elf
.root
.u
.def
.section
;
6466 sec
->flags
|= SEC_KEEP
;
6468 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6469 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6470 eh
->elf
.root
.u
.def
.value
,
6471 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6472 sec
->flags
|= SEC_KEEP
;
6474 sec
= eh
->elf
.root
.u
.def
.section
;
6475 sec
->flags
|= SEC_KEEP
;
6479 /* Mark sections containing dynamically referenced symbols. When
6480 building shared libraries, we must assume that any visible symbol is
6484 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
6486 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6487 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
6488 struct ppc_link_hash_entry
*fdh
;
6489 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
6491 /* Dynamic linking info is on the func descriptor sym. */
6492 fdh
= defined_func_desc (eh
);
6496 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
6497 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
6498 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
6499 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
6500 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
6501 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
6502 && (!bfd_link_executable (info
)
6503 || info
->gc_keep_exported
6504 || info
->export_dynamic
6507 && (*d
->match
) (&d
->head
, NULL
, eh
->elf
.root
.root
.string
)))
6508 && (eh
->elf
.versioned
>= versioned
6509 || !bfd_hide_sym_by_version (info
->version_info
,
6510 eh
->elf
.root
.root
.string
)))))
6513 struct ppc_link_hash_entry
*fh
;
6515 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
6517 /* Function descriptor syms cause the associated
6518 function code sym section to be marked. */
6519 fh
= defined_code_entry (eh
);
6522 code_sec
= fh
->elf
.root
.u
.def
.section
;
6523 code_sec
->flags
|= SEC_KEEP
;
6525 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6526 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6527 eh
->elf
.root
.u
.def
.value
,
6528 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6529 code_sec
->flags
|= SEC_KEEP
;
6535 /* Return the section that should be marked against GC for a given
6539 ppc64_elf_gc_mark_hook (asection
*sec
,
6540 struct bfd_link_info
*info
,
6541 Elf_Internal_Rela
*rel
,
6542 struct elf_link_hash_entry
*h
,
6543 Elf_Internal_Sym
*sym
)
6547 /* Syms return NULL if we're marking .opd, so we avoid marking all
6548 function sections, as all functions are referenced in .opd. */
6550 if (get_opd_info (sec
) != NULL
)
6555 enum elf_ppc64_reloc_type r_type
;
6556 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6558 r_type
= ELF64_R_TYPE (rel
->r_info
);
6561 case R_PPC64_GNU_VTINHERIT
:
6562 case R_PPC64_GNU_VTENTRY
:
6566 switch (h
->root
.type
)
6568 case bfd_link_hash_defined
:
6569 case bfd_link_hash_defweak
:
6570 eh
= (struct ppc_link_hash_entry
*) h
;
6571 fdh
= defined_func_desc (eh
);
6574 /* -mcall-aixdesc code references the dot-symbol on
6575 a call reloc. Mark the function descriptor too
6576 against garbage collection. */
6578 if (fdh
->elf
.is_weakalias
)
6579 weakdef (&fdh
->elf
)->mark
= 1;
6583 /* Function descriptor syms cause the associated
6584 function code sym section to be marked. */
6585 fh
= defined_code_entry (eh
);
6588 /* They also mark their opd section. */
6589 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6591 rsec
= fh
->elf
.root
.u
.def
.section
;
6593 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6594 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6595 eh
->elf
.root
.u
.def
.value
,
6596 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
6597 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6599 rsec
= h
->root
.u
.def
.section
;
6602 case bfd_link_hash_common
:
6603 rsec
= h
->root
.u
.c
.p
->section
;
6607 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6613 struct _opd_sec_data
*opd
;
6615 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6616 opd
= get_opd_info (rsec
);
6617 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6621 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6628 /* The maximum size of .sfpr. */
6629 #define SFPR_MAX (218*4)
6631 struct sfpr_def_parms
6633 const char name
[12];
6634 unsigned char lo
, hi
;
6635 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
6636 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6639 /* Auto-generate _save*, _rest* functions in .sfpr.
6640 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6644 sfpr_define (struct bfd_link_info
*info
,
6645 const struct sfpr_def_parms
*parm
,
6648 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6650 size_t len
= strlen (parm
->name
);
6651 bfd_boolean writing
= FALSE
;
6657 memcpy (sym
, parm
->name
, len
);
6660 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6662 struct ppc_link_hash_entry
*h
;
6664 sym
[len
+ 0] = i
/ 10 + '0';
6665 sym
[len
+ 1] = i
% 10 + '0';
6666 h
= (struct ppc_link_hash_entry
*)
6667 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
6668 if (stub_sec
!= NULL
)
6671 && h
->elf
.root
.type
== bfd_link_hash_defined
6672 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6674 struct elf_link_hash_entry
*s
;
6676 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6677 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
6680 if (s
->root
.type
== bfd_link_hash_new
6681 || (s
->root
.type
= bfd_link_hash_defined
6682 && s
->root
.u
.def
.section
== stub_sec
))
6684 s
->root
.type
= bfd_link_hash_defined
;
6685 s
->root
.u
.def
.section
= stub_sec
;
6686 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6687 + h
->elf
.root
.u
.def
.value
);
6690 s
->ref_regular_nonweak
= 1;
6691 s
->forced_local
= 1;
6693 s
->root
.linker_def
= 1;
6701 if (!h
->elf
.def_regular
)
6703 h
->elf
.root
.type
= bfd_link_hash_defined
;
6704 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6705 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6706 h
->elf
.type
= STT_FUNC
;
6707 h
->elf
.def_regular
= 1;
6709 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
6711 if (htab
->sfpr
->contents
== NULL
)
6713 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6714 if (htab
->sfpr
->contents
== NULL
)
6721 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6723 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6725 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6726 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6734 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6736 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6741 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6743 p
= savegpr0 (abfd
, p
, r
);
6744 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6746 bfd_put_32 (abfd
, BLR
, p
);
6751 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6753 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6758 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6760 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6762 p
= restgpr0 (abfd
, p
, r
);
6763 bfd_put_32 (abfd
, MTLR_R0
, p
);
6767 p
= restgpr0 (abfd
, p
, 30);
6768 p
= restgpr0 (abfd
, p
, 31);
6770 bfd_put_32 (abfd
, BLR
, p
);
6775 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6777 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6782 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6784 p
= savegpr1 (abfd
, p
, r
);
6785 bfd_put_32 (abfd
, BLR
, p
);
6790 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6792 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6797 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6799 p
= restgpr1 (abfd
, p
, r
);
6800 bfd_put_32 (abfd
, BLR
, p
);
6805 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6807 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6812 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6814 p
= savefpr (abfd
, p
, r
);
6815 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6817 bfd_put_32 (abfd
, BLR
, p
);
6822 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6824 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6829 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6831 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6833 p
= restfpr (abfd
, p
, r
);
6834 bfd_put_32 (abfd
, MTLR_R0
, p
);
6838 p
= restfpr (abfd
, p
, 30);
6839 p
= restfpr (abfd
, p
, 31);
6841 bfd_put_32 (abfd
, BLR
, p
);
6846 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6848 p
= savefpr (abfd
, p
, r
);
6849 bfd_put_32 (abfd
, BLR
, p
);
6854 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6856 p
= restfpr (abfd
, p
, r
);
6857 bfd_put_32 (abfd
, BLR
, p
);
6862 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6864 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6866 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6871 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6873 p
= savevr (abfd
, p
, r
);
6874 bfd_put_32 (abfd
, BLR
, p
);
6879 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6881 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6883 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6888 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6890 p
= restvr (abfd
, p
, r
);
6891 bfd_put_32 (abfd
, BLR
, p
);
6895 /* Called via elf_link_hash_traverse to transfer dynamic linking
6896 information on function code symbol entries to their corresponding
6897 function descriptor symbol entries. */
6900 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6902 struct bfd_link_info
*info
;
6903 struct ppc_link_hash_table
*htab
;
6904 struct ppc_link_hash_entry
*fh
;
6905 struct ppc_link_hash_entry
*fdh
;
6906 bfd_boolean force_local
;
6908 fh
= (struct ppc_link_hash_entry
*) h
;
6909 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6915 if (fh
->elf
.root
.root
.string
[0] != '.'
6916 || fh
->elf
.root
.root
.string
[1] == '\0')
6920 htab
= ppc_hash_table (info
);
6924 /* Find the corresponding function descriptor symbol. */
6925 fdh
= lookup_fdh (fh
, htab
);
6927 /* Resolve undefined references to dot-symbols as the value
6928 in the function descriptor, if we have one in a regular object.
6929 This is to satisfy cases like ".quad .foo". Calls to functions
6930 in dynamic objects are handled elsewhere. */
6931 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6932 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6933 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6934 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6935 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6936 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6937 fdh
->elf
.root
.u
.def
.value
,
6938 &fh
->elf
.root
.u
.def
.section
,
6939 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
6941 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6942 fh
->elf
.forced_local
= 1;
6943 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6944 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6947 if (!fh
->elf
.dynamic
)
6949 struct plt_entry
*ent
;
6951 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6952 if (ent
->plt
.refcount
> 0)
6958 /* Create a descriptor as undefined if necessary. */
6960 && !bfd_link_executable (info
)
6961 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6962 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6964 fdh
= make_fdh (info
, fh
);
6969 /* We can't support overriding of symbols on a fake descriptor. */
6972 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6973 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6974 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6976 /* Transfer dynamic linking information to the function descriptor. */
6979 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6980 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6981 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6982 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6983 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6984 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6985 || fh
->elf
.type
== STT_FUNC
6986 || fh
->elf
.type
== STT_GNU_IFUNC
);
6987 move_plt_plist (fh
, fdh
);
6989 if (!fdh
->elf
.forced_local
6990 && fh
->elf
.dynindx
!= -1)
6991 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6995 /* Now that the info is on the function descriptor, clear the
6996 function code sym info. Any function code syms for which we
6997 don't have a definition in a regular file, we force local.
6998 This prevents a shared library from exporting syms that have
6999 been imported from another library. Function code syms that
7000 are really in the library we must leave global to prevent the
7001 linker dragging in a definition from a static library. */
7002 force_local
= (!fh
->elf
.def_regular
7004 || !fdh
->elf
.def_regular
7005 || fdh
->elf
.forced_local
);
7006 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7011 static const struct sfpr_def_parms save_res_funcs
[] =
7013 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
7014 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
7015 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
7016 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
7017 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
7018 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
7019 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
7020 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
7021 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
7022 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
7023 { "_savevr_", 20, 31, savevr
, savevr_tail
},
7024 { "_restvr_", 20, 31, restvr
, restvr_tail
}
7027 /* Called near the start of bfd_elf_size_dynamic_sections. We use
7028 this hook to a) provide some gcc support functions, and b) transfer
7029 dynamic linking information gathered so far on function code symbol
7030 entries, to their corresponding function descriptor symbol entries. */
7033 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
7034 struct bfd_link_info
*info
)
7036 struct ppc_link_hash_table
*htab
;
7038 htab
= ppc_hash_table (info
);
7042 /* Provide any missing _save* and _rest* functions. */
7043 if (htab
->sfpr
!= NULL
)
7047 htab
->sfpr
->size
= 0;
7048 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
7049 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
7051 if (htab
->sfpr
->size
== 0)
7052 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
7055 if (bfd_link_relocatable (info
))
7058 if (htab
->elf
.hgot
!= NULL
)
7060 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
7061 /* Make .TOC. defined so as to prevent it being made dynamic.
7062 The wrong value here is fixed later in ppc64_elf_set_toc. */
7063 if (!htab
->elf
.hgot
->def_regular
7064 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
7066 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
7067 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
7068 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7069 htab
->elf
.hgot
->def_regular
= 1;
7070 htab
->elf
.hgot
->root
.linker_def
= 1;
7072 htab
->elf
.hgot
->type
= STT_OBJECT
;
7073 htab
->elf
.hgot
->other
= ((htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1))
7077 if (htab
->need_func_desc_adj
)
7079 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7080 htab
->need_func_desc_adj
= 0;
7086 /* Find dynamic relocs for H that apply to read-only sections. */
7089 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7091 struct ppc_link_hash_entry
*eh
;
7092 struct elf_dyn_relocs
*p
;
7094 eh
= (struct ppc_link_hash_entry
*) h
;
7095 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7097 asection
*s
= p
->sec
->output_section
;
7099 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7105 /* Return true if we have dynamic relocs against H or any of its weak
7106 aliases, that apply to read-only sections. Cannot be used after
7107 size_dynamic_sections. */
7110 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7112 struct ppc_link_hash_entry
*eh
;
7114 eh
= (struct ppc_link_hash_entry
*) h
;
7117 if (readonly_dynrelocs (&eh
->elf
))
7119 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
7120 } while (eh
!= NULL
&& &eh
->elf
!= h
);
7125 /* Return whether EH has pc-relative dynamic relocs. */
7128 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
7130 struct elf_dyn_relocs
*p
;
7132 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7133 if (p
->pc_count
!= 0)
7138 /* Return true if a global entry stub will be created for H. Valid
7139 for ELFv2 before plt entries have been allocated. */
7142 global_entry_stub (struct elf_link_hash_entry
*h
)
7144 struct plt_entry
*pent
;
7146 if (!h
->pointer_equality_needed
7150 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7151 if (pent
->plt
.refcount
> 0
7152 && pent
->addend
== 0)
7158 /* Adjust a symbol defined by a dynamic object and referenced by a
7159 regular object. The current definition is in some section of the
7160 dynamic object, but we're not including those sections. We have to
7161 change the definition to something the rest of the link can
7165 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7166 struct elf_link_hash_entry
*h
)
7168 struct ppc_link_hash_table
*htab
;
7171 htab
= ppc_hash_table (info
);
7175 /* Deal with function syms. */
7176 if (h
->type
== STT_FUNC
7177 || h
->type
== STT_GNU_IFUNC
7180 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
7181 || SYMBOL_CALLS_LOCAL (info
, h
)
7182 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
7183 /* Discard dyn_relocs when non-pic if we've decided that a
7184 function symbol is local and not an ifunc. We keep dynamic
7185 relocs for ifuncs when local rather than always emitting a
7186 plt call stub for them and defining the symbol on the call
7187 stub. We can't do that for ELFv1 anyway (a function symbol
7188 is defined on a descriptor, not code) and it can be faster at
7189 run-time due to not needing to bounce through a stub. The
7190 dyn_relocs for ifuncs will be applied even in a static
7192 if (!bfd_link_pic (info
)
7193 && h
->type
!= STT_GNU_IFUNC
7195 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7197 /* Clear procedure linkage table information for any symbol that
7198 won't need a .plt entry. */
7199 struct plt_entry
*ent
;
7200 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7201 if (ent
->plt
.refcount
> 0)
7204 || (h
->type
!= STT_GNU_IFUNC
&& local
))
7206 h
->plt
.plist
= NULL
;
7208 h
->pointer_equality_needed
= 0;
7210 else if (abiversion (info
->output_bfd
) >= 2)
7212 /* Taking a function's address in a read/write section
7213 doesn't require us to define the function symbol in the
7214 executable on a global entry stub. A dynamic reloc can
7215 be used instead. The reason we prefer a few more dynamic
7216 relocs is that calling via a global entry stub costs a
7217 few more instructions, and pointer_equality_needed causes
7218 extra work in ld.so when resolving these symbols. */
7219 if (global_entry_stub (h
))
7221 if (!readonly_dynrelocs (h
))
7223 h
->pointer_equality_needed
= 0;
7224 /* If we haven't seen a branch reloc then we don't need
7227 h
->plt
.plist
= NULL
;
7229 else if (!bfd_link_pic (info
))
7230 /* We are going to be defining the function symbol on the
7231 plt stub, so no dyn_relocs needed when non-pic. */
7232 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7235 /* ELFv2 function symbols can't have copy relocs. */
7238 else if (!h
->needs_plt
7239 && !readonly_dynrelocs (h
))
7241 /* If we haven't seen a branch reloc then we don't need a
7243 h
->plt
.plist
= NULL
;
7244 h
->pointer_equality_needed
= 0;
7249 h
->plt
.plist
= NULL
;
7251 /* If this is a weak symbol, and there is a real definition, the
7252 processor independent code will have arranged for us to see the
7253 real definition first, and we can just use the same value. */
7254 if (h
->is_weakalias
)
7256 struct elf_link_hash_entry
*def
= weakdef (h
);
7257 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7258 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7259 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7260 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
7261 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
7262 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7266 /* If we are creating a shared library, we must presume that the
7267 only references to the symbol are via the global offset table.
7268 For such cases we need not do anything here; the relocations will
7269 be handled correctly by relocate_section. */
7270 if (bfd_link_pic (info
))
7273 /* If there are no references to this symbol that do not use the
7274 GOT, we don't need to generate a copy reloc. */
7275 if (!h
->non_got_ref
)
7278 /* Don't generate a copy reloc for symbols defined in the executable. */
7279 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
7281 /* If -z nocopyreloc was given, don't generate them either. */
7282 || info
->nocopyreloc
7284 /* If we don't find any dynamic relocs in read-only sections, then
7285 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7286 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
7288 /* Protected variables do not work with .dynbss. The copy in
7289 .dynbss won't be used by the shared library with the protected
7290 definition for the variable. Text relocations are preferable
7291 to an incorrect program. */
7292 || h
->protected_def
)
7295 if (h
->plt
.plist
!= NULL
)
7297 /* We should never get here, but unfortunately there are versions
7298 of gcc out there that improperly (for this ABI) put initialized
7299 function pointers, vtable refs and suchlike in read-only
7300 sections. Allow them to proceed, but warn that this might
7301 break at runtime. */
7302 info
->callbacks
->einfo
7303 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
7304 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7305 h
->root
.root
.string
);
7308 /* This is a reference to a symbol defined by a dynamic object which
7309 is not a function. */
7311 /* We must allocate the symbol in our .dynbss section, which will
7312 become part of the .bss section of the executable. There will be
7313 an entry for this symbol in the .dynsym section. The dynamic
7314 object will contain position independent code, so all references
7315 from the dynamic object to this symbol will go through the global
7316 offset table. The dynamic linker will use the .dynsym entry to
7317 determine the address it must put in the global offset table, so
7318 both the dynamic object and the regular object will refer to the
7319 same memory location for the variable. */
7320 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7322 s
= htab
->elf
.sdynrelro
;
7323 srel
= htab
->elf
.sreldynrelro
;
7327 s
= htab
->elf
.sdynbss
;
7328 srel
= htab
->elf
.srelbss
;
7330 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7332 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
7333 linker to copy the initial value out of the dynamic object
7334 and into the runtime process image. */
7335 srel
->size
+= sizeof (Elf64_External_Rela
);
7339 /* We no longer want dyn_relocs. */
7340 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7341 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7344 /* If given a function descriptor symbol, hide both the function code
7345 sym and the descriptor. */
7347 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
7348 struct elf_link_hash_entry
*h
,
7349 bfd_boolean force_local
)
7351 struct ppc_link_hash_entry
*eh
;
7352 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
7354 eh
= (struct ppc_link_hash_entry
*) h
;
7355 if (eh
->is_func_descriptor
)
7357 struct ppc_link_hash_entry
*fh
= eh
->oh
;
7362 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7365 /* We aren't supposed to use alloca in BFD because on
7366 systems which do not have alloca the version in libiberty
7367 calls xmalloc, which might cause the program to crash
7368 when it runs out of memory. This function doesn't have a
7369 return status, so there's no way to gracefully return an
7370 error. So cheat. We know that string[-1] can be safely
7371 accessed; It's either a string in an ELF string table,
7372 or allocated in an objalloc structure. */
7374 p
= eh
->elf
.root
.root
.string
- 1;
7377 fh
= (struct ppc_link_hash_entry
*)
7378 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7381 /* Unfortunately, if it so happens that the string we were
7382 looking for was allocated immediately before this string,
7383 then we overwrote the string terminator. That's the only
7384 reason the lookup should fail. */
7387 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
7388 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
7390 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
7391 fh
= (struct ppc_link_hash_entry
*)
7392 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7401 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7406 get_sym_h (struct elf_link_hash_entry
**hp
,
7407 Elf_Internal_Sym
**symp
,
7409 unsigned char **tls_maskp
,
7410 Elf_Internal_Sym
**locsymsp
,
7411 unsigned long r_symndx
,
7414 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7416 if (r_symndx
>= symtab_hdr
->sh_info
)
7418 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7419 struct elf_link_hash_entry
*h
;
7421 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7422 h
= elf_follow_link (h
);
7430 if (symsecp
!= NULL
)
7432 asection
*symsec
= NULL
;
7433 if (h
->root
.type
== bfd_link_hash_defined
7434 || h
->root
.type
== bfd_link_hash_defweak
)
7435 symsec
= h
->root
.u
.def
.section
;
7439 if (tls_maskp
!= NULL
)
7441 struct ppc_link_hash_entry
*eh
;
7443 eh
= (struct ppc_link_hash_entry
*) h
;
7444 *tls_maskp
= &eh
->tls_mask
;
7449 Elf_Internal_Sym
*sym
;
7450 Elf_Internal_Sym
*locsyms
= *locsymsp
;
7452 if (locsyms
== NULL
)
7454 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7455 if (locsyms
== NULL
)
7456 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
7457 symtab_hdr
->sh_info
,
7458 0, NULL
, NULL
, NULL
);
7459 if (locsyms
== NULL
)
7461 *locsymsp
= locsyms
;
7463 sym
= locsyms
+ r_symndx
;
7471 if (symsecp
!= NULL
)
7472 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7474 if (tls_maskp
!= NULL
)
7476 struct got_entry
**lgot_ents
;
7477 unsigned char *tls_mask
;
7480 lgot_ents
= elf_local_got_ents (ibfd
);
7481 if (lgot_ents
!= NULL
)
7483 struct plt_entry
**local_plt
= (struct plt_entry
**)
7484 (lgot_ents
+ symtab_hdr
->sh_info
);
7485 unsigned char *lgot_masks
= (unsigned char *)
7486 (local_plt
+ symtab_hdr
->sh_info
);
7487 tls_mask
= &lgot_masks
[r_symndx
];
7489 *tls_maskp
= tls_mask
;
7495 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7496 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7497 type suitable for optimization, and 1 otherwise. */
7500 get_tls_mask (unsigned char **tls_maskp
,
7501 unsigned long *toc_symndx
,
7502 bfd_vma
*toc_addend
,
7503 Elf_Internal_Sym
**locsymsp
,
7504 const Elf_Internal_Rela
*rel
,
7507 unsigned long r_symndx
;
7509 struct elf_link_hash_entry
*h
;
7510 Elf_Internal_Sym
*sym
;
7514 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7515 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7518 if ((*tls_maskp
!= NULL
7519 && (**tls_maskp
& TLS_TLS
) != 0
7520 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7522 || ppc64_elf_section_data (sec
) == NULL
7523 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7526 /* Look inside a TOC section too. */
7529 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7530 off
= h
->root
.u
.def
.value
;
7533 off
= sym
->st_value
;
7534 off
+= rel
->r_addend
;
7535 BFD_ASSERT (off
% 8 == 0);
7536 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7537 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7538 if (toc_symndx
!= NULL
)
7539 *toc_symndx
= r_symndx
;
7540 if (toc_addend
!= NULL
)
7541 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7542 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7544 if ((h
== NULL
|| is_static_defined (h
))
7545 && (next_r
== -1 || next_r
== -2))
7550 /* Find (or create) an entry in the tocsave hash table. */
7552 static struct tocsave_entry
*
7553 tocsave_find (struct ppc_link_hash_table
*htab
,
7554 enum insert_option insert
,
7555 Elf_Internal_Sym
**local_syms
,
7556 const Elf_Internal_Rela
*irela
,
7559 unsigned long r_indx
;
7560 struct elf_link_hash_entry
*h
;
7561 Elf_Internal_Sym
*sym
;
7562 struct tocsave_entry ent
, *p
;
7564 struct tocsave_entry
**slot
;
7566 r_indx
= ELF64_R_SYM (irela
->r_info
);
7567 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7569 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7572 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7577 ent
.offset
= h
->root
.u
.def
.value
;
7579 ent
.offset
= sym
->st_value
;
7580 ent
.offset
+= irela
->r_addend
;
7582 hash
= tocsave_htab_hash (&ent
);
7583 slot
= ((struct tocsave_entry
**)
7584 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7590 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7599 /* Adjust all global syms defined in opd sections. In gcc generated
7600 code for the old ABI, these will already have been done. */
7603 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7605 struct ppc_link_hash_entry
*eh
;
7607 struct _opd_sec_data
*opd
;
7609 if (h
->root
.type
== bfd_link_hash_indirect
)
7612 if (h
->root
.type
!= bfd_link_hash_defined
7613 && h
->root
.type
!= bfd_link_hash_defweak
)
7616 eh
= (struct ppc_link_hash_entry
*) h
;
7617 if (eh
->adjust_done
)
7620 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7621 opd
= get_opd_info (sym_sec
);
7622 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7624 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7627 /* This entry has been deleted. */
7628 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7631 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7632 if (discarded_section (dsec
))
7634 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7638 eh
->elf
.root
.u
.def
.value
= 0;
7639 eh
->elf
.root
.u
.def
.section
= dsec
;
7642 eh
->elf
.root
.u
.def
.value
+= adjust
;
7643 eh
->adjust_done
= 1;
7648 /* Handles decrementing dynamic reloc counts for the reloc specified by
7649 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7650 have already been determined. */
7653 dec_dynrel_count (bfd_vma r_info
,
7655 struct bfd_link_info
*info
,
7656 Elf_Internal_Sym
**local_syms
,
7657 struct elf_link_hash_entry
*h
,
7658 Elf_Internal_Sym
*sym
)
7660 enum elf_ppc64_reloc_type r_type
;
7661 asection
*sym_sec
= NULL
;
7663 /* Can this reloc be dynamic? This switch, and later tests here
7664 should be kept in sync with the code in check_relocs. */
7665 r_type
= ELF64_R_TYPE (r_info
);
7671 case R_PPC64_TPREL16
:
7672 case R_PPC64_TPREL16_LO
:
7673 case R_PPC64_TPREL16_HI
:
7674 case R_PPC64_TPREL16_HA
:
7675 case R_PPC64_TPREL16_DS
:
7676 case R_PPC64_TPREL16_LO_DS
:
7677 case R_PPC64_TPREL16_HIGH
:
7678 case R_PPC64_TPREL16_HIGHA
:
7679 case R_PPC64_TPREL16_HIGHER
:
7680 case R_PPC64_TPREL16_HIGHERA
:
7681 case R_PPC64_TPREL16_HIGHEST
:
7682 case R_PPC64_TPREL16_HIGHESTA
:
7683 case R_PPC64_TPREL64
:
7684 case R_PPC64_DTPMOD64
:
7685 case R_PPC64_DTPREL64
:
7686 case R_PPC64_ADDR64
:
7690 case R_PPC64_ADDR14
:
7691 case R_PPC64_ADDR14_BRNTAKEN
:
7692 case R_PPC64_ADDR14_BRTAKEN
:
7693 case R_PPC64_ADDR16
:
7694 case R_PPC64_ADDR16_DS
:
7695 case R_PPC64_ADDR16_HA
:
7696 case R_PPC64_ADDR16_HI
:
7697 case R_PPC64_ADDR16_HIGH
:
7698 case R_PPC64_ADDR16_HIGHA
:
7699 case R_PPC64_ADDR16_HIGHER
:
7700 case R_PPC64_ADDR16_HIGHERA
:
7701 case R_PPC64_ADDR16_HIGHEST
:
7702 case R_PPC64_ADDR16_HIGHESTA
:
7703 case R_PPC64_ADDR16_LO
:
7704 case R_PPC64_ADDR16_LO_DS
:
7705 case R_PPC64_ADDR24
:
7706 case R_PPC64_ADDR32
:
7707 case R_PPC64_UADDR16
:
7708 case R_PPC64_UADDR32
:
7709 case R_PPC64_UADDR64
:
7714 if (local_syms
!= NULL
)
7716 unsigned long r_symndx
;
7717 bfd
*ibfd
= sec
->owner
;
7719 r_symndx
= ELF64_R_SYM (r_info
);
7720 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7724 if ((bfd_link_pic (info
)
7725 && (must_be_dyn_reloc (info
, r_type
)
7727 && (!SYMBOLIC_BIND (info
, h
)
7728 || h
->root
.type
== bfd_link_hash_defweak
7729 || !h
->def_regular
))))
7730 || (ELIMINATE_COPY_RELOCS
7731 && !bfd_link_pic (info
)
7733 && (h
->root
.type
== bfd_link_hash_defweak
7734 || !h
->def_regular
)))
7741 struct elf_dyn_relocs
*p
;
7742 struct elf_dyn_relocs
**pp
;
7743 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
7745 /* elf_gc_sweep may have already removed all dyn relocs associated
7746 with local syms for a given section. Also, symbol flags are
7747 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7748 report a dynreloc miscount. */
7749 if (*pp
== NULL
&& info
->gc_sections
)
7752 while ((p
= *pp
) != NULL
)
7756 if (!must_be_dyn_reloc (info
, r_type
))
7768 struct ppc_dyn_relocs
*p
;
7769 struct ppc_dyn_relocs
**pp
;
7771 bfd_boolean is_ifunc
;
7773 if (local_syms
== NULL
)
7774 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7775 if (sym_sec
== NULL
)
7778 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7779 pp
= (struct ppc_dyn_relocs
**) vpp
;
7781 if (*pp
== NULL
&& info
->gc_sections
)
7784 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7785 while ((p
= *pp
) != NULL
)
7787 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7798 /* xgettext:c-format */
7799 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7801 bfd_set_error (bfd_error_bad_value
);
7805 /* Remove unused Official Procedure Descriptor entries. Currently we
7806 only remove those associated with functions in discarded link-once
7807 sections, or weakly defined functions that have been overridden. It
7808 would be possible to remove many more entries for statically linked
7812 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7815 bfd_boolean some_edited
= FALSE
;
7816 asection
*need_pad
= NULL
;
7817 struct ppc_link_hash_table
*htab
;
7819 htab
= ppc_hash_table (info
);
7823 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7826 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7827 Elf_Internal_Shdr
*symtab_hdr
;
7828 Elf_Internal_Sym
*local_syms
;
7829 struct _opd_sec_data
*opd
;
7830 bfd_boolean need_edit
, add_aux_fields
, broken
;
7831 bfd_size_type cnt_16b
= 0;
7833 if (!is_ppc64_elf (ibfd
))
7836 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7837 if (sec
== NULL
|| sec
->size
== 0)
7840 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7843 if (sec
->output_section
== bfd_abs_section_ptr
)
7846 /* Look through the section relocs. */
7847 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7851 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7853 /* Read the relocations. */
7854 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7856 if (relstart
== NULL
)
7859 /* First run through the relocs to check they are sane, and to
7860 determine whether we need to edit this opd section. */
7864 relend
= relstart
+ sec
->reloc_count
;
7865 for (rel
= relstart
; rel
< relend
; )
7867 enum elf_ppc64_reloc_type r_type
;
7868 unsigned long r_symndx
;
7870 struct elf_link_hash_entry
*h
;
7871 Elf_Internal_Sym
*sym
;
7874 /* .opd contains an array of 16 or 24 byte entries. We're
7875 only interested in the reloc pointing to a function entry
7877 offset
= rel
->r_offset
;
7878 if (rel
+ 1 == relend
7879 || rel
[1].r_offset
!= offset
+ 8)
7881 /* If someone messes with .opd alignment then after a
7882 "ld -r" we might have padding in the middle of .opd.
7883 Also, there's nothing to prevent someone putting
7884 something silly in .opd with the assembler. No .opd
7885 optimization for them! */
7888 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7893 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7894 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7897 /* xgettext:c-format */
7898 (_("%pB: unexpected reloc type %u in .opd section"),
7904 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7905 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7909 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7911 const char *sym_name
;
7913 sym_name
= h
->root
.root
.string
;
7915 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7919 /* xgettext:c-format */
7920 (_("%pB: undefined sym `%s' in .opd section"),
7926 /* opd entries are always for functions defined in the
7927 current input bfd. If the symbol isn't defined in the
7928 input bfd, then we won't be using the function in this
7929 bfd; It must be defined in a linkonce section in another
7930 bfd, or is weak. It's also possible that we are
7931 discarding the function due to a linker script /DISCARD/,
7932 which we test for via the output_section. */
7933 if (sym_sec
->owner
!= ibfd
7934 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7938 if (rel
+ 1 == relend
7939 || (rel
+ 2 < relend
7940 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7945 if (sec
->size
== offset
+ 24)
7950 if (sec
->size
== offset
+ 16)
7957 else if (rel
+ 1 < relend
7958 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7959 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7961 if (rel
[0].r_offset
== offset
+ 16)
7963 else if (rel
[0].r_offset
!= offset
+ 24)
7970 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7972 if (!broken
&& (need_edit
|| add_aux_fields
))
7974 Elf_Internal_Rela
*write_rel
;
7975 Elf_Internal_Shdr
*rel_hdr
;
7976 bfd_byte
*rptr
, *wptr
;
7977 bfd_byte
*new_contents
;
7980 new_contents
= NULL
;
7981 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7982 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7983 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7984 if (opd
->adjust
== NULL
)
7987 /* This seems a waste of time as input .opd sections are all
7988 zeros as generated by gcc, but I suppose there's no reason
7989 this will always be so. We might start putting something in
7990 the third word of .opd entries. */
7991 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7994 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7999 if (local_syms
!= NULL
8000 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8002 if (elf_section_data (sec
)->relocs
!= relstart
)
8006 sec
->contents
= loc
;
8007 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8010 elf_section_data (sec
)->relocs
= relstart
;
8012 new_contents
= sec
->contents
;
8015 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
8016 if (new_contents
== NULL
)
8020 wptr
= new_contents
;
8021 rptr
= sec
->contents
;
8022 write_rel
= relstart
;
8023 for (rel
= relstart
; rel
< relend
; )
8025 unsigned long r_symndx
;
8027 struct elf_link_hash_entry
*h
;
8028 struct ppc_link_hash_entry
*fdh
= NULL
;
8029 Elf_Internal_Sym
*sym
;
8031 Elf_Internal_Rela
*next_rel
;
8034 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8035 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8040 if (next_rel
+ 1 == relend
8041 || (next_rel
+ 2 < relend
8042 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
8045 /* See if the .opd entry is full 24 byte or
8046 16 byte (with fd_aux entry overlapped with next
8049 if (next_rel
== relend
)
8051 if (sec
->size
== rel
->r_offset
+ 16)
8054 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
8058 && h
->root
.root
.string
[0] == '.')
8060 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
8063 fdh
= ppc_follow_link (fdh
);
8064 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
8065 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8070 skip
= (sym_sec
->owner
!= ibfd
8071 || sym_sec
->output_section
== bfd_abs_section_ptr
);
8074 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
8076 /* Arrange for the function descriptor sym
8078 fdh
->elf
.root
.u
.def
.value
= 0;
8079 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
8081 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
8083 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
8088 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8092 if (++rel
== next_rel
)
8095 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8096 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8103 /* We'll be keeping this opd entry. */
8108 /* Redefine the function descriptor symbol to
8109 this location in the opd section. It is
8110 necessary to update the value here rather
8111 than using an array of adjustments as we do
8112 for local symbols, because various places
8113 in the generic ELF code use the value
8114 stored in u.def.value. */
8115 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
8116 fdh
->adjust_done
= 1;
8119 /* Local syms are a bit tricky. We could
8120 tweak them as they can be cached, but
8121 we'd need to look through the local syms
8122 for the function descriptor sym which we
8123 don't have at the moment. So keep an
8124 array of adjustments. */
8125 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
8126 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
8129 memcpy (wptr
, rptr
, opd_ent_size
);
8130 wptr
+= opd_ent_size
;
8131 if (add_aux_fields
&& opd_ent_size
== 16)
8133 memset (wptr
, '\0', 8);
8137 /* We need to adjust any reloc offsets to point to the
8139 for ( ; rel
!= next_rel
; ++rel
)
8141 rel
->r_offset
+= adjust
;
8142 if (write_rel
!= rel
)
8143 memcpy (write_rel
, rel
, sizeof (*rel
));
8148 rptr
+= opd_ent_size
;
8151 sec
->size
= wptr
- new_contents
;
8152 sec
->reloc_count
= write_rel
- relstart
;
8155 free (sec
->contents
);
8156 sec
->contents
= new_contents
;
8159 /* Fudge the header size too, as this is used later in
8160 elf_bfd_final_link if we are emitting relocs. */
8161 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
8162 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
8165 else if (elf_section_data (sec
)->relocs
!= relstart
)
8168 if (local_syms
!= NULL
8169 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8171 if (!info
->keep_memory
)
8174 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8179 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
8181 /* If we are doing a final link and the last .opd entry is just 16 byte
8182 long, add a 8 byte padding after it. */
8183 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
8187 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
8189 BFD_ASSERT (need_pad
->size
> 0);
8191 p
= bfd_malloc (need_pad
->size
+ 8);
8195 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
8196 p
, 0, need_pad
->size
))
8199 need_pad
->contents
= p
;
8200 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8204 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
8208 need_pad
->contents
= p
;
8211 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
8212 need_pad
->size
+= 8;
8218 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8221 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
8223 struct ppc_link_hash_table
*htab
;
8225 htab
= ppc_hash_table (info
);
8229 if (abiversion (info
->output_bfd
) == 1)
8232 if (htab
->params
->no_multi_toc
)
8233 htab
->do_multi_toc
= 0;
8234 else if (!htab
->do_multi_toc
)
8235 htab
->params
->no_multi_toc
= 1;
8237 /* Default to --no-plt-localentry, as this option can cause problems
8238 with symbol interposition. For example, glibc libpthread.so and
8239 libc.so duplicate many pthread symbols, with a fallback
8240 implementation in libc.so. In some cases the fallback does more
8241 work than the pthread implementation. __pthread_condattr_destroy
8242 is one such symbol: the libpthread.so implementation is
8243 localentry:0 while the libc.so implementation is localentry:8.
8244 An app that "cleverly" uses dlopen to only load necessary
8245 libraries at runtime may omit loading libpthread.so when not
8246 running multi-threaded, which then results in the libc.so
8247 fallback symbols being used and ld.so complaining. Now there
8248 are workarounds in ld (see non_zero_localentry) to detect the
8249 pthread situation, but that may not be the only case where
8250 --plt-localentry can cause trouble. */
8251 if (htab
->params
->plt_localentry0
< 0)
8252 htab
->params
->plt_localentry0
= 0;
8253 if (htab
->params
->plt_localentry0
8254 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
8255 FALSE
, FALSE
, FALSE
) == NULL
)
8257 (_("warning: --plt-localentry is especially dangerous without "
8258 "ld.so support to detect ABI violations"));
8260 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
8261 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
8262 FALSE
, FALSE
, TRUE
));
8263 /* Move dynamic linking info to the function descriptor sym. */
8264 if (htab
->tls_get_addr
!= NULL
)
8265 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
8266 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
8267 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
8268 FALSE
, FALSE
, TRUE
));
8269 if (htab
->params
->tls_get_addr_opt
)
8271 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
8273 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8274 FALSE
, FALSE
, TRUE
);
8276 func_desc_adjust (opt
, info
);
8277 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8278 FALSE
, FALSE
, TRUE
);
8280 && (opt_fd
->root
.type
== bfd_link_hash_defined
8281 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8283 /* If glibc supports an optimized __tls_get_addr call stub,
8284 signalled by the presence of __tls_get_addr_opt, and we'll
8285 be calling __tls_get_addr via a plt call stub, then
8286 make __tls_get_addr point to __tls_get_addr_opt. */
8287 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
8288 if (htab
->elf
.dynamic_sections_created
8290 && (tga_fd
->type
== STT_FUNC
8291 || tga_fd
->needs_plt
)
8292 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8293 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
8295 struct plt_entry
*ent
;
8297 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8298 if (ent
->plt
.refcount
> 0)
8302 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8303 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8304 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8306 if (opt_fd
->dynindx
!= -1)
8308 /* Use __tls_get_addr_opt in dynamic relocations. */
8309 opt_fd
->dynindx
= -1;
8310 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8311 opt_fd
->dynstr_index
);
8312 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8315 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
8316 tga
= &htab
->tls_get_addr
->elf
;
8317 if (opt
!= NULL
&& tga
!= NULL
)
8319 tga
->root
.type
= bfd_link_hash_indirect
;
8320 tga
->root
.u
.i
.link
= &opt
->root
;
8321 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8323 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8325 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
8327 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8328 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8329 if (htab
->tls_get_addr
!= NULL
)
8331 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8332 htab
->tls_get_addr
->is_func
= 1;
8337 else if (htab
->params
->tls_get_addr_opt
< 0)
8338 htab
->params
->tls_get_addr_opt
= 0;
8340 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
8343 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8347 branch_reloc_hash_match (const bfd
*ibfd
,
8348 const Elf_Internal_Rela
*rel
,
8349 const struct ppc_link_hash_entry
*hash1
,
8350 const struct ppc_link_hash_entry
*hash2
)
8352 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8353 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8354 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8356 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8358 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8359 struct elf_link_hash_entry
*h
;
8361 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8362 h
= elf_follow_link (h
);
8363 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
8369 /* Run through all the TLS relocs looking for optimization
8370 opportunities. The linker has been hacked (see ppc64elf.em) to do
8371 a preliminary section layout so that we know the TLS segment
8372 offsets. We can't optimize earlier because some optimizations need
8373 to know the tp offset, and we need to optimize before allocating
8374 dynamic relocations. */
8377 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8381 struct ppc_link_hash_table
*htab
;
8382 unsigned char *toc_ref
;
8385 if (!bfd_link_executable (info
))
8388 htab
= ppc_hash_table (info
);
8392 /* Make two passes over the relocs. On the first pass, mark toc
8393 entries involved with tls relocs, and check that tls relocs
8394 involved in setting up a tls_get_addr call are indeed followed by
8395 such a call. If they are not, we can't do any tls optimization.
8396 On the second pass twiddle tls_mask flags to notify
8397 relocate_section that optimization can be done, and adjust got
8398 and plt refcounts. */
8400 for (pass
= 0; pass
< 2; ++pass
)
8401 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8403 Elf_Internal_Sym
*locsyms
= NULL
;
8404 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8406 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8407 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8409 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8410 bfd_boolean found_tls_get_addr_arg
= 0;
8412 /* Read the relocations. */
8413 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8415 if (relstart
== NULL
)
8421 relend
= relstart
+ sec
->reloc_count
;
8422 for (rel
= relstart
; rel
< relend
; rel
++)
8424 enum elf_ppc64_reloc_type r_type
;
8425 unsigned long r_symndx
;
8426 struct elf_link_hash_entry
*h
;
8427 Elf_Internal_Sym
*sym
;
8429 unsigned char *tls_mask
;
8430 unsigned char tls_set
, tls_clear
, tls_type
= 0;
8432 bfd_boolean ok_tprel
, is_local
;
8433 long toc_ref_index
= 0;
8434 int expecting_tls_get_addr
= 0;
8435 bfd_boolean ret
= FALSE
;
8437 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8438 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8442 if (elf_section_data (sec
)->relocs
!= relstart
)
8444 if (toc_ref
!= NULL
)
8447 && (elf_symtab_hdr (ibfd
).contents
8448 != (unsigned char *) locsyms
))
8455 if (h
->root
.type
== bfd_link_hash_defined
8456 || h
->root
.type
== bfd_link_hash_defweak
)
8457 value
= h
->root
.u
.def
.value
;
8458 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8462 found_tls_get_addr_arg
= 0;
8467 /* Symbols referenced by TLS relocs must be of type
8468 STT_TLS. So no need for .opd local sym adjust. */
8469 value
= sym
->st_value
;
8478 && h
->root
.type
== bfd_link_hash_undefweak
)
8480 else if (sym_sec
!= NULL
8481 && sym_sec
->output_section
!= NULL
)
8483 value
+= sym_sec
->output_offset
;
8484 value
+= sym_sec
->output_section
->vma
;
8485 value
-= htab
->elf
.tls_sec
->vma
;
8486 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
8487 < (bfd_vma
) 1 << 32);
8491 r_type
= ELF64_R_TYPE (rel
->r_info
);
8492 /* If this section has old-style __tls_get_addr calls
8493 without marker relocs, then check that each
8494 __tls_get_addr call reloc is preceded by a reloc
8495 that conceivably belongs to the __tls_get_addr arg
8496 setup insn. If we don't find matching arg setup
8497 relocs, don't do any tls optimization. */
8499 && sec
->has_tls_get_addr_call
8501 && (h
== &htab
->tls_get_addr
->elf
8502 || h
== &htab
->tls_get_addr_fd
->elf
)
8503 && !found_tls_get_addr_arg
8504 && is_branch_reloc (r_type
))
8506 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8507 "TLS optimization disabled\n"),
8508 ibfd
, sec
, rel
->r_offset
);
8513 found_tls_get_addr_arg
= 0;
8516 case R_PPC64_GOT_TLSLD16
:
8517 case R_PPC64_GOT_TLSLD16_LO
:
8518 expecting_tls_get_addr
= 1;
8519 found_tls_get_addr_arg
= 1;
8522 case R_PPC64_GOT_TLSLD16_HI
:
8523 case R_PPC64_GOT_TLSLD16_HA
:
8524 /* These relocs should never be against a symbol
8525 defined in a shared lib. Leave them alone if
8526 that turns out to be the case. */
8533 tls_type
= TLS_TLS
| TLS_LD
;
8536 case R_PPC64_GOT_TLSGD16
:
8537 case R_PPC64_GOT_TLSGD16_LO
:
8538 expecting_tls_get_addr
= 1;
8539 found_tls_get_addr_arg
= 1;
8542 case R_PPC64_GOT_TLSGD16_HI
:
8543 case R_PPC64_GOT_TLSGD16_HA
:
8549 tls_set
= TLS_TLS
| TLS_TPRELGD
;
8551 tls_type
= TLS_TLS
| TLS_GD
;
8554 case R_PPC64_GOT_TPREL16_DS
:
8555 case R_PPC64_GOT_TPREL16_LO_DS
:
8556 case R_PPC64_GOT_TPREL16_HI
:
8557 case R_PPC64_GOT_TPREL16_HA
:
8562 tls_clear
= TLS_TPREL
;
8563 tls_type
= TLS_TLS
| TLS_TPREL
;
8570 found_tls_get_addr_arg
= 1;
8575 case R_PPC64_TOC16_LO
:
8576 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8579 /* Mark this toc entry as referenced by a TLS
8580 code sequence. We can do that now in the
8581 case of R_PPC64_TLS, and after checking for
8582 tls_get_addr for the TOC16 relocs. */
8583 if (toc_ref
== NULL
)
8584 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8585 if (toc_ref
== NULL
)
8589 value
= h
->root
.u
.def
.value
;
8591 value
= sym
->st_value
;
8592 value
+= rel
->r_addend
;
8595 BFD_ASSERT (value
< toc
->size
8596 && toc
->output_offset
% 8 == 0);
8597 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8598 if (r_type
== R_PPC64_TLS
8599 || r_type
== R_PPC64_TLSGD
8600 || r_type
== R_PPC64_TLSLD
)
8602 toc_ref
[toc_ref_index
] = 1;
8606 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8611 expecting_tls_get_addr
= 2;
8614 case R_PPC64_TPREL64
:
8618 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8623 tls_set
= TLS_EXPLICIT
;
8624 tls_clear
= TLS_TPREL
;
8629 case R_PPC64_DTPMOD64
:
8633 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8635 if (rel
+ 1 < relend
8637 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8638 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8642 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8645 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
8654 tls_set
= TLS_EXPLICIT
;
8665 if (!expecting_tls_get_addr
8666 || !sec
->has_tls_get_addr_call
)
8669 if (rel
+ 1 < relend
8670 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8672 htab
->tls_get_addr_fd
))
8674 if (expecting_tls_get_addr
== 2)
8676 /* Check for toc tls entries. */
8677 unsigned char *toc_tls
;
8680 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8685 if (toc_tls
!= NULL
)
8687 if ((*toc_tls
& TLS_TLS
) != 0
8688 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8689 found_tls_get_addr_arg
= 1;
8691 toc_ref
[toc_ref_index
] = 1;
8697 /* Uh oh, we didn't find the expected call. We
8698 could just mark this symbol to exclude it
8699 from tls optimization but it's safer to skip
8700 the entire optimization. */
8701 /* xgettext:c-format */
8702 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8703 "TLS optimization disabled\n"),
8704 ibfd
, sec
, rel
->r_offset
);
8709 /* If we don't have old-style __tls_get_addr calls
8710 without TLSGD/TLSLD marker relocs, and we haven't
8711 found a new-style __tls_get_addr call with a
8712 marker for this symbol, then we either have a
8713 broken object file or an -mlongcall style
8714 indirect call to __tls_get_addr without a marker.
8715 Disable optimization in this case. */
8716 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8717 && (tls_set
& TLS_EXPLICIT
) == 0
8718 && !sec
->has_tls_get_addr_call
8719 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8720 != (TLS_TLS
| TLS_MARK
)))
8723 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
8725 struct plt_entry
*ent
;
8726 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8729 if (ent
->addend
== 0)
8731 if (ent
->plt
.refcount
> 0)
8733 ent
->plt
.refcount
-= 1;
8734 expecting_tls_get_addr
= 0;
8740 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
8742 struct plt_entry
*ent
;
8743 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8746 if (ent
->addend
== 0)
8748 if (ent
->plt
.refcount
> 0)
8749 ent
->plt
.refcount
-= 1;
8757 if ((tls_set
& TLS_EXPLICIT
) == 0)
8759 struct got_entry
*ent
;
8761 /* Adjust got entry for this reloc. */
8765 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8767 for (; ent
!= NULL
; ent
= ent
->next
)
8768 if (ent
->addend
== rel
->r_addend
8769 && ent
->owner
== ibfd
8770 && ent
->tls_type
== tls_type
)
8777 /* We managed to get rid of a got entry. */
8778 if (ent
->got
.refcount
> 0)
8779 ent
->got
.refcount
-= 1;
8784 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8785 we'll lose one or two dyn relocs. */
8786 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8790 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8792 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8798 *tls_mask
|= tls_set
;
8799 *tls_mask
&= ~tls_clear
;
8802 if (elf_section_data (sec
)->relocs
!= relstart
)
8807 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8809 if (!info
->keep_memory
)
8812 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8816 if (toc_ref
!= NULL
)
8818 htab
->do_tls_opt
= 1;
8822 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8823 the values of any global symbols in a toc section that has been
8824 edited. Globals in toc sections should be a rarity, so this function
8825 sets a flag if any are found in toc sections other than the one just
8826 edited, so that further hash table traversals can be avoided. */
8828 struct adjust_toc_info
8831 unsigned long *skip
;
8832 bfd_boolean global_toc_syms
;
8835 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8838 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8840 struct ppc_link_hash_entry
*eh
;
8841 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8844 if (h
->root
.type
!= bfd_link_hash_defined
8845 && h
->root
.type
!= bfd_link_hash_defweak
)
8848 eh
= (struct ppc_link_hash_entry
*) h
;
8849 if (eh
->adjust_done
)
8852 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8854 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8855 i
= toc_inf
->toc
->rawsize
>> 3;
8857 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8859 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8862 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8865 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8866 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8869 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8870 eh
->adjust_done
= 1;
8872 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8873 toc_inf
->global_toc_syms
= TRUE
;
8878 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8879 on a _LO variety toc/got reloc. */
8882 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8884 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8885 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8886 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8887 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8888 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8889 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8890 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8891 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8892 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8893 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8894 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8895 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8896 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8897 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8898 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8899 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8900 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8901 /* Exclude lfqu by testing reloc. If relocs are ever
8902 defined for the reduced D field in psq_lu then those
8903 will need testing too. */
8904 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8905 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8907 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8908 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8909 /* Exclude stfqu. psq_stu as above for psq_lu. */
8910 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8911 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8912 && (insn
& 1) == 0));
8915 /* Examine all relocs referencing .toc sections in order to remove
8916 unused .toc entries. */
8919 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8922 struct adjust_toc_info toc_inf
;
8923 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8925 htab
->do_toc_opt
= 1;
8926 toc_inf
.global_toc_syms
= TRUE
;
8927 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8929 asection
*toc
, *sec
;
8930 Elf_Internal_Shdr
*symtab_hdr
;
8931 Elf_Internal_Sym
*local_syms
;
8932 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8933 unsigned long *skip
, *drop
;
8934 unsigned char *used
;
8935 unsigned char *keep
, last
, some_unused
;
8937 if (!is_ppc64_elf (ibfd
))
8940 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8943 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8944 || discarded_section (toc
))
8949 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8951 /* Look at sections dropped from the final link. */
8954 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8956 if (sec
->reloc_count
== 0
8957 || !discarded_section (sec
)
8958 || get_opd_info (sec
)
8959 || (sec
->flags
& SEC_ALLOC
) == 0
8960 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8963 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
8964 if (relstart
== NULL
)
8967 /* Run through the relocs to see which toc entries might be
8969 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8971 enum elf_ppc64_reloc_type r_type
;
8972 unsigned long r_symndx
;
8974 struct elf_link_hash_entry
*h
;
8975 Elf_Internal_Sym
*sym
;
8978 r_type
= ELF64_R_TYPE (rel
->r_info
);
8985 case R_PPC64_TOC16_LO
:
8986 case R_PPC64_TOC16_HI
:
8987 case R_PPC64_TOC16_HA
:
8988 case R_PPC64_TOC16_DS
:
8989 case R_PPC64_TOC16_LO_DS
:
8993 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8994 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9002 val
= h
->root
.u
.def
.value
;
9004 val
= sym
->st_value
;
9005 val
+= rel
->r_addend
;
9007 if (val
>= toc
->size
)
9010 /* Anything in the toc ought to be aligned to 8 bytes.
9011 If not, don't mark as unused. */
9017 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9022 skip
[val
>> 3] = ref_from_discarded
;
9025 if (elf_section_data (sec
)->relocs
!= relstart
)
9029 /* For largetoc loads of address constants, we can convert
9030 . addis rx,2,addr@got@ha
9031 . ld ry,addr@got@l(rx)
9033 . addis rx,2,addr@toc@ha
9034 . addi ry,rx,addr@toc@l
9035 when addr is within 2G of the toc pointer. This then means
9036 that the word storing "addr" in the toc is no longer needed. */
9038 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9039 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9040 && toc
->reloc_count
!= 0)
9042 /* Read toc relocs. */
9043 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9045 if (toc_relocs
== NULL
)
9048 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9050 enum elf_ppc64_reloc_type r_type
;
9051 unsigned long r_symndx
;
9053 struct elf_link_hash_entry
*h
;
9054 Elf_Internal_Sym
*sym
;
9057 r_type
= ELF64_R_TYPE (rel
->r_info
);
9058 if (r_type
!= R_PPC64_ADDR64
)
9061 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9062 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9067 || sym_sec
->output_section
== NULL
9068 || discarded_section (sym_sec
))
9071 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9076 if (h
->type
== STT_GNU_IFUNC
)
9078 val
= h
->root
.u
.def
.value
;
9082 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9084 val
= sym
->st_value
;
9086 val
+= rel
->r_addend
;
9087 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9089 /* We don't yet know the exact toc pointer value, but we
9090 know it will be somewhere in the toc section. Don't
9091 optimize if the difference from any possible toc
9092 pointer is outside [ff..f80008000, 7fff7fff]. */
9093 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9094 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9097 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9098 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9103 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9108 skip
[rel
->r_offset
>> 3]
9109 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9116 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9120 if (local_syms
!= NULL
9121 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9125 && elf_section_data (sec
)->relocs
!= relstart
)
9127 if (toc_relocs
!= NULL
9128 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9135 /* Now check all kept sections that might reference the toc.
9136 Check the toc itself last. */
9137 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9140 sec
= (sec
== toc
? NULL
9141 : sec
->next
== NULL
? toc
9142 : sec
->next
== toc
&& toc
->next
? toc
->next
9147 if (sec
->reloc_count
== 0
9148 || discarded_section (sec
)
9149 || get_opd_info (sec
)
9150 || (sec
->flags
& SEC_ALLOC
) == 0
9151 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9154 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9156 if (relstart
== NULL
)
9162 /* Mark toc entries referenced as used. */
9166 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9168 enum elf_ppc64_reloc_type r_type
;
9169 unsigned long r_symndx
;
9171 struct elf_link_hash_entry
*h
;
9172 Elf_Internal_Sym
*sym
;
9174 enum {no_check
, check_lo
, check_ha
} insn_check
;
9176 r_type
= ELF64_R_TYPE (rel
->r_info
);
9180 insn_check
= no_check
;
9183 case R_PPC64_GOT_TLSLD16_HA
:
9184 case R_PPC64_GOT_TLSGD16_HA
:
9185 case R_PPC64_GOT_TPREL16_HA
:
9186 case R_PPC64_GOT_DTPREL16_HA
:
9187 case R_PPC64_GOT16_HA
:
9188 case R_PPC64_TOC16_HA
:
9189 insn_check
= check_ha
;
9192 case R_PPC64_GOT_TLSLD16_LO
:
9193 case R_PPC64_GOT_TLSGD16_LO
:
9194 case R_PPC64_GOT_TPREL16_LO_DS
:
9195 case R_PPC64_GOT_DTPREL16_LO_DS
:
9196 case R_PPC64_GOT16_LO
:
9197 case R_PPC64_GOT16_LO_DS
:
9198 case R_PPC64_TOC16_LO
:
9199 case R_PPC64_TOC16_LO_DS
:
9200 insn_check
= check_lo
;
9204 if (insn_check
!= no_check
)
9206 bfd_vma off
= rel
->r_offset
& ~3;
9207 unsigned char buf
[4];
9210 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9215 insn
= bfd_get_32 (ibfd
, buf
);
9216 if (insn_check
== check_lo
9217 ? !ok_lo_toc_insn (insn
, r_type
)
9218 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9219 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9223 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9224 sprintf (str
, "%#08x", insn
);
9225 info
->callbacks
->einfo
9226 /* xgettext:c-format */
9227 (_("%H: toc optimization is not supported for"
9228 " %s instruction\n"),
9229 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9236 case R_PPC64_TOC16_LO
:
9237 case R_PPC64_TOC16_HI
:
9238 case R_PPC64_TOC16_HA
:
9239 case R_PPC64_TOC16_DS
:
9240 case R_PPC64_TOC16_LO_DS
:
9241 /* In case we're taking addresses of toc entries. */
9242 case R_PPC64_ADDR64
:
9249 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9250 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9261 val
= h
->root
.u
.def
.value
;
9263 val
= sym
->st_value
;
9264 val
+= rel
->r_addend
;
9266 if (val
>= toc
->size
)
9269 if ((skip
[val
>> 3] & can_optimize
) != 0)
9276 case R_PPC64_TOC16_HA
:
9279 case R_PPC64_TOC16_LO_DS
:
9280 off
= rel
->r_offset
;
9281 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9282 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9288 if ((opc
& (0x3f << 2)) == (58u << 2))
9293 /* Wrong sort of reloc, or not a ld. We may
9294 as well clear ref_from_discarded too. */
9301 /* For the toc section, we only mark as used if this
9302 entry itself isn't unused. */
9303 else if ((used
[rel
->r_offset
>> 3]
9304 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9307 /* Do all the relocs again, to catch reference
9316 if (elf_section_data (sec
)->relocs
!= relstart
)
9320 /* Merge the used and skip arrays. Assume that TOC
9321 doublewords not appearing as either used or unused belong
9322 to an entry more than one doubleword in size. */
9323 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9324 drop
< skip
+ (toc
->size
+ 7) / 8;
9329 *drop
&= ~ref_from_discarded
;
9330 if ((*drop
& can_optimize
) != 0)
9334 else if ((*drop
& ref_from_discarded
) != 0)
9337 last
= ref_from_discarded
;
9347 bfd_byte
*contents
, *src
;
9349 Elf_Internal_Sym
*sym
;
9350 bfd_boolean local_toc_syms
= FALSE
;
9352 /* Shuffle the toc contents, and at the same time convert the
9353 skip array from booleans into offsets. */
9354 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9357 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9359 for (src
= contents
, off
= 0, drop
= skip
;
9360 src
< contents
+ toc
->size
;
9363 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9368 memcpy (src
- off
, src
, 8);
9372 toc
->rawsize
= toc
->size
;
9373 toc
->size
= src
- contents
- off
;
9375 /* Adjust addends for relocs against the toc section sym,
9376 and optimize any accesses we can. */
9377 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9379 if (sec
->reloc_count
== 0
9380 || discarded_section (sec
))
9383 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9385 if (relstart
== NULL
)
9388 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9390 enum elf_ppc64_reloc_type r_type
;
9391 unsigned long r_symndx
;
9393 struct elf_link_hash_entry
*h
;
9396 r_type
= ELF64_R_TYPE (rel
->r_info
);
9403 case R_PPC64_TOC16_LO
:
9404 case R_PPC64_TOC16_HI
:
9405 case R_PPC64_TOC16_HA
:
9406 case R_PPC64_TOC16_DS
:
9407 case R_PPC64_TOC16_LO_DS
:
9408 case R_PPC64_ADDR64
:
9412 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9413 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9421 val
= h
->root
.u
.def
.value
;
9424 val
= sym
->st_value
;
9426 local_toc_syms
= TRUE
;
9429 val
+= rel
->r_addend
;
9431 if (val
> toc
->rawsize
)
9433 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9435 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9437 Elf_Internal_Rela
*tocrel
9438 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9439 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9443 case R_PPC64_TOC16_HA
:
9444 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9447 case R_PPC64_TOC16_LO_DS
:
9448 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9452 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9454 info
->callbacks
->einfo
9455 /* xgettext:c-format */
9456 (_("%H: %s references "
9457 "optimized away TOC entry\n"),
9458 ibfd
, sec
, rel
->r_offset
,
9459 ppc64_elf_howto_table
[r_type
]->name
);
9460 bfd_set_error (bfd_error_bad_value
);
9463 rel
->r_addend
= tocrel
->r_addend
;
9464 elf_section_data (sec
)->relocs
= relstart
;
9468 if (h
!= NULL
|| sym
->st_value
!= 0)
9471 rel
->r_addend
-= skip
[val
>> 3];
9472 elf_section_data (sec
)->relocs
= relstart
;
9475 if (elf_section_data (sec
)->relocs
!= relstart
)
9479 /* We shouldn't have local or global symbols defined in the TOC,
9480 but handle them anyway. */
9481 if (local_syms
!= NULL
)
9482 for (sym
= local_syms
;
9483 sym
< local_syms
+ symtab_hdr
->sh_info
;
9485 if (sym
->st_value
!= 0
9486 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9490 if (sym
->st_value
> toc
->rawsize
)
9491 i
= toc
->rawsize
>> 3;
9493 i
= sym
->st_value
>> 3;
9495 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9499 (_("%s defined on removed toc entry"),
9500 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9503 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9504 sym
->st_value
= (bfd_vma
) i
<< 3;
9507 sym
->st_value
-= skip
[i
];
9508 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9511 /* Adjust any global syms defined in this toc input section. */
9512 if (toc_inf
.global_toc_syms
)
9515 toc_inf
.skip
= skip
;
9516 toc_inf
.global_toc_syms
= FALSE
;
9517 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9521 if (toc
->reloc_count
!= 0)
9523 Elf_Internal_Shdr
*rel_hdr
;
9524 Elf_Internal_Rela
*wrel
;
9527 /* Remove unused toc relocs, and adjust those we keep. */
9528 if (toc_relocs
== NULL
)
9529 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9531 if (toc_relocs
== NULL
)
9535 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9536 if ((skip
[rel
->r_offset
>> 3]
9537 & (ref_from_discarded
| can_optimize
)) == 0)
9539 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9540 wrel
->r_info
= rel
->r_info
;
9541 wrel
->r_addend
= rel
->r_addend
;
9544 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9545 &local_syms
, NULL
, NULL
))
9548 elf_section_data (toc
)->relocs
= toc_relocs
;
9549 toc
->reloc_count
= wrel
- toc_relocs
;
9550 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9551 sz
= rel_hdr
->sh_entsize
;
9552 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9555 else if (toc_relocs
!= NULL
9556 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9559 if (local_syms
!= NULL
9560 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9562 if (!info
->keep_memory
)
9565 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9573 /* Return true iff input section I references the TOC using
9574 instructions limited to +/-32k offsets. */
9577 ppc64_elf_has_small_toc_reloc (asection
*i
)
9579 return (is_ppc64_elf (i
->owner
)
9580 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9583 /* Allocate space for one GOT entry. */
9586 allocate_got (struct elf_link_hash_entry
*h
,
9587 struct bfd_link_info
*info
,
9588 struct got_entry
*gent
)
9590 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9591 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9592 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9594 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9595 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9596 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9598 gent
->got
.offset
= got
->size
;
9599 got
->size
+= entsize
;
9601 if (h
->type
== STT_GNU_IFUNC
)
9603 htab
->elf
.irelplt
->size
+= rentsize
;
9604 htab
->got_reli_size
+= rentsize
;
9606 else if (((bfd_link_pic (info
)
9607 && !((gent
->tls_type
& TLS_TPREL
) != 0
9608 && bfd_link_executable (info
)
9609 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9610 || (htab
->elf
.dynamic_sections_created
9612 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9613 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9615 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9616 relgot
->size
+= rentsize
;
9620 /* This function merges got entries in the same toc group. */
9623 merge_got_entries (struct got_entry
**pent
)
9625 struct got_entry
*ent
, *ent2
;
9627 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9628 if (!ent
->is_indirect
)
9629 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9630 if (!ent2
->is_indirect
9631 && ent2
->addend
== ent
->addend
9632 && ent2
->tls_type
== ent
->tls_type
9633 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9635 ent2
->is_indirect
= TRUE
;
9636 ent2
->got
.ent
= ent
;
9640 /* If H is undefined, make it dynamic if that makes sense. */
9643 ensure_undef_dynamic (struct bfd_link_info
*info
,
9644 struct elf_link_hash_entry
*h
)
9646 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9648 if (htab
->dynamic_sections_created
9649 && ((info
->dynamic_undefined_weak
!= 0
9650 && h
->root
.type
== bfd_link_hash_undefweak
)
9651 || h
->root
.type
== bfd_link_hash_undefined
)
9654 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9655 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9659 /* Allocate space in .plt, .got and associated reloc sections for
9663 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9665 struct bfd_link_info
*info
;
9666 struct ppc_link_hash_table
*htab
;
9668 struct ppc_link_hash_entry
*eh
;
9669 struct got_entry
**pgent
, *gent
;
9671 if (h
->root
.type
== bfd_link_hash_indirect
)
9674 info
= (struct bfd_link_info
*) inf
;
9675 htab
= ppc_hash_table (info
);
9679 eh
= (struct ppc_link_hash_entry
*) h
;
9680 /* Run through the TLS GD got entries first if we're changing them
9682 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
9683 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9684 if (gent
->got
.refcount
> 0
9685 && (gent
->tls_type
& TLS_GD
) != 0)
9687 /* This was a GD entry that has been converted to TPREL. If
9688 there happens to be a TPREL entry we can use that one. */
9689 struct got_entry
*ent
;
9690 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9691 if (ent
->got
.refcount
> 0
9692 && (ent
->tls_type
& TLS_TPREL
) != 0
9693 && ent
->addend
== gent
->addend
9694 && ent
->owner
== gent
->owner
)
9696 gent
->got
.refcount
= 0;
9700 /* If not, then we'll be using our own TPREL entry. */
9701 if (gent
->got
.refcount
!= 0)
9702 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9705 /* Remove any list entry that won't generate a word in the GOT before
9706 we call merge_got_entries. Otherwise we risk merging to empty
9708 pgent
= &h
->got
.glist
;
9709 while ((gent
= *pgent
) != NULL
)
9710 if (gent
->got
.refcount
> 0)
9712 if ((gent
->tls_type
& TLS_LD
) != 0
9715 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9716 *pgent
= gent
->next
;
9719 pgent
= &gent
->next
;
9722 *pgent
= gent
->next
;
9724 if (!htab
->do_multi_toc
)
9725 merge_got_entries (&h
->got
.glist
);
9727 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9728 if (!gent
->is_indirect
)
9730 /* Make sure this symbol is output as a dynamic symbol. */
9731 if (!ensure_undef_dynamic (info
, h
))
9734 if (!is_ppc64_elf (gent
->owner
))
9737 allocate_got (h
, info
, gent
);
9740 /* If no dynamic sections we can't have dynamic relocs, except for
9741 IFUNCs which are handled even in static executables. */
9742 if (!htab
->elf
.dynamic_sections_created
9743 && h
->type
!= STT_GNU_IFUNC
)
9744 eh
->dyn_relocs
= NULL
;
9746 /* Discard relocs on undefined symbols that must be local. */
9747 else if (h
->root
.type
== bfd_link_hash_undefined
9748 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9749 eh
->dyn_relocs
= NULL
;
9751 /* Also discard relocs on undefined weak syms with non-default
9752 visibility, or when dynamic_undefined_weak says so. */
9753 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9754 eh
->dyn_relocs
= NULL
;
9756 if (eh
->dyn_relocs
!= NULL
)
9758 struct elf_dyn_relocs
*p
, **pp
;
9760 /* In the shared -Bsymbolic case, discard space allocated for
9761 dynamic pc-relative relocs against symbols which turn out to
9762 be defined in regular objects. For the normal shared case,
9763 discard space for relocs that have become local due to symbol
9764 visibility changes. */
9766 if (bfd_link_pic (info
))
9768 /* Relocs that use pc_count are those that appear on a call
9769 insn, or certain REL relocs (see must_be_dyn_reloc) that
9770 can be generated via assembly. We want calls to
9771 protected symbols to resolve directly to the function
9772 rather than going via the plt. If people want function
9773 pointer comparisons to work as expected then they should
9774 avoid writing weird assembly. */
9775 if (SYMBOL_CALLS_LOCAL (info
, h
))
9777 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
9779 p
->count
-= p
->pc_count
;
9788 if (eh
->dyn_relocs
!= NULL
)
9790 /* Make sure this symbol is output as a dynamic symbol. */
9791 if (!ensure_undef_dynamic (info
, h
))
9795 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
9797 /* For the non-pic case, discard space for relocs against
9798 symbols which turn out to need copy relocs or are not
9800 if (h
->dynamic_adjusted
9802 && !ELF_COMMON_DEF_P (h
))
9804 /* Make sure this symbol is output as a dynamic symbol. */
9805 if (!ensure_undef_dynamic (info
, h
))
9808 if (h
->dynindx
== -1)
9809 eh
->dyn_relocs
= NULL
;
9812 eh
->dyn_relocs
= NULL
;
9815 /* Finally, allocate space. */
9816 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9818 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9819 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9820 sreloc
= htab
->elf
.irelplt
;
9821 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9825 if ((htab
->elf
.dynamic_sections_created
9826 && h
->dynindx
!= -1)
9827 || h
->type
== STT_GNU_IFUNC
)
9829 struct plt_entry
*pent
;
9830 bfd_boolean doneone
= FALSE
;
9831 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9832 if (pent
->plt
.refcount
> 0)
9834 if (!htab
->elf
.dynamic_sections_created
9835 || h
->dynindx
== -1)
9838 pent
->plt
.offset
= s
->size
;
9839 s
->size
+= PLT_ENTRY_SIZE (htab
);
9840 s
= htab
->elf
.irelplt
;
9844 /* If this is the first .plt entry, make room for the special
9848 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9850 pent
->plt
.offset
= s
->size
;
9852 /* Make room for this entry. */
9853 s
->size
+= PLT_ENTRY_SIZE (htab
);
9855 /* Make room for the .glink code. */
9858 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
9861 /* We need bigger stubs past index 32767. */
9862 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
9869 /* We also need to make an entry in the .rela.plt section. */
9870 s
= htab
->elf
.srelplt
;
9872 s
->size
+= sizeof (Elf64_External_Rela
);
9876 pent
->plt
.offset
= (bfd_vma
) -1;
9879 h
->plt
.plist
= NULL
;
9885 h
->plt
.plist
= NULL
;
9892 #define PPC_LO(v) ((v) & 0xffff)
9893 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9894 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9896 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9897 to set up space for global entry stubs. These are put in glink,
9898 after the branch table. */
9901 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9903 struct bfd_link_info
*info
;
9904 struct ppc_link_hash_table
*htab
;
9905 struct plt_entry
*pent
;
9908 if (h
->root
.type
== bfd_link_hash_indirect
)
9911 if (!h
->pointer_equality_needed
)
9918 htab
= ppc_hash_table (info
);
9922 s
= htab
->global_entry
;
9923 plt
= htab
->elf
.splt
;
9924 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9925 if (pent
->plt
.offset
!= (bfd_vma
) -1
9926 && pent
->addend
== 0)
9928 /* For ELFv2, if this symbol is not defined in a regular file
9929 and we are not generating a shared library or pie, then we
9930 need to define the symbol in the executable on a call stub.
9931 This is to avoid text relocations. */
9932 bfd_vma off
, stub_align
, stub_off
, stub_size
;
9933 unsigned int align_power
;
9937 if (htab
->params
->plt_stub_align
>= 0)
9938 align_power
= htab
->params
->plt_stub_align
;
9940 align_power
= -htab
->params
->plt_stub_align
;
9941 /* Setting section alignment is delayed until we know it is
9942 non-empty. Otherwise the .text output section will be
9943 aligned at least to plt_stub_align even when no global
9944 entry stubs are needed. */
9945 if (s
->alignment_power
< align_power
)
9946 s
->alignment_power
= align_power
;
9947 stub_align
= (bfd_vma
) 1 << align_power
;
9948 if (htab
->params
->plt_stub_align
>= 0
9949 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
9950 - (stub_off
& -stub_align
))
9951 > ((stub_size
- 1) & -stub_align
)))
9952 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
9953 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
9954 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
9955 /* Note that for --plt-stub-align negative we have a possible
9956 dependency between stub offset and size. Break that
9957 dependency by assuming the max stub size when calculating
9959 if (PPC_HA (off
) == 0)
9961 h
->root
.type
= bfd_link_hash_defined
;
9962 h
->root
.u
.def
.section
= s
;
9963 h
->root
.u
.def
.value
= stub_off
;
9964 s
->size
= stub_off
+ stub_size
;
9970 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9971 read-only sections. */
9974 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
9978 if (h
->root
.type
== bfd_link_hash_indirect
)
9981 sec
= readonly_dynrelocs (h
);
9984 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9986 info
->flags
|= DF_TEXTREL
;
9987 info
->callbacks
->minfo
9988 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
9989 sec
->owner
, h
->root
.root
.string
, sec
);
9991 /* Not an error, just cut short the traversal. */
9997 /* Set the sizes of the dynamic sections. */
10000 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10001 struct bfd_link_info
*info
)
10003 struct ppc_link_hash_table
*htab
;
10006 bfd_boolean relocs
;
10008 struct got_entry
*first_tlsld
;
10010 htab
= ppc_hash_table (info
);
10014 dynobj
= htab
->elf
.dynobj
;
10015 if (dynobj
== NULL
)
10018 if (htab
->elf
.dynamic_sections_created
)
10020 /* Set the contents of the .interp section to the interpreter. */
10021 if (bfd_link_executable (info
) && !info
->nointerp
)
10023 s
= bfd_get_linker_section (dynobj
, ".interp");
10026 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10027 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10031 /* Set up .got offsets for local syms, and space for local dynamic
10033 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10035 struct got_entry
**lgot_ents
;
10036 struct got_entry
**end_lgot_ents
;
10037 struct plt_entry
**local_plt
;
10038 struct plt_entry
**end_local_plt
;
10039 unsigned char *lgot_masks
;
10040 bfd_size_type locsymcount
;
10041 Elf_Internal_Shdr
*symtab_hdr
;
10043 if (!is_ppc64_elf (ibfd
))
10046 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10048 struct ppc_dyn_relocs
*p
;
10050 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10052 if (!bfd_is_abs_section (p
->sec
)
10053 && bfd_is_abs_section (p
->sec
->output_section
))
10055 /* Input section has been discarded, either because
10056 it is a copy of a linkonce section or due to
10057 linker script /DISCARD/, so we'll be discarding
10060 else if (p
->count
!= 0)
10062 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10064 srel
= htab
->elf
.irelplt
;
10065 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10066 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10067 info
->flags
|= DF_TEXTREL
;
10072 lgot_ents
= elf_local_got_ents (ibfd
);
10076 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10077 locsymcount
= symtab_hdr
->sh_info
;
10078 end_lgot_ents
= lgot_ents
+ locsymcount
;
10079 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10080 end_local_plt
= local_plt
+ locsymcount
;
10081 lgot_masks
= (unsigned char *) end_local_plt
;
10082 s
= ppc64_elf_tdata (ibfd
)->got
;
10083 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10085 struct got_entry
**pent
, *ent
;
10088 while ((ent
= *pent
) != NULL
)
10089 if (ent
->got
.refcount
> 0)
10091 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10093 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10098 unsigned int ent_size
= 8;
10099 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10101 ent
->got
.offset
= s
->size
;
10102 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10107 s
->size
+= ent_size
;
10108 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10110 htab
->elf
.irelplt
->size
+= rel_size
;
10111 htab
->got_reli_size
+= rel_size
;
10113 else if (bfd_link_pic (info
)
10114 && !((ent
->tls_type
& TLS_TPREL
) != 0
10115 && bfd_link_executable (info
)))
10117 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10118 srel
->size
+= rel_size
;
10127 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
10128 for (; local_plt
< end_local_plt
; ++local_plt
)
10130 struct plt_entry
*ent
;
10132 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10133 if (ent
->plt
.refcount
> 0)
10135 s
= htab
->elf
.iplt
;
10136 ent
->plt
.offset
= s
->size
;
10137 s
->size
+= PLT_ENTRY_SIZE (htab
);
10139 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10142 ent
->plt
.offset
= (bfd_vma
) -1;
10146 /* Allocate global sym .plt and .got entries, and space for global
10147 sym dynamic relocs. */
10148 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10150 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10151 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10153 first_tlsld
= NULL
;
10154 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10156 struct got_entry
*ent
;
10158 if (!is_ppc64_elf (ibfd
))
10161 ent
= ppc64_tlsld_got (ibfd
);
10162 if (ent
->got
.refcount
> 0)
10164 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10166 ent
->is_indirect
= TRUE
;
10167 ent
->got
.ent
= first_tlsld
;
10171 if (first_tlsld
== NULL
)
10173 s
= ppc64_elf_tdata (ibfd
)->got
;
10174 ent
->got
.offset
= s
->size
;
10177 if (bfd_link_pic (info
))
10179 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10180 srel
->size
+= sizeof (Elf64_External_Rela
);
10185 ent
->got
.offset
= (bfd_vma
) -1;
10188 /* We now have determined the sizes of the various dynamic sections.
10189 Allocate memory for them. */
10191 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10193 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10196 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10197 /* These haven't been allocated yet; don't strip. */
10199 else if (s
== htab
->elf
.sgot
10200 || s
== htab
->elf
.splt
10201 || s
== htab
->elf
.iplt
10202 || s
== htab
->glink
10203 || s
== htab
->global_entry
10204 || s
== htab
->elf
.sdynbss
10205 || s
== htab
->elf
.sdynrelro
)
10207 /* Strip this section if we don't need it; see the
10210 else if (s
== htab
->glink_eh_frame
)
10212 if (!bfd_is_abs_section (s
->output_section
))
10213 /* Not sized yet. */
10216 else if (CONST_STRNEQ (s
->name
, ".rela"))
10220 if (s
!= htab
->elf
.srelplt
)
10223 /* We use the reloc_count field as a counter if we need
10224 to copy relocs into the output file. */
10225 s
->reloc_count
= 0;
10230 /* It's not one of our sections, so don't allocate space. */
10236 /* If we don't need this section, strip it from the
10237 output file. This is mostly to handle .rela.bss and
10238 .rela.plt. We must create both sections in
10239 create_dynamic_sections, because they must be created
10240 before the linker maps input sections to output
10241 sections. The linker does that before
10242 adjust_dynamic_symbol is called, and it is that
10243 function which decides whether anything needs to go
10244 into these sections. */
10245 s
->flags
|= SEC_EXCLUDE
;
10249 if (bfd_is_abs_section (s
->output_section
))
10250 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10253 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10256 /* Allocate memory for the section contents. We use bfd_zalloc
10257 here in case unused entries are not reclaimed before the
10258 section's contents are written out. This should not happen,
10259 but this way if it does we get a R_PPC64_NONE reloc in .rela
10260 sections instead of garbage.
10261 We also rely on the section contents being zero when writing
10262 the GOT and .dynrelro. */
10263 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10264 if (s
->contents
== NULL
)
10268 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10270 if (!is_ppc64_elf (ibfd
))
10273 s
= ppc64_elf_tdata (ibfd
)->got
;
10274 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10277 s
->flags
|= SEC_EXCLUDE
;
10280 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10281 if (s
->contents
== NULL
)
10285 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10289 s
->flags
|= SEC_EXCLUDE
;
10292 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10293 if (s
->contents
== NULL
)
10296 s
->reloc_count
= 0;
10301 if (htab
->elf
.dynamic_sections_created
)
10303 bfd_boolean tls_opt
;
10305 /* Add some entries to the .dynamic section. We fill in the
10306 values later, in ppc64_elf_finish_dynamic_sections, but we
10307 must add the entries now so that we get the correct size for
10308 the .dynamic section. The DT_DEBUG entry is filled in by the
10309 dynamic linker and used by the debugger. */
10310 #define add_dynamic_entry(TAG, VAL) \
10311 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10313 if (bfd_link_executable (info
))
10315 if (!add_dynamic_entry (DT_DEBUG
, 0))
10319 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10321 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10322 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10323 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10324 || !add_dynamic_entry (DT_JMPREL
, 0)
10325 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10329 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10331 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10332 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10336 tls_opt
= (htab
->params
->tls_get_addr_opt
10337 && htab
->tls_get_addr_fd
!= NULL
10338 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10339 if (tls_opt
|| !htab
->opd_abi
)
10341 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10347 if (!add_dynamic_entry (DT_RELA
, 0)
10348 || !add_dynamic_entry (DT_RELASZ
, 0)
10349 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10352 /* If any dynamic relocs apply to a read-only section,
10353 then we need a DT_TEXTREL entry. */
10354 if ((info
->flags
& DF_TEXTREL
) == 0)
10355 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10357 if ((info
->flags
& DF_TEXTREL
) != 0)
10359 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10364 #undef add_dynamic_entry
10369 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10372 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10374 if (h
->plt
.plist
!= NULL
10376 && !h
->pointer_equality_needed
)
10379 return _bfd_elf_hash_symbol (h
);
10382 /* Determine the type of stub needed, if any, for a call. */
10384 static inline enum ppc_stub_type
10385 ppc_type_of_stub (asection
*input_sec
,
10386 const Elf_Internal_Rela
*rel
,
10387 struct ppc_link_hash_entry
**hash
,
10388 struct plt_entry
**plt_ent
,
10389 bfd_vma destination
,
10390 unsigned long local_off
)
10392 struct ppc_link_hash_entry
*h
= *hash
;
10394 bfd_vma branch_offset
;
10395 bfd_vma max_branch_offset
;
10396 enum elf_ppc64_reloc_type r_type
;
10400 struct plt_entry
*ent
;
10401 struct ppc_link_hash_entry
*fdh
= h
;
10403 && h
->oh
->is_func_descriptor
)
10405 fdh
= ppc_follow_link (h
->oh
);
10409 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10410 if (ent
->addend
== rel
->r_addend
10411 && ent
->plt
.offset
!= (bfd_vma
) -1)
10414 return ppc_stub_plt_call
;
10417 /* Here, we know we don't have a plt entry. If we don't have a
10418 either a defined function descriptor or a defined entry symbol
10419 in a regular object file, then it is pointless trying to make
10420 any other type of stub. */
10421 if (!is_static_defined (&fdh
->elf
)
10422 && !is_static_defined (&h
->elf
))
10423 return ppc_stub_none
;
10425 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10427 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10428 struct plt_entry
**local_plt
= (struct plt_entry
**)
10429 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10430 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10432 if (local_plt
[r_symndx
] != NULL
)
10434 struct plt_entry
*ent
;
10436 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10437 if (ent
->addend
== rel
->r_addend
10438 && ent
->plt
.offset
!= (bfd_vma
) -1)
10441 return ppc_stub_plt_call
;
10446 /* Determine where the call point is. */
10447 location
= (input_sec
->output_offset
10448 + input_sec
->output_section
->vma
10451 branch_offset
= destination
- location
;
10452 r_type
= ELF64_R_TYPE (rel
->r_info
);
10454 /* Determine if a long branch stub is needed. */
10455 max_branch_offset
= 1 << 25;
10456 if (r_type
!= R_PPC64_REL24
)
10457 max_branch_offset
= 1 << 15;
10459 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10460 /* We need a stub. Figure out whether a long_branch or plt_branch
10461 is needed later. */
10462 return ppc_stub_long_branch
;
10464 return ppc_stub_none
;
10467 /* With power7 weakly ordered memory model, it is possible for ld.so
10468 to update a plt entry in one thread and have another thread see a
10469 stale zero toc entry. To avoid this we need some sort of acquire
10470 barrier in the call stub. One solution is to make the load of the
10471 toc word seem to appear to depend on the load of the function entry
10472 word. Another solution is to test for r2 being zero, and branch to
10473 the appropriate glink entry if so.
10475 . fake dep barrier compare
10476 . ld 12,xxx(2) ld 12,xxx(2)
10477 . mtctr 12 mtctr 12
10478 . xor 11,12,12 ld 2,xxx+8(2)
10479 . add 2,2,11 cmpldi 2,0
10480 . ld 2,xxx+8(2) bnectr+
10481 . bctr b <glink_entry>
10483 The solution involving the compare turns out to be faster, so
10484 that's what we use unless the branch won't reach. */
10486 #define ALWAYS_USE_FAKE_DEP 0
10487 #define ALWAYS_EMIT_R2SAVE 0
10489 static inline unsigned int
10490 plt_stub_size (struct ppc_link_hash_table
*htab
,
10491 struct ppc_stub_hash_entry
*stub_entry
,
10494 unsigned size
= 12;
10496 if (ALWAYS_EMIT_R2SAVE
10497 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10499 if (PPC_HA (off
) != 0)
10504 if (htab
->params
->plt_static_chain
)
10506 if (htab
->params
->plt_thread_safe
10507 && htab
->elf
.dynamic_sections_created
10508 && stub_entry
->h
!= NULL
10509 && stub_entry
->h
->elf
.dynindx
!= -1)
10511 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10514 if (stub_entry
->h
!= NULL
10515 && (stub_entry
->h
== htab
->tls_get_addr_fd
10516 || stub_entry
->h
== htab
->tls_get_addr
)
10517 && htab
->params
->tls_get_addr_opt
)
10520 if (ALWAYS_EMIT_R2SAVE
10521 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10527 /* Depending on the sign of plt_stub_align:
10528 If positive, return the padding to align to a 2**plt_stub_align
10530 If negative, if this stub would cross fewer 2**plt_stub_align
10531 boundaries if we align, then return the padding needed to do so. */
10533 static inline unsigned int
10534 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10535 struct ppc_stub_hash_entry
*stub_entry
,
10539 unsigned stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10540 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10542 if (htab
->params
->plt_stub_align
>= 0)
10544 stub_align
= 1 << htab
->params
->plt_stub_align
;
10545 if ((stub_off
& (stub_align
- 1)) != 0)
10546 return stub_align
- (stub_off
& (stub_align
- 1));
10550 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10551 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10552 > ((stub_size
- 1) & -stub_align
))
10553 return stub_align
- (stub_off
& (stub_align
- 1));
10557 /* Build a .plt call stub. */
10559 static inline bfd_byte
*
10560 build_plt_stub (struct ppc_link_hash_table
*htab
,
10561 struct ppc_stub_hash_entry
*stub_entry
,
10562 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10564 bfd
*obfd
= htab
->params
->stub_bfd
;
10565 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10566 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10567 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10568 && htab
->elf
.dynamic_sections_created
10569 && stub_entry
->h
!= NULL
10570 && stub_entry
->h
->elf
.dynindx
!= -1);
10571 bfd_boolean use_fake_dep
= plt_thread_safe
;
10572 bfd_vma cmp_branch_off
= 0;
10574 if (!ALWAYS_USE_FAKE_DEP
10577 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10578 || stub_entry
->h
== htab
->tls_get_addr
)
10579 && htab
->params
->tls_get_addr_opt
))
10581 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10582 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10583 / PLT_ENTRY_SIZE (htab
));
10584 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
10587 if (pltindex
> 32768)
10588 glinkoff
+= (pltindex
- 32768) * 4;
10590 + htab
->glink
->output_offset
10591 + htab
->glink
->output_section
->vma
);
10592 from
= (p
- stub_entry
->group
->stub_sec
->contents
10593 + 4 * (ALWAYS_EMIT_R2SAVE
10594 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10595 + 4 * (PPC_HA (offset
) != 0)
10596 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10597 != PPC_HA (offset
))
10598 + 4 * (plt_static_chain
!= 0)
10600 + stub_entry
->group
->stub_sec
->output_offset
10601 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10602 cmp_branch_off
= to
- from
;
10603 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10606 if (PPC_HA (offset
) != 0)
10610 if (ALWAYS_EMIT_R2SAVE
10611 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10612 r
[0].r_offset
+= 4;
10613 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10614 r
[1].r_offset
= r
[0].r_offset
+ 4;
10615 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10616 r
[1].r_addend
= r
[0].r_addend
;
10619 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10621 r
[2].r_offset
= r
[1].r_offset
+ 4;
10622 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10623 r
[2].r_addend
= r
[0].r_addend
;
10627 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10628 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10629 r
[2].r_addend
= r
[0].r_addend
+ 8;
10630 if (plt_static_chain
)
10632 r
[3].r_offset
= r
[2].r_offset
+ 4;
10633 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10634 r
[3].r_addend
= r
[0].r_addend
+ 16;
10639 if (ALWAYS_EMIT_R2SAVE
10640 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10641 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10644 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10645 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10649 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10650 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10653 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10655 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10658 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10663 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10664 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10666 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10667 if (plt_static_chain
)
10668 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10675 if (ALWAYS_EMIT_R2SAVE
10676 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10677 r
[0].r_offset
+= 4;
10678 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10681 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10683 r
[1].r_offset
= r
[0].r_offset
+ 4;
10684 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10685 r
[1].r_addend
= r
[0].r_addend
;
10689 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10690 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10691 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10692 if (plt_static_chain
)
10694 r
[2].r_offset
= r
[1].r_offset
+ 4;
10695 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10696 r
[2].r_addend
= r
[0].r_addend
+ 8;
10701 if (ALWAYS_EMIT_R2SAVE
10702 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10703 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10704 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10706 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10708 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10711 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10716 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10717 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10719 if (plt_static_chain
)
10720 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10721 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10724 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10726 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10727 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10728 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10731 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10735 /* Build a special .plt call stub for __tls_get_addr. */
10737 #define LD_R11_0R3 0xe9630000
10738 #define LD_R12_0R3 0xe9830000
10739 #define MR_R0_R3 0x7c601b78
10740 #define CMPDI_R11_0 0x2c2b0000
10741 #define ADD_R3_R12_R13 0x7c6c6a14
10742 #define BEQLR 0x4d820020
10743 #define MR_R3_R0 0x7c030378
10744 #define STD_R11_0R1 0xf9610000
10745 #define BCTRL 0x4e800421
10746 #define LD_R11_0R1 0xe9610000
10747 #define MTLR_R11 0x7d6803a6
10749 static inline bfd_byte
*
10750 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10751 struct ppc_stub_hash_entry
*stub_entry
,
10752 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10754 bfd
*obfd
= htab
->params
->stub_bfd
;
10756 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10757 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10758 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10759 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10760 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10761 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10762 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10764 r
[0].r_offset
+= 7 * 4;
10765 if (!ALWAYS_EMIT_R2SAVE
10766 && stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
10767 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10769 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10770 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10773 r
[0].r_offset
+= 2 * 4;
10774 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10775 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10777 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10778 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10779 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10780 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10785 static Elf_Internal_Rela
*
10786 get_relocs (asection
*sec
, int count
)
10788 Elf_Internal_Rela
*relocs
;
10789 struct bfd_elf_section_data
*elfsec_data
;
10791 elfsec_data
= elf_section_data (sec
);
10792 relocs
= elfsec_data
->relocs
;
10793 if (relocs
== NULL
)
10795 bfd_size_type relsize
;
10796 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10797 relocs
= bfd_alloc (sec
->owner
, relsize
);
10798 if (relocs
== NULL
)
10800 elfsec_data
->relocs
= relocs
;
10801 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10802 sizeof (Elf_Internal_Shdr
));
10803 if (elfsec_data
->rela
.hdr
== NULL
)
10805 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10806 * sizeof (Elf64_External_Rela
));
10807 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10808 sec
->reloc_count
= 0;
10810 relocs
+= sec
->reloc_count
;
10811 sec
->reloc_count
+= count
;
10816 get_r2off (struct bfd_link_info
*info
,
10817 struct ppc_stub_hash_entry
*stub_entry
)
10819 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10820 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10824 /* Support linking -R objects. Get the toc pointer from the
10827 if (!htab
->opd_abi
)
10829 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10830 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10832 if (strcmp (opd
->name
, ".opd") != 0
10833 || opd
->reloc_count
!= 0)
10835 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for `%pT'\n"),
10836 stub_entry
->h
->elf
.root
.root
.string
);
10837 bfd_set_error (bfd_error_bad_value
);
10838 return (bfd_vma
) -1;
10840 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10841 return (bfd_vma
) -1;
10842 r2off
= bfd_get_64 (opd
->owner
, buf
);
10843 r2off
-= elf_gp (info
->output_bfd
);
10845 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10850 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10852 struct ppc_stub_hash_entry
*stub_entry
;
10853 struct ppc_branch_hash_entry
*br_entry
;
10854 struct bfd_link_info
*info
;
10855 struct ppc_link_hash_table
*htab
;
10859 Elf_Internal_Rela
*r
;
10862 /* Massage our args to the form they really have. */
10863 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10866 htab
= ppc_hash_table (info
);
10870 /* Make a note of the offset within the stubs for this entry. */
10871 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10872 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10874 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10875 switch (stub_entry
->stub_type
)
10877 case ppc_stub_long_branch
:
10878 case ppc_stub_long_branch_r2off
:
10879 /* Branches are relative. This is where we are going to. */
10880 dest
= (stub_entry
->target_value
10881 + stub_entry
->target_section
->output_offset
10882 + stub_entry
->target_section
->output_section
->vma
);
10883 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10886 /* And this is where we are coming from. */
10887 off
-= (stub_entry
->stub_offset
10888 + stub_entry
->group
->stub_sec
->output_offset
10889 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10892 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10894 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10896 if (r2off
== (bfd_vma
) -1)
10898 htab
->stub_error
= TRUE
;
10901 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10903 if (PPC_HA (r2off
) != 0)
10905 bfd_put_32 (htab
->params
->stub_bfd
,
10906 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10909 if (PPC_LO (r2off
) != 0)
10911 bfd_put_32 (htab
->params
->stub_bfd
,
10912 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10917 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
10920 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10923 (_("long branch stub `%s' offset overflow"),
10924 stub_entry
->root
.string
);
10925 htab
->stub_error
= TRUE
;
10929 if (info
->emitrelocations
)
10931 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10934 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
10935 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10936 r
->r_addend
= dest
;
10937 if (stub_entry
->h
!= NULL
)
10939 struct elf_link_hash_entry
**hashes
;
10940 unsigned long symndx
;
10941 struct ppc_link_hash_entry
*h
;
10943 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10944 if (hashes
== NULL
)
10946 bfd_size_type hsize
;
10948 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10949 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10950 if (hashes
== NULL
)
10952 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10953 htab
->stub_globals
= 1;
10955 symndx
= htab
->stub_globals
++;
10957 hashes
[symndx
] = &h
->elf
;
10958 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
10959 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10960 h
= ppc_follow_link (h
->oh
);
10961 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10962 /* H is an opd symbol. The addend must be zero. */
10966 off
= (h
->elf
.root
.u
.def
.value
10967 + h
->elf
.root
.u
.def
.section
->output_offset
10968 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10969 r
->r_addend
-= off
;
10975 case ppc_stub_plt_branch
:
10976 case ppc_stub_plt_branch_r2off
:
10977 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10978 stub_entry
->root
.string
+ 9,
10980 if (br_entry
== NULL
)
10982 _bfd_error_handler (_("can't find branch stub `%s'"),
10983 stub_entry
->root
.string
);
10984 htab
->stub_error
= TRUE
;
10988 dest
= (stub_entry
->target_value
10989 + stub_entry
->target_section
->output_offset
10990 + stub_entry
->target_section
->output_section
->vma
);
10991 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10992 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10994 bfd_put_64 (htab
->brlt
->owner
, dest
,
10995 htab
->brlt
->contents
+ br_entry
->offset
);
10997 if (br_entry
->iter
== htab
->stub_iteration
)
10999 br_entry
->iter
= 0;
11001 if (htab
->relbrlt
!= NULL
)
11003 /* Create a reloc for the branch lookup table entry. */
11004 Elf_Internal_Rela rela
;
11007 rela
.r_offset
= (br_entry
->offset
11008 + htab
->brlt
->output_offset
11009 + htab
->brlt
->output_section
->vma
);
11010 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11011 rela
.r_addend
= dest
;
11013 rl
= htab
->relbrlt
->contents
;
11014 rl
+= (htab
->relbrlt
->reloc_count
++
11015 * sizeof (Elf64_External_Rela
));
11016 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11018 else if (info
->emitrelocations
)
11020 r
= get_relocs (htab
->brlt
, 1);
11023 /* brlt, being SEC_LINKER_CREATED does not go through the
11024 normal reloc processing. Symbols and offsets are not
11025 translated from input file to output file form, so
11026 set up the offset per the output file. */
11027 r
->r_offset
= (br_entry
->offset
11028 + htab
->brlt
->output_offset
11029 + htab
->brlt
->output_section
->vma
);
11030 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11031 r
->r_addend
= dest
;
11035 dest
= (br_entry
->offset
11036 + htab
->brlt
->output_offset
11037 + htab
->brlt
->output_section
->vma
);
11040 - elf_gp (info
->output_bfd
)
11041 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11043 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11045 info
->callbacks
->einfo
11046 (_("%P: linkage table error against `%pT'\n"),
11047 stub_entry
->root
.string
);
11048 bfd_set_error (bfd_error_bad_value
);
11049 htab
->stub_error
= TRUE
;
11053 if (info
->emitrelocations
)
11055 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11058 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11059 if (bfd_big_endian (info
->output_bfd
))
11060 r
[0].r_offset
+= 2;
11061 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11062 r
[0].r_offset
+= 4;
11063 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11064 r
[0].r_addend
= dest
;
11065 if (PPC_HA (off
) != 0)
11067 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11068 r
[1].r_offset
= r
[0].r_offset
+ 4;
11069 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11070 r
[1].r_addend
= r
[0].r_addend
;
11075 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11077 if (PPC_HA (off
) != 0)
11079 bfd_put_32 (htab
->params
->stub_bfd
,
11080 ADDIS_R12_R2
| PPC_HA (off
), p
);
11082 bfd_put_32 (htab
->params
->stub_bfd
,
11083 LD_R12_0R12
| PPC_LO (off
), p
);
11086 bfd_put_32 (htab
->params
->stub_bfd
,
11087 LD_R12_0R2
| PPC_LO (off
), p
);
11091 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11093 if (r2off
== (bfd_vma
) -1)
11095 htab
->stub_error
= TRUE
;
11099 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11101 if (PPC_HA (off
) != 0)
11103 bfd_put_32 (htab
->params
->stub_bfd
,
11104 ADDIS_R12_R2
| PPC_HA (off
), p
);
11106 bfd_put_32 (htab
->params
->stub_bfd
,
11107 LD_R12_0R12
| PPC_LO (off
), p
);
11110 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11112 if (PPC_HA (r2off
) != 0)
11115 bfd_put_32 (htab
->params
->stub_bfd
,
11116 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11118 if (PPC_LO (r2off
) != 0)
11121 bfd_put_32 (htab
->params
->stub_bfd
,
11122 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11126 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
11128 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
11132 case ppc_stub_plt_call
:
11133 case ppc_stub_plt_call_r2save
:
11134 if (stub_entry
->h
!= NULL
11135 && stub_entry
->h
->is_func_descriptor
11136 && stub_entry
->h
->oh
!= NULL
)
11138 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11140 /* If the old-ABI "dot-symbol" is undefined make it weak so
11141 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11142 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11143 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11144 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11145 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11148 /* Now build the stub. */
11149 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11150 if (dest
>= (bfd_vma
) -2)
11153 plt
= htab
->elf
.splt
;
11154 if (!htab
->elf
.dynamic_sections_created
11155 || stub_entry
->h
== NULL
11156 || stub_entry
->h
->elf
.dynindx
== -1)
11157 plt
= htab
->elf
.iplt
;
11159 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
11161 if (stub_entry
->h
== NULL
11162 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
11164 Elf_Internal_Rela rela
;
11167 rela
.r_offset
= dest
;
11169 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
11171 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
11172 rela
.r_addend
= (stub_entry
->target_value
11173 + stub_entry
->target_section
->output_offset
11174 + stub_entry
->target_section
->output_section
->vma
);
11176 rl
= (htab
->elf
.irelplt
->contents
11177 + (htab
->elf
.irelplt
->reloc_count
++
11178 * sizeof (Elf64_External_Rela
)));
11179 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
11180 stub_entry
->plt_ent
->plt
.offset
|= 1;
11181 htab
->local_ifunc_resolver
= 1;
11185 - elf_gp (info
->output_bfd
)
11186 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11188 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11190 info
->callbacks
->einfo
11191 /* xgettext:c-format */
11192 (_("%P: linkage table error against `%pT'\n"),
11193 stub_entry
->h
!= NULL
11194 ? stub_entry
->h
->elf
.root
.root
.string
11196 bfd_set_error (bfd_error_bad_value
);
11197 htab
->stub_error
= TRUE
;
11201 if (htab
->params
->plt_stub_align
!= 0)
11203 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11205 stub_entry
->group
->stub_sec
->size
+= pad
;
11206 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11211 if (info
->emitrelocations
)
11213 r
= get_relocs (stub_entry
->group
->stub_sec
,
11214 ((PPC_HA (off
) != 0)
11216 ? 2 + (htab
->params
->plt_static_chain
11217 && PPC_HA (off
+ 16) == PPC_HA (off
))
11221 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11222 if (bfd_big_endian (info
->output_bfd
))
11223 r
[0].r_offset
+= 2;
11224 r
[0].r_addend
= dest
;
11226 if (stub_entry
->h
!= NULL
11227 && (stub_entry
->h
== htab
->tls_get_addr_fd
11228 || stub_entry
->h
== htab
->tls_get_addr
)
11229 && htab
->params
->tls_get_addr_opt
)
11230 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11232 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11235 case ppc_stub_save_res
:
11243 stub_entry
->group
->stub_sec
->size
+= p
- loc
;
11245 if (htab
->params
->emit_stub_syms
)
11247 struct elf_link_hash_entry
*h
;
11250 const char *const stub_str
[] = { "long_branch",
11251 "long_branch_r2off",
11253 "plt_branch_r2off",
11257 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11258 len2
= strlen (stub_entry
->root
.string
);
11259 name
= bfd_malloc (len1
+ len2
+ 2);
11262 memcpy (name
, stub_entry
->root
.string
, 9);
11263 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11264 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11265 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11268 if (h
->root
.type
== bfd_link_hash_new
)
11270 h
->root
.type
= bfd_link_hash_defined
;
11271 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11272 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11273 h
->ref_regular
= 1;
11274 h
->def_regular
= 1;
11275 h
->ref_regular_nonweak
= 1;
11276 h
->forced_local
= 1;
11278 h
->root
.linker_def
= 1;
11285 /* As above, but don't actually build the stub. Just bump offset so
11286 we know stub section sizes, and select plt_branch stubs where
11287 long_branch stubs won't do. */
11290 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11292 struct ppc_stub_hash_entry
*stub_entry
;
11293 struct bfd_link_info
*info
;
11294 struct ppc_link_hash_table
*htab
;
11298 /* Massage our args to the form they really have. */
11299 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11302 htab
= ppc_hash_table (info
);
11306 if (stub_entry
->h
!= NULL
11307 && stub_entry
->h
->save_res
11308 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11309 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11311 /* Don't make stubs to out-of-line register save/restore
11312 functions. Instead, emit copies of the functions. */
11313 stub_entry
->group
->needs_save_res
= 1;
11314 stub_entry
->stub_type
= ppc_stub_save_res
;
11318 if (stub_entry
->stub_type
== ppc_stub_plt_call
11319 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11322 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11323 if (off
>= (bfd_vma
) -2)
11325 plt
= htab
->elf
.splt
;
11326 if (!htab
->elf
.dynamic_sections_created
11327 || stub_entry
->h
== NULL
11328 || stub_entry
->h
->elf
.dynindx
== -1)
11329 plt
= htab
->elf
.iplt
;
11330 off
+= (plt
->output_offset
11331 + plt
->output_section
->vma
11332 - elf_gp (info
->output_bfd
)
11333 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11335 size
= plt_stub_size (htab
, stub_entry
, off
);
11336 if (stub_entry
->h
!= NULL
11337 && (stub_entry
->h
== htab
->tls_get_addr_fd
11338 || stub_entry
->h
== htab
->tls_get_addr
)
11339 && htab
->params
->tls_get_addr_opt
11340 && (ALWAYS_EMIT_R2SAVE
11341 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
11342 stub_entry
->group
->tls_get_addr_opt_bctrl
11343 = stub_entry
->group
->stub_sec
->size
+ size
- 5 * 4;
11345 if (htab
->params
->plt_stub_align
)
11346 size
+= plt_stub_pad (htab
, stub_entry
, off
);
11347 if (info
->emitrelocations
)
11349 stub_entry
->group
->stub_sec
->reloc_count
11350 += ((PPC_HA (off
) != 0)
11352 ? 2 + (htab
->params
->plt_static_chain
11353 && PPC_HA (off
+ 16) == PPC_HA (off
))
11355 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11360 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11363 bfd_vma local_off
= 0;
11365 off
= (stub_entry
->target_value
11366 + stub_entry
->target_section
->output_offset
11367 + stub_entry
->target_section
->output_section
->vma
);
11368 off
-= (stub_entry
->group
->stub_sec
->size
11369 + stub_entry
->group
->stub_sec
->output_offset
11370 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11372 /* Reset the stub type from the plt variant in case we now
11373 can reach with a shorter stub. */
11374 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
11375 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11378 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11380 r2off
= get_r2off (info
, stub_entry
);
11381 if (r2off
== (bfd_vma
) -1)
11383 htab
->stub_error
= TRUE
;
11387 if (PPC_HA (r2off
) != 0)
11389 if (PPC_LO (r2off
) != 0)
11394 local_off
= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11396 /* If the branch offset is too big, use a ppc_stub_plt_branch.
11397 Do the same for -R objects without function descriptors. */
11398 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26) - local_off
11399 || (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11401 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0))
11403 struct ppc_branch_hash_entry
*br_entry
;
11405 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11406 stub_entry
->root
.string
+ 9,
11408 if (br_entry
== NULL
)
11410 _bfd_error_handler (_("can't build branch stub `%s'"),
11411 stub_entry
->root
.string
);
11412 htab
->stub_error
= TRUE
;
11416 if (br_entry
->iter
!= htab
->stub_iteration
)
11418 br_entry
->iter
= htab
->stub_iteration
;
11419 br_entry
->offset
= htab
->brlt
->size
;
11420 htab
->brlt
->size
+= 8;
11422 if (htab
->relbrlt
!= NULL
)
11423 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11424 else if (info
->emitrelocations
)
11426 htab
->brlt
->reloc_count
+= 1;
11427 htab
->brlt
->flags
|= SEC_RELOC
;
11431 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11432 off
= (br_entry
->offset
11433 + htab
->brlt
->output_offset
11434 + htab
->brlt
->output_section
->vma
11435 - elf_gp (info
->output_bfd
)
11436 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11438 if (info
->emitrelocations
)
11440 stub_entry
->group
->stub_sec
->reloc_count
11441 += 1 + (PPC_HA (off
) != 0);
11442 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11445 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11448 if (PPC_HA (off
) != 0)
11454 if (PPC_HA (off
) != 0)
11457 if (PPC_HA (r2off
) != 0)
11459 if (PPC_LO (r2off
) != 0)
11463 else if (info
->emitrelocations
)
11465 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11466 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11470 stub_entry
->group
->stub_sec
->size
+= size
;
11474 /* Set up various things so that we can make a list of input sections
11475 for each output section included in the link. Returns -1 on error,
11476 0 when no stubs will be needed, and 1 on success. */
11479 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11483 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11488 htab
->sec_info_arr_size
= bfd_get_next_section_id ();
11489 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11490 htab
->sec_info
= bfd_zmalloc (amt
);
11491 if (htab
->sec_info
== NULL
)
11494 /* Set toc_off for com, und, abs and ind sections. */
11495 for (id
= 0; id
< 3; id
++)
11496 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11501 /* Set up for first pass at multitoc partitioning. */
11504 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11506 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11508 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11509 htab
->toc_bfd
= NULL
;
11510 htab
->toc_first_sec
= NULL
;
11513 /* The linker repeatedly calls this function for each TOC input section
11514 and linker generated GOT section. Group input bfds such that the toc
11515 within a group is less than 64k in size. */
11518 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11520 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11521 bfd_vma addr
, off
, limit
;
11526 if (!htab
->second_toc_pass
)
11528 /* Keep track of the first .toc or .got section for this input bfd. */
11529 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11533 htab
->toc_bfd
= isec
->owner
;
11534 htab
->toc_first_sec
= isec
;
11537 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11538 off
= addr
- htab
->toc_curr
;
11539 limit
= 0x80008000;
11540 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11542 if (off
+ isec
->size
> limit
)
11544 addr
= (htab
->toc_first_sec
->output_offset
11545 + htab
->toc_first_sec
->output_section
->vma
);
11546 htab
->toc_curr
= addr
;
11547 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11550 /* toc_curr is the base address of this toc group. Set elf_gp
11551 for the input section to be the offset relative to the
11552 output toc base plus 0x8000. Making the input elf_gp an
11553 offset allows us to move the toc as a whole without
11554 recalculating input elf_gp. */
11555 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
11556 off
+= TOC_BASE_OFF
;
11558 /* Die if someone uses a linker script that doesn't keep input
11559 file .toc and .got together. */
11561 && elf_gp (isec
->owner
) != 0
11562 && elf_gp (isec
->owner
) != off
)
11565 elf_gp (isec
->owner
) = off
;
11569 /* During the second pass toc_first_sec points to the start of
11570 a toc group, and toc_curr is used to track the old elf_gp.
11571 We use toc_bfd to ensure we only look at each bfd once. */
11572 if (htab
->toc_bfd
== isec
->owner
)
11574 htab
->toc_bfd
= isec
->owner
;
11576 if (htab
->toc_first_sec
== NULL
11577 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11579 htab
->toc_curr
= elf_gp (isec
->owner
);
11580 htab
->toc_first_sec
= isec
;
11582 addr
= (htab
->toc_first_sec
->output_offset
11583 + htab
->toc_first_sec
->output_section
->vma
);
11584 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
11585 elf_gp (isec
->owner
) = off
;
11590 /* Called via elf_link_hash_traverse to merge GOT entries for global
11594 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11596 if (h
->root
.type
== bfd_link_hash_indirect
)
11599 merge_got_entries (&h
->got
.glist
);
11604 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11608 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11610 struct got_entry
*gent
;
11612 if (h
->root
.type
== bfd_link_hash_indirect
)
11615 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11616 if (!gent
->is_indirect
)
11617 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11621 /* Called on the first multitoc pass after the last call to
11622 ppc64_elf_next_toc_section. This function removes duplicate GOT
11626 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11628 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11629 struct bfd
*ibfd
, *ibfd2
;
11630 bfd_boolean done_something
;
11632 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11634 if (!htab
->do_multi_toc
)
11637 /* Merge global sym got entries within a toc group. */
11638 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11640 /* And tlsld_got. */
11641 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11643 struct got_entry
*ent
, *ent2
;
11645 if (!is_ppc64_elf (ibfd
))
11648 ent
= ppc64_tlsld_got (ibfd
);
11649 if (!ent
->is_indirect
11650 && ent
->got
.offset
!= (bfd_vma
) -1)
11652 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11654 if (!is_ppc64_elf (ibfd2
))
11657 ent2
= ppc64_tlsld_got (ibfd2
);
11658 if (!ent2
->is_indirect
11659 && ent2
->got
.offset
!= (bfd_vma
) -1
11660 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11662 ent2
->is_indirect
= TRUE
;
11663 ent2
->got
.ent
= ent
;
11669 /* Zap sizes of got sections. */
11670 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11671 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11672 htab
->got_reli_size
= 0;
11674 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11676 asection
*got
, *relgot
;
11678 if (!is_ppc64_elf (ibfd
))
11681 got
= ppc64_elf_tdata (ibfd
)->got
;
11684 got
->rawsize
= got
->size
;
11686 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11687 relgot
->rawsize
= relgot
->size
;
11692 /* Now reallocate the got, local syms first. We don't need to
11693 allocate section contents again since we never increase size. */
11694 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11696 struct got_entry
**lgot_ents
;
11697 struct got_entry
**end_lgot_ents
;
11698 struct plt_entry
**local_plt
;
11699 struct plt_entry
**end_local_plt
;
11700 unsigned char *lgot_masks
;
11701 bfd_size_type locsymcount
;
11702 Elf_Internal_Shdr
*symtab_hdr
;
11705 if (!is_ppc64_elf (ibfd
))
11708 lgot_ents
= elf_local_got_ents (ibfd
);
11712 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11713 locsymcount
= symtab_hdr
->sh_info
;
11714 end_lgot_ents
= lgot_ents
+ locsymcount
;
11715 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11716 end_local_plt
= local_plt
+ locsymcount
;
11717 lgot_masks
= (unsigned char *) end_local_plt
;
11718 s
= ppc64_elf_tdata (ibfd
)->got
;
11719 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11721 struct got_entry
*ent
;
11723 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11725 unsigned int ent_size
= 8;
11726 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11728 ent
->got
.offset
= s
->size
;
11729 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11734 s
->size
+= ent_size
;
11735 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
11737 htab
->elf
.irelplt
->size
+= rel_size
;
11738 htab
->got_reli_size
+= rel_size
;
11740 else if (bfd_link_pic (info
)
11741 && !((ent
->tls_type
& TLS_TPREL
) != 0
11742 && bfd_link_executable (info
)))
11744 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11745 srel
->size
+= rel_size
;
11751 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11753 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11755 struct got_entry
*ent
;
11757 if (!is_ppc64_elf (ibfd
))
11760 ent
= ppc64_tlsld_got (ibfd
);
11761 if (!ent
->is_indirect
11762 && ent
->got
.offset
!= (bfd_vma
) -1)
11764 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11765 ent
->got
.offset
= s
->size
;
11767 if (bfd_link_pic (info
))
11769 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11770 srel
->size
+= sizeof (Elf64_External_Rela
);
11775 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11776 if (!done_something
)
11777 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11781 if (!is_ppc64_elf (ibfd
))
11784 got
= ppc64_elf_tdata (ibfd
)->got
;
11787 done_something
= got
->rawsize
!= got
->size
;
11788 if (done_something
)
11793 if (done_something
)
11794 (*htab
->params
->layout_sections_again
) ();
11796 /* Set up for second pass over toc sections to recalculate elf_gp
11797 on input sections. */
11798 htab
->toc_bfd
= NULL
;
11799 htab
->toc_first_sec
= NULL
;
11800 htab
->second_toc_pass
= TRUE
;
11801 return done_something
;
11804 /* Called after second pass of multitoc partitioning. */
11807 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11809 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11811 /* After the second pass, toc_curr tracks the TOC offset used
11812 for code sections below in ppc64_elf_next_input_section. */
11813 htab
->toc_curr
= TOC_BASE_OFF
;
11816 /* No toc references were found in ISEC. If the code in ISEC makes no
11817 calls, then there's no need to use toc adjusting stubs when branching
11818 into ISEC. Actually, indirect calls from ISEC are OK as they will
11819 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11820 needed, and 2 if a cyclical call-graph was found but no other reason
11821 for a stub was detected. If called from the top level, a return of
11822 2 means the same as a return of 0. */
11825 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11829 /* Mark this section as checked. */
11830 isec
->call_check_done
= 1;
11832 /* We know none of our code bearing sections will need toc stubs. */
11833 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11836 if (isec
->size
== 0)
11839 if (isec
->output_section
== NULL
)
11843 if (isec
->reloc_count
!= 0)
11845 Elf_Internal_Rela
*relstart
, *rel
;
11846 Elf_Internal_Sym
*local_syms
;
11847 struct ppc_link_hash_table
*htab
;
11849 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11850 info
->keep_memory
);
11851 if (relstart
== NULL
)
11854 /* Look for branches to outside of this section. */
11856 htab
= ppc_hash_table (info
);
11860 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11862 enum elf_ppc64_reloc_type r_type
;
11863 unsigned long r_symndx
;
11864 struct elf_link_hash_entry
*h
;
11865 struct ppc_link_hash_entry
*eh
;
11866 Elf_Internal_Sym
*sym
;
11868 struct _opd_sec_data
*opd
;
11872 r_type
= ELF64_R_TYPE (rel
->r_info
);
11873 if (r_type
!= R_PPC64_REL24
11874 && r_type
!= R_PPC64_REL14
11875 && r_type
!= R_PPC64_REL14_BRTAKEN
11876 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11879 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11880 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11887 /* Calls to dynamic lib functions go through a plt call stub
11889 eh
= (struct ppc_link_hash_entry
*) h
;
11891 && (eh
->elf
.plt
.plist
!= NULL
11893 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11899 if (sym_sec
== NULL
)
11900 /* Ignore other undefined symbols. */
11903 /* Assume branches to other sections not included in the
11904 link need stubs too, to cover -R and absolute syms. */
11905 if (sym_sec
->output_section
== NULL
)
11912 sym_value
= sym
->st_value
;
11915 if (h
->root
.type
!= bfd_link_hash_defined
11916 && h
->root
.type
!= bfd_link_hash_defweak
)
11918 sym_value
= h
->root
.u
.def
.value
;
11920 sym_value
+= rel
->r_addend
;
11922 /* If this branch reloc uses an opd sym, find the code section. */
11923 opd
= get_opd_info (sym_sec
);
11926 if (h
== NULL
&& opd
->adjust
!= NULL
)
11930 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11932 /* Assume deleted functions won't ever be called. */
11934 sym_value
+= adjust
;
11937 dest
= opd_entry_value (sym_sec
, sym_value
,
11938 &sym_sec
, NULL
, FALSE
);
11939 if (dest
== (bfd_vma
) -1)
11944 + sym_sec
->output_offset
11945 + sym_sec
->output_section
->vma
);
11947 /* Ignore branch to self. */
11948 if (sym_sec
== isec
)
11951 /* If the called function uses the toc, we need a stub. */
11952 if (sym_sec
->has_toc_reloc
11953 || sym_sec
->makes_toc_func_call
)
11959 /* Assume any branch that needs a long branch stub might in fact
11960 need a plt_branch stub. A plt_branch stub uses r2. */
11961 else if (dest
- (isec
->output_offset
11962 + isec
->output_section
->vma
11963 + rel
->r_offset
) + (1 << 25)
11964 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11972 /* If calling back to a section in the process of being
11973 tested, we can't say for sure that no toc adjusting stubs
11974 are needed, so don't return zero. */
11975 else if (sym_sec
->call_check_in_progress
)
11978 /* Branches to another section that itself doesn't have any TOC
11979 references are OK. Recursively call ourselves to check. */
11980 else if (!sym_sec
->call_check_done
)
11984 /* Mark current section as indeterminate, so that other
11985 sections that call back to current won't be marked as
11987 isec
->call_check_in_progress
= 1;
11988 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11989 isec
->call_check_in_progress
= 0;
12000 if (local_syms
!= NULL
12001 && (elf_symtab_hdr (isec
->owner
).contents
12002 != (unsigned char *) local_syms
))
12004 if (elf_section_data (isec
)->relocs
!= relstart
)
12009 && isec
->map_head
.s
!= NULL
12010 && (strcmp (isec
->output_section
->name
, ".init") == 0
12011 || strcmp (isec
->output_section
->name
, ".fini") == 0))
12013 if (isec
->map_head
.s
->has_toc_reloc
12014 || isec
->map_head
.s
->makes_toc_func_call
)
12016 else if (!isec
->map_head
.s
->call_check_done
)
12019 isec
->call_check_in_progress
= 1;
12020 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
12021 isec
->call_check_in_progress
= 0;
12028 isec
->makes_toc_func_call
= 1;
12033 /* The linker repeatedly calls this function for each input section,
12034 in the order that input sections are linked into output sections.
12035 Build lists of input sections to determine groupings between which
12036 we may insert linker stubs. */
12039 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12041 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12046 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12047 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12049 /* This happens to make the list in reverse order,
12050 which is what we want. */
12051 htab
->sec_info
[isec
->id
].u
.list
12052 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12053 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12056 if (htab
->multi_toc_needed
)
12058 /* Analyse sections that aren't already flagged as needing a
12059 valid toc pointer. Exclude .fixup for the linux kernel.
12060 .fixup contains branches, but only back to the function that
12061 hit an exception. */
12062 if (!(isec
->has_toc_reloc
12063 || (isec
->flags
& SEC_CODE
) == 0
12064 || strcmp (isec
->name
, ".fixup") == 0
12065 || isec
->call_check_done
))
12067 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12070 /* Make all sections use the TOC assigned for this object file.
12071 This will be wrong for pasted sections; We fix that in
12072 check_pasted_section(). */
12073 if (elf_gp (isec
->owner
) != 0)
12074 htab
->toc_curr
= elf_gp (isec
->owner
);
12077 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12081 /* Check that all .init and .fini sections use the same toc, if they
12082 have toc relocs. */
12085 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12087 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
12091 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12092 bfd_vma toc_off
= 0;
12095 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12096 if (i
->has_toc_reloc
)
12099 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12100 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
12105 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12106 if (i
->makes_toc_func_call
)
12108 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12112 /* Make sure the whole pasted function uses the same toc offset. */
12114 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12115 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
12121 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
12123 return (check_pasted_section (info
, ".init")
12124 & check_pasted_section (info
, ".fini"));
12127 /* See whether we can group stub sections together. Grouping stub
12128 sections may result in fewer stubs. More importantly, we need to
12129 put all .init* and .fini* stubs at the beginning of the .init or
12130 .fini output sections respectively, because glibc splits the
12131 _init and _fini functions into multiple parts. Putting a stub in
12132 the middle of a function is not a good idea. */
12135 group_sections (struct bfd_link_info
*info
,
12136 bfd_size_type stub_group_size
,
12137 bfd_boolean stubs_always_before_branch
)
12139 struct ppc_link_hash_table
*htab
;
12141 bfd_boolean suppress_size_errors
;
12143 htab
= ppc_hash_table (info
);
12147 suppress_size_errors
= FALSE
;
12148 if (stub_group_size
== 1)
12150 /* Default values. */
12151 if (stubs_always_before_branch
)
12152 stub_group_size
= 0x1e00000;
12154 stub_group_size
= 0x1c00000;
12155 suppress_size_errors
= TRUE
;
12158 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
12162 if (osec
->id
>= htab
->sec_info_arr_size
)
12165 tail
= htab
->sec_info
[osec
->id
].u
.list
;
12166 while (tail
!= NULL
)
12170 bfd_size_type total
;
12171 bfd_boolean big_sec
;
12173 struct map_stub
*group
;
12174 bfd_size_type group_size
;
12177 total
= tail
->size
;
12178 group_size
= (ppc64_elf_section_data (tail
) != NULL
12179 && ppc64_elf_section_data (tail
)->has_14bit_branch
12180 ? stub_group_size
>> 10 : stub_group_size
);
12182 big_sec
= total
> group_size
;
12183 if (big_sec
&& !suppress_size_errors
)
12184 /* xgettext:c-format */
12185 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
12186 tail
->owner
, tail
);
12187 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
12189 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
12190 && ((total
+= curr
->output_offset
- prev
->output_offset
)
12191 < (ppc64_elf_section_data (prev
) != NULL
12192 && ppc64_elf_section_data (prev
)->has_14bit_branch
12193 ? (group_size
= stub_group_size
>> 10) : group_size
))
12194 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12197 /* OK, the size from the start of CURR to the end is less
12198 than group_size and thus can be handled by one stub
12199 section. (or the tail section is itself larger than
12200 group_size, in which case we may be toast.) We should
12201 really be keeping track of the total size of stubs added
12202 here, as stubs contribute to the final output section
12203 size. That's a little tricky, and this way will only
12204 break if stubs added make the total size more than 2^25,
12205 ie. for the default stub_group_size, if stubs total more
12206 than 2097152 bytes, or nearly 75000 plt call stubs. */
12207 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
12210 group
->link_sec
= curr
;
12211 group
->stub_sec
= NULL
;
12212 group
->needs_save_res
= 0;
12213 group
->tls_get_addr_opt_bctrl
= -1u;
12214 group
->next
= htab
->group
;
12215 htab
->group
= group
;
12218 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12219 /* Set up this stub group. */
12220 htab
->sec_info
[tail
->id
].u
.group
= group
;
12222 while (tail
!= curr
&& (tail
= prev
) != NULL
);
12224 /* But wait, there's more! Input sections up to group_size
12225 bytes before the stub section can be handled by it too.
12226 Don't do this if we have a really large section after the
12227 stubs, as adding more stubs increases the chance that
12228 branches may not reach into the stub section. */
12229 if (!stubs_always_before_branch
&& !big_sec
)
12232 while (prev
!= NULL
12233 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12234 < (ppc64_elf_section_data (prev
) != NULL
12235 && ppc64_elf_section_data (prev
)->has_14bit_branch
12236 ? (group_size
= stub_group_size
>> 10) : group_size
))
12237 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12240 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12241 htab
->sec_info
[tail
->id
].u
.group
= group
;
12250 static const unsigned char glink_eh_frame_cie
[] =
12252 0, 0, 0, 16, /* length. */
12253 0, 0, 0, 0, /* id. */
12254 1, /* CIE version. */
12255 'z', 'R', 0, /* Augmentation string. */
12256 4, /* Code alignment. */
12257 0x78, /* Data alignment. */
12259 1, /* Augmentation size. */
12260 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12261 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
12265 stub_eh_frame_size (struct map_stub
*group
, size_t align
)
12267 size_t this_size
= 17;
12268 if (group
->tls_get_addr_opt_bctrl
!= -1u)
12270 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
12273 else if (to_bctrl
< 256)
12275 else if (to_bctrl
< 65536)
12281 this_size
= (this_size
+ align
- 1) & -align
;
12285 /* Stripping output sections is normally done before dynamic section
12286 symbols have been allocated. This function is called later, and
12287 handles cases like htab->brlt which is mapped to its own output
12291 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12293 if (isec
->size
== 0
12294 && isec
->output_section
->size
== 0
12295 && !(isec
->output_section
->flags
& SEC_KEEP
)
12296 && !bfd_section_removed_from_list (info
->output_bfd
,
12297 isec
->output_section
)
12298 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12300 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12301 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12302 info
->output_bfd
->section_count
--;
12306 /* Determine and set the size of the stub section for a final link.
12308 The basic idea here is to examine all the relocations looking for
12309 PC-relative calls to a target that is unreachable with a "bl"
12313 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12315 bfd_size_type stub_group_size
;
12316 bfd_boolean stubs_always_before_branch
;
12317 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12322 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12323 htab
->params
->plt_thread_safe
= 1;
12324 if (!htab
->opd_abi
)
12325 htab
->params
->plt_thread_safe
= 0;
12326 else if (htab
->params
->plt_thread_safe
== -1)
12328 static const char *const thread_starter
[] =
12332 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12334 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12335 "mq_notify", "create_timer",
12340 "GOMP_parallel_start",
12341 "GOMP_parallel_loop_static",
12342 "GOMP_parallel_loop_static_start",
12343 "GOMP_parallel_loop_dynamic",
12344 "GOMP_parallel_loop_dynamic_start",
12345 "GOMP_parallel_loop_guided",
12346 "GOMP_parallel_loop_guided_start",
12347 "GOMP_parallel_loop_runtime",
12348 "GOMP_parallel_loop_runtime_start",
12349 "GOMP_parallel_sections",
12350 "GOMP_parallel_sections_start",
12356 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12358 struct elf_link_hash_entry
*h
;
12359 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12360 FALSE
, FALSE
, TRUE
);
12361 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12362 if (htab
->params
->plt_thread_safe
)
12366 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12367 if (htab
->params
->group_size
< 0)
12368 stub_group_size
= -htab
->params
->group_size
;
12370 stub_group_size
= htab
->params
->group_size
;
12372 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12375 #define STUB_SHRINK_ITER 20
12376 /* Loop until no stubs added. After iteration 20 of this loop we may
12377 exit on a stub section shrinking. This is to break out of a
12378 pathological case where adding stubs on one iteration decreases
12379 section gaps (perhaps due to alignment), which then requires
12380 fewer or smaller stubs on the next iteration. */
12385 unsigned int bfd_indx
;
12386 struct map_stub
*group
;
12388 htab
->stub_iteration
+= 1;
12390 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12392 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12394 Elf_Internal_Shdr
*symtab_hdr
;
12396 Elf_Internal_Sym
*local_syms
= NULL
;
12398 if (!is_ppc64_elf (input_bfd
))
12401 /* We'll need the symbol table in a second. */
12402 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12403 if (symtab_hdr
->sh_info
== 0)
12406 /* Walk over each section attached to the input bfd. */
12407 for (section
= input_bfd
->sections
;
12409 section
= section
->next
)
12411 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12413 /* If there aren't any relocs, then there's nothing more
12415 if ((section
->flags
& SEC_RELOC
) == 0
12416 || (section
->flags
& SEC_ALLOC
) == 0
12417 || (section
->flags
& SEC_LOAD
) == 0
12418 || (section
->flags
& SEC_CODE
) == 0
12419 || section
->reloc_count
== 0)
12422 /* If this section is a link-once section that will be
12423 discarded, then don't create any stubs. */
12424 if (section
->output_section
== NULL
12425 || section
->output_section
->owner
!= info
->output_bfd
)
12428 /* Get the relocs. */
12430 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12431 info
->keep_memory
);
12432 if (internal_relocs
== NULL
)
12433 goto error_ret_free_local
;
12435 /* Now examine each relocation. */
12436 irela
= internal_relocs
;
12437 irelaend
= irela
+ section
->reloc_count
;
12438 for (; irela
< irelaend
; irela
++)
12440 enum elf_ppc64_reloc_type r_type
;
12441 unsigned int r_indx
;
12442 enum ppc_stub_type stub_type
;
12443 struct ppc_stub_hash_entry
*stub_entry
;
12444 asection
*sym_sec
, *code_sec
;
12445 bfd_vma sym_value
, code_value
;
12446 bfd_vma destination
;
12447 unsigned long local_off
;
12448 bfd_boolean ok_dest
;
12449 struct ppc_link_hash_entry
*hash
;
12450 struct ppc_link_hash_entry
*fdh
;
12451 struct elf_link_hash_entry
*h
;
12452 Elf_Internal_Sym
*sym
;
12454 const asection
*id_sec
;
12455 struct _opd_sec_data
*opd
;
12456 struct plt_entry
*plt_ent
;
12458 r_type
= ELF64_R_TYPE (irela
->r_info
);
12459 r_indx
= ELF64_R_SYM (irela
->r_info
);
12461 if (r_type
>= R_PPC64_max
)
12463 bfd_set_error (bfd_error_bad_value
);
12464 goto error_ret_free_internal
;
12467 /* Only look for stubs on branch instructions. */
12468 if (r_type
!= R_PPC64_REL24
12469 && r_type
!= R_PPC64_REL14
12470 && r_type
!= R_PPC64_REL14_BRTAKEN
12471 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12474 /* Now determine the call target, its name, value,
12476 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12477 r_indx
, input_bfd
))
12478 goto error_ret_free_internal
;
12479 hash
= (struct ppc_link_hash_entry
*) h
;
12486 sym_value
= sym
->st_value
;
12487 if (sym_sec
!= NULL
12488 && sym_sec
->output_section
!= NULL
)
12491 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12492 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12494 sym_value
= hash
->elf
.root
.u
.def
.value
;
12495 if (sym_sec
->output_section
!= NULL
)
12498 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12499 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12501 /* Recognise an old ABI func code entry sym, and
12502 use the func descriptor sym instead if it is
12504 if (hash
->elf
.root
.root
.string
[0] == '.'
12505 && hash
->oh
!= NULL
)
12507 fdh
= ppc_follow_link (hash
->oh
);
12508 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12509 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12511 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12512 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12513 if (sym_sec
->output_section
!= NULL
)
12522 bfd_set_error (bfd_error_bad_value
);
12523 goto error_ret_free_internal
;
12530 sym_value
+= irela
->r_addend
;
12531 destination
= (sym_value
12532 + sym_sec
->output_offset
12533 + sym_sec
->output_section
->vma
);
12534 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12539 code_sec
= sym_sec
;
12540 code_value
= sym_value
;
12541 opd
= get_opd_info (sym_sec
);
12546 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12548 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12551 code_value
+= adjust
;
12552 sym_value
+= adjust
;
12554 dest
= opd_entry_value (sym_sec
, sym_value
,
12555 &code_sec
, &code_value
, FALSE
);
12556 if (dest
!= (bfd_vma
) -1)
12558 destination
= dest
;
12561 /* Fixup old ABI sym to point at code
12563 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12564 hash
->elf
.root
.u
.def
.section
= code_sec
;
12565 hash
->elf
.root
.u
.def
.value
= code_value
;
12570 /* Determine what (if any) linker stub is needed. */
12572 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12573 &plt_ent
, destination
,
12576 if (stub_type
!= ppc_stub_plt_call
)
12578 /* Check whether we need a TOC adjusting stub.
12579 Since the linker pastes together pieces from
12580 different object files when creating the
12581 _init and _fini functions, it may be that a
12582 call to what looks like a local sym is in
12583 fact a call needing a TOC adjustment. */
12584 if (code_sec
!= NULL
12585 && code_sec
->output_section
!= NULL
12586 && (htab
->sec_info
[code_sec
->id
].toc_off
12587 != htab
->sec_info
[section
->id
].toc_off
)
12588 && (code_sec
->has_toc_reloc
12589 || code_sec
->makes_toc_func_call
))
12590 stub_type
= ppc_stub_long_branch_r2off
;
12593 if (stub_type
== ppc_stub_none
)
12596 /* __tls_get_addr calls might be eliminated. */
12597 if (stub_type
!= ppc_stub_plt_call
12599 && (hash
== htab
->tls_get_addr
12600 || hash
== htab
->tls_get_addr_fd
)
12601 && section
->has_tls_reloc
12602 && irela
!= internal_relocs
)
12604 /* Get tls info. */
12605 unsigned char *tls_mask
;
12607 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12608 irela
- 1, input_bfd
))
12609 goto error_ret_free_internal
;
12610 if ((*tls_mask
& TLS_TLS
) != 0)
12614 if (stub_type
== ppc_stub_plt_call
)
12617 && htab
->params
->plt_localentry0
!= 0
12618 && is_elfv2_localentry0 (&hash
->elf
))
12619 htab
->has_plt_localentry0
= 1;
12620 else if (irela
+ 1 < irelaend
12621 && irela
[1].r_offset
== irela
->r_offset
+ 4
12622 && (ELF64_R_TYPE (irela
[1].r_info
)
12623 == R_PPC64_TOCSAVE
))
12625 if (!tocsave_find (htab
, INSERT
,
12626 &local_syms
, irela
+ 1, input_bfd
))
12627 goto error_ret_free_internal
;
12630 stub_type
= ppc_stub_plt_call_r2save
;
12633 /* Support for grouping stub sections. */
12634 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12636 /* Get the name of this stub. */
12637 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12639 goto error_ret_free_internal
;
12641 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12642 stub_name
, FALSE
, FALSE
);
12643 if (stub_entry
!= NULL
)
12645 /* The proper stub has already been created. */
12647 if (stub_type
== ppc_stub_plt_call_r2save
)
12648 stub_entry
->stub_type
= stub_type
;
12652 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12653 if (stub_entry
== NULL
)
12656 error_ret_free_internal
:
12657 if (elf_section_data (section
)->relocs
== NULL
)
12658 free (internal_relocs
);
12659 error_ret_free_local
:
12660 if (local_syms
!= NULL
12661 && (symtab_hdr
->contents
12662 != (unsigned char *) local_syms
))
12667 stub_entry
->stub_type
= stub_type
;
12668 if (stub_type
!= ppc_stub_plt_call
12669 && stub_type
!= ppc_stub_plt_call_r2save
)
12671 stub_entry
->target_value
= code_value
;
12672 stub_entry
->target_section
= code_sec
;
12676 stub_entry
->target_value
= sym_value
;
12677 stub_entry
->target_section
= sym_sec
;
12679 stub_entry
->h
= hash
;
12680 stub_entry
->plt_ent
= plt_ent
;
12681 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12683 if (stub_entry
->h
!= NULL
)
12684 htab
->stub_globals
+= 1;
12687 /* We're done with the internal relocs, free them. */
12688 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12689 free (internal_relocs
);
12692 if (local_syms
!= NULL
12693 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12695 if (!info
->keep_memory
)
12698 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12702 /* We may have added some stubs. Find out the new size of the
12704 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12705 if (group
->stub_sec
!= NULL
)
12707 asection
*stub_sec
= group
->stub_sec
;
12709 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12710 || stub_sec
->rawsize
< stub_sec
->size
)
12711 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12712 stub_sec
->rawsize
= stub_sec
->size
;
12713 stub_sec
->size
= 0;
12714 stub_sec
->reloc_count
= 0;
12715 stub_sec
->flags
&= ~SEC_RELOC
;
12718 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12719 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
12720 htab
->brlt
->rawsize
= htab
->brlt
->size
;
12721 htab
->brlt
->size
= 0;
12722 htab
->brlt
->reloc_count
= 0;
12723 htab
->brlt
->flags
&= ~SEC_RELOC
;
12724 if (htab
->relbrlt
!= NULL
)
12725 htab
->relbrlt
->size
= 0;
12727 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12729 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12730 if (group
->needs_save_res
)
12731 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12733 if (info
->emitrelocations
12734 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12736 htab
->glink
->reloc_count
= 1;
12737 htab
->glink
->flags
|= SEC_RELOC
;
12740 if (htab
->glink_eh_frame
!= NULL
12741 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12742 && htab
->glink_eh_frame
->output_section
->size
> 8)
12744 size_t size
= 0, align
= 4;
12746 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12747 if (group
->stub_sec
!= NULL
)
12748 size
+= stub_eh_frame_size (group
, align
);
12749 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12750 size
+= (24 + align
- 1) & -align
;
12752 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12753 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12754 size
= (size
+ align
- 1) & -align
;
12755 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12756 htab
->glink_eh_frame
->size
= size
;
12759 if (htab
->params
->plt_stub_align
!= 0)
12760 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12761 if (group
->stub_sec
!= NULL
)
12763 int align
= abs (htab
->params
->plt_stub_align
);
12764 group
->stub_sec
->size
12765 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12768 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12769 if (group
->stub_sec
!= NULL
12770 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
12771 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12772 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
12776 && (htab
->brlt
->rawsize
== htab
->brlt
->size
12777 || (htab
->stub_iteration
> STUB_SHRINK_ITER
12778 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
12779 && (htab
->glink_eh_frame
== NULL
12780 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12783 /* Ask the linker to do its stuff. */
12784 (*htab
->params
->layout_sections_again
) ();
12787 if (htab
->glink_eh_frame
!= NULL
12788 && htab
->glink_eh_frame
->size
!= 0)
12791 bfd_byte
*p
, *last_fde
;
12792 size_t last_fde_len
, size
, align
, pad
;
12793 struct map_stub
*group
;
12795 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12798 htab
->glink_eh_frame
->contents
= p
;
12802 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12803 /* CIE length (rewrite in case little-endian). */
12804 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
12805 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12806 p
+= last_fde_len
+ 4;
12808 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12809 if (group
->stub_sec
!= NULL
)
12812 last_fde_len
= stub_eh_frame_size (group
, align
) - 4;
12814 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12817 val
= p
- htab
->glink_eh_frame
->contents
;
12818 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12820 /* Offset to stub section, written later. */
12822 /* stub section size. */
12823 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
12825 /* Augmentation. */
12827 if (group
->tls_get_addr_opt_bctrl
!= -1u)
12829 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
12831 /* This FDE needs more than just the default.
12832 Describe __tls_get_addr_opt stub LR. */
12834 *p
++ = DW_CFA_advance_loc
+ to_bctrl
;
12835 else if (to_bctrl
< 256)
12837 *p
++ = DW_CFA_advance_loc1
;
12840 else if (to_bctrl
< 65536)
12842 *p
++ = DW_CFA_advance_loc2
;
12843 bfd_put_16 (htab
->elf
.dynobj
, to_bctrl
, p
);
12848 *p
++ = DW_CFA_advance_loc4
;
12849 bfd_put_32 (htab
->elf
.dynobj
, to_bctrl
, p
);
12852 *p
++ = DW_CFA_offset_extended_sf
;
12854 *p
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
12855 *p
++ = DW_CFA_advance_loc
+ 4;
12856 *p
++ = DW_CFA_restore_extended
;
12860 p
= last_fde
+ last_fde_len
+ 4;
12862 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12865 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
12867 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12870 val
= p
- htab
->glink_eh_frame
->contents
;
12871 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12873 /* Offset to .glink, written later. */
12876 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12878 /* Augmentation. */
12881 *p
++ = DW_CFA_advance_loc
+ 1;
12882 *p
++ = DW_CFA_register
;
12884 *p
++ = htab
->opd_abi
? 12 : 0;
12885 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
12886 *p
++ = DW_CFA_restore_extended
;
12888 p
+= ((24 + align
- 1) & -align
) - 24;
12890 /* Subsume any padding into the last FDE if user .eh_frame
12891 sections are aligned more than glink_eh_frame. Otherwise any
12892 zero padding will be seen as a terminator. */
12893 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12894 size
= p
- htab
->glink_eh_frame
->contents
;
12895 pad
= ((size
+ align
- 1) & -align
) - size
;
12896 htab
->glink_eh_frame
->size
= size
+ pad
;
12897 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12900 maybe_strip_output (info
, htab
->brlt
);
12901 if (htab
->glink_eh_frame
!= NULL
)
12902 maybe_strip_output (info
, htab
->glink_eh_frame
);
12907 /* Called after we have determined section placement. If sections
12908 move, we'll be called again. Provide a value for TOCstart. */
12911 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12914 bfd_vma TOCstart
, adjust
;
12918 struct elf_link_hash_entry
*h
;
12919 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12921 if (is_elf_hash_table (htab
)
12922 && htab
->hgot
!= NULL
)
12926 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12927 if (is_elf_hash_table (htab
))
12931 && h
->root
.type
== bfd_link_hash_defined
12932 && !h
->root
.linker_def
12933 && (!is_elf_hash_table (htab
)
12934 || h
->def_regular
))
12936 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12937 + h
->root
.u
.def
.section
->output_offset
12938 + h
->root
.u
.def
.section
->output_section
->vma
);
12939 _bfd_set_gp_value (obfd
, TOCstart
);
12944 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12945 order. The TOC starts where the first of these sections starts. */
12946 s
= bfd_get_section_by_name (obfd
, ".got");
12947 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12948 s
= bfd_get_section_by_name (obfd
, ".toc");
12949 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12950 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12951 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12952 s
= bfd_get_section_by_name (obfd
, ".plt");
12953 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12955 /* This may happen for
12956 o references to TOC base (SYM@toc / TOC[tc0]) without a
12958 o bad linker script
12959 o --gc-sections and empty TOC sections
12961 FIXME: Warn user? */
12963 /* Look for a likely section. We probably won't even be
12965 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12966 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12968 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12971 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12972 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12973 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12976 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12977 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12981 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12982 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12988 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12990 /* Force alignment. */
12991 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12992 TOCstart
-= adjust
;
12993 _bfd_set_gp_value (obfd
, TOCstart
);
12995 if (info
!= NULL
&& s
!= NULL
)
12997 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13001 if (htab
->elf
.hgot
!= NULL
)
13003 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
13004 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
13009 struct bfd_link_hash_entry
*bh
= NULL
;
13010 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
13011 s
, TOC_BASE_OFF
- adjust
,
13012 NULL
, FALSE
, FALSE
, &bh
);
13018 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
13019 write out any global entry stubs. */
13022 build_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
13024 struct bfd_link_info
*info
;
13025 struct ppc_link_hash_table
*htab
;
13026 struct plt_entry
*pent
;
13029 if (h
->root
.type
== bfd_link_hash_indirect
)
13032 if (!h
->pointer_equality_needed
)
13035 if (h
->def_regular
)
13039 htab
= ppc_hash_table (info
);
13043 s
= htab
->global_entry
;
13044 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
13045 if (pent
->plt
.offset
!= (bfd_vma
) -1
13046 && pent
->addend
== 0)
13052 p
= s
->contents
+ h
->root
.u
.def
.value
;
13053 plt
= htab
->elf
.splt
;
13054 if (!htab
->elf
.dynamic_sections_created
13055 || h
->dynindx
== -1)
13056 plt
= htab
->elf
.iplt
;
13057 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
13058 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
13060 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
13062 info
->callbacks
->einfo
13063 (_("%P: linkage table error against `%pT'\n"),
13064 h
->root
.root
.string
);
13065 bfd_set_error (bfd_error_bad_value
);
13066 htab
->stub_error
= TRUE
;
13069 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
13070 if (htab
->params
->emit_stub_syms
)
13072 size_t len
= strlen (h
->root
.root
.string
);
13073 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
13078 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
13079 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
13082 if (h
->root
.type
== bfd_link_hash_new
)
13084 h
->root
.type
= bfd_link_hash_defined
;
13085 h
->root
.u
.def
.section
= s
;
13086 h
->root
.u
.def
.value
= p
- s
->contents
;
13087 h
->ref_regular
= 1;
13088 h
->def_regular
= 1;
13089 h
->ref_regular_nonweak
= 1;
13090 h
->forced_local
= 1;
13092 h
->root
.linker_def
= 1;
13096 if (PPC_HA (off
) != 0)
13098 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
13101 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
13103 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
13105 bfd_put_32 (s
->owner
, BCTR
, p
);
13111 /* Build all the stubs associated with the current output file.
13112 The stubs are kept in a hash table attached to the main linker
13113 hash table. This function is called via gldelf64ppc_finish. */
13116 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13119 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13120 struct map_stub
*group
;
13121 asection
*stub_sec
;
13123 int stub_sec_count
= 0;
13128 /* Allocate memory to hold the linker stubs. */
13129 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13130 if ((stub_sec
= group
->stub_sec
) != NULL
13131 && stub_sec
->size
!= 0)
13133 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
, stub_sec
->size
);
13134 if (stub_sec
->contents
== NULL
)
13136 stub_sec
->size
= 0;
13139 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13144 /* Build the .glink plt call stub. */
13145 if (htab
->params
->emit_stub_syms
)
13147 struct elf_link_hash_entry
*h
;
13148 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13149 TRUE
, FALSE
, FALSE
);
13152 if (h
->root
.type
== bfd_link_hash_new
)
13154 h
->root
.type
= bfd_link_hash_defined
;
13155 h
->root
.u
.def
.section
= htab
->glink
;
13156 h
->root
.u
.def
.value
= 8;
13157 h
->ref_regular
= 1;
13158 h
->def_regular
= 1;
13159 h
->ref_regular_nonweak
= 1;
13160 h
->forced_local
= 1;
13162 h
->root
.linker_def
= 1;
13165 plt0
= (htab
->elf
.splt
->output_section
->vma
13166 + htab
->elf
.splt
->output_offset
13168 if (info
->emitrelocations
)
13170 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13173 r
->r_offset
= (htab
->glink
->output_offset
13174 + htab
->glink
->output_section
->vma
);
13175 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13176 r
->r_addend
= plt0
;
13178 p
= htab
->glink
->contents
;
13179 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13180 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13184 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13186 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13188 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13190 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13192 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13194 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13196 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13198 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13200 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13202 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13207 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13209 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13211 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13213 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
13215 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13217 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13219 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13221 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13223 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13225 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13227 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13229 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13231 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13234 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13236 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
13238 /* Build the .glink lazy link call stubs. */
13240 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
13246 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13251 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13253 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13258 bfd_put_32 (htab
->glink
->owner
,
13259 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13265 /* Build .glink global entry stubs. */
13266 if (htab
->global_entry
!= NULL
&& htab
->global_entry
->size
!= 0)
13267 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs
, info
);
13269 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13271 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13273 if (htab
->brlt
->contents
== NULL
)
13276 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13278 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13279 htab
->relbrlt
->size
);
13280 if (htab
->relbrlt
->contents
== NULL
)
13284 /* Build the stubs as directed by the stub hash table. */
13285 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13287 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13288 if (group
->needs_save_res
)
13289 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13291 if (htab
->relbrlt
!= NULL
)
13292 htab
->relbrlt
->reloc_count
= 0;
13294 if (htab
->params
->plt_stub_align
!= 0)
13295 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13296 if ((stub_sec
= group
->stub_sec
) != NULL
)
13298 int align
= abs (htab
->params
->plt_stub_align
);
13299 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13302 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13303 if (group
->needs_save_res
)
13305 stub_sec
= group
->stub_sec
;
13306 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
13307 htab
->sfpr
->contents
, htab
->sfpr
->size
);
13308 if (htab
->params
->emit_stub_syms
)
13312 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13313 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13318 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13319 if ((stub_sec
= group
->stub_sec
) != NULL
)
13321 stub_sec_count
+= 1;
13322 if (stub_sec
->rawsize
!= stub_sec
->size
13323 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13324 || stub_sec
->rawsize
< stub_sec
->size
))
13330 htab
->stub_error
= TRUE
;
13331 _bfd_error_handler (_("stubs don't match calculated size"));
13334 if (htab
->stub_error
)
13340 *stats
= bfd_malloc (500);
13341 if (*stats
== NULL
)
13344 len
= sprintf (*stats
,
13345 ngettext ("linker stubs in %u group\n",
13346 "linker stubs in %u groups\n",
13349 sprintf (*stats
+ len
, _(" branch %lu\n"
13350 " toc adjust %lu\n"
13351 " long branch %lu\n"
13352 " long toc adj %lu\n"
13354 " plt call toc %lu\n"
13355 " global entry %lu"),
13356 htab
->stub_count
[ppc_stub_long_branch
- 1],
13357 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13358 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13359 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13360 htab
->stub_count
[ppc_stub_plt_call
- 1],
13361 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13362 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13367 /* What to do when ld finds relocations against symbols defined in
13368 discarded sections. */
13370 static unsigned int
13371 ppc64_elf_action_discarded (asection
*sec
)
13373 if (strcmp (".opd", sec
->name
) == 0)
13376 if (strcmp (".toc", sec
->name
) == 0)
13379 if (strcmp (".toc1", sec
->name
) == 0)
13382 return _bfd_elf_default_action_discarded (sec
);
13385 /* The RELOCATE_SECTION function is called by the ELF backend linker
13386 to handle the relocations for a section.
13388 The relocs are always passed as Rela structures; if the section
13389 actually uses Rel structures, the r_addend field will always be
13392 This function is responsible for adjust the section contents as
13393 necessary, and (if using Rela relocs and generating a
13394 relocatable output file) adjusting the reloc addend as
13397 This function does not have to worry about setting the reloc
13398 address or the reloc symbol index.
13400 LOCAL_SYMS is a pointer to the swapped in local symbols.
13402 LOCAL_SECTIONS is an array giving the section in the input file
13403 corresponding to the st_shndx field of each local symbol.
13405 The global hash table entry for the global symbols can be found
13406 via elf_sym_hashes (input_bfd).
13408 When generating relocatable output, this function must handle
13409 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13410 going to be the section symbol corresponding to the output
13411 section, which means that the addend must be adjusted
13415 ppc64_elf_relocate_section (bfd
*output_bfd
,
13416 struct bfd_link_info
*info
,
13418 asection
*input_section
,
13419 bfd_byte
*contents
,
13420 Elf_Internal_Rela
*relocs
,
13421 Elf_Internal_Sym
*local_syms
,
13422 asection
**local_sections
)
13424 struct ppc_link_hash_table
*htab
;
13425 Elf_Internal_Shdr
*symtab_hdr
;
13426 struct elf_link_hash_entry
**sym_hashes
;
13427 Elf_Internal_Rela
*rel
;
13428 Elf_Internal_Rela
*wrel
;
13429 Elf_Internal_Rela
*relend
;
13430 Elf_Internal_Rela outrel
;
13432 struct got_entry
**local_got_ents
;
13434 bfd_boolean ret
= TRUE
;
13435 bfd_boolean is_opd
;
13436 /* Assume 'at' branch hints. */
13437 bfd_boolean is_isa_v2
= TRUE
;
13438 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13440 /* Initialize howto table if needed. */
13441 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13444 htab
= ppc_hash_table (info
);
13448 /* Don't relocate stub sections. */
13449 if (input_section
->owner
== htab
->params
->stub_bfd
)
13452 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13454 local_got_ents
= elf_local_got_ents (input_bfd
);
13455 TOCstart
= elf_gp (output_bfd
);
13456 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13457 sym_hashes
= elf_sym_hashes (input_bfd
);
13458 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13460 rel
= wrel
= relocs
;
13461 relend
= relocs
+ input_section
->reloc_count
;
13462 for (; rel
< relend
; wrel
++, rel
++)
13464 enum elf_ppc64_reloc_type r_type
;
13466 bfd_reloc_status_type r
;
13467 Elf_Internal_Sym
*sym
;
13469 struct elf_link_hash_entry
*h_elf
;
13470 struct ppc_link_hash_entry
*h
;
13471 struct ppc_link_hash_entry
*fdh
;
13472 const char *sym_name
;
13473 unsigned long r_symndx
, toc_symndx
;
13474 bfd_vma toc_addend
;
13475 unsigned char tls_mask
, tls_gd
, tls_type
;
13476 unsigned char sym_type
;
13477 bfd_vma relocation
;
13478 bfd_boolean unresolved_reloc
;
13479 bfd_boolean warned
;
13480 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13483 struct ppc_stub_hash_entry
*stub_entry
;
13484 bfd_vma max_br_offset
;
13486 Elf_Internal_Rela orig_rel
;
13487 reloc_howto_type
*howto
;
13488 struct reloc_howto_struct alt_howto
;
13493 r_type
= ELF64_R_TYPE (rel
->r_info
);
13494 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13496 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13497 symbol of the previous ADDR64 reloc. The symbol gives us the
13498 proper TOC base to use. */
13499 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13501 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13503 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13509 unresolved_reloc
= FALSE
;
13512 if (r_symndx
< symtab_hdr
->sh_info
)
13514 /* It's a local symbol. */
13515 struct _opd_sec_data
*opd
;
13517 sym
= local_syms
+ r_symndx
;
13518 sec
= local_sections
[r_symndx
];
13519 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13520 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13521 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13522 opd
= get_opd_info (sec
);
13523 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13525 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13531 /* If this is a relocation against the opd section sym
13532 and we have edited .opd, adjust the reloc addend so
13533 that ld -r and ld --emit-relocs output is correct.
13534 If it is a reloc against some other .opd symbol,
13535 then the symbol value will be adjusted later. */
13536 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13537 rel
->r_addend
+= adjust
;
13539 relocation
+= adjust
;
13545 bfd_boolean ignored
;
13547 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13548 r_symndx
, symtab_hdr
, sym_hashes
,
13549 h_elf
, sec
, relocation
,
13550 unresolved_reloc
, warned
, ignored
);
13551 sym_name
= h_elf
->root
.root
.string
;
13552 sym_type
= h_elf
->type
;
13554 && sec
->owner
== output_bfd
13555 && strcmp (sec
->name
, ".opd") == 0)
13557 /* This is a symbol defined in a linker script. All
13558 such are defined in output sections, even those
13559 defined by simple assignment from a symbol defined in
13560 an input section. Transfer the symbol to an
13561 appropriate input .opd section, so that a branch to
13562 this symbol will be mapped to the location specified
13563 by the opd entry. */
13564 struct bfd_link_order
*lo
;
13565 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13566 if (lo
->type
== bfd_indirect_link_order
)
13568 asection
*isec
= lo
->u
.indirect
.section
;
13569 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13570 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13573 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13574 h_elf
->root
.u
.def
.section
= isec
;
13581 h
= (struct ppc_link_hash_entry
*) h_elf
;
13583 if (sec
!= NULL
&& discarded_section (sec
))
13585 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13586 input_bfd
, input_section
,
13587 contents
+ rel
->r_offset
);
13588 wrel
->r_offset
= rel
->r_offset
;
13590 wrel
->r_addend
= 0;
13592 /* For ld -r, remove relocations in debug sections against
13593 symbols defined in discarded sections. Not done for
13594 non-debug to preserve relocs in .eh_frame which the
13595 eh_frame editing code expects to be present. */
13596 if (bfd_link_relocatable (info
)
13597 && (input_section
->flags
& SEC_DEBUGGING
))
13603 if (bfd_link_relocatable (info
))
13606 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13608 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13609 sec
= bfd_abs_section_ptr
;
13610 unresolved_reloc
= FALSE
;
13613 /* TLS optimizations. Replace instruction sequences and relocs
13614 based on information we collected in tls_optimize. We edit
13615 RELOCS so that --emit-relocs will output something sensible
13616 for the final instruction stream. */
13621 tls_mask
= h
->tls_mask
;
13622 else if (local_got_ents
!= NULL
)
13624 struct plt_entry
**local_plt
= (struct plt_entry
**)
13625 (local_got_ents
+ symtab_hdr
->sh_info
);
13626 unsigned char *lgot_masks
= (unsigned char *)
13627 (local_plt
+ symtab_hdr
->sh_info
);
13628 tls_mask
= lgot_masks
[r_symndx
];
13630 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
13631 && (r_type
== R_PPC64_TLS
13632 || r_type
== R_PPC64_TLSGD
13633 || r_type
== R_PPC64_TLSLD
))
13635 /* Check for toc tls entries. */
13636 unsigned char *toc_tls
;
13638 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13639 &local_syms
, rel
, input_bfd
))
13643 tls_mask
= *toc_tls
;
13646 /* Check that tls relocs are used with tls syms, and non-tls
13647 relocs are used with non-tls syms. */
13648 if (r_symndx
!= STN_UNDEF
13649 && r_type
!= R_PPC64_NONE
13651 || h
->elf
.root
.type
== bfd_link_hash_defined
13652 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13653 && (IS_PPC64_TLS_RELOC (r_type
)
13654 != (sym_type
== STT_TLS
13655 || (sym_type
== STT_SECTION
13656 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13658 if ((tls_mask
& TLS_TLS
) != 0
13659 && (r_type
== R_PPC64_TLS
13660 || r_type
== R_PPC64_TLSGD
13661 || r_type
== R_PPC64_TLSLD
))
13662 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13665 info
->callbacks
->einfo
13666 (!IS_PPC64_TLS_RELOC (r_type
)
13667 /* xgettext:c-format */
13668 ? _("%H: %s used with TLS symbol `%pT'\n")
13669 /* xgettext:c-format */
13670 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13671 input_bfd
, input_section
, rel
->r_offset
,
13672 ppc64_elf_howto_table
[r_type
]->name
,
13676 /* Ensure reloc mapping code below stays sane. */
13677 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13678 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13679 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13680 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13681 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13682 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13683 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13684 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13685 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13686 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13694 case R_PPC64_LO_DS_OPT
:
13695 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
13696 if ((insn
& (0x3f << 26)) != 58u << 26)
13698 insn
+= (14u << 26) - (58u << 26);
13699 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13700 r_type
= R_PPC64_TOC16_LO
;
13701 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13704 case R_PPC64_TOC16
:
13705 case R_PPC64_TOC16_LO
:
13706 case R_PPC64_TOC16_DS
:
13707 case R_PPC64_TOC16_LO_DS
:
13709 /* Check for toc tls entries. */
13710 unsigned char *toc_tls
;
13713 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13714 &local_syms
, rel
, input_bfd
);
13720 tls_mask
= *toc_tls
;
13721 if (r_type
== R_PPC64_TOC16_DS
13722 || r_type
== R_PPC64_TOC16_LO_DS
)
13724 if ((tls_mask
& TLS_TLS
) != 0
13725 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13730 /* If we found a GD reloc pair, then we might be
13731 doing a GD->IE transition. */
13734 tls_gd
= TLS_TPRELGD
;
13735 if ((tls_mask
& TLS_TLS
) != 0
13736 && (tls_mask
& TLS_GD
) == 0)
13739 else if (retval
== 3)
13741 if ((tls_mask
& TLS_TLS
) != 0
13742 && (tls_mask
& TLS_LD
) == 0)
13750 case R_PPC64_GOT_TPREL16_HI
:
13751 case R_PPC64_GOT_TPREL16_HA
:
13752 if ((tls_mask
& TLS_TLS
) != 0
13753 && (tls_mask
& TLS_TPREL
) == 0)
13755 rel
->r_offset
-= d_offset
;
13756 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13757 r_type
= R_PPC64_NONE
;
13758 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13762 case R_PPC64_GOT_TPREL16_DS
:
13763 case R_PPC64_GOT_TPREL16_LO_DS
:
13764 if ((tls_mask
& TLS_TLS
) != 0
13765 && (tls_mask
& TLS_TPREL
) == 0)
13768 insn
= bfd_get_32 (input_bfd
,
13769 contents
+ rel
->r_offset
- d_offset
);
13771 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13772 bfd_put_32 (input_bfd
, insn
,
13773 contents
+ rel
->r_offset
- d_offset
);
13774 r_type
= R_PPC64_TPREL16_HA
;
13775 if (toc_symndx
!= 0)
13777 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13778 rel
->r_addend
= toc_addend
;
13779 /* We changed the symbol. Start over in order to
13780 get h, sym, sec etc. right. */
13784 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13789 if ((tls_mask
& TLS_TLS
) != 0
13790 && (tls_mask
& TLS_TPREL
) == 0)
13792 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13793 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13796 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
13797 /* Was PPC64_TLS which sits on insn boundary, now
13798 PPC64_TPREL16_LO which is at low-order half-word. */
13799 rel
->r_offset
+= d_offset
;
13800 r_type
= R_PPC64_TPREL16_LO
;
13801 if (toc_symndx
!= 0)
13803 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13804 rel
->r_addend
= toc_addend
;
13805 /* We changed the symbol. Start over in order to
13806 get h, sym, sec etc. right. */
13810 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13814 case R_PPC64_GOT_TLSGD16_HI
:
13815 case R_PPC64_GOT_TLSGD16_HA
:
13816 tls_gd
= TLS_TPRELGD
;
13817 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13821 case R_PPC64_GOT_TLSLD16_HI
:
13822 case R_PPC64_GOT_TLSLD16_HA
:
13823 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13826 if ((tls_mask
& tls_gd
) != 0)
13827 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13828 + R_PPC64_GOT_TPREL16_DS
);
13831 rel
->r_offset
-= d_offset
;
13832 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13833 r_type
= R_PPC64_NONE
;
13835 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13839 case R_PPC64_GOT_TLSGD16
:
13840 case R_PPC64_GOT_TLSGD16_LO
:
13841 tls_gd
= TLS_TPRELGD
;
13842 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13846 case R_PPC64_GOT_TLSLD16
:
13847 case R_PPC64_GOT_TLSLD16_LO
:
13848 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13850 unsigned int insn1
, insn2
;
13854 offset
= (bfd_vma
) -1;
13855 /* If not using the newer R_PPC64_TLSGD/LD to mark
13856 __tls_get_addr calls, we must trust that the call
13857 stays with its arg setup insns, ie. that the next
13858 reloc is the __tls_get_addr call associated with
13859 the current reloc. Edit both insns. */
13860 if (input_section
->has_tls_get_addr_call
13861 && rel
+ 1 < relend
13862 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13863 htab
->tls_get_addr
,
13864 htab
->tls_get_addr_fd
))
13865 offset
= rel
[1].r_offset
;
13866 /* We read the low GOT_TLS (or TOC16) insn because we
13867 need to keep the destination reg. It may be
13868 something other than the usual r3, and moved to r3
13869 before the call by intervening code. */
13870 insn1
= bfd_get_32 (input_bfd
,
13871 contents
+ rel
->r_offset
- d_offset
);
13872 if ((tls_mask
& tls_gd
) != 0)
13875 insn1
&= (0x1f << 21) | (0x1f << 16);
13876 insn1
|= 58 << 26; /* ld */
13877 insn2
= 0x7c636a14; /* add 3,3,13 */
13878 if (offset
!= (bfd_vma
) -1)
13879 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13880 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13881 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13882 + R_PPC64_GOT_TPREL16_DS
);
13884 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13885 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13890 insn1
&= 0x1f << 21;
13891 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13892 insn2
= 0x38630000; /* addi 3,3,0 */
13895 /* Was an LD reloc. */
13897 sec
= local_sections
[toc_symndx
];
13899 r_symndx
< symtab_hdr
->sh_info
;
13901 if (local_sections
[r_symndx
] == sec
)
13903 if (r_symndx
>= symtab_hdr
->sh_info
)
13904 r_symndx
= STN_UNDEF
;
13905 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13906 if (r_symndx
!= STN_UNDEF
)
13907 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13908 + sec
->output_offset
13909 + sec
->output_section
->vma
);
13911 else if (toc_symndx
!= 0)
13913 r_symndx
= toc_symndx
;
13914 rel
->r_addend
= toc_addend
;
13916 r_type
= R_PPC64_TPREL16_HA
;
13917 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13918 if (offset
!= (bfd_vma
) -1)
13920 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
13921 R_PPC64_TPREL16_LO
);
13922 rel
[1].r_offset
= offset
+ d_offset
;
13923 rel
[1].r_addend
= rel
->r_addend
;
13926 bfd_put_32 (input_bfd
, insn1
,
13927 contents
+ rel
->r_offset
- d_offset
);
13928 if (offset
!= (bfd_vma
) -1)
13929 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13930 if ((tls_mask
& tls_gd
) == 0
13931 && (tls_gd
== 0 || toc_symndx
!= 0))
13933 /* We changed the symbol. Start over in order
13934 to get h, sym, sec etc. right. */
13940 case R_PPC64_TLSGD
:
13941 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
13942 && rel
+ 1 < relend
)
13944 unsigned int insn2
;
13945 bfd_vma offset
= rel
->r_offset
;
13947 if ((tls_mask
& TLS_TPRELGD
) != 0)
13950 r_type
= R_PPC64_NONE
;
13951 insn2
= 0x7c636a14; /* add 3,3,13 */
13956 if (toc_symndx
!= 0)
13958 r_symndx
= toc_symndx
;
13959 rel
->r_addend
= toc_addend
;
13961 r_type
= R_PPC64_TPREL16_LO
;
13962 rel
->r_offset
= offset
+ d_offset
;
13963 insn2
= 0x38630000; /* addi 3,3,0 */
13965 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13966 /* Zap the reloc on the _tls_get_addr call too. */
13967 BFD_ASSERT (offset
== rel
[1].r_offset
);
13968 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13969 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13970 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
13975 case R_PPC64_TLSLD
:
13976 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
13977 && rel
+ 1 < relend
)
13979 unsigned int insn2
;
13980 bfd_vma offset
= rel
->r_offset
;
13983 sec
= local_sections
[toc_symndx
];
13985 r_symndx
< symtab_hdr
->sh_info
;
13987 if (local_sections
[r_symndx
] == sec
)
13989 if (r_symndx
>= symtab_hdr
->sh_info
)
13990 r_symndx
= STN_UNDEF
;
13991 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13992 if (r_symndx
!= STN_UNDEF
)
13993 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13994 + sec
->output_offset
13995 + sec
->output_section
->vma
);
13997 r_type
= R_PPC64_TPREL16_LO
;
13998 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13999 rel
->r_offset
= offset
+ d_offset
;
14000 /* Zap the reloc on the _tls_get_addr call too. */
14001 BFD_ASSERT (offset
== rel
[1].r_offset
);
14002 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14003 insn2
= 0x38630000; /* addi 3,3,0 */
14004 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14009 case R_PPC64_DTPMOD64
:
14010 if (rel
+ 1 < relend
14011 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
14012 && rel
[1].r_offset
== rel
->r_offset
+ 8)
14014 if ((tls_mask
& TLS_GD
) == 0)
14016 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
14017 if ((tls_mask
& TLS_TPRELGD
) != 0)
14018 r_type
= R_PPC64_TPREL64
;
14021 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14022 r_type
= R_PPC64_NONE
;
14024 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14029 if ((tls_mask
& TLS_LD
) == 0)
14031 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14032 r_type
= R_PPC64_NONE
;
14033 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14038 case R_PPC64_TPREL64
:
14039 if ((tls_mask
& TLS_TPREL
) == 0)
14041 r_type
= R_PPC64_NONE
;
14042 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14046 case R_PPC64_ENTRY
:
14047 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14048 if (!bfd_link_pic (info
)
14049 && !info
->traditional_format
14050 && relocation
+ 0x80008000 <= 0xffffffff)
14052 unsigned int insn1
, insn2
;
14054 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14055 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14056 if ((insn1
& ~0xfffc) == LD_R2_0R12
14057 && insn2
== ADD_R2_R2_R12
)
14059 bfd_put_32 (input_bfd
,
14060 LIS_R2
+ PPC_HA (relocation
),
14061 contents
+ rel
->r_offset
);
14062 bfd_put_32 (input_bfd
,
14063 ADDI_R2_R2
+ PPC_LO (relocation
),
14064 contents
+ rel
->r_offset
+ 4);
14069 relocation
-= (rel
->r_offset
14070 + input_section
->output_offset
14071 + input_section
->output_section
->vma
);
14072 if (relocation
+ 0x80008000 <= 0xffffffff)
14074 unsigned int insn1
, insn2
;
14076 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14077 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14078 if ((insn1
& ~0xfffc) == LD_R2_0R12
14079 && insn2
== ADD_R2_R2_R12
)
14081 bfd_put_32 (input_bfd
,
14082 ADDIS_R2_R12
+ PPC_HA (relocation
),
14083 contents
+ rel
->r_offset
);
14084 bfd_put_32 (input_bfd
,
14085 ADDI_R2_R2
+ PPC_LO (relocation
),
14086 contents
+ rel
->r_offset
+ 4);
14092 case R_PPC64_REL16_HA
:
14093 /* If we are generating a non-PIC executable, edit
14094 . 0: addis 2,12,.TOC.-0b@ha
14095 . addi 2,2,.TOC.-0b@l
14096 used by ELFv2 global entry points to set up r2, to
14099 if .TOC. is in range. */
14100 if (!bfd_link_pic (info
)
14101 && !info
->traditional_format
14103 && rel
->r_addend
== d_offset
14104 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
14105 && rel
+ 1 < relend
14106 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
14107 && rel
[1].r_offset
== rel
->r_offset
+ 4
14108 && rel
[1].r_addend
== rel
->r_addend
+ 4
14109 && relocation
+ 0x80008000 <= 0xffffffff)
14111 unsigned int insn1
, insn2
;
14112 bfd_vma offset
= rel
->r_offset
- d_offset
;
14113 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
14114 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14115 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
14116 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
14118 r_type
= R_PPC64_ADDR16_HA
;
14119 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14120 rel
->r_addend
-= d_offset
;
14121 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
14122 rel
[1].r_addend
-= d_offset
+ 4;
14123 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
14129 /* Handle other relocations that tweak non-addend part of insn. */
14131 max_br_offset
= 1 << 25;
14132 addend
= rel
->r_addend
;
14133 reloc_dest
= DEST_NORMAL
;
14139 case R_PPC64_TOCSAVE
:
14140 if (relocation
+ addend
== (rel
->r_offset
14141 + input_section
->output_offset
14142 + input_section
->output_section
->vma
)
14143 && tocsave_find (htab
, NO_INSERT
,
14144 &local_syms
, rel
, input_bfd
))
14146 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14148 || insn
== CROR_151515
|| insn
== CROR_313131
)
14149 bfd_put_32 (input_bfd
,
14150 STD_R2_0R1
+ STK_TOC (htab
),
14151 contents
+ rel
->r_offset
);
14155 /* Branch taken prediction relocations. */
14156 case R_PPC64_ADDR14_BRTAKEN
:
14157 case R_PPC64_REL14_BRTAKEN
:
14158 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14159 /* Fall through. */
14161 /* Branch not taken prediction relocations. */
14162 case R_PPC64_ADDR14_BRNTAKEN
:
14163 case R_PPC64_REL14_BRNTAKEN
:
14164 insn
|= bfd_get_32 (input_bfd
,
14165 contents
+ rel
->r_offset
) & ~(0x01 << 21);
14166 /* Fall through. */
14168 case R_PPC64_REL14
:
14169 max_br_offset
= 1 << 15;
14170 /* Fall through. */
14172 case R_PPC64_REL24
:
14173 /* Calls to functions with a different TOC, such as calls to
14174 shared objects, need to alter the TOC pointer. This is
14175 done using a linkage stub. A REL24 branching to these
14176 linkage stubs needs to be followed by a nop, as the nop
14177 will be replaced with an instruction to restore the TOC
14182 && h
->oh
->is_func_descriptor
)
14183 fdh
= ppc_follow_link (h
->oh
);
14184 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
14186 if (stub_entry
!= NULL
14187 && (stub_entry
->stub_type
== ppc_stub_plt_call
14188 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14189 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14190 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
14192 bfd_boolean can_plt_call
= FALSE
;
14194 if (stub_entry
->stub_type
== ppc_stub_plt_call
14196 && htab
->params
->plt_localentry0
!= 0
14197 && is_elfv2_localentry0 (&h
->elf
))
14199 /* The function doesn't use or change r2. */
14200 can_plt_call
= TRUE
;
14203 /* All of these stubs may modify r2, so there must be a
14204 branch and link followed by a nop. The nop is
14205 replaced by an insn to restore r2. */
14206 else if (rel
->r_offset
+ 8 <= input_section
->size
)
14210 br
= bfd_get_32 (input_bfd
,
14211 contents
+ rel
->r_offset
);
14216 nop
= bfd_get_32 (input_bfd
,
14217 contents
+ rel
->r_offset
+ 4);
14219 || nop
== CROR_151515
|| nop
== CROR_313131
)
14222 && (h
== htab
->tls_get_addr_fd
14223 || h
== htab
->tls_get_addr
)
14224 && htab
->params
->tls_get_addr_opt
)
14226 /* Special stub used, leave nop alone. */
14229 bfd_put_32 (input_bfd
,
14230 LD_R2_0R1
+ STK_TOC (htab
),
14231 contents
+ rel
->r_offset
+ 4);
14232 can_plt_call
= TRUE
;
14237 if (!can_plt_call
&& h
!= NULL
)
14239 const char *name
= h
->elf
.root
.root
.string
;
14244 if (strncmp (name
, "__libc_start_main", 17) == 0
14245 && (name
[17] == 0 || name
[17] == '@'))
14247 /* Allow crt1 branch to go via a toc adjusting
14248 stub. Other calls that never return could do
14249 the same, if we could detect such. */
14250 can_plt_call
= TRUE
;
14256 /* g++ as of 20130507 emits self-calls without a
14257 following nop. This is arguably wrong since we
14258 have conflicting information. On the one hand a
14259 global symbol and on the other a local call
14260 sequence, but don't error for this special case.
14261 It isn't possible to cheaply verify we have
14262 exactly such a call. Allow all calls to the same
14264 asection
*code_sec
= sec
;
14266 if (get_opd_info (sec
) != NULL
)
14268 bfd_vma off
= (relocation
+ addend
14269 - sec
->output_section
->vma
14270 - sec
->output_offset
);
14272 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14274 if (code_sec
== input_section
)
14275 can_plt_call
= TRUE
;
14280 if (stub_entry
->stub_type
== ppc_stub_plt_call
14281 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14282 info
->callbacks
->einfo
14283 /* xgettext:c-format */
14284 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14285 "recompile with -fPIC\n"),
14286 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14288 info
->callbacks
->einfo
14289 /* xgettext:c-format */
14290 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14291 "(-mcmodel=small toc adjust stub)\n"),
14292 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14294 bfd_set_error (bfd_error_bad_value
);
14299 && (stub_entry
->stub_type
== ppc_stub_plt_call
14300 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14301 unresolved_reloc
= FALSE
;
14304 if ((stub_entry
== NULL
14305 || stub_entry
->stub_type
== ppc_stub_long_branch
14306 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14307 && get_opd_info (sec
) != NULL
)
14309 /* The branch destination is the value of the opd entry. */
14310 bfd_vma off
= (relocation
+ addend
14311 - sec
->output_section
->vma
14312 - sec
->output_offset
);
14313 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14314 if (dest
!= (bfd_vma
) -1)
14318 reloc_dest
= DEST_OPD
;
14322 /* If the branch is out of reach we ought to have a long
14324 from
= (rel
->r_offset
14325 + input_section
->output_offset
14326 + input_section
->output_section
->vma
);
14328 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14332 if (stub_entry
!= NULL
14333 && (stub_entry
->stub_type
== ppc_stub_long_branch
14334 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14335 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14336 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14337 || (relocation
+ addend
- from
+ max_br_offset
14338 < 2 * max_br_offset
)))
14339 /* Don't use the stub if this branch is in range. */
14342 if (stub_entry
!= NULL
)
14344 /* Munge up the value and addend so that we call the stub
14345 rather than the procedure directly. */
14346 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14348 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14349 relocation
+= (stub_sec
->output_offset
14350 + stub_sec
->output_section
->vma
14351 + stub_sec
->size
- htab
->sfpr
->size
14352 - htab
->sfpr
->output_offset
14353 - htab
->sfpr
->output_section
->vma
);
14355 relocation
= (stub_entry
->stub_offset
14356 + stub_sec
->output_offset
14357 + stub_sec
->output_section
->vma
);
14359 reloc_dest
= DEST_STUB
;
14361 if ((stub_entry
->stub_type
== ppc_stub_plt_call
14362 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14363 && (ALWAYS_EMIT_R2SAVE
14364 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14365 && rel
+ 1 < relend
14366 && rel
[1].r_offset
== rel
->r_offset
+ 4
14367 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14375 /* Set 'a' bit. This is 0b00010 in BO field for branch
14376 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14377 for branch on CTR insns (BO == 1a00t or 1a01t). */
14378 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14379 insn
|= 0x02 << 21;
14380 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14381 insn
|= 0x08 << 21;
14387 /* Invert 'y' bit if not the default. */
14388 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14389 insn
^= 0x01 << 21;
14392 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14395 /* NOP out calls to undefined weak functions.
14396 We can thus call a weak function without first
14397 checking whether the function is defined. */
14399 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14400 && h
->elf
.dynindx
== -1
14401 && r_type
== R_PPC64_REL24
14405 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14411 /* Set `addend'. */
14416 /* xgettext:c-format */
14417 _bfd_error_handler (_("%pB: %s unsupported"),
14418 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14420 bfd_set_error (bfd_error_bad_value
);
14426 case R_PPC64_TLSGD
:
14427 case R_PPC64_TLSLD
:
14428 case R_PPC64_TOCSAVE
:
14429 case R_PPC64_GNU_VTINHERIT
:
14430 case R_PPC64_GNU_VTENTRY
:
14431 case R_PPC64_ENTRY
:
14434 /* GOT16 relocations. Like an ADDR16 using the symbol's
14435 address in the GOT as relocation value instead of the
14436 symbol's value itself. Also, create a GOT entry for the
14437 symbol and put the symbol value there. */
14438 case R_PPC64_GOT_TLSGD16
:
14439 case R_PPC64_GOT_TLSGD16_LO
:
14440 case R_PPC64_GOT_TLSGD16_HI
:
14441 case R_PPC64_GOT_TLSGD16_HA
:
14442 tls_type
= TLS_TLS
| TLS_GD
;
14445 case R_PPC64_GOT_TLSLD16
:
14446 case R_PPC64_GOT_TLSLD16_LO
:
14447 case R_PPC64_GOT_TLSLD16_HI
:
14448 case R_PPC64_GOT_TLSLD16_HA
:
14449 tls_type
= TLS_TLS
| TLS_LD
;
14452 case R_PPC64_GOT_TPREL16_DS
:
14453 case R_PPC64_GOT_TPREL16_LO_DS
:
14454 case R_PPC64_GOT_TPREL16_HI
:
14455 case R_PPC64_GOT_TPREL16_HA
:
14456 tls_type
= TLS_TLS
| TLS_TPREL
;
14459 case R_PPC64_GOT_DTPREL16_DS
:
14460 case R_PPC64_GOT_DTPREL16_LO_DS
:
14461 case R_PPC64_GOT_DTPREL16_HI
:
14462 case R_PPC64_GOT_DTPREL16_HA
:
14463 tls_type
= TLS_TLS
| TLS_DTPREL
;
14466 case R_PPC64_GOT16
:
14467 case R_PPC64_GOT16_LO
:
14468 case R_PPC64_GOT16_HI
:
14469 case R_PPC64_GOT16_HA
:
14470 case R_PPC64_GOT16_DS
:
14471 case R_PPC64_GOT16_LO_DS
:
14474 /* Relocation is to the entry for this symbol in the global
14479 unsigned long indx
= 0;
14480 struct got_entry
*ent
;
14482 if (tls_type
== (TLS_TLS
| TLS_LD
)
14484 || !h
->elf
.def_dynamic
))
14485 ent
= ppc64_tlsld_got (input_bfd
);
14490 if (!htab
->elf
.dynamic_sections_created
14491 || h
->elf
.dynindx
== -1
14492 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14493 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
14494 /* This is actually a static link, or it is a
14495 -Bsymbolic link and the symbol is defined
14496 locally, or the symbol was forced to be local
14497 because of a version file. */
14501 indx
= h
->elf
.dynindx
;
14502 unresolved_reloc
= FALSE
;
14504 ent
= h
->elf
.got
.glist
;
14508 if (local_got_ents
== NULL
)
14510 ent
= local_got_ents
[r_symndx
];
14513 for (; ent
!= NULL
; ent
= ent
->next
)
14514 if (ent
->addend
== orig_rel
.r_addend
14515 && ent
->owner
== input_bfd
14516 && ent
->tls_type
== tls_type
)
14522 if (ent
->is_indirect
)
14523 ent
= ent
->got
.ent
;
14524 offp
= &ent
->got
.offset
;
14525 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14529 /* The offset must always be a multiple of 8. We use the
14530 least significant bit to record whether we have already
14531 processed this entry. */
14533 if ((off
& 1) != 0)
14537 /* Generate relocs for the dynamic linker, except in
14538 the case of TLSLD where we'll use one entry per
14546 ? h
->elf
.type
== STT_GNU_IFUNC
14547 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14550 relgot
= htab
->elf
.irelplt
;
14552 htab
->local_ifunc_resolver
= 1;
14553 else if (is_static_defined (&h
->elf
))
14554 htab
->maybe_local_ifunc_resolver
= 1;
14557 || (bfd_link_pic (info
)
14559 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
14560 || (tls_type
== (TLS_TLS
| TLS_LD
)
14561 && !h
->elf
.def_dynamic
))
14562 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
14563 && bfd_link_executable (info
)
14564 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
14565 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14566 if (relgot
!= NULL
)
14568 outrel
.r_offset
= (got
->output_section
->vma
14569 + got
->output_offset
14571 outrel
.r_addend
= addend
;
14572 if (tls_type
& (TLS_LD
| TLS_GD
))
14574 outrel
.r_addend
= 0;
14575 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14576 if (tls_type
== (TLS_TLS
| TLS_GD
))
14578 loc
= relgot
->contents
;
14579 loc
+= (relgot
->reloc_count
++
14580 * sizeof (Elf64_External_Rela
));
14581 bfd_elf64_swap_reloca_out (output_bfd
,
14583 outrel
.r_offset
+= 8;
14584 outrel
.r_addend
= addend
;
14586 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14589 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14590 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14591 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14592 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14593 else if (indx
!= 0)
14594 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14598 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14600 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14602 /* Write the .got section contents for the sake
14604 loc
= got
->contents
+ off
;
14605 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14609 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14611 outrel
.r_addend
+= relocation
;
14612 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14614 if (htab
->elf
.tls_sec
== NULL
)
14615 outrel
.r_addend
= 0;
14617 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14620 loc
= relgot
->contents
;
14621 loc
+= (relgot
->reloc_count
++
14622 * sizeof (Elf64_External_Rela
));
14623 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14626 /* Init the .got section contents here if we're not
14627 emitting a reloc. */
14630 relocation
+= addend
;
14633 if (htab
->elf
.tls_sec
== NULL
)
14637 if (tls_type
& TLS_LD
)
14640 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14641 if (tls_type
& TLS_TPREL
)
14642 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14645 if (tls_type
& (TLS_GD
| TLS_LD
))
14647 bfd_put_64 (output_bfd
, relocation
,
14648 got
->contents
+ off
+ 8);
14652 bfd_put_64 (output_bfd
, relocation
,
14653 got
->contents
+ off
);
14657 if (off
>= (bfd_vma
) -2)
14660 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14661 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14665 case R_PPC64_PLT16_HA
:
14666 case R_PPC64_PLT16_HI
:
14667 case R_PPC64_PLT16_LO
:
14668 case R_PPC64_PLT16_LO_DS
:
14669 case R_PPC64_PLT32
:
14670 case R_PPC64_PLT64
:
14671 /* Relocation is to the entry for this symbol in the
14672 procedure linkage table. */
14674 struct plt_entry
**plt_list
= NULL
;
14676 plt_list
= &h
->elf
.plt
.plist
;
14677 else if (local_got_ents
!= NULL
)
14679 struct plt_entry
**local_plt
= (struct plt_entry
**)
14680 (local_got_ents
+ symtab_hdr
->sh_info
);
14681 unsigned char *local_got_tls_masks
= (unsigned char *)
14682 (local_plt
+ symtab_hdr
->sh_info
);
14683 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
14684 plt_list
= local_plt
+ r_symndx
;
14688 struct plt_entry
*ent
;
14690 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
14691 if (ent
->plt
.offset
!= (bfd_vma
) -1
14692 && ent
->addend
== orig_rel
.r_addend
)
14697 plt
= htab
->elf
.splt
;
14698 if (!htab
->elf
.dynamic_sections_created
14700 || h
->elf
.dynindx
== -1)
14701 plt
= htab
->elf
.iplt
;
14702 if (r_type
== R_PPC64_PLT16_HA
14703 || r_type
==R_PPC64_PLT16_HI
14704 || r_type
==R_PPC64_PLT16_LO
14705 || r_type
==R_PPC64_PLT16_LO_DS
)
14707 got
= (elf_gp (output_bfd
)
14708 + htab
->sec_info
[input_section
->id
].toc_off
);
14711 relocation
= (plt
->output_section
->vma
14712 + plt
->output_offset
14713 + ent
->plt
.offset
);
14715 unresolved_reloc
= FALSE
;
14723 /* Relocation value is TOC base. */
14724 relocation
= TOCstart
;
14725 if (r_symndx
== STN_UNDEF
)
14726 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14727 else if (unresolved_reloc
)
14729 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14730 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14732 unresolved_reloc
= TRUE
;
14735 /* TOC16 relocs. We want the offset relative to the TOC base,
14736 which is the address of the start of the TOC plus 0x8000.
14737 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14739 case R_PPC64_TOC16
:
14740 case R_PPC64_TOC16_LO
:
14741 case R_PPC64_TOC16_HI
:
14742 case R_PPC64_TOC16_DS
:
14743 case R_PPC64_TOC16_LO_DS
:
14744 case R_PPC64_TOC16_HA
:
14745 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14748 /* Relocate against the beginning of the section. */
14749 case R_PPC64_SECTOFF
:
14750 case R_PPC64_SECTOFF_LO
:
14751 case R_PPC64_SECTOFF_HI
:
14752 case R_PPC64_SECTOFF_DS
:
14753 case R_PPC64_SECTOFF_LO_DS
:
14754 case R_PPC64_SECTOFF_HA
:
14756 addend
-= sec
->output_section
->vma
;
14759 case R_PPC64_REL16
:
14760 case R_PPC64_REL16_LO
:
14761 case R_PPC64_REL16_HI
:
14762 case R_PPC64_REL16_HA
:
14763 case R_PPC64_REL16DX_HA
:
14766 case R_PPC64_REL14
:
14767 case R_PPC64_REL14_BRNTAKEN
:
14768 case R_PPC64_REL14_BRTAKEN
:
14769 case R_PPC64_REL24
:
14772 case R_PPC64_TPREL16
:
14773 case R_PPC64_TPREL16_LO
:
14774 case R_PPC64_TPREL16_HI
:
14775 case R_PPC64_TPREL16_HA
:
14776 case R_PPC64_TPREL16_DS
:
14777 case R_PPC64_TPREL16_LO_DS
:
14778 case R_PPC64_TPREL16_HIGH
:
14779 case R_PPC64_TPREL16_HIGHA
:
14780 case R_PPC64_TPREL16_HIGHER
:
14781 case R_PPC64_TPREL16_HIGHERA
:
14782 case R_PPC64_TPREL16_HIGHEST
:
14783 case R_PPC64_TPREL16_HIGHESTA
:
14785 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14786 && h
->elf
.dynindx
== -1)
14788 /* Make this relocation against an undefined weak symbol
14789 resolve to zero. This is really just a tweak, since
14790 code using weak externs ought to check that they are
14791 defined before using them. */
14792 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
14794 insn
= bfd_get_32 (input_bfd
, p
);
14795 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
14797 bfd_put_32 (input_bfd
, insn
, p
);
14800 if (htab
->elf
.tls_sec
!= NULL
)
14801 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14802 /* The TPREL16 relocs shouldn't really be used in shared
14803 libs or with non-local symbols as that will result in
14804 DT_TEXTREL being set, but support them anyway. */
14807 case R_PPC64_DTPREL16
:
14808 case R_PPC64_DTPREL16_LO
:
14809 case R_PPC64_DTPREL16_HI
:
14810 case R_PPC64_DTPREL16_HA
:
14811 case R_PPC64_DTPREL16_DS
:
14812 case R_PPC64_DTPREL16_LO_DS
:
14813 case R_PPC64_DTPREL16_HIGH
:
14814 case R_PPC64_DTPREL16_HIGHA
:
14815 case R_PPC64_DTPREL16_HIGHER
:
14816 case R_PPC64_DTPREL16_HIGHERA
:
14817 case R_PPC64_DTPREL16_HIGHEST
:
14818 case R_PPC64_DTPREL16_HIGHESTA
:
14819 if (htab
->elf
.tls_sec
!= NULL
)
14820 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14823 case R_PPC64_ADDR64_LOCAL
:
14824 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
14829 case R_PPC64_DTPMOD64
:
14834 case R_PPC64_TPREL64
:
14835 if (htab
->elf
.tls_sec
!= NULL
)
14836 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14839 case R_PPC64_DTPREL64
:
14840 if (htab
->elf
.tls_sec
!= NULL
)
14841 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14842 /* Fall through. */
14844 /* Relocations that may need to be propagated if this is a
14846 case R_PPC64_REL30
:
14847 case R_PPC64_REL32
:
14848 case R_PPC64_REL64
:
14849 case R_PPC64_ADDR14
:
14850 case R_PPC64_ADDR14_BRNTAKEN
:
14851 case R_PPC64_ADDR14_BRTAKEN
:
14852 case R_PPC64_ADDR16
:
14853 case R_PPC64_ADDR16_DS
:
14854 case R_PPC64_ADDR16_HA
:
14855 case R_PPC64_ADDR16_HI
:
14856 case R_PPC64_ADDR16_HIGH
:
14857 case R_PPC64_ADDR16_HIGHA
:
14858 case R_PPC64_ADDR16_HIGHER
:
14859 case R_PPC64_ADDR16_HIGHERA
:
14860 case R_PPC64_ADDR16_HIGHEST
:
14861 case R_PPC64_ADDR16_HIGHESTA
:
14862 case R_PPC64_ADDR16_LO
:
14863 case R_PPC64_ADDR16_LO_DS
:
14864 case R_PPC64_ADDR24
:
14865 case R_PPC64_ADDR32
:
14866 case R_PPC64_ADDR64
:
14867 case R_PPC64_UADDR16
:
14868 case R_PPC64_UADDR32
:
14869 case R_PPC64_UADDR64
:
14871 if ((input_section
->flags
& SEC_ALLOC
) == 0)
14874 if (NO_OPD_RELOCS
&& is_opd
)
14877 if (bfd_link_pic (info
)
14879 || h
->dyn_relocs
!= NULL
)
14880 && ((h
!= NULL
&& pc_dynrelocs (h
))
14881 || must_be_dyn_reloc (info
, r_type
)))
14883 ? h
->dyn_relocs
!= NULL
14884 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14886 bfd_boolean skip
, relocate
;
14891 /* When generating a dynamic object, these relocations
14892 are copied into the output file to be resolved at run
14898 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
14899 input_section
, rel
->r_offset
);
14900 if (out_off
== (bfd_vma
) -1)
14902 else if (out_off
== (bfd_vma
) -2)
14903 skip
= TRUE
, relocate
= TRUE
;
14904 out_off
+= (input_section
->output_section
->vma
14905 + input_section
->output_offset
);
14906 outrel
.r_offset
= out_off
;
14907 outrel
.r_addend
= rel
->r_addend
;
14909 /* Optimize unaligned reloc use. */
14910 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
14911 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
14912 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
14913 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
14914 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
14915 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
14916 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
14917 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
14918 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
14921 memset (&outrel
, 0, sizeof outrel
);
14922 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14924 && r_type
!= R_PPC64_TOC
)
14926 indx
= h
->elf
.dynindx
;
14927 BFD_ASSERT (indx
!= -1);
14928 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14932 /* This symbol is local, or marked to become local,
14933 or this is an opd section reloc which must point
14934 at a local function. */
14935 outrel
.r_addend
+= relocation
;
14936 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
14938 if (is_opd
&& h
!= NULL
)
14940 /* Lie about opd entries. This case occurs
14941 when building shared libraries and we
14942 reference a function in another shared
14943 lib. The same thing happens for a weak
14944 definition in an application that's
14945 overridden by a strong definition in a
14946 shared lib. (I believe this is a generic
14947 bug in binutils handling of weak syms.)
14948 In these cases we won't use the opd
14949 entry in this lib. */
14950 unresolved_reloc
= FALSE
;
14953 && r_type
== R_PPC64_ADDR64
14955 ? h
->elf
.type
== STT_GNU_IFUNC
14956 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14957 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14960 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14962 /* We need to relocate .opd contents for ld.so.
14963 Prelink also wants simple and consistent rules
14964 for relocs. This make all RELATIVE relocs have
14965 *r_offset equal to r_addend. */
14972 ? h
->elf
.type
== STT_GNU_IFUNC
14973 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14975 info
->callbacks
->einfo
14976 /* xgettext:c-format */
14977 (_("%H: %s for indirect "
14978 "function `%pT' unsupported\n"),
14979 input_bfd
, input_section
, rel
->r_offset
,
14980 ppc64_elf_howto_table
[r_type
]->name
,
14984 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
14986 else if (sec
== NULL
|| sec
->owner
== NULL
)
14988 bfd_set_error (bfd_error_bad_value
);
14995 osec
= sec
->output_section
;
14996 indx
= elf_section_data (osec
)->dynindx
;
15000 if ((osec
->flags
& SEC_READONLY
) == 0
15001 && htab
->elf
.data_index_section
!= NULL
)
15002 osec
= htab
->elf
.data_index_section
;
15004 osec
= htab
->elf
.text_index_section
;
15005 indx
= elf_section_data (osec
)->dynindx
;
15007 BFD_ASSERT (indx
!= 0);
15009 /* We are turning this relocation into one
15010 against a section symbol, so subtract out
15011 the output section's address but not the
15012 offset of the input section in the output
15014 outrel
.r_addend
-= osec
->vma
;
15017 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15021 sreloc
= elf_section_data (input_section
)->sreloc
;
15023 ? h
->elf
.type
== STT_GNU_IFUNC
15024 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15026 sreloc
= htab
->elf
.irelplt
;
15028 htab
->local_ifunc_resolver
= 1;
15029 else if (is_static_defined (&h
->elf
))
15030 htab
->maybe_local_ifunc_resolver
= 1;
15032 if (sreloc
== NULL
)
15035 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
15038 loc
= sreloc
->contents
;
15039 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15040 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15042 /* If this reloc is against an external symbol, it will
15043 be computed at runtime, so there's no need to do
15044 anything now. However, for the sake of prelink ensure
15045 that the section contents are a known value. */
15048 unresolved_reloc
= FALSE
;
15049 /* The value chosen here is quite arbitrary as ld.so
15050 ignores section contents except for the special
15051 case of .opd where the contents might be accessed
15052 before relocation. Choose zero, as that won't
15053 cause reloc overflow. */
15056 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15057 to improve backward compatibility with older
15059 if (r_type
== R_PPC64_ADDR64
)
15060 addend
= outrel
.r_addend
;
15061 /* Adjust pc_relative relocs to have zero in *r_offset. */
15062 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
15063 addend
= outrel
.r_offset
;
15069 case R_PPC64_GLOB_DAT
:
15070 case R_PPC64_JMP_SLOT
:
15071 case R_PPC64_JMP_IREL
:
15072 case R_PPC64_RELATIVE
:
15073 /* We shouldn't ever see these dynamic relocs in relocatable
15075 /* Fall through. */
15077 case R_PPC64_PLTGOT16
:
15078 case R_PPC64_PLTGOT16_DS
:
15079 case R_PPC64_PLTGOT16_HA
:
15080 case R_PPC64_PLTGOT16_HI
:
15081 case R_PPC64_PLTGOT16_LO
:
15082 case R_PPC64_PLTGOT16_LO_DS
:
15083 case R_PPC64_PLTREL32
:
15084 case R_PPC64_PLTREL64
:
15085 /* These ones haven't been implemented yet. */
15087 info
->callbacks
->einfo
15088 /* xgettext:c-format */
15089 (_("%P: %pB: %s is not supported for `%pT'\n"),
15091 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
15093 bfd_set_error (bfd_error_invalid_operation
);
15098 /* Multi-instruction sequences that access the TOC can be
15099 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15100 to nop; addi rb,r2,x; */
15106 case R_PPC64_GOT_TLSLD16_HI
:
15107 case R_PPC64_GOT_TLSGD16_HI
:
15108 case R_PPC64_GOT_TPREL16_HI
:
15109 case R_PPC64_GOT_DTPREL16_HI
:
15110 case R_PPC64_GOT16_HI
:
15111 case R_PPC64_TOC16_HI
:
15112 /* These relocs would only be useful if building up an
15113 offset to later add to r2, perhaps in an indexed
15114 addressing mode instruction. Don't try to optimize.
15115 Unfortunately, the possibility of someone building up an
15116 offset like this or even with the HA relocs, means that
15117 we need to check the high insn when optimizing the low
15121 case R_PPC64_GOT_TLSLD16_HA
:
15122 case R_PPC64_GOT_TLSGD16_HA
:
15123 case R_PPC64_GOT_TPREL16_HA
:
15124 case R_PPC64_GOT_DTPREL16_HA
:
15125 case R_PPC64_GOT16_HA
:
15126 case R_PPC64_TOC16_HA
:
15127 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15128 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15130 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15131 bfd_put_32 (input_bfd
, NOP
, p
);
15136 case R_PPC64_GOT_TLSLD16_LO
:
15137 case R_PPC64_GOT_TLSGD16_LO
:
15138 case R_PPC64_GOT_TPREL16_LO_DS
:
15139 case R_PPC64_GOT_DTPREL16_LO_DS
:
15140 case R_PPC64_GOT16_LO
:
15141 case R_PPC64_GOT16_LO_DS
:
15142 case R_PPC64_TOC16_LO
:
15143 case R_PPC64_TOC16_LO_DS
:
15144 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15145 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15147 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15148 insn
= bfd_get_32 (input_bfd
, p
);
15149 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15151 /* Transform addic to addi when we change reg. */
15152 insn
&= ~((0x3f << 26) | (0x1f << 16));
15153 insn
|= (14u << 26) | (2 << 16);
15157 insn
&= ~(0x1f << 16);
15160 bfd_put_32 (input_bfd
, insn
, p
);
15164 case R_PPC64_TPREL16_HA
:
15165 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15167 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15168 insn
= bfd_get_32 (input_bfd
, p
);
15169 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15170 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15171 /* xgettext:c-format */
15172 info
->callbacks
->minfo
15173 (_("%H: warning: %s unexpected insn %#x.\n"),
15174 input_bfd
, input_section
, rel
->r_offset
,
15175 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15178 bfd_put_32 (input_bfd
, NOP
, p
);
15184 case R_PPC64_TPREL16_LO
:
15185 case R_PPC64_TPREL16_LO_DS
:
15186 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15188 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15189 insn
= bfd_get_32 (input_bfd
, p
);
15190 insn
&= ~(0x1f << 16);
15192 bfd_put_32 (input_bfd
, insn
, p
);
15197 /* Do any further special processing. */
15203 case R_PPC64_REL16_HA
:
15204 case R_PPC64_REL16DX_HA
:
15205 case R_PPC64_ADDR16_HA
:
15206 case R_PPC64_ADDR16_HIGHA
:
15207 case R_PPC64_ADDR16_HIGHERA
:
15208 case R_PPC64_ADDR16_HIGHESTA
:
15209 case R_PPC64_TOC16_HA
:
15210 case R_PPC64_SECTOFF_HA
:
15211 case R_PPC64_TPREL16_HA
:
15212 case R_PPC64_TPREL16_HIGHA
:
15213 case R_PPC64_TPREL16_HIGHERA
:
15214 case R_PPC64_TPREL16_HIGHESTA
:
15215 case R_PPC64_DTPREL16_HA
:
15216 case R_PPC64_DTPREL16_HIGHA
:
15217 case R_PPC64_DTPREL16_HIGHERA
:
15218 case R_PPC64_DTPREL16_HIGHESTA
:
15219 /* It's just possible that this symbol is a weak symbol
15220 that's not actually defined anywhere. In that case,
15221 'sec' would be NULL, and we should leave the symbol
15222 alone (it will be set to zero elsewhere in the link). */
15225 /* Fall through. */
15227 case R_PPC64_GOT16_HA
:
15228 case R_PPC64_PLTGOT16_HA
:
15229 case R_PPC64_PLT16_HA
:
15230 case R_PPC64_GOT_TLSGD16_HA
:
15231 case R_PPC64_GOT_TLSLD16_HA
:
15232 case R_PPC64_GOT_TPREL16_HA
:
15233 case R_PPC64_GOT_DTPREL16_HA
:
15234 /* Add 0x10000 if sign bit in 0:15 is set.
15235 Bits 0:15 are not used. */
15239 case R_PPC64_ADDR16_DS
:
15240 case R_PPC64_ADDR16_LO_DS
:
15241 case R_PPC64_GOT16_DS
:
15242 case R_PPC64_GOT16_LO_DS
:
15243 case R_PPC64_PLT16_LO_DS
:
15244 case R_PPC64_SECTOFF_DS
:
15245 case R_PPC64_SECTOFF_LO_DS
:
15246 case R_PPC64_TOC16_DS
:
15247 case R_PPC64_TOC16_LO_DS
:
15248 case R_PPC64_PLTGOT16_DS
:
15249 case R_PPC64_PLTGOT16_LO_DS
:
15250 case R_PPC64_GOT_TPREL16_DS
:
15251 case R_PPC64_GOT_TPREL16_LO_DS
:
15252 case R_PPC64_GOT_DTPREL16_DS
:
15253 case R_PPC64_GOT_DTPREL16_LO_DS
:
15254 case R_PPC64_TPREL16_DS
:
15255 case R_PPC64_TPREL16_LO_DS
:
15256 case R_PPC64_DTPREL16_DS
:
15257 case R_PPC64_DTPREL16_LO_DS
:
15258 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15260 /* If this reloc is against an lq, lxv, or stxv insn, then
15261 the value must be a multiple of 16. This is somewhat of
15262 a hack, but the "correct" way to do this by defining _DQ
15263 forms of all the _DS relocs bloats all reloc switches in
15264 this file. It doesn't make much sense to use these
15265 relocs in data, so testing the insn should be safe. */
15266 if ((insn
& (0x3f << 26)) == (56u << 26)
15267 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15269 relocation
+= addend
;
15270 addend
= insn
& (mask
^ 3);
15271 if ((relocation
& mask
) != 0)
15273 relocation
^= relocation
& mask
;
15274 info
->callbacks
->einfo
15275 /* xgettext:c-format */
15276 (_("%H: error: %s not a multiple of %u\n"),
15277 input_bfd
, input_section
, rel
->r_offset
,
15278 ppc64_elf_howto_table
[r_type
]->name
,
15280 bfd_set_error (bfd_error_bad_value
);
15287 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15288 because such sections are not SEC_ALLOC and thus ld.so will
15289 not process them. */
15290 howto
= ppc64_elf_howto_table
[(int) r_type
];
15291 if (unresolved_reloc
15292 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15293 && h
->elf
.def_dynamic
)
15294 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15295 rel
->r_offset
) != (bfd_vma
) -1)
15297 info
->callbacks
->einfo
15298 /* xgettext:c-format */
15299 (_("%H: unresolvable %s against `%pT'\n"),
15300 input_bfd
, input_section
, rel
->r_offset
,
15302 h
->elf
.root
.root
.string
);
15306 /* 16-bit fields in insns mostly have signed values, but a
15307 few insns have 16-bit unsigned values. Really, we should
15308 have different reloc types. */
15309 if (howto
->complain_on_overflow
!= complain_overflow_dont
15310 && howto
->dst_mask
== 0xffff
15311 && (input_section
->flags
& SEC_CODE
) != 0)
15313 enum complain_overflow complain
= complain_overflow_signed
;
15315 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15316 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15317 complain
= complain_overflow_bitfield
;
15318 else if (howto
->rightshift
== 0
15319 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15320 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15321 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15322 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15323 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15324 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15325 complain
= complain_overflow_unsigned
;
15326 if (howto
->complain_on_overflow
!= complain
)
15328 alt_howto
= *howto
;
15329 alt_howto
.complain_on_overflow
= complain
;
15330 howto
= &alt_howto
;
15334 if (r_type
== R_PPC64_REL16DX_HA
)
15336 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15337 if (rel
->r_offset
+ 4 > input_section
->size
)
15338 r
= bfd_reloc_outofrange
;
15341 relocation
+= addend
;
15342 relocation
-= (rel
->r_offset
15343 + input_section
->output_offset
15344 + input_section
->output_section
->vma
);
15345 relocation
= (bfd_signed_vma
) relocation
>> 16;
15346 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15348 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15349 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15351 if (relocation
+ 0x8000 > 0xffff)
15352 r
= bfd_reloc_overflow
;
15356 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15357 rel
->r_offset
, relocation
, addend
);
15359 if (r
!= bfd_reloc_ok
)
15361 char *more_info
= NULL
;
15362 const char *reloc_name
= howto
->name
;
15364 if (reloc_dest
!= DEST_NORMAL
)
15366 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15367 if (more_info
!= NULL
)
15369 strcpy (more_info
, reloc_name
);
15370 strcat (more_info
, (reloc_dest
== DEST_OPD
15371 ? " (OPD)" : " (stub)"));
15372 reloc_name
= more_info
;
15376 if (r
== bfd_reloc_overflow
)
15378 /* On code like "if (foo) foo();" don't report overflow
15379 on a branch to zero when foo is undefined. */
15381 && (reloc_dest
== DEST_STUB
15383 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15384 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15385 && is_branch_reloc (r_type
))))
15386 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15387 sym_name
, reloc_name
,
15389 input_bfd
, input_section
,
15394 info
->callbacks
->einfo
15395 /* xgettext:c-format */
15396 (_("%H: %s against `%pT': error %d\n"),
15397 input_bfd
, input_section
, rel
->r_offset
,
15398 reloc_name
, sym_name
, (int) r
);
15401 if (more_info
!= NULL
)
15411 Elf_Internal_Shdr
*rel_hdr
;
15412 size_t deleted
= rel
- wrel
;
15414 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15415 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15416 if (rel_hdr
->sh_size
== 0)
15418 /* It is too late to remove an empty reloc section. Leave
15420 ??? What is wrong with an empty section??? */
15421 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15424 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15425 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15426 input_section
->reloc_count
-= deleted
;
15429 /* If we're emitting relocations, then shortly after this function
15430 returns, reloc offsets and addends for this section will be
15431 adjusted. Worse, reloc symbol indices will be for the output
15432 file rather than the input. Save a copy of the relocs for
15433 opd_entry_value. */
15434 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15437 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15438 rel
= bfd_alloc (input_bfd
, amt
);
15439 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15440 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15443 memcpy (rel
, relocs
, amt
);
15448 /* Adjust the value of any local symbols in opd sections. */
15451 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15452 const char *name ATTRIBUTE_UNUSED
,
15453 Elf_Internal_Sym
*elfsym
,
15454 asection
*input_sec
,
15455 struct elf_link_hash_entry
*h
)
15457 struct _opd_sec_data
*opd
;
15464 opd
= get_opd_info (input_sec
);
15465 if (opd
== NULL
|| opd
->adjust
== NULL
)
15468 value
= elfsym
->st_value
- input_sec
->output_offset
;
15469 if (!bfd_link_relocatable (info
))
15470 value
-= input_sec
->output_section
->vma
;
15472 adjust
= opd
->adjust
[OPD_NDX (value
)];
15476 elfsym
->st_value
+= adjust
;
15480 /* Finish up dynamic symbol handling. We set the contents of various
15481 dynamic sections here. */
15484 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15485 struct bfd_link_info
*info
,
15486 struct elf_link_hash_entry
*h
,
15487 Elf_Internal_Sym
*sym
)
15489 struct ppc_link_hash_table
*htab
;
15490 struct plt_entry
*ent
;
15491 Elf_Internal_Rela rela
;
15494 htab
= ppc_hash_table (info
);
15498 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15499 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15501 /* This symbol has an entry in the procedure linkage
15502 table. Set it up. */
15503 if (!htab
->elf
.dynamic_sections_created
15504 || h
->dynindx
== -1)
15506 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
15508 && (h
->root
.type
== bfd_link_hash_defined
15509 || h
->root
.type
== bfd_link_hash_defweak
));
15510 rela
.r_offset
= (htab
->elf
.iplt
->output_section
->vma
15511 + htab
->elf
.iplt
->output_offset
15512 + ent
->plt
.offset
);
15514 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
15516 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15517 rela
.r_addend
= (h
->root
.u
.def
.value
15518 + h
->root
.u
.def
.section
->output_offset
15519 + h
->root
.u
.def
.section
->output_section
->vma
15521 loc
= (htab
->elf
.irelplt
->contents
15522 + (htab
->elf
.irelplt
->reloc_count
++
15523 * sizeof (Elf64_External_Rela
)));
15524 htab
->local_ifunc_resolver
= 1;
15528 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
15529 + htab
->elf
.splt
->output_offset
15530 + ent
->plt
.offset
);
15531 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
15532 rela
.r_addend
= ent
->addend
;
15533 loc
= (htab
->elf
.srelplt
->contents
15534 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
15535 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
15536 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
15537 htab
->maybe_local_ifunc_resolver
= 1;
15539 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15541 if (!htab
->opd_abi
)
15543 if (!h
->def_regular
)
15545 /* Mark the symbol as undefined, rather than as
15546 defined in glink. Leave the value if there were
15547 any relocations where pointer equality matters
15548 (this is a clue for the dynamic linker, to make
15549 function pointer comparisons work between an
15550 application and shared library), otherwise set it
15552 sym
->st_shndx
= SHN_UNDEF
;
15553 if (!h
->pointer_equality_needed
)
15555 else if (!h
->ref_regular_nonweak
)
15557 /* This breaks function pointer comparisons, but
15558 that is better than breaking tests for a NULL
15559 function pointer. */
15568 /* This symbol needs a copy reloc. Set it up. */
15571 if (h
->dynindx
== -1
15572 || (h
->root
.type
!= bfd_link_hash_defined
15573 && h
->root
.type
!= bfd_link_hash_defweak
)
15574 || htab
->elf
.srelbss
== NULL
15575 || htab
->elf
.sreldynrelro
== NULL
)
15578 rela
.r_offset
= (h
->root
.u
.def
.value
15579 + h
->root
.u
.def
.section
->output_section
->vma
15580 + h
->root
.u
.def
.section
->output_offset
);
15581 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15583 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
15584 srel
= htab
->elf
.sreldynrelro
;
15586 srel
= htab
->elf
.srelbss
;
15587 loc
= srel
->contents
;
15588 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15589 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15595 /* Used to decide how to sort relocs in an optimal manner for the
15596 dynamic linker, before writing them out. */
15598 static enum elf_reloc_type_class
15599 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15600 const asection
*rel_sec
,
15601 const Elf_Internal_Rela
*rela
)
15603 enum elf_ppc64_reloc_type r_type
;
15604 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15606 if (rel_sec
== htab
->elf
.irelplt
)
15607 return reloc_class_ifunc
;
15609 r_type
= ELF64_R_TYPE (rela
->r_info
);
15612 case R_PPC64_RELATIVE
:
15613 return reloc_class_relative
;
15614 case R_PPC64_JMP_SLOT
:
15615 return reloc_class_plt
;
15617 return reloc_class_copy
;
15619 return reloc_class_normal
;
15623 /* Finish up the dynamic sections. */
15626 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15627 struct bfd_link_info
*info
)
15629 struct ppc_link_hash_table
*htab
;
15633 htab
= ppc_hash_table (info
);
15637 dynobj
= htab
->elf
.dynobj
;
15638 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15640 if (htab
->elf
.dynamic_sections_created
)
15642 Elf64_External_Dyn
*dyncon
, *dynconend
;
15644 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15647 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15648 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15649 for (; dyncon
< dynconend
; dyncon
++)
15651 Elf_Internal_Dyn dyn
;
15654 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15661 case DT_PPC64_GLINK
:
15663 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15664 /* We stupidly defined DT_PPC64_GLINK to be the start
15665 of glink rather than the first entry point, which is
15666 what ld.so needs, and now have a bigger stub to
15667 support automatic multiple TOCs. */
15668 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
15672 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15675 dyn
.d_un
.d_ptr
= s
->vma
;
15679 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15680 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15681 if (htab
->has_plt_localentry0
)
15682 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
15685 case DT_PPC64_OPDSZ
:
15686 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15689 dyn
.d_un
.d_val
= s
->size
;
15693 s
= htab
->elf
.splt
;
15694 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15698 s
= htab
->elf
.srelplt
;
15699 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15703 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15707 if (htab
->local_ifunc_resolver
)
15708 info
->callbacks
->einfo
15709 (_("%X%P: text relocations and GNU indirect "
15710 "functions will result in a segfault at runtime\n"));
15711 else if (htab
->maybe_local_ifunc_resolver
)
15712 info
->callbacks
->einfo
15713 (_("%P: warning: text relocations and GNU indirect "
15714 "functions may result in a segfault at runtime\n"));
15718 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15722 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
15723 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
15725 /* Fill in the first entry in the global offset table.
15726 We use it to hold the link-time TOCbase. */
15727 bfd_put_64 (output_bfd
,
15728 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15729 htab
->elf
.sgot
->contents
);
15731 /* Set .got entry size. */
15732 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
15735 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
15736 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
15738 /* Set .plt entry size. */
15739 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15740 = PLT_ENTRY_SIZE (htab
);
15743 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15744 brlt ourselves if emitrelocations. */
15745 if (htab
->brlt
!= NULL
15746 && htab
->brlt
->reloc_count
!= 0
15747 && !_bfd_elf_link_output_relocs (output_bfd
,
15749 elf_section_data (htab
->brlt
)->rela
.hdr
,
15750 elf_section_data (htab
->brlt
)->relocs
,
15754 if (htab
->glink
!= NULL
15755 && htab
->glink
->reloc_count
!= 0
15756 && !_bfd_elf_link_output_relocs (output_bfd
,
15758 elf_section_data (htab
->glink
)->rela
.hdr
,
15759 elf_section_data (htab
->glink
)->relocs
,
15763 if (htab
->glink_eh_frame
!= NULL
15764 && htab
->glink_eh_frame
->size
!= 0)
15768 struct map_stub
*group
;
15771 p
= htab
->glink_eh_frame
->contents
;
15772 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15774 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15775 if (group
->stub_sec
!= NULL
)
15777 /* Offset to stub section. */
15778 val
= (group
->stub_sec
->output_section
->vma
15779 + group
->stub_sec
->output_offset
);
15780 val
-= (htab
->glink_eh_frame
->output_section
->vma
15781 + htab
->glink_eh_frame
->output_offset
15782 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15783 if (val
+ 0x80000000 > 0xffffffff)
15786 (_("%s offset too large for .eh_frame sdata4 encoding"),
15787 group
->stub_sec
->name
);
15790 bfd_put_32 (dynobj
, val
, p
+ 8);
15791 p
+= stub_eh_frame_size (group
, align
);
15793 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15795 /* Offset to .glink. */
15796 val
= (htab
->glink
->output_section
->vma
15797 + htab
->glink
->output_offset
15799 val
-= (htab
->glink_eh_frame
->output_section
->vma
15800 + htab
->glink_eh_frame
->output_offset
15801 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15802 if (val
+ 0x80000000 > 0xffffffff)
15805 (_("%s offset too large for .eh_frame sdata4 encoding"),
15806 htab
->glink
->name
);
15809 bfd_put_32 (dynobj
, val
, p
+ 8);
15810 p
+= (24 + align
- 1) & -align
;
15813 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15814 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15815 htab
->glink_eh_frame
,
15816 htab
->glink_eh_frame
->contents
))
15820 /* We need to handle writing out multiple GOT sections ourselves,
15821 since we didn't add them to DYNOBJ. We know dynobj is the first
15823 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15827 if (!is_ppc64_elf (dynobj
))
15830 s
= ppc64_elf_tdata (dynobj
)->got
;
15833 && s
->output_section
!= bfd_abs_section_ptr
15834 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15835 s
->contents
, s
->output_offset
,
15838 s
= ppc64_elf_tdata (dynobj
)->relgot
;
15841 && s
->output_section
!= bfd_abs_section_ptr
15842 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15843 s
->contents
, s
->output_offset
,
15851 #include "elf64-target.h"
15853 /* FreeBSD support */
15855 #undef TARGET_LITTLE_SYM
15856 #undef TARGET_LITTLE_NAME
15858 #undef TARGET_BIG_SYM
15859 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15860 #undef TARGET_BIG_NAME
15861 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15864 #define ELF_OSABI ELFOSABI_FREEBSD
15867 #define elf64_bed elf64_powerpc_fbsd_bed
15869 #include "elf64-target.h"