1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Written by Linus Nordberg, Swox AB <info@swox.com>,
5 based on elf32-ppc.c by Ian Lance Taylor.
6 Largely rewritten by Alan Modra.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc.,
22 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 /* The 64-bit PowerPC ELF ABI may be found at
26 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
27 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
35 #include "elf/ppc64.h"
36 #include "elf64-ppc.h"
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
41 static bfd_reloc_status_type ppc64_elf_branch_reloc
42 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
43 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
44 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
45 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
46 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
47 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
48 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
49 static bfd_reloc_status_type ppc64_elf_toc_reloc
50 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
51 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
52 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
53 static bfd_reloc_status_type ppc64_elf_toc64_reloc
54 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
55 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
56 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
57 static bfd_vma opd_entry_value
58 (asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
60 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
61 #define TARGET_LITTLE_NAME "elf64-powerpcle"
62 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
63 #define TARGET_BIG_NAME "elf64-powerpc"
64 #define ELF_ARCH bfd_arch_powerpc
65 #define ELF_TARGET_ID PPC64_ELF_DATA
66 #define ELF_MACHINE_CODE EM_PPC64
67 #define ELF_MAXPAGESIZE 0x10000
68 #define ELF_COMMONPAGESIZE 0x1000
69 #define elf_info_to_howto ppc64_elf_info_to_howto
71 #define elf_backend_want_got_sym 0
72 #define elf_backend_want_plt_sym 0
73 #define elf_backend_plt_alignment 3
74 #define elf_backend_plt_not_loaded 1
75 #define elf_backend_got_header_size 8
76 #define elf_backend_can_gc_sections 1
77 #define elf_backend_can_refcount 1
78 #define elf_backend_rela_normal 1
79 #define elf_backend_default_execstack 0
81 #define bfd_elf64_mkobject ppc64_elf_mkobject
82 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
83 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
84 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
85 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
86 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
87 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
88 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
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
92 #define elf_backend_object_p ppc64_elf_object_p
93 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
94 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
95 #define elf_backend_write_core_note ppc64_elf_write_core_note
96 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
97 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
98 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
99 #define elf_backend_check_directives ppc64_elf_process_dot_syms
100 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
101 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
102 #define elf_backend_check_relocs ppc64_elf_check_relocs
103 #define elf_backend_gc_keep ppc64_elf_gc_keep
104 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
105 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
106 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
107 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
108 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
109 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
110 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
111 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
112 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
113 #define elf_backend_action_discarded ppc64_elf_action_discarded
114 #define elf_backend_relocate_section ppc64_elf_relocate_section
115 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
116 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
117 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
118 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
119 #define elf_backend_special_sections ppc64_elf_special_sections
120 #define elf_backend_post_process_headers _bfd_elf_set_osabi
121 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
123 /* The name of the dynamic interpreter. This is put in the .interp
125 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
127 /* The size in bytes of an entry in the procedure linkage table. */
128 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
130 /* The initial size of the plt reserved for the dynamic linker. */
131 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
133 /* Offsets to some stack save slots. */
135 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
136 /* This one is dodgy. ABIv2 does not have a linker word, so use the
137 CR save slot. Used only by optimised __tls_get_addr call stub,
138 relying on __tls_get_addr_opt not saving CR.. */
139 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
141 /* TOC base pointers offset from start of TOC. */
142 #define TOC_BASE_OFF 0x8000
144 /* Offset of tp and dtp pointers from start of TLS block. */
145 #define TP_OFFSET 0x7000
146 #define DTP_OFFSET 0x8000
148 /* .plt call stub instructions. The normal stub is like this, but
149 sometimes the .plt entry crosses a 64k boundary and we need to
150 insert an addi to adjust r11. */
151 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
152 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
153 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
154 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
155 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
156 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
157 #define BCTR 0x4e800420 /* bctr */
159 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
160 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
161 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
163 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
164 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
165 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
166 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
167 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
168 #define BNECTR 0x4ca20420 /* bnectr+ */
169 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
171 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
172 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
173 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
175 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
177 /* glink call stub instructions. We enter with the index in R0. */
178 #define GLINK_CALL_STUB_SIZE (16*4)
182 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
183 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
185 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
186 /* ld %2,(0b-1b)(%11) */
187 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
188 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
194 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
195 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
196 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
197 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
198 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
201 #define NOP 0x60000000
203 /* Some other nops. */
204 #define CROR_151515 0x4def7b82
205 #define CROR_313131 0x4ffffb82
207 /* .glink entries for the first 32k functions are two instructions. */
208 #define LI_R0_0 0x38000000 /* li %r0,0 */
209 #define B_DOT 0x48000000 /* b . */
211 /* After that, we need two instructions to load the index, followed by
213 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
214 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
216 /* Instructions used by the save and restore reg functions. */
217 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
218 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
219 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
220 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
221 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
222 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
223 #define LI_R12_0 0x39800000 /* li %r12,0 */
224 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
225 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
226 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
227 #define BLR 0x4e800020 /* blr */
229 /* Since .opd is an array of descriptors and each entry will end up
230 with identical R_PPC64_RELATIVE relocs, there is really no need to
231 propagate .opd relocs; The dynamic linker should be taught to
232 relocate .opd without reloc entries. */
233 #ifndef NO_OPD_RELOCS
234 #define NO_OPD_RELOCS 0
237 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
239 /* Relocation HOWTO's. */
240 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
242 static reloc_howto_type ppc64_elf_howto_raw[] = {
243 /* This reloc does nothing. */
244 HOWTO (R_PPC64_NONE, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE, /* pc_relative */
250 complain_overflow_dont, /* complain_on_overflow */
251 bfd_elf_generic_reloc, /* special_function */
252 "R_PPC64_NONE", /* name */
253 FALSE, /* partial_inplace */
256 FALSE), /* pcrel_offset */
258 /* A standard 32 bit relocation. */
259 HOWTO (R_PPC64_ADDR32, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE, /* pc_relative */
265 complain_overflow_bitfield, /* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_PPC64_ADDR32", /* name */
268 FALSE, /* partial_inplace */
270 0xffffffff, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 /* An absolute 26 bit branch; the lower two bits must be zero.
274 FIXME: we don't check that, we just clear them. */
275 HOWTO (R_PPC64_ADDR24, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE, /* pc_relative */
281 complain_overflow_bitfield, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_PPC64_ADDR24", /* name */
284 FALSE, /* partial_inplace */
286 0x03fffffc, /* dst_mask */
287 FALSE), /* pcrel_offset */
289 /* A standard 16 bit relocation. */
290 HOWTO (R_PPC64_ADDR16, /* type */
292 1, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE, /* pc_relative */
296 complain_overflow_bitfield, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_PPC64_ADDR16", /* name */
299 FALSE, /* partial_inplace */
301 0xffff, /* dst_mask */
302 FALSE), /* pcrel_offset */
304 /* A 16 bit relocation without overflow. */
305 HOWTO (R_PPC64_ADDR16_LO, /* type */
307 1, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE, /* pc_relative */
311 complain_overflow_dont,/* complain_on_overflow */
312 bfd_elf_generic_reloc, /* special_function */
313 "R_PPC64_ADDR16_LO", /* name */
314 FALSE, /* partial_inplace */
316 0xffff, /* dst_mask */
317 FALSE), /* pcrel_offset */
319 /* Bits 16-31 of an address. */
320 HOWTO (R_PPC64_ADDR16_HI, /* type */
322 1, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE, /* pc_relative */
326 complain_overflow_signed, /* complain_on_overflow */
327 bfd_elf_generic_reloc, /* special_function */
328 "R_PPC64_ADDR16_HI", /* name */
329 FALSE, /* partial_inplace */
331 0xffff, /* dst_mask */
332 FALSE), /* pcrel_offset */
334 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
335 bits, treated as a signed number, is negative. */
336 HOWTO (R_PPC64_ADDR16_HA, /* type */
338 1, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE, /* pc_relative */
342 complain_overflow_signed, /* complain_on_overflow */
343 ppc64_elf_ha_reloc, /* special_function */
344 "R_PPC64_ADDR16_HA", /* name */
345 FALSE, /* partial_inplace */
347 0xffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 /* An absolute 16 bit branch; the lower two bits must be zero.
351 FIXME: we don't check that, we just clear them. */
352 HOWTO (R_PPC64_ADDR14, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE, /* pc_relative */
358 complain_overflow_bitfield, /* complain_on_overflow */
359 ppc64_elf_branch_reloc, /* special_function */
360 "R_PPC64_ADDR14", /* name */
361 FALSE, /* partial_inplace */
363 0x0000fffc, /* dst_mask */
364 FALSE), /* pcrel_offset */
366 /* An absolute 16 bit branch, for which bit 10 should be set to
367 indicate that the branch is expected to be taken. The lower two
368 bits must be zero. */
369 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_bitfield, /* complain_on_overflow */
376 ppc64_elf_brtaken_reloc, /* special_function */
377 "R_PPC64_ADDR14_BRTAKEN",/* name */
378 FALSE, /* partial_inplace */
380 0x0000fffc, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* An absolute 16 bit branch, for which bit 10 should be set to
384 indicate that the branch is not expected to be taken. The lower
385 two bits must be zero. */
386 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_bitfield, /* complain_on_overflow */
393 ppc64_elf_brtaken_reloc, /* special_function */
394 "R_PPC64_ADDR14_BRNTAKEN",/* name */
395 FALSE, /* partial_inplace */
397 0x0000fffc, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 /* A relative 26 bit branch; the lower two bits must be zero. */
401 HOWTO (R_PPC64_REL24, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 TRUE, /* pc_relative */
407 complain_overflow_signed, /* complain_on_overflow */
408 ppc64_elf_branch_reloc, /* special_function */
409 "R_PPC64_REL24", /* name */
410 FALSE, /* partial_inplace */
412 0x03fffffc, /* dst_mask */
413 TRUE), /* pcrel_offset */
415 /* A relative 16 bit branch; the lower two bits must be zero. */
416 HOWTO (R_PPC64_REL14, /* type */
418 2, /* size (0 = byte, 1 = short, 2 = long) */
420 TRUE, /* pc_relative */
422 complain_overflow_signed, /* complain_on_overflow */
423 ppc64_elf_branch_reloc, /* special_function */
424 "R_PPC64_REL14", /* name */
425 FALSE, /* partial_inplace */
427 0x0000fffc, /* dst_mask */
428 TRUE), /* pcrel_offset */
430 /* A relative 16 bit branch. Bit 10 should be set to indicate that
431 the branch is expected to be taken. The lower two bits must be
433 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE, /* pc_relative */
439 complain_overflow_signed, /* complain_on_overflow */
440 ppc64_elf_brtaken_reloc, /* special_function */
441 "R_PPC64_REL14_BRTAKEN", /* name */
442 FALSE, /* partial_inplace */
444 0x0000fffc, /* dst_mask */
445 TRUE), /* pcrel_offset */
447 /* A relative 16 bit branch. Bit 10 should be set to indicate that
448 the branch is not expected to be taken. The lower two bits must
450 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE, /* pc_relative */
456 complain_overflow_signed, /* complain_on_overflow */
457 ppc64_elf_brtaken_reloc, /* special_function */
458 "R_PPC64_REL14_BRNTAKEN",/* name */
459 FALSE, /* partial_inplace */
461 0x0000fffc, /* dst_mask */
462 TRUE), /* pcrel_offset */
464 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
466 HOWTO (R_PPC64_GOT16, /* type */
468 1, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE, /* pc_relative */
472 complain_overflow_signed, /* complain_on_overflow */
473 ppc64_elf_unhandled_reloc, /* special_function */
474 "R_PPC64_GOT16", /* name */
475 FALSE, /* partial_inplace */
477 0xffff, /* dst_mask */
478 FALSE), /* pcrel_offset */
480 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
482 HOWTO (R_PPC64_GOT16_LO, /* type */
484 1, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE, /* pc_relative */
488 complain_overflow_dont, /* complain_on_overflow */
489 ppc64_elf_unhandled_reloc, /* special_function */
490 "R_PPC64_GOT16_LO", /* name */
491 FALSE, /* partial_inplace */
493 0xffff, /* dst_mask */
494 FALSE), /* pcrel_offset */
496 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
498 HOWTO (R_PPC64_GOT16_HI, /* 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_HI", /* name */
507 FALSE, /* partial_inplace */
509 0xffff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
514 HOWTO (R_PPC64_GOT16_HA, /* type */
516 1, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE, /* pc_relative */
520 complain_overflow_signed,/* complain_on_overflow */
521 ppc64_elf_unhandled_reloc, /* special_function */
522 "R_PPC64_GOT16_HA", /* name */
523 FALSE, /* partial_inplace */
525 0xffff, /* dst_mask */
526 FALSE), /* pcrel_offset */
528 /* This is used only by the dynamic linker. The symbol should exist
529 both in the object being run and in some shared library. The
530 dynamic linker copies the data addressed by the symbol from the
531 shared library into the object, because the object being
532 run has to have the data at some particular address. */
533 HOWTO (R_PPC64_COPY, /* type */
535 0, /* this one is variable size */
537 FALSE, /* pc_relative */
539 complain_overflow_dont, /* complain_on_overflow */
540 ppc64_elf_unhandled_reloc, /* special_function */
541 "R_PPC64_COPY", /* name */
542 FALSE, /* partial_inplace */
545 FALSE), /* pcrel_offset */
547 /* Like R_PPC64_ADDR64, but used when setting global offset table
549 HOWTO (R_PPC64_GLOB_DAT, /* type */
551 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
553 FALSE, /* pc_relative */
555 complain_overflow_dont, /* complain_on_overflow */
556 ppc64_elf_unhandled_reloc, /* special_function */
557 "R_PPC64_GLOB_DAT", /* name */
558 FALSE, /* partial_inplace */
560 ONES (64), /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* Created by the link editor. Marks a procedure linkage table
564 entry for a symbol. */
565 HOWTO (R_PPC64_JMP_SLOT, /* type */
567 0, /* size (0 = byte, 1 = short, 2 = long) */
569 FALSE, /* pc_relative */
571 complain_overflow_dont, /* complain_on_overflow */
572 ppc64_elf_unhandled_reloc, /* special_function */
573 "R_PPC64_JMP_SLOT", /* name */
574 FALSE, /* partial_inplace */
577 FALSE), /* pcrel_offset */
579 /* Used only by the dynamic linker. When the object is run, this
580 doubleword64 is set to the load address of the object, plus the
582 HOWTO (R_PPC64_RELATIVE, /* type */
584 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
586 FALSE, /* pc_relative */
588 complain_overflow_dont, /* complain_on_overflow */
589 bfd_elf_generic_reloc, /* special_function */
590 "R_PPC64_RELATIVE", /* name */
591 FALSE, /* partial_inplace */
593 ONES (64), /* dst_mask */
594 FALSE), /* pcrel_offset */
596 /* Like R_PPC64_ADDR32, but may be unaligned. */
597 HOWTO (R_PPC64_UADDR32, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 FALSE, /* pc_relative */
603 complain_overflow_bitfield, /* complain_on_overflow */
604 bfd_elf_generic_reloc, /* special_function */
605 "R_PPC64_UADDR32", /* name */
606 FALSE, /* partial_inplace */
608 0xffffffff, /* dst_mask */
609 FALSE), /* pcrel_offset */
611 /* Like R_PPC64_ADDR16, but may be unaligned. */
612 HOWTO (R_PPC64_UADDR16, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE, /* pc_relative */
618 complain_overflow_bitfield, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 "R_PPC64_UADDR16", /* name */
621 FALSE, /* partial_inplace */
623 0xffff, /* dst_mask */
624 FALSE), /* pcrel_offset */
626 /* 32-bit PC relative. */
627 HOWTO (R_PPC64_REL32, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 TRUE, /* pc_relative */
633 /* FIXME: Verify. Was complain_overflow_bitfield. */
634 complain_overflow_signed, /* complain_on_overflow */
635 bfd_elf_generic_reloc, /* special_function */
636 "R_PPC64_REL32", /* name */
637 FALSE, /* partial_inplace */
639 0xffffffff, /* dst_mask */
640 TRUE), /* pcrel_offset */
642 /* 32-bit relocation to the symbol's procedure linkage table. */
643 HOWTO (R_PPC64_PLT32, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE, /* pc_relative */
649 complain_overflow_bitfield, /* complain_on_overflow */
650 ppc64_elf_unhandled_reloc, /* special_function */
651 "R_PPC64_PLT32", /* name */
652 FALSE, /* partial_inplace */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
658 FIXME: R_PPC64_PLTREL32 not supported. */
659 HOWTO (R_PPC64_PLTREL32, /* 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_PLTREL32", /* name */
668 FALSE, /* partial_inplace */
670 0xffffffff, /* dst_mask */
671 TRUE), /* pcrel_offset */
673 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
675 HOWTO (R_PPC64_PLT16_LO, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE, /* pc_relative */
681 complain_overflow_dont, /* complain_on_overflow */
682 ppc64_elf_unhandled_reloc, /* special_function */
683 "R_PPC64_PLT16_LO", /* name */
684 FALSE, /* partial_inplace */
686 0xffff, /* dst_mask */
687 FALSE), /* pcrel_offset */
689 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
691 HOWTO (R_PPC64_PLT16_HI, /* type */
693 1, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE, /* pc_relative */
697 complain_overflow_signed, /* complain_on_overflow */
698 ppc64_elf_unhandled_reloc, /* special_function */
699 "R_PPC64_PLT16_HI", /* name */
700 FALSE, /* partial_inplace */
702 0xffff, /* dst_mask */
703 FALSE), /* pcrel_offset */
705 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
707 HOWTO (R_PPC64_PLT16_HA, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE, /* pc_relative */
713 complain_overflow_signed, /* complain_on_overflow */
714 ppc64_elf_unhandled_reloc, /* special_function */
715 "R_PPC64_PLT16_HA", /* name */
716 FALSE, /* partial_inplace */
718 0xffff, /* dst_mask */
719 FALSE), /* pcrel_offset */
721 /* 16-bit section relative relocation. */
722 HOWTO (R_PPC64_SECTOFF, /* type */
724 1, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE, /* pc_relative */
728 complain_overflow_bitfield, /* complain_on_overflow */
729 ppc64_elf_sectoff_reloc, /* special_function */
730 "R_PPC64_SECTOFF", /* name */
731 FALSE, /* partial_inplace */
733 0xffff, /* dst_mask */
734 FALSE), /* pcrel_offset */
736 /* Like R_PPC64_SECTOFF, but no overflow warning. */
737 HOWTO (R_PPC64_SECTOFF_LO, /* type */
739 1, /* size (0 = byte, 1 = short, 2 = long) */
741 FALSE, /* pc_relative */
743 complain_overflow_dont, /* complain_on_overflow */
744 ppc64_elf_sectoff_reloc, /* special_function */
745 "R_PPC64_SECTOFF_LO", /* name */
746 FALSE, /* partial_inplace */
748 0xffff, /* dst_mask */
749 FALSE), /* pcrel_offset */
751 /* 16-bit upper half section relative relocation. */
752 HOWTO (R_PPC64_SECTOFF_HI, /* type */
754 1, /* size (0 = byte, 1 = short, 2 = long) */
756 FALSE, /* pc_relative */
758 complain_overflow_signed, /* complain_on_overflow */
759 ppc64_elf_sectoff_reloc, /* special_function */
760 "R_PPC64_SECTOFF_HI", /* name */
761 FALSE, /* partial_inplace */
763 0xffff, /* dst_mask */
764 FALSE), /* pcrel_offset */
766 /* 16-bit upper half adjusted section relative relocation. */
767 HOWTO (R_PPC64_SECTOFF_HA, /* type */
769 1, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE, /* pc_relative */
773 complain_overflow_signed, /* complain_on_overflow */
774 ppc64_elf_sectoff_ha_reloc, /* special_function */
775 "R_PPC64_SECTOFF_HA", /* name */
776 FALSE, /* partial_inplace */
778 0xffff, /* dst_mask */
779 FALSE), /* pcrel_offset */
781 /* Like R_PPC64_REL24 without touching the two least significant bits. */
782 HOWTO (R_PPC64_REL30, /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 TRUE, /* pc_relative */
788 complain_overflow_dont, /* complain_on_overflow */
789 bfd_elf_generic_reloc, /* special_function */
790 "R_PPC64_REL30", /* name */
791 FALSE, /* partial_inplace */
793 0xfffffffc, /* dst_mask */
794 TRUE), /* pcrel_offset */
796 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
798 /* A standard 64-bit relocation. */
799 HOWTO (R_PPC64_ADDR64, /* type */
801 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
803 FALSE, /* pc_relative */
805 complain_overflow_dont, /* complain_on_overflow */
806 bfd_elf_generic_reloc, /* special_function */
807 "R_PPC64_ADDR64", /* name */
808 FALSE, /* partial_inplace */
810 ONES (64), /* dst_mask */
811 FALSE), /* pcrel_offset */
813 /* The bits 32-47 of an address. */
814 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE, /* pc_relative */
820 complain_overflow_dont, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_PPC64_ADDR16_HIGHER", /* name */
823 FALSE, /* partial_inplace */
825 0xffff, /* dst_mask */
826 FALSE), /* pcrel_offset */
828 /* The bits 32-47 of an address, plus 1 if the contents of the low
829 16 bits, treated as a signed number, is negative. */
830 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE, /* pc_relative */
836 complain_overflow_dont, /* complain_on_overflow */
837 ppc64_elf_ha_reloc, /* special_function */
838 "R_PPC64_ADDR16_HIGHERA", /* name */
839 FALSE, /* partial_inplace */
841 0xffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
844 /* The bits 48-63 of an address. */
845 HOWTO (R_PPC64_ADDR16_HIGHEST,/* 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_HIGHEST", /* name */
854 FALSE, /* partial_inplace */
856 0xffff, /* dst_mask */
857 FALSE), /* pcrel_offset */
859 /* The bits 48-63 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_HIGHESTA,/* 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_HIGHESTA", /* name */
870 FALSE, /* partial_inplace */
872 0xffff, /* dst_mask */
873 FALSE), /* pcrel_offset */
875 /* Like ADDR64, but may be unaligned. */
876 HOWTO (R_PPC64_UADDR64, /* type */
878 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
880 FALSE, /* pc_relative */
882 complain_overflow_dont, /* complain_on_overflow */
883 bfd_elf_generic_reloc, /* special_function */
884 "R_PPC64_UADDR64", /* name */
885 FALSE, /* partial_inplace */
887 ONES (64), /* dst_mask */
888 FALSE), /* pcrel_offset */
890 /* 64-bit relative relocation. */
891 HOWTO (R_PPC64_REL64, /* type */
893 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
895 TRUE, /* pc_relative */
897 complain_overflow_dont, /* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 "R_PPC64_REL64", /* name */
900 FALSE, /* partial_inplace */
902 ONES (64), /* dst_mask */
903 TRUE), /* pcrel_offset */
905 /* 64-bit relocation to the symbol's procedure linkage table. */
906 HOWTO (R_PPC64_PLT64, /* type */
908 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
910 FALSE, /* pc_relative */
912 complain_overflow_dont, /* complain_on_overflow */
913 ppc64_elf_unhandled_reloc, /* special_function */
914 "R_PPC64_PLT64", /* name */
915 FALSE, /* partial_inplace */
917 ONES (64), /* dst_mask */
918 FALSE), /* pcrel_offset */
920 /* 64-bit PC relative relocation to the symbol's procedure linkage
922 /* FIXME: R_PPC64_PLTREL64 not supported. */
923 HOWTO (R_PPC64_PLTREL64, /* type */
925 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
927 TRUE, /* pc_relative */
929 complain_overflow_dont, /* complain_on_overflow */
930 ppc64_elf_unhandled_reloc, /* special_function */
931 "R_PPC64_PLTREL64", /* name */
932 FALSE, /* partial_inplace */
934 ONES (64), /* dst_mask */
935 TRUE), /* pcrel_offset */
937 /* 16 bit TOC-relative relocation. */
939 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
940 HOWTO (R_PPC64_TOC16, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE, /* pc_relative */
946 complain_overflow_signed, /* complain_on_overflow */
947 ppc64_elf_toc_reloc, /* special_function */
948 "R_PPC64_TOC16", /* name */
949 FALSE, /* partial_inplace */
951 0xffff, /* dst_mask */
952 FALSE), /* pcrel_offset */
954 /* 16 bit TOC-relative relocation without overflow. */
956 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
957 HOWTO (R_PPC64_TOC16_LO, /* type */
959 1, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE, /* pc_relative */
963 complain_overflow_dont, /* complain_on_overflow */
964 ppc64_elf_toc_reloc, /* special_function */
965 "R_PPC64_TOC16_LO", /* name */
966 FALSE, /* partial_inplace */
968 0xffff, /* dst_mask */
969 FALSE), /* pcrel_offset */
971 /* 16 bit TOC-relative relocation, high 16 bits. */
973 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
974 HOWTO (R_PPC64_TOC16_HI, /* type */
976 1, /* size (0 = byte, 1 = short, 2 = long) */
978 FALSE, /* pc_relative */
980 complain_overflow_signed, /* complain_on_overflow */
981 ppc64_elf_toc_reloc, /* special_function */
982 "R_PPC64_TOC16_HI", /* name */
983 FALSE, /* partial_inplace */
985 0xffff, /* dst_mask */
986 FALSE), /* pcrel_offset */
988 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
989 contents of the low 16 bits, treated as a signed number, is
992 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
993 HOWTO (R_PPC64_TOC16_HA, /* type */
995 1, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE, /* pc_relative */
999 complain_overflow_signed, /* complain_on_overflow */
1000 ppc64_elf_toc_ha_reloc, /* special_function */
1001 "R_PPC64_TOC16_HA", /* name */
1002 FALSE, /* partial_inplace */
1004 0xffff, /* dst_mask */
1005 FALSE), /* pcrel_offset */
1007 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1009 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1010 HOWTO (R_PPC64_TOC, /* type */
1012 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1014 FALSE, /* pc_relative */
1016 complain_overflow_bitfield, /* complain_on_overflow */
1017 ppc64_elf_toc64_reloc, /* special_function */
1018 "R_PPC64_TOC", /* name */
1019 FALSE, /* partial_inplace */
1021 ONES (64), /* dst_mask */
1022 FALSE), /* pcrel_offset */
1024 /* Like R_PPC64_GOT16, but also informs the link editor that the
1025 value to relocate may (!) refer to a PLT entry which the link
1026 editor (a) may replace with the symbol value. If the link editor
1027 is unable to fully resolve the symbol, it may (b) create a PLT
1028 entry and store the address to the new PLT entry in the GOT.
1029 This permits lazy resolution of function symbols at run time.
1030 The link editor may also skip all of this and just (c) emit a
1031 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1032 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1033 HOWTO (R_PPC64_PLTGOT16, /* type */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE, /* pc_relative */
1039 complain_overflow_signed, /* complain_on_overflow */
1040 ppc64_elf_unhandled_reloc, /* special_function */
1041 "R_PPC64_PLTGOT16", /* name */
1042 FALSE, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE), /* pcrel_offset */
1047 /* Like R_PPC64_PLTGOT16, but without overflow. */
1048 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1049 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
1051 1, /* size (0 = byte, 1 = short, 2 = long) */
1053 FALSE, /* pc_relative */
1055 complain_overflow_dont, /* complain_on_overflow */
1056 ppc64_elf_unhandled_reloc, /* special_function */
1057 "R_PPC64_PLTGOT16_LO", /* name */
1058 FALSE, /* partial_inplace */
1060 0xffff, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1063 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1064 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1065 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1066 16, /* rightshift */
1067 1, /* size (0 = byte, 1 = short, 2 = long) */
1069 FALSE, /* pc_relative */
1071 complain_overflow_signed, /* complain_on_overflow */
1072 ppc64_elf_unhandled_reloc, /* special_function */
1073 "R_PPC64_PLTGOT16_HI", /* name */
1074 FALSE, /* partial_inplace */
1076 0xffff, /* dst_mask */
1077 FALSE), /* pcrel_offset */
1079 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1080 1 if the contents of the low 16 bits, treated as a signed number,
1082 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1083 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1084 16, /* rightshift */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE, /* pc_relative */
1089 complain_overflow_signed, /* complain_on_overflow */
1090 ppc64_elf_unhandled_reloc, /* special_function */
1091 "R_PPC64_PLTGOT16_HA", /* name */
1092 FALSE, /* partial_inplace */
1094 0xffff, /* dst_mask */
1095 FALSE), /* pcrel_offset */
1097 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1098 HOWTO (R_PPC64_ADDR16_DS, /* type */
1100 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE, /* pc_relative */
1104 complain_overflow_bitfield, /* complain_on_overflow */
1105 bfd_elf_generic_reloc, /* special_function */
1106 "R_PPC64_ADDR16_DS", /* name */
1107 FALSE, /* partial_inplace */
1109 0xfffc, /* dst_mask */
1110 FALSE), /* pcrel_offset */
1112 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1113 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1115 1, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE, /* pc_relative */
1119 complain_overflow_dont,/* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 "R_PPC64_ADDR16_LO_DS",/* name */
1122 FALSE, /* partial_inplace */
1124 0xfffc, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1127 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1128 HOWTO (R_PPC64_GOT16_DS, /* type */
1130 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 FALSE, /* pc_relative */
1134 complain_overflow_signed, /* complain_on_overflow */
1135 ppc64_elf_unhandled_reloc, /* special_function */
1136 "R_PPC64_GOT16_DS", /* name */
1137 FALSE, /* partial_inplace */
1139 0xfffc, /* dst_mask */
1140 FALSE), /* pcrel_offset */
1142 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1143 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1145 1, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_dont, /* complain_on_overflow */
1150 ppc64_elf_unhandled_reloc, /* special_function */
1151 "R_PPC64_GOT16_LO_DS", /* name */
1152 FALSE, /* partial_inplace */
1154 0xfffc, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1158 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1160 1, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 ppc64_elf_unhandled_reloc, /* special_function */
1166 "R_PPC64_PLT16_LO_DS", /* name */
1167 FALSE, /* partial_inplace */
1169 0xfffc, /* dst_mask */
1170 FALSE), /* pcrel_offset */
1172 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1173 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1175 1, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE, /* pc_relative */
1179 complain_overflow_bitfield, /* complain_on_overflow */
1180 ppc64_elf_sectoff_reloc, /* special_function */
1181 "R_PPC64_SECTOFF_DS", /* name */
1182 FALSE, /* partial_inplace */
1184 0xfffc, /* dst_mask */
1185 FALSE), /* pcrel_offset */
1187 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1188 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1190 1, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE, /* pc_relative */
1194 complain_overflow_dont, /* complain_on_overflow */
1195 ppc64_elf_sectoff_reloc, /* special_function */
1196 "R_PPC64_SECTOFF_LO_DS",/* name */
1197 FALSE, /* partial_inplace */
1199 0xfffc, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1202 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1203 HOWTO (R_PPC64_TOC16_DS, /* type */
1205 1, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE, /* pc_relative */
1209 complain_overflow_signed, /* complain_on_overflow */
1210 ppc64_elf_toc_reloc, /* special_function */
1211 "R_PPC64_TOC16_DS", /* name */
1212 FALSE, /* partial_inplace */
1214 0xfffc, /* dst_mask */
1215 FALSE), /* pcrel_offset */
1217 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1218 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1220 1, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE, /* pc_relative */
1224 complain_overflow_dont, /* complain_on_overflow */
1225 ppc64_elf_toc_reloc, /* special_function */
1226 "R_PPC64_TOC16_LO_DS", /* name */
1227 FALSE, /* partial_inplace */
1229 0xfffc, /* dst_mask */
1230 FALSE), /* pcrel_offset */
1232 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1233 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1234 HOWTO (R_PPC64_PLTGOT16_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_unhandled_reloc, /* special_function */
1242 "R_PPC64_PLTGOT16_DS", /* name */
1243 FALSE, /* partial_inplace */
1245 0xfffc, /* dst_mask */
1246 FALSE), /* pcrel_offset */
1248 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1249 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1250 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1252 1, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE, /* pc_relative */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 ppc64_elf_unhandled_reloc, /* special_function */
1258 "R_PPC64_PLTGOT16_LO_DS",/* name */
1259 FALSE, /* partial_inplace */
1261 0xfffc, /* dst_mask */
1262 FALSE), /* pcrel_offset */
1264 /* Marker relocs for TLS. */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 FALSE, /* pc_relative */
1271 complain_overflow_dont, /* complain_on_overflow */
1272 bfd_elf_generic_reloc, /* special_function */
1273 "R_PPC64_TLS", /* name */
1274 FALSE, /* partial_inplace */
1277 FALSE), /* pcrel_offset */
1279 HOWTO (R_PPC64_TLSGD,
1281 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE, /* pc_relative */
1285 complain_overflow_dont, /* complain_on_overflow */
1286 bfd_elf_generic_reloc, /* special_function */
1287 "R_PPC64_TLSGD", /* name */
1288 FALSE, /* partial_inplace */
1291 FALSE), /* pcrel_offset */
1293 HOWTO (R_PPC64_TLSLD,
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE, /* pc_relative */
1299 complain_overflow_dont, /* complain_on_overflow */
1300 bfd_elf_generic_reloc, /* special_function */
1301 "R_PPC64_TLSLD", /* name */
1302 FALSE, /* partial_inplace */
1305 FALSE), /* pcrel_offset */
1307 HOWTO (R_PPC64_TOCSAVE,
1309 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE, /* pc_relative */
1313 complain_overflow_dont, /* complain_on_overflow */
1314 bfd_elf_generic_reloc, /* special_function */
1315 "R_PPC64_TOCSAVE", /* name */
1316 FALSE, /* partial_inplace */
1319 FALSE), /* pcrel_offset */
1321 /* Computes the load module index of the load module that contains the
1322 definition of its TLS sym. */
1323 HOWTO (R_PPC64_DTPMOD64,
1325 4, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE, /* pc_relative */
1329 complain_overflow_dont, /* complain_on_overflow */
1330 ppc64_elf_unhandled_reloc, /* special_function */
1331 "R_PPC64_DTPMOD64", /* name */
1332 FALSE, /* partial_inplace */
1334 ONES (64), /* dst_mask */
1335 FALSE), /* pcrel_offset */
1337 /* Computes a dtv-relative displacement, the difference between the value
1338 of sym+add and the base address of the thread-local storage block that
1339 contains the definition of sym, minus 0x8000. */
1340 HOWTO (R_PPC64_DTPREL64,
1342 4, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE, /* pc_relative */
1346 complain_overflow_dont, /* complain_on_overflow */
1347 ppc64_elf_unhandled_reloc, /* special_function */
1348 "R_PPC64_DTPREL64", /* name */
1349 FALSE, /* partial_inplace */
1351 ONES (64), /* dst_mask */
1352 FALSE), /* pcrel_offset */
1354 /* A 16 bit dtprel reloc. */
1355 HOWTO (R_PPC64_DTPREL16,
1357 1, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE, /* pc_relative */
1361 complain_overflow_signed, /* complain_on_overflow */
1362 ppc64_elf_unhandled_reloc, /* special_function */
1363 "R_PPC64_DTPREL16", /* name */
1364 FALSE, /* partial_inplace */
1366 0xffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 /* Like DTPREL16, but no overflow. */
1370 HOWTO (R_PPC64_DTPREL16_LO,
1372 1, /* size (0 = byte, 1 = short, 2 = long) */
1374 FALSE, /* pc_relative */
1376 complain_overflow_dont, /* complain_on_overflow */
1377 ppc64_elf_unhandled_reloc, /* special_function */
1378 "R_PPC64_DTPREL16_LO", /* name */
1379 FALSE, /* partial_inplace */
1381 0xffff, /* dst_mask */
1382 FALSE), /* pcrel_offset */
1384 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1385 HOWTO (R_PPC64_DTPREL16_HI,
1386 16, /* rightshift */
1387 1, /* size (0 = byte, 1 = short, 2 = long) */
1389 FALSE, /* pc_relative */
1391 complain_overflow_signed, /* complain_on_overflow */
1392 ppc64_elf_unhandled_reloc, /* special_function */
1393 "R_PPC64_DTPREL16_HI", /* name */
1394 FALSE, /* partial_inplace */
1396 0xffff, /* dst_mask */
1397 FALSE), /* pcrel_offset */
1399 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1400 HOWTO (R_PPC64_DTPREL16_HA,
1401 16, /* rightshift */
1402 1, /* size (0 = byte, 1 = short, 2 = long) */
1404 FALSE, /* pc_relative */
1406 complain_overflow_signed, /* complain_on_overflow */
1407 ppc64_elf_unhandled_reloc, /* special_function */
1408 "R_PPC64_DTPREL16_HA", /* name */
1409 FALSE, /* partial_inplace */
1411 0xffff, /* dst_mask */
1412 FALSE), /* pcrel_offset */
1414 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1415 HOWTO (R_PPC64_DTPREL16_HIGHER,
1416 32, /* rightshift */
1417 1, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE, /* pc_relative */
1421 complain_overflow_dont, /* complain_on_overflow */
1422 ppc64_elf_unhandled_reloc, /* special_function */
1423 "R_PPC64_DTPREL16_HIGHER", /* name */
1424 FALSE, /* partial_inplace */
1426 0xffff, /* dst_mask */
1427 FALSE), /* pcrel_offset */
1429 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1430 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1431 32, /* rightshift */
1432 1, /* size (0 = byte, 1 = short, 2 = long) */
1434 FALSE, /* pc_relative */
1436 complain_overflow_dont, /* complain_on_overflow */
1437 ppc64_elf_unhandled_reloc, /* special_function */
1438 "R_PPC64_DTPREL16_HIGHERA", /* name */
1439 FALSE, /* partial_inplace */
1441 0xffff, /* dst_mask */
1442 FALSE), /* pcrel_offset */
1444 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1445 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1446 48, /* rightshift */
1447 1, /* size (0 = byte, 1 = short, 2 = long) */
1449 FALSE, /* pc_relative */
1451 complain_overflow_dont, /* complain_on_overflow */
1452 ppc64_elf_unhandled_reloc, /* special_function */
1453 "R_PPC64_DTPREL16_HIGHEST", /* name */
1454 FALSE, /* partial_inplace */
1456 0xffff, /* dst_mask */
1457 FALSE), /* pcrel_offset */
1459 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1460 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1461 48, /* rightshift */
1462 1, /* size (0 = byte, 1 = short, 2 = long) */
1464 FALSE, /* pc_relative */
1466 complain_overflow_dont, /* complain_on_overflow */
1467 ppc64_elf_unhandled_reloc, /* special_function */
1468 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1469 FALSE, /* partial_inplace */
1471 0xffff, /* dst_mask */
1472 FALSE), /* pcrel_offset */
1474 /* Like DTPREL16, but for insns with a DS field. */
1475 HOWTO (R_PPC64_DTPREL16_DS,
1477 1, /* size (0 = byte, 1 = short, 2 = long) */
1479 FALSE, /* pc_relative */
1481 complain_overflow_signed, /* complain_on_overflow */
1482 ppc64_elf_unhandled_reloc, /* special_function */
1483 "R_PPC64_DTPREL16_DS", /* name */
1484 FALSE, /* partial_inplace */
1486 0xfffc, /* dst_mask */
1487 FALSE), /* pcrel_offset */
1489 /* Like DTPREL16_DS, but no overflow. */
1490 HOWTO (R_PPC64_DTPREL16_LO_DS,
1492 1, /* size (0 = byte, 1 = short, 2 = long) */
1494 FALSE, /* pc_relative */
1496 complain_overflow_dont, /* complain_on_overflow */
1497 ppc64_elf_unhandled_reloc, /* special_function */
1498 "R_PPC64_DTPREL16_LO_DS", /* name */
1499 FALSE, /* partial_inplace */
1501 0xfffc, /* dst_mask */
1502 FALSE), /* pcrel_offset */
1504 /* Computes a tp-relative displacement, the difference between the value of
1505 sym+add and the value of the thread pointer (r13). */
1506 HOWTO (R_PPC64_TPREL64,
1508 4, /* size (0 = byte, 1 = short, 2 = long) */
1510 FALSE, /* pc_relative */
1512 complain_overflow_dont, /* complain_on_overflow */
1513 ppc64_elf_unhandled_reloc, /* special_function */
1514 "R_PPC64_TPREL64", /* name */
1515 FALSE, /* partial_inplace */
1517 ONES (64), /* dst_mask */
1518 FALSE), /* pcrel_offset */
1520 /* A 16 bit tprel reloc. */
1521 HOWTO (R_PPC64_TPREL16,
1523 1, /* size (0 = byte, 1 = short, 2 = long) */
1525 FALSE, /* pc_relative */
1527 complain_overflow_signed, /* complain_on_overflow */
1528 ppc64_elf_unhandled_reloc, /* special_function */
1529 "R_PPC64_TPREL16", /* name */
1530 FALSE, /* partial_inplace */
1532 0xffff, /* dst_mask */
1533 FALSE), /* pcrel_offset */
1535 /* Like TPREL16, but no overflow. */
1536 HOWTO (R_PPC64_TPREL16_LO,
1538 1, /* size (0 = byte, 1 = short, 2 = long) */
1540 FALSE, /* pc_relative */
1542 complain_overflow_dont, /* complain_on_overflow */
1543 ppc64_elf_unhandled_reloc, /* special_function */
1544 "R_PPC64_TPREL16_LO", /* name */
1545 FALSE, /* partial_inplace */
1547 0xffff, /* dst_mask */
1548 FALSE), /* pcrel_offset */
1550 /* Like TPREL16_LO, but next higher group of 16 bits. */
1551 HOWTO (R_PPC64_TPREL16_HI,
1552 16, /* rightshift */
1553 1, /* size (0 = byte, 1 = short, 2 = long) */
1555 FALSE, /* pc_relative */
1557 complain_overflow_signed, /* complain_on_overflow */
1558 ppc64_elf_unhandled_reloc, /* special_function */
1559 "R_PPC64_TPREL16_HI", /* name */
1560 FALSE, /* partial_inplace */
1562 0xffff, /* dst_mask */
1563 FALSE), /* pcrel_offset */
1565 /* Like TPREL16_HI, but adjust for low 16 bits. */
1566 HOWTO (R_PPC64_TPREL16_HA,
1567 16, /* rightshift */
1568 1, /* size (0 = byte, 1 = short, 2 = long) */
1570 FALSE, /* pc_relative */
1572 complain_overflow_signed, /* complain_on_overflow */
1573 ppc64_elf_unhandled_reloc, /* special_function */
1574 "R_PPC64_TPREL16_HA", /* name */
1575 FALSE, /* partial_inplace */
1577 0xffff, /* dst_mask */
1578 FALSE), /* pcrel_offset */
1580 /* Like TPREL16_HI, but next higher group of 16 bits. */
1581 HOWTO (R_PPC64_TPREL16_HIGHER,
1582 32, /* rightshift */
1583 1, /* size (0 = byte, 1 = short, 2 = long) */
1585 FALSE, /* pc_relative */
1587 complain_overflow_dont, /* complain_on_overflow */
1588 ppc64_elf_unhandled_reloc, /* special_function */
1589 "R_PPC64_TPREL16_HIGHER", /* name */
1590 FALSE, /* partial_inplace */
1592 0xffff, /* dst_mask */
1593 FALSE), /* pcrel_offset */
1595 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1596 HOWTO (R_PPC64_TPREL16_HIGHERA,
1597 32, /* rightshift */
1598 1, /* size (0 = byte, 1 = short, 2 = long) */
1600 FALSE, /* pc_relative */
1602 complain_overflow_dont, /* complain_on_overflow */
1603 ppc64_elf_unhandled_reloc, /* special_function */
1604 "R_PPC64_TPREL16_HIGHERA", /* name */
1605 FALSE, /* partial_inplace */
1607 0xffff, /* dst_mask */
1608 FALSE), /* pcrel_offset */
1610 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1611 HOWTO (R_PPC64_TPREL16_HIGHEST,
1612 48, /* rightshift */
1613 1, /* size (0 = byte, 1 = short, 2 = long) */
1615 FALSE, /* pc_relative */
1617 complain_overflow_dont, /* complain_on_overflow */
1618 ppc64_elf_unhandled_reloc, /* special_function */
1619 "R_PPC64_TPREL16_HIGHEST", /* name */
1620 FALSE, /* partial_inplace */
1622 0xffff, /* dst_mask */
1623 FALSE), /* pcrel_offset */
1625 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1626 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1627 48, /* rightshift */
1628 1, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE, /* pc_relative */
1632 complain_overflow_dont, /* complain_on_overflow */
1633 ppc64_elf_unhandled_reloc, /* special_function */
1634 "R_PPC64_TPREL16_HIGHESTA", /* name */
1635 FALSE, /* partial_inplace */
1637 0xffff, /* dst_mask */
1638 FALSE), /* pcrel_offset */
1640 /* Like TPREL16, but for insns with a DS field. */
1641 HOWTO (R_PPC64_TPREL16_DS,
1643 1, /* size (0 = byte, 1 = short, 2 = long) */
1645 FALSE, /* pc_relative */
1647 complain_overflow_signed, /* complain_on_overflow */
1648 ppc64_elf_unhandled_reloc, /* special_function */
1649 "R_PPC64_TPREL16_DS", /* name */
1650 FALSE, /* partial_inplace */
1652 0xfffc, /* dst_mask */
1653 FALSE), /* pcrel_offset */
1655 /* Like TPREL16_DS, but no overflow. */
1656 HOWTO (R_PPC64_TPREL16_LO_DS,
1658 1, /* size (0 = byte, 1 = short, 2 = long) */
1660 FALSE, /* pc_relative */
1662 complain_overflow_dont, /* complain_on_overflow */
1663 ppc64_elf_unhandled_reloc, /* special_function */
1664 "R_PPC64_TPREL16_LO_DS", /* name */
1665 FALSE, /* partial_inplace */
1667 0xfffc, /* dst_mask */
1668 FALSE), /* pcrel_offset */
1670 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1671 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1672 to the first entry relative to the TOC base (r2). */
1673 HOWTO (R_PPC64_GOT_TLSGD16,
1675 1, /* size (0 = byte, 1 = short, 2 = long) */
1677 FALSE, /* pc_relative */
1679 complain_overflow_signed, /* complain_on_overflow */
1680 ppc64_elf_unhandled_reloc, /* special_function */
1681 "R_PPC64_GOT_TLSGD16", /* name */
1682 FALSE, /* partial_inplace */
1684 0xffff, /* dst_mask */
1685 FALSE), /* pcrel_offset */
1687 /* Like GOT_TLSGD16, but no overflow. */
1688 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1690 1, /* size (0 = byte, 1 = short, 2 = long) */
1692 FALSE, /* pc_relative */
1694 complain_overflow_dont, /* complain_on_overflow */
1695 ppc64_elf_unhandled_reloc, /* special_function */
1696 "R_PPC64_GOT_TLSGD16_LO", /* name */
1697 FALSE, /* partial_inplace */
1699 0xffff, /* dst_mask */
1700 FALSE), /* pcrel_offset */
1702 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1703 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1704 16, /* rightshift */
1705 1, /* size (0 = byte, 1 = short, 2 = long) */
1707 FALSE, /* pc_relative */
1709 complain_overflow_signed, /* complain_on_overflow */
1710 ppc64_elf_unhandled_reloc, /* special_function */
1711 "R_PPC64_GOT_TLSGD16_HI", /* name */
1712 FALSE, /* partial_inplace */
1714 0xffff, /* dst_mask */
1715 FALSE), /* pcrel_offset */
1717 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1718 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1719 16, /* rightshift */
1720 1, /* size (0 = byte, 1 = short, 2 = long) */
1722 FALSE, /* pc_relative */
1724 complain_overflow_signed, /* complain_on_overflow */
1725 ppc64_elf_unhandled_reloc, /* special_function */
1726 "R_PPC64_GOT_TLSGD16_HA", /* name */
1727 FALSE, /* partial_inplace */
1729 0xffff, /* dst_mask */
1730 FALSE), /* pcrel_offset */
1732 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1733 with values (sym+add)@dtpmod and zero, and computes the offset to the
1734 first entry relative to the TOC base (r2). */
1735 HOWTO (R_PPC64_GOT_TLSLD16,
1737 1, /* size (0 = byte, 1 = short, 2 = long) */
1739 FALSE, /* pc_relative */
1741 complain_overflow_signed, /* complain_on_overflow */
1742 ppc64_elf_unhandled_reloc, /* special_function */
1743 "R_PPC64_GOT_TLSLD16", /* name */
1744 FALSE, /* partial_inplace */
1746 0xffff, /* dst_mask */
1747 FALSE), /* pcrel_offset */
1749 /* Like GOT_TLSLD16, but no overflow. */
1750 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1752 1, /* size (0 = byte, 1 = short, 2 = long) */
1754 FALSE, /* pc_relative */
1756 complain_overflow_dont, /* complain_on_overflow */
1757 ppc64_elf_unhandled_reloc, /* special_function */
1758 "R_PPC64_GOT_TLSLD16_LO", /* name */
1759 FALSE, /* partial_inplace */
1761 0xffff, /* dst_mask */
1762 FALSE), /* pcrel_offset */
1764 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1765 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1766 16, /* rightshift */
1767 1, /* size (0 = byte, 1 = short, 2 = long) */
1769 FALSE, /* pc_relative */
1771 complain_overflow_signed, /* complain_on_overflow */
1772 ppc64_elf_unhandled_reloc, /* special_function */
1773 "R_PPC64_GOT_TLSLD16_HI", /* name */
1774 FALSE, /* partial_inplace */
1776 0xffff, /* dst_mask */
1777 FALSE), /* pcrel_offset */
1779 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1780 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1781 16, /* rightshift */
1782 1, /* size (0 = byte, 1 = short, 2 = long) */
1784 FALSE, /* pc_relative */
1786 complain_overflow_signed, /* complain_on_overflow */
1787 ppc64_elf_unhandled_reloc, /* special_function */
1788 "R_PPC64_GOT_TLSLD16_HA", /* name */
1789 FALSE, /* partial_inplace */
1791 0xffff, /* dst_mask */
1792 FALSE), /* pcrel_offset */
1794 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1795 the offset to the entry relative to the TOC base (r2). */
1796 HOWTO (R_PPC64_GOT_DTPREL16_DS,
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_DTPREL16_DS", /* name */
1805 FALSE, /* partial_inplace */
1807 0xfffc, /* dst_mask */
1808 FALSE), /* pcrel_offset */
1810 /* Like GOT_DTPREL16_DS, but no overflow. */
1811 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1813 1, /* size (0 = byte, 1 = short, 2 = long) */
1815 FALSE, /* pc_relative */
1817 complain_overflow_dont, /* complain_on_overflow */
1818 ppc64_elf_unhandled_reloc, /* special_function */
1819 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1820 FALSE, /* partial_inplace */
1822 0xfffc, /* dst_mask */
1823 FALSE), /* pcrel_offset */
1825 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1826 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1827 16, /* rightshift */
1828 1, /* size (0 = byte, 1 = short, 2 = long) */
1830 FALSE, /* pc_relative */
1832 complain_overflow_signed, /* complain_on_overflow */
1833 ppc64_elf_unhandled_reloc, /* special_function */
1834 "R_PPC64_GOT_DTPREL16_HI", /* name */
1835 FALSE, /* partial_inplace */
1837 0xffff, /* dst_mask */
1838 FALSE), /* pcrel_offset */
1840 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1841 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1842 16, /* rightshift */
1843 1, /* size (0 = byte, 1 = short, 2 = long) */
1845 FALSE, /* pc_relative */
1847 complain_overflow_signed, /* complain_on_overflow */
1848 ppc64_elf_unhandled_reloc, /* special_function */
1849 "R_PPC64_GOT_DTPREL16_HA", /* name */
1850 FALSE, /* partial_inplace */
1852 0xffff, /* dst_mask */
1853 FALSE), /* pcrel_offset */
1855 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1856 offset to the entry relative to the TOC base (r2). */
1857 HOWTO (R_PPC64_GOT_TPREL16_DS,
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_TPREL16_DS", /* name */
1866 FALSE, /* partial_inplace */
1868 0xfffc, /* dst_mask */
1869 FALSE), /* pcrel_offset */
1871 /* Like GOT_TPREL16_DS, but no overflow. */
1872 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1874 1, /* size (0 = byte, 1 = short, 2 = long) */
1876 FALSE, /* pc_relative */
1878 complain_overflow_dont, /* complain_on_overflow */
1879 ppc64_elf_unhandled_reloc, /* special_function */
1880 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1881 FALSE, /* partial_inplace */
1883 0xfffc, /* dst_mask */
1884 FALSE), /* pcrel_offset */
1886 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1887 HOWTO (R_PPC64_GOT_TPREL16_HI,
1888 16, /* rightshift */
1889 1, /* size (0 = byte, 1 = short, 2 = long) */
1891 FALSE, /* pc_relative */
1893 complain_overflow_signed, /* complain_on_overflow */
1894 ppc64_elf_unhandled_reloc, /* special_function */
1895 "R_PPC64_GOT_TPREL16_HI", /* name */
1896 FALSE, /* partial_inplace */
1898 0xffff, /* dst_mask */
1899 FALSE), /* pcrel_offset */
1901 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1902 HOWTO (R_PPC64_GOT_TPREL16_HA,
1903 16, /* rightshift */
1904 1, /* size (0 = byte, 1 = short, 2 = long) */
1906 FALSE, /* pc_relative */
1908 complain_overflow_signed, /* complain_on_overflow */
1909 ppc64_elf_unhandled_reloc, /* special_function */
1910 "R_PPC64_GOT_TPREL16_HA", /* name */
1911 FALSE, /* partial_inplace */
1913 0xffff, /* dst_mask */
1914 FALSE), /* pcrel_offset */
1916 HOWTO (R_PPC64_JMP_IREL, /* type */
1918 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1920 FALSE, /* pc_relative */
1922 complain_overflow_dont, /* complain_on_overflow */
1923 ppc64_elf_unhandled_reloc, /* special_function */
1924 "R_PPC64_JMP_IREL", /* name */
1925 FALSE, /* partial_inplace */
1928 FALSE), /* pcrel_offset */
1930 HOWTO (R_PPC64_IRELATIVE, /* type */
1932 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1934 FALSE, /* pc_relative */
1936 complain_overflow_dont, /* complain_on_overflow */
1937 bfd_elf_generic_reloc, /* special_function */
1938 "R_PPC64_IRELATIVE", /* name */
1939 FALSE, /* partial_inplace */
1941 ONES (64), /* dst_mask */
1942 FALSE), /* pcrel_offset */
1944 /* A 16 bit relative relocation. */
1945 HOWTO (R_PPC64_REL16, /* type */
1947 1, /* size (0 = byte, 1 = short, 2 = long) */
1949 TRUE, /* pc_relative */
1951 complain_overflow_bitfield, /* complain_on_overflow */
1952 bfd_elf_generic_reloc, /* special_function */
1953 "R_PPC64_REL16", /* name */
1954 FALSE, /* partial_inplace */
1956 0xffff, /* dst_mask */
1957 TRUE), /* pcrel_offset */
1959 /* A 16 bit relative relocation without overflow. */
1960 HOWTO (R_PPC64_REL16_LO, /* type */
1962 1, /* size (0 = byte, 1 = short, 2 = long) */
1964 TRUE, /* pc_relative */
1966 complain_overflow_dont,/* complain_on_overflow */
1967 bfd_elf_generic_reloc, /* special_function */
1968 "R_PPC64_REL16_LO", /* name */
1969 FALSE, /* partial_inplace */
1971 0xffff, /* dst_mask */
1972 TRUE), /* pcrel_offset */
1974 /* The high order 16 bits of a relative address. */
1975 HOWTO (R_PPC64_REL16_HI, /* type */
1976 16, /* rightshift */
1977 1, /* size (0 = byte, 1 = short, 2 = long) */
1979 TRUE, /* pc_relative */
1981 complain_overflow_signed, /* complain_on_overflow */
1982 bfd_elf_generic_reloc, /* special_function */
1983 "R_PPC64_REL16_HI", /* name */
1984 FALSE, /* partial_inplace */
1986 0xffff, /* dst_mask */
1987 TRUE), /* pcrel_offset */
1989 /* The high order 16 bits of a relative address, plus 1 if the contents of
1990 the low 16 bits, treated as a signed number, is negative. */
1991 HOWTO (R_PPC64_REL16_HA, /* type */
1992 16, /* rightshift */
1993 1, /* size (0 = byte, 1 = short, 2 = long) */
1995 TRUE, /* pc_relative */
1997 complain_overflow_signed, /* complain_on_overflow */
1998 ppc64_elf_ha_reloc, /* special_function */
1999 "R_PPC64_REL16_HA", /* name */
2000 FALSE, /* partial_inplace */
2002 0xffff, /* dst_mask */
2003 TRUE), /* pcrel_offset */
2005 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2006 HOWTO (R_PPC64_ADDR16_HIGH, /* type */
2007 16, /* rightshift */
2008 1, /* size (0 = byte, 1 = short, 2 = long) */
2010 FALSE, /* pc_relative */
2012 complain_overflow_dont, /* complain_on_overflow */
2013 bfd_elf_generic_reloc, /* special_function */
2014 "R_PPC64_ADDR16_HIGH", /* name */
2015 FALSE, /* partial_inplace */
2017 0xffff, /* dst_mask */
2018 FALSE), /* pcrel_offset */
2020 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2021 HOWTO (R_PPC64_ADDR16_HIGHA, /* type */
2022 16, /* rightshift */
2023 1, /* size (0 = byte, 1 = short, 2 = long) */
2025 FALSE, /* pc_relative */
2027 complain_overflow_dont, /* complain_on_overflow */
2028 ppc64_elf_ha_reloc, /* special_function */
2029 "R_PPC64_ADDR16_HIGHA", /* name */
2030 FALSE, /* partial_inplace */
2032 0xffff, /* dst_mask */
2033 FALSE), /* pcrel_offset */
2035 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2036 HOWTO (R_PPC64_DTPREL16_HIGH,
2037 16, /* rightshift */
2038 1, /* size (0 = byte, 1 = short, 2 = long) */
2040 FALSE, /* pc_relative */
2042 complain_overflow_dont, /* complain_on_overflow */
2043 ppc64_elf_unhandled_reloc, /* special_function */
2044 "R_PPC64_DTPREL16_HIGH", /* name */
2045 FALSE, /* partial_inplace */
2047 0xffff, /* dst_mask */
2048 FALSE), /* pcrel_offset */
2050 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2051 HOWTO (R_PPC64_DTPREL16_HIGHA,
2052 16, /* rightshift */
2053 1, /* size (0 = byte, 1 = short, 2 = long) */
2055 FALSE, /* pc_relative */
2057 complain_overflow_dont, /* complain_on_overflow */
2058 ppc64_elf_unhandled_reloc, /* special_function */
2059 "R_PPC64_DTPREL16_HIGHA", /* name */
2060 FALSE, /* partial_inplace */
2062 0xffff, /* dst_mask */
2063 FALSE), /* pcrel_offset */
2065 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2066 HOWTO (R_PPC64_TPREL16_HIGH,
2067 16, /* rightshift */
2068 1, /* size (0 = byte, 1 = short, 2 = long) */
2070 FALSE, /* pc_relative */
2072 complain_overflow_dont, /* complain_on_overflow */
2073 ppc64_elf_unhandled_reloc, /* special_function */
2074 "R_PPC64_TPREL16_HIGH", /* name */
2075 FALSE, /* partial_inplace */
2077 0xffff, /* dst_mask */
2078 FALSE), /* pcrel_offset */
2080 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2081 HOWTO (R_PPC64_TPREL16_HIGHA,
2082 16, /* rightshift */
2083 1, /* size (0 = byte, 1 = short, 2 = long) */
2085 FALSE, /* pc_relative */
2087 complain_overflow_dont, /* complain_on_overflow */
2088 ppc64_elf_unhandled_reloc, /* special_function */
2089 "R_PPC64_TPREL16_HIGHA", /* name */
2090 FALSE, /* partial_inplace */
2092 0xffff, /* dst_mask */
2093 FALSE), /* pcrel_offset */
2095 /* GNU extension to record C++ vtable hierarchy. */
2096 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
2098 0, /* size (0 = byte, 1 = short, 2 = long) */
2100 FALSE, /* pc_relative */
2102 complain_overflow_dont, /* complain_on_overflow */
2103 NULL, /* special_function */
2104 "R_PPC64_GNU_VTINHERIT", /* name */
2105 FALSE, /* partial_inplace */
2108 FALSE), /* pcrel_offset */
2110 /* GNU extension to record C++ vtable member usage. */
2111 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
2113 0, /* size (0 = byte, 1 = short, 2 = long) */
2115 FALSE, /* pc_relative */
2117 complain_overflow_dont, /* complain_on_overflow */
2118 NULL, /* special_function */
2119 "R_PPC64_GNU_VTENTRY", /* name */
2120 FALSE, /* partial_inplace */
2123 FALSE), /* pcrel_offset */
2127 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2131 ppc_howto_init (void)
2133 unsigned int i, type;
2136 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
2139 type = ppc64_elf_howto_raw[i].type;
2140 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
2141 / sizeof (ppc64_elf_howto_table[0])));
2142 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
2146 static reloc_howto_type *
2147 ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2148 bfd_reloc_code_real_type code)
2150 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
2152 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2153 /* Initialize howto table if needed. */
2161 case BFD_RELOC_NONE: r = R_PPC64_NONE;
2163 case BFD_RELOC_32: r = R_PPC64_ADDR32;
2165 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
2167 case BFD_RELOC_16: r = R_PPC64_ADDR16;
2169 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
2171 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
2173 case BFD_RELOC_PPC64_ADDR16_HIGH: r = R_PPC64_ADDR16_HIGH;
2175 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
2177 case BFD_RELOC_PPC64_ADDR16_HIGHA: r = R_PPC64_ADDR16_HIGHA;
2179 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
2181 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
2183 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
2185 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
2187 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
2189 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
2191 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
2193 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
2195 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
2197 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
2199 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
2201 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
2203 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
2205 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
2207 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
2209 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
2211 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
2213 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
2215 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
2217 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
2219 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
2221 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
2223 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
2225 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
2227 case BFD_RELOC_64: r = R_PPC64_ADDR64;
2229 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
2231 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
2233 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
2235 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
2237 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
2239 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
2241 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
2243 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
2245 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
2247 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
2249 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
2251 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
2253 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
2255 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
2257 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
2259 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
2261 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
2263 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
2265 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
2267 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
2269 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
2271 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
2273 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
2275 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
2277 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
2279 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
2281 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
2283 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
2285 case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD;
2287 case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD;
2289 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
2291 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
2293 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
2295 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
2297 case BFD_RELOC_PPC64_TPREL16_HIGH: r = R_PPC64_TPREL16_HIGH;
2299 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
2301 case BFD_RELOC_PPC64_TPREL16_HIGHA: r = R_PPC64_TPREL16_HIGHA;
2303 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
2305 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
2307 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
2309 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
2311 case BFD_RELOC_PPC64_DTPREL16_HIGH: r = R_PPC64_DTPREL16_HIGH;
2313 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
2315 case BFD_RELOC_PPC64_DTPREL16_HIGHA: r = R_PPC64_DTPREL16_HIGHA;
2317 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
2319 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
2321 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
2323 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
2325 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
2327 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
2329 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
2331 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
2333 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
2335 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
2337 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
2339 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
2341 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2343 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2345 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2347 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2349 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2351 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2353 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2355 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2357 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2359 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2361 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2363 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2365 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2367 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2369 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2371 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2373 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2375 case BFD_RELOC_16_PCREL: r = R_PPC64_REL16;
2377 case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO;
2379 case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI;
2381 case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
2383 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2385 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2389 return ppc64_elf_howto_table[r];
2392 static reloc_howto_type *
2393 ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2399 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
2401 if (ppc64_elf_howto_raw[i].name != NULL
2402 && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0)
2403 return &ppc64_elf_howto_raw[i];
2408 /* Set the howto pointer for a PowerPC ELF reloc. */
2411 ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2412 Elf_Internal_Rela *dst)
2416 /* Initialize howto table if needed. */
2417 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2420 type = ELF64_R_TYPE (dst->r_info);
2421 if (type >= (sizeof (ppc64_elf_howto_table)
2422 / sizeof (ppc64_elf_howto_table[0])))
2424 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
2426 type = R_PPC64_NONE;
2428 cache_ptr->howto = ppc64_elf_howto_table[type];
2431 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2433 static bfd_reloc_status_type
2434 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2435 void *data, asection *input_section,
2436 bfd *output_bfd, char **error_message)
2438 /* If this is a relocatable link (output_bfd test tells us), just
2439 call the generic function. Any adjustment will be done at final
2441 if (output_bfd != NULL)
2442 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2443 input_section, output_bfd, error_message);
2445 /* Adjust the addend for sign extension of the low 16 bits.
2446 We won't actually be using the low 16 bits, so trashing them
2448 reloc_entry->addend += 0x8000;
2449 return bfd_reloc_continue;
2452 static bfd_reloc_status_type
2453 ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2454 void *data, asection *input_section,
2455 bfd *output_bfd, char **error_message)
2457 if (output_bfd != NULL)
2458 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2459 input_section, output_bfd, error_message);
2461 if (strcmp (symbol->section->name, ".opd") == 0
2462 && (symbol->section->owner->flags & DYNAMIC) == 0)
2464 bfd_vma dest = opd_entry_value (symbol->section,
2465 symbol->value + reloc_entry->addend,
2467 if (dest != (bfd_vma) -1)
2468 reloc_entry->addend = dest - (symbol->value
2469 + symbol->section->output_section->vma
2470 + symbol->section->output_offset);
2472 return bfd_reloc_continue;
2475 static bfd_reloc_status_type
2476 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2477 void *data, asection *input_section,
2478 bfd *output_bfd, char **error_message)
2481 enum elf_ppc64_reloc_type r_type;
2482 bfd_size_type octets;
2483 /* Assume 'at' branch hints. */
2484 bfd_boolean is_isa_v2 = TRUE;
2486 /* If this is a relocatable link (output_bfd test tells us), just
2487 call the generic function. Any adjustment will be done at final
2489 if (output_bfd != NULL)
2490 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2491 input_section, output_bfd, error_message);
2493 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2494 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2495 insn &= ~(0x01 << 21);
2496 r_type = reloc_entry->howto->type;
2497 if (r_type == R_PPC64_ADDR14_BRTAKEN
2498 || r_type == R_PPC64_REL14_BRTAKEN)
2499 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2503 /* Set 'a' bit. This is 0b00010 in BO field for branch
2504 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2505 for branch on CTR insns (BO == 1a00t or 1a01t). */
2506 if ((insn & (0x14 << 21)) == (0x04 << 21))
2508 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2518 if (!bfd_is_com_section (symbol->section))
2519 target = symbol->value;
2520 target += symbol->section->output_section->vma;
2521 target += symbol->section->output_offset;
2522 target += reloc_entry->addend;
2524 from = (reloc_entry->address
2525 + input_section->output_offset
2526 + input_section->output_section->vma);
2528 /* Invert 'y' bit if not the default. */
2529 if ((bfd_signed_vma) (target - from) < 0)
2532 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2534 return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
2535 input_section, output_bfd, error_message);
2538 static bfd_reloc_status_type
2539 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2540 void *data, asection *input_section,
2541 bfd *output_bfd, char **error_message)
2543 /* If this is a relocatable link (output_bfd test tells us), just
2544 call the generic function. Any adjustment will be done at final
2546 if (output_bfd != NULL)
2547 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2548 input_section, output_bfd, error_message);
2550 /* Subtract the symbol section base address. */
2551 reloc_entry->addend -= symbol->section->output_section->vma;
2552 return bfd_reloc_continue;
2555 static bfd_reloc_status_type
2556 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2557 void *data, asection *input_section,
2558 bfd *output_bfd, char **error_message)
2560 /* If this is a relocatable link (output_bfd test tells us), just
2561 call the generic function. Any adjustment will be done at final
2563 if (output_bfd != NULL)
2564 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2565 input_section, output_bfd, error_message);
2567 /* Subtract the symbol section base address. */
2568 reloc_entry->addend -= symbol->section->output_section->vma;
2570 /* Adjust the addend for sign extension of the low 16 bits. */
2571 reloc_entry->addend += 0x8000;
2572 return bfd_reloc_continue;
2575 static bfd_reloc_status_type
2576 ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2577 void *data, asection *input_section,
2578 bfd *output_bfd, char **error_message)
2582 /* If this is a relocatable link (output_bfd test tells us), just
2583 call the generic function. Any adjustment will be done at final
2585 if (output_bfd != NULL)
2586 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2587 input_section, output_bfd, error_message);
2589 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2591 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2593 /* Subtract the TOC base address. */
2594 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2595 return bfd_reloc_continue;
2598 static bfd_reloc_status_type
2599 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2600 void *data, asection *input_section,
2601 bfd *output_bfd, char **error_message)
2605 /* If this is a relocatable link (output_bfd test tells us), just
2606 call the generic function. Any adjustment will be done at final
2608 if (output_bfd != NULL)
2609 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2610 input_section, output_bfd, error_message);
2612 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2614 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2616 /* Subtract the TOC base address. */
2617 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2619 /* Adjust the addend for sign extension of the low 16 bits. */
2620 reloc_entry->addend += 0x8000;
2621 return bfd_reloc_continue;
2624 static bfd_reloc_status_type
2625 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2626 void *data, asection *input_section,
2627 bfd *output_bfd, char **error_message)
2630 bfd_size_type octets;
2632 /* If this is a relocatable link (output_bfd test tells us), just
2633 call the generic function. Any adjustment will be done at final
2635 if (output_bfd != NULL)
2636 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2637 input_section, output_bfd, error_message);
2639 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2641 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2643 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2644 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2645 return bfd_reloc_ok;
2648 static bfd_reloc_status_type
2649 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2650 void *data, asection *input_section,
2651 bfd *output_bfd, char **error_message)
2653 /* If this is a relocatable link (output_bfd test tells us), just
2654 call the generic function. Any adjustment will be done at final
2656 if (output_bfd != NULL)
2657 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2658 input_section, output_bfd, error_message);
2660 if (error_message != NULL)
2662 static char buf[60];
2663 sprintf (buf, "generic linker can't handle %s",
2664 reloc_entry->howto->name);
2665 *error_message = buf;
2667 return bfd_reloc_dangerous;
2670 /* Track GOT entries needed for a given symbol. We might need more
2671 than one got entry per symbol. */
2674 struct got_entry *next;
2676 /* The symbol addend that we'll be placing in the GOT. */
2679 /* Unlike other ELF targets, we use separate GOT entries for the same
2680 symbol referenced from different input files. This is to support
2681 automatic multiple TOC/GOT sections, where the TOC base can vary
2682 from one input file to another. After partitioning into TOC groups
2683 we merge entries within the group.
2685 Point to the BFD owning this GOT entry. */
2688 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2689 TLS_TPREL or TLS_DTPREL for tls entries. */
2690 unsigned char tls_type;
2692 /* Non-zero if got.ent points to real entry. */
2693 unsigned char is_indirect;
2695 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2698 bfd_signed_vma refcount;
2700 struct got_entry *ent;
2704 /* The same for PLT. */
2707 struct plt_entry *next;
2713 bfd_signed_vma refcount;
2718 struct ppc64_elf_obj_tdata
2720 struct elf_obj_tdata elf;
2722 /* Shortcuts to dynamic linker sections. */
2726 /* Used during garbage collection. We attach global symbols defined
2727 on removed .opd entries to this section so that the sym is removed. */
2728 asection *deleted_section;
2730 /* TLS local dynamic got entry handling. Support for multiple GOT
2731 sections means we potentially need one of these for each input bfd. */
2732 struct got_entry tlsld_got;
2735 /* A copy of relocs before they are modified for --emit-relocs. */
2736 Elf_Internal_Rela *relocs;
2738 /* Section contents. */
2742 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2743 the reloc to be in the range -32768 to 32767. */
2744 unsigned int has_small_toc_reloc : 1;
2746 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2747 instruction not one we handle. */
2748 unsigned int unexpected_toc_insn : 1;
2751 #define ppc64_elf_tdata(bfd) \
2752 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2754 #define ppc64_tlsld_got(bfd) \
2755 (&ppc64_elf_tdata (bfd)->tlsld_got)
2757 #define is_ppc64_elf(bfd) \
2758 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2759 && elf_object_id (bfd) == PPC64_ELF_DATA)
2761 /* Override the generic function because we store some extras. */
2764 ppc64_elf_mkobject (bfd *abfd)
2766 return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
2770 /* Fix bad default arch selected for a 64 bit input bfd when the
2771 default is 32 bit. */
2774 ppc64_elf_object_p (bfd *abfd)
2776 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
2778 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2780 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2782 /* Relies on arch after 32 bit default being 64 bit default. */
2783 abfd->arch_info = abfd->arch_info->next;
2784 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2790 /* Support for core dump NOTE sections. */
2793 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2795 size_t offset, size;
2797 if (note->descsz != 504)
2801 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2804 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
2810 /* Make a ".reg/999" section. */
2811 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2812 size, note->descpos + offset);
2816 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2818 if (note->descsz != 136)
2821 elf_tdata (abfd)->core->pid
2822 = bfd_get_32 (abfd, note->descdata + 24);
2823 elf_tdata (abfd)->core->program
2824 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2825 elf_tdata (abfd)->core->command
2826 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2832 ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2845 va_start (ap, note_type);
2846 memset (data, 0, sizeof (data));
2847 strncpy (data + 40, va_arg (ap, const char *), 16);
2848 strncpy (data + 56, va_arg (ap, const char *), 80);
2850 return elfcore_write_note (abfd, buf, bufsiz,
2851 "CORE", note_type, data, sizeof (data));
2862 va_start (ap, note_type);
2863 memset (data, 0, 112);
2864 pid = va_arg (ap, long);
2865 bfd_put_32 (abfd, pid, data + 32);
2866 cursig = va_arg (ap, int);
2867 bfd_put_16 (abfd, cursig, data + 12);
2868 greg = va_arg (ap, const void *);
2869 memcpy (data + 112, greg, 384);
2870 memset (data + 496, 0, 8);
2872 return elfcore_write_note (abfd, buf, bufsiz,
2873 "CORE", note_type, data, sizeof (data));
2878 /* Add extra PPC sections. */
2880 static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
2882 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
2883 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2884 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2885 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2886 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2887 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2888 { NULL, 0, 0, 0, 0 }
2891 enum _ppc64_sec_type {
2897 struct _ppc64_elf_section_data
2899 struct bfd_elf_section_data elf;
2903 /* An array with one entry for each opd function descriptor. */
2904 struct _opd_sec_data
2906 /* Points to the function code section for local opd entries. */
2907 asection **func_sec;
2909 /* After editing .opd, adjust references to opd local syms. */
2913 /* An array for toc sections, indexed by offset/8. */
2914 struct _toc_sec_data
2916 /* Specifies the relocation symbol index used at a given toc offset. */
2919 /* And the relocation addend. */
2924 enum _ppc64_sec_type sec_type:2;
2926 /* Flag set when small branches are detected. Used to
2927 select suitable defaults for the stub group size. */
2928 unsigned int has_14bit_branch:1;
2931 #define ppc64_elf_section_data(sec) \
2932 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2935 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
2937 if (!sec->used_by_bfd)
2939 struct _ppc64_elf_section_data *sdata;
2940 bfd_size_type amt = sizeof (*sdata);
2942 sdata = bfd_zalloc (abfd, amt);
2945 sec->used_by_bfd = sdata;
2948 return _bfd_elf_new_section_hook (abfd, sec);
2951 static struct _opd_sec_data *
2952 get_opd_info (asection * sec)
2955 && ppc64_elf_section_data (sec) != NULL
2956 && ppc64_elf_section_data (sec)->sec_type == sec_opd)
2957 return &ppc64_elf_section_data (sec)->u.opd;
2962 abiversion (bfd *abfd)
2964 return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
2968 set_abiversion (bfd *abfd, int ver)
2970 elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
2971 elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
2974 /* Parameters for the qsort hook. */
2975 static bfd_boolean synthetic_relocatable;
2977 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2980 compare_symbols (const void *ap, const void *bp)
2982 const asymbol *a = * (const asymbol **) ap;
2983 const asymbol *b = * (const asymbol **) bp;
2985 /* Section symbols first. */
2986 if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
2988 if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
2991 /* then .opd symbols. */
2992 if (strcmp (a->section->name, ".opd") == 0
2993 && strcmp (b->section->name, ".opd") != 0)
2995 if (strcmp (a->section->name, ".opd") != 0
2996 && strcmp (b->section->name, ".opd") == 0)
2999 /* then other code symbols. */
3000 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3001 == (SEC_CODE | SEC_ALLOC)
3002 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3003 != (SEC_CODE | SEC_ALLOC))
3006 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3007 != (SEC_CODE | SEC_ALLOC)
3008 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3009 == (SEC_CODE | SEC_ALLOC))
3012 if (synthetic_relocatable)
3014 if (a->section->id < b->section->id)
3017 if (a->section->id > b->section->id)
3021 if (a->value + a->section->vma < b->value + b->section->vma)
3024 if (a->value + a->section->vma > b->value + b->section->vma)
3027 /* For syms with the same value, prefer strong dynamic global function
3028 syms over other syms. */
3029 if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
3032 if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
3035 if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
3038 if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
3041 if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
3044 if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
3047 if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
3050 if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
3056 /* Search SYMS for a symbol of the given VALUE. */
3059 sym_exists_at (asymbol **syms, long lo, long hi, int id, bfd_vma value)
3067 mid = (lo + hi) >> 1;
3068 if (syms[mid]->value + syms[mid]->section->vma < value)
3070 else if (syms[mid]->value + syms[mid]->section->vma > value)
3080 mid = (lo + hi) >> 1;
3081 if (syms[mid]->section->id < id)
3083 else if (syms[mid]->section->id > id)
3085 else if (syms[mid]->value < value)
3087 else if (syms[mid]->value > value)
3097 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
3099 bfd_vma vma = *(bfd_vma *) ptr;
3100 return ((section->flags & SEC_ALLOC) != 0
3101 && section->vma <= vma
3102 && vma < section->vma + section->size);
3105 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3106 entry syms. Also generate @plt symbols for the glink branch table. */
3109 ppc64_elf_get_synthetic_symtab (bfd *abfd,
3110 long static_count, asymbol **static_syms,
3111 long dyn_count, asymbol **dyn_syms,
3118 long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
3119 asection *opd = NULL;
3120 bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
3122 int abi = abiversion (abfd);
3128 opd = bfd_get_section_by_name (abfd, ".opd");
3129 if (opd == NULL && abi == 1)
3133 symcount = static_count;
3135 symcount += dyn_count;
3139 syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
3143 if (!relocatable && static_count != 0 && dyn_count != 0)
3145 /* Use both symbol tables. */
3146 memcpy (syms, static_syms, static_count * sizeof (*syms));
3147 memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms));
3149 else if (!relocatable && static_count == 0)
3150 memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
3152 memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
3154 synthetic_relocatable = relocatable;
3155 qsort (syms, symcount, sizeof (*syms), compare_symbols);
3157 if (!relocatable && symcount > 1)
3160 /* Trim duplicate syms, since we may have merged the normal and
3161 dynamic symbols. Actually, we only care about syms that have
3162 different values, so trim any with the same value. */
3163 for (i = 1, j = 1; i < symcount; ++i)
3164 if (syms[i - 1]->value + syms[i - 1]->section->vma
3165 != syms[i]->value + syms[i]->section->vma)
3166 syms[j++] = syms[i];
3171 if (strcmp (syms[i]->section->name, ".opd") == 0)
3175 for (; i < symcount; ++i)
3176 if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3177 != (SEC_CODE | SEC_ALLOC))
3178 || (syms[i]->flags & BSF_SECTION_SYM) == 0)
3182 for (; i < symcount; ++i)
3183 if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
3187 for (; i < symcount; ++i)
3188 if (strcmp (syms[i]->section->name, ".opd") != 0)
3192 for (; i < symcount; ++i)
3193 if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3194 != (SEC_CODE | SEC_ALLOC))
3202 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3207 if (opdsymend == secsymend)
3210 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3211 relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
3215 if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
3222 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3226 while (r < opd->relocation + relcount
3227 && r->address < syms[i]->value + opd->vma)
3230 if (r == opd->relocation + relcount)
3233 if (r->address != syms[i]->value + opd->vma)
3236 if (r->howto->type != R_PPC64_ADDR64)
3239 sym = *r->sym_ptr_ptr;
3240 if (!sym_exists_at (syms, opdsymend, symcount,
3241 sym->section->id, sym->value + r->addend))
3244 size += sizeof (asymbol);
3245 size += strlen (syms[i]->name) + 2;
3249 s = *ret = bfd_malloc (size);
3256 names = (char *) (s + count);
3258 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3262 while (r < opd->relocation + relcount
3263 && r->address < syms[i]->value + opd->vma)
3266 if (r == opd->relocation + relcount)
3269 if (r->address != syms[i]->value + opd->vma)
3272 if (r->howto->type != R_PPC64_ADDR64)
3275 sym = *r->sym_ptr_ptr;
3276 if (!sym_exists_at (syms, opdsymend, symcount,
3277 sym->section->id, sym->value + r->addend))
3282 s->flags |= BSF_SYNTHETIC;
3283 s->section = sym->section;
3284 s->value = sym->value + r->addend;
3287 len = strlen (syms[i]->name);
3288 memcpy (names, syms[i]->name, len + 1);
3290 /* Have udata.p point back to the original symbol this
3291 synthetic symbol was derived from. */
3292 s->udata.p = syms[i];
3299 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3300 bfd_byte *contents = NULL;
3303 bfd_vma glink_vma = 0, resolv_vma = 0;
3304 asection *dynamic, *glink = NULL, *relplt = NULL;
3307 if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
3309 free_contents_and_exit:
3317 for (i = secsymend; i < opdsymend; ++i)
3321 /* Ignore bogus symbols. */
3322 if (syms[i]->value > opd->size - 8)
3325 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3326 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3329 size += sizeof (asymbol);
3330 size += strlen (syms[i]->name) + 2;
3334 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3336 && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL)
3338 bfd_byte *dynbuf, *extdyn, *extdynend;
3340 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
3342 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
3343 goto free_contents_and_exit;
3345 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
3346 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
3349 extdynend = extdyn + dynamic->size;
3350 for (; extdyn < extdynend; extdyn += extdynsize)
3352 Elf_Internal_Dyn dyn;
3353 (*swap_dyn_in) (abfd, extdyn, &dyn);
3355 if (dyn.d_tag == DT_NULL)
3358 if (dyn.d_tag == DT_PPC64_GLINK)
3360 /* The first glink stub starts at offset 32; see
3361 comment in ppc64_elf_finish_dynamic_sections. */
3362 glink_vma = dyn.d_un.d_val + GLINK_CALL_STUB_SIZE - 8 * 4;
3363 /* The .glink section usually does not survive the final
3364 link; search for the section (usually .text) where the
3365 glink stubs now reside. */
3366 glink = bfd_sections_find_if (abfd, section_covers_vma,
3377 /* Determine __glink trampoline by reading the relative branch
3378 from the first glink stub. */
3380 unsigned int off = 0;
3382 while (bfd_get_section_contents (abfd, glink, buf,
3383 glink_vma + off - glink->vma, 4))
3385 unsigned int insn = bfd_get_32 (abfd, buf);
3387 if ((insn & ~0x3fffffc) == 0)
3389 resolv_vma = glink_vma + off + (insn ^ 0x2000000) - 0x2000000;
3398 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
3400 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
3403 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3404 if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
3405 goto free_contents_and_exit;
3407 plt_count = relplt->size / sizeof (Elf64_External_Rela);
3408 size += plt_count * sizeof (asymbol);
3410 p = relplt->relocation;
3411 for (i = 0; i < plt_count; i++, p++)
3413 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
3415 size += sizeof ("+0x") - 1 + 16;
3420 s = *ret = bfd_malloc (size);
3422 goto free_contents_and_exit;
3424 names = (char *) (s + count + plt_count + (resolv_vma != 0));
3426 for (i = secsymend; i < opdsymend; ++i)
3430 if (syms[i]->value > opd->size - 8)
3433 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3434 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3438 asection *sec = abfd->sections;
3445 long mid = (lo + hi) >> 1;
3446 if (syms[mid]->section->vma < ent)
3448 else if (syms[mid]->section->vma > ent)
3452 sec = syms[mid]->section;
3457 if (lo >= hi && lo > codesecsym)
3458 sec = syms[lo - 1]->section;
3460 for (; sec != NULL; sec = sec->next)
3464 /* SEC_LOAD may not be set if SEC is from a separate debug
3466 if ((sec->flags & SEC_ALLOC) == 0)
3468 if ((sec->flags & SEC_CODE) != 0)
3471 s->flags |= BSF_SYNTHETIC;
3472 s->value = ent - s->section->vma;
3475 len = strlen (syms[i]->name);
3476 memcpy (names, syms[i]->name, len + 1);
3478 /* Have udata.p point back to the original symbol this
3479 synthetic symbol was derived from. */
3480 s->udata.p = syms[i];
3486 if (glink != NULL && relplt != NULL)
3490 /* Add a symbol for the main glink trampoline. */
3491 memset (s, 0, sizeof *s);
3493 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
3495 s->value = resolv_vma - glink->vma;
3497 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3498 names += sizeof ("__glink_PLTresolve");
3503 /* FIXME: It would be very much nicer to put sym@plt on the
3504 stub rather than on the glink branch table entry. The
3505 objdump disassembler would then use a sensible symbol
3506 name on plt calls. The difficulty in doing so is
3507 a) finding the stubs, and,
3508 b) matching stubs against plt entries, and,
3509 c) there can be multiple stubs for a given plt entry.
3511 Solving (a) could be done by code scanning, but older
3512 ppc64 binaries used different stubs to current code.
3513 (b) is the tricky one since you need to known the toc
3514 pointer for at least one function that uses a pic stub to
3515 be able to calculate the plt address referenced.
3516 (c) means gdb would need to set multiple breakpoints (or
3517 find the glink branch itself) when setting breakpoints
3518 for pending shared library loads. */
3519 p = relplt->relocation;
3520 for (i = 0; i < plt_count; i++, p++)
3524 *s = **p->sym_ptr_ptr;
3525 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3526 we are defining a symbol, ensure one of them is set. */
3527 if ((s->flags & BSF_LOCAL) == 0)
3528 s->flags |= BSF_GLOBAL;
3529 s->flags |= BSF_SYNTHETIC;
3531 s->value = glink_vma - glink->vma;
3534 len = strlen ((*p->sym_ptr_ptr)->name);
3535 memcpy (names, (*p->sym_ptr_ptr)->name, len);
3539 memcpy (names, "+0x", sizeof ("+0x") - 1);
3540 names += sizeof ("+0x") - 1;
3541 bfd_sprintf_vma (abfd, names, p->addend);
3542 names += strlen (names);
3544 memcpy (names, "@plt", sizeof ("@plt"));
3545 names += sizeof ("@plt");
3565 /* The following functions are specific to the ELF linker, while
3566 functions above are used generally. Those named ppc64_elf_* are
3567 called by the main ELF linker code. They appear in this file more
3568 or less in the order in which they are called. eg.
3569 ppc64_elf_check_relocs is called early in the link process,
3570 ppc64_elf_finish_dynamic_sections is one of the last functions
3573 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3574 functions have both a function code symbol and a function descriptor
3575 symbol. A call to foo in a relocatable object file looks like:
3582 The function definition in another object file might be:
3586 . .quad .TOC.@tocbase
3592 When the linker resolves the call during a static link, the branch
3593 unsurprisingly just goes to .foo and the .opd information is unused.
3594 If the function definition is in a shared library, things are a little
3595 different: The call goes via a plt call stub, the opd information gets
3596 copied to the plt, and the linker patches the nop.
3604 . std 2,40(1) # in practice, the call stub
3605 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3606 . addi 11,11,Lfoo@toc@l # this is the general idea
3614 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3616 The "reloc ()" notation is supposed to indicate that the linker emits
3617 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3620 What are the difficulties here? Well, firstly, the relocations
3621 examined by the linker in check_relocs are against the function code
3622 sym .foo, while the dynamic relocation in the plt is emitted against
3623 the function descriptor symbol, foo. Somewhere along the line, we need
3624 to carefully copy dynamic link information from one symbol to the other.
3625 Secondly, the generic part of the elf linker will make .foo a dynamic
3626 symbol as is normal for most other backends. We need foo dynamic
3627 instead, at least for an application final link. However, when
3628 creating a shared library containing foo, we need to have both symbols
3629 dynamic so that references to .foo are satisfied during the early
3630 stages of linking. Otherwise the linker might decide to pull in a
3631 definition from some other object, eg. a static library.
3633 Update: As of August 2004, we support a new convention. Function
3634 calls may use the function descriptor symbol, ie. "bl foo". This
3635 behaves exactly as "bl .foo". */
3637 /* Of those relocs that might be copied as dynamic relocs, this function
3638 selects those that must be copied when linking a shared library,
3639 even when the symbol is local. */
3642 must_be_dyn_reloc (struct bfd_link_info *info,
3643 enum elf_ppc64_reloc_type r_type)
3655 case R_PPC64_TPREL16:
3656 case R_PPC64_TPREL16_LO:
3657 case R_PPC64_TPREL16_HI:
3658 case R_PPC64_TPREL16_HA:
3659 case R_PPC64_TPREL16_DS:
3660 case R_PPC64_TPREL16_LO_DS:
3661 case R_PPC64_TPREL16_HIGH:
3662 case R_PPC64_TPREL16_HIGHA:
3663 case R_PPC64_TPREL16_HIGHER:
3664 case R_PPC64_TPREL16_HIGHERA:
3665 case R_PPC64_TPREL16_HIGHEST:
3666 case R_PPC64_TPREL16_HIGHESTA:
3667 case R_PPC64_TPREL64:
3668 return !info->executable;
3672 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3673 copying dynamic variables from a shared lib into an app's dynbss
3674 section, and instead use a dynamic relocation to point into the
3675 shared lib. With code that gcc generates, it's vital that this be
3676 enabled; In the PowerPC64 ABI, the address of a function is actually
3677 the address of a function descriptor, which resides in the .opd
3678 section. gcc uses the descriptor directly rather than going via the
3679 GOT as some other ABI's do, which means that initialized function
3680 pointers must reference the descriptor. Thus, a function pointer
3681 initialized to the address of a function in a shared library will
3682 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3683 redefines the function descriptor symbol to point to the copy. This
3684 presents a problem as a plt entry for that function is also
3685 initialized from the function descriptor symbol and the copy reloc
3686 may not be initialized first. */
3687 #define ELIMINATE_COPY_RELOCS 1
3689 /* Section name for stubs is the associated section name plus this
3691 #define STUB_SUFFIX ".stub"
3694 ppc_stub_long_branch:
3695 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3696 destination, but a 24 bit branch in a stub section will reach.
3699 ppc_stub_plt_branch:
3700 Similar to the above, but a 24 bit branch in the stub section won't
3701 reach its destination.
3702 . addis %r11,%r2,xxx@toc@ha
3703 . ld %r12,xxx@toc@l(%r11)
3708 Used to call a function in a shared library. If it so happens that
3709 the plt entry referenced crosses a 64k boundary, then an extra
3710 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3712 . addis %r11,%r2,xxx@toc@ha
3713 . ld %r12,xxx+0@toc@l(%r11)
3715 . ld %r2,xxx+8@toc@l(%r11)
3716 . ld %r11,xxx+16@toc@l(%r11)
3719 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3720 code to adjust the value and save r2 to support multiple toc sections.
3721 A ppc_stub_long_branch with an r2 offset looks like:
3723 . addis %r2,%r2,off@ha
3724 . addi %r2,%r2,off@l
3727 A ppc_stub_plt_branch with an r2 offset looks like:
3729 . addis %r11,%r2,xxx@toc@ha
3730 . ld %r12,xxx@toc@l(%r11)
3731 . addis %r2,%r2,off@ha
3732 . addi %r2,%r2,off@l
3736 In cases where the "addis" instruction would add zero, the "addis" is
3737 omitted and following instructions modified slightly in some cases.
3740 enum ppc_stub_type {
3742 ppc_stub_long_branch,
3743 ppc_stub_long_branch_r2off,
3744 ppc_stub_plt_branch,
3745 ppc_stub_plt_branch_r2off,
3747 ppc_stub_plt_call_r2save
3750 struct ppc_stub_hash_entry {
3752 /* Base hash table entry structure. */
3753 struct bfd_hash_entry root;
3755 enum ppc_stub_type stub_type;
3757 /* The stub section. */
3760 /* Offset within stub_sec of the beginning of this stub. */
3761 bfd_vma stub_offset;
3763 /* Given the symbol's value and its section we can determine its final
3764 value when building the stubs (so the stub knows where to jump. */
3765 bfd_vma target_value;
3766 asection *target_section;
3768 /* The symbol table entry, if any, that this was derived from. */
3769 struct ppc_link_hash_entry *h;
3770 struct plt_entry *plt_ent;
3772 /* Where this stub is being called from, or, in the case of combined
3773 stub sections, the first input section in the group. */
3776 /* Symbol st_other. */
3777 unsigned char other;
3780 struct ppc_branch_hash_entry {
3782 /* Base hash table entry structure. */
3783 struct bfd_hash_entry root;
3785 /* Offset within branch lookup table. */
3786 unsigned int offset;
3788 /* Generation marker. */
3792 /* Used to track dynamic relocations for local symbols. */
3793 struct ppc_dyn_relocs
3795 struct ppc_dyn_relocs *next;
3797 /* The input section of the reloc. */
3800 /* Total number of relocs copied for the input section. */
3801 unsigned int count : 31;
3803 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3804 unsigned int ifunc : 1;
3807 struct ppc_link_hash_entry
3809 struct elf_link_hash_entry elf;
3812 /* A pointer to the most recently used stub hash entry against this
3814 struct ppc_stub_hash_entry *stub_cache;
3816 /* A pointer to the next symbol starting with a '.' */
3817 struct ppc_link_hash_entry *next_dot_sym;
3820 /* Track dynamic relocs copied for this symbol. */
3821 struct elf_dyn_relocs *dyn_relocs;
3823 /* Link between function code and descriptor symbols. */
3824 struct ppc_link_hash_entry *oh;
3826 /* Flag function code and descriptor symbols. */
3827 unsigned int is_func:1;
3828 unsigned int is_func_descriptor:1;
3829 unsigned int fake:1;
3831 /* Whether global opd/toc sym has been adjusted or not.
3832 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3833 should be set for all globals defined in any opd/toc section. */
3834 unsigned int adjust_done:1;
3836 /* Set if we twiddled this symbol to weak at some stage. */
3837 unsigned int was_undefined:1;
3839 /* Contexts in which symbol is used in the GOT (or TOC).
3840 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3841 corresponding relocs are encountered during check_relocs.
3842 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3843 indicate the corresponding GOT entry type is not needed.
3844 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3845 a TPREL one. We use a separate flag rather than setting TPREL
3846 just for convenience in distinguishing the two cases. */
3847 #define TLS_GD 1 /* GD reloc. */
3848 #define TLS_LD 2 /* LD reloc. */
3849 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3850 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3851 #define TLS_TLS 16 /* Any TLS reloc. */
3852 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3853 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3854 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3855 unsigned char tls_mask;
3858 /* ppc64 ELF linker hash table. */
3860 struct ppc_link_hash_table
3862 struct elf_link_hash_table elf;
3864 /* The stub hash table. */
3865 struct bfd_hash_table stub_hash_table;
3867 /* Another hash table for plt_branch stubs. */
3868 struct bfd_hash_table branch_hash_table;
3870 /* Hash table for function prologue tocsave. */
3871 htab_t tocsave_htab;
3873 /* Linker stub bfd. */
3876 /* Linker call-backs. */
3877 asection * (*add_stub_section) (const char *, asection *);
3878 void (*layout_sections_again) (void);
3880 /* Array to keep track of which stub sections have been created, and
3881 information on stub grouping. */
3883 /* This is the section to which stubs in the group will be attached. */
3885 /* The stub section. */
3887 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3891 /* Temp used when calculating TOC pointers. */
3894 asection *toc_first_sec;
3896 /* Highest input section id. */
3899 /* Highest output section index. */
3902 /* Used when adding symbols. */
3903 struct ppc_link_hash_entry *dot_syms;
3905 /* List of input sections for each output section. */
3906 asection **input_list;
3908 /* Short-cuts to get to dynamic linker sections. */
3920 asection *glink_eh_frame;
3922 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3923 struct ppc_link_hash_entry *tls_get_addr;
3924 struct ppc_link_hash_entry *tls_get_addr_fd;
3926 /* The size of reliplt used by got entry relocs. */
3927 bfd_size_type got_reli_size;
3930 unsigned long stub_count[ppc_stub_plt_call_r2save];
3932 /* Number of stubs against global syms. */
3933 unsigned long stub_globals;
3935 /* Alignment of PLT call stubs. */
3936 unsigned int plt_stub_align:4;
3938 /* Set if we're linking code with function descriptors. */
3939 unsigned int opd_abi:1;
3941 /* Set if PLT call stubs should load r11. */
3942 unsigned int plt_static_chain:1;
3944 /* Set if PLT call stubs need a read-read barrier. */
3945 unsigned int plt_thread_safe:1;
3947 /* Set if we should emit symbols for stubs. */
3948 unsigned int emit_stub_syms:1;
3950 /* Set if __tls_get_addr optimization should not be done. */
3951 unsigned int no_tls_get_addr_opt:1;
3953 /* Support for multiple toc sections. */
3954 unsigned int do_multi_toc:1;
3955 unsigned int multi_toc_needed:1;
3956 unsigned int second_toc_pass:1;
3957 unsigned int do_toc_opt:1;
3960 unsigned int stub_error:1;
3962 /* Temp used by ppc64_elf_process_dot_syms. */
3963 unsigned int twiddled_syms:1;
3965 /* Incremented every time we size stubs. */
3966 unsigned int stub_iteration;
3968 /* Small local sym cache. */
3969 struct sym_cache sym_cache;
3972 /* Rename some of the generic section flags to better document how they
3975 /* Nonzero if this section has TLS related relocations. */
3976 #define has_tls_reloc sec_flg0
3978 /* Nonzero if this section has a call to __tls_get_addr. */
3979 #define has_tls_get_addr_call sec_flg1
3981 /* Nonzero if this section has any toc or got relocs. */
3982 #define has_toc_reloc sec_flg2
3984 /* Nonzero if this section has a call to another section that uses
3986 #define makes_toc_func_call sec_flg3
3988 /* Recursion protection when determining above flag. */
3989 #define call_check_in_progress sec_flg4
3990 #define call_check_done sec_flg5
3992 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3994 #define ppc_hash_table(p) \
3995 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3996 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3998 #define ppc_stub_hash_lookup(table, string, create, copy) \
3999 ((struct ppc_stub_hash_entry *) \
4000 bfd_hash_lookup ((table), (string), (create), (copy)))
4002 #define ppc_branch_hash_lookup(table, string, create, copy) \
4003 ((struct ppc_branch_hash_entry *) \
4004 bfd_hash_lookup ((table), (string), (create), (copy)))
4006 /* Create an entry in the stub hash table. */
4008 static struct bfd_hash_entry *
4009 stub_hash_newfunc (struct bfd_hash_entry *entry,
4010 struct bfd_hash_table *table,
4013 /* Allocate the structure if it has not already been allocated by a
4017 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
4022 /* Call the allocation method of the superclass. */
4023 entry = bfd_hash_newfunc (entry, table, string);
4026 struct ppc_stub_hash_entry *eh;
4028 /* Initialize the local fields. */
4029 eh = (struct ppc_stub_hash_entry *) entry;
4030 eh->stub_type = ppc_stub_none;
4031 eh->stub_sec = NULL;
4032 eh->stub_offset = 0;
4033 eh->target_value = 0;
4034 eh->target_section = NULL;
4044 /* Create an entry in the branch hash table. */
4046 static struct bfd_hash_entry *
4047 branch_hash_newfunc (struct bfd_hash_entry *entry,
4048 struct bfd_hash_table *table,
4051 /* Allocate the structure if it has not already been allocated by a
4055 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
4060 /* Call the allocation method of the superclass. */
4061 entry = bfd_hash_newfunc (entry, table, string);
4064 struct ppc_branch_hash_entry *eh;
4066 /* Initialize the local fields. */
4067 eh = (struct ppc_branch_hash_entry *) entry;
4075 /* Create an entry in a ppc64 ELF linker hash table. */
4077 static struct bfd_hash_entry *
4078 link_hash_newfunc (struct bfd_hash_entry *entry,
4079 struct bfd_hash_table *table,
4082 /* Allocate the structure if it has not already been allocated by a
4086 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
4091 /* Call the allocation method of the superclass. */
4092 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
4095 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
4097 memset (&eh->u.stub_cache, 0,
4098 (sizeof (struct ppc_link_hash_entry)
4099 - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
4101 /* When making function calls, old ABI code references function entry
4102 points (dot symbols), while new ABI code references the function
4103 descriptor symbol. We need to make any combination of reference and
4104 definition work together, without breaking archive linking.
4106 For a defined function "foo" and an undefined call to "bar":
4107 An old object defines "foo" and ".foo", references ".bar" (possibly
4109 A new object defines "foo" and references "bar".
4111 A new object thus has no problem with its undefined symbols being
4112 satisfied by definitions in an old object. On the other hand, the
4113 old object won't have ".bar" satisfied by a new object.
4115 Keep a list of newly added dot-symbols. */
4117 if (string[0] == '.')
4119 struct ppc_link_hash_table *htab;
4121 htab = (struct ppc_link_hash_table *) table;
4122 eh->u.next_dot_sym = htab->dot_syms;
4123 htab->dot_syms = eh;
4130 struct tocsave_entry {
4136 tocsave_htab_hash (const void *p)
4138 const struct tocsave_entry *e = (const struct tocsave_entry *) p;
4139 return ((bfd_vma)(intptr_t) e->sec ^ e->offset) >> 3;
4143 tocsave_htab_eq (const void *p1, const void *p2)
4145 const struct tocsave_entry *e1 = (const struct tocsave_entry *) p1;
4146 const struct tocsave_entry *e2 = (const struct tocsave_entry *) p2;
4147 return e1->sec == e2->sec && e1->offset == e2->offset;
4150 /* Create a ppc64 ELF linker hash table. */
4152 static struct bfd_link_hash_table *
4153 ppc64_elf_link_hash_table_create (bfd *abfd)
4155 struct ppc_link_hash_table *htab;
4156 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
4158 htab = bfd_zmalloc (amt);
4162 if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
4163 sizeof (struct ppc_link_hash_entry),
4170 /* Init the stub hash table too. */
4171 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
4172 sizeof (struct ppc_stub_hash_entry)))
4175 /* And the branch hash table. */
4176 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
4177 sizeof (struct ppc_branch_hash_entry)))
4180 htab->tocsave_htab = htab_try_create (1024,
4184 if (htab->tocsave_htab == NULL)
4187 /* Initializing two fields of the union is just cosmetic. We really
4188 only care about glist, but when compiled on a 32-bit host the
4189 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4190 debugger inspection of these fields look nicer. */
4191 htab->elf.init_got_refcount.refcount = 0;
4192 htab->elf.init_got_refcount.glist = NULL;
4193 htab->elf.init_plt_refcount.refcount = 0;
4194 htab->elf.init_plt_refcount.glist = NULL;
4195 htab->elf.init_got_offset.offset = 0;
4196 htab->elf.init_got_offset.glist = NULL;
4197 htab->elf.init_plt_offset.offset = 0;
4198 htab->elf.init_plt_offset.glist = NULL;
4200 return &htab->elf.root;
4203 /* Free the derived linker hash table. */
4206 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
4208 struct ppc_link_hash_table *htab = (struct ppc_link_hash_table *) hash;
4210 bfd_hash_table_free (&htab->stub_hash_table);
4211 bfd_hash_table_free (&htab->branch_hash_table);
4212 if (htab->tocsave_htab)
4213 htab_delete (htab->tocsave_htab);
4214 _bfd_elf_link_hash_table_free (hash);
4217 /* Create sections for linker generated code. */
4220 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
4222 struct ppc_link_hash_table *htab;
4225 htab = ppc_hash_table (info);
4227 /* Create .sfpr for code to save and restore fp regs. */
4228 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
4229 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4230 htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
4232 if (htab->sfpr == NULL
4233 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
4236 /* Create .glink for lazy dynamic linking support. */
4237 htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4239 if (htab->glink == NULL
4240 || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
4243 if (!info->no_ld_generated_unwind_info)
4245 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
4246 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4247 htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj,
4250 if (htab->glink_eh_frame == NULL
4251 || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
4255 flags = SEC_ALLOC | SEC_LINKER_CREATED;
4256 htab->iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
4257 if (htab->iplt == NULL
4258 || ! bfd_set_section_alignment (dynobj, htab->iplt, 3))
4261 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4262 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4263 htab->reliplt = bfd_make_section_anyway_with_flags (dynobj,
4266 if (htab->reliplt == NULL
4267 || ! bfd_set_section_alignment (dynobj, htab->reliplt, 3))
4270 /* Create branch lookup table for plt_branch stubs. */
4271 flags = (SEC_ALLOC | SEC_LOAD
4272 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4273 htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
4275 if (htab->brlt == NULL
4276 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
4282 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4283 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4284 htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
4287 if (htab->relbrlt == NULL
4288 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
4294 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4297 ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
4299 struct ppc_link_hash_table *htab;
4301 elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64;
4303 /* Always hook our dynamic sections into the first bfd, which is the
4304 linker created stub bfd. This ensures that the GOT header is at
4305 the start of the output TOC section. */
4306 htab = ppc_hash_table (info);
4309 htab->stub_bfd = abfd;
4310 htab->elf.dynobj = abfd;
4312 if (info->relocatable)
4315 return create_linkage_sections (htab->elf.dynobj, info);
4318 /* Build a name for an entry in the stub hash table. */
4321 ppc_stub_name (const asection *input_section,
4322 const asection *sym_sec,
4323 const struct ppc_link_hash_entry *h,
4324 const Elf_Internal_Rela *rel)
4329 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4330 offsets from a sym as a branch target? In fact, we could
4331 probably assume the addend is always zero. */
4332 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
4336 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
4337 stub_name = bfd_malloc (len);
4338 if (stub_name == NULL)
4341 len = sprintf (stub_name, "%08x.%s+%x",
4342 input_section->id & 0xffffffff,
4343 h->elf.root.root.string,
4344 (int) rel->r_addend & 0xffffffff);
4348 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4349 stub_name = bfd_malloc (len);
4350 if (stub_name == NULL)
4353 len = sprintf (stub_name, "%08x.%x:%x+%x",
4354 input_section->id & 0xffffffff,
4355 sym_sec->id & 0xffffffff,
4356 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
4357 (int) rel->r_addend & 0xffffffff);
4359 if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
4360 stub_name[len - 2] = 0;
4364 /* Look up an entry in the stub hash. Stub entries are cached because
4365 creating the stub name takes a bit of time. */
4367 static struct ppc_stub_hash_entry *
4368 ppc_get_stub_entry (const asection *input_section,
4369 const asection *sym_sec,
4370 struct ppc_link_hash_entry *h,
4371 const Elf_Internal_Rela *rel,
4372 struct ppc_link_hash_table *htab)
4374 struct ppc_stub_hash_entry *stub_entry;
4375 const asection *id_sec;
4377 /* If this input section is part of a group of sections sharing one
4378 stub section, then use the id of the first section in the group.
4379 Stub names need to include a section id, as there may well be
4380 more than one stub used to reach say, printf, and we need to
4381 distinguish between them. */
4382 id_sec = htab->stub_group[input_section->id].link_sec;
4384 if (h != NULL && h->u.stub_cache != NULL
4385 && h->u.stub_cache->h == h
4386 && h->u.stub_cache->id_sec == id_sec)
4388 stub_entry = h->u.stub_cache;
4394 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
4395 if (stub_name == NULL)
4398 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4399 stub_name, FALSE, FALSE);
4401 h->u.stub_cache = stub_entry;
4409 /* Add a new stub entry to the stub hash. Not all fields of the new
4410 stub entry are initialised. */
4412 static struct ppc_stub_hash_entry *
4413 ppc_add_stub (const char *stub_name,
4415 struct bfd_link_info *info)
4417 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4420 struct ppc_stub_hash_entry *stub_entry;
4422 link_sec = htab->stub_group[section->id].link_sec;
4423 stub_sec = htab->stub_group[section->id].stub_sec;
4424 if (stub_sec == NULL)
4426 stub_sec = htab->stub_group[link_sec->id].stub_sec;
4427 if (stub_sec == NULL)
4433 namelen = strlen (link_sec->name);
4434 len = namelen + sizeof (STUB_SUFFIX);
4435 s_name = bfd_alloc (htab->stub_bfd, len);
4439 memcpy (s_name, link_sec->name, namelen);
4440 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
4441 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
4442 if (stub_sec == NULL)
4444 htab->stub_group[link_sec->id].stub_sec = stub_sec;
4446 htab->stub_group[section->id].stub_sec = stub_sec;
4449 /* Enter this entry into the linker stub hash table. */
4450 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4452 if (stub_entry == NULL)
4454 info->callbacks->einfo (_("%P: %B: cannot create stub entry %s\n"),
4455 section->owner, stub_name);
4459 stub_entry->stub_sec = stub_sec;
4460 stub_entry->stub_offset = 0;
4461 stub_entry->id_sec = link_sec;
4465 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4466 not already done. */
4469 create_got_section (bfd *abfd, struct bfd_link_info *info)
4471 asection *got, *relgot;
4473 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4475 if (!is_ppc64_elf (abfd))
4482 if (! _bfd_elf_create_got_section (htab->elf.dynobj, info))
4485 htab->got = bfd_get_linker_section (htab->elf.dynobj, ".got");
4490 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4491 | SEC_LINKER_CREATED);
4493 got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
4495 || !bfd_set_section_alignment (abfd, got, 3))
4498 relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
4499 flags | SEC_READONLY);
4501 || ! bfd_set_section_alignment (abfd, relgot, 3))
4504 ppc64_elf_tdata (abfd)->got = got;
4505 ppc64_elf_tdata (abfd)->relgot = relgot;
4509 /* Create the dynamic sections, and set up shortcuts. */
4512 ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
4514 struct ppc_link_hash_table *htab;
4516 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
4519 htab = ppc_hash_table (info);
4524 htab->got = bfd_get_linker_section (dynobj, ".got");
4525 htab->plt = bfd_get_linker_section (dynobj, ".plt");
4526 htab->relplt = bfd_get_linker_section (dynobj, ".rela.plt");
4527 htab->dynbss = bfd_get_linker_section (dynobj, ".dynbss");
4529 htab->relbss = bfd_get_linker_section (dynobj, ".rela.bss");
4531 if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss
4532 || (!info->shared && !htab->relbss))
4538 /* Follow indirect and warning symbol links. */
4540 static inline struct bfd_link_hash_entry *
4541 follow_link (struct bfd_link_hash_entry *h)
4543 while (h->type == bfd_link_hash_indirect
4544 || h->type == bfd_link_hash_warning)
4549 static inline struct elf_link_hash_entry *
4550 elf_follow_link (struct elf_link_hash_entry *h)
4552 return (struct elf_link_hash_entry *) follow_link (&h->root);
4555 static inline struct ppc_link_hash_entry *
4556 ppc_follow_link (struct ppc_link_hash_entry *h)
4558 return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
4561 /* Merge PLT info on FROM with that on TO. */
4564 move_plt_plist (struct ppc_link_hash_entry *from,
4565 struct ppc_link_hash_entry *to)
4567 if (from->elf.plt.plist != NULL)
4569 if (to->elf.plt.plist != NULL)
4571 struct plt_entry **entp;
4572 struct plt_entry *ent;
4574 for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
4576 struct plt_entry *dent;
4578 for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
4579 if (dent->addend == ent->addend)
4581 dent->plt.refcount += ent->plt.refcount;
4588 *entp = to->elf.plt.plist;
4591 to->elf.plt.plist = from->elf.plt.plist;
4592 from->elf.plt.plist = NULL;
4596 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4599 ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
4600 struct elf_link_hash_entry *dir,
4601 struct elf_link_hash_entry *ind)
4603 struct ppc_link_hash_entry *edir, *eind;
4605 edir = (struct ppc_link_hash_entry *) dir;
4606 eind = (struct ppc_link_hash_entry *) ind;
4608 edir->is_func |= eind->is_func;
4609 edir->is_func_descriptor |= eind->is_func_descriptor;
4610 edir->tls_mask |= eind->tls_mask;
4611 if (eind->oh != NULL)
4612 edir->oh = ppc_follow_link (eind->oh);
4614 /* If called to transfer flags for a weakdef during processing
4615 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4616 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4617 if (!(ELIMINATE_COPY_RELOCS
4618 && eind->elf.root.type != bfd_link_hash_indirect
4619 && edir->elf.dynamic_adjusted))
4620 edir->elf.non_got_ref |= eind->elf.non_got_ref;
4622 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
4623 edir->elf.ref_regular |= eind->elf.ref_regular;
4624 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
4625 edir->elf.needs_plt |= eind->elf.needs_plt;
4627 /* Copy over any dynamic relocs we may have on the indirect sym. */
4628 if (eind->dyn_relocs != NULL)
4630 if (edir->dyn_relocs != NULL)
4632 struct elf_dyn_relocs **pp;
4633 struct elf_dyn_relocs *p;
4635 /* Add reloc counts against the indirect sym to the direct sym
4636 list. Merge any entries against the same section. */
4637 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
4639 struct elf_dyn_relocs *q;
4641 for (q = edir->dyn_relocs; q != NULL; q = q->next)
4642 if (q->sec == p->sec)
4644 q->pc_count += p->pc_count;
4645 q->count += p->count;
4652 *pp = edir->dyn_relocs;
4655 edir->dyn_relocs = eind->dyn_relocs;
4656 eind->dyn_relocs = NULL;
4659 /* If we were called to copy over info for a weak sym, that's all.
4660 You might think dyn_relocs need not be copied over; After all,
4661 both syms will be dynamic or both non-dynamic so we're just
4662 moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
4663 code in ppc64_elf_adjust_dynamic_symbol needs to check for
4664 dyn_relocs in read-only sections, and it does so on what is the
4666 if (eind->elf.root.type != bfd_link_hash_indirect)
4669 /* Copy over got entries that we may have already seen to the
4670 symbol which just became indirect. */
4671 if (eind->elf.got.glist != NULL)
4673 if (edir->elf.got.glist != NULL)
4675 struct got_entry **entp;
4676 struct got_entry *ent;
4678 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
4680 struct got_entry *dent;
4682 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
4683 if (dent->addend == ent->addend
4684 && dent->owner == ent->owner
4685 && dent->tls_type == ent->tls_type)
4687 dent->got.refcount += ent->got.refcount;
4694 *entp = edir->elf.got.glist;
4697 edir->elf.got.glist = eind->elf.got.glist;
4698 eind->elf.got.glist = NULL;
4701 /* And plt entries. */
4702 move_plt_plist (eind, edir);
4704 if (eind->elf.dynindx != -1)
4706 if (edir->elf.dynindx != -1)
4707 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4708 edir->elf.dynstr_index);
4709 edir->elf.dynindx = eind->elf.dynindx;
4710 edir->elf.dynstr_index = eind->elf.dynstr_index;
4711 eind->elf.dynindx = -1;
4712 eind->elf.dynstr_index = 0;
4716 /* Find the function descriptor hash entry from the given function code
4717 hash entry FH. Link the entries via their OH fields. */
4719 static struct ppc_link_hash_entry *
4720 lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
4722 struct ppc_link_hash_entry *fdh = fh->oh;
4726 const char *fd_name = fh->elf.root.root.string + 1;
4728 fdh = (struct ppc_link_hash_entry *)
4729 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
4733 fdh->is_func_descriptor = 1;
4739 return ppc_follow_link (fdh);
4742 /* Make a fake function descriptor sym for the code sym FH. */
4744 static struct ppc_link_hash_entry *
4745 make_fdh (struct bfd_link_info *info,
4746 struct ppc_link_hash_entry *fh)
4750 struct bfd_link_hash_entry *bh;
4751 struct ppc_link_hash_entry *fdh;
4753 abfd = fh->elf.root.u.undef.abfd;
4754 newsym = bfd_make_empty_symbol (abfd);
4755 newsym->name = fh->elf.root.root.string + 1;
4756 newsym->section = bfd_und_section_ptr;
4758 newsym->flags = BSF_WEAK;
4761 if (!_bfd_generic_link_add_one_symbol (info, abfd, newsym->name,
4762 newsym->flags, newsym->section,
4763 newsym->value, NULL, FALSE, FALSE,
4767 fdh = (struct ppc_link_hash_entry *) bh;
4768 fdh->elf.non_elf = 0;
4770 fdh->is_func_descriptor = 1;
4777 /* Fix function descriptor symbols defined in .opd sections to be
4781 ppc64_elf_add_symbol_hook (bfd *ibfd,
4782 struct bfd_link_info *info,
4783 Elf_Internal_Sym *isym,
4785 flagword *flags ATTRIBUTE_UNUSED,
4787 bfd_vma *value ATTRIBUTE_UNUSED)
4789 if ((ibfd->flags & DYNAMIC) == 0
4790 && ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
4791 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4793 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
4795 if ((ibfd->flags & DYNAMIC) == 0)
4796 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4798 else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC)
4800 else if (*sec != NULL
4801 && strcmp ((*sec)->name, ".opd") == 0)
4802 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
4804 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
4806 if (abiversion (ibfd) == 0)
4807 set_abiversion (ibfd, 2);
4808 else if (abiversion (ibfd) == 1)
4810 info->callbacks->einfo (_("%P: symbol '%s' has invalid st_other"
4811 " for ABI version 1\n"), name);
4812 bfd_set_error (bfd_error_bad_value);
4820 /* Merge non-visibility st_other attributes: local entry point. */
4823 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
4824 const Elf_Internal_Sym *isym,
4825 bfd_boolean definition,
4826 bfd_boolean dynamic)
4828 if (definition && !dynamic)
4829 h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
4830 | ELF_ST_VISIBILITY (h->other));
4833 /* This function makes an old ABI object reference to ".bar" cause the
4834 inclusion of a new ABI object archive that defines "bar".
4835 NAME is a symbol defined in an archive. Return a symbol in the hash
4836 table that might be satisfied by the archive symbols. */
4838 static struct elf_link_hash_entry *
4839 ppc64_elf_archive_symbol_lookup (bfd *abfd,
4840 struct bfd_link_info *info,
4843 struct elf_link_hash_entry *h;
4847 h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
4849 /* Don't return this sym if it is a fake function descriptor
4850 created by add_symbol_adjust. */
4851 && !(h->root.type == bfd_link_hash_undefweak
4852 && ((struct ppc_link_hash_entry *) h)->fake))
4858 len = strlen (name);
4859 dot_name = bfd_alloc (abfd, len + 2);
4860 if (dot_name == NULL)
4861 return (struct elf_link_hash_entry *) 0 - 1;
4863 memcpy (dot_name + 1, name, len + 1);
4864 h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
4865 bfd_release (abfd, dot_name);
4869 /* This function satisfies all old ABI object references to ".bar" if a
4870 new ABI object defines "bar". Well, at least, undefined dot symbols
4871 are made weak. This stops later archive searches from including an
4872 object if we already have a function descriptor definition. It also
4873 prevents the linker complaining about undefined symbols.
4874 We also check and correct mismatched symbol visibility here. The
4875 most restrictive visibility of the function descriptor and the
4876 function entry symbol is used. */
4879 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
4881 struct ppc_link_hash_table *htab;
4882 struct ppc_link_hash_entry *fdh;
4884 if (eh->elf.root.type == bfd_link_hash_indirect)
4887 if (eh->elf.root.type == bfd_link_hash_warning)
4888 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
4890 if (eh->elf.root.root.string[0] != '.')
4893 htab = ppc_hash_table (info);
4897 fdh = lookup_fdh (eh, htab);
4900 if (!info->relocatable
4901 && (eh->elf.root.type == bfd_link_hash_undefined
4902 || eh->elf.root.type == bfd_link_hash_undefweak)
4903 && eh->elf.ref_regular)
4905 /* Make an undefweak function descriptor sym, which is enough to
4906 pull in an --as-needed shared lib, but won't cause link
4907 errors. Archives are handled elsewhere. */
4908 fdh = make_fdh (info, eh);
4911 fdh->elf.ref_regular = 1;
4916 unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
4917 unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
4918 if (entry_vis < descr_vis)
4919 fdh->elf.other += entry_vis - descr_vis;
4920 else if (entry_vis > descr_vis)
4921 eh->elf.other += descr_vis - entry_vis;
4923 if ((fdh->elf.root.type == bfd_link_hash_defined
4924 || fdh->elf.root.type == bfd_link_hash_defweak)
4925 && eh->elf.root.type == bfd_link_hash_undefined)
4927 eh->elf.root.type = bfd_link_hash_undefweak;
4928 eh->was_undefined = 1;
4929 htab->twiddled_syms = 1;
4936 /* Process list of dot-symbols we made in link_hash_newfunc. */
4939 ppc64_elf_process_dot_syms (bfd *ibfd, struct bfd_link_info *info)
4941 struct ppc_link_hash_table *htab;
4942 struct ppc_link_hash_entry **p, *eh;
4944 if (!is_ppc64_elf (info->output_bfd))
4946 htab = ppc_hash_table (info);
4950 if (is_ppc64_elf (ibfd))
4952 p = &htab->dot_syms;
4953 while ((eh = *p) != NULL)
4956 if (&eh->elf == htab->elf.hgot)
4958 else if (htab->elf.hgot == NULL
4959 && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
4960 htab->elf.hgot = &eh->elf;
4961 else if (!add_symbol_adjust (eh, info))
4963 p = &eh->u.next_dot_sym;
4967 /* Clear the list for non-ppc64 input files. */
4968 p = &htab->dot_syms;
4969 while ((eh = *p) != NULL)
4972 p = &eh->u.next_dot_sym;
4975 /* We need to fix the undefs list for any syms we have twiddled to
4977 if (htab->twiddled_syms)
4979 bfd_link_repair_undef_list (&htab->elf.root);
4980 htab->twiddled_syms = 0;
4985 /* Undo hash table changes when an --as-needed input file is determined
4986 not to be needed. */
4989 ppc64_elf_notice_as_needed (bfd *ibfd,
4990 struct bfd_link_info *info,
4991 enum notice_asneeded_action act)
4993 if (act == notice_not_needed)
4995 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5000 htab->dot_syms = NULL;
5002 return _bfd_elf_notice_as_needed (ibfd, info, act);
5005 /* If --just-symbols against a final linked binary, then assume we need
5006 toc adjusting stubs when calling functions defined there. */
5009 ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info)
5011 if ((sec->flags & SEC_CODE) != 0
5012 && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
5013 && is_ppc64_elf (sec->owner))
5015 asection *got = bfd_get_section_by_name (sec->owner, ".got");
5017 && got->size >= elf_backend_got_header_size
5018 && bfd_get_section_by_name (sec->owner, ".opd") != NULL)
5019 sec->has_toc_reloc = 1;
5021 _bfd_elf_link_just_syms (sec, info);
5024 static struct plt_entry **
5025 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
5026 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
5028 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
5029 struct plt_entry **local_plt;
5030 unsigned char *local_got_tls_masks;
5032 if (local_got_ents == NULL)
5034 bfd_size_type size = symtab_hdr->sh_info;
5036 size *= (sizeof (*local_got_ents)
5037 + sizeof (*local_plt)
5038 + sizeof (*local_got_tls_masks));
5039 local_got_ents = bfd_zalloc (abfd, size);
5040 if (local_got_ents == NULL)
5042 elf_local_got_ents (abfd) = local_got_ents;
5045 if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0)
5047 struct got_entry *ent;
5049 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
5050 if (ent->addend == r_addend
5051 && ent->owner == abfd
5052 && ent->tls_type == tls_type)
5056 bfd_size_type amt = sizeof (*ent);
5057 ent = bfd_alloc (abfd, amt);
5060 ent->next = local_got_ents[r_symndx];
5061 ent->addend = r_addend;
5063 ent->tls_type = tls_type;
5064 ent->is_indirect = FALSE;
5065 ent->got.refcount = 0;
5066 local_got_ents[r_symndx] = ent;
5068 ent->got.refcount += 1;
5071 local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
5072 local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info);
5073 local_got_tls_masks[r_symndx] |= tls_type;
5075 return local_plt + r_symndx;
5079 update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
5081 struct plt_entry *ent;
5083 for (ent = *plist; ent != NULL; ent = ent->next)
5084 if (ent->addend == addend)
5088 bfd_size_type amt = sizeof (*ent);
5089 ent = bfd_alloc (abfd, amt);
5093 ent->addend = addend;
5094 ent->plt.refcount = 0;
5097 ent->plt.refcount += 1;
5102 is_branch_reloc (enum elf_ppc64_reloc_type r_type)
5104 return (r_type == R_PPC64_REL24
5105 || r_type == R_PPC64_REL14
5106 || r_type == R_PPC64_REL14_BRTAKEN
5107 || r_type == R_PPC64_REL14_BRNTAKEN
5108 || r_type == R_PPC64_ADDR24
5109 || r_type == R_PPC64_ADDR14
5110 || r_type == R_PPC64_ADDR14_BRTAKEN
5111 || r_type == R_PPC64_ADDR14_BRNTAKEN);
5114 /* Look through the relocs for a section during the first phase, and
5115 calculate needed space in the global offset table, procedure
5116 linkage table, and dynamic reloc sections. */
5119 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
5120 asection *sec, const Elf_Internal_Rela *relocs)
5122 struct ppc_link_hash_table *htab;
5123 Elf_Internal_Shdr *symtab_hdr;
5124 struct elf_link_hash_entry **sym_hashes;
5125 const Elf_Internal_Rela *rel;
5126 const Elf_Internal_Rela *rel_end;
5128 asection **opd_sym_map;
5129 struct elf_link_hash_entry *tga, *dottga;
5131 if (info->relocatable)
5134 /* Don't do anything special with non-loaded, non-alloced sections.
5135 In particular, any relocs in such sections should not affect GOT
5136 and PLT reference counting (ie. we don't allow them to create GOT
5137 or PLT entries), there's no possibility or desire to optimize TLS
5138 relocs, and there's not much point in propagating relocs to shared
5139 libs that the dynamic linker won't relocate. */
5140 if ((sec->flags & SEC_ALLOC) == 0)
5143 BFD_ASSERT (is_ppc64_elf (abfd));
5145 htab = ppc_hash_table (info);
5149 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
5150 FALSE, FALSE, TRUE);
5151 dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
5152 FALSE, FALSE, TRUE);
5153 symtab_hdr = &elf_symtab_hdr (abfd);
5154 sym_hashes = elf_sym_hashes (abfd);
5157 if (strcmp (sec->name, ".opd") == 0)
5159 /* Garbage collection needs some extra help with .opd sections.
5160 We don't want to necessarily keep everything referenced by
5161 relocs in .opd, as that would keep all functions. Instead,
5162 if we reference an .opd symbol (a function descriptor), we
5163 want to keep the function code symbol's section. This is
5164 easy for global symbols, but for local syms we need to keep
5165 information about the associated function section. */
5168 if (abiversion (abfd) == 0)
5169 set_abiversion (abfd, 1);
5170 else if (abiversion (abfd) == 2)
5172 info->callbacks->einfo (_("%P: .opd not allowed in ABI version %d\n"),
5174 bfd_set_error (bfd_error_bad_value);
5177 amt = sec->size * sizeof (*opd_sym_map) / 8;
5178 opd_sym_map = bfd_zalloc (abfd, amt);
5179 if (opd_sym_map == NULL)
5181 ppc64_elf_section_data (sec)->u.opd.func_sec = opd_sym_map;
5182 BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal);
5183 ppc64_elf_section_data (sec)->sec_type = sec_opd;
5186 rel_end = relocs + sec->reloc_count;
5187 for (rel = relocs; rel < rel_end; rel++)
5189 unsigned long r_symndx;
5190 struct elf_link_hash_entry *h;
5191 enum elf_ppc64_reloc_type r_type;
5193 struct _ppc64_elf_section_data *ppc64_sec;
5194 struct plt_entry **ifunc;
5196 r_symndx = ELF64_R_SYM (rel->r_info);
5197 if (r_symndx < symtab_hdr->sh_info)
5201 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5202 h = elf_follow_link (h);
5204 /* PR15323, ref flags aren't set for references in the same
5206 h->root.non_ir_ref = 1;
5208 if (h == htab->elf.hgot)
5209 sec->has_toc_reloc = 1;
5216 if (h->type == STT_GNU_IFUNC)
5219 ifunc = &h->plt.plist;
5224 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5229 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5231 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
5232 rel->r_addend, PLT_IFUNC);
5237 r_type = ELF64_R_TYPE (rel->r_info);
5238 if (is_branch_reloc (r_type))
5240 if (h != NULL && (h == tga || h == dottga))
5243 && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
5244 || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
5245 /* We have a new-style __tls_get_addr call with a marker
5249 /* Mark this section as having an old-style call. */
5250 sec->has_tls_get_addr_call = 1;
5253 /* STT_GNU_IFUNC symbols must have a PLT entry. */
5255 && !update_plt_info (abfd, ifunc, rel->r_addend))
5263 /* These special tls relocs tie a call to __tls_get_addr with
5264 its parameter symbol. */
5267 case R_PPC64_GOT_TLSLD16:
5268 case R_PPC64_GOT_TLSLD16_LO:
5269 case R_PPC64_GOT_TLSLD16_HI:
5270 case R_PPC64_GOT_TLSLD16_HA:
5271 tls_type = TLS_TLS | TLS_LD;
5274 case R_PPC64_GOT_TLSGD16:
5275 case R_PPC64_GOT_TLSGD16_LO:
5276 case R_PPC64_GOT_TLSGD16_HI:
5277 case R_PPC64_GOT_TLSGD16_HA:
5278 tls_type = TLS_TLS | TLS_GD;
5281 case R_PPC64_GOT_TPREL16_DS:
5282 case R_PPC64_GOT_TPREL16_LO_DS:
5283 case R_PPC64_GOT_TPREL16_HI:
5284 case R_PPC64_GOT_TPREL16_HA:
5285 if (!info->executable)
5286 info->flags |= DF_STATIC_TLS;
5287 tls_type = TLS_TLS | TLS_TPREL;
5290 case R_PPC64_GOT_DTPREL16_DS:
5291 case R_PPC64_GOT_DTPREL16_LO_DS:
5292 case R_PPC64_GOT_DTPREL16_HI:
5293 case R_PPC64_GOT_DTPREL16_HA:
5294 tls_type = TLS_TLS | TLS_DTPREL;
5296 sec->has_tls_reloc = 1;
5300 case R_PPC64_GOT16_DS:
5301 case R_PPC64_GOT16_HA:
5302 case R_PPC64_GOT16_HI:
5303 case R_PPC64_GOT16_LO:
5304 case R_PPC64_GOT16_LO_DS:
5305 /* This symbol requires a global offset table entry. */
5306 sec->has_toc_reloc = 1;
5307 if (r_type == R_PPC64_GOT_TLSLD16
5308 || r_type == R_PPC64_GOT_TLSGD16
5309 || r_type == R_PPC64_GOT_TPREL16_DS
5310 || r_type == R_PPC64_GOT_DTPREL16_DS
5311 || r_type == R_PPC64_GOT16
5312 || r_type == R_PPC64_GOT16_DS)
5314 htab->do_multi_toc = 1;
5315 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5318 if (ppc64_elf_tdata (abfd)->got == NULL
5319 && !create_got_section (abfd, info))
5324 struct ppc_link_hash_entry *eh;
5325 struct got_entry *ent;
5327 eh = (struct ppc_link_hash_entry *) h;
5328 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
5329 if (ent->addend == rel->r_addend
5330 && ent->owner == abfd
5331 && ent->tls_type == tls_type)
5335 bfd_size_type amt = sizeof (*ent);
5336 ent = bfd_alloc (abfd, amt);
5339 ent->next = eh->elf.got.glist;
5340 ent->addend = rel->r_addend;
5342 ent->tls_type = tls_type;
5343 ent->is_indirect = FALSE;
5344 ent->got.refcount = 0;
5345 eh->elf.got.glist = ent;
5347 ent->got.refcount += 1;
5348 eh->tls_mask |= tls_type;
5351 /* This is a global offset table entry for a local symbol. */
5352 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5353 rel->r_addend, tls_type))
5357 case R_PPC64_PLT16_HA:
5358 case R_PPC64_PLT16_HI:
5359 case R_PPC64_PLT16_LO:
5362 /* This symbol requires a procedure linkage table entry. We
5363 actually build the entry in adjust_dynamic_symbol,
5364 because this might be a case of linking PIC code without
5365 linking in any dynamic objects, in which case we don't
5366 need to generate a procedure linkage table after all. */
5369 /* It does not make sense to have a procedure linkage
5370 table entry for a local symbol. */
5371 bfd_set_error (bfd_error_bad_value);
5376 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5379 if (h->root.root.string[0] == '.'
5380 && h->root.root.string[1] != '\0')
5381 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5385 /* The following relocations don't need to propagate the
5386 relocation if linking a shared object since they are
5387 section relative. */
5388 case R_PPC64_SECTOFF:
5389 case R_PPC64_SECTOFF_LO:
5390 case R_PPC64_SECTOFF_HI:
5391 case R_PPC64_SECTOFF_HA:
5392 case R_PPC64_SECTOFF_DS:
5393 case R_PPC64_SECTOFF_LO_DS:
5394 case R_PPC64_DTPREL16:
5395 case R_PPC64_DTPREL16_LO:
5396 case R_PPC64_DTPREL16_HI:
5397 case R_PPC64_DTPREL16_HA:
5398 case R_PPC64_DTPREL16_DS:
5399 case R_PPC64_DTPREL16_LO_DS:
5400 case R_PPC64_DTPREL16_HIGH:
5401 case R_PPC64_DTPREL16_HIGHA:
5402 case R_PPC64_DTPREL16_HIGHER:
5403 case R_PPC64_DTPREL16_HIGHERA:
5404 case R_PPC64_DTPREL16_HIGHEST:
5405 case R_PPC64_DTPREL16_HIGHESTA:
5410 case R_PPC64_REL16_LO:
5411 case R_PPC64_REL16_HI:
5412 case R_PPC64_REL16_HA:
5416 case R_PPC64_TOC16_DS:
5417 htab->do_multi_toc = 1;
5418 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5419 case R_PPC64_TOC16_LO:
5420 case R_PPC64_TOC16_HI:
5421 case R_PPC64_TOC16_HA:
5422 case R_PPC64_TOC16_LO_DS:
5423 sec->has_toc_reloc = 1;
5426 /* This relocation describes the C++ object vtable hierarchy.
5427 Reconstruct it for later use during GC. */
5428 case R_PPC64_GNU_VTINHERIT:
5429 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5433 /* This relocation describes which C++ vtable entries are actually
5434 used. Record for later use during GC. */
5435 case R_PPC64_GNU_VTENTRY:
5436 BFD_ASSERT (h != NULL);
5438 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5443 case R_PPC64_REL14_BRTAKEN:
5444 case R_PPC64_REL14_BRNTAKEN:
5446 asection *dest = NULL;
5448 /* Heuristic: If jumping outside our section, chances are
5449 we are going to need a stub. */
5452 /* If the sym is weak it may be overridden later, so
5453 don't assume we know where a weak sym lives. */
5454 if (h->root.type == bfd_link_hash_defined)
5455 dest = h->root.u.def.section;
5459 Elf_Internal_Sym *isym;
5461 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5466 dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
5470 ppc64_elf_section_data (sec)->has_14bit_branch = 1;
5475 if (h != NULL && ifunc == NULL)
5477 /* We may need a .plt entry if the function this reloc
5478 refers to is in a shared lib. */
5479 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5482 if (h->root.root.string[0] == '.'
5483 && h->root.root.string[1] != '\0')
5484 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5485 if (h == tga || h == dottga)
5486 sec->has_tls_reloc = 1;
5490 case R_PPC64_TPREL64:
5491 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
5492 if (!info->executable)
5493 info->flags |= DF_STATIC_TLS;
5496 case R_PPC64_DTPMOD64:
5497 if (rel + 1 < rel_end
5498 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
5499 && rel[1].r_offset == rel->r_offset + 8)
5500 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
5502 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
5505 case R_PPC64_DTPREL64:
5506 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
5508 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
5509 && rel[-1].r_offset == rel->r_offset - 8)
5510 /* This is the second reloc of a dtpmod, dtprel pair.
5511 Don't mark with TLS_DTPREL. */
5515 sec->has_tls_reloc = 1;
5518 struct ppc_link_hash_entry *eh;
5519 eh = (struct ppc_link_hash_entry *) h;
5520 eh->tls_mask |= tls_type;
5523 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5524 rel->r_addend, tls_type))
5527 ppc64_sec = ppc64_elf_section_data (sec);
5528 if (ppc64_sec->sec_type != sec_toc)
5532 /* One extra to simplify get_tls_mask. */
5533 amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
5534 ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
5535 if (ppc64_sec->u.toc.symndx == NULL)
5537 amt = sec->size * sizeof (bfd_vma) / 8;
5538 ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
5539 if (ppc64_sec->u.toc.add == NULL)
5541 BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
5542 ppc64_sec->sec_type = sec_toc;
5544 BFD_ASSERT (rel->r_offset % 8 == 0);
5545 ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
5546 ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
5548 /* Mark the second slot of a GD or LD entry.
5549 -1 to indicate GD and -2 to indicate LD. */
5550 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
5551 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1;
5552 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
5553 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
5556 case R_PPC64_TPREL16:
5557 case R_PPC64_TPREL16_LO:
5558 case R_PPC64_TPREL16_HI:
5559 case R_PPC64_TPREL16_HA:
5560 case R_PPC64_TPREL16_DS:
5561 case R_PPC64_TPREL16_LO_DS:
5562 case R_PPC64_TPREL16_HIGH:
5563 case R_PPC64_TPREL16_HIGHA:
5564 case R_PPC64_TPREL16_HIGHER:
5565 case R_PPC64_TPREL16_HIGHERA:
5566 case R_PPC64_TPREL16_HIGHEST:
5567 case R_PPC64_TPREL16_HIGHESTA:
5570 if (!info->executable)
5571 info->flags |= DF_STATIC_TLS;
5576 case R_PPC64_ADDR64:
5577 if (opd_sym_map != NULL
5578 && rel + 1 < rel_end
5579 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
5583 if (h->root.root.string[0] == '.'
5584 && h->root.root.string[1] != 0
5585 && lookup_fdh ((struct ppc_link_hash_entry *) h, htab))
5588 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5593 Elf_Internal_Sym *isym;
5595 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5600 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5601 if (s != NULL && s != sec)
5602 opd_sym_map[rel->r_offset / 8] = s;
5610 case R_PPC64_ADDR14:
5611 case R_PPC64_ADDR14_BRNTAKEN:
5612 case R_PPC64_ADDR14_BRTAKEN:
5613 case R_PPC64_ADDR16:
5614 case R_PPC64_ADDR16_DS:
5615 case R_PPC64_ADDR16_HA:
5616 case R_PPC64_ADDR16_HI:
5617 case R_PPC64_ADDR16_HIGH:
5618 case R_PPC64_ADDR16_HIGHA:
5619 case R_PPC64_ADDR16_HIGHER:
5620 case R_PPC64_ADDR16_HIGHERA:
5621 case R_PPC64_ADDR16_HIGHEST:
5622 case R_PPC64_ADDR16_HIGHESTA:
5623 case R_PPC64_ADDR16_LO:
5624 case R_PPC64_ADDR16_LO_DS:
5625 case R_PPC64_ADDR24:
5626 case R_PPC64_ADDR32:
5627 case R_PPC64_UADDR16:
5628 case R_PPC64_UADDR32:
5629 case R_PPC64_UADDR64:
5631 if (h != NULL && !info->shared)
5632 /* We may need a copy reloc. */
5635 /* Don't propagate .opd relocs. */
5636 if (NO_OPD_RELOCS && opd_sym_map != NULL)
5639 /* If we are creating a shared library, and this is a reloc
5640 against a global symbol, or a non PC relative reloc
5641 against a local symbol, then we need to copy the reloc
5642 into the shared library. However, if we are linking with
5643 -Bsymbolic, we do not need to copy a reloc against a
5644 global symbol which is defined in an object we are
5645 including in the link (i.e., DEF_REGULAR is set). At
5646 this point we have not seen all the input files, so it is
5647 possible that DEF_REGULAR is not set now but will be set
5648 later (it is never cleared). In case of a weak definition,
5649 DEF_REGULAR may be cleared later by a strong definition in
5650 a shared library. We account for that possibility below by
5651 storing information in the dyn_relocs field of the hash
5652 table entry. A similar situation occurs when creating
5653 shared libraries and symbol visibility changes render the
5656 If on the other hand, we are creating an executable, we
5657 may need to keep relocations for symbols satisfied by a
5658 dynamic library if we manage to avoid copy relocs for the
5662 && (must_be_dyn_reloc (info, r_type)
5664 && (!SYMBOLIC_BIND (info, h)
5665 || h->root.type == bfd_link_hash_defweak
5666 || !h->def_regular))))
5667 || (ELIMINATE_COPY_RELOCS
5670 && (h->root.type == bfd_link_hash_defweak
5671 || !h->def_regular))
5675 /* We must copy these reloc types into the output file.
5676 Create a reloc section in dynobj and make room for
5680 sreloc = _bfd_elf_make_dynamic_reloc_section
5681 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
5687 /* If this is a global symbol, we count the number of
5688 relocations we need for this symbol. */
5691 struct elf_dyn_relocs *p;
5692 struct elf_dyn_relocs **head;
5694 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
5696 if (p == NULL || p->sec != sec)
5698 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
5708 if (!must_be_dyn_reloc (info, r_type))
5713 /* Track dynamic relocs needed for local syms too.
5714 We really need local syms available to do this
5716 struct ppc_dyn_relocs *p;
5717 struct ppc_dyn_relocs **head;
5718 bfd_boolean is_ifunc;
5721 Elf_Internal_Sym *isym;
5723 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5728 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5732 vpp = &elf_section_data (s)->local_dynrel;
5733 head = (struct ppc_dyn_relocs **) vpp;
5734 is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
5736 if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
5738 if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
5740 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
5746 p->ifunc = is_ifunc;
5762 /* Merge backend specific data from an object file to the output
5763 object file when linking. */
5766 ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5768 unsigned long iflags, oflags;
5770 if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
5773 if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
5776 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5779 iflags = elf_elfheader (ibfd)->e_flags;
5780 oflags = elf_elfheader (obfd)->e_flags;
5782 if (!elf_flags_init (obfd) || oflags == 0)
5784 elf_flags_init (obfd) = TRUE;
5785 elf_elfheader (obfd)->e_flags = iflags;
5787 else if (iflags == oflags || iflags == 0)
5789 else if (iflags & ~EF_PPC64_ABI)
5791 (*_bfd_error_handler)
5792 (_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
5793 bfd_set_error (bfd_error_bad_value);
5798 (*_bfd_error_handler)
5799 (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
5800 ibfd, iflags, oflags);
5801 bfd_set_error (bfd_error_bad_value);
5805 /* Merge Tag_compatibility attributes and any common GNU ones. */
5806 _bfd_elf_merge_object_attributes (ibfd, obfd);
5812 ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
5814 /* Print normal ELF private data. */
5815 _bfd_elf_print_private_bfd_data (abfd, ptr);
5817 if (elf_elfheader (abfd)->e_flags != 0)
5821 /* xgettext:c-format */
5822 fprintf (file, _("private flags = 0x%lx:"),
5823 elf_elfheader (abfd)->e_flags);
5825 if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
5826 fprintf (file, _(" [abiv%ld]"),
5827 elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
5834 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5835 of the code entry point, and its section. */
5838 opd_entry_value (asection *opd_sec,
5840 asection **code_sec,
5842 bfd_boolean in_code_sec)
5844 bfd *opd_bfd = opd_sec->owner;
5845 Elf_Internal_Rela *relocs;
5846 Elf_Internal_Rela *lo, *hi, *look;
5849 /* No relocs implies we are linking a --just-symbols object, or looking
5850 at a final linked executable with addr2line or somesuch. */
5851 if (opd_sec->reloc_count == 0)
5853 bfd_byte *contents = ppc64_elf_tdata (opd_bfd)->opd.contents;
5855 if (contents == NULL)
5857 if (!bfd_malloc_and_get_section (opd_bfd, opd_sec, &contents))
5858 return (bfd_vma) -1;
5859 ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
5862 val = bfd_get_64 (opd_bfd, contents + offset);
5863 if (code_sec != NULL)
5865 asection *sec, *likely = NULL;
5871 && val < sec->vma + sec->size)
5877 for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
5879 && (sec->flags & SEC_LOAD) != 0
5880 && (sec->flags & SEC_ALLOC) != 0)
5885 if (code_off != NULL)
5886 *code_off = val - likely->vma;
5892 BFD_ASSERT (is_ppc64_elf (opd_bfd));
5894 relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
5896 relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
5898 /* Go find the opd reloc at the sym address. */
5900 BFD_ASSERT (lo != NULL);
5901 hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
5905 look = lo + (hi - lo) / 2;
5906 if (look->r_offset < offset)
5908 else if (look->r_offset > offset)
5912 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd);
5914 if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
5915 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
5917 unsigned long symndx = ELF64_R_SYM (look->r_info);
5920 if (symndx < symtab_hdr->sh_info
5921 || elf_sym_hashes (opd_bfd) == NULL)
5923 Elf_Internal_Sym *sym;
5925 sym = (Elf_Internal_Sym *) symtab_hdr->contents;
5928 size_t symcnt = symtab_hdr->sh_info;
5929 if (elf_sym_hashes (opd_bfd) == NULL)
5930 symcnt = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
5931 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, symcnt,
5932 0, NULL, NULL, NULL);
5935 symtab_hdr->contents = (bfd_byte *) sym;
5939 val = sym->st_value;
5940 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
5941 BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
5945 struct elf_link_hash_entry **sym_hashes;
5946 struct elf_link_hash_entry *rh;
5948 sym_hashes = elf_sym_hashes (opd_bfd);
5949 rh = sym_hashes[symndx - symtab_hdr->sh_info];
5952 rh = elf_follow_link (rh);
5953 BFD_ASSERT (rh->root.type == bfd_link_hash_defined
5954 || rh->root.type == bfd_link_hash_defweak);
5955 val = rh->root.u.def.value;
5956 sec = rh->root.u.def.section;
5960 /* Handle the odd case where we can be called
5961 during bfd_elf_link_add_symbols before the
5962 symbol hashes have been fully populated. */
5963 Elf_Internal_Sym *sym;
5965 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, 1,
5966 symndx, NULL, NULL, NULL);
5970 val = sym->st_value;
5971 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
5975 val += look->r_addend;
5976 if (code_off != NULL)
5978 if (code_sec != NULL)
5980 if (in_code_sec && *code_sec != sec)
5985 if (sec != NULL && sec->output_section != NULL)
5986 val += sec->output_section->vma + sec->output_offset;
5995 /* If the ELF symbol SYM might be a function in SEC, return the
5996 function size and set *CODE_OFF to the function's entry point,
5997 otherwise return zero. */
5999 static bfd_size_type
6000 ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
6005 if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
6006 | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
6010 if (!(sym->flags & BSF_SYNTHETIC))
6011 size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
6013 if (strcmp (sym->section->name, ".opd") == 0)
6015 if (opd_entry_value (sym->section, sym->value,
6016 &sec, code_off, TRUE) == (bfd_vma) -1)
6018 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6019 symbol. This size has nothing to do with the code size of the
6020 function, which is what we're supposed to return, but the
6021 code size isn't available without looking up the dot-sym.
6022 However, doing that would be a waste of time particularly
6023 since elf_find_function will look at the dot-sym anyway.
6024 Now, elf_find_function will keep the largest size of any
6025 function sym found at the code address of interest, so return
6026 1 here to avoid it incorrectly caching a larger function size
6027 for a small function. This does mean we return the wrong
6028 size for a new-ABI function of size 24, but all that does is
6029 disable caching for such functions. */
6035 if (sym->section != sec)
6037 *code_off = sym->value;
6044 /* Return true if symbol is defined in a regular object file. */
6047 is_static_defined (struct elf_link_hash_entry *h)
6049 return ((h->root.type == bfd_link_hash_defined
6050 || h->root.type == bfd_link_hash_defweak)
6051 && h->root.u.def.section != NULL
6052 && h->root.u.def.section->output_section != NULL);
6055 /* If FDH is a function descriptor symbol, return the associated code
6056 entry symbol if it is defined. Return NULL otherwise. */
6058 static struct ppc_link_hash_entry *
6059 defined_code_entry (struct ppc_link_hash_entry *fdh)
6061 if (fdh->is_func_descriptor)
6063 struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
6064 if (fh->elf.root.type == bfd_link_hash_defined
6065 || fh->elf.root.type == bfd_link_hash_defweak)
6071 /* If FH is a function code entry symbol, return the associated
6072 function descriptor symbol if it is defined. Return NULL otherwise. */
6074 static struct ppc_link_hash_entry *
6075 defined_func_desc (struct ppc_link_hash_entry *fh)
6078 && fh->oh->is_func_descriptor)
6080 struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
6081 if (fdh->elf.root.type == bfd_link_hash_defined
6082 || fdh->elf.root.type == bfd_link_hash_defweak)
6088 /* Mark all our entry sym sections, both opd and code section. */
6091 ppc64_elf_gc_keep (struct bfd_link_info *info)
6093 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6094 struct bfd_sym_chain *sym;
6099 for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
6101 struct ppc_link_hash_entry *eh, *fh;
6104 eh = (struct ppc_link_hash_entry *)
6105 elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
6108 if (eh->elf.root.type != bfd_link_hash_defined
6109 && eh->elf.root.type != bfd_link_hash_defweak)
6112 fh = defined_code_entry (eh);
6115 sec = fh->elf.root.u.def.section;
6116 sec->flags |= SEC_KEEP;
6118 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6119 && opd_entry_value (eh->elf.root.u.def.section,
6120 eh->elf.root.u.def.value,
6121 &sec, NULL, FALSE) != (bfd_vma) -1)
6122 sec->flags |= SEC_KEEP;
6124 sec = eh->elf.root.u.def.section;
6125 sec->flags |= SEC_KEEP;
6129 /* Mark sections containing dynamically referenced symbols. When
6130 building shared libraries, we must assume that any visible symbol is
6134 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
6136 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6137 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
6138 struct ppc_link_hash_entry *fdh;
6140 /* Dynamic linking info is on the func descriptor sym. */
6141 fdh = defined_func_desc (eh);
6145 if ((eh->elf.root.type == bfd_link_hash_defined
6146 || eh->elf.root.type == bfd_link_hash_defweak)
6147 && (eh->elf.ref_dynamic
6148 || (!info->executable
6149 && eh->elf.def_regular
6150 && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
6151 && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
6152 && (strchr (eh->elf.root.root.string, ELF_VER_CHR) != NULL
6153 || !bfd_hide_sym_by_version (info->version_info,
6154 eh->elf.root.root.string)))))
6157 struct ppc_link_hash_entry *fh;
6159 eh->elf.root.u.def.section->flags |= SEC_KEEP;
6161 /* Function descriptor syms cause the associated
6162 function code sym section to be marked. */
6163 fh = defined_code_entry (eh);
6166 code_sec = fh->elf.root.u.def.section;
6167 code_sec->flags |= SEC_KEEP;
6169 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6170 && opd_entry_value (eh->elf.root.u.def.section,
6171 eh->elf.root.u.def.value,
6172 &code_sec, NULL, FALSE) != (bfd_vma) -1)
6173 code_sec->flags |= SEC_KEEP;
6179 /* Return the section that should be marked against GC for a given
6183 ppc64_elf_gc_mark_hook (asection *sec,
6184 struct bfd_link_info *info,
6185 Elf_Internal_Rela *rel,
6186 struct elf_link_hash_entry *h,
6187 Elf_Internal_Sym *sym)
6191 /* Syms return NULL if we're marking .opd, so we avoid marking all
6192 function sections, as all functions are referenced in .opd. */
6194 if (get_opd_info (sec) != NULL)
6199 enum elf_ppc64_reloc_type r_type;
6200 struct ppc_link_hash_entry *eh, *fh, *fdh;
6202 r_type = ELF64_R_TYPE (rel->r_info);
6205 case R_PPC64_GNU_VTINHERIT:
6206 case R_PPC64_GNU_VTENTRY:
6210 switch (h->root.type)
6212 case bfd_link_hash_defined:
6213 case bfd_link_hash_defweak:
6214 eh = (struct ppc_link_hash_entry *) h;
6215 fdh = defined_func_desc (eh);
6219 /* Function descriptor syms cause the associated
6220 function code sym section to be marked. */
6221 fh = defined_code_entry (eh);
6224 /* They also mark their opd section. */
6225 eh->elf.root.u.def.section->gc_mark = 1;
6227 rsec = fh->elf.root.u.def.section;
6229 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6230 && opd_entry_value (eh->elf.root.u.def.section,
6231 eh->elf.root.u.def.value,
6232 &rsec, NULL, FALSE) != (bfd_vma) -1)
6233 eh->elf.root.u.def.section->gc_mark = 1;
6235 rsec = h->root.u.def.section;
6238 case bfd_link_hash_common:
6239 rsec = h->root.u.c.p->section;
6243 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
6249 struct _opd_sec_data *opd;
6251 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6252 opd = get_opd_info (rsec);
6253 if (opd != NULL && opd->func_sec != NULL)
6257 rsec = opd->func_sec[(sym->st_value + rel->r_addend) / 8];
6264 /* Update the .got, .plt. and dynamic reloc reference counts for the
6265 section being removed. */
6268 ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
6269 asection *sec, const Elf_Internal_Rela *relocs)
6271 struct ppc_link_hash_table *htab;
6272 Elf_Internal_Shdr *symtab_hdr;
6273 struct elf_link_hash_entry **sym_hashes;
6274 struct got_entry **local_got_ents;
6275 const Elf_Internal_Rela *rel, *relend;
6277 if (info->relocatable)
6280 if ((sec->flags & SEC_ALLOC) == 0)
6283 elf_section_data (sec)->local_dynrel = NULL;
6285 htab = ppc_hash_table (info);
6289 symtab_hdr = &elf_symtab_hdr (abfd);
6290 sym_hashes = elf_sym_hashes (abfd);
6291 local_got_ents = elf_local_got_ents (abfd);
6293 relend = relocs + sec->reloc_count;
6294 for (rel = relocs; rel < relend; rel++)
6296 unsigned long r_symndx;
6297 enum elf_ppc64_reloc_type r_type;
6298 struct elf_link_hash_entry *h = NULL;
6299 unsigned char tls_type = 0;
6301 r_symndx = ELF64_R_SYM (rel->r_info);
6302 r_type = ELF64_R_TYPE (rel->r_info);
6303 if (r_symndx >= symtab_hdr->sh_info)
6305 struct ppc_link_hash_entry *eh;
6306 struct elf_dyn_relocs **pp;
6307 struct elf_dyn_relocs *p;
6309 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6310 h = elf_follow_link (h);
6311 eh = (struct ppc_link_hash_entry *) h;
6313 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6316 /* Everything must go for SEC. */
6322 if (is_branch_reloc (r_type))
6324 struct plt_entry **ifunc = NULL;
6327 if (h->type == STT_GNU_IFUNC)
6328 ifunc = &h->plt.plist;
6330 else if (local_got_ents != NULL)
6332 struct plt_entry **local_plt = (struct plt_entry **)
6333 (local_got_ents + symtab_hdr->sh_info);
6334 unsigned char *local_got_tls_masks = (unsigned char *)
6335 (local_plt + symtab_hdr->sh_info);
6336 if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
6337 ifunc = local_plt + r_symndx;
6341 struct plt_entry *ent;
6343 for (ent = *ifunc; ent != NULL; ent = ent->next)
6344 if (ent->addend == rel->r_addend)
6348 if (ent->plt.refcount > 0)
6349 ent->plt.refcount -= 1;
6356 case R_PPC64_GOT_TLSLD16:
6357 case R_PPC64_GOT_TLSLD16_LO:
6358 case R_PPC64_GOT_TLSLD16_HI:
6359 case R_PPC64_GOT_TLSLD16_HA:
6360 tls_type = TLS_TLS | TLS_LD;
6363 case R_PPC64_GOT_TLSGD16:
6364 case R_PPC64_GOT_TLSGD16_LO:
6365 case R_PPC64_GOT_TLSGD16_HI:
6366 case R_PPC64_GOT_TLSGD16_HA:
6367 tls_type = TLS_TLS | TLS_GD;
6370 case R_PPC64_GOT_TPREL16_DS:
6371 case R_PPC64_GOT_TPREL16_LO_DS:
6372 case R_PPC64_GOT_TPREL16_HI:
6373 case R_PPC64_GOT_TPREL16_HA:
6374 tls_type = TLS_TLS | TLS_TPREL;
6377 case R_PPC64_GOT_DTPREL16_DS:
6378 case R_PPC64_GOT_DTPREL16_LO_DS:
6379 case R_PPC64_GOT_DTPREL16_HI:
6380 case R_PPC64_GOT_DTPREL16_HA:
6381 tls_type = TLS_TLS | TLS_DTPREL;
6385 case R_PPC64_GOT16_DS:
6386 case R_PPC64_GOT16_HA:
6387 case R_PPC64_GOT16_HI:
6388 case R_PPC64_GOT16_LO:
6389 case R_PPC64_GOT16_LO_DS:
6392 struct got_entry *ent;
6397 ent = local_got_ents[r_symndx];
6399 for (; ent != NULL; ent = ent->next)
6400 if (ent->addend == rel->r_addend
6401 && ent->owner == abfd
6402 && ent->tls_type == tls_type)
6406 if (ent->got.refcount > 0)
6407 ent->got.refcount -= 1;
6411 case R_PPC64_PLT16_HA:
6412 case R_PPC64_PLT16_HI:
6413 case R_PPC64_PLT16_LO:
6417 case R_PPC64_REL14_BRNTAKEN:
6418 case R_PPC64_REL14_BRTAKEN:
6422 struct plt_entry *ent;
6424 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
6425 if (ent->addend == rel->r_addend)
6427 if (ent != NULL && ent->plt.refcount > 0)
6428 ent->plt.refcount -= 1;
6439 /* The maximum size of .sfpr. */
6440 #define SFPR_MAX (218*4)
6442 struct sfpr_def_parms
6444 const char name[12];
6445 unsigned char lo, hi;
6446 bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
6447 bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
6450 /* Auto-generate _save*, _rest* functions in .sfpr. */
6453 sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm)
6455 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6457 size_t len = strlen (parm->name);
6458 bfd_boolean writing = FALSE;
6464 memcpy (sym, parm->name, len);
6467 for (i = parm->lo; i <= parm->hi; i++)
6469 struct elf_link_hash_entry *h;
6471 sym[len + 0] = i / 10 + '0';
6472 sym[len + 1] = i % 10 + '0';
6473 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
6477 h->root.type = bfd_link_hash_defined;
6478 h->root.u.def.section = htab->sfpr;
6479 h->root.u.def.value = htab->sfpr->size;
6482 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
6484 if (htab->sfpr->contents == NULL)
6486 htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
6487 if (htab->sfpr->contents == NULL)
6493 bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
6495 p = (*parm->write_ent) (htab->elf.dynobj, p, i);
6497 p = (*parm->write_tail) (htab->elf.dynobj, p, i);
6498 htab->sfpr->size = p - htab->sfpr->contents;
6506 savegpr0 (bfd *abfd, bfd_byte *p, int r)
6508 bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6513 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
6515 p = savegpr0 (abfd, p, r);
6516 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6518 bfd_put_32 (abfd, BLR, p);
6523 restgpr0 (bfd *abfd, bfd_byte *p, int r)
6525 bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6530 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
6532 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6534 p = restgpr0 (abfd, p, r);
6535 bfd_put_32 (abfd, MTLR_R0, p);
6539 p = restgpr0 (abfd, p, 30);
6540 p = restgpr0 (abfd, p, 31);
6542 bfd_put_32 (abfd, BLR, p);
6547 savegpr1 (bfd *abfd, bfd_byte *p, int r)
6549 bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6554 savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
6556 p = savegpr1 (abfd, p, r);
6557 bfd_put_32 (abfd, BLR, p);
6562 restgpr1 (bfd *abfd, bfd_byte *p, int r)
6564 bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6569 restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
6571 p = restgpr1 (abfd, p, r);
6572 bfd_put_32 (abfd, BLR, p);
6577 savefpr (bfd *abfd, bfd_byte *p, int r)
6579 bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6584 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
6586 p = savefpr (abfd, p, r);
6587 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6589 bfd_put_32 (abfd, BLR, p);
6594 restfpr (bfd *abfd, bfd_byte *p, int r)
6596 bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6601 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
6603 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6605 p = restfpr (abfd, p, r);
6606 bfd_put_32 (abfd, MTLR_R0, p);
6610 p = restfpr (abfd, p, 30);
6611 p = restfpr (abfd, p, 31);
6613 bfd_put_32 (abfd, BLR, p);
6618 savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
6620 p = savefpr (abfd, p, r);
6621 bfd_put_32 (abfd, BLR, p);
6626 restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
6628 p = restfpr (abfd, p, r);
6629 bfd_put_32 (abfd, BLR, p);
6634 savevr (bfd *abfd, bfd_byte *p, int r)
6636 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6638 bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
6643 savevr_tail (bfd *abfd, bfd_byte *p, int r)
6645 p = savevr (abfd, p, r);
6646 bfd_put_32 (abfd, BLR, p);
6651 restvr (bfd *abfd, bfd_byte *p, int r)
6653 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6655 bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
6660 restvr_tail (bfd *abfd, bfd_byte *p, int r)
6662 p = restvr (abfd, p, r);
6663 bfd_put_32 (abfd, BLR, p);
6667 /* Called via elf_link_hash_traverse to transfer dynamic linking
6668 information on function code symbol entries to their corresponding
6669 function descriptor symbol entries. */
6672 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
6674 struct bfd_link_info *info;
6675 struct ppc_link_hash_table *htab;
6676 struct plt_entry *ent;
6677 struct ppc_link_hash_entry *fh;
6678 struct ppc_link_hash_entry *fdh;
6679 bfd_boolean force_local;
6681 fh = (struct ppc_link_hash_entry *) h;
6682 if (fh->elf.root.type == bfd_link_hash_indirect)
6686 htab = ppc_hash_table (info);
6690 /* Resolve undefined references to dot-symbols as the value
6691 in the function descriptor, if we have one in a regular object.
6692 This is to satisfy cases like ".quad .foo". Calls to functions
6693 in dynamic objects are handled elsewhere. */
6694 if (fh->elf.root.type == bfd_link_hash_undefweak
6695 && fh->was_undefined
6696 && (fdh = defined_func_desc (fh)) != NULL
6697 && get_opd_info (fdh->elf.root.u.def.section) != NULL
6698 && opd_entry_value (fdh->elf.root.u.def.section,
6699 fdh->elf.root.u.def.value,
6700 &fh->elf.root.u.def.section,
6701 &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
6703 fh->elf.root.type = fdh->elf.root.type;
6704 fh->elf.forced_local = 1;
6705 fh->elf.def_regular = fdh->elf.def_regular;
6706 fh->elf.def_dynamic = fdh->elf.def_dynamic;
6709 /* If this is a function code symbol, transfer dynamic linking
6710 information to the function descriptor symbol. */
6714 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
6715 if (ent->plt.refcount > 0)
6718 || fh->elf.root.root.string[0] != '.'
6719 || fh->elf.root.root.string[1] == '\0')
6722 /* Find the corresponding function descriptor symbol. Create it
6723 as undefined if necessary. */
6725 fdh = lookup_fdh (fh, htab);
6727 && !info->executable
6728 && (fh->elf.root.type == bfd_link_hash_undefined
6729 || fh->elf.root.type == bfd_link_hash_undefweak))
6731 fdh = make_fdh (info, fh);
6736 /* Fake function descriptors are made undefweak. If the function
6737 code symbol is strong undefined, make the fake sym the same.
6738 If the function code symbol is defined, then force the fake
6739 descriptor local; We can't support overriding of symbols in a
6740 shared library on a fake descriptor. */
6744 && fdh->elf.root.type == bfd_link_hash_undefweak)
6746 if (fh->elf.root.type == bfd_link_hash_undefined)
6748 fdh->elf.root.type = bfd_link_hash_undefined;
6749 bfd_link_add_undef (&htab->elf.root, &fdh->elf.root);
6751 else if (fh->elf.root.type == bfd_link_hash_defined
6752 || fh->elf.root.type == bfd_link_hash_defweak)
6754 _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
6759 && !fdh->elf.forced_local
6760 && (!info->executable
6761 || fdh->elf.def_dynamic
6762 || fdh->elf.ref_dynamic
6763 || (fdh->elf.root.type == bfd_link_hash_undefweak
6764 && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT)))
6766 if (fdh->elf.dynindx == -1)
6767 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
6769 fdh->elf.ref_regular |= fh->elf.ref_regular;
6770 fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
6771 fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
6772 fdh->elf.non_got_ref |= fh->elf.non_got_ref;
6773 if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT)
6775 move_plt_plist (fh, fdh);
6776 fdh->elf.needs_plt = 1;
6778 fdh->is_func_descriptor = 1;
6783 /* Now that the info is on the function descriptor, clear the
6784 function code sym info. Any function code syms for which we
6785 don't have a definition in a regular file, we force local.
6786 This prevents a shared library from exporting syms that have
6787 been imported from another library. Function code syms that
6788 are really in the library we must leave global to prevent the
6789 linker dragging in a definition from a static library. */
6790 force_local = (!fh->elf.def_regular
6792 || !fdh->elf.def_regular
6793 || fdh->elf.forced_local);
6794 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
6799 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6800 this hook to a) provide some gcc support functions, and b) transfer
6801 dynamic linking information gathered so far on function code symbol
6802 entries, to their corresponding function descriptor symbol entries. */
6805 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
6806 struct bfd_link_info *info)
6808 struct ppc_link_hash_table *htab;
6810 static const struct sfpr_def_parms funcs[] =
6812 { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
6813 { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
6814 { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
6815 { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
6816 { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
6817 { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
6818 { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
6819 { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
6820 { "._savef", 14, 31, savefpr, savefpr1_tail },
6821 { "._restf", 14, 31, restfpr, restfpr1_tail },
6822 { "_savevr_", 20, 31, savevr, savevr_tail },
6823 { "_restvr_", 20, 31, restvr, restvr_tail }
6826 htab = ppc_hash_table (info);
6830 if (!info->relocatable
6831 && htab->elf.hgot != NULL)
6832 _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
6834 if (htab->sfpr == NULL)
6835 /* We don't have any relocs. */
6838 /* Provide any missing _save* and _rest* functions. */
6839 htab->sfpr->size = 0;
6840 if (!info->relocatable)
6841 for (i = 0; i < sizeof (funcs) / sizeof (funcs[0]); i++)
6842 if (!sfpr_define (info, &funcs[i]))
6845 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
6847 if (htab->sfpr->size == 0)
6848 htab->sfpr->flags |= SEC_EXCLUDE;
6853 /* Adjust a symbol defined by a dynamic object and referenced by a
6854 regular object. The current definition is in some section of the
6855 dynamic object, but we're not including those sections. We have to
6856 change the definition to something the rest of the link can
6860 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
6861 struct elf_link_hash_entry *h)
6863 struct ppc_link_hash_table *htab;
6866 htab = ppc_hash_table (info);
6870 /* Deal with function syms. */
6871 if (h->type == STT_FUNC
6872 || h->type == STT_GNU_IFUNC
6875 /* Clear procedure linkage table information for any symbol that
6876 won't need a .plt entry. */
6877 struct plt_entry *ent;
6878 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
6879 if (ent->plt.refcount > 0)
6882 || (h->type != STT_GNU_IFUNC
6883 && (SYMBOL_CALLS_LOCAL (info, h)
6884 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6885 && h->root.type == bfd_link_hash_undefweak))))
6887 h->plt.plist = NULL;
6892 h->plt.plist = NULL;
6894 /* If this is a weak symbol, and there is a real definition, the
6895 processor independent code will have arranged for us to see the
6896 real definition first, and we can just use the same value. */
6897 if (h->u.weakdef != NULL)
6899 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6900 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6901 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6902 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6903 if (ELIMINATE_COPY_RELOCS)
6904 h->non_got_ref = h->u.weakdef->non_got_ref;
6908 /* If we are creating a shared library, we must presume that the
6909 only references to the symbol are via the global offset table.
6910 For such cases we need not do anything here; the relocations will
6911 be handled correctly by relocate_section. */
6915 /* If there are no references to this symbol that do not use the
6916 GOT, we don't need to generate a copy reloc. */
6917 if (!h->non_got_ref)
6920 /* Don't generate a copy reloc for symbols defined in the executable. */
6921 if (!h->def_dynamic || !h->ref_regular || h->def_regular)
6924 if (ELIMINATE_COPY_RELOCS)
6926 struct ppc_link_hash_entry * eh;
6927 struct elf_dyn_relocs *p;
6929 eh = (struct ppc_link_hash_entry *) h;
6930 for (p = eh->dyn_relocs; p != NULL; p = p->next)
6932 s = p->sec->output_section;
6933 if (s != NULL && (s->flags & SEC_READONLY) != 0)
6937 /* If we didn't find any dynamic relocs in read-only sections, then
6938 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6946 if (h->plt.plist != NULL)
6948 /* We should never get here, but unfortunately there are versions
6949 of gcc out there that improperly (for this ABI) put initialized
6950 function pointers, vtable refs and suchlike in read-only
6951 sections. Allow them to proceed, but warn that this might
6952 break at runtime. */
6953 info->callbacks->einfo
6954 (_("%P: copy reloc against `%T' requires lazy plt linking; "
6955 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6956 h->root.root.string);
6959 /* This is a reference to a symbol defined by a dynamic object which
6960 is not a function. */
6962 /* We must allocate the symbol in our .dynbss section, which will
6963 become part of the .bss section of the executable. There will be
6964 an entry for this symbol in the .dynsym section. The dynamic
6965 object will contain position independent code, so all references
6966 from the dynamic object to this symbol will go through the global
6967 offset table. The dynamic linker will use the .dynsym entry to
6968 determine the address it must put in the global offset table, so
6969 both the dynamic object and the regular object will refer to the
6970 same memory location for the variable. */
6972 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6973 to copy the initial value out of the dynamic object and into the
6974 runtime process image. We need to remember the offset into the
6975 .rela.bss section we are going to use. */
6976 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6978 htab->relbss->size += sizeof (Elf64_External_Rela);
6984 return _bfd_elf_adjust_dynamic_copy (h, s);
6987 /* If given a function descriptor symbol, hide both the function code
6988 sym and the descriptor. */
6990 ppc64_elf_hide_symbol (struct bfd_link_info *info,
6991 struct elf_link_hash_entry *h,
6992 bfd_boolean force_local)
6994 struct ppc_link_hash_entry *eh;
6995 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
6997 eh = (struct ppc_link_hash_entry *) h;
6998 if (eh->is_func_descriptor)
7000 struct ppc_link_hash_entry *fh = eh->oh;
7005 struct ppc_link_hash_table *htab;
7008 /* We aren't supposed to use alloca in BFD because on
7009 systems which do not have alloca the version in libiberty
7010 calls xmalloc, which might cause the program to crash
7011 when it runs out of memory. This function doesn't have a
7012 return status, so there's no way to gracefully return an
7013 error. So cheat. We know that string[-1] can be safely
7014 accessed; It's either a string in an ELF string table,
7015 or allocated in an objalloc structure. */
7017 p = eh->elf.root.root.string - 1;
7020 htab = ppc_hash_table (info);
7024 fh = (struct ppc_link_hash_entry *)
7025 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
7028 /* Unfortunately, if it so happens that the string we were
7029 looking for was allocated immediately before this string,
7030 then we overwrote the string terminator. That's the only
7031 reason the lookup should fail. */
7034 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
7035 while (q >= eh->elf.root.root.string && *q == *p)
7037 if (q < eh->elf.root.root.string && *p == '.')
7038 fh = (struct ppc_link_hash_entry *)
7039 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
7048 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
7053 get_sym_h (struct elf_link_hash_entry **hp,
7054 Elf_Internal_Sym **symp,
7056 unsigned char **tls_maskp,
7057 Elf_Internal_Sym **locsymsp,
7058 unsigned long r_symndx,
7061 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7063 if (r_symndx >= symtab_hdr->sh_info)
7065 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7066 struct elf_link_hash_entry *h;
7068 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7069 h = elf_follow_link (h);
7077 if (symsecp != NULL)
7079 asection *symsec = NULL;
7080 if (h->root.type == bfd_link_hash_defined
7081 || h->root.type == bfd_link_hash_defweak)
7082 symsec = h->root.u.def.section;
7086 if (tls_maskp != NULL)
7088 struct ppc_link_hash_entry *eh;
7090 eh = (struct ppc_link_hash_entry *) h;
7091 *tls_maskp = &eh->tls_mask;
7096 Elf_Internal_Sym *sym;
7097 Elf_Internal_Sym *locsyms = *locsymsp;
7099 if (locsyms == NULL)
7101 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
7102 if (locsyms == NULL)
7103 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
7104 symtab_hdr->sh_info,
7105 0, NULL, NULL, NULL);
7106 if (locsyms == NULL)
7108 *locsymsp = locsyms;
7110 sym = locsyms + r_symndx;
7118 if (symsecp != NULL)
7119 *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx);
7121 if (tls_maskp != NULL)
7123 struct got_entry **lgot_ents;
7124 unsigned char *tls_mask;
7127 lgot_ents = elf_local_got_ents (ibfd);
7128 if (lgot_ents != NULL)
7130 struct plt_entry **local_plt = (struct plt_entry **)
7131 (lgot_ents + symtab_hdr->sh_info);
7132 unsigned char *lgot_masks = (unsigned char *)
7133 (local_plt + symtab_hdr->sh_info);
7134 tls_mask = &lgot_masks[r_symndx];
7136 *tls_maskp = tls_mask;
7142 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7143 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7144 type suitable for optimization, and 1 otherwise. */
7147 get_tls_mask (unsigned char **tls_maskp,
7148 unsigned long *toc_symndx,
7149 bfd_vma *toc_addend,
7150 Elf_Internal_Sym **locsymsp,
7151 const Elf_Internal_Rela *rel,
7154 unsigned long r_symndx;
7156 struct elf_link_hash_entry *h;
7157 Elf_Internal_Sym *sym;
7161 r_symndx = ELF64_R_SYM (rel->r_info);
7162 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7165 if ((*tls_maskp != NULL && **tls_maskp != 0)
7167 || ppc64_elf_section_data (sec) == NULL
7168 || ppc64_elf_section_data (sec)->sec_type != sec_toc)
7171 /* Look inside a TOC section too. */
7174 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
7175 off = h->root.u.def.value;
7178 off = sym->st_value;
7179 off += rel->r_addend;
7180 BFD_ASSERT (off % 8 == 0);
7181 r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8];
7182 next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1];
7183 if (toc_symndx != NULL)
7184 *toc_symndx = r_symndx;
7185 if (toc_addend != NULL)
7186 *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8];
7187 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7189 if ((h == NULL || is_static_defined (h))
7190 && (next_r == -1 || next_r == -2))
7195 /* Find (or create) an entry in the tocsave hash table. */
7197 static struct tocsave_entry *
7198 tocsave_find (struct ppc_link_hash_table *htab,
7199 enum insert_option insert,
7200 Elf_Internal_Sym **local_syms,
7201 const Elf_Internal_Rela *irela,
7204 unsigned long r_indx;
7205 struct elf_link_hash_entry *h;
7206 Elf_Internal_Sym *sym;
7207 struct tocsave_entry ent, *p;
7209 struct tocsave_entry **slot;
7211 r_indx = ELF64_R_SYM (irela->r_info);
7212 if (!get_sym_h (&h, &sym, &ent.sec, NULL, local_syms, r_indx, ibfd))
7214 if (ent.sec == NULL || ent.sec->output_section == NULL)
7216 (*_bfd_error_handler)
7217 (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"));
7222 ent.offset = h->root.u.def.value;
7224 ent.offset = sym->st_value;
7225 ent.offset += irela->r_addend;
7227 hash = tocsave_htab_hash (&ent);
7228 slot = ((struct tocsave_entry **)
7229 htab_find_slot_with_hash (htab->tocsave_htab, &ent, hash, insert));
7235 p = (struct tocsave_entry *) bfd_alloc (ibfd, sizeof (*p));
7244 /* Adjust all global syms defined in opd sections. In gcc generated
7245 code for the old ABI, these will already have been done. */
7248 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
7250 struct ppc_link_hash_entry *eh;
7252 struct _opd_sec_data *opd;
7254 if (h->root.type == bfd_link_hash_indirect)
7257 if (h->root.type != bfd_link_hash_defined
7258 && h->root.type != bfd_link_hash_defweak)
7261 eh = (struct ppc_link_hash_entry *) h;
7262 if (eh->adjust_done)
7265 sym_sec = eh->elf.root.u.def.section;
7266 opd = get_opd_info (sym_sec);
7267 if (opd != NULL && opd->adjust != NULL)
7269 long adjust = opd->adjust[eh->elf.root.u.def.value / 8];
7272 /* This entry has been deleted. */
7273 asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
7276 for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
7277 if (discarded_section (dsec))
7279 ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
7283 eh->elf.root.u.def.value = 0;
7284 eh->elf.root.u.def.section = dsec;
7287 eh->elf.root.u.def.value += adjust;
7288 eh->adjust_done = 1;
7293 /* Handles decrementing dynamic reloc counts for the reloc specified by
7294 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7295 have already been determined. */
7298 dec_dynrel_count (bfd_vma r_info,
7300 struct bfd_link_info *info,
7301 Elf_Internal_Sym **local_syms,
7302 struct elf_link_hash_entry *h,
7303 Elf_Internal_Sym *sym)
7305 enum elf_ppc64_reloc_type r_type;
7306 asection *sym_sec = NULL;
7308 /* Can this reloc be dynamic? This switch, and later tests here
7309 should be kept in sync with the code in check_relocs. */
7310 r_type = ELF64_R_TYPE (r_info);
7316 case R_PPC64_TPREL16:
7317 case R_PPC64_TPREL16_LO:
7318 case R_PPC64_TPREL16_HI:
7319 case R_PPC64_TPREL16_HA:
7320 case R_PPC64_TPREL16_DS:
7321 case R_PPC64_TPREL16_LO_DS:
7322 case R_PPC64_TPREL16_HIGH:
7323 case R_PPC64_TPREL16_HIGHA:
7324 case R_PPC64_TPREL16_HIGHER:
7325 case R_PPC64_TPREL16_HIGHERA:
7326 case R_PPC64_TPREL16_HIGHEST:
7327 case R_PPC64_TPREL16_HIGHESTA:
7331 case R_PPC64_TPREL64:
7332 case R_PPC64_DTPMOD64:
7333 case R_PPC64_DTPREL64:
7334 case R_PPC64_ADDR64:
7338 case R_PPC64_ADDR14:
7339 case R_PPC64_ADDR14_BRNTAKEN:
7340 case R_PPC64_ADDR14_BRTAKEN:
7341 case R_PPC64_ADDR16:
7342 case R_PPC64_ADDR16_DS:
7343 case R_PPC64_ADDR16_HA:
7344 case R_PPC64_ADDR16_HI:
7345 case R_PPC64_ADDR16_HIGH:
7346 case R_PPC64_ADDR16_HIGHA:
7347 case R_PPC64_ADDR16_HIGHER:
7348 case R_PPC64_ADDR16_HIGHERA:
7349 case R_PPC64_ADDR16_HIGHEST:
7350 case R_PPC64_ADDR16_HIGHESTA:
7351 case R_PPC64_ADDR16_LO:
7352 case R_PPC64_ADDR16_LO_DS:
7353 case R_PPC64_ADDR24:
7354 case R_PPC64_ADDR32:
7355 case R_PPC64_UADDR16:
7356 case R_PPC64_UADDR32:
7357 case R_PPC64_UADDR64:
7362 if (local_syms != NULL)
7364 unsigned long r_symndx;
7365 bfd *ibfd = sec->owner;
7367 r_symndx = ELF64_R_SYM (r_info);
7368 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
7373 && (must_be_dyn_reloc (info, r_type)
7375 && (!SYMBOLIC_BIND (info, h)
7376 || h->root.type == bfd_link_hash_defweak
7377 || !h->def_regular))))
7378 || (ELIMINATE_COPY_RELOCS
7381 && (h->root.type == bfd_link_hash_defweak
7382 || !h->def_regular)))
7389 struct elf_dyn_relocs *p;
7390 struct elf_dyn_relocs **pp;
7391 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
7393 /* elf_gc_sweep may have already removed all dyn relocs associated
7394 with local syms for a given section. Also, symbol flags are
7395 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7396 report a dynreloc miscount. */
7397 if (*pp == NULL && info->gc_sections)
7400 while ((p = *pp) != NULL)
7404 if (!must_be_dyn_reloc (info, r_type))
7416 struct ppc_dyn_relocs *p;
7417 struct ppc_dyn_relocs **pp;
7419 bfd_boolean is_ifunc;
7421 if (local_syms == NULL)
7422 sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
7423 if (sym_sec == NULL)
7426 vpp = &elf_section_data (sym_sec)->local_dynrel;
7427 pp = (struct ppc_dyn_relocs **) vpp;
7429 if (*pp == NULL && info->gc_sections)
7432 is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
7433 while ((p = *pp) != NULL)
7435 if (p->sec == sec && p->ifunc == is_ifunc)
7446 info->callbacks->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
7448 bfd_set_error (bfd_error_bad_value);
7452 /* Remove unused Official Procedure Descriptor entries. Currently we
7453 only remove those associated with functions in discarded link-once
7454 sections, or weakly defined functions that have been overridden. It
7455 would be possible to remove many more entries for statically linked
7459 ppc64_elf_edit_opd (struct bfd_link_info *info, bfd_boolean non_overlapping)
7462 bfd_boolean some_edited = FALSE;
7463 asection *need_pad = NULL;
7465 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7468 Elf_Internal_Rela *relstart, *rel, *relend;
7469 Elf_Internal_Shdr *symtab_hdr;
7470 Elf_Internal_Sym *local_syms;
7472 struct _opd_sec_data *opd;
7473 bfd_boolean need_edit, add_aux_fields;
7474 bfd_size_type cnt_16b = 0;
7476 if (!is_ppc64_elf (ibfd))
7479 sec = bfd_get_section_by_name (ibfd, ".opd");
7480 if (sec == NULL || sec->size == 0)
7483 if (sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
7486 if (sec->output_section == bfd_abs_section_ptr)
7489 /* Look through the section relocs. */
7490 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
7494 symtab_hdr = &elf_symtab_hdr (ibfd);
7496 /* Read the relocations. */
7497 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
7499 if (relstart == NULL)
7502 /* First run through the relocs to check they are sane, and to
7503 determine whether we need to edit this opd section. */
7507 relend = relstart + sec->reloc_count;
7508 for (rel = relstart; rel < relend; )
7510 enum elf_ppc64_reloc_type r_type;
7511 unsigned long r_symndx;
7513 struct elf_link_hash_entry *h;
7514 Elf_Internal_Sym *sym;
7516 /* .opd contains a regular array of 16 or 24 byte entries. We're
7517 only interested in the reloc pointing to a function entry
7519 if (rel->r_offset != offset
7520 || rel + 1 >= relend
7521 || (rel + 1)->r_offset != offset + 8)
7523 /* If someone messes with .opd alignment then after a
7524 "ld -r" we might have padding in the middle of .opd.
7525 Also, there's nothing to prevent someone putting
7526 something silly in .opd with the assembler. No .opd
7527 optimization for them! */
7529 (*_bfd_error_handler)
7530 (_("%B: .opd is not a regular array of opd entries"), ibfd);
7535 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
7536 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
7538 (*_bfd_error_handler)
7539 (_("%B: unexpected reloc type %u in .opd section"),
7545 r_symndx = ELF64_R_SYM (rel->r_info);
7546 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7550 if (sym_sec == NULL || sym_sec->owner == NULL)
7552 const char *sym_name;
7554 sym_name = h->root.root.string;
7556 sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
7559 (*_bfd_error_handler)
7560 (_("%B: undefined sym `%s' in .opd section"),
7566 /* opd entries are always for functions defined in the
7567 current input bfd. If the symbol isn't defined in the
7568 input bfd, then we won't be using the function in this
7569 bfd; It must be defined in a linkonce section in another
7570 bfd, or is weak. It's also possible that we are
7571 discarding the function due to a linker script /DISCARD/,
7572 which we test for via the output_section. */
7573 if (sym_sec->owner != ibfd
7574 || sym_sec->output_section == bfd_abs_section_ptr)
7579 || (rel + 1 == relend && rel->r_offset == offset + 16))
7581 if (sec->size == offset + 24)
7586 if (rel == relend && sec->size == offset + 16)
7594 if (rel->r_offset == offset + 24)
7596 else if (rel->r_offset != offset + 16)
7598 else if (rel + 1 < relend
7599 && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
7600 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
7605 else if (rel + 2 < relend
7606 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_ADDR64
7607 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC)
7616 add_aux_fields = non_overlapping && cnt_16b > 0;
7618 if (need_edit || add_aux_fields)
7620 Elf_Internal_Rela *write_rel;
7621 Elf_Internal_Shdr *rel_hdr;
7622 bfd_byte *rptr, *wptr;
7623 bfd_byte *new_contents;
7628 new_contents = NULL;
7629 amt = sec->size * sizeof (long) / 8;
7630 opd = &ppc64_elf_section_data (sec)->u.opd;
7631 opd->adjust = bfd_zalloc (sec->owner, amt);
7632 if (opd->adjust == NULL)
7634 ppc64_elf_section_data (sec)->sec_type = sec_opd;
7636 /* This seems a waste of time as input .opd sections are all
7637 zeros as generated by gcc, but I suppose there's no reason
7638 this will always be so. We might start putting something in
7639 the third word of .opd entries. */
7640 if ((sec->flags & SEC_IN_MEMORY) == 0)
7643 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
7648 if (local_syms != NULL
7649 && symtab_hdr->contents != (unsigned char *) local_syms)
7651 if (elf_section_data (sec)->relocs != relstart)
7655 sec->contents = loc;
7656 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
7659 elf_section_data (sec)->relocs = relstart;
7661 new_contents = sec->contents;
7664 new_contents = bfd_malloc (sec->size + cnt_16b * 8);
7665 if (new_contents == NULL)
7669 wptr = new_contents;
7670 rptr = sec->contents;
7672 write_rel = relstart;
7676 for (rel = relstart; rel < relend; rel++)
7678 unsigned long r_symndx;
7680 struct elf_link_hash_entry *h;
7681 Elf_Internal_Sym *sym;
7683 r_symndx = ELF64_R_SYM (rel->r_info);
7684 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7688 if (rel->r_offset == offset)
7690 struct ppc_link_hash_entry *fdh = NULL;
7692 /* See if the .opd entry is full 24 byte or
7693 16 byte (with fd_aux entry overlapped with next
7696 if ((rel + 2 == relend && sec->size == offset + 16)
7697 || (rel + 3 < relend
7698 && rel[2].r_offset == offset + 16
7699 && rel[3].r_offset == offset + 24
7700 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_ADDR64
7701 && ELF64_R_TYPE (rel[3].r_info) == R_PPC64_TOC))
7705 && h->root.root.string[0] == '.')
7707 struct ppc_link_hash_table *htab;
7709 htab = ppc_hash_table (info);
7711 fdh = lookup_fdh ((struct ppc_link_hash_entry *) h,
7714 && fdh->elf.root.type != bfd_link_hash_defined
7715 && fdh->elf.root.type != bfd_link_hash_defweak)
7719 skip = (sym_sec->owner != ibfd
7720 || sym_sec->output_section == bfd_abs_section_ptr);
7723 if (fdh != NULL && sym_sec->owner == ibfd)
7725 /* Arrange for the function descriptor sym
7727 fdh->elf.root.u.def.value = 0;
7728 fdh->elf.root.u.def.section = sym_sec;
7730 opd->adjust[rel->r_offset / 8] = -1;
7734 /* We'll be keeping this opd entry. */
7738 /* Redefine the function descriptor symbol to
7739 this location in the opd section. It is
7740 necessary to update the value here rather
7741 than using an array of adjustments as we do
7742 for local symbols, because various places
7743 in the generic ELF code use the value
7744 stored in u.def.value. */
7745 fdh->elf.root.u.def.value = wptr - new_contents;
7746 fdh->adjust_done = 1;
7749 /* Local syms are a bit tricky. We could
7750 tweak them as they can be cached, but
7751 we'd need to look through the local syms
7752 for the function descriptor sym which we
7753 don't have at the moment. So keep an
7754 array of adjustments. */
7755 opd->adjust[rel->r_offset / 8]
7756 = (wptr - new_contents) - (rptr - sec->contents);
7759 memcpy (wptr, rptr, opd_ent_size);
7760 wptr += opd_ent_size;
7761 if (add_aux_fields && opd_ent_size == 16)
7763 memset (wptr, '\0', 8);
7767 rptr += opd_ent_size;
7768 offset += opd_ent_size;
7774 && !info->relocatable
7775 && !dec_dynrel_count (rel->r_info, sec, info,
7781 /* We need to adjust any reloc offsets to point to the
7782 new opd entries. While we're at it, we may as well
7783 remove redundant relocs. */
7784 rel->r_offset += opd->adjust[(offset - opd_ent_size) / 8];
7785 if (write_rel != rel)
7786 memcpy (write_rel, rel, sizeof (*rel));
7791 sec->size = wptr - new_contents;
7792 sec->reloc_count = write_rel - relstart;
7795 free (sec->contents);
7796 sec->contents = new_contents;
7799 /* Fudge the header size too, as this is used later in
7800 elf_bfd_final_link if we are emitting relocs. */
7801 rel_hdr = _bfd_elf_single_rel_hdr (sec);
7802 rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
7805 else if (elf_section_data (sec)->relocs != relstart)
7808 if (local_syms != NULL
7809 && symtab_hdr->contents != (unsigned char *) local_syms)
7811 if (!info->keep_memory)
7814 symtab_hdr->contents = (unsigned char *) local_syms;
7819 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
7821 /* If we are doing a final link and the last .opd entry is just 16 byte
7822 long, add a 8 byte padding after it. */
7823 if (need_pad != NULL && !info->relocatable)
7827 if ((need_pad->flags & SEC_IN_MEMORY) == 0)
7829 BFD_ASSERT (need_pad->size > 0);
7831 p = bfd_malloc (need_pad->size + 8);
7835 if (! bfd_get_section_contents (need_pad->owner, need_pad,
7836 p, 0, need_pad->size))
7839 need_pad->contents = p;
7840 need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
7844 p = bfd_realloc (need_pad->contents, need_pad->size + 8);
7848 need_pad->contents = p;
7851 memset (need_pad->contents + need_pad->size, 0, 8);
7852 need_pad->size += 8;
7858 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7861 ppc64_elf_tls_setup (struct bfd_link_info *info,
7862 int no_tls_get_addr_opt,
7865 struct ppc_link_hash_table *htab;
7867 htab = ppc_hash_table (info);
7871 if (abiversion (info->output_bfd) == 1)
7875 htab->do_multi_toc = 0;
7876 else if (!htab->do_multi_toc)
7879 htab->tls_get_addr = ((struct ppc_link_hash_entry *)
7880 elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
7881 FALSE, FALSE, TRUE));
7882 /* Move dynamic linking info to the function descriptor sym. */
7883 if (htab->tls_get_addr != NULL)
7884 func_desc_adjust (&htab->tls_get_addr->elf, info);
7885 htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
7886 elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
7887 FALSE, FALSE, TRUE));
7888 if (!no_tls_get_addr_opt)
7890 struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
7892 opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
7893 FALSE, FALSE, TRUE);
7895 func_desc_adjust (opt, info);
7896 opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
7897 FALSE, FALSE, TRUE);
7899 && (opt_fd->root.type == bfd_link_hash_defined
7900 || opt_fd->root.type == bfd_link_hash_defweak))
7902 /* If glibc supports an optimized __tls_get_addr call stub,
7903 signalled by the presence of __tls_get_addr_opt, and we'll
7904 be calling __tls_get_addr via a plt call stub, then
7905 make __tls_get_addr point to __tls_get_addr_opt. */
7906 tga_fd = &htab->tls_get_addr_fd->elf;
7907 if (htab->elf.dynamic_sections_created
7909 && (tga_fd->type == STT_FUNC
7910 || tga_fd->needs_plt)
7911 && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
7912 || (ELF_ST_VISIBILITY (tga_fd->other) != STV_DEFAULT
7913 && tga_fd->root.type == bfd_link_hash_undefweak)))
7915 struct plt_entry *ent;
7917 for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
7918 if (ent->plt.refcount > 0)
7922 tga_fd->root.type = bfd_link_hash_indirect;
7923 tga_fd->root.u.i.link = &opt_fd->root;
7924 ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
7925 if (opt_fd->dynindx != -1)
7927 /* Use __tls_get_addr_opt in dynamic relocations. */
7928 opt_fd->dynindx = -1;
7929 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
7930 opt_fd->dynstr_index);
7931 if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
7934 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
7935 tga = &htab->tls_get_addr->elf;
7936 if (opt != NULL && tga != NULL)
7938 tga->root.type = bfd_link_hash_indirect;
7939 tga->root.u.i.link = &opt->root;
7940 ppc64_elf_copy_indirect_symbol (info, opt, tga);
7941 _bfd_elf_link_hash_hide_symbol (info, opt,
7943 htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
7945 htab->tls_get_addr_fd->oh = htab->tls_get_addr;
7946 htab->tls_get_addr_fd->is_func_descriptor = 1;
7947 if (htab->tls_get_addr != NULL)
7949 htab->tls_get_addr->oh = htab->tls_get_addr_fd;
7950 htab->tls_get_addr->is_func = 1;
7956 no_tls_get_addr_opt = TRUE;
7958 htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
7959 return _bfd_elf_tls_setup (info->output_bfd, info);
7962 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7966 branch_reloc_hash_match (const bfd *ibfd,
7967 const Elf_Internal_Rela *rel,
7968 const struct ppc_link_hash_entry *hash1,
7969 const struct ppc_link_hash_entry *hash2)
7971 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7972 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
7973 unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
7975 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
7977 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7978 struct elf_link_hash_entry *h;
7980 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7981 h = elf_follow_link (h);
7982 if (h == &hash1->elf || h == &hash2->elf)
7988 /* Run through all the TLS relocs looking for optimization
7989 opportunities. The linker has been hacked (see ppc64elf.em) to do
7990 a preliminary section layout so that we know the TLS segment
7991 offsets. We can't optimize earlier because some optimizations need
7992 to know the tp offset, and we need to optimize before allocating
7993 dynamic relocations. */
7996 ppc64_elf_tls_optimize (struct bfd_link_info *info)
8000 struct ppc_link_hash_table *htab;
8001 unsigned char *toc_ref;
8004 if (info->relocatable || !info->executable)
8007 htab = ppc_hash_table (info);
8011 /* Make two passes over the relocs. On the first pass, mark toc
8012 entries involved with tls relocs, and check that tls relocs
8013 involved in setting up a tls_get_addr call are indeed followed by
8014 such a call. If they are not, we can't do any tls optimization.
8015 On the second pass twiddle tls_mask flags to notify
8016 relocate_section that optimization can be done, and adjust got
8017 and plt refcounts. */
8019 for (pass = 0; pass < 2; ++pass)
8020 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8022 Elf_Internal_Sym *locsyms = NULL;
8023 asection *toc = bfd_get_section_by_name (ibfd, ".toc");
8025 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8026 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
8028 Elf_Internal_Rela *relstart, *rel, *relend;
8029 bfd_boolean found_tls_get_addr_arg = 0;
8031 /* Read the relocations. */
8032 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8034 if (relstart == NULL)
8037 relend = relstart + sec->reloc_count;
8038 for (rel = relstart; rel < relend; rel++)
8040 enum elf_ppc64_reloc_type r_type;
8041 unsigned long r_symndx;
8042 struct elf_link_hash_entry *h;
8043 Elf_Internal_Sym *sym;
8045 unsigned char *tls_mask;
8046 unsigned char tls_set, tls_clear, tls_type = 0;
8048 bfd_boolean ok_tprel, is_local;
8049 long toc_ref_index = 0;
8050 int expecting_tls_get_addr = 0;
8051 bfd_boolean ret = FALSE;
8053 r_symndx = ELF64_R_SYM (rel->r_info);
8054 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
8058 if (elf_section_data (sec)->relocs != relstart)
8060 if (toc_ref != NULL)
8063 && (elf_symtab_hdr (ibfd).contents
8064 != (unsigned char *) locsyms))
8071 if (h->root.type == bfd_link_hash_defined
8072 || h->root.type == bfd_link_hash_defweak)
8073 value = h->root.u.def.value;
8074 else if (h->root.type == bfd_link_hash_undefweak)
8078 found_tls_get_addr_arg = 0;
8083 /* Symbols referenced by TLS relocs must be of type
8084 STT_TLS. So no need for .opd local sym adjust. */
8085 value = sym->st_value;
8094 && h->root.type == bfd_link_hash_undefweak)
8098 value += sym_sec->output_offset;
8099 value += sym_sec->output_section->vma;
8100 value -= htab->elf.tls_sec->vma;
8101 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
8102 < (bfd_vma) 1 << 32);
8106 r_type = ELF64_R_TYPE (rel->r_info);
8107 /* If this section has old-style __tls_get_addr calls
8108 without marker relocs, then check that each
8109 __tls_get_addr call reloc is preceded by a reloc
8110 that conceivably belongs to the __tls_get_addr arg
8111 setup insn. If we don't find matching arg setup
8112 relocs, don't do any tls optimization. */
8114 && sec->has_tls_get_addr_call
8116 && (h == &htab->tls_get_addr->elf
8117 || h == &htab->tls_get_addr_fd->elf)
8118 && !found_tls_get_addr_arg
8119 && is_branch_reloc (r_type))
8121 info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
8122 "TLS optimization disabled\n"),
8123 ibfd, sec, rel->r_offset);
8128 found_tls_get_addr_arg = 0;
8131 case R_PPC64_GOT_TLSLD16:
8132 case R_PPC64_GOT_TLSLD16_LO:
8133 expecting_tls_get_addr = 1;
8134 found_tls_get_addr_arg = 1;
8137 case R_PPC64_GOT_TLSLD16_HI:
8138 case R_PPC64_GOT_TLSLD16_HA:
8139 /* These relocs should never be against a symbol
8140 defined in a shared lib. Leave them alone if
8141 that turns out to be the case. */
8148 tls_type = TLS_TLS | TLS_LD;
8151 case R_PPC64_GOT_TLSGD16:
8152 case R_PPC64_GOT_TLSGD16_LO:
8153 expecting_tls_get_addr = 1;
8154 found_tls_get_addr_arg = 1;
8157 case R_PPC64_GOT_TLSGD16_HI:
8158 case R_PPC64_GOT_TLSGD16_HA:
8164 tls_set = TLS_TLS | TLS_TPRELGD;
8166 tls_type = TLS_TLS | TLS_GD;
8169 case R_PPC64_GOT_TPREL16_DS:
8170 case R_PPC64_GOT_TPREL16_LO_DS:
8171 case R_PPC64_GOT_TPREL16_HI:
8172 case R_PPC64_GOT_TPREL16_HA:
8177 tls_clear = TLS_TPREL;
8178 tls_type = TLS_TLS | TLS_TPREL;
8185 found_tls_get_addr_arg = 1;
8190 case R_PPC64_TOC16_LO:
8191 if (sym_sec == NULL || sym_sec != toc)
8194 /* Mark this toc entry as referenced by a TLS
8195 code sequence. We can do that now in the
8196 case of R_PPC64_TLS, and after checking for
8197 tls_get_addr for the TOC16 relocs. */
8198 if (toc_ref == NULL)
8199 toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
8200 if (toc_ref == NULL)
8204 value = h->root.u.def.value;
8206 value = sym->st_value;
8207 value += rel->r_addend;
8208 BFD_ASSERT (value < toc->size && value % 8 == 0);
8209 toc_ref_index = (value + toc->output_offset) / 8;
8210 if (r_type == R_PPC64_TLS
8211 || r_type == R_PPC64_TLSGD
8212 || r_type == R_PPC64_TLSLD)
8214 toc_ref[toc_ref_index] = 1;
8218 if (pass != 0 && toc_ref[toc_ref_index] == 0)
8223 expecting_tls_get_addr = 2;
8226 case R_PPC64_TPREL64:
8230 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8235 tls_set = TLS_EXPLICIT;
8236 tls_clear = TLS_TPREL;
8241 case R_PPC64_DTPMOD64:
8245 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8247 if (rel + 1 < relend
8249 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
8250 && rel[1].r_offset == rel->r_offset + 8)
8254 tls_set = TLS_EXPLICIT | TLS_GD;
8257 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
8266 tls_set = TLS_EXPLICIT;
8277 if (!expecting_tls_get_addr
8278 || !sec->has_tls_get_addr_call)
8281 if (rel + 1 < relend
8282 && branch_reloc_hash_match (ibfd, rel + 1,
8284 htab->tls_get_addr_fd))
8286 if (expecting_tls_get_addr == 2)
8288 /* Check for toc tls entries. */
8289 unsigned char *toc_tls;
8292 retval = get_tls_mask (&toc_tls, NULL, NULL,
8297 if (toc_tls != NULL)
8299 if ((*toc_tls & (TLS_GD | TLS_LD)) != 0)
8300 found_tls_get_addr_arg = 1;
8302 toc_ref[toc_ref_index] = 1;
8308 if (expecting_tls_get_addr != 1)
8311 /* Uh oh, we didn't find the expected call. We
8312 could just mark this symbol to exclude it
8313 from tls optimization but it's safer to skip
8314 the entire optimization. */
8315 info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
8316 "TLS optimization disabled\n"),
8317 ibfd, sec, rel->r_offset);
8322 if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
8324 struct plt_entry *ent;
8325 for (ent = htab->tls_get_addr->elf.plt.plist;
8328 if (ent->addend == 0)
8330 if (ent->plt.refcount > 0)
8332 ent->plt.refcount -= 1;
8333 expecting_tls_get_addr = 0;
8339 if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
8341 struct plt_entry *ent;
8342 for (ent = htab->tls_get_addr_fd->elf.plt.plist;
8345 if (ent->addend == 0)
8347 if (ent->plt.refcount > 0)
8348 ent->plt.refcount -= 1;
8356 if ((tls_set & TLS_EXPLICIT) == 0)
8358 struct got_entry *ent;
8360 /* Adjust got entry for this reloc. */
8364 ent = elf_local_got_ents (ibfd)[r_symndx];
8366 for (; ent != NULL; ent = ent->next)
8367 if (ent->addend == rel->r_addend
8368 && ent->owner == ibfd
8369 && ent->tls_type == tls_type)
8376 /* We managed to get rid of a got entry. */
8377 if (ent->got.refcount > 0)
8378 ent->got.refcount -= 1;
8383 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8384 we'll lose one or two dyn relocs. */
8385 if (!dec_dynrel_count (rel->r_info, sec, info,
8389 if (tls_set == (TLS_EXPLICIT | TLS_GD))
8391 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
8397 *tls_mask |= tls_set;
8398 *tls_mask &= ~tls_clear;
8401 if (elf_section_data (sec)->relocs != relstart)
8406 && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
8408 if (!info->keep_memory)
8411 elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
8415 if (toc_ref != NULL)
8420 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8421 the values of any global symbols in a toc section that has been
8422 edited. Globals in toc sections should be a rarity, so this function
8423 sets a flag if any are found in toc sections other than the one just
8424 edited, so that futher hash table traversals can be avoided. */
8426 struct adjust_toc_info
8429 unsigned long *skip;
8430 bfd_boolean global_toc_syms;
8433 enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
8436 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
8438 struct ppc_link_hash_entry *eh;
8439 struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
8442 if (h->root.type != bfd_link_hash_defined
8443 && h->root.type != bfd_link_hash_defweak)
8446 eh = (struct ppc_link_hash_entry *) h;
8447 if (eh->adjust_done)
8450 if (eh->elf.root.u.def.section == toc_inf->toc)
8452 if (eh->elf.root.u.def.value > toc_inf->toc->rawsize)
8453 i = toc_inf->toc->rawsize >> 3;
8455 i = eh->elf.root.u.def.value >> 3;
8457 if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0)
8459 (*_bfd_error_handler)
8460 (_("%s defined on removed toc entry"), eh->elf.root.root.string);
8463 while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0);
8464 eh->elf.root.u.def.value = (bfd_vma) i << 3;
8467 eh->elf.root.u.def.value -= toc_inf->skip[i];
8468 eh->adjust_done = 1;
8470 else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
8471 toc_inf->global_toc_syms = TRUE;
8476 /* Return TRUE iff INSN is one we expect on a _LO variety toc/got reloc. */
8479 ok_lo_toc_insn (unsigned int insn)
8481 return ((insn & (0x3f << 26)) == 14u << 26 /* addi */
8482 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
8483 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
8484 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
8485 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
8486 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
8487 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
8488 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
8489 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
8490 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
8491 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
8492 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
8493 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
8494 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
8495 || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
8497 || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
8498 && ((insn & 3) == 0 || (insn & 3) == 3))
8499 || (insn & (0x3f << 26)) == 12u << 26 /* addic */);
8502 /* Examine all relocs referencing .toc sections in order to remove
8503 unused .toc entries. */
8506 ppc64_elf_edit_toc (struct bfd_link_info *info)
8509 struct adjust_toc_info toc_inf;
8510 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8512 htab->do_toc_opt = 1;
8513 toc_inf.global_toc_syms = TRUE;
8514 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8516 asection *toc, *sec;
8517 Elf_Internal_Shdr *symtab_hdr;
8518 Elf_Internal_Sym *local_syms;
8519 Elf_Internal_Rela *relstart, *rel, *toc_relocs;
8520 unsigned long *skip, *drop;
8521 unsigned char *used;
8522 unsigned char *keep, last, some_unused;
8524 if (!is_ppc64_elf (ibfd))
8527 toc = bfd_get_section_by_name (ibfd, ".toc");
8530 || toc->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
8531 || discarded_section (toc))
8536 symtab_hdr = &elf_symtab_hdr (ibfd);
8538 /* Look at sections dropped from the final link. */
8541 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8543 if (sec->reloc_count == 0
8544 || !discarded_section (sec)
8545 || get_opd_info (sec)
8546 || (sec->flags & SEC_ALLOC) == 0
8547 || (sec->flags & SEC_DEBUGGING) != 0)
8550 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
8551 if (relstart == NULL)
8554 /* Run through the relocs to see which toc entries might be
8556 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8558 enum elf_ppc64_reloc_type r_type;
8559 unsigned long r_symndx;
8561 struct elf_link_hash_entry *h;
8562 Elf_Internal_Sym *sym;
8565 r_type = ELF64_R_TYPE (rel->r_info);
8572 case R_PPC64_TOC16_LO:
8573 case R_PPC64_TOC16_HI:
8574 case R_PPC64_TOC16_HA:
8575 case R_PPC64_TOC16_DS:
8576 case R_PPC64_TOC16_LO_DS:
8580 r_symndx = ELF64_R_SYM (rel->r_info);
8581 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8589 val = h->root.u.def.value;
8591 val = sym->st_value;
8592 val += rel->r_addend;
8594 if (val >= toc->size)
8597 /* Anything in the toc ought to be aligned to 8 bytes.
8598 If not, don't mark as unused. */
8604 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
8609 skip[val >> 3] = ref_from_discarded;
8612 if (elf_section_data (sec)->relocs != relstart)
8616 /* For largetoc loads of address constants, we can convert
8617 . addis rx,2,addr@got@ha
8618 . ld ry,addr@got@l(rx)
8620 . addis rx,2,addr@toc@ha
8621 . addi ry,rx,addr@toc@l
8622 when addr is within 2G of the toc pointer. This then means
8623 that the word storing "addr" in the toc is no longer needed. */
8625 if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc
8626 && toc->output_section->rawsize < (bfd_vma) 1 << 31
8627 && toc->reloc_count != 0)
8629 /* Read toc relocs. */
8630 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
8632 if (toc_relocs == NULL)
8635 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
8637 enum elf_ppc64_reloc_type r_type;
8638 unsigned long r_symndx;
8640 struct elf_link_hash_entry *h;
8641 Elf_Internal_Sym *sym;
8644 r_type = ELF64_R_TYPE (rel->r_info);
8645 if (r_type != R_PPC64_ADDR64)
8648 r_symndx = ELF64_R_SYM (rel->r_info);
8649 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8654 || discarded_section (sym_sec))
8657 if (!SYMBOL_CALLS_LOCAL (info, h))
8662 if (h->type == STT_GNU_IFUNC)
8664 val = h->root.u.def.value;
8668 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
8670 val = sym->st_value;
8672 val += rel->r_addend;
8673 val += sym_sec->output_section->vma + sym_sec->output_offset;
8675 /* We don't yet know the exact toc pointer value, but we
8676 know it will be somewhere in the toc section. Don't
8677 optimize if the difference from any possible toc
8678 pointer is outside [ff..f80008000, 7fff7fff]. */
8679 addr = toc->output_section->vma + TOC_BASE_OFF;
8680 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
8683 addr = toc->output_section->vma + toc->output_section->rawsize;
8684 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
8689 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
8694 skip[rel->r_offset >> 3]
8695 |= can_optimize | ((rel - toc_relocs) << 2);
8702 used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
8706 if (local_syms != NULL
8707 && symtab_hdr->contents != (unsigned char *) local_syms)
8711 && elf_section_data (sec)->relocs != relstart)
8713 if (toc_relocs != NULL
8714 && elf_section_data (toc)->relocs != toc_relocs)
8721 /* Now check all kept sections that might reference the toc.
8722 Check the toc itself last. */
8723 for (sec = (ibfd->sections == toc && toc->next ? toc->next
8726 sec = (sec == toc ? NULL
8727 : sec->next == NULL ? toc
8728 : sec->next == toc && toc->next ? toc->next
8733 if (sec->reloc_count == 0
8734 || discarded_section (sec)
8735 || get_opd_info (sec)
8736 || (sec->flags & SEC_ALLOC) == 0
8737 || (sec->flags & SEC_DEBUGGING) != 0)
8740 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8742 if (relstart == NULL)
8745 /* Mark toc entries referenced as used. */
8749 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8751 enum elf_ppc64_reloc_type r_type;
8752 unsigned long r_symndx;
8754 struct elf_link_hash_entry *h;
8755 Elf_Internal_Sym *sym;
8757 enum {no_check, check_lo, check_ha} insn_check;
8759 r_type = ELF64_R_TYPE (rel->r_info);
8763 insn_check = no_check;
8766 case R_PPC64_GOT_TLSLD16_HA:
8767 case R_PPC64_GOT_TLSGD16_HA:
8768 case R_PPC64_GOT_TPREL16_HA:
8769 case R_PPC64_GOT_DTPREL16_HA:
8770 case R_PPC64_GOT16_HA:
8771 case R_PPC64_TOC16_HA:
8772 insn_check = check_ha;
8775 case R_PPC64_GOT_TLSLD16_LO:
8776 case R_PPC64_GOT_TLSGD16_LO:
8777 case R_PPC64_GOT_TPREL16_LO_DS:
8778 case R_PPC64_GOT_DTPREL16_LO_DS:
8779 case R_PPC64_GOT16_LO:
8780 case R_PPC64_GOT16_LO_DS:
8781 case R_PPC64_TOC16_LO:
8782 case R_PPC64_TOC16_LO_DS:
8783 insn_check = check_lo;
8787 if (insn_check != no_check)
8789 bfd_vma off = rel->r_offset & ~3;
8790 unsigned char buf[4];
8793 if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
8798 insn = bfd_get_32 (ibfd, buf);
8799 if (insn_check == check_lo
8800 ? !ok_lo_toc_insn (insn)
8801 : ((insn & ((0x3f << 26) | 0x1f << 16))
8802 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8806 ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
8807 sprintf (str, "%#08x", insn);
8808 info->callbacks->einfo
8809 (_("%P: %H: toc optimization is not supported for"
8810 " %s instruction.\n"),
8811 ibfd, sec, rel->r_offset & ~3, str);
8818 case R_PPC64_TOC16_LO:
8819 case R_PPC64_TOC16_HI:
8820 case R_PPC64_TOC16_HA:
8821 case R_PPC64_TOC16_DS:
8822 case R_PPC64_TOC16_LO_DS:
8823 /* In case we're taking addresses of toc entries. */
8824 case R_PPC64_ADDR64:
8831 r_symndx = ELF64_R_SYM (rel->r_info);
8832 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8843 val = h->root.u.def.value;
8845 val = sym->st_value;
8846 val += rel->r_addend;
8848 if (val >= toc->size)
8851 if ((skip[val >> 3] & can_optimize) != 0)
8858 case R_PPC64_TOC16_HA:
8861 case R_PPC64_TOC16_LO_DS:
8862 off = rel->r_offset;
8863 off += (bfd_big_endian (ibfd) ? -2 : 3);
8864 if (!bfd_get_section_contents (ibfd, sec, &opc,
8870 if ((opc & (0x3f << 2)) == (58u << 2))
8875 /* Wrong sort of reloc, or not a ld. We may
8876 as well clear ref_from_discarded too. */
8883 /* For the toc section, we only mark as used if this
8884 entry itself isn't unused. */
8885 else if ((used[rel->r_offset >> 3]
8886 || !(skip[rel->r_offset >> 3] & ref_from_discarded))
8889 /* Do all the relocs again, to catch reference
8898 if (elf_section_data (sec)->relocs != relstart)
8902 /* Merge the used and skip arrays. Assume that TOC
8903 doublewords not appearing as either used or unused belong
8904 to to an entry more than one doubleword in size. */
8905 for (drop = skip, keep = used, last = 0, some_unused = 0;
8906 drop < skip + (toc->size + 7) / 8;
8911 *drop &= ~ref_from_discarded;
8912 if ((*drop & can_optimize) != 0)
8916 else if ((*drop & ref_from_discarded) != 0)
8919 last = ref_from_discarded;
8929 bfd_byte *contents, *src;
8931 Elf_Internal_Sym *sym;
8932 bfd_boolean local_toc_syms = FALSE;
8934 /* Shuffle the toc contents, and at the same time convert the
8935 skip array from booleans into offsets. */
8936 if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
8939 elf_section_data (toc)->this_hdr.contents = contents;
8941 for (src = contents, off = 0, drop = skip;
8942 src < contents + toc->size;
8945 if ((*drop & (can_optimize | ref_from_discarded)) != 0)
8950 memcpy (src - off, src, 8);
8954 toc->rawsize = toc->size;
8955 toc->size = src - contents - off;
8957 /* Adjust addends for relocs against the toc section sym,
8958 and optimize any accesses we can. */
8959 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8961 if (sec->reloc_count == 0
8962 || discarded_section (sec))
8965 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8967 if (relstart == NULL)
8970 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8972 enum elf_ppc64_reloc_type r_type;
8973 unsigned long r_symndx;
8975 struct elf_link_hash_entry *h;
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:
8990 case R_PPC64_ADDR64:
8994 r_symndx = ELF64_R_SYM (rel->r_info);
8995 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9003 val = h->root.u.def.value;
9006 val = sym->st_value;
9008 local_toc_syms = TRUE;
9011 val += rel->r_addend;
9013 if (val > toc->rawsize)
9015 else if ((skip[val >> 3] & ref_from_discarded) != 0)
9017 else if ((skip[val >> 3] & can_optimize) != 0)
9019 Elf_Internal_Rela *tocrel
9020 = toc_relocs + (skip[val >> 3] >> 2);
9021 unsigned long tsym = ELF64_R_SYM (tocrel->r_info);
9025 case R_PPC64_TOC16_HA:
9026 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA);
9029 case R_PPC64_TOC16_LO_DS:
9030 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT);
9034 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
9036 info->callbacks->einfo
9037 (_("%P: %H: %s references "
9038 "optimized away TOC entry\n"),
9039 ibfd, sec, rel->r_offset,
9040 ppc64_elf_howto_table[r_type]->name);
9041 bfd_set_error (bfd_error_bad_value);
9044 rel->r_addend = tocrel->r_addend;
9045 elf_section_data (sec)->relocs = relstart;
9049 if (h != NULL || sym->st_value != 0)
9052 rel->r_addend -= skip[val >> 3];
9053 elf_section_data (sec)->relocs = relstart;
9056 if (elf_section_data (sec)->relocs != relstart)
9060 /* We shouldn't have local or global symbols defined in the TOC,
9061 but handle them anyway. */
9062 if (local_syms != NULL)
9063 for (sym = local_syms;
9064 sym < local_syms + symtab_hdr->sh_info;
9066 if (sym->st_value != 0
9067 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
9071 if (sym->st_value > toc->rawsize)
9072 i = toc->rawsize >> 3;
9074 i = sym->st_value >> 3;
9076 if ((skip[i] & (ref_from_discarded | can_optimize)) != 0)
9079 (*_bfd_error_handler)
9080 (_("%s defined on removed toc entry"),
9081 bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL));
9084 while ((skip[i] & (ref_from_discarded | can_optimize)));
9085 sym->st_value = (bfd_vma) i << 3;
9088 sym->st_value -= skip[i];
9089 symtab_hdr->contents = (unsigned char *) local_syms;
9092 /* Adjust any global syms defined in this toc input section. */
9093 if (toc_inf.global_toc_syms)
9096 toc_inf.skip = skip;
9097 toc_inf.global_toc_syms = FALSE;
9098 elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
9102 if (toc->reloc_count != 0)
9104 Elf_Internal_Shdr *rel_hdr;
9105 Elf_Internal_Rela *wrel;
9108 /* Remove unused toc relocs, and adjust those we keep. */
9109 if (toc_relocs == NULL)
9110 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
9112 if (toc_relocs == NULL)
9116 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9117 if ((skip[rel->r_offset >> 3]
9118 & (ref_from_discarded | can_optimize)) == 0)
9120 wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
9121 wrel->r_info = rel->r_info;
9122 wrel->r_addend = rel->r_addend;
9125 else if (!dec_dynrel_count (rel->r_info, toc, info,
9126 &local_syms, NULL, NULL))
9129 elf_section_data (toc)->relocs = toc_relocs;
9130 toc->reloc_count = wrel - toc_relocs;
9131 rel_hdr = _bfd_elf_single_rel_hdr (toc);
9132 sz = rel_hdr->sh_entsize;
9133 rel_hdr->sh_size = toc->reloc_count * sz;
9136 else if (toc_relocs != NULL
9137 && elf_section_data (toc)->relocs != toc_relocs)
9140 if (local_syms != NULL
9141 && symtab_hdr->contents != (unsigned char *) local_syms)
9143 if (!info->keep_memory)
9146 symtab_hdr->contents = (unsigned char *) local_syms;
9154 /* Return true iff input section I references the TOC using
9155 instructions limited to +/-32k offsets. */
9158 ppc64_elf_has_small_toc_reloc (asection *i)
9160 return (is_ppc64_elf (i->owner)
9161 && ppc64_elf_tdata (i->owner)->has_small_toc_reloc);
9164 /* Allocate space for one GOT entry. */
9167 allocate_got (struct elf_link_hash_entry *h,
9168 struct bfd_link_info *info,
9169 struct got_entry *gent)
9171 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9173 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
9174 int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
9176 int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
9177 ? 2 : 1) * sizeof (Elf64_External_Rela);
9178 asection *got = ppc64_elf_tdata (gent->owner)->got;
9180 gent->got.offset = got->size;
9181 got->size += entsize;
9183 dyn = htab->elf.dynamic_sections_created;
9184 if (h->type == STT_GNU_IFUNC)
9186 htab->reliplt->size += rentsize;
9187 htab->got_reli_size += rentsize;
9189 else if ((info->shared
9190 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
9191 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9192 || h->root.type != bfd_link_hash_undefweak))
9194 asection *relgot = ppc64_elf_tdata (gent->owner)->relgot;
9195 relgot->size += rentsize;
9199 /* This function merges got entries in the same toc group. */
9202 merge_got_entries (struct got_entry **pent)
9204 struct got_entry *ent, *ent2;
9206 for (ent = *pent; ent != NULL; ent = ent->next)
9207 if (!ent->is_indirect)
9208 for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next)
9209 if (!ent2->is_indirect
9210 && ent2->addend == ent->addend
9211 && ent2->tls_type == ent->tls_type
9212 && elf_gp (ent2->owner) == elf_gp (ent->owner))
9214 ent2->is_indirect = TRUE;
9215 ent2->got.ent = ent;
9219 /* Allocate space in .plt, .got and associated reloc sections for
9223 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9225 struct bfd_link_info *info;
9226 struct ppc_link_hash_table *htab;
9228 struct ppc_link_hash_entry *eh;
9229 struct elf_dyn_relocs *p;
9230 struct got_entry **pgent, *gent;
9232 if (h->root.type == bfd_link_hash_indirect)
9235 info = (struct bfd_link_info *) inf;
9236 htab = ppc_hash_table (info);
9240 if ((htab->elf.dynamic_sections_created
9242 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
9243 || h->type == STT_GNU_IFUNC)
9245 struct plt_entry *pent;
9246 bfd_boolean doneone = FALSE;
9247 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9248 if (pent->plt.refcount > 0)
9250 if (!htab->elf.dynamic_sections_created
9251 || h->dynindx == -1)
9254 pent->plt.offset = s->size;
9255 s->size += PLT_ENTRY_SIZE (htab);
9260 /* If this is the first .plt entry, make room for the special
9264 s->size += PLT_INITIAL_ENTRY_SIZE (htab);
9266 pent->plt.offset = s->size;
9268 /* Make room for this entry. */
9269 s->size += PLT_ENTRY_SIZE (htab);
9271 /* Make room for the .glink code. */
9274 s->size += GLINK_CALL_STUB_SIZE;
9277 /* We need bigger stubs past index 32767. */
9278 if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
9285 /* We also need to make an entry in the .rela.plt section. */
9288 s->size += sizeof (Elf64_External_Rela);
9292 pent->plt.offset = (bfd_vma) -1;
9295 h->plt.plist = NULL;
9301 h->plt.plist = NULL;
9305 eh = (struct ppc_link_hash_entry *) h;
9306 /* Run through the TLS GD got entries first if we're changing them
9308 if ((eh->tls_mask & TLS_TPRELGD) != 0)
9309 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9310 if (gent->got.refcount > 0
9311 && (gent->tls_type & TLS_GD) != 0)
9313 /* This was a GD entry that has been converted to TPREL. If
9314 there happens to be a TPREL entry we can use that one. */
9315 struct got_entry *ent;
9316 for (ent = h->got.glist; ent != NULL; ent = ent->next)
9317 if (ent->got.refcount > 0
9318 && (ent->tls_type & TLS_TPREL) != 0
9319 && ent->addend == gent->addend
9320 && ent->owner == gent->owner)
9322 gent->got.refcount = 0;
9326 /* If not, then we'll be using our own TPREL entry. */
9327 if (gent->got.refcount != 0)
9328 gent->tls_type = TLS_TLS | TLS_TPREL;
9331 /* Remove any list entry that won't generate a word in the GOT before
9332 we call merge_got_entries. Otherwise we risk merging to empty
9334 pgent = &h->got.glist;
9335 while ((gent = *pgent) != NULL)
9336 if (gent->got.refcount > 0)
9338 if ((gent->tls_type & TLS_LD) != 0
9341 ppc64_tlsld_got (gent->owner)->got.refcount += 1;
9342 *pgent = gent->next;
9345 pgent = &gent->next;
9348 *pgent = gent->next;
9350 if (!htab->do_multi_toc)
9351 merge_got_entries (&h->got.glist);
9353 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9354 if (!gent->is_indirect)
9356 /* Make sure this symbol is output as a dynamic symbol.
9357 Undefined weak syms won't yet be marked as dynamic,
9358 nor will all TLS symbols. */
9359 if (h->dynindx == -1
9361 && h->type != STT_GNU_IFUNC
9362 && htab->elf.dynamic_sections_created)
9364 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9368 if (!is_ppc64_elf (gent->owner))
9371 allocate_got (h, info, gent);
9374 if (eh->dyn_relocs == NULL
9375 || (!htab->elf.dynamic_sections_created
9376 && h->type != STT_GNU_IFUNC))
9379 /* In the shared -Bsymbolic case, discard space allocated for
9380 dynamic pc-relative relocs against symbols which turn out to be
9381 defined in regular objects. For the normal shared case, discard
9382 space for relocs that have become local due to symbol visibility
9387 /* Relocs that use pc_count are those that appear on a call insn,
9388 or certain REL relocs (see must_be_dyn_reloc) that can be
9389 generated via assembly. We want calls to protected symbols to
9390 resolve directly to the function rather than going via the plt.
9391 If people want function pointer comparisons to work as expected
9392 then they should avoid writing weird assembly. */
9393 if (SYMBOL_CALLS_LOCAL (info, h))
9395 struct elf_dyn_relocs **pp;
9397 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
9399 p->count -= p->pc_count;
9408 /* Also discard relocs on undefined weak syms with non-default
9410 if (eh->dyn_relocs != NULL
9411 && h->root.type == bfd_link_hash_undefweak)
9413 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9414 eh->dyn_relocs = NULL;
9416 /* Make sure this symbol is output as a dynamic symbol.
9417 Undefined weak syms won't yet be marked as dynamic. */
9418 else if (h->dynindx == -1
9419 && !h->forced_local)
9421 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9426 else if (h->type == STT_GNU_IFUNC)
9428 if (!h->non_got_ref)
9429 eh->dyn_relocs = NULL;
9431 else if (ELIMINATE_COPY_RELOCS)
9433 /* For the non-shared case, discard space for relocs against
9434 symbols which turn out to need copy relocs or are not
9440 /* Make sure this symbol is output as a dynamic symbol.
9441 Undefined weak syms won't yet be marked as dynamic. */
9442 if (h->dynindx == -1
9443 && !h->forced_local)
9445 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9449 /* If that succeeded, we know we'll be keeping all the
9451 if (h->dynindx != -1)
9455 eh->dyn_relocs = NULL;
9460 /* Finally, allocate space. */
9461 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9463 asection *sreloc = elf_section_data (p->sec)->sreloc;
9464 if (eh->elf.type == STT_GNU_IFUNC)
9465 sreloc = htab->reliplt;
9466 sreloc->size += p->count * sizeof (Elf64_External_Rela);
9472 /* Find any dynamic relocs that apply to read-only sections. */
9475 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9477 struct ppc_link_hash_entry *eh;
9478 struct elf_dyn_relocs *p;
9480 eh = (struct ppc_link_hash_entry *) h;
9481 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9483 asection *s = p->sec->output_section;
9485 if (s != NULL && (s->flags & SEC_READONLY) != 0)
9487 struct bfd_link_info *info = inf;
9489 info->flags |= DF_TEXTREL;
9491 /* Not an error, just cut short the traversal. */
9498 /* Set the sizes of the dynamic sections. */
9501 ppc64_elf_size_dynamic_sections (bfd *output_bfd,
9502 struct bfd_link_info *info)
9504 struct ppc_link_hash_table *htab;
9509 struct got_entry *first_tlsld;
9511 htab = ppc_hash_table (info);
9515 dynobj = htab->elf.dynobj;
9519 if (htab->elf.dynamic_sections_created)
9521 /* Set the contents of the .interp section to the interpreter. */
9522 if (info->executable)
9524 s = bfd_get_linker_section (dynobj, ".interp");
9527 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
9528 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
9532 /* Set up .got offsets for local syms, and space for local dynamic
9534 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9536 struct got_entry **lgot_ents;
9537 struct got_entry **end_lgot_ents;
9538 struct plt_entry **local_plt;
9539 struct plt_entry **end_local_plt;
9540 unsigned char *lgot_masks;
9541 bfd_size_type locsymcount;
9542 Elf_Internal_Shdr *symtab_hdr;
9544 if (!is_ppc64_elf (ibfd))
9547 for (s = ibfd->sections; s != NULL; s = s->next)
9549 struct ppc_dyn_relocs *p;
9551 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
9553 if (!bfd_is_abs_section (p->sec)
9554 && bfd_is_abs_section (p->sec->output_section))
9556 /* Input section has been discarded, either because
9557 it is a copy of a linkonce section or due to
9558 linker script /DISCARD/, so we'll be discarding
9561 else if (p->count != 0)
9563 asection *srel = elf_section_data (p->sec)->sreloc;
9565 srel = htab->reliplt;
9566 srel->size += p->count * sizeof (Elf64_External_Rela);
9567 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
9568 info->flags |= DF_TEXTREL;
9573 lgot_ents = elf_local_got_ents (ibfd);
9577 symtab_hdr = &elf_symtab_hdr (ibfd);
9578 locsymcount = symtab_hdr->sh_info;
9579 end_lgot_ents = lgot_ents + locsymcount;
9580 local_plt = (struct plt_entry **) end_lgot_ents;
9581 end_local_plt = local_plt + locsymcount;
9582 lgot_masks = (unsigned char *) end_local_plt;
9583 s = ppc64_elf_tdata (ibfd)->got;
9584 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
9586 struct got_entry **pent, *ent;
9589 while ((ent = *pent) != NULL)
9590 if (ent->got.refcount > 0)
9592 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
9594 ppc64_tlsld_got (ibfd)->got.refcount += 1;
9599 unsigned int ent_size = 8;
9600 unsigned int rel_size = sizeof (Elf64_External_Rela);
9602 ent->got.offset = s->size;
9603 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
9608 s->size += ent_size;
9609 if ((*lgot_masks & PLT_IFUNC) != 0)
9611 htab->reliplt->size += rel_size;
9612 htab->got_reli_size += rel_size;
9614 else if (info->shared)
9616 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
9617 srel->size += rel_size;
9626 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
9627 for (; local_plt < end_local_plt; ++local_plt)
9629 struct plt_entry *ent;
9631 for (ent = *local_plt; ent != NULL; ent = ent->next)
9632 if (ent->plt.refcount > 0)
9635 ent->plt.offset = s->size;
9636 s->size += PLT_ENTRY_SIZE (htab);
9638 htab->reliplt->size += sizeof (Elf64_External_Rela);
9641 ent->plt.offset = (bfd_vma) -1;
9645 /* Allocate global sym .plt and .got entries, and space for global
9646 sym dynamic relocs. */
9647 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
9650 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9652 struct got_entry *ent;
9654 if (!is_ppc64_elf (ibfd))
9657 ent = ppc64_tlsld_got (ibfd);
9658 if (ent->got.refcount > 0)
9660 if (!htab->do_multi_toc && first_tlsld != NULL)
9662 ent->is_indirect = TRUE;
9663 ent->got.ent = first_tlsld;
9667 if (first_tlsld == NULL)
9669 s = ppc64_elf_tdata (ibfd)->got;
9670 ent->got.offset = s->size;
9675 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
9676 srel->size += sizeof (Elf64_External_Rela);
9681 ent->got.offset = (bfd_vma) -1;
9684 /* We now have determined the sizes of the various dynamic sections.
9685 Allocate memory for them. */
9687 for (s = dynobj->sections; s != NULL; s = s->next)
9689 if ((s->flags & SEC_LINKER_CREATED) == 0)
9692 if (s == htab->brlt || s == htab->relbrlt)
9693 /* These haven't been allocated yet; don't strip. */
9695 else if (s == htab->got
9699 || s == htab->dynbss)
9701 /* Strip this section if we don't need it; see the
9704 else if (s == htab->glink_eh_frame)
9706 if (!bfd_is_abs_section (s->output_section))
9707 /* Not sized yet. */
9710 else if (CONST_STRNEQ (s->name, ".rela"))
9714 if (s != htab->relplt)
9717 /* We use the reloc_count field as a counter if we need
9718 to copy relocs into the output file. */
9724 /* It's not one of our sections, so don't allocate space. */
9730 /* If we don't need this section, strip it from the
9731 output file. This is mostly to handle .rela.bss and
9732 .rela.plt. We must create both sections in
9733 create_dynamic_sections, because they must be created
9734 before the linker maps input sections to output
9735 sections. The linker does that before
9736 adjust_dynamic_symbol is called, and it is that
9737 function which decides whether anything needs to go
9738 into these sections. */
9739 s->flags |= SEC_EXCLUDE;
9743 if ((s->flags & SEC_HAS_CONTENTS) == 0)
9746 /* Allocate memory for the section contents. We use bfd_zalloc
9747 here in case unused entries are not reclaimed before the
9748 section's contents are written out. This should not happen,
9749 but this way if it does we get a R_PPC64_NONE reloc in .rela
9750 sections instead of garbage.
9751 We also rely on the section contents being zero when writing
9753 s->contents = bfd_zalloc (dynobj, s->size);
9754 if (s->contents == NULL)
9758 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9760 if (!is_ppc64_elf (ibfd))
9763 s = ppc64_elf_tdata (ibfd)->got;
9764 if (s != NULL && s != htab->got)
9767 s->flags |= SEC_EXCLUDE;
9770 s->contents = bfd_zalloc (ibfd, s->size);
9771 if (s->contents == NULL)
9775 s = ppc64_elf_tdata (ibfd)->relgot;
9779 s->flags |= SEC_EXCLUDE;
9782 s->contents = bfd_zalloc (ibfd, s->size);
9783 if (s->contents == NULL)
9791 if (htab->elf.dynamic_sections_created)
9793 /* Add some entries to the .dynamic section. We fill in the
9794 values later, in ppc64_elf_finish_dynamic_sections, but we
9795 must add the entries now so that we get the correct size for
9796 the .dynamic section. The DT_DEBUG entry is filled in by the
9797 dynamic linker and used by the debugger. */
9798 #define add_dynamic_entry(TAG, VAL) \
9799 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9801 if (info->executable)
9803 if (!add_dynamic_entry (DT_DEBUG, 0))
9807 if (htab->plt != NULL && htab->plt->size != 0)
9809 if (!add_dynamic_entry (DT_PLTGOT, 0)
9810 || !add_dynamic_entry (DT_PLTRELSZ, 0)
9811 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
9812 || !add_dynamic_entry (DT_JMPREL, 0)
9813 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
9817 if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
9819 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
9820 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
9824 if (!htab->no_tls_get_addr_opt
9825 && htab->tls_get_addr_fd != NULL
9826 && htab->tls_get_addr_fd->elf.plt.plist != NULL
9827 && !add_dynamic_entry (DT_PPC64_TLSOPT, 0))
9832 if (!add_dynamic_entry (DT_RELA, 0)
9833 || !add_dynamic_entry (DT_RELASZ, 0)
9834 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
9837 /* If any dynamic relocs apply to a read-only section,
9838 then we need a DT_TEXTREL entry. */
9839 if ((info->flags & DF_TEXTREL) == 0)
9840 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
9842 if ((info->flags & DF_TEXTREL) != 0)
9844 if (!add_dynamic_entry (DT_TEXTREL, 0))
9849 #undef add_dynamic_entry
9854 /* Determine the type of stub needed, if any, for a call. */
9856 static inline enum ppc_stub_type
9857 ppc_type_of_stub (asection *input_sec,
9858 const Elf_Internal_Rela *rel,
9859 struct ppc_link_hash_entry **hash,
9860 struct plt_entry **plt_ent,
9861 bfd_vma destination,
9862 unsigned long local_off)
9864 struct ppc_link_hash_entry *h = *hash;
9866 bfd_vma branch_offset;
9867 bfd_vma max_branch_offset;
9868 enum elf_ppc64_reloc_type r_type;
9872 struct plt_entry *ent;
9873 struct ppc_link_hash_entry *fdh = h;
9875 && h->oh->is_func_descriptor)
9877 fdh = ppc_follow_link (h->oh);
9881 for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
9882 if (ent->addend == rel->r_addend
9883 && ent->plt.offset != (bfd_vma) -1)
9886 return ppc_stub_plt_call;
9889 /* Here, we know we don't have a plt entry. If we don't have a
9890 either a defined function descriptor or a defined entry symbol
9891 in a regular object file, then it is pointless trying to make
9892 any other type of stub. */
9893 if (!is_static_defined (&fdh->elf)
9894 && !is_static_defined (&h->elf))
9895 return ppc_stub_none;
9897 else if (elf_local_got_ents (input_sec->owner) != NULL)
9899 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
9900 struct plt_entry **local_plt = (struct plt_entry **)
9901 elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
9902 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
9904 if (local_plt[r_symndx] != NULL)
9906 struct plt_entry *ent;
9908 for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
9909 if (ent->addend == rel->r_addend
9910 && ent->plt.offset != (bfd_vma) -1)
9913 return ppc_stub_plt_call;
9918 /* Determine where the call point is. */
9919 location = (input_sec->output_offset
9920 + input_sec->output_section->vma
9923 branch_offset = destination - location;
9924 r_type = ELF64_R_TYPE (rel->r_info);
9926 /* Determine if a long branch stub is needed. */
9927 max_branch_offset = 1 << 25;
9928 if (r_type != R_PPC64_REL24)
9929 max_branch_offset = 1 << 15;
9931 if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
9932 /* We need a stub. Figure out whether a long_branch or plt_branch
9934 return ppc_stub_long_branch;
9936 return ppc_stub_none;
9939 /* With power7 weakly ordered memory model, it is possible for ld.so
9940 to update a plt entry in one thread and have another thread see a
9941 stale zero toc entry. To avoid this we need some sort of acquire
9942 barrier in the call stub. One solution is to make the load of the
9943 toc word seem to appear to depend on the load of the function entry
9944 word. Another solution is to test for r2 being zero, and branch to
9945 the appropriate glink entry if so.
9947 . fake dep barrier compare
9948 . ld 12,xxx(2) ld 12,xxx(2)
9950 . xor 11,12,12 ld 2,xxx+8(2)
9951 . add 2,2,11 cmpldi 2,0
9952 . ld 2,xxx+8(2) bnectr+
9953 . bctr b <glink_entry>
9955 The solution involving the compare turns out to be faster, so
9956 that's what we use unless the branch won't reach. */
9958 #define ALWAYS_USE_FAKE_DEP 0
9959 #define ALWAYS_EMIT_R2SAVE 0
9961 #define PPC_LO(v) ((v) & 0xffff)
9962 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9963 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9965 static inline unsigned int
9966 plt_stub_size (struct ppc_link_hash_table *htab,
9967 struct ppc_stub_hash_entry *stub_entry,
9972 if (ALWAYS_EMIT_R2SAVE
9973 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
9975 if (PPC_HA (off) != 0)
9980 if (htab->plt_static_chain)
9982 if (htab->plt_thread_safe)
9984 if (PPC_HA (off + 8 + 8 * htab->plt_static_chain) != PPC_HA (off))
9987 if (stub_entry->h != NULL
9988 && (stub_entry->h == htab->tls_get_addr_fd
9989 || stub_entry->h == htab->tls_get_addr)
9990 && !htab->no_tls_get_addr_opt)
9995 /* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
9996 then return the padding needed to do so. */
9997 static inline unsigned int
9998 plt_stub_pad (struct ppc_link_hash_table *htab,
9999 struct ppc_stub_hash_entry *stub_entry,
10002 int stub_align = 1 << htab->plt_stub_align;
10003 unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
10004 bfd_vma stub_off = stub_entry->stub_sec->size;
10006 if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
10007 > (stub_size & -stub_align))
10008 return stub_align - (stub_off & (stub_align - 1));
10012 /* Build a .plt call stub. */
10014 static inline bfd_byte *
10015 build_plt_stub (struct ppc_link_hash_table *htab,
10016 struct ppc_stub_hash_entry *stub_entry,
10017 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10019 bfd *obfd = htab->stub_bfd;
10020 bfd_boolean plt_load_toc = htab->opd_abi;
10021 bfd_boolean plt_static_chain = htab->plt_static_chain;
10022 bfd_boolean plt_thread_safe = htab->plt_thread_safe;
10023 bfd_boolean use_fake_dep = plt_thread_safe;
10024 bfd_vma cmp_branch_off = 0;
10026 if (!ALWAYS_USE_FAKE_DEP
10029 && !(stub_entry->h != NULL
10030 && (stub_entry->h == htab->tls_get_addr_fd
10031 || stub_entry->h == htab->tls_get_addr)
10032 && !htab->no_tls_get_addr_opt))
10034 bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
10035 bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
10036 / PLT_ENTRY_SIZE (htab));
10037 bfd_vma glinkoff = GLINK_CALL_STUB_SIZE + pltindex * 8;
10040 if (pltindex > 32768)
10041 glinkoff += (pltindex - 32768) * 4;
10043 + htab->glink->output_offset
10044 + htab->glink->output_section->vma);
10045 from = (p - stub_entry->stub_sec->contents
10046 + 4 * (ALWAYS_EMIT_R2SAVE
10047 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10048 + 4 * (PPC_HA (offset) != 0)
10049 + 4 * (PPC_HA (offset + 8 + 8 * plt_static_chain)
10050 != PPC_HA (offset))
10051 + 4 * (plt_static_chain != 0)
10053 + stub_entry->stub_sec->output_offset
10054 + stub_entry->stub_sec->output_section->vma);
10055 cmp_branch_off = to - from;
10056 use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
10059 if (PPC_HA (offset) != 0)
10063 if (ALWAYS_EMIT_R2SAVE
10064 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10065 r[0].r_offset += 4;
10066 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10067 r[1].r_offset = r[0].r_offset + 4;
10068 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10069 r[1].r_addend = r[0].r_addend;
10072 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10074 r[2].r_offset = r[1].r_offset + 4;
10075 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO);
10076 r[2].r_addend = r[0].r_addend;
10080 r[2].r_offset = r[1].r_offset + 8 + 8 * use_fake_dep;
10081 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10082 r[2].r_addend = r[0].r_addend + 8;
10083 if (plt_static_chain)
10085 r[3].r_offset = r[2].r_offset + 4;
10086 r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10087 r[3].r_addend = r[0].r_addend + 16;
10092 if (ALWAYS_EMIT_R2SAVE
10093 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10094 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10095 bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
10096 bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
10098 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10100 bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p), p += 4;
10103 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10108 bfd_put_32 (obfd, XOR_R2_R12_R12, p), p += 4;
10109 bfd_put_32 (obfd, ADD_R11_R11_R2, p), p += 4;
10111 bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p), p += 4;
10112 if (plt_static_chain)
10113 bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
10120 if (ALWAYS_EMIT_R2SAVE
10121 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10122 r[0].r_offset += 4;
10123 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10126 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10128 r[1].r_offset = r[0].r_offset + 4;
10129 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16);
10130 r[1].r_addend = r[0].r_addend;
10134 r[1].r_offset = r[0].r_offset + 8 + 8 * use_fake_dep;
10135 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10136 r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain;
10137 if (plt_static_chain)
10139 r[2].r_offset = r[1].r_offset + 4;
10140 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10141 r[2].r_addend = r[0].r_addend + 8;
10146 if (ALWAYS_EMIT_R2SAVE
10147 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10148 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10149 bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p), p += 4;
10151 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10153 bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4;
10156 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10161 bfd_put_32 (obfd, XOR_R11_R12_R12, p), p += 4;
10162 bfd_put_32 (obfd, ADD_R2_R2_R11, p), p += 4;
10164 if (plt_static_chain)
10165 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4;
10166 bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4;
10169 if (plt_load_toc && plt_thread_safe && !use_fake_dep)
10171 bfd_put_32 (obfd, CMPLDI_R2_0, p), p += 4;
10172 bfd_put_32 (obfd, BNECTR_P4, p), p += 4;
10173 bfd_put_32 (obfd, B_DOT | (cmp_branch_off & 0x3fffffc), p), p += 4;
10176 bfd_put_32 (obfd, BCTR, p), p += 4;
10180 /* Build a special .plt call stub for __tls_get_addr. */
10182 #define LD_R11_0R3 0xe9630000
10183 #define LD_R12_0R3 0xe9830000
10184 #define MR_R0_R3 0x7c601b78
10185 #define CMPDI_R11_0 0x2c2b0000
10186 #define ADD_R3_R12_R13 0x7c6c6a14
10187 #define BEQLR 0x4d820020
10188 #define MR_R3_R0 0x7c030378
10189 #define STD_R11_0R1 0xf9610000
10190 #define BCTRL 0x4e800421
10191 #define LD_R11_0R1 0xe9610000
10192 #define MTLR_R11 0x7d6803a6
10194 static inline bfd_byte *
10195 build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
10196 struct ppc_stub_hash_entry *stub_entry,
10197 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10199 bfd *obfd = htab->stub_bfd;
10201 bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
10202 bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
10203 bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
10204 bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
10205 bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
10206 bfd_put_32 (obfd, BEQLR, p), p += 4;
10207 bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
10208 bfd_put_32 (obfd, MFLR_R11, p), p += 4;
10209 bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10212 r[0].r_offset += 9 * 4;
10213 p = build_plt_stub (htab, stub_entry, p, offset, r);
10214 bfd_put_32 (obfd, BCTRL, p - 4);
10216 bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10217 bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4;
10218 bfd_put_32 (obfd, MTLR_R11, p), p += 4;
10219 bfd_put_32 (obfd, BLR, p), p += 4;
10224 static Elf_Internal_Rela *
10225 get_relocs (asection *sec, int count)
10227 Elf_Internal_Rela *relocs;
10228 struct bfd_elf_section_data *elfsec_data;
10230 elfsec_data = elf_section_data (sec);
10231 relocs = elfsec_data->relocs;
10232 if (relocs == NULL)
10234 bfd_size_type relsize;
10235 relsize = sec->reloc_count * sizeof (*relocs);
10236 relocs = bfd_alloc (sec->owner, relsize);
10237 if (relocs == NULL)
10239 elfsec_data->relocs = relocs;
10240 elfsec_data->rela.hdr = bfd_zalloc (sec->owner,
10241 sizeof (Elf_Internal_Shdr));
10242 if (elfsec_data->rela.hdr == NULL)
10244 elfsec_data->rela.hdr->sh_size = (sec->reloc_count
10245 * sizeof (Elf64_External_Rela));
10246 elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela);
10247 sec->reloc_count = 0;
10249 relocs += sec->reloc_count;
10250 sec->reloc_count += count;
10255 get_r2off (struct bfd_link_info *info,
10256 struct ppc_stub_hash_entry *stub_entry)
10258 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10259 bfd_vma r2off = htab->stub_group[stub_entry->target_section->id].toc_off;
10263 /* Support linking -R objects. Get the toc pointer from the
10266 if (!htab->opd_abi)
10268 asection *opd = stub_entry->h->elf.root.u.def.section;
10269 bfd_vma opd_off = stub_entry->h->elf.root.u.def.value;
10271 if (strcmp (opd->name, ".opd") != 0
10272 || opd->reloc_count != 0)
10274 info->callbacks->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
10275 stub_entry->h->elf.root.root.string);
10276 bfd_set_error (bfd_error_bad_value);
10279 if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8))
10281 r2off = bfd_get_64 (opd->owner, buf);
10282 r2off -= elf_gp (info->output_bfd);
10284 r2off -= htab->stub_group[stub_entry->id_sec->id].toc_off;
10289 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10291 struct ppc_stub_hash_entry *stub_entry;
10292 struct ppc_branch_hash_entry *br_entry;
10293 struct bfd_link_info *info;
10294 struct ppc_link_hash_table *htab;
10299 Elf_Internal_Rela *r;
10302 /* Massage our args to the form they really have. */
10303 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10306 htab = ppc_hash_table (info);
10310 /* Make a note of the offset within the stubs for this entry. */
10311 stub_entry->stub_offset = stub_entry->stub_sec->size;
10312 loc = stub_entry->stub_sec->contents + stub_entry->stub_offset;
10314 htab->stub_count[stub_entry->stub_type - 1] += 1;
10315 switch (stub_entry->stub_type)
10317 case ppc_stub_long_branch:
10318 case ppc_stub_long_branch_r2off:
10319 /* Branches are relative. This is where we are going to. */
10320 dest = (stub_entry->target_value
10321 + stub_entry->target_section->output_offset
10322 + stub_entry->target_section->output_section->vma);
10323 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10326 /* And this is where we are coming from. */
10327 off -= (stub_entry->stub_offset
10328 + stub_entry->stub_sec->output_offset
10329 + stub_entry->stub_sec->output_section->vma);
10332 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10334 bfd_vma r2off = get_r2off (info, stub_entry);
10338 htab->stub_error = TRUE;
10341 bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
10344 if (PPC_HA (r2off) != 0)
10347 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
10350 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
10354 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
10356 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
10358 info->callbacks->einfo
10359 (_("%P: long branch stub `%s' offset overflow\n"),
10360 stub_entry->root.string);
10361 htab->stub_error = TRUE;
10365 if (info->emitrelocations)
10367 r = get_relocs (stub_entry->stub_sec, 1);
10370 r->r_offset = loc - stub_entry->stub_sec->contents;
10371 r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
10372 r->r_addend = dest;
10373 if (stub_entry->h != NULL)
10375 struct elf_link_hash_entry **hashes;
10376 unsigned long symndx;
10377 struct ppc_link_hash_entry *h;
10379 hashes = elf_sym_hashes (htab->stub_bfd);
10380 if (hashes == NULL)
10382 bfd_size_type hsize;
10384 hsize = (htab->stub_globals + 1) * sizeof (*hashes);
10385 hashes = bfd_zalloc (htab->stub_bfd, hsize);
10386 if (hashes == NULL)
10388 elf_sym_hashes (htab->stub_bfd) = hashes;
10389 htab->stub_globals = 1;
10391 symndx = htab->stub_globals++;
10393 hashes[symndx] = &h->elf;
10394 r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
10395 if (h->oh != NULL && h->oh->is_func)
10396 h = ppc_follow_link (h->oh);
10397 if (h->elf.root.u.def.section != stub_entry->target_section)
10398 /* H is an opd symbol. The addend must be zero. */
10402 off = (h->elf.root.u.def.value
10403 + h->elf.root.u.def.section->output_offset
10404 + h->elf.root.u.def.section->output_section->vma);
10405 r->r_addend -= off;
10411 case ppc_stub_plt_branch:
10412 case ppc_stub_plt_branch_r2off:
10413 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
10414 stub_entry->root.string + 9,
10416 if (br_entry == NULL)
10418 info->callbacks->einfo (_("%P: can't find branch stub `%s'\n"),
10419 stub_entry->root.string);
10420 htab->stub_error = TRUE;
10424 dest = (stub_entry->target_value
10425 + stub_entry->target_section->output_offset
10426 + stub_entry->target_section->output_section->vma);
10427 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
10428 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10430 bfd_put_64 (htab->brlt->owner, dest,
10431 htab->brlt->contents + br_entry->offset);
10433 if (br_entry->iter == htab->stub_iteration)
10435 br_entry->iter = 0;
10437 if (htab->relbrlt != NULL)
10439 /* Create a reloc for the branch lookup table entry. */
10440 Elf_Internal_Rela rela;
10443 rela.r_offset = (br_entry->offset
10444 + htab->brlt->output_offset
10445 + htab->brlt->output_section->vma);
10446 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10447 rela.r_addend = dest;
10449 rl = htab->relbrlt->contents;
10450 rl += (htab->relbrlt->reloc_count++
10451 * sizeof (Elf64_External_Rela));
10452 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
10454 else if (info->emitrelocations)
10456 r = get_relocs (htab->brlt, 1);
10459 /* brlt, being SEC_LINKER_CREATED does not go through the
10460 normal reloc processing. Symbols and offsets are not
10461 translated from input file to output file form, so
10462 set up the offset per the output file. */
10463 r->r_offset = (br_entry->offset
10464 + htab->brlt->output_offset
10465 + htab->brlt->output_section->vma);
10466 r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10467 r->r_addend = dest;
10471 dest = (br_entry->offset
10472 + htab->brlt->output_offset
10473 + htab->brlt->output_section->vma);
10476 - elf_gp (htab->brlt->output_section->owner)
10477 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10479 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
10481 info->callbacks->einfo
10482 (_("%P: linkage table error against `%T'\n"),
10483 stub_entry->root.string);
10484 bfd_set_error (bfd_error_bad_value);
10485 htab->stub_error = TRUE;
10489 if (info->emitrelocations)
10491 r = get_relocs (stub_entry->stub_sec, 1 + (PPC_HA (off) != 0));
10494 r[0].r_offset = loc - stub_entry->stub_sec->contents;
10495 if (bfd_big_endian (info->output_bfd))
10496 r[0].r_offset += 2;
10497 if (stub_entry->stub_type == ppc_stub_plt_branch_r2off
10499 r[0].r_offset += 4;
10500 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10501 r[0].r_addend = dest;
10502 if (PPC_HA (off) != 0)
10504 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10505 r[1].r_offset = r[0].r_offset + 4;
10506 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10507 r[1].r_addend = r[0].r_addend;
10511 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
10514 if (PPC_HA (off) != 0)
10517 bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
10519 bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
10524 bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
10529 bfd_vma r2off = get_r2off (info, stub_entry);
10533 htab->stub_error = TRUE;
10537 bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
10540 if (PPC_HA (off) != 0)
10543 bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
10545 bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
10550 bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
10554 if (PPC_HA (r2off) != 0)
10557 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
10560 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
10563 bfd_put_32 (htab->stub_bfd, MTCTR_R12, loc);
10565 bfd_put_32 (htab->stub_bfd, BCTR, loc);
10568 case ppc_stub_plt_call:
10569 case ppc_stub_plt_call_r2save:
10570 if (stub_entry->h != NULL
10571 && stub_entry->h->is_func_descriptor
10572 && stub_entry->h->oh != NULL)
10574 struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
10576 /* If the old-ABI "dot-symbol" is undefined make it weak so
10577 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
10578 FIXME: We used to define the symbol on one of the call
10579 stubs instead, which is why we test symbol section id
10580 against htab->top_id in various places. Likely all
10581 these checks could now disappear. */
10582 if (fh->elf.root.type == bfd_link_hash_undefined)
10583 fh->elf.root.type = bfd_link_hash_undefweak;
10584 /* Stop undo_symbol_twiddle changing it back to undefined. */
10585 fh->was_undefined = 0;
10588 /* Now build the stub. */
10589 dest = stub_entry->plt_ent->plt.offset & ~1;
10590 if (dest >= (bfd_vma) -2)
10594 if (!htab->elf.dynamic_sections_created
10595 || stub_entry->h == NULL
10596 || stub_entry->h->elf.dynindx == -1)
10599 dest += plt->output_offset + plt->output_section->vma;
10601 if (stub_entry->h == NULL
10602 && (stub_entry->plt_ent->plt.offset & 1) == 0)
10604 Elf_Internal_Rela rela;
10607 rela.r_offset = dest;
10609 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
10611 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
10612 rela.r_addend = (stub_entry->target_value
10613 + stub_entry->target_section->output_offset
10614 + stub_entry->target_section->output_section->vma);
10616 rl = (htab->reliplt->contents
10617 + (htab->reliplt->reloc_count++
10618 * sizeof (Elf64_External_Rela)));
10619 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
10620 stub_entry->plt_ent->plt.offset |= 1;
10624 - elf_gp (plt->output_section->owner)
10625 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10627 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
10629 info->callbacks->einfo
10630 (_("%P: linkage table error against `%T'\n"),
10631 stub_entry->h != NULL
10632 ? stub_entry->h->elf.root.root.string
10634 bfd_set_error (bfd_error_bad_value);
10635 htab->stub_error = TRUE;
10639 if (htab->plt_stub_align != 0)
10641 unsigned pad = plt_stub_pad (htab, stub_entry, off);
10643 stub_entry->stub_sec->size += pad;
10644 stub_entry->stub_offset = stub_entry->stub_sec->size;
10649 if (info->emitrelocations)
10651 r = get_relocs (stub_entry->stub_sec,
10653 + (PPC_HA (off) != 0)
10654 + (htab->plt_static_chain
10655 && PPC_HA (off + 16) == PPC_HA (off))));
10658 r[0].r_offset = loc - stub_entry->stub_sec->contents;
10659 if (bfd_big_endian (info->output_bfd))
10660 r[0].r_offset += 2;
10661 r[0].r_addend = dest;
10663 if (stub_entry->h != NULL
10664 && (stub_entry->h == htab->tls_get_addr_fd
10665 || stub_entry->h == htab->tls_get_addr)
10666 && !htab->no_tls_get_addr_opt)
10667 p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
10669 p = build_plt_stub (htab, stub_entry, loc, off, r);
10678 stub_entry->stub_sec->size += size;
10680 if (htab->emit_stub_syms)
10682 struct elf_link_hash_entry *h;
10685 const char *const stub_str[] = { "long_branch",
10686 "long_branch_r2off",
10688 "plt_branch_r2off",
10692 len1 = strlen (stub_str[stub_entry->stub_type - 1]);
10693 len2 = strlen (stub_entry->root.string);
10694 name = bfd_malloc (len1 + len2 + 2);
10697 memcpy (name, stub_entry->root.string, 9);
10698 memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
10699 memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
10700 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
10703 if (h->root.type == bfd_link_hash_new)
10705 h->root.type = bfd_link_hash_defined;
10706 h->root.u.def.section = stub_entry->stub_sec;
10707 h->root.u.def.value = stub_entry->stub_offset;
10708 h->ref_regular = 1;
10709 h->def_regular = 1;
10710 h->ref_regular_nonweak = 1;
10711 h->forced_local = 1;
10719 /* As above, but don't actually build the stub. Just bump offset so
10720 we know stub section sizes, and select plt_branch stubs where
10721 long_branch stubs won't do. */
10724 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10726 struct ppc_stub_hash_entry *stub_entry;
10727 struct bfd_link_info *info;
10728 struct ppc_link_hash_table *htab;
10732 /* Massage our args to the form they really have. */
10733 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10736 htab = ppc_hash_table (info);
10740 if (stub_entry->stub_type == ppc_stub_plt_call
10741 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10744 off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
10745 if (off >= (bfd_vma) -2)
10748 if (!htab->elf.dynamic_sections_created
10749 || stub_entry->h == NULL
10750 || stub_entry->h->elf.dynindx == -1)
10752 off += (plt->output_offset
10753 + plt->output_section->vma
10754 - elf_gp (plt->output_section->owner)
10755 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10757 size = plt_stub_size (htab, stub_entry, off);
10758 if (htab->plt_stub_align)
10759 size += plt_stub_pad (htab, stub_entry, off);
10760 if (info->emitrelocations)
10762 stub_entry->stub_sec->reloc_count
10763 += ((PPC_HA (off) != 0)
10765 ? 2 + (htab->plt_static_chain
10766 && PPC_HA (off + 16) == PPC_HA (off))
10768 stub_entry->stub_sec->flags |= SEC_RELOC;
10773 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
10776 bfd_vma local_off = 0;
10778 off = (stub_entry->target_value
10779 + stub_entry->target_section->output_offset
10780 + stub_entry->target_section->output_section->vma);
10781 off -= (stub_entry->stub_sec->size
10782 + stub_entry->stub_sec->output_offset
10783 + stub_entry->stub_sec->output_section->vma);
10785 /* Reset the stub type from the plt variant in case we now
10786 can reach with a shorter stub. */
10787 if (stub_entry->stub_type >= ppc_stub_plt_branch)
10788 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
10791 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10793 r2off = get_r2off (info, stub_entry);
10794 if (r2off == 0 && htab->opd_abi)
10796 htab->stub_error = TRUE;
10800 if (PPC_HA (r2off) != 0)
10805 local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10807 /* If the branch offset if too big, use a ppc_stub_plt_branch.
10808 Do the same for -R objects without function descriptors. */
10809 if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
10810 || (stub_entry->stub_type == ppc_stub_long_branch_r2off
10813 struct ppc_branch_hash_entry *br_entry;
10815 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
10816 stub_entry->root.string + 9,
10818 if (br_entry == NULL)
10820 info->callbacks->einfo (_("%P: can't build branch stub `%s'\n"),
10821 stub_entry->root.string);
10822 htab->stub_error = TRUE;
10826 if (br_entry->iter != htab->stub_iteration)
10828 br_entry->iter = htab->stub_iteration;
10829 br_entry->offset = htab->brlt->size;
10830 htab->brlt->size += 8;
10832 if (htab->relbrlt != NULL)
10833 htab->relbrlt->size += sizeof (Elf64_External_Rela);
10834 else if (info->emitrelocations)
10836 htab->brlt->reloc_count += 1;
10837 htab->brlt->flags |= SEC_RELOC;
10841 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
10842 off = (br_entry->offset
10843 + htab->brlt->output_offset
10844 + htab->brlt->output_section->vma
10845 - elf_gp (htab->brlt->output_section->owner)
10846 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10848 if (info->emitrelocations)
10850 stub_entry->stub_sec->reloc_count += 1 + (PPC_HA (off) != 0);
10851 stub_entry->stub_sec->flags |= SEC_RELOC;
10854 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
10858 if (PPC_HA (off) != 0)
10864 if (PPC_HA (off) != 0)
10867 if (PPC_HA (r2off) != 0)
10871 else if (info->emitrelocations)
10873 stub_entry->stub_sec->reloc_count += 1;
10874 stub_entry->stub_sec->flags |= SEC_RELOC;
10878 stub_entry->stub_sec->size += size;
10882 /* Set up various things so that we can make a list of input sections
10883 for each output section included in the link. Returns -1 on error,
10884 0 when no stubs will be needed, and 1 on success. */
10887 ppc64_elf_setup_section_lists
10888 (struct bfd_link_info *info,
10889 asection *(*add_stub_section) (const char *, asection *),
10890 void (*layout_sections_again) (void))
10893 int top_id, top_index, id;
10895 asection **input_list;
10897 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10901 /* Stash our params away. */
10902 htab->add_stub_section = add_stub_section;
10903 htab->layout_sections_again = layout_sections_again;
10905 /* Find the top input section id. */
10906 for (input_bfd = info->input_bfds, top_id = 3;
10908 input_bfd = input_bfd->link_next)
10910 for (section = input_bfd->sections;
10912 section = section->next)
10914 if (top_id < section->id)
10915 top_id = section->id;
10919 htab->top_id = top_id;
10920 amt = sizeof (struct map_stub) * (top_id + 1);
10921 htab->stub_group = bfd_zmalloc (amt);
10922 if (htab->stub_group == NULL)
10925 /* Set toc_off for com, und, abs and ind sections. */
10926 for (id = 0; id < 3; id++)
10927 htab->stub_group[id].toc_off = TOC_BASE_OFF;
10929 /* We can't use output_bfd->section_count here to find the top output
10930 section index as some sections may have been removed, and
10931 strip_excluded_output_sections doesn't renumber the indices. */
10932 for (section = info->output_bfd->sections, top_index = 0;
10934 section = section->next)
10936 if (top_index < section->index)
10937 top_index = section->index;
10940 htab->top_index = top_index;
10941 amt = sizeof (asection *) * (top_index + 1);
10942 input_list = bfd_zmalloc (amt);
10943 htab->input_list = input_list;
10944 if (input_list == NULL)
10950 /* Set up for first pass at multitoc partitioning. */
10953 ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
10955 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10957 htab->toc_curr = ppc64_elf_set_toc (info, info->output_bfd);
10958 htab->toc_bfd = NULL;
10959 htab->toc_first_sec = NULL;
10962 /* The linker repeatedly calls this function for each TOC input section
10963 and linker generated GOT section. Group input bfds such that the toc
10964 within a group is less than 64k in size. */
10967 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
10969 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10970 bfd_vma addr, off, limit;
10975 if (!htab->second_toc_pass)
10977 /* Keep track of the first .toc or .got section for this input bfd. */
10978 bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
10982 htab->toc_bfd = isec->owner;
10983 htab->toc_first_sec = isec;
10986 addr = isec->output_offset + isec->output_section->vma;
10987 off = addr - htab->toc_curr;
10988 limit = 0x80008000;
10989 if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc)
10991 if (off + isec->size > limit)
10993 addr = (htab->toc_first_sec->output_offset
10994 + htab->toc_first_sec->output_section->vma);
10995 htab->toc_curr = addr;
10998 /* toc_curr is the base address of this toc group. Set elf_gp
10999 for the input section to be the offset relative to the
11000 output toc base plus 0x8000. Making the input elf_gp an
11001 offset allows us to move the toc as a whole without
11002 recalculating input elf_gp. */
11003 off = htab->toc_curr - elf_gp (isec->output_section->owner);
11004 off += TOC_BASE_OFF;
11006 /* Die if someone uses a linker script that doesn't keep input
11007 file .toc and .got together. */
11009 && elf_gp (isec->owner) != 0
11010 && elf_gp (isec->owner) != off)
11013 elf_gp (isec->owner) = off;
11017 /* During the second pass toc_first_sec points to the start of
11018 a toc group, and toc_curr is used to track the old elf_gp.
11019 We use toc_bfd to ensure we only look at each bfd once. */
11020 if (htab->toc_bfd == isec->owner)
11022 htab->toc_bfd = isec->owner;
11024 if (htab->toc_first_sec == NULL
11025 || htab->toc_curr != elf_gp (isec->owner))
11027 htab->toc_curr = elf_gp (isec->owner);
11028 htab->toc_first_sec = isec;
11030 addr = (htab->toc_first_sec->output_offset
11031 + htab->toc_first_sec->output_section->vma);
11032 off = addr - elf_gp (isec->output_section->owner) + TOC_BASE_OFF;
11033 elf_gp (isec->owner) = off;
11038 /* Called via elf_link_hash_traverse to merge GOT entries for global
11042 merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
11044 if (h->root.type == bfd_link_hash_indirect)
11047 merge_got_entries (&h->got.glist);
11052 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11056 reallocate_got (struct elf_link_hash_entry *h, void *inf)
11058 struct got_entry *gent;
11060 if (h->root.type == bfd_link_hash_indirect)
11063 for (gent = h->got.glist; gent != NULL; gent = gent->next)
11064 if (!gent->is_indirect)
11065 allocate_got (h, (struct bfd_link_info *) inf, gent);
11069 /* Called on the first multitoc pass after the last call to
11070 ppc64_elf_next_toc_section. This function removes duplicate GOT
11074 ppc64_elf_layout_multitoc (struct bfd_link_info *info)
11076 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11077 struct bfd *ibfd, *ibfd2;
11078 bfd_boolean done_something;
11080 htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
11082 if (!htab->do_multi_toc)
11085 /* Merge global sym got entries within a toc group. */
11086 elf_link_hash_traverse (&htab->elf, merge_global_got, info);
11088 /* And tlsld_got. */
11089 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11091 struct got_entry *ent, *ent2;
11093 if (!is_ppc64_elf (ibfd))
11096 ent = ppc64_tlsld_got (ibfd);
11097 if (!ent->is_indirect
11098 && ent->got.offset != (bfd_vma) -1)
11100 for (ibfd2 = ibfd->link_next; ibfd2 != NULL; ibfd2 = ibfd2->link_next)
11102 if (!is_ppc64_elf (ibfd2))
11105 ent2 = ppc64_tlsld_got (ibfd2);
11106 if (!ent2->is_indirect
11107 && ent2->got.offset != (bfd_vma) -1
11108 && elf_gp (ibfd2) == elf_gp (ibfd))
11110 ent2->is_indirect = TRUE;
11111 ent2->got.ent = ent;
11117 /* Zap sizes of got sections. */
11118 htab->reliplt->rawsize = htab->reliplt->size;
11119 htab->reliplt->size -= htab->got_reli_size;
11120 htab->got_reli_size = 0;
11122 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11124 asection *got, *relgot;
11126 if (!is_ppc64_elf (ibfd))
11129 got = ppc64_elf_tdata (ibfd)->got;
11132 got->rawsize = got->size;
11134 relgot = ppc64_elf_tdata (ibfd)->relgot;
11135 relgot->rawsize = relgot->size;
11140 /* Now reallocate the got, local syms first. We don't need to
11141 allocate section contents again since we never increase size. */
11142 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11144 struct got_entry **lgot_ents;
11145 struct got_entry **end_lgot_ents;
11146 struct plt_entry **local_plt;
11147 struct plt_entry **end_local_plt;
11148 unsigned char *lgot_masks;
11149 bfd_size_type locsymcount;
11150 Elf_Internal_Shdr *symtab_hdr;
11153 if (!is_ppc64_elf (ibfd))
11156 lgot_ents = elf_local_got_ents (ibfd);
11160 symtab_hdr = &elf_symtab_hdr (ibfd);
11161 locsymcount = symtab_hdr->sh_info;
11162 end_lgot_ents = lgot_ents + locsymcount;
11163 local_plt = (struct plt_entry **) end_lgot_ents;
11164 end_local_plt = local_plt + locsymcount;
11165 lgot_masks = (unsigned char *) end_local_plt;
11166 s = ppc64_elf_tdata (ibfd)->got;
11167 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
11169 struct got_entry *ent;
11171 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
11173 unsigned int ent_size = 8;
11174 unsigned int rel_size = sizeof (Elf64_External_Rela);
11176 ent->got.offset = s->size;
11177 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
11182 s->size += ent_size;
11183 if ((*lgot_masks & PLT_IFUNC) != 0)
11185 htab->reliplt->size += rel_size;
11186 htab->got_reli_size += rel_size;
11188 else if (info->shared)
11190 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11191 srel->size += rel_size;
11197 elf_link_hash_traverse (&htab->elf, reallocate_got, info);
11199 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11201 struct got_entry *ent;
11203 if (!is_ppc64_elf (ibfd))
11206 ent = ppc64_tlsld_got (ibfd);
11207 if (!ent->is_indirect
11208 && ent->got.offset != (bfd_vma) -1)
11210 asection *s = ppc64_elf_tdata (ibfd)->got;
11211 ent->got.offset = s->size;
11215 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11216 srel->size += sizeof (Elf64_External_Rela);
11221 done_something = htab->reliplt->rawsize != htab->reliplt->size;
11222 if (!done_something)
11223 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11227 if (!is_ppc64_elf (ibfd))
11230 got = ppc64_elf_tdata (ibfd)->got;
11233 done_something = got->rawsize != got->size;
11234 if (done_something)
11239 if (done_something)
11240 (*htab->layout_sections_again) ();
11242 /* Set up for second pass over toc sections to recalculate elf_gp
11243 on input sections. */
11244 htab->toc_bfd = NULL;
11245 htab->toc_first_sec = NULL;
11246 htab->second_toc_pass = TRUE;
11247 return done_something;
11250 /* Called after second pass of multitoc partitioning. */
11253 ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info)
11255 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11257 /* After the second pass, toc_curr tracks the TOC offset used
11258 for code sections below in ppc64_elf_next_input_section. */
11259 htab->toc_curr = TOC_BASE_OFF;
11262 /* No toc references were found in ISEC. If the code in ISEC makes no
11263 calls, then there's no need to use toc adjusting stubs when branching
11264 into ISEC. Actually, indirect calls from ISEC are OK as they will
11265 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11266 needed, and 2 if a cyclical call-graph was found but no other reason
11267 for a stub was detected. If called from the top level, a return of
11268 2 means the same as a return of 0. */
11271 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
11275 /* Mark this section as checked. */
11276 isec->call_check_done = 1;
11278 /* We know none of our code bearing sections will need toc stubs. */
11279 if ((isec->flags & SEC_LINKER_CREATED) != 0)
11282 if (isec->size == 0)
11285 if (isec->output_section == NULL)
11289 if (isec->reloc_count != 0)
11291 Elf_Internal_Rela *relstart, *rel;
11292 Elf_Internal_Sym *local_syms;
11293 struct ppc_link_hash_table *htab;
11295 relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
11296 info->keep_memory);
11297 if (relstart == NULL)
11300 /* Look for branches to outside of this section. */
11302 htab = ppc_hash_table (info);
11306 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
11308 enum elf_ppc64_reloc_type r_type;
11309 unsigned long r_symndx;
11310 struct elf_link_hash_entry *h;
11311 struct ppc_link_hash_entry *eh;
11312 Elf_Internal_Sym *sym;
11314 struct _opd_sec_data *opd;
11318 r_type = ELF64_R_TYPE (rel->r_info);
11319 if (r_type != R_PPC64_REL24
11320 && r_type != R_PPC64_REL14
11321 && r_type != R_PPC64_REL14_BRTAKEN
11322 && r_type != R_PPC64_REL14_BRNTAKEN)
11325 r_symndx = ELF64_R_SYM (rel->r_info);
11326 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
11333 /* Calls to dynamic lib functions go through a plt call stub
11335 eh = (struct ppc_link_hash_entry *) h;
11337 && (eh->elf.plt.plist != NULL
11339 && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
11345 if (sym_sec == NULL)
11346 /* Ignore other undefined symbols. */
11349 /* Assume branches to other sections not included in the
11350 link need stubs too, to cover -R and absolute syms. */
11351 if (sym_sec->output_section == NULL)
11358 sym_value = sym->st_value;
11361 if (h->root.type != bfd_link_hash_defined
11362 && h->root.type != bfd_link_hash_defweak)
11364 sym_value = h->root.u.def.value;
11366 sym_value += rel->r_addend;
11368 /* If this branch reloc uses an opd sym, find the code section. */
11369 opd = get_opd_info (sym_sec);
11372 if (h == NULL && opd->adjust != NULL)
11376 adjust = opd->adjust[sym->st_value / 8];
11378 /* Assume deleted functions won't ever be called. */
11380 sym_value += adjust;
11383 dest = opd_entry_value (sym_sec, sym_value,
11384 &sym_sec, NULL, FALSE);
11385 if (dest == (bfd_vma) -1)
11390 + sym_sec->output_offset
11391 + sym_sec->output_section->vma);
11393 /* Ignore branch to self. */
11394 if (sym_sec == isec)
11397 /* If the called function uses the toc, we need a stub. */
11398 if (sym_sec->has_toc_reloc
11399 || sym_sec->makes_toc_func_call)
11405 /* Assume any branch that needs a long branch stub might in fact
11406 need a plt_branch stub. A plt_branch stub uses r2. */
11407 else if (dest - (isec->output_offset
11408 + isec->output_section->vma
11409 + rel->r_offset) + (1 << 25)
11410 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11418 /* If calling back to a section in the process of being
11419 tested, we can't say for sure that no toc adjusting stubs
11420 are needed, so don't return zero. */
11421 else if (sym_sec->call_check_in_progress)
11424 /* Branches to another section that itself doesn't have any TOC
11425 references are OK. Recursively call ourselves to check. */
11426 else if (!sym_sec->call_check_done)
11430 /* Mark current section as indeterminate, so that other
11431 sections that call back to current won't be marked as
11433 isec->call_check_in_progress = 1;
11434 recur = toc_adjusting_stub_needed (info, sym_sec);
11435 isec->call_check_in_progress = 0;
11446 if (local_syms != NULL
11447 && (elf_symtab_hdr (isec->owner).contents
11448 != (unsigned char *) local_syms))
11450 if (elf_section_data (isec)->relocs != relstart)
11455 && isec->map_head.s != NULL
11456 && (strcmp (isec->output_section->name, ".init") == 0
11457 || strcmp (isec->output_section->name, ".fini") == 0))
11459 if (isec->map_head.s->has_toc_reloc
11460 || isec->map_head.s->makes_toc_func_call)
11462 else if (!isec->map_head.s->call_check_done)
11465 isec->call_check_in_progress = 1;
11466 recur = toc_adjusting_stub_needed (info, isec->map_head.s);
11467 isec->call_check_in_progress = 0;
11474 isec->makes_toc_func_call = 1;
11479 /* The linker repeatedly calls this function for each input section,
11480 in the order that input sections are linked into output sections.
11481 Build lists of input sections to determine groupings between which
11482 we may insert linker stubs. */
11485 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
11487 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11492 if ((isec->output_section->flags & SEC_CODE) != 0
11493 && isec->output_section->index <= htab->top_index)
11495 asection **list = htab->input_list + isec->output_section->index;
11496 /* Steal the link_sec pointer for our list. */
11497 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
11498 /* This happens to make the list in reverse order,
11499 which is what we want. */
11500 PREV_SEC (isec) = *list;
11504 if (htab->multi_toc_needed)
11506 /* If a code section has a function that uses the TOC then we need
11507 to use the right TOC (obviously). Also, make sure that .opd gets
11508 the correct TOC value for R_PPC64_TOC relocs that don't have or
11509 can't find their function symbol (shouldn't ever happen now).
11510 Also specially treat .fixup for the linux kernel. .fixup
11511 contains branches, but only back to the function that hit an
11513 if (isec->has_toc_reloc
11514 || (isec->flags & SEC_CODE) == 0
11515 || strcmp (isec->name, ".fixup") == 0)
11517 if (elf_gp (isec->owner) != 0)
11518 htab->toc_curr = elf_gp (isec->owner);
11522 if (!isec->call_check_done
11523 && toc_adjusting_stub_needed (info, isec) < 0)
11525 /* If we make a local call from this section, ie. a branch
11526 without a following nop, then we have no place to put a
11527 toc restoring insn. We must use the same toc group as
11529 Testing makes_toc_func_call actually tests for *any*
11530 calls to functions that need a good toc pointer. A more
11531 precise test would be better, as this one will set
11532 incorrect values for pasted .init/.fini fragments.
11533 (Fixed later in check_pasted_section.) */
11534 if (isec->makes_toc_func_call
11535 && elf_gp (isec->owner) != 0)
11536 htab->toc_curr = elf_gp (isec->owner);
11540 /* Functions that don't use the TOC can belong in any TOC group.
11541 Use the last TOC base. */
11542 htab->stub_group[isec->id].toc_off = htab->toc_curr;
11546 /* Check that all .init and .fini sections use the same toc, if they
11547 have toc relocs. */
11550 check_pasted_section (struct bfd_link_info *info, const char *name)
11552 asection *o = bfd_get_section_by_name (info->output_bfd, name);
11556 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11557 bfd_vma toc_off = 0;
11560 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11561 if (i->has_toc_reloc)
11564 toc_off = htab->stub_group[i->id].toc_off;
11565 else if (toc_off != htab->stub_group[i->id].toc_off)
11570 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11571 if (i->makes_toc_func_call)
11573 toc_off = htab->stub_group[i->id].toc_off;
11577 /* Make sure the whole pasted function uses the same toc offset. */
11579 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11580 htab->stub_group[i->id].toc_off = toc_off;
11586 ppc64_elf_check_init_fini (struct bfd_link_info *info)
11588 return (check_pasted_section (info, ".init")
11589 & check_pasted_section (info, ".fini"));
11592 /* See whether we can group stub sections together. Grouping stub
11593 sections may result in fewer stubs. More importantly, we need to
11594 put all .init* and .fini* stubs at the beginning of the .init or
11595 .fini output sections respectively, because glibc splits the
11596 _init and _fini functions into multiple parts. Putting a stub in
11597 the middle of a function is not a good idea. */
11600 group_sections (struct ppc_link_hash_table *htab,
11601 bfd_size_type stub_group_size,
11602 bfd_boolean stubs_always_before_branch)
11605 bfd_size_type stub14_group_size;
11606 bfd_boolean suppress_size_errors;
11608 suppress_size_errors = FALSE;
11609 stub14_group_size = stub_group_size;
11610 if (stub_group_size == 1)
11612 /* Default values. */
11613 if (stubs_always_before_branch)
11615 stub_group_size = 0x1e00000;
11616 stub14_group_size = 0x7800;
11620 stub_group_size = 0x1c00000;
11621 stub14_group_size = 0x7000;
11623 suppress_size_errors = TRUE;
11626 list = htab->input_list + htab->top_index;
11629 asection *tail = *list;
11630 while (tail != NULL)
11634 bfd_size_type total;
11635 bfd_boolean big_sec;
11639 total = tail->size;
11640 big_sec = total > (ppc64_elf_section_data (tail) != NULL
11641 && ppc64_elf_section_data (tail)->has_14bit_branch
11642 ? stub14_group_size : stub_group_size);
11643 if (big_sec && !suppress_size_errors)
11644 (*_bfd_error_handler) (_("%B section %A exceeds stub group size"),
11645 tail->owner, tail);
11646 curr_toc = htab->stub_group[tail->id].toc_off;
11648 while ((prev = PREV_SEC (curr)) != NULL
11649 && ((total += curr->output_offset - prev->output_offset)
11650 < (ppc64_elf_section_data (prev) != NULL
11651 && ppc64_elf_section_data (prev)->has_14bit_branch
11652 ? stub14_group_size : stub_group_size))
11653 && htab->stub_group[prev->id].toc_off == curr_toc)
11656 /* OK, the size from the start of CURR to the end is less
11657 than stub_group_size and thus can be handled by one stub
11658 section. (or the tail section is itself larger than
11659 stub_group_size, in which case we may be toast.) We
11660 should really be keeping track of the total size of stubs
11661 added here, as stubs contribute to the final output
11662 section size. That's a little tricky, and this way will
11663 only break if stubs added make the total size more than
11664 2^25, ie. for the default stub_group_size, if stubs total
11665 more than 2097152 bytes, or nearly 75000 plt call stubs. */
11668 prev = PREV_SEC (tail);
11669 /* Set up this stub group. */
11670 htab->stub_group[tail->id].link_sec = curr;
11672 while (tail != curr && (tail = prev) != NULL);
11674 /* But wait, there's more! Input sections up to stub_group_size
11675 bytes before the stub section can be handled by it too.
11676 Don't do this if we have a really large section after the
11677 stubs, as adding more stubs increases the chance that
11678 branches may not reach into the stub section. */
11679 if (!stubs_always_before_branch && !big_sec)
11682 while (prev != NULL
11683 && ((total += tail->output_offset - prev->output_offset)
11684 < (ppc64_elf_section_data (prev) != NULL
11685 && ppc64_elf_section_data (prev)->has_14bit_branch
11686 ? stub14_group_size : stub_group_size))
11687 && htab->stub_group[prev->id].toc_off == curr_toc)
11690 prev = PREV_SEC (tail);
11691 htab->stub_group[tail->id].link_sec = curr;
11697 while (list-- != htab->input_list);
11698 free (htab->input_list);
11702 static const unsigned char glink_eh_frame_cie[] =
11704 0, 0, 0, 16, /* length. */
11705 0, 0, 0, 0, /* id. */
11706 1, /* CIE version. */
11707 'z', 'R', 0, /* Augmentation string. */
11708 4, /* Code alignment. */
11709 0x78, /* Data alignment. */
11711 1, /* Augmentation size. */
11712 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
11713 DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
11716 /* Stripping output sections is normally done before dynamic section
11717 symbols have been allocated. This function is called later, and
11718 handles cases like htab->brlt which is mapped to its own output
11722 maybe_strip_output (struct bfd_link_info *info, asection *isec)
11724 if (isec->size == 0
11725 && isec->output_section->size == 0
11726 && !(isec->output_section->flags & SEC_KEEP)
11727 && !bfd_section_removed_from_list (info->output_bfd,
11728 isec->output_section)
11729 && elf_section_data (isec->output_section)->dynindx == 0)
11731 isec->output_section->flags |= SEC_EXCLUDE;
11732 bfd_section_list_remove (info->output_bfd, isec->output_section);
11733 info->output_bfd->section_count--;
11737 /* Determine and set the size of the stub section for a final link.
11739 The basic idea here is to examine all the relocations looking for
11740 PC-relative calls to a target that is unreachable with a "bl"
11744 ppc64_elf_size_stubs (struct bfd_link_info *info, bfd_signed_vma group_size,
11745 bfd_boolean plt_static_chain, int plt_thread_safe,
11746 int plt_stub_align)
11748 bfd_size_type stub_group_size;
11749 bfd_boolean stubs_always_before_branch;
11750 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11755 htab->plt_static_chain = plt_static_chain;
11756 htab->plt_stub_align = plt_stub_align;
11757 if (plt_thread_safe == -1 && !info->executable)
11758 plt_thread_safe = 1;
11759 if (!htab->opd_abi)
11760 plt_thread_safe = 0;
11761 else if (plt_thread_safe == -1)
11763 static const char *const thread_starter[] =
11767 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
11769 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
11770 "mq_notify", "create_timer",
11774 "GOMP_parallel_start",
11775 "GOMP_parallel_loop_static_start",
11776 "GOMP_parallel_loop_dynamic_start",
11777 "GOMP_parallel_loop_guided_start",
11778 "GOMP_parallel_loop_runtime_start",
11779 "GOMP_parallel_sections_start",
11783 for (i = 0; i < sizeof (thread_starter)/ sizeof (thread_starter[0]); i++)
11785 struct elf_link_hash_entry *h;
11786 h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
11787 FALSE, FALSE, TRUE);
11788 plt_thread_safe = h != NULL && h->ref_regular;
11789 if (plt_thread_safe)
11793 htab->plt_thread_safe = plt_thread_safe;
11794 stubs_always_before_branch = group_size < 0;
11795 if (group_size < 0)
11796 stub_group_size = -group_size;
11798 stub_group_size = group_size;
11800 group_sections (htab, stub_group_size, stubs_always_before_branch);
11805 unsigned int bfd_indx;
11806 asection *stub_sec;
11808 htab->stub_iteration += 1;
11810 for (input_bfd = info->input_bfds, bfd_indx = 0;
11812 input_bfd = input_bfd->link_next, bfd_indx++)
11814 Elf_Internal_Shdr *symtab_hdr;
11816 Elf_Internal_Sym *local_syms = NULL;
11818 if (!is_ppc64_elf (input_bfd))
11821 /* We'll need the symbol table in a second. */
11822 symtab_hdr = &elf_symtab_hdr (input_bfd);
11823 if (symtab_hdr->sh_info == 0)
11826 /* Walk over each section attached to the input bfd. */
11827 for (section = input_bfd->sections;
11829 section = section->next)
11831 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
11833 /* If there aren't any relocs, then there's nothing more
11835 if ((section->flags & SEC_RELOC) == 0
11836 || (section->flags & SEC_ALLOC) == 0
11837 || (section->flags & SEC_LOAD) == 0
11838 || (section->flags & SEC_CODE) == 0
11839 || section->reloc_count == 0)
11842 /* If this section is a link-once section that will be
11843 discarded, then don't create any stubs. */
11844 if (section->output_section == NULL
11845 || section->output_section->owner != info->output_bfd)
11848 /* Get the relocs. */
11850 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
11851 info->keep_memory);
11852 if (internal_relocs == NULL)
11853 goto error_ret_free_local;
11855 /* Now examine each relocation. */
11856 irela = internal_relocs;
11857 irelaend = irela + section->reloc_count;
11858 for (; irela < irelaend; irela++)
11860 enum elf_ppc64_reloc_type r_type;
11861 unsigned int r_indx;
11862 enum ppc_stub_type stub_type;
11863 struct ppc_stub_hash_entry *stub_entry;
11864 asection *sym_sec, *code_sec;
11865 bfd_vma sym_value, code_value;
11866 bfd_vma destination;
11867 unsigned long local_off;
11868 bfd_boolean ok_dest;
11869 struct ppc_link_hash_entry *hash;
11870 struct ppc_link_hash_entry *fdh;
11871 struct elf_link_hash_entry *h;
11872 Elf_Internal_Sym *sym;
11874 const asection *id_sec;
11875 struct _opd_sec_data *opd;
11876 struct plt_entry *plt_ent;
11878 r_type = ELF64_R_TYPE (irela->r_info);
11879 r_indx = ELF64_R_SYM (irela->r_info);
11881 if (r_type >= R_PPC64_max)
11883 bfd_set_error (bfd_error_bad_value);
11884 goto error_ret_free_internal;
11887 /* Only look for stubs on branch instructions. */
11888 if (r_type != R_PPC64_REL24
11889 && r_type != R_PPC64_REL14
11890 && r_type != R_PPC64_REL14_BRTAKEN
11891 && r_type != R_PPC64_REL14_BRNTAKEN)
11894 /* Now determine the call target, its name, value,
11896 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
11897 r_indx, input_bfd))
11898 goto error_ret_free_internal;
11899 hash = (struct ppc_link_hash_entry *) h;
11906 sym_value = sym->st_value;
11909 else if (hash->elf.root.type == bfd_link_hash_defined
11910 || hash->elf.root.type == bfd_link_hash_defweak)
11912 sym_value = hash->elf.root.u.def.value;
11913 if (sym_sec->output_section != NULL)
11916 else if (hash->elf.root.type == bfd_link_hash_undefweak
11917 || hash->elf.root.type == bfd_link_hash_undefined)
11919 /* Recognise an old ABI func code entry sym, and
11920 use the func descriptor sym instead if it is
11922 if (hash->elf.root.root.string[0] == '.'
11923 && (fdh = lookup_fdh (hash, htab)) != NULL)
11925 if (fdh->elf.root.type == bfd_link_hash_defined
11926 || fdh->elf.root.type == bfd_link_hash_defweak)
11928 sym_sec = fdh->elf.root.u.def.section;
11929 sym_value = fdh->elf.root.u.def.value;
11930 if (sym_sec->output_section != NULL)
11939 bfd_set_error (bfd_error_bad_value);
11940 goto error_ret_free_internal;
11947 sym_value += irela->r_addend;
11948 destination = (sym_value
11949 + sym_sec->output_offset
11950 + sym_sec->output_section->vma);
11951 local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
11956 code_sec = sym_sec;
11957 code_value = sym_value;
11958 opd = get_opd_info (sym_sec);
11963 if (hash == NULL && opd->adjust != NULL)
11965 long adjust = opd->adjust[sym_value / 8];
11968 code_value += adjust;
11969 sym_value += adjust;
11971 dest = opd_entry_value (sym_sec, sym_value,
11972 &code_sec, &code_value, FALSE);
11973 if (dest != (bfd_vma) -1)
11975 destination = dest;
11978 /* Fixup old ABI sym to point at code
11980 hash->elf.root.type = bfd_link_hash_defweak;
11981 hash->elf.root.u.def.section = code_sec;
11982 hash->elf.root.u.def.value = code_value;
11987 /* Determine what (if any) linker stub is needed. */
11989 stub_type = ppc_type_of_stub (section, irela, &hash,
11990 &plt_ent, destination,
11993 if (stub_type != ppc_stub_plt_call)
11995 /* Check whether we need a TOC adjusting stub.
11996 Since the linker pastes together pieces from
11997 different object files when creating the
11998 _init and _fini functions, it may be that a
11999 call to what looks like a local sym is in
12000 fact a call needing a TOC adjustment. */
12001 if (code_sec != NULL
12002 && code_sec->output_section != NULL
12003 && (htab->stub_group[code_sec->id].toc_off
12004 != htab->stub_group[section->id].toc_off)
12005 && (code_sec->has_toc_reloc
12006 || code_sec->makes_toc_func_call))
12007 stub_type = ppc_stub_long_branch_r2off;
12010 if (stub_type == ppc_stub_none)
12013 /* __tls_get_addr calls might be eliminated. */
12014 if (stub_type != ppc_stub_plt_call
12016 && (hash == htab->tls_get_addr
12017 || hash == htab->tls_get_addr_fd)
12018 && section->has_tls_reloc
12019 && irela != internal_relocs)
12021 /* Get tls info. */
12022 unsigned char *tls_mask;
12024 if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
12025 irela - 1, input_bfd))
12026 goto error_ret_free_internal;
12027 if (*tls_mask != 0)
12031 if (stub_type == ppc_stub_plt_call
12032 && irela + 1 < irelaend
12033 && irela[1].r_offset == irela->r_offset + 4
12034 && ELF64_R_TYPE (irela[1].r_info) == R_PPC64_TOCSAVE)
12036 if (!tocsave_find (htab, INSERT,
12037 &local_syms, irela + 1, input_bfd))
12038 goto error_ret_free_internal;
12040 else if (stub_type == ppc_stub_plt_call)
12041 stub_type = ppc_stub_plt_call_r2save;
12043 /* Support for grouping stub sections. */
12044 id_sec = htab->stub_group[section->id].link_sec;
12046 /* Get the name of this stub. */
12047 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
12049 goto error_ret_free_internal;
12051 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
12052 stub_name, FALSE, FALSE);
12053 if (stub_entry != NULL)
12055 /* The proper stub has already been created. */
12057 if (stub_type == ppc_stub_plt_call_r2save)
12058 stub_entry->stub_type = stub_type;
12062 stub_entry = ppc_add_stub (stub_name, section, info);
12063 if (stub_entry == NULL)
12066 error_ret_free_internal:
12067 if (elf_section_data (section)->relocs == NULL)
12068 free (internal_relocs);
12069 error_ret_free_local:
12070 if (local_syms != NULL
12071 && (symtab_hdr->contents
12072 != (unsigned char *) local_syms))
12077 stub_entry->stub_type = stub_type;
12078 if (stub_type != ppc_stub_plt_call
12079 && stub_type != ppc_stub_plt_call_r2save)
12081 stub_entry->target_value = code_value;
12082 stub_entry->target_section = code_sec;
12086 stub_entry->target_value = sym_value;
12087 stub_entry->target_section = sym_sec;
12089 stub_entry->h = hash;
12090 stub_entry->plt_ent = plt_ent;
12091 stub_entry->other = hash ? hash->elf.other : sym->st_other;
12093 if (stub_entry->h != NULL)
12094 htab->stub_globals += 1;
12097 /* We're done with the internal relocs, free them. */
12098 if (elf_section_data (section)->relocs != internal_relocs)
12099 free (internal_relocs);
12102 if (local_syms != NULL
12103 && symtab_hdr->contents != (unsigned char *) local_syms)
12105 if (!info->keep_memory)
12108 symtab_hdr->contents = (unsigned char *) local_syms;
12112 /* We may have added some stubs. Find out the new size of the
12114 for (stub_sec = htab->stub_bfd->sections;
12116 stub_sec = stub_sec->next)
12117 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12119 stub_sec->rawsize = stub_sec->size;
12120 stub_sec->size = 0;
12121 stub_sec->reloc_count = 0;
12122 stub_sec->flags &= ~SEC_RELOC;
12125 htab->brlt->size = 0;
12126 htab->brlt->reloc_count = 0;
12127 htab->brlt->flags &= ~SEC_RELOC;
12128 if (htab->relbrlt != NULL)
12129 htab->relbrlt->size = 0;
12131 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
12133 if (info->emitrelocations
12134 && htab->glink != NULL && htab->glink->size != 0)
12136 htab->glink->reloc_count = 1;
12137 htab->glink->flags |= SEC_RELOC;
12140 if (htab->glink_eh_frame != NULL
12141 && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
12142 && htab->glink_eh_frame->output_section->size != 0)
12144 size_t size = 0, align;
12146 for (stub_sec = htab->stub_bfd->sections;
12148 stub_sec = stub_sec->next)
12149 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12151 if (htab->glink != NULL && htab->glink->size != 0)
12154 size += sizeof (glink_eh_frame_cie);
12156 align <<= htab->glink_eh_frame->output_section->alignment_power;
12158 size = (size + align) & ~align;
12159 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12160 htab->glink_eh_frame->size = size;
12163 if (htab->plt_stub_align != 0)
12164 for (stub_sec = htab->stub_bfd->sections;
12166 stub_sec = stub_sec->next)
12167 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12168 stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
12169 & (-1 << htab->plt_stub_align));
12171 for (stub_sec = htab->stub_bfd->sections;
12173 stub_sec = stub_sec->next)
12174 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
12175 && stub_sec->rawsize != stub_sec->size)
12178 /* Exit from this loop when no stubs have been added, and no stubs
12179 have changed size. */
12180 if (stub_sec == NULL
12181 && (htab->glink_eh_frame == NULL
12182 || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
12185 /* Ask the linker to do its stuff. */
12186 (*htab->layout_sections_again) ();
12189 maybe_strip_output (info, htab->brlt);
12190 if (htab->glink_eh_frame != NULL)
12191 maybe_strip_output (info, htab->glink_eh_frame);
12196 /* Called after we have determined section placement. If sections
12197 move, we'll be called again. Provide a value for TOCstart. */
12200 ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
12205 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12206 order. The TOC starts where the first of these sections starts. */
12207 s = bfd_get_section_by_name (obfd, ".got");
12208 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12209 s = bfd_get_section_by_name (obfd, ".toc");
12210 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12211 s = bfd_get_section_by_name (obfd, ".tocbss");
12212 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12213 s = bfd_get_section_by_name (obfd, ".plt");
12214 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12216 /* This may happen for
12217 o references to TOC base (SYM@toc / TOC[tc0]) without a
12219 o bad linker script
12220 o --gc-sections and empty TOC sections
12222 FIXME: Warn user? */
12224 /* Look for a likely section. We probably won't even be
12226 for (s = obfd->sections; s != NULL; s = s->next)
12227 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
12229 == (SEC_ALLOC | SEC_SMALL_DATA))
12232 for (s = obfd->sections; s != NULL; s = s->next)
12233 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
12234 == (SEC_ALLOC | SEC_SMALL_DATA))
12237 for (s = obfd->sections; s != NULL; s = s->next)
12238 if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
12242 for (s = obfd->sections; s != NULL; s = s->next)
12243 if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
12249 TOCstart = s->output_section->vma + s->output_offset;
12251 _bfd_set_gp_value (obfd, TOCstart);
12253 if (info != NULL && s != NULL && is_ppc64_elf (obfd))
12255 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12258 && htab->elf.hgot != NULL)
12260 htab->elf.hgot->type = STT_OBJECT;
12261 htab->elf.hgot->root.type = bfd_link_hash_defined;
12262 htab->elf.hgot->root.u.def.value = TOC_BASE_OFF;
12263 htab->elf.hgot->root.u.def.section = s;
12269 /* Build all the stubs associated with the current output file.
12270 The stubs are kept in a hash table attached to the main linker
12271 hash table. This function is called via gldelf64ppc_finish. */
12274 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms,
12275 struct bfd_link_info *info,
12278 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12279 asection *stub_sec;
12281 int stub_sec_count = 0;
12286 htab->emit_stub_syms = emit_stub_syms;
12288 /* Allocate memory to hold the linker stubs. */
12289 for (stub_sec = htab->stub_bfd->sections;
12291 stub_sec = stub_sec->next)
12292 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
12293 && stub_sec->size != 0)
12295 stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
12296 if (stub_sec->contents == NULL)
12298 /* We want to check that built size is the same as calculated
12299 size. rawsize is a convenient location to use. */
12300 stub_sec->rawsize = stub_sec->size;
12301 stub_sec->size = 0;
12304 if (htab->glink != NULL && htab->glink->size != 0)
12309 /* Build the .glink plt call stub. */
12310 if (htab->emit_stub_syms)
12312 struct elf_link_hash_entry *h;
12313 h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
12314 TRUE, FALSE, FALSE);
12317 if (h->root.type == bfd_link_hash_new)
12319 h->root.type = bfd_link_hash_defined;
12320 h->root.u.def.section = htab->glink;
12321 h->root.u.def.value = 8;
12322 h->ref_regular = 1;
12323 h->def_regular = 1;
12324 h->ref_regular_nonweak = 1;
12325 h->forced_local = 1;
12329 plt0 = htab->plt->output_section->vma + htab->plt->output_offset - 16;
12330 if (info->emitrelocations)
12332 Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
12335 r->r_offset = (htab->glink->output_offset
12336 + htab->glink->output_section->vma);
12337 r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
12338 r->r_addend = plt0;
12340 p = htab->glink->contents;
12341 plt0 -= htab->glink->output_section->vma + htab->glink->output_offset;
12342 bfd_put_64 (htab->glink->owner, plt0, p);
12346 bfd_put_32 (htab->glink->owner, MFLR_R12, p);
12348 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
12350 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
12352 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
12354 bfd_put_32 (htab->glink->owner, MTLR_R12, p);
12356 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
12358 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
12360 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
12362 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
12364 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
12369 bfd_put_32 (htab->glink->owner, MFLR_R0, p);
12371 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
12373 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
12375 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
12377 bfd_put_32 (htab->glink->owner, MTLR_R0, p);
12379 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
12381 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
12383 bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
12385 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
12387 bfd_put_32 (htab->glink->owner, SRDI_R0_R0_2, p);
12389 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
12391 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 8, p);
12394 bfd_put_32 (htab->glink->owner, BCTR, p);
12396 while (p - htab->glink->contents < GLINK_CALL_STUB_SIZE)
12398 bfd_put_32 (htab->glink->owner, NOP, p);
12402 /* Build the .glink lazy link call stubs. */
12404 while (p < htab->glink->contents + htab->glink->size)
12410 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
12415 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
12417 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx),
12422 bfd_put_32 (htab->glink->owner,
12423 B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
12427 htab->glink->rawsize = p - htab->glink->contents;
12430 if (htab->brlt->size != 0)
12432 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
12434 if (htab->brlt->contents == NULL)
12437 if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
12439 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
12440 htab->relbrlt->size);
12441 if (htab->relbrlt->contents == NULL)
12445 if (htab->glink_eh_frame != NULL
12446 && htab->glink_eh_frame->size != 0)
12449 bfd_byte *last_fde;
12450 size_t last_fde_len, size, align, pad;
12452 p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
12455 htab->glink_eh_frame->contents = p;
12458 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12460 memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
12461 /* CIE length (rewrite in case little-endian). */
12462 last_fde_len = sizeof (glink_eh_frame_cie) - 4;
12463 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12464 p += sizeof (glink_eh_frame_cie);
12466 for (stub_sec = htab->stub_bfd->sections;
12468 stub_sec = stub_sec->next)
12469 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12474 bfd_put_32 (htab->elf.dynobj, 16, p);
12477 val = p - htab->glink_eh_frame->contents;
12478 bfd_put_32 (htab->elf.dynobj, val, p);
12480 /* Offset to stub section. */
12481 val = (stub_sec->output_section->vma
12482 + stub_sec->output_offset);
12483 val -= (htab->glink_eh_frame->output_section->vma
12484 + htab->glink_eh_frame->output_offset);
12485 val -= p - htab->glink_eh_frame->contents;
12486 if (val + 0x80000000 > 0xffffffff)
12488 info->callbacks->einfo
12489 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
12493 bfd_put_32 (htab->elf.dynobj, val, p);
12495 /* stub section size. */
12496 bfd_put_32 (htab->elf.dynobj, stub_sec->rawsize, p);
12498 /* Augmentation. */
12503 if (htab->glink != NULL && htab->glink->size != 0)
12508 bfd_put_32 (htab->elf.dynobj, 20, p);
12511 val = p - htab->glink_eh_frame->contents;
12512 bfd_put_32 (htab->elf.dynobj, val, p);
12514 /* Offset to .glink. */
12515 val = (htab->glink->output_section->vma
12516 + htab->glink->output_offset
12518 val -= (htab->glink_eh_frame->output_section->vma
12519 + htab->glink_eh_frame->output_offset);
12520 val -= p - htab->glink_eh_frame->contents;
12521 if (val + 0x80000000 > 0xffffffff)
12523 info->callbacks->einfo
12524 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
12525 htab->glink->name);
12528 bfd_put_32 (htab->elf.dynobj, val, p);
12531 bfd_put_32 (htab->elf.dynobj, htab->glink->rawsize - 8, p);
12533 /* Augmentation. */
12536 *p++ = DW_CFA_advance_loc + 1;
12537 *p++ = DW_CFA_register;
12540 *p++ = DW_CFA_advance_loc + 4;
12541 *p++ = DW_CFA_restore_extended;
12544 /* Subsume any padding into the last FDE if user .eh_frame
12545 sections are aligned more than glink_eh_frame. Otherwise any
12546 zero padding will be seen as a terminator. */
12547 size = p - htab->glink_eh_frame->contents;
12549 align <<= htab->glink_eh_frame->output_section->alignment_power;
12551 pad = ((size + align) & ~align) - size;
12552 htab->glink_eh_frame->size = size + pad;
12553 bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
12556 /* Build the stubs as directed by the stub hash table. */
12557 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
12559 if (htab->relbrlt != NULL)
12560 htab->relbrlt->reloc_count = 0;
12562 if (htab->plt_stub_align != 0)
12563 for (stub_sec = htab->stub_bfd->sections;
12565 stub_sec = stub_sec->next)
12566 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12567 stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
12568 & (-1 << htab->plt_stub_align));
12570 for (stub_sec = htab->stub_bfd->sections;
12572 stub_sec = stub_sec->next)
12573 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12575 stub_sec_count += 1;
12576 if (stub_sec->rawsize != stub_sec->size)
12580 if (stub_sec != NULL
12581 || htab->glink->rawsize != htab->glink->size
12582 || (htab->glink_eh_frame != NULL
12583 && htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size))
12585 htab->stub_error = TRUE;
12586 info->callbacks->einfo (_("%P: stubs don't match calculated size\n"));
12589 if (htab->stub_error)
12594 *stats = bfd_malloc (500);
12595 if (*stats == NULL)
12598 sprintf (*stats, _("linker stubs in %u group%s\n"
12600 " toc adjust %lu\n"
12601 " long branch %lu\n"
12602 " long toc adj %lu\n"
12604 " plt call toc %lu"),
12606 stub_sec_count == 1 ? "" : "s",
12607 htab->stub_count[ppc_stub_long_branch - 1],
12608 htab->stub_count[ppc_stub_long_branch_r2off - 1],
12609 htab->stub_count[ppc_stub_plt_branch - 1],
12610 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
12611 htab->stub_count[ppc_stub_plt_call - 1],
12612 htab->stub_count[ppc_stub_plt_call_r2save - 1]);
12617 /* This function undoes the changes made by add_symbol_adjust. */
12620 undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
12622 struct ppc_link_hash_entry *eh;
12624 if (h->root.type == bfd_link_hash_indirect)
12627 eh = (struct ppc_link_hash_entry *) h;
12628 if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined)
12631 eh->elf.root.type = bfd_link_hash_undefined;
12636 ppc64_elf_restore_symbols (struct bfd_link_info *info)
12638 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12641 elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info);
12644 /* What to do when ld finds relocations against symbols defined in
12645 discarded sections. */
12647 static unsigned int
12648 ppc64_elf_action_discarded (asection *sec)
12650 if (strcmp (".opd", sec->name) == 0)
12653 if (strcmp (".toc", sec->name) == 0)
12656 if (strcmp (".toc1", sec->name) == 0)
12659 return _bfd_elf_default_action_discarded (sec);
12662 /* The RELOCATE_SECTION function is called by the ELF backend linker
12663 to handle the relocations for a section.
12665 The relocs are always passed as Rela structures; if the section
12666 actually uses Rel structures, the r_addend field will always be
12669 This function is responsible for adjust the section contents as
12670 necessary, and (if using Rela relocs and generating a
12671 relocatable output file) adjusting the reloc addend as
12674 This function does not have to worry about setting the reloc
12675 address or the reloc symbol index.
12677 LOCAL_SYMS is a pointer to the swapped in local symbols.
12679 LOCAL_SECTIONS is an array giving the section in the input file
12680 corresponding to the st_shndx field of each local symbol.
12682 The global hash table entry for the global symbols can be found
12683 via elf_sym_hashes (input_bfd).
12685 When generating relocatable output, this function must handle
12686 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
12687 going to be the section symbol corresponding to the output
12688 section, which means that the addend must be adjusted
12692 ppc64_elf_relocate_section (bfd *output_bfd,
12693 struct bfd_link_info *info,
12695 asection *input_section,
12696 bfd_byte *contents,
12697 Elf_Internal_Rela *relocs,
12698 Elf_Internal_Sym *local_syms,
12699 asection **local_sections)
12701 struct ppc_link_hash_table *htab;
12702 Elf_Internal_Shdr *symtab_hdr;
12703 struct elf_link_hash_entry **sym_hashes;
12704 Elf_Internal_Rela *rel;
12705 Elf_Internal_Rela *relend;
12706 Elf_Internal_Rela outrel;
12708 struct got_entry **local_got_ents;
12710 bfd_boolean ret = TRUE;
12711 bfd_boolean is_opd;
12712 /* Assume 'at' branch hints. */
12713 bfd_boolean is_isa_v2 = TRUE;
12714 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
12716 /* Initialize howto table if needed. */
12717 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
12720 htab = ppc_hash_table (info);
12724 /* Don't relocate stub sections. */
12725 if (input_section->owner == htab->stub_bfd)
12728 BFD_ASSERT (is_ppc64_elf (input_bfd));
12730 local_got_ents = elf_local_got_ents (input_bfd);
12731 TOCstart = elf_gp (output_bfd);
12732 symtab_hdr = &elf_symtab_hdr (input_bfd);
12733 sym_hashes = elf_sym_hashes (input_bfd);
12734 is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
12737 relend = relocs + input_section->reloc_count;
12738 for (; rel < relend; rel++)
12740 enum elf_ppc64_reloc_type r_type;
12742 bfd_reloc_status_type r;
12743 Elf_Internal_Sym *sym;
12745 struct elf_link_hash_entry *h_elf;
12746 struct ppc_link_hash_entry *h;
12747 struct ppc_link_hash_entry *fdh;
12748 const char *sym_name;
12749 unsigned long r_symndx, toc_symndx;
12750 bfd_vma toc_addend;
12751 unsigned char tls_mask, tls_gd, tls_type;
12752 unsigned char sym_type;
12753 bfd_vma relocation;
12754 bfd_boolean unresolved_reloc;
12755 bfd_boolean warned;
12756 enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
12759 struct ppc_stub_hash_entry *stub_entry;
12760 bfd_vma max_br_offset;
12762 const Elf_Internal_Rela orig_rel = *rel;
12764 r_type = ELF64_R_TYPE (rel->r_info);
12765 r_symndx = ELF64_R_SYM (rel->r_info);
12767 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
12768 symbol of the previous ADDR64 reloc. The symbol gives us the
12769 proper TOC base to use. */
12770 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
12772 && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64
12774 r_symndx = ELF64_R_SYM (rel[-1].r_info);
12780 unresolved_reloc = FALSE;
12783 if (r_symndx < symtab_hdr->sh_info)
12785 /* It's a local symbol. */
12786 struct _opd_sec_data *opd;
12788 sym = local_syms + r_symndx;
12789 sec = local_sections[r_symndx];
12790 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
12791 sym_type = ELF64_ST_TYPE (sym->st_info);
12792 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
12793 opd = get_opd_info (sec);
12794 if (opd != NULL && opd->adjust != NULL)
12796 long adjust = opd->adjust[(sym->st_value + rel->r_addend) / 8];
12801 /* If this is a relocation against the opd section sym
12802 and we have edited .opd, adjust the reloc addend so
12803 that ld -r and ld --emit-relocs output is correct.
12804 If it is a reloc against some other .opd symbol,
12805 then the symbol value will be adjusted later. */
12806 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
12807 rel->r_addend += adjust;
12809 relocation += adjust;
12815 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
12816 r_symndx, symtab_hdr, sym_hashes,
12817 h_elf, sec, relocation,
12818 unresolved_reloc, warned);
12819 sym_name = h_elf->root.root.string;
12820 sym_type = h_elf->type;
12822 && sec->owner == output_bfd
12823 && strcmp (sec->name, ".opd") == 0)
12825 /* This is a symbol defined in a linker script. All
12826 such are defined in output sections, even those
12827 defined by simple assignment from a symbol defined in
12828 an input section. Transfer the symbol to an
12829 appropriate input .opd section, so that a branch to
12830 this symbol will be mapped to the location specified
12831 by the opd entry. */
12832 struct bfd_link_order *lo;
12833 for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
12834 if (lo->type == bfd_indirect_link_order)
12836 asection *isec = lo->u.indirect.section;
12837 if (h_elf->root.u.def.value >= isec->output_offset
12838 && h_elf->root.u.def.value < (isec->output_offset
12841 h_elf->root.u.def.value -= isec->output_offset;
12842 h_elf->root.u.def.section = isec;
12849 h = (struct ppc_link_hash_entry *) h_elf;
12851 if (sec != NULL && discarded_section (sec))
12852 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
12854 ppc64_elf_howto_table[r_type], 0,
12857 if (info->relocatable)
12860 if (h != NULL && &h->elf == htab->elf.hgot)
12862 relocation = (TOCstart
12863 + htab->stub_group[input_section->id].toc_off);
12864 sec = bfd_abs_section_ptr;
12865 unresolved_reloc = FALSE;
12868 /* TLS optimizations. Replace instruction sequences and relocs
12869 based on information we collected in tls_optimize. We edit
12870 RELOCS so that --emit-relocs will output something sensible
12871 for the final instruction stream. */
12876 tls_mask = h->tls_mask;
12877 else if (local_got_ents != NULL)
12879 struct plt_entry **local_plt = (struct plt_entry **)
12880 (local_got_ents + symtab_hdr->sh_info);
12881 unsigned char *lgot_masks = (unsigned char *)
12882 (local_plt + symtab_hdr->sh_info);
12883 tls_mask = lgot_masks[r_symndx];
12886 && (r_type == R_PPC64_TLS
12887 || r_type == R_PPC64_TLSGD
12888 || r_type == R_PPC64_TLSLD))
12890 /* Check for toc tls entries. */
12891 unsigned char *toc_tls;
12893 if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
12894 &local_syms, rel, input_bfd))
12898 tls_mask = *toc_tls;
12901 /* Check that tls relocs are used with tls syms, and non-tls
12902 relocs are used with non-tls syms. */
12903 if (r_symndx != STN_UNDEF
12904 && r_type != R_PPC64_NONE
12906 || h->elf.root.type == bfd_link_hash_defined
12907 || h->elf.root.type == bfd_link_hash_defweak)
12908 && (IS_PPC64_TLS_RELOC (r_type)
12909 != (sym_type == STT_TLS
12910 || (sym_type == STT_SECTION
12911 && (sec->flags & SEC_THREAD_LOCAL) != 0))))
12914 && (r_type == R_PPC64_TLS
12915 || r_type == R_PPC64_TLSGD
12916 || r_type == R_PPC64_TLSLD))
12917 /* R_PPC64_TLS is OK against a symbol in the TOC. */
12920 info->callbacks->einfo
12921 (!IS_PPC64_TLS_RELOC (r_type)
12922 ? _("%P: %H: %s used with TLS symbol `%T'\n")
12923 : _("%P: %H: %s used with non-TLS symbol `%T'\n"),
12924 input_bfd, input_section, rel->r_offset,
12925 ppc64_elf_howto_table[r_type]->name,
12929 /* Ensure reloc mapping code below stays sane. */
12930 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
12931 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
12932 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
12933 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
12934 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
12935 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
12936 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
12937 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
12938 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
12939 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
12947 case R_PPC64_LO_DS_OPT:
12948 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
12949 if ((insn & (0x3f << 26)) != 58u << 26)
12951 insn += (14u << 26) - (58u << 26);
12952 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
12953 r_type = R_PPC64_TOC16_LO;
12954 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
12957 case R_PPC64_TOC16:
12958 case R_PPC64_TOC16_LO:
12959 case R_PPC64_TOC16_DS:
12960 case R_PPC64_TOC16_LO_DS:
12962 /* Check for toc tls entries. */
12963 unsigned char *toc_tls;
12966 retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
12967 &local_syms, rel, input_bfd);
12973 tls_mask = *toc_tls;
12974 if (r_type == R_PPC64_TOC16_DS
12975 || r_type == R_PPC64_TOC16_LO_DS)
12978 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
12983 /* If we found a GD reloc pair, then we might be
12984 doing a GD->IE transition. */
12987 tls_gd = TLS_TPRELGD;
12988 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
12991 else if (retval == 3)
12993 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13001 case R_PPC64_GOT_TPREL16_HI:
13002 case R_PPC64_GOT_TPREL16_HA:
13004 && (tls_mask & TLS_TPREL) == 0)
13006 rel->r_offset -= d_offset;
13007 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13008 r_type = R_PPC64_NONE;
13009 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13013 case R_PPC64_GOT_TPREL16_DS:
13014 case R_PPC64_GOT_TPREL16_LO_DS:
13016 && (tls_mask & TLS_TPREL) == 0)
13019 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
13021 insn |= 0x3c0d0000; /* addis 0,13,0 */
13022 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
13023 r_type = R_PPC64_TPREL16_HA;
13024 if (toc_symndx != 0)
13026 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13027 rel->r_addend = toc_addend;
13028 /* We changed the symbol. Start over in order to
13029 get h, sym, sec etc. right. */
13034 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13040 && (tls_mask & TLS_TPREL) == 0)
13042 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
13043 insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
13046 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
13047 /* Was PPC64_TLS which sits on insn boundary, now
13048 PPC64_TPREL16_LO which is at low-order half-word. */
13049 rel->r_offset += d_offset;
13050 r_type = R_PPC64_TPREL16_LO;
13051 if (toc_symndx != 0)
13053 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13054 rel->r_addend = toc_addend;
13055 /* We changed the symbol. Start over in order to
13056 get h, sym, sec etc. right. */
13061 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13065 case R_PPC64_GOT_TLSGD16_HI:
13066 case R_PPC64_GOT_TLSGD16_HA:
13067 tls_gd = TLS_TPRELGD;
13068 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13072 case R_PPC64_GOT_TLSLD16_HI:
13073 case R_PPC64_GOT_TLSLD16_HA:
13074 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13077 if ((tls_mask & tls_gd) != 0)
13078 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13079 + R_PPC64_GOT_TPREL16_DS);
13082 rel->r_offset -= d_offset;
13083 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13084 r_type = R_PPC64_NONE;
13086 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13090 case R_PPC64_GOT_TLSGD16:
13091 case R_PPC64_GOT_TLSGD16_LO:
13092 tls_gd = TLS_TPRELGD;
13093 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13097 case R_PPC64_GOT_TLSLD16:
13098 case R_PPC64_GOT_TLSLD16_LO:
13099 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13101 unsigned int insn1, insn2, insn3;
13105 offset = (bfd_vma) -1;
13106 /* If not using the newer R_PPC64_TLSGD/LD to mark
13107 __tls_get_addr calls, we must trust that the call
13108 stays with its arg setup insns, ie. that the next
13109 reloc is the __tls_get_addr call associated with
13110 the current reloc. Edit both insns. */
13111 if (input_section->has_tls_get_addr_call
13112 && rel + 1 < relend
13113 && branch_reloc_hash_match (input_bfd, rel + 1,
13114 htab->tls_get_addr,
13115 htab->tls_get_addr_fd))
13116 offset = rel[1].r_offset;
13117 if ((tls_mask & tls_gd) != 0)
13120 insn1 = bfd_get_32 (output_bfd,
13121 contents + rel->r_offset - d_offset);
13122 insn1 &= (1 << 26) - (1 << 2);
13123 insn1 |= 58 << 26; /* ld */
13124 insn2 = 0x7c636a14; /* add 3,3,13 */
13125 if (offset != (bfd_vma) -1)
13126 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13127 if ((tls_mask & TLS_EXPLICIT) == 0)
13128 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13129 + R_PPC64_GOT_TPREL16_DS);
13131 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
13132 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13137 insn1 = 0x3c6d0000; /* addis 3,13,0 */
13138 insn2 = 0x38630000; /* addi 3,3,0 */
13141 /* Was an LD reloc. */
13143 sec = local_sections[toc_symndx];
13145 r_symndx < symtab_hdr->sh_info;
13147 if (local_sections[r_symndx] == sec)
13149 if (r_symndx >= symtab_hdr->sh_info)
13150 r_symndx = STN_UNDEF;
13151 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13152 if (r_symndx != STN_UNDEF)
13153 rel->r_addend -= (local_syms[r_symndx].st_value
13154 + sec->output_offset
13155 + sec->output_section->vma);
13157 else if (toc_symndx != 0)
13159 r_symndx = toc_symndx;
13160 rel->r_addend = toc_addend;
13162 r_type = R_PPC64_TPREL16_HA;
13163 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13164 if (offset != (bfd_vma) -1)
13166 rel[1].r_info = ELF64_R_INFO (r_symndx,
13167 R_PPC64_TPREL16_LO);
13168 rel[1].r_offset = offset + d_offset;
13169 rel[1].r_addend = rel->r_addend;
13172 bfd_put_32 (output_bfd, insn1,
13173 contents + rel->r_offset - d_offset);
13174 if (offset != (bfd_vma) -1)
13176 insn3 = bfd_get_32 (output_bfd,
13177 contents + offset + 4);
13179 || insn3 == CROR_151515 || insn3 == CROR_313131)
13181 rel[1].r_offset += 4;
13182 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13185 bfd_put_32 (output_bfd, insn2, contents + offset);
13187 if ((tls_mask & tls_gd) == 0
13188 && (tls_gd == 0 || toc_symndx != 0))
13190 /* We changed the symbol. Start over in order
13191 to get h, sym, sec etc. right. */
13198 case R_PPC64_TLSGD:
13199 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13201 unsigned int insn2, insn3;
13202 bfd_vma offset = rel->r_offset;
13204 if ((tls_mask & TLS_TPRELGD) != 0)
13207 r_type = R_PPC64_NONE;
13208 insn2 = 0x7c636a14; /* add 3,3,13 */
13213 if (toc_symndx != 0)
13215 r_symndx = toc_symndx;
13216 rel->r_addend = toc_addend;
13218 r_type = R_PPC64_TPREL16_LO;
13219 rel->r_offset = offset + d_offset;
13220 insn2 = 0x38630000; /* addi 3,3,0 */
13222 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13223 /* Zap the reloc on the _tls_get_addr call too. */
13224 BFD_ASSERT (offset == rel[1].r_offset);
13225 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13226 insn3 = bfd_get_32 (output_bfd,
13227 contents + offset + 4);
13229 || insn3 == CROR_151515 || insn3 == CROR_313131)
13231 rel->r_offset += 4;
13232 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13235 bfd_put_32 (output_bfd, insn2, contents + offset);
13236 if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
13244 case R_PPC64_TLSLD:
13245 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13247 unsigned int insn2, insn3;
13248 bfd_vma offset = rel->r_offset;
13251 sec = local_sections[toc_symndx];
13253 r_symndx < symtab_hdr->sh_info;
13255 if (local_sections[r_symndx] == sec)
13257 if (r_symndx >= symtab_hdr->sh_info)
13258 r_symndx = STN_UNDEF;
13259 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13260 if (r_symndx != STN_UNDEF)
13261 rel->r_addend -= (local_syms[r_symndx].st_value
13262 + sec->output_offset
13263 + sec->output_section->vma);
13265 r_type = R_PPC64_TPREL16_LO;
13266 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13267 rel->r_offset = offset + d_offset;
13268 /* Zap the reloc on the _tls_get_addr call too. */
13269 BFD_ASSERT (offset == rel[1].r_offset);
13270 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13271 insn2 = 0x38630000; /* addi 3,3,0 */
13272 insn3 = bfd_get_32 (output_bfd,
13273 contents + offset + 4);
13275 || insn3 == CROR_151515 || insn3 == CROR_313131)
13277 rel->r_offset += 4;
13278 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13281 bfd_put_32 (output_bfd, insn2, contents + offset);
13287 case R_PPC64_DTPMOD64:
13288 if (rel + 1 < relend
13289 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
13290 && rel[1].r_offset == rel->r_offset + 8)
13292 if ((tls_mask & TLS_GD) == 0)
13294 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
13295 if ((tls_mask & TLS_TPRELGD) != 0)
13296 r_type = R_PPC64_TPREL64;
13299 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
13300 r_type = R_PPC64_NONE;
13302 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13307 if ((tls_mask & TLS_LD) == 0)
13309 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
13310 r_type = R_PPC64_NONE;
13311 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13316 case R_PPC64_TPREL64:
13317 if ((tls_mask & TLS_TPREL) == 0)
13319 r_type = R_PPC64_NONE;
13320 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13325 /* Handle other relocations that tweak non-addend part of insn. */
13327 max_br_offset = 1 << 25;
13328 addend = rel->r_addend;
13329 reloc_dest = DEST_NORMAL;
13335 case R_PPC64_TOCSAVE:
13336 if (relocation + addend == (rel->r_offset
13337 + input_section->output_offset
13338 + input_section->output_section->vma)
13339 && tocsave_find (htab, NO_INSERT,
13340 &local_syms, rel, input_bfd))
13342 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
13344 || insn == CROR_151515 || insn == CROR_313131)
13345 bfd_put_32 (input_bfd,
13346 STD_R2_0R1 + STK_TOC (htab),
13347 contents + rel->r_offset);
13351 /* Branch taken prediction relocations. */
13352 case R_PPC64_ADDR14_BRTAKEN:
13353 case R_PPC64_REL14_BRTAKEN:
13354 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
13357 /* Branch not taken prediction relocations. */
13358 case R_PPC64_ADDR14_BRNTAKEN:
13359 case R_PPC64_REL14_BRNTAKEN:
13360 insn |= bfd_get_32 (output_bfd,
13361 contents + rel->r_offset) & ~(0x01 << 21);
13364 case R_PPC64_REL14:
13365 max_br_offset = 1 << 15;
13368 case R_PPC64_REL24:
13369 /* Calls to functions with a different TOC, such as calls to
13370 shared objects, need to alter the TOC pointer. This is
13371 done using a linkage stub. A REL24 branching to these
13372 linkage stubs needs to be followed by a nop, as the nop
13373 will be replaced with an instruction to restore the TOC
13378 && h->oh->is_func_descriptor)
13379 fdh = ppc_follow_link (h->oh);
13380 stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
13382 if (stub_entry != NULL
13383 && (stub_entry->stub_type == ppc_stub_plt_call
13384 || stub_entry->stub_type == ppc_stub_plt_call_r2save
13385 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
13386 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
13388 bfd_boolean can_plt_call = FALSE;
13390 /* All of these stubs will modify r2, so there must be a
13391 branch and link followed by a nop. The nop is
13392 replaced by an insn to restore r2. */
13393 if (rel->r_offset + 8 <= input_section->size)
13397 br = bfd_get_32 (input_bfd,
13398 contents + rel->r_offset);
13403 nop = bfd_get_32 (input_bfd,
13404 contents + rel->r_offset + 4);
13406 || nop == CROR_151515 || nop == CROR_313131)
13409 && (h == htab->tls_get_addr_fd
13410 || h == htab->tls_get_addr)
13411 && !htab->no_tls_get_addr_opt)
13413 /* Special stub used, leave nop alone. */
13416 bfd_put_32 (input_bfd,
13417 LD_R2_0R1 + STK_TOC (htab),
13418 contents + rel->r_offset + 4);
13419 can_plt_call = TRUE;
13424 if (!can_plt_call && h != NULL)
13426 const char *name = h->elf.root.root.string;
13431 if (strncmp (name, "__libc_start_main", 17) == 0
13432 && (name[17] == 0 || name[17] == '@'))
13434 /* Allow crt1 branch to go via a toc adjusting
13435 stub. Other calls that never return could do
13436 the same, if we could detect such. */
13437 can_plt_call = TRUE;
13443 /* g++ as of 20130507 emits self-calls without a
13444 following nop. This is arguably wrong since we
13445 have conflicting information. On the one hand a
13446 global symbol and on the other a local call
13447 sequence, but don't error for this special case.
13448 It isn't possible to cheaply verify we have
13449 exactly such a call. Allow all calls to the same
13451 asection *code_sec = sec;
13453 if (get_opd_info (sec) != NULL)
13455 bfd_vma off = (relocation + addend
13456 - sec->output_section->vma
13457 - sec->output_offset);
13459 opd_entry_value (sec, off, &code_sec, NULL, FALSE);
13461 if (code_sec == input_section)
13462 can_plt_call = TRUE;
13467 info->callbacks->einfo
13468 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
13469 "recompile with -fPIC"),
13470 input_bfd, input_section, rel->r_offset, sym_name);
13472 bfd_set_error (bfd_error_bad_value);
13477 && (stub_entry->stub_type == ppc_stub_plt_call
13478 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
13479 unresolved_reloc = FALSE;
13482 if ((stub_entry == NULL
13483 || stub_entry->stub_type == ppc_stub_long_branch
13484 || stub_entry->stub_type == ppc_stub_plt_branch)
13485 && get_opd_info (sec) != NULL)
13487 /* The branch destination is the value of the opd entry. */
13488 bfd_vma off = (relocation + addend
13489 - sec->output_section->vma
13490 - sec->output_offset);
13491 bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
13492 if (dest != (bfd_vma) -1)
13496 reloc_dest = DEST_OPD;
13500 /* If the branch is out of reach we ought to have a long
13502 from = (rel->r_offset
13503 + input_section->output_offset
13504 + input_section->output_section->vma);
13506 relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
13510 if (stub_entry != NULL
13511 && (stub_entry->stub_type == ppc_stub_long_branch
13512 || stub_entry->stub_type == ppc_stub_plt_branch)
13513 && (r_type == R_PPC64_ADDR14_BRTAKEN
13514 || r_type == R_PPC64_ADDR14_BRNTAKEN
13515 || (relocation + addend - from + max_br_offset
13516 < 2 * max_br_offset)))
13517 /* Don't use the stub if this branch is in range. */
13520 if (stub_entry != NULL)
13522 /* Munge up the value and addend so that we call the stub
13523 rather than the procedure directly. */
13524 relocation = (stub_entry->stub_offset
13525 + stub_entry->stub_sec->output_offset
13526 + stub_entry->stub_sec->output_section->vma);
13528 reloc_dest = DEST_STUB;
13530 if ((stub_entry->stub_type == ppc_stub_plt_call
13531 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
13532 && (ALWAYS_EMIT_R2SAVE
13533 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
13534 && rel + 1 < relend
13535 && rel[1].r_offset == rel->r_offset + 4
13536 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
13544 /* Set 'a' bit. This is 0b00010 in BO field for branch
13545 on CR(BI) insns (BO == 001at or 011at), and 0b01000
13546 for branch on CTR insns (BO == 1a00t or 1a01t). */
13547 if ((insn & (0x14 << 21)) == (0x04 << 21))
13548 insn |= 0x02 << 21;
13549 else if ((insn & (0x14 << 21)) == (0x10 << 21))
13550 insn |= 0x08 << 21;
13556 /* Invert 'y' bit if not the default. */
13557 if ((bfd_signed_vma) (relocation + addend - from) < 0)
13558 insn ^= 0x01 << 21;
13561 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
13564 /* NOP out calls to undefined weak functions.
13565 We can thus call a weak function without first
13566 checking whether the function is defined. */
13568 && h->elf.root.type == bfd_link_hash_undefweak
13569 && h->elf.dynindx == -1
13570 && r_type == R_PPC64_REL24
13574 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13580 /* Set `addend'. */
13585 info->callbacks->einfo
13586 (_("%P: %B: unknown relocation type %d for `%T'\n"),
13587 input_bfd, (int) r_type, sym_name);
13589 bfd_set_error (bfd_error_bad_value);
13595 case R_PPC64_TLSGD:
13596 case R_PPC64_TLSLD:
13597 case R_PPC64_TOCSAVE:
13598 case R_PPC64_GNU_VTINHERIT:
13599 case R_PPC64_GNU_VTENTRY:
13602 /* GOT16 relocations. Like an ADDR16 using the symbol's
13603 address in the GOT as relocation value instead of the
13604 symbol's value itself. Also, create a GOT entry for the
13605 symbol and put the symbol value there. */
13606 case R_PPC64_GOT_TLSGD16:
13607 case R_PPC64_GOT_TLSGD16_LO:
13608 case R_PPC64_GOT_TLSGD16_HI:
13609 case R_PPC64_GOT_TLSGD16_HA:
13610 tls_type = TLS_TLS | TLS_GD;
13613 case R_PPC64_GOT_TLSLD16:
13614 case R_PPC64_GOT_TLSLD16_LO:
13615 case R_PPC64_GOT_TLSLD16_HI:
13616 case R_PPC64_GOT_TLSLD16_HA:
13617 tls_type = TLS_TLS | TLS_LD;
13620 case R_PPC64_GOT_TPREL16_DS:
13621 case R_PPC64_GOT_TPREL16_LO_DS:
13622 case R_PPC64_GOT_TPREL16_HI:
13623 case R_PPC64_GOT_TPREL16_HA:
13624 tls_type = TLS_TLS | TLS_TPREL;
13627 case R_PPC64_GOT_DTPREL16_DS:
13628 case R_PPC64_GOT_DTPREL16_LO_DS:
13629 case R_PPC64_GOT_DTPREL16_HI:
13630 case R_PPC64_GOT_DTPREL16_HA:
13631 tls_type = TLS_TLS | TLS_DTPREL;
13634 case R_PPC64_GOT16:
13635 case R_PPC64_GOT16_LO:
13636 case R_PPC64_GOT16_HI:
13637 case R_PPC64_GOT16_HA:
13638 case R_PPC64_GOT16_DS:
13639 case R_PPC64_GOT16_LO_DS:
13642 /* Relocation is to the entry for this symbol in the global
13647 unsigned long indx = 0;
13648 struct got_entry *ent;
13650 if (tls_type == (TLS_TLS | TLS_LD)
13652 || !h->elf.def_dynamic))
13653 ent = ppc64_tlsld_got (input_bfd);
13659 bfd_boolean dyn = htab->elf.dynamic_sections_created;
13660 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
13663 && SYMBOL_CALLS_LOCAL (info, &h->elf)))
13664 /* This is actually a static link, or it is a
13665 -Bsymbolic link and the symbol is defined
13666 locally, or the symbol was forced to be local
13667 because of a version file. */
13671 BFD_ASSERT (h->elf.dynindx != -1);
13672 indx = h->elf.dynindx;
13673 unresolved_reloc = FALSE;
13675 ent = h->elf.got.glist;
13679 if (local_got_ents == NULL)
13681 ent = local_got_ents[r_symndx];
13684 for (; ent != NULL; ent = ent->next)
13685 if (ent->addend == orig_rel.r_addend
13686 && ent->owner == input_bfd
13687 && ent->tls_type == tls_type)
13693 if (ent->is_indirect)
13694 ent = ent->got.ent;
13695 offp = &ent->got.offset;
13696 got = ppc64_elf_tdata (ent->owner)->got;
13700 /* The offset must always be a multiple of 8. We use the
13701 least significant bit to record whether we have already
13702 processed this entry. */
13704 if ((off & 1) != 0)
13708 /* Generate relocs for the dynamic linker, except in
13709 the case of TLSLD where we'll use one entry per
13717 ? h->elf.type == STT_GNU_IFUNC
13718 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
13720 relgot = htab->reliplt;
13721 else if ((info->shared || indx != 0)
13723 || (tls_type == (TLS_TLS | TLS_LD)
13724 && !h->elf.def_dynamic)
13725 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
13726 || h->elf.root.type != bfd_link_hash_undefweak))
13727 relgot = ppc64_elf_tdata (ent->owner)->relgot;
13728 if (relgot != NULL)
13730 outrel.r_offset = (got->output_section->vma
13731 + got->output_offset
13733 outrel.r_addend = addend;
13734 if (tls_type & (TLS_LD | TLS_GD))
13736 outrel.r_addend = 0;
13737 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
13738 if (tls_type == (TLS_TLS | TLS_GD))
13740 loc = relgot->contents;
13741 loc += (relgot->reloc_count++
13742 * sizeof (Elf64_External_Rela));
13743 bfd_elf64_swap_reloca_out (output_bfd,
13745 outrel.r_offset += 8;
13746 outrel.r_addend = addend;
13748 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
13751 else if (tls_type == (TLS_TLS | TLS_DTPREL))
13752 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
13753 else if (tls_type == (TLS_TLS | TLS_TPREL))
13754 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
13755 else if (indx != 0)
13756 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
13760 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
13762 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
13764 /* Write the .got section contents for the sake
13766 loc = got->contents + off;
13767 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
13771 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
13773 outrel.r_addend += relocation;
13774 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
13775 outrel.r_addend -= htab->elf.tls_sec->vma;
13777 loc = relgot->contents;
13778 loc += (relgot->reloc_count++
13779 * sizeof (Elf64_External_Rela));
13780 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
13783 /* Init the .got section contents here if we're not
13784 emitting a reloc. */
13787 relocation += addend;
13788 if (tls_type == (TLS_TLS | TLS_LD))
13790 else if (tls_type != 0)
13792 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
13793 if (tls_type == (TLS_TLS | TLS_TPREL))
13794 relocation += DTP_OFFSET - TP_OFFSET;
13796 if (tls_type == (TLS_TLS | TLS_GD))
13798 bfd_put_64 (output_bfd, relocation,
13799 got->contents + off + 8);
13804 bfd_put_64 (output_bfd, relocation,
13805 got->contents + off);
13809 if (off >= (bfd_vma) -2)
13812 relocation = got->output_section->vma + got->output_offset + off;
13813 addend = -(TOCstart + htab->stub_group[input_section->id].toc_off);
13817 case R_PPC64_PLT16_HA:
13818 case R_PPC64_PLT16_HI:
13819 case R_PPC64_PLT16_LO:
13820 case R_PPC64_PLT32:
13821 case R_PPC64_PLT64:
13822 /* Relocation is to the entry for this symbol in the
13823 procedure linkage table. */
13825 /* Resolve a PLT reloc against a local symbol directly,
13826 without using the procedure linkage table. */
13830 /* It's possible that we didn't make a PLT entry for this
13831 symbol. This happens when statically linking PIC code,
13832 or when using -Bsymbolic. Go find a match if there is a
13834 if (htab->plt != NULL)
13836 struct plt_entry *ent;
13837 for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next)
13838 if (ent->addend == orig_rel.r_addend
13839 && ent->plt.offset != (bfd_vma) -1)
13841 relocation = (htab->plt->output_section->vma
13842 + htab->plt->output_offset
13843 + ent->plt.offset);
13844 unresolved_reloc = FALSE;
13850 /* Relocation value is TOC base. */
13851 relocation = TOCstart;
13852 if (r_symndx == STN_UNDEF)
13853 relocation += htab->stub_group[input_section->id].toc_off;
13854 else if (unresolved_reloc)
13856 else if (sec != NULL && sec->id <= htab->top_id)
13857 relocation += htab->stub_group[sec->id].toc_off;
13859 unresolved_reloc = TRUE;
13862 /* TOC16 relocs. We want the offset relative to the TOC base,
13863 which is the address of the start of the TOC plus 0x8000.
13864 The TOC consists of sections .got, .toc, .tocbss, and .plt,
13866 case R_PPC64_TOC16:
13867 case R_PPC64_TOC16_LO:
13868 case R_PPC64_TOC16_HI:
13869 case R_PPC64_TOC16_DS:
13870 case R_PPC64_TOC16_LO_DS:
13871 case R_PPC64_TOC16_HA:
13872 addend -= TOCstart + htab->stub_group[input_section->id].toc_off;
13875 /* Relocate against the beginning of the section. */
13876 case R_PPC64_SECTOFF:
13877 case R_PPC64_SECTOFF_LO:
13878 case R_PPC64_SECTOFF_HI:
13879 case R_PPC64_SECTOFF_DS:
13880 case R_PPC64_SECTOFF_LO_DS:
13881 case R_PPC64_SECTOFF_HA:
13883 addend -= sec->output_section->vma;
13886 case R_PPC64_REL16:
13887 case R_PPC64_REL16_LO:
13888 case R_PPC64_REL16_HI:
13889 case R_PPC64_REL16_HA:
13892 case R_PPC64_REL14:
13893 case R_PPC64_REL14_BRNTAKEN:
13894 case R_PPC64_REL14_BRTAKEN:
13895 case R_PPC64_REL24:
13898 case R_PPC64_TPREL16:
13899 case R_PPC64_TPREL16_LO:
13900 case R_PPC64_TPREL16_HI:
13901 case R_PPC64_TPREL16_HA:
13902 case R_PPC64_TPREL16_DS:
13903 case R_PPC64_TPREL16_LO_DS:
13904 case R_PPC64_TPREL16_HIGH:
13905 case R_PPC64_TPREL16_HIGHA:
13906 case R_PPC64_TPREL16_HIGHER:
13907 case R_PPC64_TPREL16_HIGHERA:
13908 case R_PPC64_TPREL16_HIGHEST:
13909 case R_PPC64_TPREL16_HIGHESTA:
13911 && h->elf.root.type == bfd_link_hash_undefweak
13912 && h->elf.dynindx == -1)
13914 /* Make this relocation against an undefined weak symbol
13915 resolve to zero. This is really just a tweak, since
13916 code using weak externs ought to check that they are
13917 defined before using them. */
13918 bfd_byte *p = contents + rel->r_offset - d_offset;
13920 insn = bfd_get_32 (output_bfd, p);
13921 insn = _bfd_elf_ppc_at_tprel_transform (insn, 13);
13923 bfd_put_32 (output_bfd, insn, p);
13926 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
13928 /* The TPREL16 relocs shouldn't really be used in shared
13929 libs as they will result in DT_TEXTREL being set, but
13930 support them anyway. */
13934 case R_PPC64_DTPREL16:
13935 case R_PPC64_DTPREL16_LO:
13936 case R_PPC64_DTPREL16_HI:
13937 case R_PPC64_DTPREL16_HA:
13938 case R_PPC64_DTPREL16_DS:
13939 case R_PPC64_DTPREL16_LO_DS:
13940 case R_PPC64_DTPREL16_HIGH:
13941 case R_PPC64_DTPREL16_HIGHA:
13942 case R_PPC64_DTPREL16_HIGHER:
13943 case R_PPC64_DTPREL16_HIGHERA:
13944 case R_PPC64_DTPREL16_HIGHEST:
13945 case R_PPC64_DTPREL16_HIGHESTA:
13946 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
13949 case R_PPC64_DTPMOD64:
13954 case R_PPC64_TPREL64:
13955 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
13958 case R_PPC64_DTPREL64:
13959 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
13962 /* Relocations that may need to be propagated if this is a
13964 case R_PPC64_REL30:
13965 case R_PPC64_REL32:
13966 case R_PPC64_REL64:
13967 case R_PPC64_ADDR14:
13968 case R_PPC64_ADDR14_BRNTAKEN:
13969 case R_PPC64_ADDR14_BRTAKEN:
13970 case R_PPC64_ADDR16:
13971 case R_PPC64_ADDR16_DS:
13972 case R_PPC64_ADDR16_HA:
13973 case R_PPC64_ADDR16_HI:
13974 case R_PPC64_ADDR16_HIGH:
13975 case R_PPC64_ADDR16_HIGHA:
13976 case R_PPC64_ADDR16_HIGHER:
13977 case R_PPC64_ADDR16_HIGHERA:
13978 case R_PPC64_ADDR16_HIGHEST:
13979 case R_PPC64_ADDR16_HIGHESTA:
13980 case R_PPC64_ADDR16_LO:
13981 case R_PPC64_ADDR16_LO_DS:
13982 case R_PPC64_ADDR24:
13983 case R_PPC64_ADDR32:
13984 case R_PPC64_ADDR64:
13985 case R_PPC64_UADDR16:
13986 case R_PPC64_UADDR32:
13987 case R_PPC64_UADDR64:
13989 if ((input_section->flags & SEC_ALLOC) == 0)
13992 if (NO_OPD_RELOCS && is_opd)
13997 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
13998 || h->elf.root.type != bfd_link_hash_undefweak)
13999 && (must_be_dyn_reloc (info, r_type)
14000 || !SYMBOL_CALLS_LOCAL (info, &h->elf)))
14001 || (ELIMINATE_COPY_RELOCS
14004 && h->elf.dynindx != -1
14005 && !h->elf.non_got_ref
14006 && !h->elf.def_regular)
14009 ? h->elf.type == STT_GNU_IFUNC
14010 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)))
14012 bfd_boolean skip, relocate;
14016 /* When generating a dynamic object, these relocations
14017 are copied into the output file to be resolved at run
14023 out_off = _bfd_elf_section_offset (output_bfd, info,
14024 input_section, rel->r_offset);
14025 if (out_off == (bfd_vma) -1)
14027 else if (out_off == (bfd_vma) -2)
14028 skip = TRUE, relocate = TRUE;
14029 out_off += (input_section->output_section->vma
14030 + input_section->output_offset);
14031 outrel.r_offset = out_off;
14032 outrel.r_addend = rel->r_addend;
14034 /* Optimize unaligned reloc use. */
14035 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
14036 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
14037 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
14038 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
14039 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
14040 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
14041 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
14042 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
14043 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
14046 memset (&outrel, 0, sizeof outrel);
14047 else if (!SYMBOL_CALLS_LOCAL (info, &h->elf)
14049 && r_type != R_PPC64_TOC)
14051 BFD_ASSERT (h->elf.dynindx != -1);
14052 outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
14056 /* This symbol is local, or marked to become local,
14057 or this is an opd section reloc which must point
14058 at a local function. */
14059 outrel.r_addend += relocation;
14060 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
14062 if (is_opd && h != NULL)
14064 /* Lie about opd entries. This case occurs
14065 when building shared libraries and we
14066 reference a function in another shared
14067 lib. The same thing happens for a weak
14068 definition in an application that's
14069 overridden by a strong definition in a
14070 shared lib. (I believe this is a generic
14071 bug in binutils handling of weak syms.)
14072 In these cases we won't use the opd
14073 entry in this lib. */
14074 unresolved_reloc = FALSE;
14077 && r_type == R_PPC64_ADDR64
14079 ? h->elf.type == STT_GNU_IFUNC
14080 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
14081 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14084 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
14086 /* We need to relocate .opd contents for ld.so.
14087 Prelink also wants simple and consistent rules
14088 for relocs. This make all RELATIVE relocs have
14089 *r_offset equal to r_addend. */
14098 ? h->elf.type == STT_GNU_IFUNC
14099 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14101 info->callbacks->einfo
14102 (_("%P: %H: %s for indirect "
14103 "function `%T' unsupported\n"),
14104 input_bfd, input_section, rel->r_offset,
14105 ppc64_elf_howto_table[r_type]->name,
14109 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
14111 else if (sec == NULL || sec->owner == NULL)
14113 bfd_set_error (bfd_error_bad_value);
14120 osec = sec->output_section;
14121 indx = elf_section_data (osec)->dynindx;
14125 if ((osec->flags & SEC_READONLY) == 0
14126 && htab->elf.data_index_section != NULL)
14127 osec = htab->elf.data_index_section;
14129 osec = htab->elf.text_index_section;
14130 indx = elf_section_data (osec)->dynindx;
14132 BFD_ASSERT (indx != 0);
14134 /* We are turning this relocation into one
14135 against a section symbol, so subtract out
14136 the output section's address but not the
14137 offset of the input section in the output
14139 outrel.r_addend -= osec->vma;
14142 outrel.r_info = ELF64_R_INFO (indx, r_type);
14146 sreloc = elf_section_data (input_section)->sreloc;
14148 ? h->elf.type == STT_GNU_IFUNC
14149 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14150 sreloc = htab->reliplt;
14151 if (sreloc == NULL)
14154 if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
14157 loc = sreloc->contents;
14158 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
14159 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
14161 /* If this reloc is against an external symbol, it will
14162 be computed at runtime, so there's no need to do
14163 anything now. However, for the sake of prelink ensure
14164 that the section contents are a known value. */
14167 unresolved_reloc = FALSE;
14168 /* The value chosen here is quite arbitrary as ld.so
14169 ignores section contents except for the special
14170 case of .opd where the contents might be accessed
14171 before relocation. Choose zero, as that won't
14172 cause reloc overflow. */
14175 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14176 to improve backward compatibility with older
14178 if (r_type == R_PPC64_ADDR64)
14179 addend = outrel.r_addend;
14180 /* Adjust pc_relative relocs to have zero in *r_offset. */
14181 else if (ppc64_elf_howto_table[r_type]->pc_relative)
14182 addend = (input_section->output_section->vma
14183 + input_section->output_offset
14190 case R_PPC64_GLOB_DAT:
14191 case R_PPC64_JMP_SLOT:
14192 case R_PPC64_JMP_IREL:
14193 case R_PPC64_RELATIVE:
14194 /* We shouldn't ever see these dynamic relocs in relocatable
14196 /* Fall through. */
14198 case R_PPC64_PLTGOT16:
14199 case R_PPC64_PLTGOT16_DS:
14200 case R_PPC64_PLTGOT16_HA:
14201 case R_PPC64_PLTGOT16_HI:
14202 case R_PPC64_PLTGOT16_LO:
14203 case R_PPC64_PLTGOT16_LO_DS:
14204 case R_PPC64_PLTREL32:
14205 case R_PPC64_PLTREL64:
14206 /* These ones haven't been implemented yet. */
14208 info->callbacks->einfo
14209 (_("%P: %B: %s is not supported for `%T'\n"),
14211 ppc64_elf_howto_table[r_type]->name, sym_name);
14213 bfd_set_error (bfd_error_invalid_operation);
14218 /* Multi-instruction sequences that access the TOC can be
14219 optimized, eg. addis ra,r2,0; addi rb,ra,x;
14220 to nop; addi rb,r2,x; */
14226 case R_PPC64_GOT_TLSLD16_HI:
14227 case R_PPC64_GOT_TLSGD16_HI:
14228 case R_PPC64_GOT_TPREL16_HI:
14229 case R_PPC64_GOT_DTPREL16_HI:
14230 case R_PPC64_GOT16_HI:
14231 case R_PPC64_TOC16_HI:
14232 /* These relocs would only be useful if building up an
14233 offset to later add to r2, perhaps in an indexed
14234 addressing mode instruction. Don't try to optimize.
14235 Unfortunately, the possibility of someone building up an
14236 offset like this or even with the HA relocs, means that
14237 we need to check the high insn when optimizing the low
14241 case R_PPC64_GOT_TLSLD16_HA:
14242 case R_PPC64_GOT_TLSGD16_HA:
14243 case R_PPC64_GOT_TPREL16_HA:
14244 case R_PPC64_GOT_DTPREL16_HA:
14245 case R_PPC64_GOT16_HA:
14246 case R_PPC64_TOC16_HA:
14247 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
14248 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
14250 bfd_byte *p = contents + (rel->r_offset & ~3);
14251 bfd_put_32 (input_bfd, NOP, p);
14255 case R_PPC64_GOT_TLSLD16_LO:
14256 case R_PPC64_GOT_TLSGD16_LO:
14257 case R_PPC64_GOT_TPREL16_LO_DS:
14258 case R_PPC64_GOT_DTPREL16_LO_DS:
14259 case R_PPC64_GOT16_LO:
14260 case R_PPC64_GOT16_LO_DS:
14261 case R_PPC64_TOC16_LO:
14262 case R_PPC64_TOC16_LO_DS:
14263 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
14264 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
14266 bfd_byte *p = contents + (rel->r_offset & ~3);
14267 insn = bfd_get_32 (input_bfd, p);
14268 if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
14270 /* Transform addic to addi when we change reg. */
14271 insn &= ~((0x3f << 26) | (0x1f << 16));
14272 insn |= (14u << 26) | (2 << 16);
14276 insn &= ~(0x1f << 16);
14279 bfd_put_32 (input_bfd, insn, p);
14284 /* Do any further special processing. */
14290 case R_PPC64_REL16_HA:
14291 case R_PPC64_ADDR16_HA:
14292 case R_PPC64_ADDR16_HIGHA:
14293 case R_PPC64_ADDR16_HIGHERA:
14294 case R_PPC64_ADDR16_HIGHESTA:
14295 case R_PPC64_TOC16_HA:
14296 case R_PPC64_SECTOFF_HA:
14297 case R_PPC64_TPREL16_HA:
14298 case R_PPC64_TPREL16_HIGHA:
14299 case R_PPC64_TPREL16_HIGHERA:
14300 case R_PPC64_TPREL16_HIGHESTA:
14301 case R_PPC64_DTPREL16_HA:
14302 case R_PPC64_DTPREL16_HIGHA:
14303 case R_PPC64_DTPREL16_HIGHERA:
14304 case R_PPC64_DTPREL16_HIGHESTA:
14305 /* It's just possible that this symbol is a weak symbol
14306 that's not actually defined anywhere. In that case,
14307 'sec' would be NULL, and we should leave the symbol
14308 alone (it will be set to zero elsewhere in the link). */
14313 case R_PPC64_GOT16_HA:
14314 case R_PPC64_PLTGOT16_HA:
14315 case R_PPC64_PLT16_HA:
14316 case R_PPC64_GOT_TLSGD16_HA:
14317 case R_PPC64_GOT_TLSLD16_HA:
14318 case R_PPC64_GOT_TPREL16_HA:
14319 case R_PPC64_GOT_DTPREL16_HA:
14320 /* Add 0x10000 if sign bit in 0:15 is set.
14321 Bits 0:15 are not used. */
14325 case R_PPC64_ADDR16_DS:
14326 case R_PPC64_ADDR16_LO_DS:
14327 case R_PPC64_GOT16_DS:
14328 case R_PPC64_GOT16_LO_DS:
14329 case R_PPC64_PLT16_LO_DS:
14330 case R_PPC64_SECTOFF_DS:
14331 case R_PPC64_SECTOFF_LO_DS:
14332 case R_PPC64_TOC16_DS:
14333 case R_PPC64_TOC16_LO_DS:
14334 case R_PPC64_PLTGOT16_DS:
14335 case R_PPC64_PLTGOT16_LO_DS:
14336 case R_PPC64_GOT_TPREL16_DS:
14337 case R_PPC64_GOT_TPREL16_LO_DS:
14338 case R_PPC64_GOT_DTPREL16_DS:
14339 case R_PPC64_GOT_DTPREL16_LO_DS:
14340 case R_PPC64_TPREL16_DS:
14341 case R_PPC64_TPREL16_LO_DS:
14342 case R_PPC64_DTPREL16_DS:
14343 case R_PPC64_DTPREL16_LO_DS:
14344 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
14346 /* If this reloc is against an lq insn, then the value must be
14347 a multiple of 16. This is somewhat of a hack, but the
14348 "correct" way to do this by defining _DQ forms of all the
14349 _DS relocs bloats all reloc switches in this file. It
14350 doesn't seem to make much sense to use any of these relocs
14351 in data, so testing the insn should be safe. */
14352 if ((insn & (0x3f << 26)) == (56u << 26))
14354 if (((relocation + addend) & mask) != 0)
14356 info->callbacks->einfo
14357 (_("%P: %H: error: %s not a multiple of %u\n"),
14358 input_bfd, input_section, rel->r_offset,
14359 ppc64_elf_howto_table[r_type]->name,
14361 bfd_set_error (bfd_error_bad_value);
14368 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
14369 because such sections are not SEC_ALLOC and thus ld.so will
14370 not process them. */
14371 if (unresolved_reloc
14372 && !((input_section->flags & SEC_DEBUGGING) != 0
14373 && h->elf.def_dynamic)
14374 && _bfd_elf_section_offset (output_bfd, info, input_section,
14375 rel->r_offset) != (bfd_vma) -1)
14377 info->callbacks->einfo
14378 (_("%P: %H: unresolvable %s against `%T'\n"),
14379 input_bfd, input_section, rel->r_offset,
14380 ppc64_elf_howto_table[(int) r_type]->name,
14381 h->elf.root.root.string);
14385 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
14393 if (r != bfd_reloc_ok)
14395 char *more_info = NULL;
14396 const char *reloc_name = ppc64_elf_howto_table[r_type]->name;
14398 if (reloc_dest != DEST_NORMAL)
14400 more_info = bfd_malloc (strlen (reloc_name) + 8);
14401 if (more_info != NULL)
14403 strcpy (more_info, reloc_name);
14404 strcat (more_info, (reloc_dest == DEST_OPD
14405 ? " (OPD)" : " (stub)"));
14406 reloc_name = more_info;
14410 if (r == bfd_reloc_overflow)
14415 && h->elf.root.type == bfd_link_hash_undefweak
14416 && ppc64_elf_howto_table[r_type]->pc_relative)
14418 /* Assume this is a call protected by other code that
14419 detects the symbol is undefined. If this is the case,
14420 we can safely ignore the overflow. If not, the
14421 program is hosed anyway, and a little warning isn't
14427 if (!((*info->callbacks->reloc_overflow)
14428 (info, &h->elf.root, sym_name,
14429 reloc_name, orig_rel.r_addend,
14430 input_bfd, input_section, rel->r_offset)))
14435 info->callbacks->einfo
14436 (_("%P: %H: %s against `%T': error %d\n"),
14437 input_bfd, input_section, rel->r_offset,
14438 reloc_name, sym_name, (int) r);
14441 if (more_info != NULL)
14446 /* If we're emitting relocations, then shortly after this function
14447 returns, reloc offsets and addends for this section will be
14448 adjusted. Worse, reloc symbol indices will be for the output
14449 file rather than the input. Save a copy of the relocs for
14450 opd_entry_value. */
14451 if (is_opd && (info->emitrelocations || info->relocatable))
14454 amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
14455 rel = bfd_alloc (input_bfd, amt);
14456 BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
14457 ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
14460 memcpy (rel, relocs, amt);
14465 /* Adjust the value of any local symbols in opd sections. */
14468 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
14469 const char *name ATTRIBUTE_UNUSED,
14470 Elf_Internal_Sym *elfsym,
14471 asection *input_sec,
14472 struct elf_link_hash_entry *h)
14474 struct _opd_sec_data *opd;
14481 opd = get_opd_info (input_sec);
14482 if (opd == NULL || opd->adjust == NULL)
14485 value = elfsym->st_value - input_sec->output_offset;
14486 if (!info->relocatable)
14487 value -= input_sec->output_section->vma;
14489 adjust = opd->adjust[value / 8];
14493 elfsym->st_value += adjust;
14497 /* Finish up dynamic symbol handling. We set the contents of various
14498 dynamic sections here. */
14501 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
14502 struct bfd_link_info *info,
14503 struct elf_link_hash_entry *h,
14504 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
14506 struct ppc_link_hash_table *htab;
14507 struct plt_entry *ent;
14508 Elf_Internal_Rela rela;
14511 htab = ppc_hash_table (info);
14515 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
14516 if (ent->plt.offset != (bfd_vma) -1)
14518 /* This symbol has an entry in the procedure linkage
14519 table. Set it up. */
14520 if (!htab->elf.dynamic_sections_created
14521 || h->dynindx == -1)
14523 BFD_ASSERT (h->type == STT_GNU_IFUNC
14525 && (h->root.type == bfd_link_hash_defined
14526 || h->root.type == bfd_link_hash_defweak));
14527 rela.r_offset = (htab->iplt->output_section->vma
14528 + htab->iplt->output_offset
14529 + ent->plt.offset);
14531 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
14533 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14534 rela.r_addend = (h->root.u.def.value
14535 + h->root.u.def.section->output_offset
14536 + h->root.u.def.section->output_section->vma
14538 loc = (htab->reliplt->contents
14539 + (htab->reliplt->reloc_count++
14540 * sizeof (Elf64_External_Rela)));
14544 rela.r_offset = (htab->plt->output_section->vma
14545 + htab->plt->output_offset
14546 + ent->plt.offset);
14547 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
14548 rela.r_addend = ent->addend;
14549 loc = (htab->relplt->contents
14550 + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
14551 / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
14553 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
14558 /* This symbol needs a copy reloc. Set it up. */
14560 if (h->dynindx == -1
14561 || (h->root.type != bfd_link_hash_defined
14562 && h->root.type != bfd_link_hash_defweak)
14563 || htab->relbss == NULL)
14566 rela.r_offset = (h->root.u.def.value
14567 + h->root.u.def.section->output_section->vma
14568 + h->root.u.def.section->output_offset);
14569 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
14571 loc = htab->relbss->contents;
14572 loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela);
14573 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
14579 /* Used to decide how to sort relocs in an optimal manner for the
14580 dynamic linker, before writing them out. */
14582 static enum elf_reloc_type_class
14583 ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
14584 const asection *rel_sec,
14585 const Elf_Internal_Rela *rela)
14587 enum elf_ppc64_reloc_type r_type;
14588 struct ppc_link_hash_table *htab = ppc_hash_table (info);
14590 if (rel_sec == htab->reliplt)
14591 return reloc_class_ifunc;
14593 r_type = ELF64_R_TYPE (rela->r_info);
14596 case R_PPC64_RELATIVE:
14597 return reloc_class_relative;
14598 case R_PPC64_JMP_SLOT:
14599 return reloc_class_plt;
14601 return reloc_class_copy;
14603 return reloc_class_normal;
14607 /* Finish up the dynamic sections. */
14610 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
14611 struct bfd_link_info *info)
14613 struct ppc_link_hash_table *htab;
14617 htab = ppc_hash_table (info);
14621 dynobj = htab->elf.dynobj;
14622 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
14624 if (htab->elf.dynamic_sections_created)
14626 Elf64_External_Dyn *dyncon, *dynconend;
14628 if (sdyn == NULL || htab->got == NULL)
14631 dyncon = (Elf64_External_Dyn *) sdyn->contents;
14632 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
14633 for (; dyncon < dynconend; dyncon++)
14635 Elf_Internal_Dyn dyn;
14638 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
14645 case DT_PPC64_GLINK:
14647 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14648 /* We stupidly defined DT_PPC64_GLINK to be the start
14649 of glink rather than the first entry point, which is
14650 what ld.so needs, and now have a bigger stub to
14651 support automatic multiple TOCs. */
14652 dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 8 * 4;
14656 s = bfd_get_section_by_name (output_bfd, ".opd");
14659 dyn.d_un.d_ptr = s->vma;
14662 case DT_PPC64_OPDSZ:
14663 s = bfd_get_section_by_name (output_bfd, ".opd");
14666 dyn.d_un.d_val = s->size;
14671 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14676 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14680 dyn.d_un.d_val = htab->relplt->size;
14684 /* Don't count procedure linkage table relocs in the
14685 overall reloc count. */
14689 dyn.d_un.d_val -= s->size;
14693 /* We may not be using the standard ELF linker script.
14694 If .rela.plt is the first .rela section, we adjust
14695 DT_RELA to not include it. */
14699 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
14701 dyn.d_un.d_ptr += s->size;
14705 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
14709 if (htab->got != NULL && htab->got->size != 0)
14711 /* Fill in the first entry in the global offset table.
14712 We use it to hold the link-time TOCbase. */
14713 bfd_put_64 (output_bfd,
14714 elf_gp (output_bfd) + TOC_BASE_OFF,
14715 htab->got->contents);
14717 /* Set .got entry size. */
14718 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8;
14721 if (htab->plt != NULL && htab->plt->size != 0)
14723 /* Set .plt entry size. */
14724 elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize
14725 = PLT_ENTRY_SIZE (htab);
14728 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
14729 brlt ourselves if emitrelocations. */
14730 if (htab->brlt != NULL
14731 && htab->brlt->reloc_count != 0
14732 && !_bfd_elf_link_output_relocs (output_bfd,
14734 elf_section_data (htab->brlt)->rela.hdr,
14735 elf_section_data (htab->brlt)->relocs,
14739 if (htab->glink != NULL
14740 && htab->glink->reloc_count != 0
14741 && !_bfd_elf_link_output_relocs (output_bfd,
14743 elf_section_data (htab->glink)->rela.hdr,
14744 elf_section_data (htab->glink)->relocs,
14749 if (htab->glink_eh_frame != NULL
14750 && htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
14751 && !_bfd_elf_write_section_eh_frame (output_bfd, info,
14752 htab->glink_eh_frame,
14753 htab->glink_eh_frame->contents))
14756 /* We need to handle writing out multiple GOT sections ourselves,
14757 since we didn't add them to DYNOBJ. We know dynobj is the first
14759 while ((dynobj = dynobj->link_next) != NULL)
14763 if (!is_ppc64_elf (dynobj))
14766 s = ppc64_elf_tdata (dynobj)->got;
14769 && s->output_section != bfd_abs_section_ptr
14770 && !bfd_set_section_contents (output_bfd, s->output_section,
14771 s->contents, s->output_offset,
14774 s = ppc64_elf_tdata (dynobj)->relgot;
14777 && s->output_section != bfd_abs_section_ptr
14778 && !bfd_set_section_contents (output_bfd, s->output_section,
14779 s->contents, s->output_offset,
14787 #include "elf64-target.h"
14789 /* FreeBSD support */
14791 #undef TARGET_LITTLE_SYM
14792 #undef TARGET_LITTLE_NAME
14794 #undef TARGET_BIG_SYM
14795 #define TARGET_BIG_SYM bfd_elf64_powerpc_freebsd_vec
14796 #undef TARGET_BIG_NAME
14797 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
14800 #define ELF_OSABI ELFOSABI_FREEBSD
14803 #define elf64_bed elf64_powerpc_fbsd_bed
14805 #include "elf64-target.h"