1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010, 2011 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
*);
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 _bfd_generic_verify_endian_match
85 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
86 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
87 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
88 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
89 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
91 #define elf_backend_object_p ppc64_elf_object_p
92 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
93 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
94 #define elf_backend_write_core_note ppc64_elf_write_core_note
95 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
96 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
97 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
98 #define elf_backend_check_directives ppc64_elf_process_dot_syms
99 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
100 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
101 #define elf_backend_check_relocs ppc64_elf_check_relocs
102 #define elf_backend_gc_keep ppc64_elf_gc_keep
103 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
104 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
105 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
106 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
107 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
108 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
109 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
110 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
111 #define elf_backend_action_discarded ppc64_elf_action_discarded
112 #define elf_backend_relocate_section ppc64_elf_relocate_section
113 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
114 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
115 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
116 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
117 #define elf_backend_special_sections ppc64_elf_special_sections
118 #define elf_backend_post_process_headers _bfd_elf_set_osabi
120 /* The name of the dynamic interpreter. This is put in the .interp
122 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
124 /* The size in bytes of an entry in the procedure linkage table. */
125 #define PLT_ENTRY_SIZE 24
127 /* The initial size of the plt reserved for the dynamic linker. */
128 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
130 /* TOC base pointers offset from start of TOC. */
131 #define TOC_BASE_OFF 0x8000
133 /* Offset of tp and dtp pointers from start of TLS block. */
134 #define TP_OFFSET 0x7000
135 #define DTP_OFFSET 0x8000
137 /* .plt call stub instructions. The normal stub is like this, but
138 sometimes the .plt entry crosses a 64k boundary and we need to
139 insert an addi to adjust r12. */
140 #define PLT_CALL_STUB_SIZE (7*4)
141 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
142 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
143 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
144 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
145 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
146 /* ld %r11,xxx+16@l(%r12) */
147 #define BCTR 0x4e800420 /* bctr */
150 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
151 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
152 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
153 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
155 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
156 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
158 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
160 /* glink call stub instructions. We enter with the index in R0. */
161 #define GLINK_CALL_STUB_SIZE (16*4)
165 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
166 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
168 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
169 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
170 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
171 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
179 #define NOP 0x60000000
181 /* Some other nops. */
182 #define CROR_151515 0x4def7b82
183 #define CROR_313131 0x4ffffb82
185 /* .glink entries for the first 32k functions are two instructions. */
186 #define LI_R0_0 0x38000000 /* li %r0,0 */
187 #define B_DOT 0x48000000 /* b . */
189 /* After that, we need two instructions to load the index, followed by
191 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
192 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
194 /* Instructions used by the save and restore reg functions. */
195 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
196 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
197 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
198 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
199 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
200 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
201 #define LI_R12_0 0x39800000 /* li %r12,0 */
202 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
203 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
204 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
205 #define BLR 0x4e800020 /* blr */
207 /* Since .opd is an array of descriptors and each entry will end up
208 with identical R_PPC64_RELATIVE relocs, there is really no need to
209 propagate .opd relocs; The dynamic linker should be taught to
210 relocate .opd without reloc entries. */
211 #ifndef NO_OPD_RELOCS
212 #define NO_OPD_RELOCS 0
215 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
217 /* Relocation HOWTO's. */
218 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
220 static reloc_howto_type ppc64_elf_howto_raw
[] = {
221 /* This reloc does nothing. */
222 HOWTO (R_PPC64_NONE
, /* type */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
226 FALSE
, /* pc_relative */
228 complain_overflow_dont
, /* complain_on_overflow */
229 bfd_elf_generic_reloc
, /* special_function */
230 "R_PPC64_NONE", /* name */
231 FALSE
, /* partial_inplace */
234 FALSE
), /* pcrel_offset */
236 /* A standard 32 bit relocation. */
237 HOWTO (R_PPC64_ADDR32
, /* type */
239 2, /* size (0 = byte, 1 = short, 2 = long) */
241 FALSE
, /* pc_relative */
243 complain_overflow_bitfield
, /* complain_on_overflow */
244 bfd_elf_generic_reloc
, /* special_function */
245 "R_PPC64_ADDR32", /* name */
246 FALSE
, /* partial_inplace */
248 0xffffffff, /* dst_mask */
249 FALSE
), /* pcrel_offset */
251 /* An absolute 26 bit branch; the lower two bits must be zero.
252 FIXME: we don't check that, we just clear them. */
253 HOWTO (R_PPC64_ADDR24
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_bitfield
, /* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_PPC64_ADDR24", /* name */
262 FALSE
, /* partial_inplace */
264 0x03fffffc, /* dst_mask */
265 FALSE
), /* pcrel_offset */
267 /* A standard 16 bit relocation. */
268 HOWTO (R_PPC64_ADDR16
, /* type */
270 1, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE
, /* pc_relative */
274 complain_overflow_bitfield
, /* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* special_function */
276 "R_PPC64_ADDR16", /* name */
277 FALSE
, /* partial_inplace */
279 0xffff, /* dst_mask */
280 FALSE
), /* pcrel_offset */
282 /* A 16 bit relocation without overflow. */
283 HOWTO (R_PPC64_ADDR16_LO
, /* type */
285 1, /* size (0 = byte, 1 = short, 2 = long) */
287 FALSE
, /* pc_relative */
289 complain_overflow_dont
,/* complain_on_overflow */
290 bfd_elf_generic_reloc
, /* special_function */
291 "R_PPC64_ADDR16_LO", /* name */
292 FALSE
, /* partial_inplace */
294 0xffff, /* dst_mask */
295 FALSE
), /* pcrel_offset */
297 /* Bits 16-31 of an address. */
298 HOWTO (R_PPC64_ADDR16_HI
, /* type */
300 1, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE
, /* pc_relative */
304 complain_overflow_dont
, /* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_PPC64_ADDR16_HI", /* name */
307 FALSE
, /* partial_inplace */
309 0xffff, /* dst_mask */
310 FALSE
), /* pcrel_offset */
312 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
313 bits, treated as a signed number, is negative. */
314 HOWTO (R_PPC64_ADDR16_HA
, /* type */
316 1, /* size (0 = byte, 1 = short, 2 = long) */
318 FALSE
, /* pc_relative */
320 complain_overflow_dont
, /* complain_on_overflow */
321 ppc64_elf_ha_reloc
, /* special_function */
322 "R_PPC64_ADDR16_HA", /* name */
323 FALSE
, /* partial_inplace */
325 0xffff, /* dst_mask */
326 FALSE
), /* pcrel_offset */
328 /* An absolute 16 bit branch; the lower two bits must be zero.
329 FIXME: we don't check that, we just clear them. */
330 HOWTO (R_PPC64_ADDR14
, /* type */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
334 FALSE
, /* pc_relative */
336 complain_overflow_bitfield
, /* complain_on_overflow */
337 ppc64_elf_branch_reloc
, /* special_function */
338 "R_PPC64_ADDR14", /* name */
339 FALSE
, /* partial_inplace */
341 0x0000fffc, /* dst_mask */
342 FALSE
), /* pcrel_offset */
344 /* An absolute 16 bit branch, for which bit 10 should be set to
345 indicate that the branch is expected to be taken. The lower two
346 bits must be zero. */
347 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 FALSE
, /* pc_relative */
353 complain_overflow_bitfield
, /* complain_on_overflow */
354 ppc64_elf_brtaken_reloc
, /* special_function */
355 "R_PPC64_ADDR14_BRTAKEN",/* name */
356 FALSE
, /* partial_inplace */
358 0x0000fffc, /* dst_mask */
359 FALSE
), /* pcrel_offset */
361 /* An absolute 16 bit branch, for which bit 10 should be set to
362 indicate that the branch is not expected to be taken. The lower
363 two bits must be zero. */
364 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 FALSE
, /* pc_relative */
370 complain_overflow_bitfield
, /* complain_on_overflow */
371 ppc64_elf_brtaken_reloc
, /* special_function */
372 "R_PPC64_ADDR14_BRNTAKEN",/* name */
373 FALSE
, /* partial_inplace */
375 0x0000fffc, /* dst_mask */
376 FALSE
), /* pcrel_offset */
378 /* A relative 26 bit branch; the lower two bits must be zero. */
379 HOWTO (R_PPC64_REL24
, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 TRUE
, /* pc_relative */
385 complain_overflow_signed
, /* complain_on_overflow */
386 ppc64_elf_branch_reloc
, /* special_function */
387 "R_PPC64_REL24", /* name */
388 FALSE
, /* partial_inplace */
390 0x03fffffc, /* dst_mask */
391 TRUE
), /* pcrel_offset */
393 /* A relative 16 bit branch; the lower two bits must be zero. */
394 HOWTO (R_PPC64_REL14
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 TRUE
, /* pc_relative */
400 complain_overflow_signed
, /* complain_on_overflow */
401 ppc64_elf_branch_reloc
, /* special_function */
402 "R_PPC64_REL14", /* name */
403 FALSE
, /* partial_inplace */
405 0x0000fffc, /* dst_mask */
406 TRUE
), /* pcrel_offset */
408 /* A relative 16 bit branch. Bit 10 should be set to indicate that
409 the branch is expected to be taken. The lower two bits must be
411 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
413 2, /* size (0 = byte, 1 = short, 2 = long) */
415 TRUE
, /* pc_relative */
417 complain_overflow_signed
, /* complain_on_overflow */
418 ppc64_elf_brtaken_reloc
, /* special_function */
419 "R_PPC64_REL14_BRTAKEN", /* name */
420 FALSE
, /* partial_inplace */
422 0x0000fffc, /* dst_mask */
423 TRUE
), /* pcrel_offset */
425 /* A relative 16 bit branch. Bit 10 should be set to indicate that
426 the branch is not expected to be taken. The lower two bits must
428 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 TRUE
, /* pc_relative */
434 complain_overflow_signed
, /* complain_on_overflow */
435 ppc64_elf_brtaken_reloc
, /* special_function */
436 "R_PPC64_REL14_BRNTAKEN",/* name */
437 FALSE
, /* partial_inplace */
439 0x0000fffc, /* dst_mask */
440 TRUE
), /* pcrel_offset */
442 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
444 HOWTO (R_PPC64_GOT16
, /* type */
446 1, /* size (0 = byte, 1 = short, 2 = long) */
448 FALSE
, /* pc_relative */
450 complain_overflow_signed
, /* complain_on_overflow */
451 ppc64_elf_unhandled_reloc
, /* special_function */
452 "R_PPC64_GOT16", /* name */
453 FALSE
, /* partial_inplace */
455 0xffff, /* dst_mask */
456 FALSE
), /* pcrel_offset */
458 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
460 HOWTO (R_PPC64_GOT16_LO
, /* type */
462 1, /* size (0 = byte, 1 = short, 2 = long) */
464 FALSE
, /* pc_relative */
466 complain_overflow_dont
, /* complain_on_overflow */
467 ppc64_elf_unhandled_reloc
, /* special_function */
468 "R_PPC64_GOT16_LO", /* name */
469 FALSE
, /* partial_inplace */
471 0xffff, /* dst_mask */
472 FALSE
), /* pcrel_offset */
474 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
476 HOWTO (R_PPC64_GOT16_HI
, /* type */
478 1, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE
, /* pc_relative */
482 complain_overflow_dont
,/* complain_on_overflow */
483 ppc64_elf_unhandled_reloc
, /* special_function */
484 "R_PPC64_GOT16_HI", /* name */
485 FALSE
, /* partial_inplace */
487 0xffff, /* dst_mask */
488 FALSE
), /* pcrel_offset */
490 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
492 HOWTO (R_PPC64_GOT16_HA
, /* type */
494 1, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE
, /* pc_relative */
498 complain_overflow_dont
,/* complain_on_overflow */
499 ppc64_elf_unhandled_reloc
, /* special_function */
500 "R_PPC64_GOT16_HA", /* name */
501 FALSE
, /* partial_inplace */
503 0xffff, /* dst_mask */
504 FALSE
), /* pcrel_offset */
506 /* This is used only by the dynamic linker. The symbol should exist
507 both in the object being run and in some shared library. The
508 dynamic linker copies the data addressed by the symbol from the
509 shared library into the object, because the object being
510 run has to have the data at some particular address. */
511 HOWTO (R_PPC64_COPY
, /* type */
513 0, /* this one is variable size */
515 FALSE
, /* pc_relative */
517 complain_overflow_dont
, /* complain_on_overflow */
518 ppc64_elf_unhandled_reloc
, /* special_function */
519 "R_PPC64_COPY", /* name */
520 FALSE
, /* partial_inplace */
523 FALSE
), /* pcrel_offset */
525 /* Like R_PPC64_ADDR64, but used when setting global offset table
527 HOWTO (R_PPC64_GLOB_DAT
, /* type */
529 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
531 FALSE
, /* pc_relative */
533 complain_overflow_dont
, /* complain_on_overflow */
534 ppc64_elf_unhandled_reloc
, /* special_function */
535 "R_PPC64_GLOB_DAT", /* name */
536 FALSE
, /* partial_inplace */
538 ONES (64), /* dst_mask */
539 FALSE
), /* pcrel_offset */
541 /* Created by the link editor. Marks a procedure linkage table
542 entry for a symbol. */
543 HOWTO (R_PPC64_JMP_SLOT
, /* type */
545 0, /* size (0 = byte, 1 = short, 2 = long) */
547 FALSE
, /* pc_relative */
549 complain_overflow_dont
, /* complain_on_overflow */
550 ppc64_elf_unhandled_reloc
, /* special_function */
551 "R_PPC64_JMP_SLOT", /* name */
552 FALSE
, /* partial_inplace */
555 FALSE
), /* pcrel_offset */
557 /* Used only by the dynamic linker. When the object is run, this
558 doubleword64 is set to the load address of the object, plus the
560 HOWTO (R_PPC64_RELATIVE
, /* type */
562 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
564 FALSE
, /* pc_relative */
566 complain_overflow_dont
, /* complain_on_overflow */
567 bfd_elf_generic_reloc
, /* special_function */
568 "R_PPC64_RELATIVE", /* name */
569 FALSE
, /* partial_inplace */
571 ONES (64), /* dst_mask */
572 FALSE
), /* pcrel_offset */
574 /* Like R_PPC64_ADDR32, but may be unaligned. */
575 HOWTO (R_PPC64_UADDR32
, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 FALSE
, /* pc_relative */
581 complain_overflow_bitfield
, /* complain_on_overflow */
582 bfd_elf_generic_reloc
, /* special_function */
583 "R_PPC64_UADDR32", /* name */
584 FALSE
, /* partial_inplace */
586 0xffffffff, /* dst_mask */
587 FALSE
), /* pcrel_offset */
589 /* Like R_PPC64_ADDR16, but may be unaligned. */
590 HOWTO (R_PPC64_UADDR16
, /* type */
592 1, /* size (0 = byte, 1 = short, 2 = long) */
594 FALSE
, /* pc_relative */
596 complain_overflow_bitfield
, /* complain_on_overflow */
597 bfd_elf_generic_reloc
, /* special_function */
598 "R_PPC64_UADDR16", /* name */
599 FALSE
, /* partial_inplace */
601 0xffff, /* dst_mask */
602 FALSE
), /* pcrel_offset */
604 /* 32-bit PC relative. */
605 HOWTO (R_PPC64_REL32
, /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 TRUE
, /* pc_relative */
611 /* FIXME: Verify. Was complain_overflow_bitfield. */
612 complain_overflow_signed
, /* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 "R_PPC64_REL32", /* name */
615 FALSE
, /* partial_inplace */
617 0xffffffff, /* dst_mask */
618 TRUE
), /* pcrel_offset */
620 /* 32-bit relocation to the symbol's procedure linkage table. */
621 HOWTO (R_PPC64_PLT32
, /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 FALSE
, /* pc_relative */
627 complain_overflow_bitfield
, /* complain_on_overflow */
628 ppc64_elf_unhandled_reloc
, /* special_function */
629 "R_PPC64_PLT32", /* name */
630 FALSE
, /* partial_inplace */
632 0xffffffff, /* dst_mask */
633 FALSE
), /* pcrel_offset */
635 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
636 FIXME: R_PPC64_PLTREL32 not supported. */
637 HOWTO (R_PPC64_PLTREL32
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 TRUE
, /* pc_relative */
643 complain_overflow_signed
, /* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_PPC64_PLTREL32", /* name */
646 FALSE
, /* partial_inplace */
648 0xffffffff, /* dst_mask */
649 TRUE
), /* pcrel_offset */
651 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
653 HOWTO (R_PPC64_PLT16_LO
, /* type */
655 1, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_dont
, /* complain_on_overflow */
660 ppc64_elf_unhandled_reloc
, /* special_function */
661 "R_PPC64_PLT16_LO", /* name */
662 FALSE
, /* partial_inplace */
664 0xffff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
667 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
669 HOWTO (R_PPC64_PLT16_HI
, /* type */
671 1, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE
, /* pc_relative */
675 complain_overflow_dont
, /* complain_on_overflow */
676 ppc64_elf_unhandled_reloc
, /* special_function */
677 "R_PPC64_PLT16_HI", /* name */
678 FALSE
, /* partial_inplace */
680 0xffff, /* dst_mask */
681 FALSE
), /* pcrel_offset */
683 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
685 HOWTO (R_PPC64_PLT16_HA
, /* type */
687 1, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE
, /* pc_relative */
691 complain_overflow_dont
, /* complain_on_overflow */
692 ppc64_elf_unhandled_reloc
, /* special_function */
693 "R_PPC64_PLT16_HA", /* name */
694 FALSE
, /* partial_inplace */
696 0xffff, /* dst_mask */
697 FALSE
), /* pcrel_offset */
699 /* 16-bit section relative relocation. */
700 HOWTO (R_PPC64_SECTOFF
, /* type */
702 1, /* size (0 = byte, 1 = short, 2 = long) */
704 FALSE
, /* pc_relative */
706 complain_overflow_bitfield
, /* complain_on_overflow */
707 ppc64_elf_sectoff_reloc
, /* special_function */
708 "R_PPC64_SECTOFF", /* name */
709 FALSE
, /* partial_inplace */
711 0xffff, /* dst_mask */
712 FALSE
), /* pcrel_offset */
714 /* Like R_PPC64_SECTOFF, but no overflow warning. */
715 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
717 1, /* size (0 = byte, 1 = short, 2 = long) */
719 FALSE
, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 ppc64_elf_sectoff_reloc
, /* special_function */
723 "R_PPC64_SECTOFF_LO", /* name */
724 FALSE
, /* partial_inplace */
726 0xffff, /* dst_mask */
727 FALSE
), /* pcrel_offset */
729 /* 16-bit upper half section relative relocation. */
730 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
734 FALSE
, /* pc_relative */
736 complain_overflow_dont
, /* complain_on_overflow */
737 ppc64_elf_sectoff_reloc
, /* special_function */
738 "R_PPC64_SECTOFF_HI", /* name */
739 FALSE
, /* partial_inplace */
741 0xffff, /* dst_mask */
742 FALSE
), /* pcrel_offset */
744 /* 16-bit upper half adjusted section relative relocation. */
745 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
747 1, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE
, /* pc_relative */
751 complain_overflow_dont
, /* complain_on_overflow */
752 ppc64_elf_sectoff_ha_reloc
, /* special_function */
753 "R_PPC64_SECTOFF_HA", /* name */
754 FALSE
, /* partial_inplace */
756 0xffff, /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 /* Like R_PPC64_REL24 without touching the two least significant bits. */
760 HOWTO (R_PPC64_REL30
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 TRUE
, /* pc_relative */
766 complain_overflow_dont
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_PPC64_REL30", /* name */
769 FALSE
, /* partial_inplace */
771 0xfffffffc, /* dst_mask */
772 TRUE
), /* pcrel_offset */
774 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
776 /* A standard 64-bit relocation. */
777 HOWTO (R_PPC64_ADDR64
, /* type */
779 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
781 FALSE
, /* pc_relative */
783 complain_overflow_dont
, /* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 "R_PPC64_ADDR64", /* name */
786 FALSE
, /* partial_inplace */
788 ONES (64), /* dst_mask */
789 FALSE
), /* pcrel_offset */
791 /* The bits 32-47 of an address. */
792 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 FALSE
, /* pc_relative */
798 complain_overflow_dont
, /* complain_on_overflow */
799 bfd_elf_generic_reloc
, /* special_function */
800 "R_PPC64_ADDR16_HIGHER", /* name */
801 FALSE
, /* partial_inplace */
803 0xffff, /* dst_mask */
804 FALSE
), /* pcrel_offset */
806 /* The bits 32-47 of an address, plus 1 if the contents of the low
807 16 bits, treated as a signed number, is negative. */
808 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
810 1, /* size (0 = byte, 1 = short, 2 = long) */
812 FALSE
, /* pc_relative */
814 complain_overflow_dont
, /* complain_on_overflow */
815 ppc64_elf_ha_reloc
, /* special_function */
816 "R_PPC64_ADDR16_HIGHERA", /* name */
817 FALSE
, /* partial_inplace */
819 0xffff, /* dst_mask */
820 FALSE
), /* pcrel_offset */
822 /* The bits 48-63 of an address. */
823 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
825 1, /* size (0 = byte, 1 = short, 2 = long) */
827 FALSE
, /* pc_relative */
829 complain_overflow_dont
, /* complain_on_overflow */
830 bfd_elf_generic_reloc
, /* special_function */
831 "R_PPC64_ADDR16_HIGHEST", /* name */
832 FALSE
, /* partial_inplace */
834 0xffff, /* dst_mask */
835 FALSE
), /* pcrel_offset */
837 /* The bits 48-63 of an address, plus 1 if the contents of the low
838 16 bits, treated as a signed number, is negative. */
839 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
841 1, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE
, /* pc_relative */
845 complain_overflow_dont
, /* complain_on_overflow */
846 ppc64_elf_ha_reloc
, /* special_function */
847 "R_PPC64_ADDR16_HIGHESTA", /* name */
848 FALSE
, /* partial_inplace */
850 0xffff, /* dst_mask */
851 FALSE
), /* pcrel_offset */
853 /* Like ADDR64, but may be unaligned. */
854 HOWTO (R_PPC64_UADDR64
, /* type */
856 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
858 FALSE
, /* pc_relative */
860 complain_overflow_dont
, /* complain_on_overflow */
861 bfd_elf_generic_reloc
, /* special_function */
862 "R_PPC64_UADDR64", /* name */
863 FALSE
, /* partial_inplace */
865 ONES (64), /* dst_mask */
866 FALSE
), /* pcrel_offset */
868 /* 64-bit relative relocation. */
869 HOWTO (R_PPC64_REL64
, /* type */
871 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
873 TRUE
, /* pc_relative */
875 complain_overflow_dont
, /* complain_on_overflow */
876 bfd_elf_generic_reloc
, /* special_function */
877 "R_PPC64_REL64", /* name */
878 FALSE
, /* partial_inplace */
880 ONES (64), /* dst_mask */
881 TRUE
), /* pcrel_offset */
883 /* 64-bit relocation to the symbol's procedure linkage table. */
884 HOWTO (R_PPC64_PLT64
, /* type */
886 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
888 FALSE
, /* pc_relative */
890 complain_overflow_dont
, /* complain_on_overflow */
891 ppc64_elf_unhandled_reloc
, /* special_function */
892 "R_PPC64_PLT64", /* name */
893 FALSE
, /* partial_inplace */
895 ONES (64), /* dst_mask */
896 FALSE
), /* pcrel_offset */
898 /* 64-bit PC relative relocation to the symbol's procedure linkage
900 /* FIXME: R_PPC64_PLTREL64 not supported. */
901 HOWTO (R_PPC64_PLTREL64
, /* type */
903 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
905 TRUE
, /* pc_relative */
907 complain_overflow_dont
, /* complain_on_overflow */
908 ppc64_elf_unhandled_reloc
, /* special_function */
909 "R_PPC64_PLTREL64", /* name */
910 FALSE
, /* partial_inplace */
912 ONES (64), /* dst_mask */
913 TRUE
), /* pcrel_offset */
915 /* 16 bit TOC-relative relocation. */
917 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
918 HOWTO (R_PPC64_TOC16
, /* type */
920 1, /* size (0 = byte, 1 = short, 2 = long) */
922 FALSE
, /* pc_relative */
924 complain_overflow_signed
, /* complain_on_overflow */
925 ppc64_elf_toc_reloc
, /* special_function */
926 "R_PPC64_TOC16", /* name */
927 FALSE
, /* partial_inplace */
929 0xffff, /* dst_mask */
930 FALSE
), /* pcrel_offset */
932 /* 16 bit TOC-relative relocation without overflow. */
934 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
935 HOWTO (R_PPC64_TOC16_LO
, /* type */
937 1, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_dont
, /* complain_on_overflow */
942 ppc64_elf_toc_reloc
, /* special_function */
943 "R_PPC64_TOC16_LO", /* name */
944 FALSE
, /* partial_inplace */
946 0xffff, /* dst_mask */
947 FALSE
), /* pcrel_offset */
949 /* 16 bit TOC-relative relocation, high 16 bits. */
951 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
952 HOWTO (R_PPC64_TOC16_HI
, /* type */
954 1, /* size (0 = byte, 1 = short, 2 = long) */
956 FALSE
, /* pc_relative */
958 complain_overflow_dont
, /* complain_on_overflow */
959 ppc64_elf_toc_reloc
, /* special_function */
960 "R_PPC64_TOC16_HI", /* name */
961 FALSE
, /* partial_inplace */
963 0xffff, /* dst_mask */
964 FALSE
), /* pcrel_offset */
966 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
967 contents of the low 16 bits, treated as a signed number, is
970 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
971 HOWTO (R_PPC64_TOC16_HA
, /* type */
973 1, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_dont
, /* complain_on_overflow */
978 ppc64_elf_toc_ha_reloc
, /* special_function */
979 "R_PPC64_TOC16_HA", /* name */
980 FALSE
, /* partial_inplace */
982 0xffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 /* 64-bit relocation; insert value of TOC base (.TOC.). */
987 /* R_PPC64_TOC 51 doubleword64 .TOC. */
988 HOWTO (R_PPC64_TOC
, /* type */
990 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
992 FALSE
, /* pc_relative */
994 complain_overflow_bitfield
, /* complain_on_overflow */
995 ppc64_elf_toc64_reloc
, /* special_function */
996 "R_PPC64_TOC", /* name */
997 FALSE
, /* partial_inplace */
999 ONES (64), /* dst_mask */
1000 FALSE
), /* pcrel_offset */
1002 /* Like R_PPC64_GOT16, but also informs the link editor that the
1003 value to relocate may (!) refer to a PLT entry which the link
1004 editor (a) may replace with the symbol value. If the link editor
1005 is unable to fully resolve the symbol, it may (b) create a PLT
1006 entry and store the address to the new PLT entry in the GOT.
1007 This permits lazy resolution of function symbols at run time.
1008 The link editor may also skip all of this and just (c) emit a
1009 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1010 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1011 HOWTO (R_PPC64_PLTGOT16
, /* type */
1013 1, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE
, /* pc_relative */
1017 complain_overflow_signed
, /* complain_on_overflow */
1018 ppc64_elf_unhandled_reloc
, /* special_function */
1019 "R_PPC64_PLTGOT16", /* name */
1020 FALSE
, /* partial_inplace */
1022 0xffff, /* dst_mask */
1023 FALSE
), /* pcrel_offset */
1025 /* Like R_PPC64_PLTGOT16, but without overflow. */
1026 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1027 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1029 1, /* size (0 = byte, 1 = short, 2 = long) */
1031 FALSE
, /* pc_relative */
1033 complain_overflow_dont
, /* complain_on_overflow */
1034 ppc64_elf_unhandled_reloc
, /* special_function */
1035 "R_PPC64_PLTGOT16_LO", /* name */
1036 FALSE
, /* partial_inplace */
1038 0xffff, /* dst_mask */
1039 FALSE
), /* pcrel_offset */
1041 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1042 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1043 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1044 16, /* rightshift */
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_dont
, /* complain_on_overflow */
1050 ppc64_elf_unhandled_reloc
, /* special_function */
1051 "R_PPC64_PLTGOT16_HI", /* name */
1052 FALSE
, /* partial_inplace */
1054 0xffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1058 1 if the contents of the low 16 bits, treated as a signed number,
1060 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1061 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1062 16, /* rightshift */
1063 1, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE
, /* pc_relative */
1067 complain_overflow_dont
,/* complain_on_overflow */
1068 ppc64_elf_unhandled_reloc
, /* special_function */
1069 "R_PPC64_PLTGOT16_HA", /* name */
1070 FALSE
, /* partial_inplace */
1072 0xffff, /* dst_mask */
1073 FALSE
), /* pcrel_offset */
1075 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1076 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE
, /* pc_relative */
1082 complain_overflow_bitfield
, /* complain_on_overflow */
1083 bfd_elf_generic_reloc
, /* special_function */
1084 "R_PPC64_ADDR16_DS", /* name */
1085 FALSE
, /* partial_inplace */
1087 0xfffc, /* dst_mask */
1088 FALSE
), /* pcrel_offset */
1090 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1091 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1093 1, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_dont
,/* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 "R_PPC64_ADDR16_LO_DS",/* name */
1100 FALSE
, /* partial_inplace */
1102 0xfffc, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1106 HOWTO (R_PPC64_GOT16_DS
, /* type */
1108 1, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_signed
, /* complain_on_overflow */
1113 ppc64_elf_unhandled_reloc
, /* special_function */
1114 "R_PPC64_GOT16_DS", /* name */
1115 FALSE
, /* partial_inplace */
1117 0xfffc, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1120 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1121 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1123 1, /* size (0 = byte, 1 = short, 2 = long) */
1125 FALSE
, /* pc_relative */
1127 complain_overflow_dont
, /* complain_on_overflow */
1128 ppc64_elf_unhandled_reloc
, /* special_function */
1129 "R_PPC64_GOT16_LO_DS", /* name */
1130 FALSE
, /* partial_inplace */
1132 0xfffc, /* dst_mask */
1133 FALSE
), /* pcrel_offset */
1135 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1136 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1138 1, /* size (0 = byte, 1 = short, 2 = long) */
1140 FALSE
, /* pc_relative */
1142 complain_overflow_dont
, /* complain_on_overflow */
1143 ppc64_elf_unhandled_reloc
, /* special_function */
1144 "R_PPC64_PLT16_LO_DS", /* name */
1145 FALSE
, /* partial_inplace */
1147 0xfffc, /* dst_mask */
1148 FALSE
), /* pcrel_offset */
1150 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1151 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1153 1, /* size (0 = byte, 1 = short, 2 = long) */
1155 FALSE
, /* pc_relative */
1157 complain_overflow_bitfield
, /* complain_on_overflow */
1158 ppc64_elf_sectoff_reloc
, /* special_function */
1159 "R_PPC64_SECTOFF_DS", /* name */
1160 FALSE
, /* partial_inplace */
1162 0xfffc, /* dst_mask */
1163 FALSE
), /* pcrel_offset */
1165 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1166 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1168 1, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE
, /* pc_relative */
1172 complain_overflow_dont
, /* complain_on_overflow */
1173 ppc64_elf_sectoff_reloc
, /* special_function */
1174 "R_PPC64_SECTOFF_LO_DS",/* name */
1175 FALSE
, /* partial_inplace */
1177 0xfffc, /* dst_mask */
1178 FALSE
), /* pcrel_offset */
1180 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1181 HOWTO (R_PPC64_TOC16_DS
, /* type */
1183 1, /* size (0 = byte, 1 = short, 2 = long) */
1185 FALSE
, /* pc_relative */
1187 complain_overflow_signed
, /* complain_on_overflow */
1188 ppc64_elf_toc_reloc
, /* special_function */
1189 "R_PPC64_TOC16_DS", /* name */
1190 FALSE
, /* partial_inplace */
1192 0xfffc, /* dst_mask */
1193 FALSE
), /* pcrel_offset */
1195 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1196 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1198 1, /* size (0 = byte, 1 = short, 2 = long) */
1200 FALSE
, /* pc_relative */
1202 complain_overflow_dont
, /* complain_on_overflow */
1203 ppc64_elf_toc_reloc
, /* special_function */
1204 "R_PPC64_TOC16_LO_DS", /* name */
1205 FALSE
, /* partial_inplace */
1207 0xfffc, /* dst_mask */
1208 FALSE
), /* pcrel_offset */
1210 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1211 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1212 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1214 1, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_signed
, /* complain_on_overflow */
1219 ppc64_elf_unhandled_reloc
, /* special_function */
1220 "R_PPC64_PLTGOT16_DS", /* name */
1221 FALSE
, /* partial_inplace */
1223 0xfffc, /* dst_mask */
1224 FALSE
), /* pcrel_offset */
1226 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1227 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1228 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1230 1, /* size (0 = byte, 1 = short, 2 = long) */
1232 FALSE
, /* pc_relative */
1234 complain_overflow_dont
, /* complain_on_overflow */
1235 ppc64_elf_unhandled_reloc
, /* special_function */
1236 "R_PPC64_PLTGOT16_LO_DS",/* name */
1237 FALSE
, /* partial_inplace */
1239 0xfffc, /* dst_mask */
1240 FALSE
), /* pcrel_offset */
1242 /* Marker relocs for TLS. */
1245 2, /* size (0 = byte, 1 = short, 2 = long) */
1247 FALSE
, /* pc_relative */
1249 complain_overflow_dont
, /* complain_on_overflow */
1250 bfd_elf_generic_reloc
, /* special_function */
1251 "R_PPC64_TLS", /* name */
1252 FALSE
, /* partial_inplace */
1255 FALSE
), /* pcrel_offset */
1257 HOWTO (R_PPC64_TLSGD
,
1259 2, /* size (0 = byte, 1 = short, 2 = long) */
1261 FALSE
, /* pc_relative */
1263 complain_overflow_dont
, /* complain_on_overflow */
1264 bfd_elf_generic_reloc
, /* special_function */
1265 "R_PPC64_TLSGD", /* name */
1266 FALSE
, /* partial_inplace */
1269 FALSE
), /* pcrel_offset */
1271 HOWTO (R_PPC64_TLSLD
,
1273 2, /* size (0 = byte, 1 = short, 2 = long) */
1275 FALSE
, /* pc_relative */
1277 complain_overflow_dont
, /* complain_on_overflow */
1278 bfd_elf_generic_reloc
, /* special_function */
1279 "R_PPC64_TLSLD", /* name */
1280 FALSE
, /* partial_inplace */
1283 FALSE
), /* pcrel_offset */
1285 /* Computes the load module index of the load module that contains the
1286 definition of its TLS sym. */
1287 HOWTO (R_PPC64_DTPMOD64
,
1289 4, /* size (0 = byte, 1 = short, 2 = long) */
1291 FALSE
, /* pc_relative */
1293 complain_overflow_dont
, /* complain_on_overflow */
1294 ppc64_elf_unhandled_reloc
, /* special_function */
1295 "R_PPC64_DTPMOD64", /* name */
1296 FALSE
, /* partial_inplace */
1298 ONES (64), /* dst_mask */
1299 FALSE
), /* pcrel_offset */
1301 /* Computes a dtv-relative displacement, the difference between the value
1302 of sym+add and the base address of the thread-local storage block that
1303 contains the definition of sym, minus 0x8000. */
1304 HOWTO (R_PPC64_DTPREL64
,
1306 4, /* size (0 = byte, 1 = short, 2 = long) */
1308 FALSE
, /* pc_relative */
1310 complain_overflow_dont
, /* complain_on_overflow */
1311 ppc64_elf_unhandled_reloc
, /* special_function */
1312 "R_PPC64_DTPREL64", /* name */
1313 FALSE
, /* partial_inplace */
1315 ONES (64), /* dst_mask */
1316 FALSE
), /* pcrel_offset */
1318 /* A 16 bit dtprel reloc. */
1319 HOWTO (R_PPC64_DTPREL16
,
1321 1, /* size (0 = byte, 1 = short, 2 = long) */
1323 FALSE
, /* pc_relative */
1325 complain_overflow_signed
, /* complain_on_overflow */
1326 ppc64_elf_unhandled_reloc
, /* special_function */
1327 "R_PPC64_DTPREL16", /* name */
1328 FALSE
, /* partial_inplace */
1330 0xffff, /* dst_mask */
1331 FALSE
), /* pcrel_offset */
1333 /* Like DTPREL16, but no overflow. */
1334 HOWTO (R_PPC64_DTPREL16_LO
,
1336 1, /* size (0 = byte, 1 = short, 2 = long) */
1338 FALSE
, /* pc_relative */
1340 complain_overflow_dont
, /* complain_on_overflow */
1341 ppc64_elf_unhandled_reloc
, /* special_function */
1342 "R_PPC64_DTPREL16_LO", /* name */
1343 FALSE
, /* partial_inplace */
1345 0xffff, /* dst_mask */
1346 FALSE
), /* pcrel_offset */
1348 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1349 HOWTO (R_PPC64_DTPREL16_HI
,
1350 16, /* rightshift */
1351 1, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE
, /* pc_relative */
1355 complain_overflow_dont
, /* complain_on_overflow */
1356 ppc64_elf_unhandled_reloc
, /* special_function */
1357 "R_PPC64_DTPREL16_HI", /* name */
1358 FALSE
, /* partial_inplace */
1360 0xffff, /* dst_mask */
1361 FALSE
), /* pcrel_offset */
1363 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1364 HOWTO (R_PPC64_DTPREL16_HA
,
1365 16, /* rightshift */
1366 1, /* size (0 = byte, 1 = short, 2 = long) */
1368 FALSE
, /* pc_relative */
1370 complain_overflow_dont
, /* complain_on_overflow */
1371 ppc64_elf_unhandled_reloc
, /* special_function */
1372 "R_PPC64_DTPREL16_HA", /* name */
1373 FALSE
, /* partial_inplace */
1375 0xffff, /* dst_mask */
1376 FALSE
), /* pcrel_offset */
1378 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1379 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1380 32, /* rightshift */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 FALSE
, /* pc_relative */
1385 complain_overflow_dont
, /* complain_on_overflow */
1386 ppc64_elf_unhandled_reloc
, /* special_function */
1387 "R_PPC64_DTPREL16_HIGHER", /* name */
1388 FALSE
, /* partial_inplace */
1390 0xffff, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1393 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1394 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1395 32, /* rightshift */
1396 1, /* size (0 = byte, 1 = short, 2 = long) */
1398 FALSE
, /* pc_relative */
1400 complain_overflow_dont
, /* complain_on_overflow */
1401 ppc64_elf_unhandled_reloc
, /* special_function */
1402 "R_PPC64_DTPREL16_HIGHERA", /* name */
1403 FALSE
, /* partial_inplace */
1405 0xffff, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1408 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1409 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1410 48, /* rightshift */
1411 1, /* size (0 = byte, 1 = short, 2 = long) */
1413 FALSE
, /* pc_relative */
1415 complain_overflow_dont
, /* complain_on_overflow */
1416 ppc64_elf_unhandled_reloc
, /* special_function */
1417 "R_PPC64_DTPREL16_HIGHEST", /* name */
1418 FALSE
, /* partial_inplace */
1420 0xffff, /* dst_mask */
1421 FALSE
), /* pcrel_offset */
1423 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1424 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1425 48, /* rightshift */
1426 1, /* size (0 = byte, 1 = short, 2 = long) */
1428 FALSE
, /* pc_relative */
1430 complain_overflow_dont
, /* complain_on_overflow */
1431 ppc64_elf_unhandled_reloc
, /* special_function */
1432 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1433 FALSE
, /* partial_inplace */
1435 0xffff, /* dst_mask */
1436 FALSE
), /* pcrel_offset */
1438 /* Like DTPREL16, but for insns with a DS field. */
1439 HOWTO (R_PPC64_DTPREL16_DS
,
1441 1, /* size (0 = byte, 1 = short, 2 = long) */
1443 FALSE
, /* pc_relative */
1445 complain_overflow_signed
, /* complain_on_overflow */
1446 ppc64_elf_unhandled_reloc
, /* special_function */
1447 "R_PPC64_DTPREL16_DS", /* name */
1448 FALSE
, /* partial_inplace */
1450 0xfffc, /* dst_mask */
1451 FALSE
), /* pcrel_offset */
1453 /* Like DTPREL16_DS, but no overflow. */
1454 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1456 1, /* size (0 = byte, 1 = short, 2 = long) */
1458 FALSE
, /* pc_relative */
1460 complain_overflow_dont
, /* complain_on_overflow */
1461 ppc64_elf_unhandled_reloc
, /* special_function */
1462 "R_PPC64_DTPREL16_LO_DS", /* name */
1463 FALSE
, /* partial_inplace */
1465 0xfffc, /* dst_mask */
1466 FALSE
), /* pcrel_offset */
1468 /* Computes a tp-relative displacement, the difference between the value of
1469 sym+add and the value of the thread pointer (r13). */
1470 HOWTO (R_PPC64_TPREL64
,
1472 4, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE
, /* pc_relative */
1476 complain_overflow_dont
, /* complain_on_overflow */
1477 ppc64_elf_unhandled_reloc
, /* special_function */
1478 "R_PPC64_TPREL64", /* name */
1479 FALSE
, /* partial_inplace */
1481 ONES (64), /* dst_mask */
1482 FALSE
), /* pcrel_offset */
1484 /* A 16 bit tprel reloc. */
1485 HOWTO (R_PPC64_TPREL16
,
1487 1, /* size (0 = byte, 1 = short, 2 = long) */
1489 FALSE
, /* pc_relative */
1491 complain_overflow_signed
, /* complain_on_overflow */
1492 ppc64_elf_unhandled_reloc
, /* special_function */
1493 "R_PPC64_TPREL16", /* name */
1494 FALSE
, /* partial_inplace */
1496 0xffff, /* dst_mask */
1497 FALSE
), /* pcrel_offset */
1499 /* Like TPREL16, but no overflow. */
1500 HOWTO (R_PPC64_TPREL16_LO
,
1502 1, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE
, /* pc_relative */
1506 complain_overflow_dont
, /* complain_on_overflow */
1507 ppc64_elf_unhandled_reloc
, /* special_function */
1508 "R_PPC64_TPREL16_LO", /* name */
1509 FALSE
, /* partial_inplace */
1511 0xffff, /* dst_mask */
1512 FALSE
), /* pcrel_offset */
1514 /* Like TPREL16_LO, but next higher group of 16 bits. */
1515 HOWTO (R_PPC64_TPREL16_HI
,
1516 16, /* rightshift */
1517 1, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE
, /* pc_relative */
1521 complain_overflow_dont
, /* complain_on_overflow */
1522 ppc64_elf_unhandled_reloc
, /* special_function */
1523 "R_PPC64_TPREL16_HI", /* name */
1524 FALSE
, /* partial_inplace */
1526 0xffff, /* dst_mask */
1527 FALSE
), /* pcrel_offset */
1529 /* Like TPREL16_HI, but adjust for low 16 bits. */
1530 HOWTO (R_PPC64_TPREL16_HA
,
1531 16, /* rightshift */
1532 1, /* size (0 = byte, 1 = short, 2 = long) */
1534 FALSE
, /* pc_relative */
1536 complain_overflow_dont
, /* complain_on_overflow */
1537 ppc64_elf_unhandled_reloc
, /* special_function */
1538 "R_PPC64_TPREL16_HA", /* name */
1539 FALSE
, /* partial_inplace */
1541 0xffff, /* dst_mask */
1542 FALSE
), /* pcrel_offset */
1544 /* Like TPREL16_HI, but next higher group of 16 bits. */
1545 HOWTO (R_PPC64_TPREL16_HIGHER
,
1546 32, /* rightshift */
1547 1, /* size (0 = byte, 1 = short, 2 = long) */
1549 FALSE
, /* pc_relative */
1551 complain_overflow_dont
, /* complain_on_overflow */
1552 ppc64_elf_unhandled_reloc
, /* special_function */
1553 "R_PPC64_TPREL16_HIGHER", /* name */
1554 FALSE
, /* partial_inplace */
1556 0xffff, /* dst_mask */
1557 FALSE
), /* pcrel_offset */
1559 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1560 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1561 32, /* rightshift */
1562 1, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE
, /* pc_relative */
1566 complain_overflow_dont
, /* complain_on_overflow */
1567 ppc64_elf_unhandled_reloc
, /* special_function */
1568 "R_PPC64_TPREL16_HIGHERA", /* name */
1569 FALSE
, /* partial_inplace */
1571 0xffff, /* dst_mask */
1572 FALSE
), /* pcrel_offset */
1574 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1575 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1576 48, /* rightshift */
1577 1, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE
, /* pc_relative */
1581 complain_overflow_dont
, /* complain_on_overflow */
1582 ppc64_elf_unhandled_reloc
, /* special_function */
1583 "R_PPC64_TPREL16_HIGHEST", /* name */
1584 FALSE
, /* partial_inplace */
1586 0xffff, /* dst_mask */
1587 FALSE
), /* pcrel_offset */
1589 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1590 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1591 48, /* rightshift */
1592 1, /* size (0 = byte, 1 = short, 2 = long) */
1594 FALSE
, /* pc_relative */
1596 complain_overflow_dont
, /* complain_on_overflow */
1597 ppc64_elf_unhandled_reloc
, /* special_function */
1598 "R_PPC64_TPREL16_HIGHESTA", /* name */
1599 FALSE
, /* partial_inplace */
1601 0xffff, /* dst_mask */
1602 FALSE
), /* pcrel_offset */
1604 /* Like TPREL16, but for insns with a DS field. */
1605 HOWTO (R_PPC64_TPREL16_DS
,
1607 1, /* size (0 = byte, 1 = short, 2 = long) */
1609 FALSE
, /* pc_relative */
1611 complain_overflow_signed
, /* complain_on_overflow */
1612 ppc64_elf_unhandled_reloc
, /* special_function */
1613 "R_PPC64_TPREL16_DS", /* name */
1614 FALSE
, /* partial_inplace */
1616 0xfffc, /* dst_mask */
1617 FALSE
), /* pcrel_offset */
1619 /* Like TPREL16_DS, but no overflow. */
1620 HOWTO (R_PPC64_TPREL16_LO_DS
,
1622 1, /* size (0 = byte, 1 = short, 2 = long) */
1624 FALSE
, /* pc_relative */
1626 complain_overflow_dont
, /* complain_on_overflow */
1627 ppc64_elf_unhandled_reloc
, /* special_function */
1628 "R_PPC64_TPREL16_LO_DS", /* name */
1629 FALSE
, /* partial_inplace */
1631 0xfffc, /* dst_mask */
1632 FALSE
), /* pcrel_offset */
1634 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1635 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1636 to the first entry relative to the TOC base (r2). */
1637 HOWTO (R_PPC64_GOT_TLSGD16
,
1639 1, /* size (0 = byte, 1 = short, 2 = long) */
1641 FALSE
, /* pc_relative */
1643 complain_overflow_signed
, /* complain_on_overflow */
1644 ppc64_elf_unhandled_reloc
, /* special_function */
1645 "R_PPC64_GOT_TLSGD16", /* name */
1646 FALSE
, /* partial_inplace */
1648 0xffff, /* dst_mask */
1649 FALSE
), /* pcrel_offset */
1651 /* Like GOT_TLSGD16, but no overflow. */
1652 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1654 1, /* size (0 = byte, 1 = short, 2 = long) */
1656 FALSE
, /* pc_relative */
1658 complain_overflow_dont
, /* complain_on_overflow */
1659 ppc64_elf_unhandled_reloc
, /* special_function */
1660 "R_PPC64_GOT_TLSGD16_LO", /* name */
1661 FALSE
, /* partial_inplace */
1663 0xffff, /* dst_mask */
1664 FALSE
), /* pcrel_offset */
1666 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1667 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1668 16, /* rightshift */
1669 1, /* size (0 = byte, 1 = short, 2 = long) */
1671 FALSE
, /* pc_relative */
1673 complain_overflow_dont
, /* complain_on_overflow */
1674 ppc64_elf_unhandled_reloc
, /* special_function */
1675 "R_PPC64_GOT_TLSGD16_HI", /* name */
1676 FALSE
, /* partial_inplace */
1678 0xffff, /* dst_mask */
1679 FALSE
), /* pcrel_offset */
1681 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1682 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1683 16, /* rightshift */
1684 1, /* size (0 = byte, 1 = short, 2 = long) */
1686 FALSE
, /* pc_relative */
1688 complain_overflow_dont
, /* complain_on_overflow */
1689 ppc64_elf_unhandled_reloc
, /* special_function */
1690 "R_PPC64_GOT_TLSGD16_HA", /* name */
1691 FALSE
, /* partial_inplace */
1693 0xffff, /* dst_mask */
1694 FALSE
), /* pcrel_offset */
1696 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1697 with values (sym+add)@dtpmod and zero, and computes the offset to the
1698 first entry relative to the TOC base (r2). */
1699 HOWTO (R_PPC64_GOT_TLSLD16
,
1701 1, /* size (0 = byte, 1 = short, 2 = long) */
1703 FALSE
, /* pc_relative */
1705 complain_overflow_signed
, /* complain_on_overflow */
1706 ppc64_elf_unhandled_reloc
, /* special_function */
1707 "R_PPC64_GOT_TLSLD16", /* name */
1708 FALSE
, /* partial_inplace */
1710 0xffff, /* dst_mask */
1711 FALSE
), /* pcrel_offset */
1713 /* Like GOT_TLSLD16, but no overflow. */
1714 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1716 1, /* size (0 = byte, 1 = short, 2 = long) */
1718 FALSE
, /* pc_relative */
1720 complain_overflow_dont
, /* complain_on_overflow */
1721 ppc64_elf_unhandled_reloc
, /* special_function */
1722 "R_PPC64_GOT_TLSLD16_LO", /* name */
1723 FALSE
, /* partial_inplace */
1725 0xffff, /* dst_mask */
1726 FALSE
), /* pcrel_offset */
1728 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1729 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1730 16, /* rightshift */
1731 1, /* size (0 = byte, 1 = short, 2 = long) */
1733 FALSE
, /* pc_relative */
1735 complain_overflow_dont
, /* complain_on_overflow */
1736 ppc64_elf_unhandled_reloc
, /* special_function */
1737 "R_PPC64_GOT_TLSLD16_HI", /* name */
1738 FALSE
, /* partial_inplace */
1740 0xffff, /* dst_mask */
1741 FALSE
), /* pcrel_offset */
1743 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1744 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1745 16, /* rightshift */
1746 1, /* size (0 = byte, 1 = short, 2 = long) */
1748 FALSE
, /* pc_relative */
1750 complain_overflow_dont
, /* complain_on_overflow */
1751 ppc64_elf_unhandled_reloc
, /* special_function */
1752 "R_PPC64_GOT_TLSLD16_HA", /* name */
1753 FALSE
, /* partial_inplace */
1755 0xffff, /* dst_mask */
1756 FALSE
), /* pcrel_offset */
1758 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1759 the offset to the entry relative to the TOC base (r2). */
1760 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1762 1, /* size (0 = byte, 1 = short, 2 = long) */
1764 FALSE
, /* pc_relative */
1766 complain_overflow_signed
, /* complain_on_overflow */
1767 ppc64_elf_unhandled_reloc
, /* special_function */
1768 "R_PPC64_GOT_DTPREL16_DS", /* name */
1769 FALSE
, /* partial_inplace */
1771 0xfffc, /* dst_mask */
1772 FALSE
), /* pcrel_offset */
1774 /* Like GOT_DTPREL16_DS, but no overflow. */
1775 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1777 1, /* size (0 = byte, 1 = short, 2 = long) */
1779 FALSE
, /* pc_relative */
1781 complain_overflow_dont
, /* complain_on_overflow */
1782 ppc64_elf_unhandled_reloc
, /* special_function */
1783 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1784 FALSE
, /* partial_inplace */
1786 0xfffc, /* dst_mask */
1787 FALSE
), /* pcrel_offset */
1789 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1790 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1791 16, /* rightshift */
1792 1, /* size (0 = byte, 1 = short, 2 = long) */
1794 FALSE
, /* pc_relative */
1796 complain_overflow_dont
, /* complain_on_overflow */
1797 ppc64_elf_unhandled_reloc
, /* special_function */
1798 "R_PPC64_GOT_DTPREL16_HI", /* name */
1799 FALSE
, /* partial_inplace */
1801 0xffff, /* dst_mask */
1802 FALSE
), /* pcrel_offset */
1804 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1805 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1806 16, /* rightshift */
1807 1, /* size (0 = byte, 1 = short, 2 = long) */
1809 FALSE
, /* pc_relative */
1811 complain_overflow_dont
, /* complain_on_overflow */
1812 ppc64_elf_unhandled_reloc
, /* special_function */
1813 "R_PPC64_GOT_DTPREL16_HA", /* name */
1814 FALSE
, /* partial_inplace */
1816 0xffff, /* dst_mask */
1817 FALSE
), /* pcrel_offset */
1819 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1820 offset to the entry relative to the TOC base (r2). */
1821 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1823 1, /* size (0 = byte, 1 = short, 2 = long) */
1825 FALSE
, /* pc_relative */
1827 complain_overflow_signed
, /* complain_on_overflow */
1828 ppc64_elf_unhandled_reloc
, /* special_function */
1829 "R_PPC64_GOT_TPREL16_DS", /* name */
1830 FALSE
, /* partial_inplace */
1832 0xfffc, /* dst_mask */
1833 FALSE
), /* pcrel_offset */
1835 /* Like GOT_TPREL16_DS, but no overflow. */
1836 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1838 1, /* size (0 = byte, 1 = short, 2 = long) */
1840 FALSE
, /* pc_relative */
1842 complain_overflow_dont
, /* complain_on_overflow */
1843 ppc64_elf_unhandled_reloc
, /* special_function */
1844 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1845 FALSE
, /* partial_inplace */
1847 0xfffc, /* dst_mask */
1848 FALSE
), /* pcrel_offset */
1850 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1851 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1852 16, /* rightshift */
1853 1, /* size (0 = byte, 1 = short, 2 = long) */
1855 FALSE
, /* pc_relative */
1857 complain_overflow_dont
, /* complain_on_overflow */
1858 ppc64_elf_unhandled_reloc
, /* special_function */
1859 "R_PPC64_GOT_TPREL16_HI", /* name */
1860 FALSE
, /* partial_inplace */
1862 0xffff, /* dst_mask */
1863 FALSE
), /* pcrel_offset */
1865 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1866 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1867 16, /* rightshift */
1868 1, /* size (0 = byte, 1 = short, 2 = long) */
1870 FALSE
, /* pc_relative */
1872 complain_overflow_dont
, /* complain_on_overflow */
1873 ppc64_elf_unhandled_reloc
, /* special_function */
1874 "R_PPC64_GOT_TPREL16_HA", /* name */
1875 FALSE
, /* partial_inplace */
1877 0xffff, /* dst_mask */
1878 FALSE
), /* pcrel_offset */
1880 HOWTO (R_PPC64_JMP_IREL
, /* type */
1882 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1884 FALSE
, /* pc_relative */
1886 complain_overflow_dont
, /* complain_on_overflow */
1887 ppc64_elf_unhandled_reloc
, /* special_function */
1888 "R_PPC64_JMP_IREL", /* name */
1889 FALSE
, /* partial_inplace */
1892 FALSE
), /* pcrel_offset */
1894 HOWTO (R_PPC64_IRELATIVE
, /* type */
1896 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1898 FALSE
, /* pc_relative */
1900 complain_overflow_dont
, /* complain_on_overflow */
1901 bfd_elf_generic_reloc
, /* special_function */
1902 "R_PPC64_IRELATIVE", /* name */
1903 FALSE
, /* partial_inplace */
1905 ONES (64), /* dst_mask */
1906 FALSE
), /* pcrel_offset */
1908 /* A 16 bit relative relocation. */
1909 HOWTO (R_PPC64_REL16
, /* type */
1911 1, /* size (0 = byte, 1 = short, 2 = long) */
1913 TRUE
, /* pc_relative */
1915 complain_overflow_bitfield
, /* complain_on_overflow */
1916 bfd_elf_generic_reloc
, /* special_function */
1917 "R_PPC64_REL16", /* name */
1918 FALSE
, /* partial_inplace */
1920 0xffff, /* dst_mask */
1921 TRUE
), /* pcrel_offset */
1923 /* A 16 bit relative relocation without overflow. */
1924 HOWTO (R_PPC64_REL16_LO
, /* type */
1926 1, /* size (0 = byte, 1 = short, 2 = long) */
1928 TRUE
, /* pc_relative */
1930 complain_overflow_dont
,/* complain_on_overflow */
1931 bfd_elf_generic_reloc
, /* special_function */
1932 "R_PPC64_REL16_LO", /* name */
1933 FALSE
, /* partial_inplace */
1935 0xffff, /* dst_mask */
1936 TRUE
), /* pcrel_offset */
1938 /* The high order 16 bits of a relative address. */
1939 HOWTO (R_PPC64_REL16_HI
, /* type */
1940 16, /* rightshift */
1941 1, /* size (0 = byte, 1 = short, 2 = long) */
1943 TRUE
, /* pc_relative */
1945 complain_overflow_dont
, /* complain_on_overflow */
1946 bfd_elf_generic_reloc
, /* special_function */
1947 "R_PPC64_REL16_HI", /* name */
1948 FALSE
, /* partial_inplace */
1950 0xffff, /* dst_mask */
1951 TRUE
), /* pcrel_offset */
1953 /* The high order 16 bits of a relative address, plus 1 if the contents of
1954 the low 16 bits, treated as a signed number, is negative. */
1955 HOWTO (R_PPC64_REL16_HA
, /* type */
1956 16, /* rightshift */
1957 1, /* size (0 = byte, 1 = short, 2 = long) */
1959 TRUE
, /* pc_relative */
1961 complain_overflow_dont
, /* complain_on_overflow */
1962 ppc64_elf_ha_reloc
, /* special_function */
1963 "R_PPC64_REL16_HA", /* name */
1964 FALSE
, /* partial_inplace */
1966 0xffff, /* dst_mask */
1967 TRUE
), /* pcrel_offset */
1969 /* GNU extension to record C++ vtable hierarchy. */
1970 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1972 0, /* size (0 = byte, 1 = short, 2 = long) */
1974 FALSE
, /* pc_relative */
1976 complain_overflow_dont
, /* complain_on_overflow */
1977 NULL
, /* special_function */
1978 "R_PPC64_GNU_VTINHERIT", /* name */
1979 FALSE
, /* partial_inplace */
1982 FALSE
), /* pcrel_offset */
1984 /* GNU extension to record C++ vtable member usage. */
1985 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1987 0, /* size (0 = byte, 1 = short, 2 = long) */
1989 FALSE
, /* pc_relative */
1991 complain_overflow_dont
, /* complain_on_overflow */
1992 NULL
, /* special_function */
1993 "R_PPC64_GNU_VTENTRY", /* name */
1994 FALSE
, /* partial_inplace */
1997 FALSE
), /* pcrel_offset */
2001 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2005 ppc_howto_init (void)
2007 unsigned int i
, type
;
2010 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2013 type
= ppc64_elf_howto_raw
[i
].type
;
2014 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
2015 / sizeof (ppc64_elf_howto_table
[0])));
2016 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2020 static reloc_howto_type
*
2021 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2022 bfd_reloc_code_real_type code
)
2024 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2026 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2027 /* Initialize howto table if needed. */
2035 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2037 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2039 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2041 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2043 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2045 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2047 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2049 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2051 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2053 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2055 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2057 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2059 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2061 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2063 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2065 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2067 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2069 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2071 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2073 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2075 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2077 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2079 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2081 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2083 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2085 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2087 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2089 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2091 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2093 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2095 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2097 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2099 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2101 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2103 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2105 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2107 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2109 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2111 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2113 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2115 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2117 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2119 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2121 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2123 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2125 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2127 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2129 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2131 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2133 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2135 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2137 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2139 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2141 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2143 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2145 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2147 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2149 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2151 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2153 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2155 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2157 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2159 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2161 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2163 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2165 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2167 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2169 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2171 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2173 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2175 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2177 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2179 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2181 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2183 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2185 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2187 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2189 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2191 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2193 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2195 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2197 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2199 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2201 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2203 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2205 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2207 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2209 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2211 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2213 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2215 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2217 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2219 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2221 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2223 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2225 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2227 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2229 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2231 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2233 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2235 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2237 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2239 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2241 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2243 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2245 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2247 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2251 return ppc64_elf_howto_table
[r
];
2254 static reloc_howto_type
*
2255 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2261 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2263 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2264 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2265 return &ppc64_elf_howto_raw
[i
];
2270 /* Set the howto pointer for a PowerPC ELF reloc. */
2273 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2274 Elf_Internal_Rela
*dst
)
2278 /* Initialize howto table if needed. */
2279 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2282 type
= ELF64_R_TYPE (dst
->r_info
);
2283 if (type
>= (sizeof (ppc64_elf_howto_table
)
2284 / sizeof (ppc64_elf_howto_table
[0])))
2286 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2288 type
= R_PPC64_NONE
;
2290 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2293 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2295 static bfd_reloc_status_type
2296 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2297 void *data
, asection
*input_section
,
2298 bfd
*output_bfd
, char **error_message
)
2300 /* If this is a relocatable link (output_bfd test tells us), just
2301 call the generic function. Any adjustment will be done at final
2303 if (output_bfd
!= NULL
)
2304 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2305 input_section
, output_bfd
, error_message
);
2307 /* Adjust the addend for sign extension of the low 16 bits.
2308 We won't actually be using the low 16 bits, so trashing them
2310 reloc_entry
->addend
+= 0x8000;
2311 return bfd_reloc_continue
;
2314 static bfd_reloc_status_type
2315 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2316 void *data
, asection
*input_section
,
2317 bfd
*output_bfd
, char **error_message
)
2319 if (output_bfd
!= NULL
)
2320 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2321 input_section
, output_bfd
, error_message
);
2323 if (strcmp (symbol
->section
->name
, ".opd") == 0
2324 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2326 bfd_vma dest
= opd_entry_value (symbol
->section
,
2327 symbol
->value
+ reloc_entry
->addend
,
2329 if (dest
!= (bfd_vma
) -1)
2330 reloc_entry
->addend
= dest
- (symbol
->value
2331 + symbol
->section
->output_section
->vma
2332 + symbol
->section
->output_offset
);
2334 return bfd_reloc_continue
;
2337 static bfd_reloc_status_type
2338 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2339 void *data
, asection
*input_section
,
2340 bfd
*output_bfd
, char **error_message
)
2343 enum elf_ppc64_reloc_type r_type
;
2344 bfd_size_type octets
;
2345 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2346 bfd_boolean is_power4
= FALSE
;
2348 /* If this is a relocatable link (output_bfd test tells us), just
2349 call the generic function. Any adjustment will be done at final
2351 if (output_bfd
!= NULL
)
2352 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2353 input_section
, output_bfd
, error_message
);
2355 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2356 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2357 insn
&= ~(0x01 << 21);
2358 r_type
= reloc_entry
->howto
->type
;
2359 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2360 || r_type
== R_PPC64_REL14_BRTAKEN
)
2361 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2365 /* Set 'a' bit. This is 0b00010 in BO field for branch
2366 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2367 for branch on CTR insns (BO == 1a00t or 1a01t). */
2368 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2370 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2380 if (!bfd_is_com_section (symbol
->section
))
2381 target
= symbol
->value
;
2382 target
+= symbol
->section
->output_section
->vma
;
2383 target
+= symbol
->section
->output_offset
;
2384 target
+= reloc_entry
->addend
;
2386 from
= (reloc_entry
->address
2387 + input_section
->output_offset
2388 + input_section
->output_section
->vma
);
2390 /* Invert 'y' bit if not the default. */
2391 if ((bfd_signed_vma
) (target
- from
) < 0)
2394 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2396 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2397 input_section
, output_bfd
, error_message
);
2400 static bfd_reloc_status_type
2401 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2402 void *data
, asection
*input_section
,
2403 bfd
*output_bfd
, char **error_message
)
2405 /* If this is a relocatable link (output_bfd test tells us), just
2406 call the generic function. Any adjustment will be done at final
2408 if (output_bfd
!= NULL
)
2409 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2410 input_section
, output_bfd
, error_message
);
2412 /* Subtract the symbol section base address. */
2413 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2414 return bfd_reloc_continue
;
2417 static bfd_reloc_status_type
2418 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2419 void *data
, asection
*input_section
,
2420 bfd
*output_bfd
, char **error_message
)
2422 /* If this is a relocatable link (output_bfd test tells us), just
2423 call the generic function. Any adjustment will be done at final
2425 if (output_bfd
!= NULL
)
2426 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2427 input_section
, output_bfd
, error_message
);
2429 /* Subtract the symbol section base address. */
2430 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2432 /* Adjust the addend for sign extension of the low 16 bits. */
2433 reloc_entry
->addend
+= 0x8000;
2434 return bfd_reloc_continue
;
2437 static bfd_reloc_status_type
2438 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2439 void *data
, asection
*input_section
,
2440 bfd
*output_bfd
, char **error_message
)
2444 /* If this is a relocatable link (output_bfd test tells us), just
2445 call the generic function. Any adjustment will be done at final
2447 if (output_bfd
!= NULL
)
2448 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2449 input_section
, output_bfd
, error_message
);
2451 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2453 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2455 /* Subtract the TOC base address. */
2456 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2457 return bfd_reloc_continue
;
2460 static bfd_reloc_status_type
2461 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2462 void *data
, asection
*input_section
,
2463 bfd
*output_bfd
, char **error_message
)
2467 /* If this is a relocatable link (output_bfd test tells us), just
2468 call the generic function. Any adjustment will be done at final
2470 if (output_bfd
!= NULL
)
2471 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2472 input_section
, output_bfd
, error_message
);
2474 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2476 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2478 /* Subtract the TOC base address. */
2479 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2481 /* Adjust the addend for sign extension of the low 16 bits. */
2482 reloc_entry
->addend
+= 0x8000;
2483 return bfd_reloc_continue
;
2486 static bfd_reloc_status_type
2487 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2488 void *data
, asection
*input_section
,
2489 bfd
*output_bfd
, char **error_message
)
2492 bfd_size_type octets
;
2494 /* If this is a relocatable link (output_bfd test tells us), just
2495 call the generic function. Any adjustment will be done at final
2497 if (output_bfd
!= NULL
)
2498 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2499 input_section
, output_bfd
, error_message
);
2501 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2503 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2505 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2506 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2507 return bfd_reloc_ok
;
2510 static bfd_reloc_status_type
2511 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2512 void *data
, asection
*input_section
,
2513 bfd
*output_bfd
, char **error_message
)
2515 /* If this is a relocatable link (output_bfd test tells us), just
2516 call the generic function. Any adjustment will be done at final
2518 if (output_bfd
!= NULL
)
2519 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2520 input_section
, output_bfd
, error_message
);
2522 if (error_message
!= NULL
)
2524 static char buf
[60];
2525 sprintf (buf
, "generic linker can't handle %s",
2526 reloc_entry
->howto
->name
);
2527 *error_message
= buf
;
2529 return bfd_reloc_dangerous
;
2532 /* Track GOT entries needed for a given symbol. We might need more
2533 than one got entry per symbol. */
2536 struct got_entry
*next
;
2538 /* The symbol addend that we'll be placing in the GOT. */
2541 /* Unlike other ELF targets, we use separate GOT entries for the same
2542 symbol referenced from different input files. This is to support
2543 automatic multiple TOC/GOT sections, where the TOC base can vary
2544 from one input file to another. After partitioning into TOC groups
2545 we merge entries within the group.
2547 Point to the BFD owning this GOT entry. */
2550 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2551 TLS_TPREL or TLS_DTPREL for tls entries. */
2552 unsigned char tls_type
;
2554 /* Non-zero if got.ent points to real entry. */
2555 unsigned char is_indirect
;
2557 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2560 bfd_signed_vma refcount
;
2562 struct got_entry
*ent
;
2566 /* The same for PLT. */
2569 struct plt_entry
*next
;
2575 bfd_signed_vma refcount
;
2580 struct ppc64_elf_obj_tdata
2582 struct elf_obj_tdata elf
;
2584 /* Shortcuts to dynamic linker sections. */
2588 /* Used during garbage collection. We attach global symbols defined
2589 on removed .opd entries to this section so that the sym is removed. */
2590 asection
*deleted_section
;
2592 /* TLS local dynamic got entry handling. Support for multiple GOT
2593 sections means we potentially need one of these for each input bfd. */
2594 struct got_entry tlsld_got
;
2596 /* A copy of relocs before they are modified for --emit-relocs. */
2597 Elf_Internal_Rela
*opd_relocs
;
2599 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2600 the reloc to be in the range -32768 to 32767. */
2601 unsigned int has_small_toc_reloc
: 1;
2603 /* Set if toc/got ha relocs detected not using r2. */
2604 unsigned int ha_relocs_not_using_r2
: 1;
2607 #define ppc64_elf_tdata(bfd) \
2608 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2610 #define ppc64_tlsld_got(bfd) \
2611 (&ppc64_elf_tdata (bfd)->tlsld_got)
2613 #define is_ppc64_elf(bfd) \
2614 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2615 && elf_object_id (bfd) == PPC64_ELF_DATA)
2617 /* Override the generic function because we store some extras. */
2620 ppc64_elf_mkobject (bfd
*abfd
)
2622 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2626 /* Fix bad default arch selected for a 64 bit input bfd when the
2627 default is 32 bit. */
2630 ppc64_elf_object_p (bfd
*abfd
)
2632 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2634 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2636 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2638 /* Relies on arch after 32 bit default being 64 bit default. */
2639 abfd
->arch_info
= abfd
->arch_info
->next
;
2640 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2646 /* Support for core dump NOTE sections. */
2649 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2651 size_t offset
, size
;
2653 if (note
->descsz
!= 504)
2657 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2660 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2666 /* Make a ".reg/999" section. */
2667 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2668 size
, note
->descpos
+ offset
);
2672 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2674 if (note
->descsz
!= 136)
2677 elf_tdata (abfd
)->core_pid
2678 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2679 elf_tdata (abfd
)->core_program
2680 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2681 elf_tdata (abfd
)->core_command
2682 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2688 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2701 va_start (ap
, note_type
);
2702 memset (data
, 0, 40);
2703 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2704 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2706 return elfcore_write_note (abfd
, buf
, bufsiz
,
2707 "CORE", note_type
, data
, sizeof (data
));
2718 va_start (ap
, note_type
);
2719 memset (data
, 0, 112);
2720 pid
= va_arg (ap
, long);
2721 bfd_put_32 (abfd
, pid
, data
+ 32);
2722 cursig
= va_arg (ap
, int);
2723 bfd_put_16 (abfd
, cursig
, data
+ 12);
2724 greg
= va_arg (ap
, const void *);
2725 memcpy (data
+ 112, greg
, 384);
2726 memset (data
+ 496, 0, 8);
2728 return elfcore_write_note (abfd
, buf
, bufsiz
,
2729 "CORE", note_type
, data
, sizeof (data
));
2734 /* Add extra PPC sections. */
2736 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2738 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2739 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2740 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2741 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2742 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2743 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2744 { NULL
, 0, 0, 0, 0 }
2747 enum _ppc64_sec_type
{
2753 struct _ppc64_elf_section_data
2755 struct bfd_elf_section_data elf
;
2759 /* An array with one entry for each opd function descriptor. */
2760 struct _opd_sec_data
2762 /* Points to the function code section for local opd entries. */
2763 asection
**func_sec
;
2765 /* After editing .opd, adjust references to opd local syms. */
2769 /* An array for toc sections, indexed by offset/8. */
2770 struct _toc_sec_data
2772 /* Specifies the relocation symbol index used at a given toc offset. */
2775 /* And the relocation addend. */
2780 enum _ppc64_sec_type sec_type
:2;
2782 /* Flag set when small branches are detected. Used to
2783 select suitable defaults for the stub group size. */
2784 unsigned int has_14bit_branch
:1;
2787 #define ppc64_elf_section_data(sec) \
2788 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2791 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2793 if (!sec
->used_by_bfd
)
2795 struct _ppc64_elf_section_data
*sdata
;
2796 bfd_size_type amt
= sizeof (*sdata
);
2798 sdata
= bfd_zalloc (abfd
, amt
);
2801 sec
->used_by_bfd
= sdata
;
2804 return _bfd_elf_new_section_hook (abfd
, sec
);
2807 static struct _opd_sec_data
*
2808 get_opd_info (asection
* sec
)
2811 && ppc64_elf_section_data (sec
) != NULL
2812 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2813 return &ppc64_elf_section_data (sec
)->u
.opd
;
2817 /* Parameters for the qsort hook. */
2818 static bfd_boolean synthetic_relocatable
;
2820 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2823 compare_symbols (const void *ap
, const void *bp
)
2825 const asymbol
*a
= * (const asymbol
**) ap
;
2826 const asymbol
*b
= * (const asymbol
**) bp
;
2828 /* Section symbols first. */
2829 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2831 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2834 /* then .opd symbols. */
2835 if (strcmp (a
->section
->name
, ".opd") == 0
2836 && strcmp (b
->section
->name
, ".opd") != 0)
2838 if (strcmp (a
->section
->name
, ".opd") != 0
2839 && strcmp (b
->section
->name
, ".opd") == 0)
2842 /* then other code symbols. */
2843 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2844 == (SEC_CODE
| SEC_ALLOC
)
2845 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2846 != (SEC_CODE
| SEC_ALLOC
))
2849 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2850 != (SEC_CODE
| SEC_ALLOC
)
2851 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2852 == (SEC_CODE
| SEC_ALLOC
))
2855 if (synthetic_relocatable
)
2857 if (a
->section
->id
< b
->section
->id
)
2860 if (a
->section
->id
> b
->section
->id
)
2864 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2867 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2870 /* For syms with the same value, prefer strong dynamic global function
2871 syms over other syms. */
2872 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2875 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2878 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2881 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2884 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2887 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2890 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2893 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2899 /* Search SYMS for a symbol of the given VALUE. */
2902 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2910 mid
= (lo
+ hi
) >> 1;
2911 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2913 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2923 mid
= (lo
+ hi
) >> 1;
2924 if (syms
[mid
]->section
->id
< id
)
2926 else if (syms
[mid
]->section
->id
> id
)
2928 else if (syms
[mid
]->value
< value
)
2930 else if (syms
[mid
]->value
> value
)
2940 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2942 bfd_vma vma
= *(bfd_vma
*) ptr
;
2943 return ((section
->flags
& SEC_ALLOC
) != 0
2944 && section
->vma
<= vma
2945 && vma
< section
->vma
+ section
->size
);
2948 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2949 entry syms. Also generate @plt symbols for the glink branch table. */
2952 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2953 long static_count
, asymbol
**static_syms
,
2954 long dyn_count
, asymbol
**dyn_syms
,
2961 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2963 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2968 opd
= bfd_get_section_by_name (abfd
, ".opd");
2972 symcount
= static_count
;
2974 symcount
+= dyn_count
;
2978 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2982 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2984 /* Use both symbol tables. */
2985 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2986 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2988 else if (!relocatable
&& static_count
== 0)
2989 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2991 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2993 synthetic_relocatable
= relocatable
;
2994 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2996 if (!relocatable
&& symcount
> 1)
2999 /* Trim duplicate syms, since we may have merged the normal and
3000 dynamic symbols. Actually, we only care about syms that have
3001 different values, so trim any with the same value. */
3002 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3003 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3004 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3005 syms
[j
++] = syms
[i
];
3010 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3014 for (; i
< symcount
; ++i
)
3015 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3016 != (SEC_CODE
| SEC_ALLOC
))
3017 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3021 for (; i
< symcount
; ++i
)
3022 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3026 for (; i
< symcount
; ++i
)
3027 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3031 for (; i
< symcount
; ++i
)
3032 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3033 != (SEC_CODE
| SEC_ALLOC
))
3041 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3046 if (opdsymend
== secsymend
)
3049 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3050 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3054 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3061 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3065 while (r
< opd
->relocation
+ relcount
3066 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3069 if (r
== opd
->relocation
+ relcount
)
3072 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3075 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3078 sym
= *r
->sym_ptr_ptr
;
3079 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3080 sym
->section
->id
, sym
->value
+ r
->addend
))
3083 size
+= sizeof (asymbol
);
3084 size
+= strlen (syms
[i
]->name
) + 2;
3088 s
= *ret
= bfd_malloc (size
);
3095 names
= (char *) (s
+ count
);
3097 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3101 while (r
< opd
->relocation
+ relcount
3102 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3105 if (r
== opd
->relocation
+ relcount
)
3108 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3111 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3114 sym
= *r
->sym_ptr_ptr
;
3115 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3116 sym
->section
->id
, sym
->value
+ r
->addend
))
3121 s
->flags
|= BSF_SYNTHETIC
;
3122 s
->section
= sym
->section
;
3123 s
->value
= sym
->value
+ r
->addend
;
3126 len
= strlen (syms
[i
]->name
);
3127 memcpy (names
, syms
[i
]->name
, len
+ 1);
3129 /* Have udata.p point back to the original symbol this
3130 synthetic symbol was derived from. */
3131 s
->udata
.p
= syms
[i
];
3138 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3142 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3143 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3146 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3150 free_contents_and_exit
:
3158 for (i
= secsymend
; i
< opdsymend
; ++i
)
3162 /* Ignore bogus symbols. */
3163 if (syms
[i
]->value
> opd
->size
- 8)
3166 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3167 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3170 size
+= sizeof (asymbol
);
3171 size
+= strlen (syms
[i
]->name
) + 2;
3175 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3177 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3179 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3181 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3183 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3184 goto free_contents_and_exit
;
3186 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3187 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3190 extdynend
= extdyn
+ dynamic
->size
;
3191 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3193 Elf_Internal_Dyn dyn
;
3194 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3196 if (dyn
.d_tag
== DT_NULL
)
3199 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3201 /* The first glink stub starts at offset 32; see comment in
3202 ppc64_elf_finish_dynamic_sections. */
3203 glink_vma
= dyn
.d_un
.d_val
+ 32;
3204 /* The .glink section usually does not survive the final
3205 link; search for the section (usually .text) where the
3206 glink stubs now reside. */
3207 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3218 /* Determine __glink trampoline by reading the relative branch
3219 from the first glink stub. */
3221 if (bfd_get_section_contents (abfd
, glink
, buf
,
3222 glink_vma
+ 4 - glink
->vma
, 4))
3224 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3226 if ((insn
& ~0x3fffffc) == 0)
3227 resolv_vma
= glink_vma
+ 4 + (insn
^ 0x2000000) - 0x2000000;
3231 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3233 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3236 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3237 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3238 goto free_contents_and_exit
;
3240 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3241 size
+= plt_count
* sizeof (asymbol
);
3243 p
= relplt
->relocation
;
3244 for (i
= 0; i
< plt_count
; i
++, p
++)
3246 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3248 size
+= sizeof ("+0x") - 1 + 16;
3253 s
= *ret
= bfd_malloc (size
);
3255 goto free_contents_and_exit
;
3257 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3259 for (i
= secsymend
; i
< opdsymend
; ++i
)
3263 if (syms
[i
]->value
> opd
->size
- 8)
3266 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3267 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3271 asection
*sec
= abfd
->sections
;
3278 long mid
= (lo
+ hi
) >> 1;
3279 if (syms
[mid
]->section
->vma
< ent
)
3281 else if (syms
[mid
]->section
->vma
> ent
)
3285 sec
= syms
[mid
]->section
;
3290 if (lo
>= hi
&& lo
> codesecsym
)
3291 sec
= syms
[lo
- 1]->section
;
3293 for (; sec
!= NULL
; sec
= sec
->next
)
3297 /* SEC_LOAD may not be set if SEC is from a separate debug
3299 if ((sec
->flags
& SEC_ALLOC
) == 0)
3301 if ((sec
->flags
& SEC_CODE
) != 0)
3304 s
->flags
|= BSF_SYNTHETIC
;
3305 s
->value
= ent
- s
->section
->vma
;
3308 len
= strlen (syms
[i
]->name
);
3309 memcpy (names
, syms
[i
]->name
, len
+ 1);
3311 /* Have udata.p point back to the original symbol this
3312 synthetic symbol was derived from. */
3313 s
->udata
.p
= syms
[i
];
3319 if (glink
!= NULL
&& relplt
!= NULL
)
3323 /* Add a symbol for the main glink trampoline. */
3324 memset (s
, 0, sizeof *s
);
3326 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3328 s
->value
= resolv_vma
- glink
->vma
;
3330 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3331 names
+= sizeof ("__glink_PLTresolve");
3336 /* FIXME: It would be very much nicer to put sym@plt on the
3337 stub rather than on the glink branch table entry. The
3338 objdump disassembler would then use a sensible symbol
3339 name on plt calls. The difficulty in doing so is
3340 a) finding the stubs, and,
3341 b) matching stubs against plt entries, and,
3342 c) there can be multiple stubs for a given plt entry.
3344 Solving (a) could be done by code scanning, but older
3345 ppc64 binaries used different stubs to current code.
3346 (b) is the tricky one since you need to known the toc
3347 pointer for at least one function that uses a pic stub to
3348 be able to calculate the plt address referenced.
3349 (c) means gdb would need to set multiple breakpoints (or
3350 find the glink branch itself) when setting breakpoints
3351 for pending shared library loads. */
3352 p
= relplt
->relocation
;
3353 for (i
= 0; i
< plt_count
; i
++, p
++)
3357 *s
= **p
->sym_ptr_ptr
;
3358 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3359 we are defining a symbol, ensure one of them is set. */
3360 if ((s
->flags
& BSF_LOCAL
) == 0)
3361 s
->flags
|= BSF_GLOBAL
;
3362 s
->flags
|= BSF_SYNTHETIC
;
3364 s
->value
= glink_vma
- glink
->vma
;
3367 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3368 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3372 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3373 names
+= sizeof ("+0x") - 1;
3374 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3375 names
+= strlen (names
);
3377 memcpy (names
, "@plt", sizeof ("@plt"));
3378 names
+= sizeof ("@plt");
3393 /* The following functions are specific to the ELF linker, while
3394 functions above are used generally. Those named ppc64_elf_* are
3395 called by the main ELF linker code. They appear in this file more
3396 or less in the order in which they are called. eg.
3397 ppc64_elf_check_relocs is called early in the link process,
3398 ppc64_elf_finish_dynamic_sections is one of the last functions
3401 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3402 functions have both a function code symbol and a function descriptor
3403 symbol. A call to foo in a relocatable object file looks like:
3410 The function definition in another object file might be:
3414 . .quad .TOC.@tocbase
3420 When the linker resolves the call during a static link, the branch
3421 unsurprisingly just goes to .foo and the .opd information is unused.
3422 If the function definition is in a shared library, things are a little
3423 different: The call goes via a plt call stub, the opd information gets
3424 copied to the plt, and the linker patches the nop.
3432 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3433 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3434 . std 2,40(1) # this is the general idea
3442 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3444 The "reloc ()" notation is supposed to indicate that the linker emits
3445 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3448 What are the difficulties here? Well, firstly, the relocations
3449 examined by the linker in check_relocs are against the function code
3450 sym .foo, while the dynamic relocation in the plt is emitted against
3451 the function descriptor symbol, foo. Somewhere along the line, we need
3452 to carefully copy dynamic link information from one symbol to the other.
3453 Secondly, the generic part of the elf linker will make .foo a dynamic
3454 symbol as is normal for most other backends. We need foo dynamic
3455 instead, at least for an application final link. However, when
3456 creating a shared library containing foo, we need to have both symbols
3457 dynamic so that references to .foo are satisfied during the early
3458 stages of linking. Otherwise the linker might decide to pull in a
3459 definition from some other object, eg. a static library.
3461 Update: As of August 2004, we support a new convention. Function
3462 calls may use the function descriptor symbol, ie. "bl foo". This
3463 behaves exactly as "bl .foo". */
3465 /* Of those relocs that might be copied as dynamic relocs, this function
3466 selects those that must be copied when linking a shared library,
3467 even when the symbol is local. */
3470 must_be_dyn_reloc (struct bfd_link_info
*info
,
3471 enum elf_ppc64_reloc_type r_type
)
3483 case R_PPC64_TPREL16
:
3484 case R_PPC64_TPREL16_LO
:
3485 case R_PPC64_TPREL16_HI
:
3486 case R_PPC64_TPREL16_HA
:
3487 case R_PPC64_TPREL16_DS
:
3488 case R_PPC64_TPREL16_LO_DS
:
3489 case R_PPC64_TPREL16_HIGHER
:
3490 case R_PPC64_TPREL16_HIGHERA
:
3491 case R_PPC64_TPREL16_HIGHEST
:
3492 case R_PPC64_TPREL16_HIGHESTA
:
3493 case R_PPC64_TPREL64
:
3494 return !info
->executable
;
3498 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3499 copying dynamic variables from a shared lib into an app's dynbss
3500 section, and instead use a dynamic relocation to point into the
3501 shared lib. With code that gcc generates, it's vital that this be
3502 enabled; In the PowerPC64 ABI, the address of a function is actually
3503 the address of a function descriptor, which resides in the .opd
3504 section. gcc uses the descriptor directly rather than going via the
3505 GOT as some other ABI's do, which means that initialized function
3506 pointers must reference the descriptor. Thus, a function pointer
3507 initialized to the address of a function in a shared library will
3508 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3509 redefines the function descriptor symbol to point to the copy. This
3510 presents a problem as a plt entry for that function is also
3511 initialized from the function descriptor symbol and the copy reloc
3512 may not be initialized first. */
3513 #define ELIMINATE_COPY_RELOCS 1
3515 /* Section name for stubs is the associated section name plus this
3517 #define STUB_SUFFIX ".stub"
3520 ppc_stub_long_branch:
3521 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3522 destination, but a 24 bit branch in a stub section will reach.
3525 ppc_stub_plt_branch:
3526 Similar to the above, but a 24 bit branch in the stub section won't
3527 reach its destination.
3528 . addis %r12,%r2,xxx@toc@ha
3529 . ld %r11,xxx@toc@l(%r12)
3534 Used to call a function in a shared library. If it so happens that
3535 the plt entry referenced crosses a 64k boundary, then an extra
3536 "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr".
3537 . addis %r12,%r2,xxx@toc@ha
3539 . ld %r11,xxx+0@toc@l(%r12)
3541 . ld %r2,xxx+8@toc@l(%r12)
3542 . ld %r11,xxx+16@toc@l(%r12)
3545 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3546 code to adjust the value and save r2 to support multiple toc sections.
3547 A ppc_stub_long_branch with an r2 offset looks like:
3549 . addis %r2,%r2,off@ha
3550 . addi %r2,%r2,off@l
3553 A ppc_stub_plt_branch with an r2 offset looks like:
3555 . addis %r12,%r2,xxx@toc@ha
3556 . ld %r11,xxx@toc@l(%r12)
3557 . addis %r2,%r2,off@ha
3558 . addi %r2,%r2,off@l
3562 In cases where the "addis" instruction would add zero, the "addis" is
3563 omitted and following instructions modified slightly in some cases.
3566 enum ppc_stub_type
{
3568 ppc_stub_long_branch
,
3569 ppc_stub_long_branch_r2off
,
3570 ppc_stub_plt_branch
,
3571 ppc_stub_plt_branch_r2off
,
3575 struct ppc_stub_hash_entry
{
3577 /* Base hash table entry structure. */
3578 struct bfd_hash_entry root
;
3580 enum ppc_stub_type stub_type
;
3582 /* The stub section. */
3585 /* Offset within stub_sec of the beginning of this stub. */
3586 bfd_vma stub_offset
;
3588 /* Given the symbol's value and its section we can determine its final
3589 value when building the stubs (so the stub knows where to jump. */
3590 bfd_vma target_value
;
3591 asection
*target_section
;
3593 /* The symbol table entry, if any, that this was derived from. */
3594 struct ppc_link_hash_entry
*h
;
3595 struct plt_entry
*plt_ent
;
3597 /* And the reloc addend that this was derived from. */
3600 /* Where this stub is being called from, or, in the case of combined
3601 stub sections, the first input section in the group. */
3605 struct ppc_branch_hash_entry
{
3607 /* Base hash table entry structure. */
3608 struct bfd_hash_entry root
;
3610 /* Offset within branch lookup table. */
3611 unsigned int offset
;
3613 /* Generation marker. */
3617 struct ppc_link_hash_entry
3619 struct elf_link_hash_entry elf
;
3622 /* A pointer to the most recently used stub hash entry against this
3624 struct ppc_stub_hash_entry
*stub_cache
;
3626 /* A pointer to the next symbol starting with a '.' */
3627 struct ppc_link_hash_entry
*next_dot_sym
;
3630 /* Track dynamic relocs copied for this symbol. */
3631 struct elf_dyn_relocs
*dyn_relocs
;
3633 /* Link between function code and descriptor symbols. */
3634 struct ppc_link_hash_entry
*oh
;
3636 /* Flag function code and descriptor symbols. */
3637 unsigned int is_func
:1;
3638 unsigned int is_func_descriptor
:1;
3639 unsigned int fake
:1;
3641 /* Whether global opd/toc sym has been adjusted or not.
3642 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3643 should be set for all globals defined in any opd/toc section. */
3644 unsigned int adjust_done
:1;
3646 /* Set if we twiddled this symbol to weak at some stage. */
3647 unsigned int was_undefined
:1;
3649 /* Contexts in which symbol is used in the GOT (or TOC).
3650 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3651 corresponding relocs are encountered during check_relocs.
3652 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3653 indicate the corresponding GOT entry type is not needed.
3654 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3655 a TPREL one. We use a separate flag rather than setting TPREL
3656 just for convenience in distinguishing the two cases. */
3657 #define TLS_GD 1 /* GD reloc. */
3658 #define TLS_LD 2 /* LD reloc. */
3659 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3660 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3661 #define TLS_TLS 16 /* Any TLS reloc. */
3662 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3663 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3664 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3665 unsigned char tls_mask
;
3668 /* ppc64 ELF linker hash table. */
3670 struct ppc_link_hash_table
3672 struct elf_link_hash_table elf
;
3674 /* The stub hash table. */
3675 struct bfd_hash_table stub_hash_table
;
3677 /* Another hash table for plt_branch stubs. */
3678 struct bfd_hash_table branch_hash_table
;
3680 /* Linker stub bfd. */
3683 /* Linker call-backs. */
3684 asection
* (*add_stub_section
) (const char *, asection
*);
3685 void (*layout_sections_again
) (void);
3687 /* Array to keep track of which stub sections have been created, and
3688 information on stub grouping. */
3690 /* This is the section to which stubs in the group will be attached. */
3692 /* The stub section. */
3694 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3698 /* Temp used when calculating TOC pointers. */
3701 asection
*toc_first_sec
;
3703 /* Highest input section id. */
3706 /* Highest output section index. */
3709 /* Used when adding symbols. */
3710 struct ppc_link_hash_entry
*dot_syms
;
3712 /* List of input sections for each output section. */
3713 asection
**input_list
;
3715 /* Short-cuts to get to dynamic linker sections. */
3727 asection
*glink_eh_frame
;
3729 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3730 struct ppc_link_hash_entry
*tls_get_addr
;
3731 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3733 /* The size of reliplt used by got entry relocs. */
3734 bfd_size_type got_reli_size
;
3737 unsigned long stub_count
[ppc_stub_plt_call
];
3739 /* Number of stubs against global syms. */
3740 unsigned long stub_globals
;
3742 /* Set if PLT call stubs should load r11. */
3743 unsigned int plt_static_chain
:1;
3745 /* Set if we should emit symbols for stubs. */
3746 unsigned int emit_stub_syms
:1;
3748 /* Set if __tls_get_addr optimization should not be done. */
3749 unsigned int no_tls_get_addr_opt
:1;
3751 /* Support for multiple toc sections. */
3752 unsigned int do_multi_toc
:1;
3753 unsigned int multi_toc_needed
:1;
3754 unsigned int second_toc_pass
:1;
3755 unsigned int do_toc_opt
:1;
3758 unsigned int stub_error
:1;
3760 /* Temp used by ppc64_elf_process_dot_syms. */
3761 unsigned int twiddled_syms
:1;
3763 /* Incremented every time we size stubs. */
3764 unsigned int stub_iteration
;
3766 /* Small local sym cache. */
3767 struct sym_cache sym_cache
;
3770 /* Rename some of the generic section flags to better document how they
3773 /* Nonzero if this section has TLS related relocations. */
3774 #define has_tls_reloc sec_flg0
3776 /* Nonzero if this section has a call to __tls_get_addr. */
3777 #define has_tls_get_addr_call sec_flg1
3779 /* Nonzero if this section has any toc or got relocs. */
3780 #define has_toc_reloc sec_flg2
3782 /* Nonzero if this section has a call to another section that uses
3784 #define makes_toc_func_call sec_flg3
3786 /* Recursion protection when determining above flag. */
3787 #define call_check_in_progress sec_flg4
3788 #define call_check_done sec_flg5
3790 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3792 #define ppc_hash_table(p) \
3793 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3794 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3796 #define ppc_stub_hash_lookup(table, string, create, copy) \
3797 ((struct ppc_stub_hash_entry *) \
3798 bfd_hash_lookup ((table), (string), (create), (copy)))
3800 #define ppc_branch_hash_lookup(table, string, create, copy) \
3801 ((struct ppc_branch_hash_entry *) \
3802 bfd_hash_lookup ((table), (string), (create), (copy)))
3804 /* Create an entry in the stub hash table. */
3806 static struct bfd_hash_entry
*
3807 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3808 struct bfd_hash_table
*table
,
3811 /* Allocate the structure if it has not already been allocated by a
3815 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3820 /* Call the allocation method of the superclass. */
3821 entry
= bfd_hash_newfunc (entry
, table
, string
);
3824 struct ppc_stub_hash_entry
*eh
;
3826 /* Initialize the local fields. */
3827 eh
= (struct ppc_stub_hash_entry
*) entry
;
3828 eh
->stub_type
= ppc_stub_none
;
3829 eh
->stub_sec
= NULL
;
3830 eh
->stub_offset
= 0;
3831 eh
->target_value
= 0;
3832 eh
->target_section
= NULL
;
3840 /* Create an entry in the branch hash table. */
3842 static struct bfd_hash_entry
*
3843 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3844 struct bfd_hash_table
*table
,
3847 /* Allocate the structure if it has not already been allocated by a
3851 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3856 /* Call the allocation method of the superclass. */
3857 entry
= bfd_hash_newfunc (entry
, table
, string
);
3860 struct ppc_branch_hash_entry
*eh
;
3862 /* Initialize the local fields. */
3863 eh
= (struct ppc_branch_hash_entry
*) entry
;
3871 /* Create an entry in a ppc64 ELF linker hash table. */
3873 static struct bfd_hash_entry
*
3874 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3875 struct bfd_hash_table
*table
,
3878 /* Allocate the structure if it has not already been allocated by a
3882 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3887 /* Call the allocation method of the superclass. */
3888 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3891 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3893 memset (&eh
->u
.stub_cache
, 0,
3894 (sizeof (struct ppc_link_hash_entry
)
3895 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3897 /* When making function calls, old ABI code references function entry
3898 points (dot symbols), while new ABI code references the function
3899 descriptor symbol. We need to make any combination of reference and
3900 definition work together, without breaking archive linking.
3902 For a defined function "foo" and an undefined call to "bar":
3903 An old object defines "foo" and ".foo", references ".bar" (possibly
3905 A new object defines "foo" and references "bar".
3907 A new object thus has no problem with its undefined symbols being
3908 satisfied by definitions in an old object. On the other hand, the
3909 old object won't have ".bar" satisfied by a new object.
3911 Keep a list of newly added dot-symbols. */
3913 if (string
[0] == '.')
3915 struct ppc_link_hash_table
*htab
;
3917 htab
= (struct ppc_link_hash_table
*) table
;
3918 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3919 htab
->dot_syms
= eh
;
3926 /* Create a ppc64 ELF linker hash table. */
3928 static struct bfd_link_hash_table
*
3929 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3931 struct ppc_link_hash_table
*htab
;
3932 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3934 htab
= bfd_zmalloc (amt
);
3938 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3939 sizeof (struct ppc_link_hash_entry
),
3946 /* Init the stub hash table too. */
3947 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3948 sizeof (struct ppc_stub_hash_entry
)))
3951 /* And the branch hash table. */
3952 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3953 sizeof (struct ppc_branch_hash_entry
)))
3956 /* Initializing two fields of the union is just cosmetic. We really
3957 only care about glist, but when compiled on a 32-bit host the
3958 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3959 debugger inspection of these fields look nicer. */
3960 htab
->elf
.init_got_refcount
.refcount
= 0;
3961 htab
->elf
.init_got_refcount
.glist
= NULL
;
3962 htab
->elf
.init_plt_refcount
.refcount
= 0;
3963 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3964 htab
->elf
.init_got_offset
.offset
= 0;
3965 htab
->elf
.init_got_offset
.glist
= NULL
;
3966 htab
->elf
.init_plt_offset
.offset
= 0;
3967 htab
->elf
.init_plt_offset
.glist
= NULL
;
3969 return &htab
->elf
.root
;
3972 /* Free the derived linker hash table. */
3975 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3977 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3979 bfd_hash_table_free (&ret
->stub_hash_table
);
3980 bfd_hash_table_free (&ret
->branch_hash_table
);
3981 _bfd_generic_link_hash_table_free (hash
);
3984 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3987 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3989 struct ppc_link_hash_table
*htab
;
3991 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3993 /* Always hook our dynamic sections into the first bfd, which is the
3994 linker created stub bfd. This ensures that the GOT header is at
3995 the start of the output TOC section. */
3996 htab
= ppc_hash_table (info
);
3999 htab
->stub_bfd
= abfd
;
4000 htab
->elf
.dynobj
= abfd
;
4003 /* Build a name for an entry in the stub hash table. */
4006 ppc_stub_name (const asection
*input_section
,
4007 const asection
*sym_sec
,
4008 const struct ppc_link_hash_entry
*h
,
4009 const Elf_Internal_Rela
*rel
)
4014 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4015 offsets from a sym as a branch target? In fact, we could
4016 probably assume the addend is always zero. */
4017 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4021 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4022 stub_name
= bfd_malloc (len
);
4023 if (stub_name
== NULL
)
4026 sprintf (stub_name
, "%08x.%s+%x",
4027 input_section
->id
& 0xffffffff,
4028 h
->elf
.root
.root
.string
,
4029 (int) rel
->r_addend
& 0xffffffff);
4033 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4034 stub_name
= bfd_malloc (len
);
4035 if (stub_name
== NULL
)
4038 sprintf (stub_name
, "%08x.%x:%x+%x",
4039 input_section
->id
& 0xffffffff,
4040 sym_sec
->id
& 0xffffffff,
4041 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4042 (int) rel
->r_addend
& 0xffffffff);
4044 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4045 stub_name
[len
- 2] = 0;
4049 /* Look up an entry in the stub hash. Stub entries are cached because
4050 creating the stub name takes a bit of time. */
4052 static struct ppc_stub_hash_entry
*
4053 ppc_get_stub_entry (const asection
*input_section
,
4054 const asection
*sym_sec
,
4055 struct ppc_link_hash_entry
*h
,
4056 const Elf_Internal_Rela
*rel
,
4057 struct ppc_link_hash_table
*htab
)
4059 struct ppc_stub_hash_entry
*stub_entry
;
4060 const asection
*id_sec
;
4062 /* If this input section is part of a group of sections sharing one
4063 stub section, then use the id of the first section in the group.
4064 Stub names need to include a section id, as there may well be
4065 more than one stub used to reach say, printf, and we need to
4066 distinguish between them. */
4067 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4069 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4070 && h
->u
.stub_cache
->h
== h
4071 && h
->u
.stub_cache
->id_sec
== id_sec
)
4073 stub_entry
= h
->u
.stub_cache
;
4079 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
4080 if (stub_name
== NULL
)
4083 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4084 stub_name
, FALSE
, FALSE
);
4086 h
->u
.stub_cache
= stub_entry
;
4094 /* Add a new stub entry to the stub hash. Not all fields of the new
4095 stub entry are initialised. */
4097 static struct ppc_stub_hash_entry
*
4098 ppc_add_stub (const char *stub_name
,
4100 struct bfd_link_info
*info
)
4102 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4105 struct ppc_stub_hash_entry
*stub_entry
;
4107 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
4108 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
4109 if (stub_sec
== NULL
)
4111 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
4112 if (stub_sec
== NULL
)
4118 namelen
= strlen (link_sec
->name
);
4119 len
= namelen
+ sizeof (STUB_SUFFIX
);
4120 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
4124 memcpy (s_name
, link_sec
->name
, namelen
);
4125 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4126 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
4127 if (stub_sec
== NULL
)
4129 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
4131 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
4134 /* Enter this entry into the linker stub hash table. */
4135 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4137 if (stub_entry
== NULL
)
4139 info
->callbacks
->einfo (_("%P: %B: cannot create stub entry %s\n"),
4140 section
->owner
, stub_name
);
4144 stub_entry
->stub_sec
= stub_sec
;
4145 stub_entry
->stub_offset
= 0;
4146 stub_entry
->id_sec
= link_sec
;
4150 /* Create sections for linker generated code. */
4153 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4155 struct ppc_link_hash_table
*htab
;
4158 htab
= ppc_hash_table (info
);
4162 /* Create .sfpr for code to save and restore fp regs. */
4163 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4164 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4165 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4167 if (htab
->sfpr
== NULL
4168 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4171 /* Create .glink for lazy dynamic linking support. */
4172 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4174 if (htab
->glink
== NULL
4175 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4178 if (!info
->no_ld_generated_unwind_info
)
4180 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4181 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4182 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4185 if (htab
->glink_eh_frame
== NULL
4186 || !bfd_set_section_alignment (abfd
, htab
->glink_eh_frame
, 2))
4190 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4191 htab
->iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4192 if (htab
->iplt
== NULL
4193 || ! bfd_set_section_alignment (dynobj
, htab
->iplt
, 3))
4196 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4197 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4198 htab
->reliplt
= bfd_make_section_anyway_with_flags (dynobj
,
4201 if (htab
->reliplt
== NULL
4202 || ! bfd_set_section_alignment (dynobj
, htab
->reliplt
, 3))
4205 /* Create branch lookup table for plt_branch stubs. */
4206 flags
= (SEC_ALLOC
| SEC_LOAD
4207 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4208 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4210 if (htab
->brlt
== NULL
4211 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4217 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4218 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4219 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4222 if (htab
->relbrlt
== NULL
4223 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4229 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4230 not already done. */
4233 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4235 asection
*got
, *relgot
;
4237 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4239 if (!is_ppc64_elf (abfd
))
4246 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4249 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
4254 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4255 | SEC_LINKER_CREATED
);
4257 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4259 || !bfd_set_section_alignment (abfd
, got
, 3))
4262 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4263 flags
| SEC_READONLY
);
4265 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4268 ppc64_elf_tdata (abfd
)->got
= got
;
4269 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4273 /* Create the dynamic sections, and set up shortcuts. */
4276 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4278 struct ppc_link_hash_table
*htab
;
4280 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4283 htab
= ppc_hash_table (info
);
4288 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
4289 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
4290 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4291 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
4293 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
4295 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
4296 || (!info
->shared
&& !htab
->relbss
))
4302 /* Follow indirect and warning symbol links. */
4304 static inline struct bfd_link_hash_entry
*
4305 follow_link (struct bfd_link_hash_entry
*h
)
4307 while (h
->type
== bfd_link_hash_indirect
4308 || h
->type
== bfd_link_hash_warning
)
4313 static inline struct elf_link_hash_entry
*
4314 elf_follow_link (struct elf_link_hash_entry
*h
)
4316 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4319 static inline struct ppc_link_hash_entry
*
4320 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4322 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4325 /* Merge PLT info on FROM with that on TO. */
4328 move_plt_plist (struct ppc_link_hash_entry
*from
,
4329 struct ppc_link_hash_entry
*to
)
4331 if (from
->elf
.plt
.plist
!= NULL
)
4333 if (to
->elf
.plt
.plist
!= NULL
)
4335 struct plt_entry
**entp
;
4336 struct plt_entry
*ent
;
4338 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4340 struct plt_entry
*dent
;
4342 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4343 if (dent
->addend
== ent
->addend
)
4345 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4352 *entp
= to
->elf
.plt
.plist
;
4355 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4356 from
->elf
.plt
.plist
= NULL
;
4360 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4363 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4364 struct elf_link_hash_entry
*dir
,
4365 struct elf_link_hash_entry
*ind
)
4367 struct ppc_link_hash_entry
*edir
, *eind
;
4369 edir
= (struct ppc_link_hash_entry
*) dir
;
4370 eind
= (struct ppc_link_hash_entry
*) ind
;
4372 edir
->is_func
|= eind
->is_func
;
4373 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4374 edir
->tls_mask
|= eind
->tls_mask
;
4375 if (eind
->oh
!= NULL
)
4376 edir
->oh
= ppc_follow_link (eind
->oh
);
4378 /* If called to transfer flags for a weakdef during processing
4379 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4380 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4381 if (!(ELIMINATE_COPY_RELOCS
4382 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4383 && edir
->elf
.dynamic_adjusted
))
4384 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4386 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4387 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4388 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4389 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4391 /* If we were called to copy over info for a weak sym, that's all. */
4392 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4395 /* Copy over any dynamic relocs we may have on the indirect sym. */
4396 if (eind
->dyn_relocs
!= NULL
)
4398 if (edir
->dyn_relocs
!= NULL
)
4400 struct elf_dyn_relocs
**pp
;
4401 struct elf_dyn_relocs
*p
;
4403 /* Add reloc counts against the indirect sym to the direct sym
4404 list. Merge any entries against the same section. */
4405 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4407 struct elf_dyn_relocs
*q
;
4409 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4410 if (q
->sec
== p
->sec
)
4412 q
->pc_count
+= p
->pc_count
;
4413 q
->count
+= p
->count
;
4420 *pp
= edir
->dyn_relocs
;
4423 edir
->dyn_relocs
= eind
->dyn_relocs
;
4424 eind
->dyn_relocs
= NULL
;
4427 /* Copy over got entries that we may have already seen to the
4428 symbol which just became indirect. */
4429 if (eind
->elf
.got
.glist
!= NULL
)
4431 if (edir
->elf
.got
.glist
!= NULL
)
4433 struct got_entry
**entp
;
4434 struct got_entry
*ent
;
4436 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4438 struct got_entry
*dent
;
4440 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4441 if (dent
->addend
== ent
->addend
4442 && dent
->owner
== ent
->owner
4443 && dent
->tls_type
== ent
->tls_type
)
4445 dent
->got
.refcount
+= ent
->got
.refcount
;
4452 *entp
= edir
->elf
.got
.glist
;
4455 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4456 eind
->elf
.got
.glist
= NULL
;
4459 /* And plt entries. */
4460 move_plt_plist (eind
, edir
);
4462 if (eind
->elf
.dynindx
!= -1)
4464 if (edir
->elf
.dynindx
!= -1)
4465 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4466 edir
->elf
.dynstr_index
);
4467 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4468 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4469 eind
->elf
.dynindx
= -1;
4470 eind
->elf
.dynstr_index
= 0;
4474 /* Find the function descriptor hash entry from the given function code
4475 hash entry FH. Link the entries via their OH fields. */
4477 static struct ppc_link_hash_entry
*
4478 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4480 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4484 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4486 fdh
= (struct ppc_link_hash_entry
*)
4487 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4491 fdh
->is_func_descriptor
= 1;
4497 return ppc_follow_link (fdh
);
4500 /* Make a fake function descriptor sym for the code sym FH. */
4502 static struct ppc_link_hash_entry
*
4503 make_fdh (struct bfd_link_info
*info
,
4504 struct ppc_link_hash_entry
*fh
)
4508 struct bfd_link_hash_entry
*bh
;
4509 struct ppc_link_hash_entry
*fdh
;
4511 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4512 newsym
= bfd_make_empty_symbol (abfd
);
4513 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4514 newsym
->section
= bfd_und_section_ptr
;
4516 newsym
->flags
= BSF_WEAK
;
4519 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4520 newsym
->flags
, newsym
->section
,
4521 newsym
->value
, NULL
, FALSE
, FALSE
,
4525 fdh
= (struct ppc_link_hash_entry
*) bh
;
4526 fdh
->elf
.non_elf
= 0;
4528 fdh
->is_func_descriptor
= 1;
4535 /* Fix function descriptor symbols defined in .opd sections to be
4539 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4540 struct bfd_link_info
*info
,
4541 Elf_Internal_Sym
*isym
,
4542 const char **name ATTRIBUTE_UNUSED
,
4543 flagword
*flags ATTRIBUTE_UNUSED
,
4545 bfd_vma
*value ATTRIBUTE_UNUSED
)
4547 if ((ibfd
->flags
& DYNAMIC
) == 0
4548 && ELF_ST_BIND (isym
->st_info
) == STB_GNU_UNIQUE
)
4549 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4551 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4553 if ((ibfd
->flags
& DYNAMIC
) == 0)
4554 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4556 else if (ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
)
4558 else if (*sec
!= NULL
4559 && strcmp ((*sec
)->name
, ".opd") == 0)
4560 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4565 /* This function makes an old ABI object reference to ".bar" cause the
4566 inclusion of a new ABI object archive that defines "bar".
4567 NAME is a symbol defined in an archive. Return a symbol in the hash
4568 table that might be satisfied by the archive symbols. */
4570 static struct elf_link_hash_entry
*
4571 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4572 struct bfd_link_info
*info
,
4575 struct elf_link_hash_entry
*h
;
4579 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4581 /* Don't return this sym if it is a fake function descriptor
4582 created by add_symbol_adjust. */
4583 && !(h
->root
.type
== bfd_link_hash_undefweak
4584 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4590 len
= strlen (name
);
4591 dot_name
= bfd_alloc (abfd
, len
+ 2);
4592 if (dot_name
== NULL
)
4593 return (struct elf_link_hash_entry
*) 0 - 1;
4595 memcpy (dot_name
+ 1, name
, len
+ 1);
4596 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4597 bfd_release (abfd
, dot_name
);
4601 /* This function satisfies all old ABI object references to ".bar" if a
4602 new ABI object defines "bar". Well, at least, undefined dot symbols
4603 are made weak. This stops later archive searches from including an
4604 object if we already have a function descriptor definition. It also
4605 prevents the linker complaining about undefined symbols.
4606 We also check and correct mismatched symbol visibility here. The
4607 most restrictive visibility of the function descriptor and the
4608 function entry symbol is used. */
4611 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4613 struct ppc_link_hash_table
*htab
;
4614 struct ppc_link_hash_entry
*fdh
;
4616 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4619 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4620 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4622 if (eh
->elf
.root
.root
.string
[0] != '.')
4625 htab
= ppc_hash_table (info
);
4629 fdh
= lookup_fdh (eh
, htab
);
4632 if (!info
->relocatable
4633 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4634 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4635 && eh
->elf
.ref_regular
)
4637 /* Make an undefweak function descriptor sym, which is enough to
4638 pull in an --as-needed shared lib, but won't cause link
4639 errors. Archives are handled elsewhere. */
4640 fdh
= make_fdh (info
, eh
);
4643 fdh
->elf
.ref_regular
= 1;
4648 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4649 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4650 if (entry_vis
< descr_vis
)
4651 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4652 else if (entry_vis
> descr_vis
)
4653 eh
->elf
.other
+= descr_vis
- entry_vis
;
4655 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4656 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4657 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4659 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4660 eh
->was_undefined
= 1;
4661 htab
->twiddled_syms
= 1;
4668 /* Process list of dot-symbols we made in link_hash_newfunc. */
4671 ppc64_elf_process_dot_syms (bfd
*ibfd
, struct bfd_link_info
*info
)
4673 struct ppc_link_hash_table
*htab
;
4674 struct ppc_link_hash_entry
**p
, *eh
;
4676 if (!is_ppc64_elf (info
->output_bfd
))
4678 htab
= ppc_hash_table (info
);
4682 if (is_ppc64_elf (ibfd
))
4684 p
= &htab
->dot_syms
;
4685 while ((eh
= *p
) != NULL
)
4688 if (!add_symbol_adjust (eh
, info
))
4690 p
= &eh
->u
.next_dot_sym
;
4694 /* Clear the list for non-ppc64 input files. */
4695 p
= &htab
->dot_syms
;
4696 while ((eh
= *p
) != NULL
)
4699 p
= &eh
->u
.next_dot_sym
;
4702 /* We need to fix the undefs list for any syms we have twiddled to
4704 if (htab
->twiddled_syms
)
4706 bfd_link_repair_undef_list (&htab
->elf
.root
);
4707 htab
->twiddled_syms
= 0;
4712 /* Undo hash table changes when an --as-needed input file is determined
4713 not to be needed. */
4716 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4717 struct bfd_link_info
*info
)
4719 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4724 htab
->dot_syms
= NULL
;
4728 /* If --just-symbols against a final linked binary, then assume we need
4729 toc adjusting stubs when calling functions defined there. */
4732 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4734 if ((sec
->flags
& SEC_CODE
) != 0
4735 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4736 && is_ppc64_elf (sec
->owner
))
4738 asection
*got
= bfd_get_section_by_name (sec
->owner
, ".got");
4740 && got
->size
>= elf_backend_got_header_size
4741 && bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4742 sec
->has_toc_reloc
= 1;
4744 _bfd_elf_link_just_syms (sec
, info
);
4747 static struct plt_entry
**
4748 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4749 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4751 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4752 struct plt_entry
**local_plt
;
4753 unsigned char *local_got_tls_masks
;
4755 if (local_got_ents
== NULL
)
4757 bfd_size_type size
= symtab_hdr
->sh_info
;
4759 size
*= (sizeof (*local_got_ents
)
4760 + sizeof (*local_plt
)
4761 + sizeof (*local_got_tls_masks
));
4762 local_got_ents
= bfd_zalloc (abfd
, size
);
4763 if (local_got_ents
== NULL
)
4765 elf_local_got_ents (abfd
) = local_got_ents
;
4768 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
4770 struct got_entry
*ent
;
4772 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4773 if (ent
->addend
== r_addend
4774 && ent
->owner
== abfd
4775 && ent
->tls_type
== tls_type
)
4779 bfd_size_type amt
= sizeof (*ent
);
4780 ent
= bfd_alloc (abfd
, amt
);
4783 ent
->next
= local_got_ents
[r_symndx
];
4784 ent
->addend
= r_addend
;
4786 ent
->tls_type
= tls_type
;
4787 ent
->is_indirect
= FALSE
;
4788 ent
->got
.refcount
= 0;
4789 local_got_ents
[r_symndx
] = ent
;
4791 ent
->got
.refcount
+= 1;
4794 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4795 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4796 local_got_tls_masks
[r_symndx
] |= tls_type
;
4798 return local_plt
+ r_symndx
;
4802 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4804 struct plt_entry
*ent
;
4806 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4807 if (ent
->addend
== addend
)
4811 bfd_size_type amt
= sizeof (*ent
);
4812 ent
= bfd_alloc (abfd
, amt
);
4816 ent
->addend
= addend
;
4817 ent
->plt
.refcount
= 0;
4820 ent
->plt
.refcount
+= 1;
4825 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4827 return (r_type
== R_PPC64_REL24
4828 || r_type
== R_PPC64_REL14
4829 || r_type
== R_PPC64_REL14_BRTAKEN
4830 || r_type
== R_PPC64_REL14_BRNTAKEN
4831 || r_type
== R_PPC64_ADDR24
4832 || r_type
== R_PPC64_ADDR14
4833 || r_type
== R_PPC64_ADDR14_BRTAKEN
4834 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
4837 /* Look through the relocs for a section during the first phase, and
4838 calculate needed space in the global offset table, procedure
4839 linkage table, and dynamic reloc sections. */
4842 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4843 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4845 struct ppc_link_hash_table
*htab
;
4846 Elf_Internal_Shdr
*symtab_hdr
;
4847 struct elf_link_hash_entry
**sym_hashes
;
4848 const Elf_Internal_Rela
*rel
;
4849 const Elf_Internal_Rela
*rel_end
;
4851 asection
**opd_sym_map
;
4852 struct elf_link_hash_entry
*tga
, *dottga
;
4854 if (info
->relocatable
)
4857 /* Don't do anything special with non-loaded, non-alloced sections.
4858 In particular, any relocs in such sections should not affect GOT
4859 and PLT reference counting (ie. we don't allow them to create GOT
4860 or PLT entries), there's no possibility or desire to optimize TLS
4861 relocs, and there's not much point in propagating relocs to shared
4862 libs that the dynamic linker won't relocate. */
4863 if ((sec
->flags
& SEC_ALLOC
) == 0)
4866 BFD_ASSERT (is_ppc64_elf (abfd
));
4868 htab
= ppc_hash_table (info
);
4872 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4873 FALSE
, FALSE
, TRUE
);
4874 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4875 FALSE
, FALSE
, TRUE
);
4876 symtab_hdr
= &elf_symtab_hdr (abfd
);
4877 sym_hashes
= elf_sym_hashes (abfd
);
4880 if (strcmp (sec
->name
, ".opd") == 0)
4882 /* Garbage collection needs some extra help with .opd sections.
4883 We don't want to necessarily keep everything referenced by
4884 relocs in .opd, as that would keep all functions. Instead,
4885 if we reference an .opd symbol (a function descriptor), we
4886 want to keep the function code symbol's section. This is
4887 easy for global symbols, but for local syms we need to keep
4888 information about the associated function section. */
4891 amt
= sec
->size
* sizeof (*opd_sym_map
) / 8;
4892 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4893 if (opd_sym_map
== NULL
)
4895 ppc64_elf_section_data (sec
)->u
.opd
.func_sec
= opd_sym_map
;
4896 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4897 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4900 if (htab
->sfpr
== NULL
4901 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4904 rel_end
= relocs
+ sec
->reloc_count
;
4905 for (rel
= relocs
; rel
< rel_end
; rel
++)
4907 unsigned long r_symndx
;
4908 struct elf_link_hash_entry
*h
;
4909 enum elf_ppc64_reloc_type r_type
;
4911 struct _ppc64_elf_section_data
*ppc64_sec
;
4912 struct plt_entry
**ifunc
;
4914 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4915 if (r_symndx
< symtab_hdr
->sh_info
)
4919 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4920 h
= elf_follow_link (h
);
4927 if (h
->type
== STT_GNU_IFUNC
)
4930 ifunc
= &h
->plt
.plist
;
4935 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4940 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4942 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4943 rel
->r_addend
, PLT_IFUNC
);
4948 r_type
= ELF64_R_TYPE (rel
->r_info
);
4949 if (is_branch_reloc (r_type
))
4951 if (h
!= NULL
&& (h
== tga
|| h
== dottga
))
4954 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4955 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4956 /* We have a new-style __tls_get_addr call with a marker
4960 /* Mark this section as having an old-style call. */
4961 sec
->has_tls_get_addr_call
= 1;
4964 /* STT_GNU_IFUNC symbols must have a PLT entry. */
4966 && !update_plt_info (abfd
, ifunc
, rel
->r_addend
))
4974 /* These special tls relocs tie a call to __tls_get_addr with
4975 its parameter symbol. */
4978 case R_PPC64_GOT_TLSLD16
:
4979 case R_PPC64_GOT_TLSLD16_LO
:
4980 case R_PPC64_GOT_TLSLD16_HI
:
4981 case R_PPC64_GOT_TLSLD16_HA
:
4982 tls_type
= TLS_TLS
| TLS_LD
;
4985 case R_PPC64_GOT_TLSGD16
:
4986 case R_PPC64_GOT_TLSGD16_LO
:
4987 case R_PPC64_GOT_TLSGD16_HI
:
4988 case R_PPC64_GOT_TLSGD16_HA
:
4989 tls_type
= TLS_TLS
| TLS_GD
;
4992 case R_PPC64_GOT_TPREL16_DS
:
4993 case R_PPC64_GOT_TPREL16_LO_DS
:
4994 case R_PPC64_GOT_TPREL16_HI
:
4995 case R_PPC64_GOT_TPREL16_HA
:
4996 if (!info
->executable
)
4997 info
->flags
|= DF_STATIC_TLS
;
4998 tls_type
= TLS_TLS
| TLS_TPREL
;
5001 case R_PPC64_GOT_DTPREL16_DS
:
5002 case R_PPC64_GOT_DTPREL16_LO_DS
:
5003 case R_PPC64_GOT_DTPREL16_HI
:
5004 case R_PPC64_GOT_DTPREL16_HA
:
5005 tls_type
= TLS_TLS
| TLS_DTPREL
;
5007 sec
->has_tls_reloc
= 1;
5011 case R_PPC64_GOT16_DS
:
5012 case R_PPC64_GOT16_HA
:
5013 case R_PPC64_GOT16_HI
:
5014 case R_PPC64_GOT16_LO
:
5015 case R_PPC64_GOT16_LO_DS
:
5016 /* This symbol requires a global offset table entry. */
5017 sec
->has_toc_reloc
= 1;
5018 if (r_type
== R_PPC64_GOT_TLSLD16
5019 || r_type
== R_PPC64_GOT_TLSGD16
5020 || r_type
== R_PPC64_GOT_TPREL16_DS
5021 || r_type
== R_PPC64_GOT_DTPREL16_DS
5022 || r_type
== R_PPC64_GOT16
5023 || r_type
== R_PPC64_GOT16_DS
)
5025 htab
->do_multi_toc
= 1;
5026 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5029 if (ppc64_elf_tdata (abfd
)->got
== NULL
5030 && !create_got_section (abfd
, info
))
5035 struct ppc_link_hash_entry
*eh
;
5036 struct got_entry
*ent
;
5038 eh
= (struct ppc_link_hash_entry
*) h
;
5039 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5040 if (ent
->addend
== rel
->r_addend
5041 && ent
->owner
== abfd
5042 && ent
->tls_type
== tls_type
)
5046 bfd_size_type amt
= sizeof (*ent
);
5047 ent
= bfd_alloc (abfd
, amt
);
5050 ent
->next
= eh
->elf
.got
.glist
;
5051 ent
->addend
= rel
->r_addend
;
5053 ent
->tls_type
= tls_type
;
5054 ent
->is_indirect
= FALSE
;
5055 ent
->got
.refcount
= 0;
5056 eh
->elf
.got
.glist
= ent
;
5058 ent
->got
.refcount
+= 1;
5059 eh
->tls_mask
|= tls_type
;
5062 /* This is a global offset table entry for a local symbol. */
5063 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5064 rel
->r_addend
, tls_type
))
5068 case R_PPC64_PLT16_HA
:
5069 case R_PPC64_PLT16_HI
:
5070 case R_PPC64_PLT16_LO
:
5073 /* This symbol requires a procedure linkage table entry. We
5074 actually build the entry in adjust_dynamic_symbol,
5075 because this might be a case of linking PIC code without
5076 linking in any dynamic objects, in which case we don't
5077 need to generate a procedure linkage table after all. */
5080 /* It does not make sense to have a procedure linkage
5081 table entry for a local symbol. */
5082 bfd_set_error (bfd_error_bad_value
);
5087 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5090 if (h
->root
.root
.string
[0] == '.'
5091 && h
->root
.root
.string
[1] != '\0')
5092 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5096 /* The following relocations don't need to propagate the
5097 relocation if linking a shared object since they are
5098 section relative. */
5099 case R_PPC64_SECTOFF
:
5100 case R_PPC64_SECTOFF_LO
:
5101 case R_PPC64_SECTOFF_HI
:
5102 case R_PPC64_SECTOFF_HA
:
5103 case R_PPC64_SECTOFF_DS
:
5104 case R_PPC64_SECTOFF_LO_DS
:
5105 case R_PPC64_DTPREL16
:
5106 case R_PPC64_DTPREL16_LO
:
5107 case R_PPC64_DTPREL16_HI
:
5108 case R_PPC64_DTPREL16_HA
:
5109 case R_PPC64_DTPREL16_DS
:
5110 case R_PPC64_DTPREL16_LO_DS
:
5111 case R_PPC64_DTPREL16_HIGHER
:
5112 case R_PPC64_DTPREL16_HIGHERA
:
5113 case R_PPC64_DTPREL16_HIGHEST
:
5114 case R_PPC64_DTPREL16_HIGHESTA
:
5119 case R_PPC64_REL16_LO
:
5120 case R_PPC64_REL16_HI
:
5121 case R_PPC64_REL16_HA
:
5125 case R_PPC64_TOC16_DS
:
5126 htab
->do_multi_toc
= 1;
5127 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5128 case R_PPC64_TOC16_LO
:
5129 case R_PPC64_TOC16_HI
:
5130 case R_PPC64_TOC16_HA
:
5131 case R_PPC64_TOC16_LO_DS
:
5132 sec
->has_toc_reloc
= 1;
5135 /* This relocation describes the C++ object vtable hierarchy.
5136 Reconstruct it for later use during GC. */
5137 case R_PPC64_GNU_VTINHERIT
:
5138 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5142 /* This relocation describes which C++ vtable entries are actually
5143 used. Record for later use during GC. */
5144 case R_PPC64_GNU_VTENTRY
:
5145 BFD_ASSERT (h
!= NULL
);
5147 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5152 case R_PPC64_REL14_BRTAKEN
:
5153 case R_PPC64_REL14_BRNTAKEN
:
5155 asection
*dest
= NULL
;
5157 /* Heuristic: If jumping outside our section, chances are
5158 we are going to need a stub. */
5161 /* If the sym is weak it may be overridden later, so
5162 don't assume we know where a weak sym lives. */
5163 if (h
->root
.type
== bfd_link_hash_defined
)
5164 dest
= h
->root
.u
.def
.section
;
5168 Elf_Internal_Sym
*isym
;
5170 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5175 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5179 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5184 if (h
!= NULL
&& ifunc
== NULL
)
5186 /* We may need a .plt entry if the function this reloc
5187 refers to is in a shared lib. */
5188 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5191 if (h
->root
.root
.string
[0] == '.'
5192 && h
->root
.root
.string
[1] != '\0')
5193 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5194 if (h
== tga
|| h
== dottga
)
5195 sec
->has_tls_reloc
= 1;
5199 case R_PPC64_TPREL64
:
5200 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5201 if (!info
->executable
)
5202 info
->flags
|= DF_STATIC_TLS
;
5205 case R_PPC64_DTPMOD64
:
5206 if (rel
+ 1 < rel_end
5207 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5208 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5209 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5211 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5214 case R_PPC64_DTPREL64
:
5215 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5217 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5218 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5219 /* This is the second reloc of a dtpmod, dtprel pair.
5220 Don't mark with TLS_DTPREL. */
5224 sec
->has_tls_reloc
= 1;
5227 struct ppc_link_hash_entry
*eh
;
5228 eh
= (struct ppc_link_hash_entry
*) h
;
5229 eh
->tls_mask
|= tls_type
;
5232 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5233 rel
->r_addend
, tls_type
))
5236 ppc64_sec
= ppc64_elf_section_data (sec
);
5237 if (ppc64_sec
->sec_type
!= sec_toc
)
5241 /* One extra to simplify get_tls_mask. */
5242 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5243 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5244 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5246 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5247 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5248 if (ppc64_sec
->u
.toc
.add
== NULL
)
5250 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5251 ppc64_sec
->sec_type
= sec_toc
;
5253 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5254 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5255 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5257 /* Mark the second slot of a GD or LD entry.
5258 -1 to indicate GD and -2 to indicate LD. */
5259 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5260 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5261 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5262 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5265 case R_PPC64_TPREL16
:
5266 case R_PPC64_TPREL16_LO
:
5267 case R_PPC64_TPREL16_HI
:
5268 case R_PPC64_TPREL16_HA
:
5269 case R_PPC64_TPREL16_DS
:
5270 case R_PPC64_TPREL16_LO_DS
:
5271 case R_PPC64_TPREL16_HIGHER
:
5272 case R_PPC64_TPREL16_HIGHERA
:
5273 case R_PPC64_TPREL16_HIGHEST
:
5274 case R_PPC64_TPREL16_HIGHESTA
:
5277 if (!info
->executable
)
5278 info
->flags
|= DF_STATIC_TLS
;
5283 case R_PPC64_ADDR64
:
5284 if (opd_sym_map
!= NULL
5285 && rel
+ 1 < rel_end
5286 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5290 if (h
->root
.root
.string
[0] == '.'
5291 && h
->root
.root
.string
[1] != 0
5292 && lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
5295 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5300 Elf_Internal_Sym
*isym
;
5302 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5307 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5308 if (s
!= NULL
&& s
!= sec
)
5309 opd_sym_map
[rel
->r_offset
/ 8] = s
;
5317 case R_PPC64_ADDR14
:
5318 case R_PPC64_ADDR14_BRNTAKEN
:
5319 case R_PPC64_ADDR14_BRTAKEN
:
5320 case R_PPC64_ADDR16
:
5321 case R_PPC64_ADDR16_DS
:
5322 case R_PPC64_ADDR16_HA
:
5323 case R_PPC64_ADDR16_HI
:
5324 case R_PPC64_ADDR16_HIGHER
:
5325 case R_PPC64_ADDR16_HIGHERA
:
5326 case R_PPC64_ADDR16_HIGHEST
:
5327 case R_PPC64_ADDR16_HIGHESTA
:
5328 case R_PPC64_ADDR16_LO
:
5329 case R_PPC64_ADDR16_LO_DS
:
5330 case R_PPC64_ADDR24
:
5331 case R_PPC64_ADDR32
:
5332 case R_PPC64_UADDR16
:
5333 case R_PPC64_UADDR32
:
5334 case R_PPC64_UADDR64
:
5336 if (h
!= NULL
&& !info
->shared
)
5337 /* We may need a copy reloc. */
5340 /* Don't propagate .opd relocs. */
5341 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5344 /* If we are creating a shared library, and this is a reloc
5345 against a global symbol, or a non PC relative reloc
5346 against a local symbol, then we need to copy the reloc
5347 into the shared library. However, if we are linking with
5348 -Bsymbolic, we do not need to copy a reloc against a
5349 global symbol which is defined in an object we are
5350 including in the link (i.e., DEF_REGULAR is set). At
5351 this point we have not seen all the input files, so it is
5352 possible that DEF_REGULAR is not set now but will be set
5353 later (it is never cleared). In case of a weak definition,
5354 DEF_REGULAR may be cleared later by a strong definition in
5355 a shared library. We account for that possibility below by
5356 storing information in the dyn_relocs field of the hash
5357 table entry. A similar situation occurs when creating
5358 shared libraries and symbol visibility changes render the
5361 If on the other hand, we are creating an executable, we
5362 may need to keep relocations for symbols satisfied by a
5363 dynamic library if we manage to avoid copy relocs for the
5367 && (must_be_dyn_reloc (info
, r_type
)
5369 && (! info
->symbolic
5370 || h
->root
.type
== bfd_link_hash_defweak
5371 || !h
->def_regular
))))
5372 || (ELIMINATE_COPY_RELOCS
5375 && (h
->root
.type
== bfd_link_hash_defweak
5376 || !h
->def_regular
))
5380 struct elf_dyn_relocs
*p
;
5381 struct elf_dyn_relocs
**head
;
5383 /* We must copy these reloc types into the output file.
5384 Create a reloc section in dynobj and make room for
5388 sreloc
= _bfd_elf_make_dynamic_reloc_section
5389 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5395 /* If this is a global symbol, we count the number of
5396 relocations we need for this symbol. */
5399 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5403 /* Track dynamic relocs needed for local syms too.
5404 We really need local syms available to do this
5408 Elf_Internal_Sym
*isym
;
5410 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5415 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5419 vpp
= &elf_section_data (s
)->local_dynrel
;
5420 head
= (struct elf_dyn_relocs
**) vpp
;
5424 if (p
== NULL
|| p
->sec
!= sec
)
5426 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5437 if (!must_be_dyn_reloc (info
, r_type
))
5450 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5451 of the code entry point, and its section. */
5454 opd_entry_value (asection
*opd_sec
,
5456 asection
**code_sec
,
5459 bfd
*opd_bfd
= opd_sec
->owner
;
5460 Elf_Internal_Rela
*relocs
;
5461 Elf_Internal_Rela
*lo
, *hi
, *look
;
5464 /* No relocs implies we are linking a --just-symbols object. */
5465 if (opd_sec
->reloc_count
== 0)
5469 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, buf
, offset
, 8))
5470 return (bfd_vma
) -1;
5472 val
= bfd_get_64 (opd_bfd
, buf
);
5473 if (code_sec
!= NULL
)
5475 asection
*sec
, *likely
= NULL
;
5476 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5478 && (sec
->flags
& SEC_LOAD
) != 0
5479 && (sec
->flags
& SEC_ALLOC
) != 0)
5484 if (code_off
!= NULL
)
5485 *code_off
= val
- likely
->vma
;
5491 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5493 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
5495 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5497 /* Go find the opd reloc at the sym address. */
5499 BFD_ASSERT (lo
!= NULL
);
5500 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5504 look
= lo
+ (hi
- lo
) / 2;
5505 if (look
->r_offset
< offset
)
5507 else if (look
->r_offset
> offset
)
5511 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5513 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5514 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5516 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5519 if (symndx
< symtab_hdr
->sh_info
)
5521 Elf_Internal_Sym
*sym
;
5523 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5526 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5527 symtab_hdr
->sh_info
,
5528 0, NULL
, NULL
, NULL
);
5531 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5535 val
= sym
->st_value
;
5536 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5537 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5541 struct elf_link_hash_entry
**sym_hashes
;
5542 struct elf_link_hash_entry
*rh
;
5544 sym_hashes
= elf_sym_hashes (opd_bfd
);
5545 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5546 rh
= elf_follow_link (rh
);
5547 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5548 || rh
->root
.type
== bfd_link_hash_defweak
);
5549 val
= rh
->root
.u
.def
.value
;
5550 sec
= rh
->root
.u
.def
.section
;
5552 val
+= look
->r_addend
;
5553 if (code_off
!= NULL
)
5555 if (code_sec
!= NULL
)
5557 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5558 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5567 /* Return true if symbol is defined in a regular object file. */
5570 is_static_defined (struct elf_link_hash_entry
*h
)
5572 return ((h
->root
.type
== bfd_link_hash_defined
5573 || h
->root
.type
== bfd_link_hash_defweak
)
5574 && h
->root
.u
.def
.section
!= NULL
5575 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5578 /* If FDH is a function descriptor symbol, return the associated code
5579 entry symbol if it is defined. Return NULL otherwise. */
5581 static struct ppc_link_hash_entry
*
5582 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5584 if (fdh
->is_func_descriptor
)
5586 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5587 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5588 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5594 /* If FH is a function code entry symbol, return the associated
5595 function descriptor symbol if it is defined. Return NULL otherwise. */
5597 static struct ppc_link_hash_entry
*
5598 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5601 && fh
->oh
->is_func_descriptor
)
5603 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5604 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5605 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5611 /* Mark all our entry sym sections, both opd and code section. */
5614 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5616 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5617 struct bfd_sym_chain
*sym
;
5622 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5624 struct ppc_link_hash_entry
*eh
, *fh
;
5627 eh
= (struct ppc_link_hash_entry
*)
5628 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5631 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5632 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5635 fh
= defined_code_entry (eh
);
5638 sec
= fh
->elf
.root
.u
.def
.section
;
5639 sec
->flags
|= SEC_KEEP
;
5641 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5642 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5643 eh
->elf
.root
.u
.def
.value
,
5644 &sec
, NULL
) != (bfd_vma
) -1)
5645 sec
->flags
|= SEC_KEEP
;
5647 sec
= eh
->elf
.root
.u
.def
.section
;
5648 sec
->flags
|= SEC_KEEP
;
5652 /* Mark sections containing dynamically referenced symbols. When
5653 building shared libraries, we must assume that any visible symbol is
5657 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5659 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5660 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5661 struct ppc_link_hash_entry
*fdh
;
5663 /* Dynamic linking info is on the func descriptor sym. */
5664 fdh
= defined_func_desc (eh
);
5668 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5669 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5670 && (eh
->elf
.ref_dynamic
5671 || (!info
->executable
5672 && eh
->elf
.def_regular
5673 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5674 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5677 struct ppc_link_hash_entry
*fh
;
5679 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5681 /* Function descriptor syms cause the associated
5682 function code sym section to be marked. */
5683 fh
= defined_code_entry (eh
);
5686 code_sec
= fh
->elf
.root
.u
.def
.section
;
5687 code_sec
->flags
|= SEC_KEEP
;
5689 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5690 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5691 eh
->elf
.root
.u
.def
.value
,
5692 &code_sec
, NULL
) != (bfd_vma
) -1)
5693 code_sec
->flags
|= SEC_KEEP
;
5699 /* Return the section that should be marked against GC for a given
5703 ppc64_elf_gc_mark_hook (asection
*sec
,
5704 struct bfd_link_info
*info
,
5705 Elf_Internal_Rela
*rel
,
5706 struct elf_link_hash_entry
*h
,
5707 Elf_Internal_Sym
*sym
)
5711 /* Syms return NULL if we're marking .opd, so we avoid marking all
5712 function sections, as all functions are referenced in .opd. */
5714 if (get_opd_info (sec
) != NULL
)
5719 enum elf_ppc64_reloc_type r_type
;
5720 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5722 r_type
= ELF64_R_TYPE (rel
->r_info
);
5725 case R_PPC64_GNU_VTINHERIT
:
5726 case R_PPC64_GNU_VTENTRY
:
5730 switch (h
->root
.type
)
5732 case bfd_link_hash_defined
:
5733 case bfd_link_hash_defweak
:
5734 eh
= (struct ppc_link_hash_entry
*) h
;
5735 fdh
= defined_func_desc (eh
);
5739 /* Function descriptor syms cause the associated
5740 function code sym section to be marked. */
5741 fh
= defined_code_entry (eh
);
5744 /* They also mark their opd section. */
5745 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5747 rsec
= fh
->elf
.root
.u
.def
.section
;
5749 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5750 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5751 eh
->elf
.root
.u
.def
.value
,
5752 &rsec
, NULL
) != (bfd_vma
) -1)
5753 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5755 rsec
= h
->root
.u
.def
.section
;
5758 case bfd_link_hash_common
:
5759 rsec
= h
->root
.u
.c
.p
->section
;
5763 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5769 struct _opd_sec_data
*opd
;
5771 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5772 opd
= get_opd_info (rsec
);
5773 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5777 rsec
= opd
->func_sec
[(sym
->st_value
+ rel
->r_addend
) / 8];
5784 /* Update the .got, .plt. and dynamic reloc reference counts for the
5785 section being removed. */
5788 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5789 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5791 struct ppc_link_hash_table
*htab
;
5792 Elf_Internal_Shdr
*symtab_hdr
;
5793 struct elf_link_hash_entry
**sym_hashes
;
5794 struct got_entry
**local_got_ents
;
5795 const Elf_Internal_Rela
*rel
, *relend
;
5797 if (info
->relocatable
)
5800 if ((sec
->flags
& SEC_ALLOC
) == 0)
5803 elf_section_data (sec
)->local_dynrel
= NULL
;
5805 htab
= ppc_hash_table (info
);
5809 symtab_hdr
= &elf_symtab_hdr (abfd
);
5810 sym_hashes
= elf_sym_hashes (abfd
);
5811 local_got_ents
= elf_local_got_ents (abfd
);
5813 relend
= relocs
+ sec
->reloc_count
;
5814 for (rel
= relocs
; rel
< relend
; rel
++)
5816 unsigned long r_symndx
;
5817 enum elf_ppc64_reloc_type r_type
;
5818 struct elf_link_hash_entry
*h
= NULL
;
5819 unsigned char tls_type
= 0;
5821 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5822 r_type
= ELF64_R_TYPE (rel
->r_info
);
5823 if (r_symndx
>= symtab_hdr
->sh_info
)
5825 struct ppc_link_hash_entry
*eh
;
5826 struct elf_dyn_relocs
**pp
;
5827 struct elf_dyn_relocs
*p
;
5829 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5830 h
= elf_follow_link (h
);
5831 eh
= (struct ppc_link_hash_entry
*) h
;
5833 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5836 /* Everything must go for SEC. */
5842 if (is_branch_reloc (r_type
))
5844 struct plt_entry
**ifunc
= NULL
;
5847 if (h
->type
== STT_GNU_IFUNC
)
5848 ifunc
= &h
->plt
.plist
;
5850 else if (local_got_ents
!= NULL
)
5852 struct plt_entry
**local_plt
= (struct plt_entry
**)
5853 (local_got_ents
+ symtab_hdr
->sh_info
);
5854 unsigned char *local_got_tls_masks
= (unsigned char *)
5855 (local_plt
+ symtab_hdr
->sh_info
);
5856 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
5857 ifunc
= local_plt
+ r_symndx
;
5861 struct plt_entry
*ent
;
5863 for (ent
= *ifunc
; ent
!= NULL
; ent
= ent
->next
)
5864 if (ent
->addend
== rel
->r_addend
)
5868 if (ent
->plt
.refcount
> 0)
5869 ent
->plt
.refcount
-= 1;
5876 case R_PPC64_GOT_TLSLD16
:
5877 case R_PPC64_GOT_TLSLD16_LO
:
5878 case R_PPC64_GOT_TLSLD16_HI
:
5879 case R_PPC64_GOT_TLSLD16_HA
:
5880 tls_type
= TLS_TLS
| TLS_LD
;
5883 case R_PPC64_GOT_TLSGD16
:
5884 case R_PPC64_GOT_TLSGD16_LO
:
5885 case R_PPC64_GOT_TLSGD16_HI
:
5886 case R_PPC64_GOT_TLSGD16_HA
:
5887 tls_type
= TLS_TLS
| TLS_GD
;
5890 case R_PPC64_GOT_TPREL16_DS
:
5891 case R_PPC64_GOT_TPREL16_LO_DS
:
5892 case R_PPC64_GOT_TPREL16_HI
:
5893 case R_PPC64_GOT_TPREL16_HA
:
5894 tls_type
= TLS_TLS
| TLS_TPREL
;
5897 case R_PPC64_GOT_DTPREL16_DS
:
5898 case R_PPC64_GOT_DTPREL16_LO_DS
:
5899 case R_PPC64_GOT_DTPREL16_HI
:
5900 case R_PPC64_GOT_DTPREL16_HA
:
5901 tls_type
= TLS_TLS
| TLS_DTPREL
;
5905 case R_PPC64_GOT16_DS
:
5906 case R_PPC64_GOT16_HA
:
5907 case R_PPC64_GOT16_HI
:
5908 case R_PPC64_GOT16_LO
:
5909 case R_PPC64_GOT16_LO_DS
:
5912 struct got_entry
*ent
;
5917 ent
= local_got_ents
[r_symndx
];
5919 for (; ent
!= NULL
; ent
= ent
->next
)
5920 if (ent
->addend
== rel
->r_addend
5921 && ent
->owner
== abfd
5922 && ent
->tls_type
== tls_type
)
5926 if (ent
->got
.refcount
> 0)
5927 ent
->got
.refcount
-= 1;
5931 case R_PPC64_PLT16_HA
:
5932 case R_PPC64_PLT16_HI
:
5933 case R_PPC64_PLT16_LO
:
5937 case R_PPC64_REL14_BRNTAKEN
:
5938 case R_PPC64_REL14_BRTAKEN
:
5942 struct plt_entry
*ent
;
5944 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5945 if (ent
->addend
== rel
->r_addend
)
5947 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
5948 ent
->plt
.refcount
-= 1;
5959 /* The maximum size of .sfpr. */
5960 #define SFPR_MAX (218*4)
5962 struct sfpr_def_parms
5964 const char name
[12];
5965 unsigned char lo
, hi
;
5966 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5967 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5970 /* Auto-generate _save*, _rest* functions in .sfpr. */
5973 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5975 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5977 size_t len
= strlen (parm
->name
);
5978 bfd_boolean writing
= FALSE
;
5984 memcpy (sym
, parm
->name
, len
);
5987 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5989 struct elf_link_hash_entry
*h
;
5991 sym
[len
+ 0] = i
/ 10 + '0';
5992 sym
[len
+ 1] = i
% 10 + '0';
5993 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5997 h
->root
.type
= bfd_link_hash_defined
;
5998 h
->root
.u
.def
.section
= htab
->sfpr
;
5999 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
6002 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
6004 if (htab
->sfpr
->contents
== NULL
)
6006 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6007 if (htab
->sfpr
->contents
== NULL
)
6013 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6015 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6017 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6018 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6026 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6028 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6033 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6035 p
= savegpr0 (abfd
, p
, r
);
6036 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6038 bfd_put_32 (abfd
, BLR
, p
);
6043 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6045 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6050 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6052 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6054 p
= restgpr0 (abfd
, p
, r
);
6055 bfd_put_32 (abfd
, MTLR_R0
, p
);
6059 p
= restgpr0 (abfd
, p
, 30);
6060 p
= restgpr0 (abfd
, p
, 31);
6062 bfd_put_32 (abfd
, BLR
, p
);
6067 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6069 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6074 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6076 p
= savegpr1 (abfd
, p
, r
);
6077 bfd_put_32 (abfd
, BLR
, p
);
6082 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6084 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6089 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6091 p
= restgpr1 (abfd
, p
, r
);
6092 bfd_put_32 (abfd
, BLR
, p
);
6097 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6099 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6104 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6106 p
= savefpr (abfd
, p
, r
);
6107 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6109 bfd_put_32 (abfd
, BLR
, p
);
6114 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6116 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6121 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6123 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6125 p
= restfpr (abfd
, p
, r
);
6126 bfd_put_32 (abfd
, MTLR_R0
, p
);
6130 p
= restfpr (abfd
, p
, 30);
6131 p
= restfpr (abfd
, p
, 31);
6133 bfd_put_32 (abfd
, BLR
, p
);
6138 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6140 p
= savefpr (abfd
, p
, r
);
6141 bfd_put_32 (abfd
, BLR
, p
);
6146 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6148 p
= restfpr (abfd
, p
, r
);
6149 bfd_put_32 (abfd
, BLR
, p
);
6154 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6156 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6158 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6163 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6165 p
= savevr (abfd
, p
, r
);
6166 bfd_put_32 (abfd
, BLR
, p
);
6171 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6173 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6175 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6180 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6182 p
= restvr (abfd
, p
, r
);
6183 bfd_put_32 (abfd
, BLR
, p
);
6187 /* Called via elf_link_hash_traverse to transfer dynamic linking
6188 information on function code symbol entries to their corresponding
6189 function descriptor symbol entries. */
6192 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6194 struct bfd_link_info
*info
;
6195 struct ppc_link_hash_table
*htab
;
6196 struct plt_entry
*ent
;
6197 struct ppc_link_hash_entry
*fh
;
6198 struct ppc_link_hash_entry
*fdh
;
6199 bfd_boolean force_local
;
6201 fh
= (struct ppc_link_hash_entry
*) h
;
6202 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6206 htab
= ppc_hash_table (info
);
6210 /* Resolve undefined references to dot-symbols as the value
6211 in the function descriptor, if we have one in a regular object.
6212 This is to satisfy cases like ".quad .foo". Calls to functions
6213 in dynamic objects are handled elsewhere. */
6214 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
6215 && fh
->was_undefined
6216 && (fdh
= defined_func_desc (fh
)) != NULL
6217 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6218 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6219 fdh
->elf
.root
.u
.def
.value
,
6220 &fh
->elf
.root
.u
.def
.section
,
6221 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
6223 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6224 fh
->elf
.forced_local
= 1;
6225 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6226 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6229 /* If this is a function code symbol, transfer dynamic linking
6230 information to the function descriptor symbol. */
6234 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6235 if (ent
->plt
.refcount
> 0)
6238 || fh
->elf
.root
.root
.string
[0] != '.'
6239 || fh
->elf
.root
.root
.string
[1] == '\0')
6242 /* Find the corresponding function descriptor symbol. Create it
6243 as undefined if necessary. */
6245 fdh
= lookup_fdh (fh
, htab
);
6247 && !info
->executable
6248 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6249 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6251 fdh
= make_fdh (info
, fh
);
6256 /* Fake function descriptors are made undefweak. If the function
6257 code symbol is strong undefined, make the fake sym the same.
6258 If the function code symbol is defined, then force the fake
6259 descriptor local; We can't support overriding of symbols in a
6260 shared library on a fake descriptor. */
6264 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6266 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
6268 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
6269 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
6271 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
6272 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6274 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6279 && !fdh
->elf
.forced_local
6280 && (!info
->executable
6281 || fdh
->elf
.def_dynamic
6282 || fdh
->elf
.ref_dynamic
6283 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
6284 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
6286 if (fdh
->elf
.dynindx
== -1)
6287 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6289 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6290 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6291 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6292 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6293 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
6295 move_plt_plist (fh
, fdh
);
6296 fdh
->elf
.needs_plt
= 1;
6298 fdh
->is_func_descriptor
= 1;
6303 /* Now that the info is on the function descriptor, clear the
6304 function code sym info. Any function code syms for which we
6305 don't have a definition in a regular file, we force local.
6306 This prevents a shared library from exporting syms that have
6307 been imported from another library. Function code syms that
6308 are really in the library we must leave global to prevent the
6309 linker dragging in a definition from a static library. */
6310 force_local
= (!fh
->elf
.def_regular
6312 || !fdh
->elf
.def_regular
6313 || fdh
->elf
.forced_local
);
6314 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6319 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6320 this hook to a) provide some gcc support functions, and b) transfer
6321 dynamic linking information gathered so far on function code symbol
6322 entries, to their corresponding function descriptor symbol entries. */
6325 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6326 struct bfd_link_info
*info
)
6328 struct ppc_link_hash_table
*htab
;
6330 const struct sfpr_def_parms funcs
[] =
6332 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6333 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6334 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6335 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6336 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6337 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6338 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6339 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6340 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6341 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6342 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6343 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6346 htab
= ppc_hash_table (info
);
6350 if (htab
->sfpr
== NULL
)
6351 /* We don't have any relocs. */
6354 /* Provide any missing _save* and _rest* functions. */
6355 htab
->sfpr
->size
= 0;
6356 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
6357 if (!sfpr_define (info
, &funcs
[i
]))
6360 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6362 if (htab
->sfpr
->size
== 0)
6363 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6368 /* Adjust a symbol defined by a dynamic object and referenced by a
6369 regular object. The current definition is in some section of the
6370 dynamic object, but we're not including those sections. We have to
6371 change the definition to something the rest of the link can
6375 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6376 struct elf_link_hash_entry
*h
)
6378 struct ppc_link_hash_table
*htab
;
6381 htab
= ppc_hash_table (info
);
6385 /* Deal with function syms. */
6386 if (h
->type
== STT_FUNC
6387 || h
->type
== STT_GNU_IFUNC
6390 /* Clear procedure linkage table information for any symbol that
6391 won't need a .plt entry. */
6392 struct plt_entry
*ent
;
6393 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6394 if (ent
->plt
.refcount
> 0)
6397 || (h
->type
!= STT_GNU_IFUNC
6398 && (SYMBOL_CALLS_LOCAL (info
, h
)
6399 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6400 && h
->root
.type
== bfd_link_hash_undefweak
))))
6402 h
->plt
.plist
= NULL
;
6407 h
->plt
.plist
= NULL
;
6409 /* If this is a weak symbol, and there is a real definition, the
6410 processor independent code will have arranged for us to see the
6411 real definition first, and we can just use the same value. */
6412 if (h
->u
.weakdef
!= NULL
)
6414 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6415 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6416 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6417 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6418 if (ELIMINATE_COPY_RELOCS
)
6419 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6423 /* If we are creating a shared library, we must presume that the
6424 only references to the symbol are via the global offset table.
6425 For such cases we need not do anything here; the relocations will
6426 be handled correctly by relocate_section. */
6430 /* If there are no references to this symbol that do not use the
6431 GOT, we don't need to generate a copy reloc. */
6432 if (!h
->non_got_ref
)
6435 /* Don't generate a copy reloc for symbols defined in the executable. */
6436 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
6439 if (ELIMINATE_COPY_RELOCS
)
6441 struct ppc_link_hash_entry
* eh
;
6442 struct elf_dyn_relocs
*p
;
6444 eh
= (struct ppc_link_hash_entry
*) h
;
6445 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6447 s
= p
->sec
->output_section
;
6448 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6452 /* If we didn't find any dynamic relocs in read-only sections, then
6453 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6461 if (h
->plt
.plist
!= NULL
)
6463 /* We should never get here, but unfortunately there are versions
6464 of gcc out there that improperly (for this ABI) put initialized
6465 function pointers, vtable refs and suchlike in read-only
6466 sections. Allow them to proceed, but warn that this might
6467 break at runtime. */
6468 info
->callbacks
->einfo
6469 (_("%P: copy reloc against `%s' requires lazy plt linking; "
6470 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6471 h
->root
.root
.string
);
6474 /* This is a reference to a symbol defined by a dynamic object which
6475 is not a function. */
6479 info
->callbacks
->einfo (_("%P: dynamic variable `%s' is zero size\n"),
6480 h
->root
.root
.string
);
6484 /* We must allocate the symbol in our .dynbss section, which will
6485 become part of the .bss section of the executable. There will be
6486 an entry for this symbol in the .dynsym section. The dynamic
6487 object will contain position independent code, so all references
6488 from the dynamic object to this symbol will go through the global
6489 offset table. The dynamic linker will use the .dynsym entry to
6490 determine the address it must put in the global offset table, so
6491 both the dynamic object and the regular object will refer to the
6492 same memory location for the variable. */
6494 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6495 to copy the initial value out of the dynamic object and into the
6496 runtime process image. We need to remember the offset into the
6497 .rela.bss section we are going to use. */
6498 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6500 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
6506 return _bfd_elf_adjust_dynamic_copy (h
, s
);
6509 /* If given a function descriptor symbol, hide both the function code
6510 sym and the descriptor. */
6512 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6513 struct elf_link_hash_entry
*h
,
6514 bfd_boolean force_local
)
6516 struct ppc_link_hash_entry
*eh
;
6517 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6519 eh
= (struct ppc_link_hash_entry
*) h
;
6520 if (eh
->is_func_descriptor
)
6522 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6527 struct ppc_link_hash_table
*htab
;
6530 /* We aren't supposed to use alloca in BFD because on
6531 systems which do not have alloca the version in libiberty
6532 calls xmalloc, which might cause the program to crash
6533 when it runs out of memory. This function doesn't have a
6534 return status, so there's no way to gracefully return an
6535 error. So cheat. We know that string[-1] can be safely
6536 accessed; It's either a string in an ELF string table,
6537 or allocated in an objalloc structure. */
6539 p
= eh
->elf
.root
.root
.string
- 1;
6542 htab
= ppc_hash_table (info
);
6546 fh
= (struct ppc_link_hash_entry
*)
6547 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6550 /* Unfortunately, if it so happens that the string we were
6551 looking for was allocated immediately before this string,
6552 then we overwrote the string terminator. That's the only
6553 reason the lookup should fail. */
6556 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6557 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6559 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6560 fh
= (struct ppc_link_hash_entry
*)
6561 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6570 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6575 get_sym_h (struct elf_link_hash_entry
**hp
,
6576 Elf_Internal_Sym
**symp
,
6578 unsigned char **tls_maskp
,
6579 Elf_Internal_Sym
**locsymsp
,
6580 unsigned long r_symndx
,
6583 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6585 if (r_symndx
>= symtab_hdr
->sh_info
)
6587 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6588 struct elf_link_hash_entry
*h
;
6590 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6591 h
= elf_follow_link (h
);
6599 if (symsecp
!= NULL
)
6601 asection
*symsec
= NULL
;
6602 if (h
->root
.type
== bfd_link_hash_defined
6603 || h
->root
.type
== bfd_link_hash_defweak
)
6604 symsec
= h
->root
.u
.def
.section
;
6608 if (tls_maskp
!= NULL
)
6610 struct ppc_link_hash_entry
*eh
;
6612 eh
= (struct ppc_link_hash_entry
*) h
;
6613 *tls_maskp
= &eh
->tls_mask
;
6618 Elf_Internal_Sym
*sym
;
6619 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6621 if (locsyms
== NULL
)
6623 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6624 if (locsyms
== NULL
)
6625 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6626 symtab_hdr
->sh_info
,
6627 0, NULL
, NULL
, NULL
);
6628 if (locsyms
== NULL
)
6630 *locsymsp
= locsyms
;
6632 sym
= locsyms
+ r_symndx
;
6640 if (symsecp
!= NULL
)
6641 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6643 if (tls_maskp
!= NULL
)
6645 struct got_entry
**lgot_ents
;
6646 unsigned char *tls_mask
;
6649 lgot_ents
= elf_local_got_ents (ibfd
);
6650 if (lgot_ents
!= NULL
)
6652 struct plt_entry
**local_plt
= (struct plt_entry
**)
6653 (lgot_ents
+ symtab_hdr
->sh_info
);
6654 unsigned char *lgot_masks
= (unsigned char *)
6655 (local_plt
+ symtab_hdr
->sh_info
);
6656 tls_mask
= &lgot_masks
[r_symndx
];
6658 *tls_maskp
= tls_mask
;
6664 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6665 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6666 type suitable for optimization, and 1 otherwise. */
6669 get_tls_mask (unsigned char **tls_maskp
,
6670 unsigned long *toc_symndx
,
6671 bfd_vma
*toc_addend
,
6672 Elf_Internal_Sym
**locsymsp
,
6673 const Elf_Internal_Rela
*rel
,
6676 unsigned long r_symndx
;
6678 struct elf_link_hash_entry
*h
;
6679 Elf_Internal_Sym
*sym
;
6683 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6684 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6687 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6689 || ppc64_elf_section_data (sec
) == NULL
6690 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6693 /* Look inside a TOC section too. */
6696 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6697 off
= h
->root
.u
.def
.value
;
6700 off
= sym
->st_value
;
6701 off
+= rel
->r_addend
;
6702 BFD_ASSERT (off
% 8 == 0);
6703 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6704 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6705 if (toc_symndx
!= NULL
)
6706 *toc_symndx
= r_symndx
;
6707 if (toc_addend
!= NULL
)
6708 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6709 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6711 if ((h
== NULL
|| is_static_defined (h
))
6712 && (next_r
== -1 || next_r
== -2))
6717 /* Adjust all global syms defined in opd sections. In gcc generated
6718 code for the old ABI, these will already have been done. */
6721 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6723 struct ppc_link_hash_entry
*eh
;
6725 struct _opd_sec_data
*opd
;
6727 if (h
->root
.type
== bfd_link_hash_indirect
)
6730 if (h
->root
.type
!= bfd_link_hash_defined
6731 && h
->root
.type
!= bfd_link_hash_defweak
)
6734 eh
= (struct ppc_link_hash_entry
*) h
;
6735 if (eh
->adjust_done
)
6738 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6739 opd
= get_opd_info (sym_sec
);
6740 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6742 long adjust
= opd
->adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6745 /* This entry has been deleted. */
6746 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6749 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6750 if (elf_discarded_section (dsec
))
6752 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6756 eh
->elf
.root
.u
.def
.value
= 0;
6757 eh
->elf
.root
.u
.def
.section
= dsec
;
6760 eh
->elf
.root
.u
.def
.value
+= adjust
;
6761 eh
->adjust_done
= 1;
6766 /* Handles decrementing dynamic reloc counts for the reloc specified by
6767 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6768 have already been determined. */
6771 dec_dynrel_count (bfd_vma r_info
,
6773 struct bfd_link_info
*info
,
6774 Elf_Internal_Sym
**local_syms
,
6775 struct elf_link_hash_entry
*h
,
6778 enum elf_ppc64_reloc_type r_type
;
6779 struct elf_dyn_relocs
*p
;
6780 struct elf_dyn_relocs
**pp
;
6782 /* Can this reloc be dynamic? This switch, and later tests here
6783 should be kept in sync with the code in check_relocs. */
6784 r_type
= ELF64_R_TYPE (r_info
);
6790 case R_PPC64_TPREL16
:
6791 case R_PPC64_TPREL16_LO
:
6792 case R_PPC64_TPREL16_HI
:
6793 case R_PPC64_TPREL16_HA
:
6794 case R_PPC64_TPREL16_DS
:
6795 case R_PPC64_TPREL16_LO_DS
:
6796 case R_PPC64_TPREL16_HIGHER
:
6797 case R_PPC64_TPREL16_HIGHERA
:
6798 case R_PPC64_TPREL16_HIGHEST
:
6799 case R_PPC64_TPREL16_HIGHESTA
:
6803 case R_PPC64_TPREL64
:
6804 case R_PPC64_DTPMOD64
:
6805 case R_PPC64_DTPREL64
:
6806 case R_PPC64_ADDR64
:
6810 case R_PPC64_ADDR14
:
6811 case R_PPC64_ADDR14_BRNTAKEN
:
6812 case R_PPC64_ADDR14_BRTAKEN
:
6813 case R_PPC64_ADDR16
:
6814 case R_PPC64_ADDR16_DS
:
6815 case R_PPC64_ADDR16_HA
:
6816 case R_PPC64_ADDR16_HI
:
6817 case R_PPC64_ADDR16_HIGHER
:
6818 case R_PPC64_ADDR16_HIGHERA
:
6819 case R_PPC64_ADDR16_HIGHEST
:
6820 case R_PPC64_ADDR16_HIGHESTA
:
6821 case R_PPC64_ADDR16_LO
:
6822 case R_PPC64_ADDR16_LO_DS
:
6823 case R_PPC64_ADDR24
:
6824 case R_PPC64_ADDR32
:
6825 case R_PPC64_UADDR16
:
6826 case R_PPC64_UADDR32
:
6827 case R_PPC64_UADDR64
:
6832 if (local_syms
!= NULL
)
6834 unsigned long r_symndx
;
6835 Elf_Internal_Sym
*sym
;
6836 bfd
*ibfd
= sec
->owner
;
6838 r_symndx
= ELF64_R_SYM (r_info
);
6839 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6844 && (must_be_dyn_reloc (info
, r_type
)
6847 || h
->root
.type
== bfd_link_hash_defweak
6848 || !h
->def_regular
))))
6849 || (ELIMINATE_COPY_RELOCS
6852 && (h
->root
.type
== bfd_link_hash_defweak
6853 || !h
->def_regular
)))
6859 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6862 if (sym_sec
!= NULL
)
6864 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6865 pp
= (struct elf_dyn_relocs
**) vpp
;
6869 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6870 pp
= (struct elf_dyn_relocs
**) vpp
;
6873 /* elf_gc_sweep may have already removed all dyn relocs associated
6874 with local syms for a given section. Don't report a dynreloc
6880 while ((p
= *pp
) != NULL
)
6884 if (!must_be_dyn_reloc (info
, r_type
))
6894 info
->callbacks
->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
6896 bfd_set_error (bfd_error_bad_value
);
6900 /* Remove unused Official Procedure Descriptor entries. Currently we
6901 only remove those associated with functions in discarded link-once
6902 sections, or weakly defined functions that have been overridden. It
6903 would be possible to remove many more entries for statically linked
6907 ppc64_elf_edit_opd (struct bfd_link_info
*info
, bfd_boolean non_overlapping
)
6910 bfd_boolean some_edited
= FALSE
;
6911 asection
*need_pad
= NULL
;
6913 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6916 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6917 Elf_Internal_Shdr
*symtab_hdr
;
6918 Elf_Internal_Sym
*local_syms
;
6920 struct _opd_sec_data
*opd
;
6921 bfd_boolean need_edit
, add_aux_fields
;
6922 bfd_size_type cnt_16b
= 0;
6924 if (!is_ppc64_elf (ibfd
))
6927 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6928 if (sec
== NULL
|| sec
->size
== 0)
6931 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6934 if (sec
->output_section
== bfd_abs_section_ptr
)
6937 /* Look through the section relocs. */
6938 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6942 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6944 /* Read the relocations. */
6945 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6947 if (relstart
== NULL
)
6950 /* First run through the relocs to check they are sane, and to
6951 determine whether we need to edit this opd section. */
6955 relend
= relstart
+ sec
->reloc_count
;
6956 for (rel
= relstart
; rel
< relend
; )
6958 enum elf_ppc64_reloc_type r_type
;
6959 unsigned long r_symndx
;
6961 struct elf_link_hash_entry
*h
;
6962 Elf_Internal_Sym
*sym
;
6964 /* .opd contains a regular array of 16 or 24 byte entries. We're
6965 only interested in the reloc pointing to a function entry
6967 if (rel
->r_offset
!= offset
6968 || rel
+ 1 >= relend
6969 || (rel
+ 1)->r_offset
!= offset
+ 8)
6971 /* If someone messes with .opd alignment then after a
6972 "ld -r" we might have padding in the middle of .opd.
6973 Also, there's nothing to prevent someone putting
6974 something silly in .opd with the assembler. No .opd
6975 optimization for them! */
6977 (*_bfd_error_handler
)
6978 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6983 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6984 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6986 (*_bfd_error_handler
)
6987 (_("%B: unexpected reloc type %u in .opd section"),
6993 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6994 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6998 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7000 const char *sym_name
;
7002 sym_name
= h
->root
.root
.string
;
7004 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7007 (*_bfd_error_handler
)
7008 (_("%B: undefined sym `%s' in .opd section"),
7014 /* opd entries are always for functions defined in the
7015 current input bfd. If the symbol isn't defined in the
7016 input bfd, then we won't be using the function in this
7017 bfd; It must be defined in a linkonce section in another
7018 bfd, or is weak. It's also possible that we are
7019 discarding the function due to a linker script /DISCARD/,
7020 which we test for via the output_section. */
7021 if (sym_sec
->owner
!= ibfd
7022 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7027 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
7029 if (sec
->size
== offset
+ 24)
7034 if (rel
== relend
&& sec
->size
== offset
+ 16)
7042 if (rel
->r_offset
== offset
+ 24)
7044 else if (rel
->r_offset
!= offset
+ 16)
7046 else if (rel
+ 1 < relend
7047 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7048 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7053 else if (rel
+ 2 < relend
7054 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
7055 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
7064 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
7066 if (need_edit
|| add_aux_fields
)
7068 Elf_Internal_Rela
*write_rel
;
7069 Elf_Internal_Shdr
*rel_hdr
;
7070 bfd_byte
*rptr
, *wptr
;
7071 bfd_byte
*new_contents
;
7076 new_contents
= NULL
;
7077 amt
= sec
->size
* sizeof (long) / 8;
7078 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7079 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7080 if (opd
->adjust
== NULL
)
7082 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
7084 /* This seems a waste of time as input .opd sections are all
7085 zeros as generated by gcc, but I suppose there's no reason
7086 this will always be so. We might start putting something in
7087 the third word of .opd entries. */
7088 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7091 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7096 if (local_syms
!= NULL
7097 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7099 if (elf_section_data (sec
)->relocs
!= relstart
)
7103 sec
->contents
= loc
;
7104 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7107 elf_section_data (sec
)->relocs
= relstart
;
7109 new_contents
= sec
->contents
;
7112 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7113 if (new_contents
== NULL
)
7117 wptr
= new_contents
;
7118 rptr
= sec
->contents
;
7120 write_rel
= relstart
;
7124 for (rel
= relstart
; rel
< relend
; rel
++)
7126 unsigned long r_symndx
;
7128 struct elf_link_hash_entry
*h
;
7129 Elf_Internal_Sym
*sym
;
7131 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7132 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7136 if (rel
->r_offset
== offset
)
7138 struct ppc_link_hash_entry
*fdh
= NULL
;
7140 /* See if the .opd entry is full 24 byte or
7141 16 byte (with fd_aux entry overlapped with next
7144 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
7145 || (rel
+ 3 < relend
7146 && rel
[2].r_offset
== offset
+ 16
7147 && rel
[3].r_offset
== offset
+ 24
7148 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
7149 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
7153 && h
->root
.root
.string
[0] == '.')
7155 struct ppc_link_hash_table
*htab
;
7157 htab
= ppc_hash_table (info
);
7159 fdh
= lookup_fdh ((struct ppc_link_hash_entry
*) h
,
7162 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
7163 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7167 skip
= (sym_sec
->owner
!= ibfd
7168 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7171 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7173 /* Arrange for the function descriptor sym
7175 fdh
->elf
.root
.u
.def
.value
= 0;
7176 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7178 opd
->adjust
[rel
->r_offset
/ 8] = -1;
7182 /* We'll be keeping this opd entry. */
7186 /* Redefine the function descriptor symbol to
7187 this location in the opd section. It is
7188 necessary to update the value here rather
7189 than using an array of adjustments as we do
7190 for local symbols, because various places
7191 in the generic ELF code use the value
7192 stored in u.def.value. */
7193 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7194 fdh
->adjust_done
= 1;
7197 /* Local syms are a bit tricky. We could
7198 tweak them as they can be cached, but
7199 we'd need to look through the local syms
7200 for the function descriptor sym which we
7201 don't have at the moment. So keep an
7202 array of adjustments. */
7203 opd
->adjust
[rel
->r_offset
/ 8]
7204 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
7207 memcpy (wptr
, rptr
, opd_ent_size
);
7208 wptr
+= opd_ent_size
;
7209 if (add_aux_fields
&& opd_ent_size
== 16)
7211 memset (wptr
, '\0', 8);
7215 rptr
+= opd_ent_size
;
7216 offset
+= opd_ent_size
;
7222 && !info
->relocatable
7223 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
7229 /* We need to adjust any reloc offsets to point to the
7230 new opd entries. While we're at it, we may as well
7231 remove redundant relocs. */
7232 rel
->r_offset
+= opd
->adjust
[(offset
- opd_ent_size
) / 8];
7233 if (write_rel
!= rel
)
7234 memcpy (write_rel
, rel
, sizeof (*rel
));
7239 sec
->size
= wptr
- new_contents
;
7240 sec
->reloc_count
= write_rel
- relstart
;
7243 free (sec
->contents
);
7244 sec
->contents
= new_contents
;
7247 /* Fudge the header size too, as this is used later in
7248 elf_bfd_final_link if we are emitting relocs. */
7249 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7250 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7253 else if (elf_section_data (sec
)->relocs
!= relstart
)
7256 if (local_syms
!= NULL
7257 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7259 if (!info
->keep_memory
)
7262 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7267 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7269 /* If we are doing a final link and the last .opd entry is just 16 byte
7270 long, add a 8 byte padding after it. */
7271 if (need_pad
!= NULL
&& !info
->relocatable
)
7275 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7277 BFD_ASSERT (need_pad
->size
> 0);
7279 p
= bfd_malloc (need_pad
->size
+ 8);
7283 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
7284 p
, 0, need_pad
->size
))
7287 need_pad
->contents
= p
;
7288 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7292 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7296 need_pad
->contents
= p
;
7299 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7300 need_pad
->size
+= 8;
7306 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7309 ppc64_elf_tls_setup (struct bfd_link_info
*info
,
7310 int no_tls_get_addr_opt
,
7313 struct ppc_link_hash_table
*htab
;
7315 htab
= ppc_hash_table (info
);
7320 htab
->do_multi_toc
= 0;
7321 else if (!htab
->do_multi_toc
)
7324 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7325 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7326 FALSE
, FALSE
, TRUE
));
7327 /* Move dynamic linking info to the function descriptor sym. */
7328 if (htab
->tls_get_addr
!= NULL
)
7329 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7330 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7331 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7332 FALSE
, FALSE
, TRUE
));
7333 if (!no_tls_get_addr_opt
)
7335 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7337 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7338 FALSE
, FALSE
, TRUE
);
7340 func_desc_adjust (opt
, info
);
7341 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7342 FALSE
, FALSE
, TRUE
);
7344 && (opt_fd
->root
.type
== bfd_link_hash_defined
7345 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7347 /* If glibc supports an optimized __tls_get_addr call stub,
7348 signalled by the presence of __tls_get_addr_opt, and we'll
7349 be calling __tls_get_addr via a plt call stub, then
7350 make __tls_get_addr point to __tls_get_addr_opt. */
7351 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7352 if (htab
->elf
.dynamic_sections_created
7354 && (tga_fd
->type
== STT_FUNC
7355 || tga_fd
->needs_plt
)
7356 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7357 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
7358 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
7360 struct plt_entry
*ent
;
7362 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7363 if (ent
->plt
.refcount
> 0)
7367 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7368 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7369 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7370 if (opt_fd
->dynindx
!= -1)
7372 /* Use __tls_get_addr_opt in dynamic relocations. */
7373 opt_fd
->dynindx
= -1;
7374 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7375 opt_fd
->dynstr_index
);
7376 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7379 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
7380 tga
= &htab
->tls_get_addr
->elf
;
7381 if (opt
!= NULL
&& tga
!= NULL
)
7383 tga
->root
.type
= bfd_link_hash_indirect
;
7384 tga
->root
.u
.i
.link
= &opt
->root
;
7385 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7386 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7388 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7390 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7391 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7392 if (htab
->tls_get_addr
!= NULL
)
7394 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7395 htab
->tls_get_addr
->is_func
= 1;
7401 no_tls_get_addr_opt
= TRUE
;
7403 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
7404 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7407 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7411 branch_reloc_hash_match (const bfd
*ibfd
,
7412 const Elf_Internal_Rela
*rel
,
7413 const struct ppc_link_hash_entry
*hash1
,
7414 const struct ppc_link_hash_entry
*hash2
)
7416 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7417 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7418 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7420 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7422 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7423 struct elf_link_hash_entry
*h
;
7425 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7426 h
= elf_follow_link (h
);
7427 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7433 /* Run through all the TLS relocs looking for optimization
7434 opportunities. The linker has been hacked (see ppc64elf.em) to do
7435 a preliminary section layout so that we know the TLS segment
7436 offsets. We can't optimize earlier because some optimizations need
7437 to know the tp offset, and we need to optimize before allocating
7438 dynamic relocations. */
7441 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7445 struct ppc_link_hash_table
*htab
;
7446 unsigned char *toc_ref
;
7449 if (info
->relocatable
|| !info
->executable
)
7452 htab
= ppc_hash_table (info
);
7456 /* Make two passes over the relocs. On the first pass, mark toc
7457 entries involved with tls relocs, and check that tls relocs
7458 involved in setting up a tls_get_addr call are indeed followed by
7459 such a call. If they are not, we can't do any tls optimization.
7460 On the second pass twiddle tls_mask flags to notify
7461 relocate_section that optimization can be done, and adjust got
7462 and plt refcounts. */
7464 for (pass
= 0; pass
< 2; ++pass
)
7465 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7467 Elf_Internal_Sym
*locsyms
= NULL
;
7468 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7470 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7471 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7473 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7474 bfd_boolean found_tls_get_addr_arg
= 0;
7476 /* Read the relocations. */
7477 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7479 if (relstart
== NULL
)
7482 relend
= relstart
+ sec
->reloc_count
;
7483 for (rel
= relstart
; rel
< relend
; rel
++)
7485 enum elf_ppc64_reloc_type r_type
;
7486 unsigned long r_symndx
;
7487 struct elf_link_hash_entry
*h
;
7488 Elf_Internal_Sym
*sym
;
7490 unsigned char *tls_mask
;
7491 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7493 bfd_boolean ok_tprel
, is_local
;
7494 long toc_ref_index
= 0;
7495 int expecting_tls_get_addr
= 0;
7496 bfd_boolean ret
= FALSE
;
7498 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7499 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7503 if (elf_section_data (sec
)->relocs
!= relstart
)
7505 if (toc_ref
!= NULL
)
7508 && (elf_symtab_hdr (ibfd
).contents
7509 != (unsigned char *) locsyms
))
7516 if (h
->root
.type
== bfd_link_hash_defined
7517 || h
->root
.type
== bfd_link_hash_defweak
)
7518 value
= h
->root
.u
.def
.value
;
7519 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7523 found_tls_get_addr_arg
= 0;
7528 /* Symbols referenced by TLS relocs must be of type
7529 STT_TLS. So no need for .opd local sym adjust. */
7530 value
= sym
->st_value
;
7539 && h
->root
.type
== bfd_link_hash_undefweak
)
7543 value
+= sym_sec
->output_offset
;
7544 value
+= sym_sec
->output_section
->vma
;
7545 value
-= htab
->elf
.tls_sec
->vma
;
7546 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7547 < (bfd_vma
) 1 << 32);
7551 r_type
= ELF64_R_TYPE (rel
->r_info
);
7552 /* If this section has old-style __tls_get_addr calls
7553 without marker relocs, then check that each
7554 __tls_get_addr call reloc is preceded by a reloc
7555 that conceivably belongs to the __tls_get_addr arg
7556 setup insn. If we don't find matching arg setup
7557 relocs, don't do any tls optimization. */
7559 && sec
->has_tls_get_addr_call
7561 && (h
== &htab
->tls_get_addr
->elf
7562 || h
== &htab
->tls_get_addr_fd
->elf
)
7563 && !found_tls_get_addr_arg
7564 && is_branch_reloc (r_type
))
7566 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7567 "TLS optimization disabled\n"),
7568 ibfd
, sec
, rel
->r_offset
);
7573 found_tls_get_addr_arg
= 0;
7576 case R_PPC64_GOT_TLSLD16
:
7577 case R_PPC64_GOT_TLSLD16_LO
:
7578 expecting_tls_get_addr
= 1;
7579 found_tls_get_addr_arg
= 1;
7582 case R_PPC64_GOT_TLSLD16_HI
:
7583 case R_PPC64_GOT_TLSLD16_HA
:
7584 /* These relocs should never be against a symbol
7585 defined in a shared lib. Leave them alone if
7586 that turns out to be the case. */
7593 tls_type
= TLS_TLS
| TLS_LD
;
7596 case R_PPC64_GOT_TLSGD16
:
7597 case R_PPC64_GOT_TLSGD16_LO
:
7598 expecting_tls_get_addr
= 1;
7599 found_tls_get_addr_arg
= 1;
7602 case R_PPC64_GOT_TLSGD16_HI
:
7603 case R_PPC64_GOT_TLSGD16_HA
:
7609 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7611 tls_type
= TLS_TLS
| TLS_GD
;
7614 case R_PPC64_GOT_TPREL16_DS
:
7615 case R_PPC64_GOT_TPREL16_LO_DS
:
7616 case R_PPC64_GOT_TPREL16_HI
:
7617 case R_PPC64_GOT_TPREL16_HA
:
7622 tls_clear
= TLS_TPREL
;
7623 tls_type
= TLS_TLS
| TLS_TPREL
;
7630 found_tls_get_addr_arg
= 1;
7635 case R_PPC64_TOC16_LO
:
7636 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7639 /* Mark this toc entry as referenced by a TLS
7640 code sequence. We can do that now in the
7641 case of R_PPC64_TLS, and after checking for
7642 tls_get_addr for the TOC16 relocs. */
7643 if (toc_ref
== NULL
)
7644 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7645 if (toc_ref
== NULL
)
7649 value
= h
->root
.u
.def
.value
;
7651 value
= sym
->st_value
;
7652 value
+= rel
->r_addend
;
7653 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
7654 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7655 if (r_type
== R_PPC64_TLS
7656 || r_type
== R_PPC64_TLSGD
7657 || r_type
== R_PPC64_TLSLD
)
7659 toc_ref
[toc_ref_index
] = 1;
7663 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7668 expecting_tls_get_addr
= 2;
7671 case R_PPC64_TPREL64
:
7675 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7680 tls_set
= TLS_EXPLICIT
;
7681 tls_clear
= TLS_TPREL
;
7686 case R_PPC64_DTPMOD64
:
7690 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7692 if (rel
+ 1 < relend
7694 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7695 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7699 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7702 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7711 tls_set
= TLS_EXPLICIT
;
7722 if (!expecting_tls_get_addr
7723 || !sec
->has_tls_get_addr_call
)
7726 if (rel
+ 1 < relend
7727 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7729 htab
->tls_get_addr_fd
))
7731 if (expecting_tls_get_addr
== 2)
7733 /* Check for toc tls entries. */
7734 unsigned char *toc_tls
;
7737 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7742 if (toc_tls
!= NULL
)
7744 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
7745 found_tls_get_addr_arg
= 1;
7747 toc_ref
[toc_ref_index
] = 1;
7753 if (expecting_tls_get_addr
!= 1)
7756 /* Uh oh, we didn't find the expected call. We
7757 could just mark this symbol to exclude it
7758 from tls optimization but it's safer to skip
7759 the entire optimization. */
7760 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7761 "TLS optimization disabled\n"),
7762 ibfd
, sec
, rel
->r_offset
);
7767 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
7769 struct plt_entry
*ent
;
7770 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7773 if (ent
->addend
== 0)
7775 if (ent
->plt
.refcount
> 0)
7777 ent
->plt
.refcount
-= 1;
7778 expecting_tls_get_addr
= 0;
7784 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
7786 struct plt_entry
*ent
;
7787 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7790 if (ent
->addend
== 0)
7792 if (ent
->plt
.refcount
> 0)
7793 ent
->plt
.refcount
-= 1;
7801 if ((tls_set
& TLS_EXPLICIT
) == 0)
7803 struct got_entry
*ent
;
7805 /* Adjust got entry for this reloc. */
7809 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7811 for (; ent
!= NULL
; ent
= ent
->next
)
7812 if (ent
->addend
== rel
->r_addend
7813 && ent
->owner
== ibfd
7814 && ent
->tls_type
== tls_type
)
7821 /* We managed to get rid of a got entry. */
7822 if (ent
->got
.refcount
> 0)
7823 ent
->got
.refcount
-= 1;
7828 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7829 we'll lose one or two dyn relocs. */
7830 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7834 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7836 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7842 *tls_mask
|= tls_set
;
7843 *tls_mask
&= ~tls_clear
;
7846 if (elf_section_data (sec
)->relocs
!= relstart
)
7851 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7853 if (!info
->keep_memory
)
7856 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7860 if (toc_ref
!= NULL
)
7865 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7866 the values of any global symbols in a toc section that has been
7867 edited. Globals in toc sections should be a rarity, so this function
7868 sets a flag if any are found in toc sections other than the one just
7869 edited, so that futher hash table traversals can be avoided. */
7871 struct adjust_toc_info
7874 unsigned long *skip
;
7875 bfd_boolean global_toc_syms
;
7878 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7881 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7883 struct ppc_link_hash_entry
*eh
;
7884 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7887 if (h
->root
.type
!= bfd_link_hash_defined
7888 && h
->root
.type
!= bfd_link_hash_defweak
)
7891 eh
= (struct ppc_link_hash_entry
*) h
;
7892 if (eh
->adjust_done
)
7895 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7897 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7898 i
= toc_inf
->toc
->rawsize
>> 3;
7900 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7902 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7904 (*_bfd_error_handler
)
7905 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7908 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7909 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7912 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7913 eh
->adjust_done
= 1;
7915 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7916 toc_inf
->global_toc_syms
= TRUE
;
7921 /* Examine all relocs referencing .toc sections in order to remove
7922 unused .toc entries. */
7925 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7928 struct adjust_toc_info toc_inf
;
7929 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7931 htab
->do_toc_opt
= 1;
7932 toc_inf
.global_toc_syms
= TRUE
;
7933 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7935 asection
*toc
, *sec
;
7936 Elf_Internal_Shdr
*symtab_hdr
;
7937 Elf_Internal_Sym
*local_syms
;
7938 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7939 unsigned long *skip
, *drop
;
7940 unsigned char *used
;
7941 unsigned char *keep
, last
, some_unused
;
7943 if (!is_ppc64_elf (ibfd
))
7946 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7949 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7950 || elf_discarded_section (toc
))
7955 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7957 /* Look at sections dropped from the final link. */
7960 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7962 if (sec
->reloc_count
== 0
7963 || !elf_discarded_section (sec
)
7964 || get_opd_info (sec
)
7965 || (sec
->flags
& SEC_ALLOC
) == 0
7966 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7969 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7970 if (relstart
== NULL
)
7973 /* Run through the relocs to see which toc entries might be
7975 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7977 enum elf_ppc64_reloc_type r_type
;
7978 unsigned long r_symndx
;
7980 struct elf_link_hash_entry
*h
;
7981 Elf_Internal_Sym
*sym
;
7984 r_type
= ELF64_R_TYPE (rel
->r_info
);
7991 case R_PPC64_TOC16_LO
:
7992 case R_PPC64_TOC16_HI
:
7993 case R_PPC64_TOC16_HA
:
7994 case R_PPC64_TOC16_DS
:
7995 case R_PPC64_TOC16_LO_DS
:
7999 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8000 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8008 val
= h
->root
.u
.def
.value
;
8010 val
= sym
->st_value
;
8011 val
+= rel
->r_addend
;
8013 if (val
>= toc
->size
)
8016 /* Anything in the toc ought to be aligned to 8 bytes.
8017 If not, don't mark as unused. */
8023 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8028 skip
[val
>> 3] = ref_from_discarded
;
8031 if (elf_section_data (sec
)->relocs
!= relstart
)
8035 /* For largetoc loads of address constants, we can convert
8036 . addis rx,2,addr@got@ha
8037 . ld ry,addr@got@l(rx)
8039 . addis rx,2,addr@toc@ha
8040 . addi ry,rx,addr@toc@l
8041 when addr is within 2G of the toc pointer. This then means
8042 that the word storing "addr" in the toc is no longer needed. */
8044 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8045 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8046 && toc
->reloc_count
!= 0)
8048 /* Read toc relocs. */
8049 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8051 if (toc_relocs
== NULL
)
8054 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8056 enum elf_ppc64_reloc_type r_type
;
8057 unsigned long r_symndx
;
8059 struct elf_link_hash_entry
*h
;
8060 Elf_Internal_Sym
*sym
;
8063 r_type
= ELF64_R_TYPE (rel
->r_info
);
8064 if (r_type
!= R_PPC64_ADDR64
)
8067 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8068 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8073 || elf_discarded_section (sym_sec
))
8076 if (!SYMBOL_CALLS_LOCAL (info
, h
))
8081 if (h
->type
== STT_GNU_IFUNC
)
8083 val
= h
->root
.u
.def
.value
;
8087 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8089 val
= sym
->st_value
;
8091 val
+= rel
->r_addend
;
8092 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8094 /* We don't yet know the exact toc pointer value, but we
8095 know it will be somewhere in the toc section. Don't
8096 optimize if the difference from any possible toc
8097 pointer is outside [ff..f80008000, 7fff7fff]. */
8098 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8099 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8102 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8103 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8108 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8113 skip
[rel
->r_offset
>> 3]
8114 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8121 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8125 if (local_syms
!= NULL
8126 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8130 && elf_section_data (sec
)->relocs
!= relstart
)
8132 if (toc_relocs
!= NULL
8133 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8140 /* Now check all kept sections that might reference the toc.
8141 Check the toc itself last. */
8142 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8145 sec
= (sec
== toc
? NULL
8146 : sec
->next
== NULL
? toc
8147 : sec
->next
== toc
&& toc
->next
? toc
->next
8152 if (sec
->reloc_count
== 0
8153 || elf_discarded_section (sec
)
8154 || get_opd_info (sec
)
8155 || (sec
->flags
& SEC_ALLOC
) == 0
8156 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8159 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8161 if (relstart
== NULL
)
8164 /* Mark toc entries referenced as used. */
8167 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8169 enum elf_ppc64_reloc_type r_type
;
8170 unsigned long r_symndx
;
8172 struct elf_link_hash_entry
*h
;
8173 Elf_Internal_Sym
*sym
;
8176 r_type
= ELF64_R_TYPE (rel
->r_info
);
8182 case R_PPC64_GOT_TLSLD16_HA
:
8183 case R_PPC64_GOT_TLSGD16_HA
:
8184 case R_PPC64_GOT_TPREL16_HA
:
8185 case R_PPC64_GOT_DTPREL16_HA
:
8186 case R_PPC64_GOT16_HA
:
8187 case R_PPC64_TOC16_HA
:
8189 bfd_vma off
= rel
->r_offset
& ~3;
8190 unsigned char buf
[4];
8193 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
8198 insn
= bfd_get_32 (ibfd
, buf
);
8199 if ((insn
& ((0x3f << 26) | 0x1f << 16))
8200 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
8201 ppc64_elf_tdata (ibfd
)->ha_relocs_not_using_r2
= 1;
8209 case R_PPC64_TOC16_LO
:
8210 case R_PPC64_TOC16_HI
:
8211 case R_PPC64_TOC16_HA
:
8212 case R_PPC64_TOC16_DS
:
8213 case R_PPC64_TOC16_LO_DS
:
8214 /* In case we're taking addresses of toc entries. */
8215 case R_PPC64_ADDR64
:
8222 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8223 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8234 val
= h
->root
.u
.def
.value
;
8236 val
= sym
->st_value
;
8237 val
+= rel
->r_addend
;
8239 if (val
>= toc
->size
)
8242 if ((skip
[val
>> 3] & can_optimize
) != 0)
8249 case R_PPC64_TOC16_HA
:
8252 case R_PPC64_TOC16_LO_DS
:
8253 off
= rel
->r_offset
+ (bfd_big_endian (ibfd
) ? -2 : 3);
8254 if (!bfd_get_section_contents (ibfd
, sec
, &opc
, off
, 1))
8259 if ((opc
& (0x3f << 2)) == (58u << 2))
8264 /* Wrong sort of reloc, or not a ld. We may
8265 as well clear ref_from_discarded too. */
8270 /* For the toc section, we only mark as used if
8271 this entry itself isn't unused. */
8274 && (used
[rel
->r_offset
>> 3]
8275 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
)))
8276 /* Do all the relocs again, to catch reference
8284 if (elf_section_data (sec
)->relocs
!= relstart
)
8288 /* Merge the used and skip arrays. Assume that TOC
8289 doublewords not appearing as either used or unused belong
8290 to to an entry more than one doubleword in size. */
8291 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8292 drop
< skip
+ (toc
->size
+ 7) / 8;
8297 *drop
&= ~ref_from_discarded
;
8298 if ((*drop
& can_optimize
) != 0)
8302 else if ((*drop
& ref_from_discarded
) != 0)
8305 last
= ref_from_discarded
;
8315 bfd_byte
*contents
, *src
;
8317 Elf_Internal_Sym
*sym
;
8318 bfd_boolean local_toc_syms
= FALSE
;
8320 /* Shuffle the toc contents, and at the same time convert the
8321 skip array from booleans into offsets. */
8322 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8325 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8327 for (src
= contents
, off
= 0, drop
= skip
;
8328 src
< contents
+ toc
->size
;
8331 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8336 memcpy (src
- off
, src
, 8);
8340 toc
->rawsize
= toc
->size
;
8341 toc
->size
= src
- contents
- off
;
8343 /* Adjust addends for relocs against the toc section sym,
8344 and optimize any accesses we can. */
8345 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8347 if (sec
->reloc_count
== 0
8348 || elf_discarded_section (sec
))
8351 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8353 if (relstart
== NULL
)
8356 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8358 enum elf_ppc64_reloc_type r_type
;
8359 unsigned long r_symndx
;
8361 struct elf_link_hash_entry
*h
;
8364 r_type
= ELF64_R_TYPE (rel
->r_info
);
8371 case R_PPC64_TOC16_LO
:
8372 case R_PPC64_TOC16_HI
:
8373 case R_PPC64_TOC16_HA
:
8374 case R_PPC64_TOC16_DS
:
8375 case R_PPC64_TOC16_LO_DS
:
8376 case R_PPC64_ADDR64
:
8380 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8381 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8389 val
= h
->root
.u
.def
.value
;
8392 val
= sym
->st_value
;
8394 local_toc_syms
= TRUE
;
8397 val
+= rel
->r_addend
;
8399 if (val
> toc
->rawsize
)
8401 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8403 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8405 Elf_Internal_Rela
*tocrel
8406 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8407 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8411 case R_PPC64_TOC16_HA
:
8412 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8415 case R_PPC64_TOC16_LO_DS
:
8416 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8420 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
8422 info
->callbacks
->einfo
8423 (_("%P: %H: %s relocation references "
8424 "optimized away TOC entry\n"),
8425 ibfd
, sec
, rel
->r_offset
,
8426 ppc64_elf_howto_table
[r_type
]->name
);
8427 bfd_set_error (bfd_error_bad_value
);
8430 rel
->r_addend
= tocrel
->r_addend
;
8431 elf_section_data (sec
)->relocs
= relstart
;
8435 if (h
!= NULL
|| sym
->st_value
!= 0)
8438 rel
->r_addend
-= skip
[val
>> 3];
8439 elf_section_data (sec
)->relocs
= relstart
;
8442 if (elf_section_data (sec
)->relocs
!= relstart
)
8446 /* We shouldn't have local or global symbols defined in the TOC,
8447 but handle them anyway. */
8448 if (local_syms
!= NULL
)
8449 for (sym
= local_syms
;
8450 sym
< local_syms
+ symtab_hdr
->sh_info
;
8452 if (sym
->st_value
!= 0
8453 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8457 if (sym
->st_value
> toc
->rawsize
)
8458 i
= toc
->rawsize
>> 3;
8460 i
= sym
->st_value
>> 3;
8462 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8465 (*_bfd_error_handler
)
8466 (_("%s defined on removed toc entry"),
8467 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8470 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8471 sym
->st_value
= (bfd_vma
) i
<< 3;
8474 sym
->st_value
-= skip
[i
];
8475 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8478 /* Adjust any global syms defined in this toc input section. */
8479 if (toc_inf
.global_toc_syms
)
8482 toc_inf
.skip
= skip
;
8483 toc_inf
.global_toc_syms
= FALSE
;
8484 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8488 if (toc
->reloc_count
!= 0)
8490 Elf_Internal_Shdr
*rel_hdr
;
8491 Elf_Internal_Rela
*wrel
;
8494 /* Remove unused toc relocs, and adjust those we keep. */
8495 if (toc_relocs
== NULL
)
8496 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8498 if (toc_relocs
== NULL
)
8502 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8503 if ((skip
[rel
->r_offset
>> 3]
8504 & (ref_from_discarded
| can_optimize
)) == 0)
8506 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8507 wrel
->r_info
= rel
->r_info
;
8508 wrel
->r_addend
= rel
->r_addend
;
8511 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8512 &local_syms
, NULL
, NULL
))
8515 elf_section_data (toc
)->relocs
= toc_relocs
;
8516 toc
->reloc_count
= wrel
- toc_relocs
;
8517 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8518 sz
= rel_hdr
->sh_entsize
;
8519 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8522 else if (toc_relocs
!= NULL
8523 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8526 if (local_syms
!= NULL
8527 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8529 if (!info
->keep_memory
)
8532 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8540 /* Return true iff input section I references the TOC using
8541 instructions limited to +/-32k offsets. */
8544 ppc64_elf_has_small_toc_reloc (asection
*i
)
8546 return (is_ppc64_elf (i
->owner
)
8547 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8550 /* Allocate space for one GOT entry. */
8553 allocate_got (struct elf_link_hash_entry
*h
,
8554 struct bfd_link_info
*info
,
8555 struct got_entry
*gent
)
8557 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8559 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8560 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8562 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8563 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8564 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8566 gent
->got
.offset
= got
->size
;
8567 got
->size
+= entsize
;
8569 dyn
= htab
->elf
.dynamic_sections_created
;
8571 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8572 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8573 || h
->root
.type
!= bfd_link_hash_undefweak
))
8575 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8576 relgot
->size
+= rentsize
;
8578 else if (h
->type
== STT_GNU_IFUNC
)
8580 asection
*relgot
= htab
->reliplt
;
8581 relgot
->size
+= rentsize
;
8582 htab
->got_reli_size
+= rentsize
;
8586 /* This function merges got entries in the same toc group. */
8589 merge_got_entries (struct got_entry
**pent
)
8591 struct got_entry
*ent
, *ent2
;
8593 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8594 if (!ent
->is_indirect
)
8595 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8596 if (!ent2
->is_indirect
8597 && ent2
->addend
== ent
->addend
8598 && ent2
->tls_type
== ent
->tls_type
8599 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8601 ent2
->is_indirect
= TRUE
;
8602 ent2
->got
.ent
= ent
;
8606 /* Allocate space in .plt, .got and associated reloc sections for
8610 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8612 struct bfd_link_info
*info
;
8613 struct ppc_link_hash_table
*htab
;
8615 struct ppc_link_hash_entry
*eh
;
8616 struct elf_dyn_relocs
*p
;
8617 struct got_entry
**pgent
, *gent
;
8619 if (h
->root
.type
== bfd_link_hash_indirect
)
8622 info
= (struct bfd_link_info
*) inf
;
8623 htab
= ppc_hash_table (info
);
8627 if ((htab
->elf
.dynamic_sections_created
8629 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
8630 || h
->type
== STT_GNU_IFUNC
)
8632 struct plt_entry
*pent
;
8633 bfd_boolean doneone
= FALSE
;
8634 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8635 if (pent
->plt
.refcount
> 0)
8637 if (!htab
->elf
.dynamic_sections_created
8638 || h
->dynindx
== -1)
8641 pent
->plt
.offset
= s
->size
;
8642 s
->size
+= PLT_ENTRY_SIZE
;
8647 /* If this is the first .plt entry, make room for the special
8651 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
8653 pent
->plt
.offset
= s
->size
;
8655 /* Make room for this entry. */
8656 s
->size
+= PLT_ENTRY_SIZE
;
8658 /* Make room for the .glink code. */
8661 s
->size
+= GLINK_CALL_STUB_SIZE
;
8662 /* We need bigger stubs past index 32767. */
8663 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
8667 /* We also need to make an entry in the .rela.plt section. */
8670 s
->size
+= sizeof (Elf64_External_Rela
);
8674 pent
->plt
.offset
= (bfd_vma
) -1;
8677 h
->plt
.plist
= NULL
;
8683 h
->plt
.plist
= NULL
;
8687 eh
= (struct ppc_link_hash_entry
*) h
;
8688 /* Run through the TLS GD got entries first if we're changing them
8690 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
8691 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8692 if (gent
->got
.refcount
> 0
8693 && (gent
->tls_type
& TLS_GD
) != 0)
8695 /* This was a GD entry that has been converted to TPREL. If
8696 there happens to be a TPREL entry we can use that one. */
8697 struct got_entry
*ent
;
8698 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8699 if (ent
->got
.refcount
> 0
8700 && (ent
->tls_type
& TLS_TPREL
) != 0
8701 && ent
->addend
== gent
->addend
8702 && ent
->owner
== gent
->owner
)
8704 gent
->got
.refcount
= 0;
8708 /* If not, then we'll be using our own TPREL entry. */
8709 if (gent
->got
.refcount
!= 0)
8710 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8713 /* Remove any list entry that won't generate a word in the GOT before
8714 we call merge_got_entries. Otherwise we risk merging to empty
8716 pgent
= &h
->got
.glist
;
8717 while ((gent
= *pgent
) != NULL
)
8718 if (gent
->got
.refcount
> 0)
8720 if ((gent
->tls_type
& TLS_LD
) != 0
8723 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8724 *pgent
= gent
->next
;
8727 pgent
= &gent
->next
;
8730 *pgent
= gent
->next
;
8732 if (!htab
->do_multi_toc
)
8733 merge_got_entries (&h
->got
.glist
);
8735 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8736 if (!gent
->is_indirect
)
8738 /* Make sure this symbol is output as a dynamic symbol.
8739 Undefined weak syms won't yet be marked as dynamic,
8740 nor will all TLS symbols. */
8741 if (h
->dynindx
== -1
8743 && h
->type
!= STT_GNU_IFUNC
8744 && htab
->elf
.dynamic_sections_created
)
8746 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8750 if (!is_ppc64_elf (gent
->owner
))
8753 allocate_got (h
, info
, gent
);
8756 if (eh
->dyn_relocs
== NULL
8757 || (!htab
->elf
.dynamic_sections_created
8758 && h
->type
!= STT_GNU_IFUNC
))
8761 /* In the shared -Bsymbolic case, discard space allocated for
8762 dynamic pc-relative relocs against symbols which turn out to be
8763 defined in regular objects. For the normal shared case, discard
8764 space for relocs that have become local due to symbol visibility
8769 /* Relocs that use pc_count are those that appear on a call insn,
8770 or certain REL relocs (see must_be_dyn_reloc) that can be
8771 generated via assembly. We want calls to protected symbols to
8772 resolve directly to the function rather than going via the plt.
8773 If people want function pointer comparisons to work as expected
8774 then they should avoid writing weird assembly. */
8775 if (SYMBOL_CALLS_LOCAL (info
, h
))
8777 struct elf_dyn_relocs
**pp
;
8779 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8781 p
->count
-= p
->pc_count
;
8790 /* Also discard relocs on undefined weak syms with non-default
8792 if (eh
->dyn_relocs
!= NULL
8793 && h
->root
.type
== bfd_link_hash_undefweak
)
8795 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8796 eh
->dyn_relocs
= NULL
;
8798 /* Make sure this symbol is output as a dynamic symbol.
8799 Undefined weak syms won't yet be marked as dynamic. */
8800 else if (h
->dynindx
== -1
8801 && !h
->forced_local
)
8803 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8808 else if (h
->type
== STT_GNU_IFUNC
)
8810 if (!h
->non_got_ref
)
8811 eh
->dyn_relocs
= NULL
;
8813 else if (ELIMINATE_COPY_RELOCS
)
8815 /* For the non-shared case, discard space for relocs against
8816 symbols which turn out to need copy relocs or are not
8822 /* Make sure this symbol is output as a dynamic symbol.
8823 Undefined weak syms won't yet be marked as dynamic. */
8824 if (h
->dynindx
== -1
8825 && !h
->forced_local
)
8827 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8831 /* If that succeeded, we know we'll be keeping all the
8833 if (h
->dynindx
!= -1)
8837 eh
->dyn_relocs
= NULL
;
8842 /* Finally, allocate space. */
8843 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8845 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8846 if (!htab
->elf
.dynamic_sections_created
)
8847 sreloc
= htab
->reliplt
;
8848 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8854 /* Find any dynamic relocs that apply to read-only sections. */
8857 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8859 struct ppc_link_hash_entry
*eh
;
8860 struct elf_dyn_relocs
*p
;
8862 eh
= (struct ppc_link_hash_entry
*) h
;
8863 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8865 asection
*s
= p
->sec
->output_section
;
8867 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8869 struct bfd_link_info
*info
= inf
;
8871 info
->flags
|= DF_TEXTREL
;
8873 /* Not an error, just cut short the traversal. */
8880 /* Set the sizes of the dynamic sections. */
8883 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8884 struct bfd_link_info
*info
)
8886 struct ppc_link_hash_table
*htab
;
8891 struct got_entry
*first_tlsld
;
8893 htab
= ppc_hash_table (info
);
8897 dynobj
= htab
->elf
.dynobj
;
8901 if (htab
->elf
.dynamic_sections_created
)
8903 /* Set the contents of the .interp section to the interpreter. */
8904 if (info
->executable
)
8906 s
= bfd_get_section_by_name (dynobj
, ".interp");
8909 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8910 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8914 /* Set up .got offsets for local syms, and space for local dynamic
8916 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8918 struct got_entry
**lgot_ents
;
8919 struct got_entry
**end_lgot_ents
;
8920 struct plt_entry
**local_plt
;
8921 struct plt_entry
**end_local_plt
;
8922 unsigned char *lgot_masks
;
8923 bfd_size_type locsymcount
;
8924 Elf_Internal_Shdr
*symtab_hdr
;
8927 if (!is_ppc64_elf (ibfd
))
8930 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8932 struct elf_dyn_relocs
*p
;
8934 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
8936 if (!bfd_is_abs_section (p
->sec
)
8937 && bfd_is_abs_section (p
->sec
->output_section
))
8939 /* Input section has been discarded, either because
8940 it is a copy of a linkonce section or due to
8941 linker script /DISCARD/, so we'll be discarding
8944 else if (p
->count
!= 0)
8946 srel
= elf_section_data (p
->sec
)->sreloc
;
8947 if (!htab
->elf
.dynamic_sections_created
)
8948 srel
= htab
->reliplt
;
8949 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8950 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8951 info
->flags
|= DF_TEXTREL
;
8956 lgot_ents
= elf_local_got_ents (ibfd
);
8960 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8961 locsymcount
= symtab_hdr
->sh_info
;
8962 end_lgot_ents
= lgot_ents
+ locsymcount
;
8963 local_plt
= (struct plt_entry
**) end_lgot_ents
;
8964 end_local_plt
= local_plt
+ locsymcount
;
8965 lgot_masks
= (unsigned char *) end_local_plt
;
8966 s
= ppc64_elf_tdata (ibfd
)->got
;
8967 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
8968 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
8970 struct got_entry
**pent
, *ent
;
8973 while ((ent
= *pent
) != NULL
)
8974 if (ent
->got
.refcount
> 0)
8976 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
8978 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
8983 unsigned int num
= 1;
8984 ent
->got
.offset
= s
->size
;
8985 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
8989 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
8990 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
8993 += num
* sizeof (Elf64_External_Rela
);
8995 += num
* sizeof (Elf64_External_Rela
);
9004 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
9005 for (; local_plt
< end_local_plt
; ++local_plt
)
9007 struct plt_entry
*ent
;
9009 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9010 if (ent
->plt
.refcount
> 0)
9013 ent
->plt
.offset
= s
->size
;
9014 s
->size
+= PLT_ENTRY_SIZE
;
9016 htab
->reliplt
->size
+= sizeof (Elf64_External_Rela
);
9019 ent
->plt
.offset
= (bfd_vma
) -1;
9023 /* Allocate global sym .plt and .got entries, and space for global
9024 sym dynamic relocs. */
9025 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9028 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9030 struct got_entry
*ent
;
9032 if (!is_ppc64_elf (ibfd
))
9035 ent
= ppc64_tlsld_got (ibfd
);
9036 if (ent
->got
.refcount
> 0)
9038 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9040 ent
->is_indirect
= TRUE
;
9041 ent
->got
.ent
= first_tlsld
;
9045 if (first_tlsld
== NULL
)
9047 s
= ppc64_elf_tdata (ibfd
)->got
;
9048 ent
->got
.offset
= s
->size
;
9053 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9054 srel
->size
+= sizeof (Elf64_External_Rela
);
9059 ent
->got
.offset
= (bfd_vma
) -1;
9062 /* We now have determined the sizes of the various dynamic sections.
9063 Allocate memory for them. */
9065 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9067 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9070 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9071 /* These haven't been allocated yet; don't strip. */
9073 else if (s
== htab
->got
9077 || s
== htab
->dynbss
)
9079 /* Strip this section if we don't need it; see the
9082 else if (s
== htab
->glink_eh_frame
)
9084 if (!bfd_is_abs_section (s
->output_section
))
9085 /* Not sized yet. */
9088 else if (CONST_STRNEQ (s
->name
, ".rela"))
9092 if (s
!= htab
->relplt
)
9095 /* We use the reloc_count field as a counter if we need
9096 to copy relocs into the output file. */
9102 /* It's not one of our sections, so don't allocate space. */
9108 /* If we don't need this section, strip it from the
9109 output file. This is mostly to handle .rela.bss and
9110 .rela.plt. We must create both sections in
9111 create_dynamic_sections, because they must be created
9112 before the linker maps input sections to output
9113 sections. The linker does that before
9114 adjust_dynamic_symbol is called, and it is that
9115 function which decides whether anything needs to go
9116 into these sections. */
9117 s
->flags
|= SEC_EXCLUDE
;
9121 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9124 /* Allocate memory for the section contents. We use bfd_zalloc
9125 here in case unused entries are not reclaimed before the
9126 section's contents are written out. This should not happen,
9127 but this way if it does we get a R_PPC64_NONE reloc in .rela
9128 sections instead of garbage.
9129 We also rely on the section contents being zero when writing
9131 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9132 if (s
->contents
== NULL
)
9136 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9138 if (!is_ppc64_elf (ibfd
))
9141 s
= ppc64_elf_tdata (ibfd
)->got
;
9142 if (s
!= NULL
&& s
!= htab
->got
)
9145 s
->flags
|= SEC_EXCLUDE
;
9148 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9149 if (s
->contents
== NULL
)
9153 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9157 s
->flags
|= SEC_EXCLUDE
;
9160 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9161 if (s
->contents
== NULL
)
9169 if (htab
->elf
.dynamic_sections_created
)
9171 /* Add some entries to the .dynamic section. We fill in the
9172 values later, in ppc64_elf_finish_dynamic_sections, but we
9173 must add the entries now so that we get the correct size for
9174 the .dynamic section. The DT_DEBUG entry is filled in by the
9175 dynamic linker and used by the debugger. */
9176 #define add_dynamic_entry(TAG, VAL) \
9177 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9179 if (info
->executable
)
9181 if (!add_dynamic_entry (DT_DEBUG
, 0))
9185 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
9187 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9188 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9189 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9190 || !add_dynamic_entry (DT_JMPREL
, 0)
9191 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9197 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9198 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9202 if (!htab
->no_tls_get_addr_opt
9203 && htab
->tls_get_addr_fd
!= NULL
9204 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
9205 && !add_dynamic_entry (DT_PPC64_TLSOPT
, 0))
9210 if (!add_dynamic_entry (DT_RELA
, 0)
9211 || !add_dynamic_entry (DT_RELASZ
, 0)
9212 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9215 /* If any dynamic relocs apply to a read-only section,
9216 then we need a DT_TEXTREL entry. */
9217 if ((info
->flags
& DF_TEXTREL
) == 0)
9218 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
9220 if ((info
->flags
& DF_TEXTREL
) != 0)
9222 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9227 #undef add_dynamic_entry
9232 /* Determine the type of stub needed, if any, for a call. */
9234 static inline enum ppc_stub_type
9235 ppc_type_of_stub (asection
*input_sec
,
9236 const Elf_Internal_Rela
*rel
,
9237 struct ppc_link_hash_entry
**hash
,
9238 struct plt_entry
**plt_ent
,
9239 bfd_vma destination
)
9241 struct ppc_link_hash_entry
*h
= *hash
;
9243 bfd_vma branch_offset
;
9244 bfd_vma max_branch_offset
;
9245 enum elf_ppc64_reloc_type r_type
;
9249 struct plt_entry
*ent
;
9250 struct ppc_link_hash_entry
*fdh
= h
;
9252 && h
->oh
->is_func_descriptor
)
9254 fdh
= ppc_follow_link (h
->oh
);
9258 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9259 if (ent
->addend
== rel
->r_addend
9260 && ent
->plt
.offset
!= (bfd_vma
) -1)
9263 return ppc_stub_plt_call
;
9266 /* Here, we know we don't have a plt entry. If we don't have a
9267 either a defined function descriptor or a defined entry symbol
9268 in a regular object file, then it is pointless trying to make
9269 any other type of stub. */
9270 if (!is_static_defined (&fdh
->elf
)
9271 && !is_static_defined (&h
->elf
))
9272 return ppc_stub_none
;
9274 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9276 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9277 struct plt_entry
**local_plt
= (struct plt_entry
**)
9278 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9279 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9281 if (local_plt
[r_symndx
] != NULL
)
9283 struct plt_entry
*ent
;
9285 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9286 if (ent
->addend
== rel
->r_addend
9287 && ent
->plt
.offset
!= (bfd_vma
) -1)
9290 return ppc_stub_plt_call
;
9295 /* Determine where the call point is. */
9296 location
= (input_sec
->output_offset
9297 + input_sec
->output_section
->vma
9300 branch_offset
= destination
- location
;
9301 r_type
= ELF64_R_TYPE (rel
->r_info
);
9303 /* Determine if a long branch stub is needed. */
9304 max_branch_offset
= 1 << 25;
9305 if (r_type
!= R_PPC64_REL24
)
9306 max_branch_offset
= 1 << 15;
9308 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
9309 /* We need a stub. Figure out whether a long_branch or plt_branch
9311 return ppc_stub_long_branch
;
9313 return ppc_stub_none
;
9316 /* Build a .plt call stub. */
9318 static inline bfd_byte
*
9319 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
, Elf_Internal_Rela
*r
,
9320 bfd_boolean plt_static_chain
)
9322 #define PPC_LO(v) ((v) & 0xffff)
9323 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9324 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9326 if (PPC_HA (offset
) != 0)
9330 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9331 r
[1].r_offset
= r
[0].r_offset
+ 8;
9332 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9333 r
[1].r_addend
= r
[0].r_addend
;
9334 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9336 r
[2].r_offset
= r
[1].r_offset
+ 4;
9337 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9338 r
[2].r_addend
= r
[0].r_addend
;
9342 r
[2].r_offset
= r
[1].r_offset
+ 8;
9343 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9344 r
[2].r_addend
= r
[0].r_addend
+ 8;
9345 if (plt_static_chain
)
9347 r
[3].r_offset
= r
[2].r_offset
+ 4;
9348 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9349 r
[3].r_addend
= r
[0].r_addend
+ 16;
9353 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9354 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9355 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
9356 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9358 bfd_put_32 (obfd
, ADDI_R12_R12
| PPC_LO (offset
), p
), p
+= 4;
9361 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9362 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
+ 8), p
), p
+= 4;
9363 if (plt_static_chain
)
9364 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
+ 16), p
), p
+= 4;
9365 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9372 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9373 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9375 r
[1].r_offset
= r
[0].r_offset
+ 4;
9376 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9377 r
[1].r_addend
= r
[0].r_addend
;
9381 r
[1].r_offset
= r
[0].r_offset
+ 8;
9382 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9383 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
9384 if (plt_static_chain
)
9386 r
[2].r_offset
= r
[1].r_offset
+ 4;
9387 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9388 r
[2].r_addend
= r
[0].r_addend
+ 8;
9392 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9393 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
), p
), p
+= 4;
9394 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9396 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9399 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9400 if (plt_static_chain
)
9401 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9402 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9403 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9408 /* Build a special .plt call stub for __tls_get_addr. */
9410 #define LD_R11_0R3 0xe9630000
9411 #define LD_R12_0R3 0xe9830000
9412 #define MR_R0_R3 0x7c601b78
9413 #define CMPDI_R11_0 0x2c2b0000
9414 #define ADD_R3_R12_R13 0x7c6c6a14
9415 #define BEQLR 0x4d820020
9416 #define MR_R3_R0 0x7c030378
9417 #define MFLR_R11 0x7d6802a6
9418 #define STD_R11_0R1 0xf9610000
9419 #define BCTRL 0x4e800421
9420 #define LD_R11_0R1 0xe9610000
9421 #define LD_R2_0R1 0xe8410000
9422 #define MTLR_R11 0x7d6803a6
9424 static inline bfd_byte
*
9425 build_tls_get_addr_stub (bfd
*obfd
, bfd_byte
*p
, int offset
,
9426 Elf_Internal_Rela
*r
, bfd_boolean plt_static_chain
)
9428 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9429 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9430 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9431 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9432 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9433 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9434 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9435 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9436 bfd_put_32 (obfd
, STD_R11_0R1
+ 32, p
), p
+= 4;
9439 r
[0].r_offset
+= 9 * 4;
9440 p
= build_plt_stub (obfd
, p
, offset
, r
, plt_static_chain
);
9441 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9443 bfd_put_32 (obfd
, LD_R11_0R1
+ 32, p
), p
+= 4;
9444 bfd_put_32 (obfd
, LD_R2_0R1
+ 40, p
), p
+= 4;
9445 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9446 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9451 static Elf_Internal_Rela
*
9452 get_relocs (asection
*sec
, int count
)
9454 Elf_Internal_Rela
*relocs
;
9455 struct bfd_elf_section_data
*elfsec_data
;
9457 elfsec_data
= elf_section_data (sec
);
9458 relocs
= elfsec_data
->relocs
;
9461 bfd_size_type relsize
;
9462 relsize
= sec
->reloc_count
* sizeof (*relocs
);
9463 relocs
= bfd_alloc (sec
->owner
, relsize
);
9466 elfsec_data
->relocs
= relocs
;
9467 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
9468 sizeof (Elf_Internal_Shdr
));
9469 if (elfsec_data
->rela
.hdr
== NULL
)
9471 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
9472 * sizeof (Elf64_External_Rela
));
9473 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
9474 sec
->reloc_count
= 0;
9476 relocs
+= sec
->reloc_count
;
9477 sec
->reloc_count
+= count
;
9482 get_r2off (struct bfd_link_info
*info
,
9483 struct ppc_stub_hash_entry
*stub_entry
)
9485 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9486 bfd_vma r2off
= htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
;
9490 /* Support linking -R objects. Get the toc pointer from the
9493 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
9494 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
9496 if (strcmp (opd
->name
, ".opd") != 0
9497 || opd
->reloc_count
!= 0)
9499 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for %s\n"),
9500 stub_entry
->h
->elf
.root
.root
.string
);
9501 bfd_set_error (bfd_error_bad_value
);
9504 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
9506 r2off
= bfd_get_64 (opd
->owner
, buf
);
9507 r2off
-= elf_gp (info
->output_bfd
);
9509 r2off
-= htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
;
9514 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9516 struct ppc_stub_hash_entry
*stub_entry
;
9517 struct ppc_branch_hash_entry
*br_entry
;
9518 struct bfd_link_info
*info
;
9519 struct ppc_link_hash_table
*htab
;
9524 Elf_Internal_Rela
*r
;
9527 /* Massage our args to the form they really have. */
9528 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9531 htab
= ppc_hash_table (info
);
9535 /* Make a note of the offset within the stubs for this entry. */
9536 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
9537 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
9539 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
9540 switch (stub_entry
->stub_type
)
9542 case ppc_stub_long_branch
:
9543 case ppc_stub_long_branch_r2off
:
9544 /* Branches are relative. This is where we are going to. */
9545 off
= dest
= (stub_entry
->target_value
9546 + stub_entry
->target_section
->output_offset
9547 + stub_entry
->target_section
->output_section
->vma
);
9549 /* And this is where we are coming from. */
9550 off
-= (stub_entry
->stub_offset
9551 + stub_entry
->stub_sec
->output_offset
9552 + stub_entry
->stub_sec
->output_section
->vma
);
9555 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9557 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9561 htab
->stub_error
= TRUE
;
9564 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9567 if (PPC_HA (r2off
) != 0)
9570 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9573 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9577 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
9579 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9581 info
->callbacks
->einfo (_("%P: long branch stub `%s' offset overflow\n"),
9582 stub_entry
->root
.string
);
9583 htab
->stub_error
= TRUE
;
9587 if (info
->emitrelocations
)
9589 r
= get_relocs (stub_entry
->stub_sec
, 1);
9592 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9593 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
9595 if (stub_entry
->h
!= NULL
)
9597 struct elf_link_hash_entry
**hashes
;
9598 unsigned long symndx
;
9599 struct ppc_link_hash_entry
*h
;
9601 hashes
= elf_sym_hashes (htab
->stub_bfd
);
9604 bfd_size_type hsize
;
9606 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
9607 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
9610 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
9611 htab
->stub_globals
= 1;
9613 symndx
= htab
->stub_globals
++;
9615 hashes
[symndx
] = &h
->elf
;
9616 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
9617 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
9618 h
= ppc_follow_link (h
->oh
);
9619 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
9620 /* H is an opd symbol. The addend must be zero. */
9624 off
= (h
->elf
.root
.u
.def
.value
9625 + h
->elf
.root
.u
.def
.section
->output_offset
9626 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
9633 case ppc_stub_plt_branch
:
9634 case ppc_stub_plt_branch_r2off
:
9635 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9636 stub_entry
->root
.string
+ 9,
9638 if (br_entry
== NULL
)
9640 info
->callbacks
->einfo (_("%P: can't find branch stub `%s'\n"),
9641 stub_entry
->root
.string
);
9642 htab
->stub_error
= TRUE
;
9646 dest
= (stub_entry
->target_value
9647 + stub_entry
->target_section
->output_offset
9648 + stub_entry
->target_section
->output_section
->vma
);
9650 bfd_put_64 (htab
->brlt
->owner
, dest
,
9651 htab
->brlt
->contents
+ br_entry
->offset
);
9653 if (br_entry
->iter
== htab
->stub_iteration
)
9657 if (htab
->relbrlt
!= NULL
)
9659 /* Create a reloc for the branch lookup table entry. */
9660 Elf_Internal_Rela rela
;
9663 rela
.r_offset
= (br_entry
->offset
9664 + htab
->brlt
->output_offset
9665 + htab
->brlt
->output_section
->vma
);
9666 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9667 rela
.r_addend
= dest
;
9669 rl
= htab
->relbrlt
->contents
;
9670 rl
+= (htab
->relbrlt
->reloc_count
++
9671 * sizeof (Elf64_External_Rela
));
9672 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
9674 else if (info
->emitrelocations
)
9676 r
= get_relocs (htab
->brlt
, 1);
9679 /* brlt, being SEC_LINKER_CREATED does not go through the
9680 normal reloc processing. Symbols and offsets are not
9681 translated from input file to output file form, so
9682 set up the offset per the output file. */
9683 r
->r_offset
= (br_entry
->offset
9684 + htab
->brlt
->output_offset
9685 + htab
->brlt
->output_section
->vma
);
9686 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9691 dest
= (br_entry
->offset
9692 + htab
->brlt
->output_offset
9693 + htab
->brlt
->output_section
->vma
);
9696 - elf_gp (htab
->brlt
->output_section
->owner
)
9697 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9699 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9701 info
->callbacks
->einfo
9702 (_("%P: linkage table error against `%s'\n"),
9703 stub_entry
->root
.string
);
9704 bfd_set_error (bfd_error_bad_value
);
9705 htab
->stub_error
= TRUE
;
9709 if (info
->emitrelocations
)
9711 r
= get_relocs (stub_entry
->stub_sec
, 1 + (PPC_HA (off
) != 0));
9714 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9715 if (bfd_big_endian (info
->output_bfd
))
9717 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
9719 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9720 r
[0].r_addend
= dest
;
9721 if (PPC_HA (off
) != 0)
9723 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9724 r
[1].r_offset
= r
[0].r_offset
+ 4;
9725 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9726 r
[1].r_addend
= r
[0].r_addend
;
9730 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
9732 if (PPC_HA (off
) != 0)
9735 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9737 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9742 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9747 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9751 htab
->stub_error
= TRUE
;
9755 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9758 if (PPC_HA (off
) != 0)
9761 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9763 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9768 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9772 if (PPC_HA (r2off
) != 0)
9775 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9778 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9781 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
9783 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
9786 case ppc_stub_plt_call
:
9787 if (stub_entry
->h
!= NULL
9788 && stub_entry
->h
->is_func_descriptor
9789 && stub_entry
->h
->oh
!= NULL
)
9791 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
9793 /* If the old-ABI "dot-symbol" is undefined make it weak so
9794 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
9795 FIXME: We used to define the symbol on one of the call
9796 stubs instead, which is why we test symbol section id
9797 against htab->top_id in various places. Likely all
9798 these checks could now disappear. */
9799 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
9800 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
9801 /* Stop undo_symbol_twiddle changing it back to undefined. */
9802 fh
->was_undefined
= 0;
9805 /* Now build the stub. */
9806 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9807 if (dest
>= (bfd_vma
) -2)
9811 if (!htab
->elf
.dynamic_sections_created
9812 || stub_entry
->h
== NULL
9813 || stub_entry
->h
->elf
.dynindx
== -1)
9816 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
9818 if (stub_entry
->h
== NULL
9819 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
9821 Elf_Internal_Rela rela
;
9824 rela
.r_offset
= dest
;
9825 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
9826 rela
.r_addend
= (stub_entry
->target_value
9827 + stub_entry
->target_section
->output_offset
9828 + stub_entry
->target_section
->output_section
->vma
);
9830 rl
= (htab
->reliplt
->contents
9831 + (htab
->reliplt
->reloc_count
++
9832 * sizeof (Elf64_External_Rela
)));
9833 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
9834 stub_entry
->plt_ent
->plt
.offset
|= 1;
9838 - elf_gp (plt
->output_section
->owner
)
9839 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9841 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9843 info
->callbacks
->einfo
9844 (_("%P: linkage table error against `%s'\n"),
9845 stub_entry
->h
!= NULL
9846 ? stub_entry
->h
->elf
.root
.root
.string
9848 bfd_set_error (bfd_error_bad_value
);
9849 htab
->stub_error
= TRUE
;
9854 if (info
->emitrelocations
)
9856 r
= get_relocs (stub_entry
->stub_sec
,
9858 + (PPC_HA (off
) != 0)
9859 + (htab
->plt_static_chain
9860 && PPC_HA (off
+ 16) == PPC_HA (off
))));
9863 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9864 if (bfd_big_endian (info
->output_bfd
))
9866 r
[0].r_addend
= dest
;
9868 if (stub_entry
->h
!= NULL
9869 && (stub_entry
->h
== htab
->tls_get_addr_fd
9870 || stub_entry
->h
== htab
->tls_get_addr
)
9871 && !htab
->no_tls_get_addr_opt
)
9872 p
= build_tls_get_addr_stub (htab
->stub_bfd
, loc
, off
, r
,
9873 htab
->plt_static_chain
);
9875 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
, r
,
9876 htab
->plt_static_chain
);
9885 stub_entry
->stub_sec
->size
+= size
;
9887 if (htab
->emit_stub_syms
)
9889 struct elf_link_hash_entry
*h
;
9892 const char *const stub_str
[] = { "long_branch",
9893 "long_branch_r2off",
9898 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
9899 len2
= strlen (stub_entry
->root
.string
);
9900 name
= bfd_malloc (len1
+ len2
+ 2);
9903 memcpy (name
, stub_entry
->root
.string
, 9);
9904 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
9905 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
9906 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
9909 if (h
->root
.type
== bfd_link_hash_new
)
9911 h
->root
.type
= bfd_link_hash_defined
;
9912 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
9913 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
9916 h
->ref_regular_nonweak
= 1;
9917 h
->forced_local
= 1;
9925 /* As above, but don't actually build the stub. Just bump offset so
9926 we know stub section sizes, and select plt_branch stubs where
9927 long_branch stubs won't do. */
9930 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9932 struct ppc_stub_hash_entry
*stub_entry
;
9933 struct bfd_link_info
*info
;
9934 struct ppc_link_hash_table
*htab
;
9938 /* Massage our args to the form they really have. */
9939 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9942 htab
= ppc_hash_table (info
);
9946 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
9949 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
9950 if (off
>= (bfd_vma
) -2)
9953 if (!htab
->elf
.dynamic_sections_created
9954 || stub_entry
->h
== NULL
9955 || stub_entry
->h
->elf
.dynindx
== -1)
9957 off
+= (plt
->output_offset
9958 + plt
->output_section
->vma
9959 - elf_gp (plt
->output_section
->owner
)
9960 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9962 size
= PLT_CALL_STUB_SIZE
;
9963 if (!htab
->plt_static_chain
)
9965 if (PPC_HA (off
) == 0)
9967 if (PPC_HA (off
+ 8 + 8 * htab
->plt_static_chain
) != PPC_HA (off
))
9969 if (stub_entry
->h
!= NULL
9970 && (stub_entry
->h
== htab
->tls_get_addr_fd
9971 || stub_entry
->h
== htab
->tls_get_addr
)
9972 && !htab
->no_tls_get_addr_opt
)
9974 if (info
->emitrelocations
)
9976 stub_entry
->stub_sec
->reloc_count
9978 + (PPC_HA (off
) != 0)
9979 + (htab
->plt_static_chain
9980 && PPC_HA (off
+ 16) == PPC_HA (off
)));
9981 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
9986 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
9990 off
= (stub_entry
->target_value
9991 + stub_entry
->target_section
->output_offset
9992 + stub_entry
->target_section
->output_section
->vma
);
9993 off
-= (stub_entry
->stub_sec
->size
9994 + stub_entry
->stub_sec
->output_offset
9995 + stub_entry
->stub_sec
->output_section
->vma
);
9997 /* Reset the stub type from the plt variant in case we now
9998 can reach with a shorter stub. */
9999 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
10000 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10003 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10005 r2off
= get_r2off (info
, stub_entry
);
10008 htab
->stub_error
= TRUE
;
10012 if (PPC_HA (r2off
) != 0)
10017 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
10018 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10020 struct ppc_branch_hash_entry
*br_entry
;
10022 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10023 stub_entry
->root
.string
+ 9,
10025 if (br_entry
== NULL
)
10027 info
->callbacks
->einfo (_("%P: can't build branch stub `%s'\n"),
10028 stub_entry
->root
.string
);
10029 htab
->stub_error
= TRUE
;
10033 if (br_entry
->iter
!= htab
->stub_iteration
)
10035 br_entry
->iter
= htab
->stub_iteration
;
10036 br_entry
->offset
= htab
->brlt
->size
;
10037 htab
->brlt
->size
+= 8;
10039 if (htab
->relbrlt
!= NULL
)
10040 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10041 else if (info
->emitrelocations
)
10043 htab
->brlt
->reloc_count
+= 1;
10044 htab
->brlt
->flags
|= SEC_RELOC
;
10048 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
10049 off
= (br_entry
->offset
10050 + htab
->brlt
->output_offset
10051 + htab
->brlt
->output_section
->vma
10052 - elf_gp (htab
->brlt
->output_section
->owner
)
10053 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
10055 if (info
->emitrelocations
)
10057 stub_entry
->stub_sec
->reloc_count
+= 1 + (PPC_HA (off
) != 0);
10058 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10061 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10064 if (PPC_HA (off
) != 0)
10070 if (PPC_HA (off
) != 0)
10073 if (PPC_HA (r2off
) != 0)
10077 else if (info
->emitrelocations
)
10079 stub_entry
->stub_sec
->reloc_count
+= 1;
10080 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10084 stub_entry
->stub_sec
->size
+= size
;
10088 /* Set up various things so that we can make a list of input sections
10089 for each output section included in the link. Returns -1 on error,
10090 0 when no stubs will be needed, and 1 on success. */
10093 ppc64_elf_setup_section_lists
10094 (struct bfd_link_info
*info
,
10095 asection
*(*add_stub_section
) (const char *, asection
*),
10096 void (*layout_sections_again
) (void))
10099 int top_id
, top_index
, id
;
10101 asection
**input_list
;
10103 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10107 /* Stash our params away. */
10108 htab
->add_stub_section
= add_stub_section
;
10109 htab
->layout_sections_again
= layout_sections_again
;
10111 if (htab
->brlt
== NULL
)
10114 /* Find the top input section id. */
10115 for (input_bfd
= info
->input_bfds
, top_id
= 3;
10117 input_bfd
= input_bfd
->link_next
)
10119 for (section
= input_bfd
->sections
;
10121 section
= section
->next
)
10123 if (top_id
< section
->id
)
10124 top_id
= section
->id
;
10128 htab
->top_id
= top_id
;
10129 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
10130 htab
->stub_group
= bfd_zmalloc (amt
);
10131 if (htab
->stub_group
== NULL
)
10134 /* Set toc_off for com, und, abs and ind sections. */
10135 for (id
= 0; id
< 3; id
++)
10136 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
10138 /* We can't use output_bfd->section_count here to find the top output
10139 section index as some sections may have been removed, and
10140 strip_excluded_output_sections doesn't renumber the indices. */
10141 for (section
= info
->output_bfd
->sections
, top_index
= 0;
10143 section
= section
->next
)
10145 if (top_index
< section
->index
)
10146 top_index
= section
->index
;
10149 htab
->top_index
= top_index
;
10150 amt
= sizeof (asection
*) * (top_index
+ 1);
10151 input_list
= bfd_zmalloc (amt
);
10152 htab
->input_list
= input_list
;
10153 if (input_list
== NULL
)
10159 /* Set up for first pass at multitoc partitioning. */
10162 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10164 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10166 elf_gp (info
->output_bfd
) = ppc64_elf_toc (info
->output_bfd
);
10167 htab
->toc_curr
= elf_gp (info
->output_bfd
);
10168 htab
->toc_bfd
= NULL
;
10169 htab
->toc_first_sec
= NULL
;
10172 /* The linker repeatedly calls this function for each TOC input section
10173 and linker generated GOT section. Group input bfds such that the toc
10174 within a group is less than 64k in size. */
10177 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10179 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10180 bfd_vma addr
, off
, limit
;
10185 if (!htab
->second_toc_pass
)
10187 /* Keep track of the first .toc or .got section for this input bfd. */
10188 if (htab
->toc_bfd
!= isec
->owner
)
10190 htab
->toc_bfd
= isec
->owner
;
10191 htab
->toc_first_sec
= isec
;
10194 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10195 off
= addr
- htab
->toc_curr
;
10196 limit
= 0x80008000;
10197 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10199 if (off
+ isec
->size
> limit
)
10201 addr
= (htab
->toc_first_sec
->output_offset
10202 + htab
->toc_first_sec
->output_section
->vma
);
10203 htab
->toc_curr
= addr
;
10206 /* toc_curr is the base address of this toc group. Set elf_gp
10207 for the input section to be the offset relative to the
10208 output toc base plus 0x8000. Making the input elf_gp an
10209 offset allows us to move the toc as a whole without
10210 recalculating input elf_gp. */
10211 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
10212 off
+= TOC_BASE_OFF
;
10214 /* Die if someone uses a linker script that doesn't keep input
10215 file .toc and .got together. */
10216 if (elf_gp (isec
->owner
) != 0
10217 && elf_gp (isec
->owner
) != off
)
10220 elf_gp (isec
->owner
) = off
;
10224 /* During the second pass toc_first_sec points to the start of
10225 a toc group, and toc_curr is used to track the old elf_gp.
10226 We use toc_bfd to ensure we only look at each bfd once. */
10227 if (htab
->toc_bfd
== isec
->owner
)
10229 htab
->toc_bfd
= isec
->owner
;
10231 if (htab
->toc_first_sec
== NULL
10232 || htab
->toc_curr
!= elf_gp (isec
->owner
))
10234 htab
->toc_curr
= elf_gp (isec
->owner
);
10235 htab
->toc_first_sec
= isec
;
10237 addr
= (htab
->toc_first_sec
->output_offset
10238 + htab
->toc_first_sec
->output_section
->vma
);
10239 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
10240 elf_gp (isec
->owner
) = off
;
10245 /* Called via elf_link_hash_traverse to merge GOT entries for global
10249 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
10251 if (h
->root
.type
== bfd_link_hash_indirect
)
10254 merge_got_entries (&h
->got
.glist
);
10259 /* Called via elf_link_hash_traverse to allocate GOT entries for global
10263 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
10265 struct got_entry
*gent
;
10267 if (h
->root
.type
== bfd_link_hash_indirect
)
10270 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
10271 if (!gent
->is_indirect
)
10272 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
10276 /* Called on the first multitoc pass after the last call to
10277 ppc64_elf_next_toc_section. This function removes duplicate GOT
10281 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
10283 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10284 struct bfd
*ibfd
, *ibfd2
;
10285 bfd_boolean done_something
;
10287 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
10289 if (!htab
->do_multi_toc
)
10292 /* Merge global sym got entries within a toc group. */
10293 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
10295 /* And tlsld_got. */
10296 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10298 struct got_entry
*ent
, *ent2
;
10300 if (!is_ppc64_elf (ibfd
))
10303 ent
= ppc64_tlsld_got (ibfd
);
10304 if (!ent
->is_indirect
10305 && ent
->got
.offset
!= (bfd_vma
) -1)
10307 for (ibfd2
= ibfd
->link_next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link_next
)
10309 if (!is_ppc64_elf (ibfd2
))
10312 ent2
= ppc64_tlsld_got (ibfd2
);
10313 if (!ent2
->is_indirect
10314 && ent2
->got
.offset
!= (bfd_vma
) -1
10315 && elf_gp (ibfd2
) == elf_gp (ibfd
))
10317 ent2
->is_indirect
= TRUE
;
10318 ent2
->got
.ent
= ent
;
10324 /* Zap sizes of got sections. */
10325 htab
->reliplt
->rawsize
= htab
->reliplt
->size
;
10326 htab
->reliplt
->size
-= htab
->got_reli_size
;
10327 htab
->got_reli_size
= 0;
10329 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10331 asection
*got
, *relgot
;
10333 if (!is_ppc64_elf (ibfd
))
10336 got
= ppc64_elf_tdata (ibfd
)->got
;
10339 got
->rawsize
= got
->size
;
10341 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
10342 relgot
->rawsize
= relgot
->size
;
10347 /* Now reallocate the got, local syms first. We don't need to
10348 allocate section contents again since we never increase size. */
10349 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10351 struct got_entry
**lgot_ents
;
10352 struct got_entry
**end_lgot_ents
;
10353 struct plt_entry
**local_plt
;
10354 struct plt_entry
**end_local_plt
;
10355 unsigned char *lgot_masks
;
10356 bfd_size_type locsymcount
;
10357 Elf_Internal_Shdr
*symtab_hdr
;
10358 asection
*s
, *srel
;
10360 if (!is_ppc64_elf (ibfd
))
10363 lgot_ents
= elf_local_got_ents (ibfd
);
10367 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10368 locsymcount
= symtab_hdr
->sh_info
;
10369 end_lgot_ents
= lgot_ents
+ locsymcount
;
10370 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10371 end_local_plt
= local_plt
+ locsymcount
;
10372 lgot_masks
= (unsigned char *) end_local_plt
;
10373 s
= ppc64_elf_tdata (ibfd
)->got
;
10374 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10375 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10377 struct got_entry
*ent
;
10379 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
10381 unsigned int num
= 1;
10382 ent
->got
.offset
= s
->size
;
10383 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10385 s
->size
+= num
* 8;
10387 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
10388 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
10390 htab
->reliplt
->size
10391 += num
* sizeof (Elf64_External_Rela
);
10392 htab
->got_reli_size
10393 += num
* sizeof (Elf64_External_Rela
);
10399 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
10401 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10403 struct got_entry
*ent
;
10405 if (!is_ppc64_elf (ibfd
))
10408 ent
= ppc64_tlsld_got (ibfd
);
10409 if (!ent
->is_indirect
10410 && ent
->got
.offset
!= (bfd_vma
) -1)
10412 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
10413 ent
->got
.offset
= s
->size
;
10417 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10418 srel
->size
+= sizeof (Elf64_External_Rela
);
10423 done_something
= htab
->reliplt
->rawsize
!= htab
->reliplt
->size
;
10424 if (!done_something
)
10425 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10429 if (!is_ppc64_elf (ibfd
))
10432 got
= ppc64_elf_tdata (ibfd
)->got
;
10435 done_something
= got
->rawsize
!= got
->size
;
10436 if (done_something
)
10441 if (done_something
)
10442 (*htab
->layout_sections_again
) ();
10444 /* Set up for second pass over toc sections to recalculate elf_gp
10445 on input sections. */
10446 htab
->toc_bfd
= NULL
;
10447 htab
->toc_first_sec
= NULL
;
10448 htab
->second_toc_pass
= TRUE
;
10449 return done_something
;
10452 /* Called after second pass of multitoc partitioning. */
10455 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
10457 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10459 /* After the second pass, toc_curr tracks the TOC offset used
10460 for code sections below in ppc64_elf_next_input_section. */
10461 htab
->toc_curr
= TOC_BASE_OFF
;
10464 /* No toc references were found in ISEC. If the code in ISEC makes no
10465 calls, then there's no need to use toc adjusting stubs when branching
10466 into ISEC. Actually, indirect calls from ISEC are OK as they will
10467 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
10468 needed, and 2 if a cyclical call-graph was found but no other reason
10469 for a stub was detected. If called from the top level, a return of
10470 2 means the same as a return of 0. */
10473 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
10477 /* Mark this section as checked. */
10478 isec
->call_check_done
= 1;
10480 /* We know none of our code bearing sections will need toc stubs. */
10481 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
10484 if (isec
->size
== 0)
10487 if (isec
->output_section
== NULL
)
10491 if (isec
->reloc_count
!= 0)
10493 Elf_Internal_Rela
*relstart
, *rel
;
10494 Elf_Internal_Sym
*local_syms
;
10495 struct ppc_link_hash_table
*htab
;
10497 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
10498 info
->keep_memory
);
10499 if (relstart
== NULL
)
10502 /* Look for branches to outside of this section. */
10504 htab
= ppc_hash_table (info
);
10508 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
10510 enum elf_ppc64_reloc_type r_type
;
10511 unsigned long r_symndx
;
10512 struct elf_link_hash_entry
*h
;
10513 struct ppc_link_hash_entry
*eh
;
10514 Elf_Internal_Sym
*sym
;
10516 struct _opd_sec_data
*opd
;
10520 r_type
= ELF64_R_TYPE (rel
->r_info
);
10521 if (r_type
!= R_PPC64_REL24
10522 && r_type
!= R_PPC64_REL14
10523 && r_type
!= R_PPC64_REL14_BRTAKEN
10524 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
10527 r_symndx
= ELF64_R_SYM (rel
->r_info
);
10528 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
10535 /* Calls to dynamic lib functions go through a plt call stub
10537 eh
= (struct ppc_link_hash_entry
*) h
;
10539 && (eh
->elf
.plt
.plist
!= NULL
10541 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
10547 if (sym_sec
== NULL
)
10548 /* Ignore other undefined symbols. */
10551 /* Assume branches to other sections not included in the
10552 link need stubs too, to cover -R and absolute syms. */
10553 if (sym_sec
->output_section
== NULL
)
10560 sym_value
= sym
->st_value
;
10563 if (h
->root
.type
!= bfd_link_hash_defined
10564 && h
->root
.type
!= bfd_link_hash_defweak
)
10566 sym_value
= h
->root
.u
.def
.value
;
10568 sym_value
+= rel
->r_addend
;
10570 /* If this branch reloc uses an opd sym, find the code section. */
10571 opd
= get_opd_info (sym_sec
);
10574 if (h
== NULL
&& opd
->adjust
!= NULL
)
10578 adjust
= opd
->adjust
[sym
->st_value
/ 8];
10580 /* Assume deleted functions won't ever be called. */
10582 sym_value
+= adjust
;
10585 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
10586 if (dest
== (bfd_vma
) -1)
10591 + sym_sec
->output_offset
10592 + sym_sec
->output_section
->vma
);
10594 /* Ignore branch to self. */
10595 if (sym_sec
== isec
)
10598 /* If the called function uses the toc, we need a stub. */
10599 if (sym_sec
->has_toc_reloc
10600 || sym_sec
->makes_toc_func_call
)
10606 /* Assume any branch that needs a long branch stub might in fact
10607 need a plt_branch stub. A plt_branch stub uses r2. */
10608 else if (dest
- (isec
->output_offset
10609 + isec
->output_section
->vma
10610 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
10616 /* If calling back to a section in the process of being
10617 tested, we can't say for sure that no toc adjusting stubs
10618 are needed, so don't return zero. */
10619 else if (sym_sec
->call_check_in_progress
)
10622 /* Branches to another section that itself doesn't have any TOC
10623 references are OK. Recursively call ourselves to check. */
10624 else if (!sym_sec
->call_check_done
)
10628 /* Mark current section as indeterminate, so that other
10629 sections that call back to current won't be marked as
10631 isec
->call_check_in_progress
= 1;
10632 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
10633 isec
->call_check_in_progress
= 0;
10644 if (local_syms
!= NULL
10645 && (elf_symtab_hdr (isec
->owner
).contents
10646 != (unsigned char *) local_syms
))
10648 if (elf_section_data (isec
)->relocs
!= relstart
)
10653 && isec
->map_head
.s
!= NULL
10654 && (strcmp (isec
->output_section
->name
, ".init") == 0
10655 || strcmp (isec
->output_section
->name
, ".fini") == 0))
10657 if (isec
->map_head
.s
->has_toc_reloc
10658 || isec
->map_head
.s
->makes_toc_func_call
)
10660 else if (!isec
->map_head
.s
->call_check_done
)
10663 isec
->call_check_in_progress
= 1;
10664 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
10665 isec
->call_check_in_progress
= 0;
10672 isec
->makes_toc_func_call
= 1;
10677 /* The linker repeatedly calls this function for each input section,
10678 in the order that input sections are linked into output sections.
10679 Build lists of input sections to determine groupings between which
10680 we may insert linker stubs. */
10683 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
10685 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10690 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
10691 && isec
->output_section
->index
<= htab
->top_index
)
10693 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
10694 /* Steal the link_sec pointer for our list. */
10695 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
10696 /* This happens to make the list in reverse order,
10697 which is what we want. */
10698 PREV_SEC (isec
) = *list
;
10702 if (htab
->multi_toc_needed
)
10704 /* If a code section has a function that uses the TOC then we need
10705 to use the right TOC (obviously). Also, make sure that .opd gets
10706 the correct TOC value for R_PPC64_TOC relocs that don't have or
10707 can't find their function symbol (shouldn't ever happen now).
10708 Also specially treat .fixup for the linux kernel. .fixup
10709 contains branches, but only back to the function that hit an
10711 if (isec
->has_toc_reloc
10712 || (isec
->flags
& SEC_CODE
) == 0
10713 || strcmp (isec
->name
, ".fixup") == 0)
10715 if (elf_gp (isec
->owner
) != 0)
10716 htab
->toc_curr
= elf_gp (isec
->owner
);
10720 if (!isec
->call_check_done
10721 && toc_adjusting_stub_needed (info
, isec
) < 0)
10723 /* If we make a local call from this section, ie. a branch
10724 without a following nop, then we have no place to put a
10725 toc restoring insn. We must use the same toc group as
10727 Testing makes_toc_func_call actually tests for *any*
10728 calls to functions that need a good toc pointer. A more
10729 precise test would be better, as this one will set
10730 incorrect values for pasted .init/.fini fragments.
10731 (Fixed later in check_pasted_section.) */
10732 if (isec
->makes_toc_func_call
10733 && elf_gp (isec
->owner
) != 0)
10734 htab
->toc_curr
= elf_gp (isec
->owner
);
10738 /* Functions that don't use the TOC can belong in any TOC group.
10739 Use the last TOC base. */
10740 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
10744 /* Check that all .init and .fini sections use the same toc, if they
10745 have toc relocs. */
10748 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
10750 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
10754 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10755 bfd_vma toc_off
= 0;
10758 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10759 if (i
->has_toc_reloc
)
10762 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10763 else if (toc_off
!= htab
->stub_group
[i
->id
].toc_off
)
10768 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10769 if (i
->makes_toc_func_call
)
10771 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10775 /* Make sure the whole pasted function uses the same toc offset. */
10777 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10778 htab
->stub_group
[i
->id
].toc_off
= toc_off
;
10784 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
10786 return (check_pasted_section (info
, ".init")
10787 & check_pasted_section (info
, ".fini"));
10790 /* See whether we can group stub sections together. Grouping stub
10791 sections may result in fewer stubs. More importantly, we need to
10792 put all .init* and .fini* stubs at the beginning of the .init or
10793 .fini output sections respectively, because glibc splits the
10794 _init and _fini functions into multiple parts. Putting a stub in
10795 the middle of a function is not a good idea. */
10798 group_sections (struct ppc_link_hash_table
*htab
,
10799 bfd_size_type stub_group_size
,
10800 bfd_boolean stubs_always_before_branch
)
10803 bfd_size_type stub14_group_size
;
10804 bfd_boolean suppress_size_errors
;
10806 suppress_size_errors
= FALSE
;
10807 stub14_group_size
= stub_group_size
;
10808 if (stub_group_size
== 1)
10810 /* Default values. */
10811 if (stubs_always_before_branch
)
10813 stub_group_size
= 0x1e00000;
10814 stub14_group_size
= 0x7800;
10818 stub_group_size
= 0x1c00000;
10819 stub14_group_size
= 0x7000;
10821 suppress_size_errors
= TRUE
;
10824 list
= htab
->input_list
+ htab
->top_index
;
10827 asection
*tail
= *list
;
10828 while (tail
!= NULL
)
10832 bfd_size_type total
;
10833 bfd_boolean big_sec
;
10837 total
= tail
->size
;
10838 big_sec
= total
> (ppc64_elf_section_data (tail
) != NULL
10839 && ppc64_elf_section_data (tail
)->has_14bit_branch
10840 ? stub14_group_size
: stub_group_size
);
10841 if (big_sec
&& !suppress_size_errors
)
10842 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
10843 tail
->owner
, tail
);
10844 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
10846 while ((prev
= PREV_SEC (curr
)) != NULL
10847 && ((total
+= curr
->output_offset
- prev
->output_offset
)
10848 < (ppc64_elf_section_data (prev
) != NULL
10849 && ppc64_elf_section_data (prev
)->has_14bit_branch
10850 ? stub14_group_size
: stub_group_size
))
10851 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10854 /* OK, the size from the start of CURR to the end is less
10855 than stub_group_size and thus can be handled by one stub
10856 section. (or the tail section is itself larger than
10857 stub_group_size, in which case we may be toast.) We
10858 should really be keeping track of the total size of stubs
10859 added here, as stubs contribute to the final output
10860 section size. That's a little tricky, and this way will
10861 only break if stubs added make the total size more than
10862 2^25, ie. for the default stub_group_size, if stubs total
10863 more than 2097152 bytes, or nearly 75000 plt call stubs. */
10866 prev
= PREV_SEC (tail
);
10867 /* Set up this stub group. */
10868 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10870 while (tail
!= curr
&& (tail
= prev
) != NULL
);
10872 /* But wait, there's more! Input sections up to stub_group_size
10873 bytes before the stub section can be handled by it too.
10874 Don't do this if we have a really large section after the
10875 stubs, as adding more stubs increases the chance that
10876 branches may not reach into the stub section. */
10877 if (!stubs_always_before_branch
&& !big_sec
)
10880 while (prev
!= NULL
10881 && ((total
+= tail
->output_offset
- prev
->output_offset
)
10882 < (ppc64_elf_section_data (prev
) != NULL
10883 && ppc64_elf_section_data (prev
)->has_14bit_branch
10884 ? stub14_group_size
: stub_group_size
))
10885 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10888 prev
= PREV_SEC (tail
);
10889 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10895 while (list
-- != htab
->input_list
);
10896 free (htab
->input_list
);
10900 static const unsigned char glink_eh_frame_cie
[] =
10902 0, 0, 0, 16, /* length. */
10903 0, 0, 0, 0, /* id. */
10904 1, /* CIE version. */
10905 'z', 'R', 0, /* Augmentation string. */
10906 4, /* Code alignment. */
10907 0x78, /* Data alignment. */
10909 1, /* Augmentation size. */
10910 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
10911 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
10914 /* Stripping output sections is normally done before dynamic section
10915 symbols have been allocated. This function is called later, and
10916 handles cases like htab->brlt which is mapped to its own output
10920 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
10922 if (isec
->size
== 0
10923 && isec
->output_section
->size
== 0
10924 && !bfd_section_removed_from_list (info
->output_bfd
,
10925 isec
->output_section
)
10926 && elf_section_data (isec
->output_section
)->dynindx
== 0)
10928 isec
->output_section
->flags
|= SEC_EXCLUDE
;
10929 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
10930 info
->output_bfd
->section_count
--;
10934 /* Determine and set the size of the stub section for a final link.
10936 The basic idea here is to examine all the relocations looking for
10937 PC-relative calls to a target that is unreachable with a "bl"
10941 ppc64_elf_size_stubs (struct bfd_link_info
*info
, bfd_signed_vma group_size
,
10942 bfd_boolean plt_static_chain
)
10944 bfd_size_type stub_group_size
;
10945 bfd_boolean stubs_always_before_branch
;
10946 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10951 htab
->plt_static_chain
= plt_static_chain
;
10952 stubs_always_before_branch
= group_size
< 0;
10953 if (group_size
< 0)
10954 stub_group_size
= -group_size
;
10956 stub_group_size
= group_size
;
10958 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
10963 unsigned int bfd_indx
;
10964 asection
*stub_sec
;
10966 htab
->stub_iteration
+= 1;
10968 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
10970 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
10972 Elf_Internal_Shdr
*symtab_hdr
;
10974 Elf_Internal_Sym
*local_syms
= NULL
;
10976 if (!is_ppc64_elf (input_bfd
))
10979 /* We'll need the symbol table in a second. */
10980 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
10981 if (symtab_hdr
->sh_info
== 0)
10984 /* Walk over each section attached to the input bfd. */
10985 for (section
= input_bfd
->sections
;
10987 section
= section
->next
)
10989 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
10991 /* If there aren't any relocs, then there's nothing more
10993 if ((section
->flags
& SEC_RELOC
) == 0
10994 || (section
->flags
& SEC_ALLOC
) == 0
10995 || (section
->flags
& SEC_LOAD
) == 0
10996 || (section
->flags
& SEC_CODE
) == 0
10997 || section
->reloc_count
== 0)
11000 /* If this section is a link-once section that will be
11001 discarded, then don't create any stubs. */
11002 if (section
->output_section
== NULL
11003 || section
->output_section
->owner
!= info
->output_bfd
)
11006 /* Get the relocs. */
11008 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
11009 info
->keep_memory
);
11010 if (internal_relocs
== NULL
)
11011 goto error_ret_free_local
;
11013 /* Now examine each relocation. */
11014 irela
= internal_relocs
;
11015 irelaend
= irela
+ section
->reloc_count
;
11016 for (; irela
< irelaend
; irela
++)
11018 enum elf_ppc64_reloc_type r_type
;
11019 unsigned int r_indx
;
11020 enum ppc_stub_type stub_type
;
11021 struct ppc_stub_hash_entry
*stub_entry
;
11022 asection
*sym_sec
, *code_sec
;
11023 bfd_vma sym_value
, code_value
;
11024 bfd_vma destination
;
11025 bfd_boolean ok_dest
;
11026 struct ppc_link_hash_entry
*hash
;
11027 struct ppc_link_hash_entry
*fdh
;
11028 struct elf_link_hash_entry
*h
;
11029 Elf_Internal_Sym
*sym
;
11031 const asection
*id_sec
;
11032 struct _opd_sec_data
*opd
;
11033 struct plt_entry
*plt_ent
;
11035 r_type
= ELF64_R_TYPE (irela
->r_info
);
11036 r_indx
= ELF64_R_SYM (irela
->r_info
);
11038 if (r_type
>= R_PPC64_max
)
11040 bfd_set_error (bfd_error_bad_value
);
11041 goto error_ret_free_internal
;
11044 /* Only look for stubs on branch instructions. */
11045 if (r_type
!= R_PPC64_REL24
11046 && r_type
!= R_PPC64_REL14
11047 && r_type
!= R_PPC64_REL14_BRTAKEN
11048 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11051 /* Now determine the call target, its name, value,
11053 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
11054 r_indx
, input_bfd
))
11055 goto error_ret_free_internal
;
11056 hash
= (struct ppc_link_hash_entry
*) h
;
11063 sym_value
= sym
->st_value
;
11066 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
11067 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
11069 sym_value
= hash
->elf
.root
.u
.def
.value
;
11070 if (sym_sec
->output_section
!= NULL
)
11073 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
11074 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
11076 /* Recognise an old ABI func code entry sym, and
11077 use the func descriptor sym instead if it is
11079 if (hash
->elf
.root
.root
.string
[0] == '.'
11080 && (fdh
= lookup_fdh (hash
, htab
)) != NULL
)
11082 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
11083 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
11085 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
11086 sym_value
= fdh
->elf
.root
.u
.def
.value
;
11087 if (sym_sec
->output_section
!= NULL
)
11096 bfd_set_error (bfd_error_bad_value
);
11097 goto error_ret_free_internal
;
11103 sym_value
+= irela
->r_addend
;
11104 destination
= (sym_value
11105 + sym_sec
->output_offset
11106 + sym_sec
->output_section
->vma
);
11109 code_sec
= sym_sec
;
11110 code_value
= sym_value
;
11111 opd
= get_opd_info (sym_sec
);
11116 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11118 long adjust
= opd
->adjust
[sym_value
/ 8];
11121 code_value
+= adjust
;
11122 sym_value
+= adjust
;
11124 dest
= opd_entry_value (sym_sec
, sym_value
,
11125 &code_sec
, &code_value
);
11126 if (dest
!= (bfd_vma
) -1)
11128 destination
= dest
;
11131 /* Fixup old ABI sym to point at code
11133 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11134 hash
->elf
.root
.u
.def
.section
= code_sec
;
11135 hash
->elf
.root
.u
.def
.value
= code_value
;
11140 /* Determine what (if any) linker stub is needed. */
11142 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11143 &plt_ent
, destination
);
11145 if (stub_type
!= ppc_stub_plt_call
)
11147 /* Check whether we need a TOC adjusting stub.
11148 Since the linker pastes together pieces from
11149 different object files when creating the
11150 _init and _fini functions, it may be that a
11151 call to what looks like a local sym is in
11152 fact a call needing a TOC adjustment. */
11153 if (code_sec
!= NULL
11154 && code_sec
->output_section
!= NULL
11155 && (htab
->stub_group
[code_sec
->id
].toc_off
11156 != htab
->stub_group
[section
->id
].toc_off
)
11157 && (code_sec
->has_toc_reloc
11158 || code_sec
->makes_toc_func_call
))
11159 stub_type
= ppc_stub_long_branch_r2off
;
11162 if (stub_type
== ppc_stub_none
)
11165 /* __tls_get_addr calls might be eliminated. */
11166 if (stub_type
!= ppc_stub_plt_call
11168 && (hash
== htab
->tls_get_addr
11169 || hash
== htab
->tls_get_addr_fd
)
11170 && section
->has_tls_reloc
11171 && irela
!= internal_relocs
)
11173 /* Get tls info. */
11174 unsigned char *tls_mask
;
11176 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
11177 irela
- 1, input_bfd
))
11178 goto error_ret_free_internal
;
11179 if (*tls_mask
!= 0)
11183 /* Support for grouping stub sections. */
11184 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
11186 /* Get the name of this stub. */
11187 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
11189 goto error_ret_free_internal
;
11191 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
11192 stub_name
, FALSE
, FALSE
);
11193 if (stub_entry
!= NULL
)
11195 /* The proper stub has already been created. */
11200 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
11201 if (stub_entry
== NULL
)
11204 error_ret_free_internal
:
11205 if (elf_section_data (section
)->relocs
== NULL
)
11206 free (internal_relocs
);
11207 error_ret_free_local
:
11208 if (local_syms
!= NULL
11209 && (symtab_hdr
->contents
11210 != (unsigned char *) local_syms
))
11215 stub_entry
->stub_type
= stub_type
;
11216 if (stub_type
!= ppc_stub_plt_call
)
11218 stub_entry
->target_value
= code_value
;
11219 stub_entry
->target_section
= code_sec
;
11223 stub_entry
->target_value
= sym_value
;
11224 stub_entry
->target_section
= sym_sec
;
11226 stub_entry
->h
= hash
;
11227 stub_entry
->plt_ent
= plt_ent
;
11228 stub_entry
->addend
= irela
->r_addend
;
11230 if (stub_entry
->h
!= NULL
)
11231 htab
->stub_globals
+= 1;
11234 /* We're done with the internal relocs, free them. */
11235 if (elf_section_data (section
)->relocs
!= internal_relocs
)
11236 free (internal_relocs
);
11239 if (local_syms
!= NULL
11240 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
11242 if (!info
->keep_memory
)
11245 symtab_hdr
->contents
= (unsigned char *) local_syms
;
11249 /* We may have added some stubs. Find out the new size of the
11251 for (stub_sec
= htab
->stub_bfd
->sections
;
11253 stub_sec
= stub_sec
->next
)
11254 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11256 stub_sec
->rawsize
= stub_sec
->size
;
11257 stub_sec
->size
= 0;
11258 stub_sec
->reloc_count
= 0;
11259 stub_sec
->flags
&= ~SEC_RELOC
;
11262 htab
->brlt
->size
= 0;
11263 htab
->brlt
->reloc_count
= 0;
11264 htab
->brlt
->flags
&= ~SEC_RELOC
;
11265 if (htab
->relbrlt
!= NULL
)
11266 htab
->relbrlt
->size
= 0;
11268 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
11270 if (info
->emitrelocations
11271 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11273 htab
->glink
->reloc_count
= 1;
11274 htab
->glink
->flags
|= SEC_RELOC
;
11277 if (htab
->glink_eh_frame
!= NULL
11278 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
11279 && (htab
->glink_eh_frame
->flags
& SEC_EXCLUDE
) == 0)
11281 bfd_size_type size
= 0;
11283 for (stub_sec
= htab
->stub_bfd
->sections
;
11285 stub_sec
= stub_sec
->next
)
11286 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11288 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11291 size
+= sizeof (glink_eh_frame_cie
);
11292 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
11293 htab
->glink_eh_frame
->size
= size
;
11296 for (stub_sec
= htab
->stub_bfd
->sections
;
11298 stub_sec
= stub_sec
->next
)
11299 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11300 && stub_sec
->rawsize
!= stub_sec
->size
)
11303 /* Exit from this loop when no stubs have been added, and no stubs
11304 have changed size. */
11305 if (stub_sec
== NULL
11306 && (htab
->glink_eh_frame
== NULL
11307 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
11310 /* Ask the linker to do its stuff. */
11311 (*htab
->layout_sections_again
) ();
11314 maybe_strip_output (info
, htab
->brlt
);
11315 if (htab
->glink_eh_frame
!= NULL
)
11316 maybe_strip_output (info
, htab
->glink_eh_frame
);
11321 /* Called after we have determined section placement. If sections
11322 move, we'll be called again. Provide a value for TOCstart. */
11325 ppc64_elf_toc (bfd
*obfd
)
11330 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
11331 order. The TOC starts where the first of these sections starts. */
11332 s
= bfd_get_section_by_name (obfd
, ".got");
11333 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11334 s
= bfd_get_section_by_name (obfd
, ".toc");
11335 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11336 s
= bfd_get_section_by_name (obfd
, ".tocbss");
11337 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11338 s
= bfd_get_section_by_name (obfd
, ".plt");
11339 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11341 /* This may happen for
11342 o references to TOC base (SYM@toc / TOC[tc0]) without a
11344 o bad linker script
11345 o --gc-sections and empty TOC sections
11347 FIXME: Warn user? */
11349 /* Look for a likely section. We probably won't even be
11351 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11352 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
11354 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11357 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11358 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
11359 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11362 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11363 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
11367 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11368 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
11374 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
11379 /* Build all the stubs associated with the current output file.
11380 The stubs are kept in a hash table attached to the main linker
11381 hash table. This function is called via gldelf64ppc_finish. */
11384 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
11385 struct bfd_link_info
*info
,
11388 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11389 asection
*stub_sec
;
11391 int stub_sec_count
= 0;
11396 htab
->emit_stub_syms
= emit_stub_syms
;
11398 /* Allocate memory to hold the linker stubs. */
11399 for (stub_sec
= htab
->stub_bfd
->sections
;
11401 stub_sec
= stub_sec
->next
)
11402 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11403 && stub_sec
->size
!= 0)
11405 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
11406 if (stub_sec
->contents
== NULL
)
11408 /* We want to check that built size is the same as calculated
11409 size. rawsize is a convenient location to use. */
11410 stub_sec
->rawsize
= stub_sec
->size
;
11411 stub_sec
->size
= 0;
11414 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11419 /* Build the .glink plt call stub. */
11420 if (htab
->emit_stub_syms
)
11422 struct elf_link_hash_entry
*h
;
11423 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
11424 TRUE
, FALSE
, FALSE
);
11427 if (h
->root
.type
== bfd_link_hash_new
)
11429 h
->root
.type
= bfd_link_hash_defined
;
11430 h
->root
.u
.def
.section
= htab
->glink
;
11431 h
->root
.u
.def
.value
= 8;
11432 h
->ref_regular
= 1;
11433 h
->def_regular
= 1;
11434 h
->ref_regular_nonweak
= 1;
11435 h
->forced_local
= 1;
11439 plt0
= htab
->plt
->output_section
->vma
+ htab
->plt
->output_offset
- 16;
11440 if (info
->emitrelocations
)
11442 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
11445 r
->r_offset
= (htab
->glink
->output_offset
11446 + htab
->glink
->output_section
->vma
);
11447 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
11448 r
->r_addend
= plt0
;
11450 p
= htab
->glink
->contents
;
11451 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
11452 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
11454 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
11456 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
11458 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
11460 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
11462 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
11464 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
11466 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
11468 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
11470 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
11472 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
11474 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
11476 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
11478 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
11482 /* Build the .glink lazy link call stubs. */
11484 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
11488 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
11493 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
11495 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
11498 bfd_put_32 (htab
->glink
->owner
,
11499 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
11503 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
11506 if (htab
->brlt
->size
!= 0)
11508 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
11510 if (htab
->brlt
->contents
== NULL
)
11513 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
11515 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
11516 htab
->relbrlt
->size
);
11517 if (htab
->relbrlt
->contents
== NULL
)
11521 if (htab
->glink_eh_frame
!= NULL
11522 && htab
->glink_eh_frame
->size
!= 0)
11526 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
11529 htab
->glink_eh_frame
->contents
= p
;
11531 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
11533 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
11534 /* CIE length (rewrite in case little-endian). */
11535 bfd_put_32 (htab
->elf
.dynobj
, sizeof (glink_eh_frame_cie
) - 4, p
);
11536 p
+= sizeof (glink_eh_frame_cie
);
11538 for (stub_sec
= htab
->stub_bfd
->sections
;
11540 stub_sec
= stub_sec
->next
)
11541 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11544 bfd_put_32 (htab
->elf
.dynobj
, 16, p
);
11547 val
= p
- htab
->glink_eh_frame
->contents
;
11548 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11550 /* Offset to stub section. */
11551 val
= (stub_sec
->output_section
->vma
11552 + stub_sec
->output_offset
);
11553 val
-= (htab
->glink_eh_frame
->output_section
->vma
11554 + htab
->glink_eh_frame
->output_offset
);
11555 val
-= p
- htab
->glink_eh_frame
->contents
;
11556 if (val
+ 0x80000000 > 0xffffffff)
11558 info
->callbacks
->einfo
11559 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
11563 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11565 /* stub section size. */
11566 bfd_put_32 (htab
->elf
.dynobj
, stub_sec
->rawsize
, p
);
11568 /* Augmentation. */
11573 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11576 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
11579 val
= p
- htab
->glink_eh_frame
->contents
;
11580 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11582 /* Offset to .glink. */
11583 val
= (htab
->glink
->output_section
->vma
11584 + htab
->glink
->output_offset
11586 val
-= (htab
->glink_eh_frame
->output_section
->vma
11587 + htab
->glink_eh_frame
->output_offset
);
11588 val
-= p
- htab
->glink_eh_frame
->contents
;
11589 if (val
+ 0x80000000 > 0xffffffff)
11591 info
->callbacks
->einfo
11592 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
11593 htab
->glink
->name
);
11596 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11599 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->rawsize
- 8, p
);
11601 /* Augmentation. */
11604 *p
++ = DW_CFA_advance_loc
+ 1;
11605 *p
++ = DW_CFA_register
;
11608 *p
++ = DW_CFA_advance_loc
+ 4;
11609 *p
++ = DW_CFA_restore_extended
;
11612 htab
->glink_eh_frame
->size
= p
- htab
->glink_eh_frame
->contents
;
11615 /* Build the stubs as directed by the stub hash table. */
11616 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
11618 if (htab
->relbrlt
!= NULL
)
11619 htab
->relbrlt
->reloc_count
= 0;
11621 for (stub_sec
= htab
->stub_bfd
->sections
;
11623 stub_sec
= stub_sec
->next
)
11624 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11626 stub_sec_count
+= 1;
11627 if (stub_sec
->rawsize
!= stub_sec
->size
)
11631 if (stub_sec
!= NULL
11632 || htab
->glink
->rawsize
!= htab
->glink
->size
11633 || (htab
->glink_eh_frame
!= NULL
11634 && htab
->glink_eh_frame
->rawsize
!= htab
->glink_eh_frame
->size
))
11636 htab
->stub_error
= TRUE
;
11637 info
->callbacks
->einfo (_("%P: stubs don't match calculated size\n"));
11640 if (htab
->stub_error
)
11645 *stats
= bfd_malloc (500);
11646 if (*stats
== NULL
)
11649 sprintf (*stats
, _("linker stubs in %u group%s\n"
11651 " toc adjust %lu\n"
11652 " long branch %lu\n"
11653 " long toc adj %lu\n"
11656 stub_sec_count
== 1 ? "" : "s",
11657 htab
->stub_count
[ppc_stub_long_branch
- 1],
11658 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
11659 htab
->stub_count
[ppc_stub_plt_branch
- 1],
11660 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
11661 htab
->stub_count
[ppc_stub_plt_call
- 1]);
11666 /* This function undoes the changes made by add_symbol_adjust. */
11669 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11671 struct ppc_link_hash_entry
*eh
;
11673 if (h
->root
.type
== bfd_link_hash_indirect
)
11676 eh
= (struct ppc_link_hash_entry
*) h
;
11677 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
11680 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
11685 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
11687 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11690 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
11693 /* What to do when ld finds relocations against symbols defined in
11694 discarded sections. */
11696 static unsigned int
11697 ppc64_elf_action_discarded (asection
*sec
)
11699 if (strcmp (".opd", sec
->name
) == 0)
11702 if (strcmp (".toc", sec
->name
) == 0)
11705 if (strcmp (".toc1", sec
->name
) == 0)
11708 return _bfd_elf_default_action_discarded (sec
);
11711 /* The RELOCATE_SECTION function is called by the ELF backend linker
11712 to handle the relocations for a section.
11714 The relocs are always passed as Rela structures; if the section
11715 actually uses Rel structures, the r_addend field will always be
11718 This function is responsible for adjust the section contents as
11719 necessary, and (if using Rela relocs and generating a
11720 relocatable output file) adjusting the reloc addend as
11723 This function does not have to worry about setting the reloc
11724 address or the reloc symbol index.
11726 LOCAL_SYMS is a pointer to the swapped in local symbols.
11728 LOCAL_SECTIONS is an array giving the section in the input file
11729 corresponding to the st_shndx field of each local symbol.
11731 The global hash table entry for the global symbols can be found
11732 via elf_sym_hashes (input_bfd).
11734 When generating relocatable output, this function must handle
11735 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
11736 going to be the section symbol corresponding to the output
11737 section, which means that the addend must be adjusted
11741 ppc64_elf_relocate_section (bfd
*output_bfd
,
11742 struct bfd_link_info
*info
,
11744 asection
*input_section
,
11745 bfd_byte
*contents
,
11746 Elf_Internal_Rela
*relocs
,
11747 Elf_Internal_Sym
*local_syms
,
11748 asection
**local_sections
)
11750 struct ppc_link_hash_table
*htab
;
11751 Elf_Internal_Shdr
*symtab_hdr
;
11752 struct elf_link_hash_entry
**sym_hashes
;
11753 Elf_Internal_Rela
*rel
;
11754 Elf_Internal_Rela
*relend
;
11755 Elf_Internal_Rela outrel
;
11757 struct got_entry
**local_got_ents
;
11759 bfd_boolean ret
= TRUE
;
11760 bfd_boolean is_opd
;
11761 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
11762 bfd_boolean is_power4
= FALSE
;
11763 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
11765 /* Initialize howto table if needed. */
11766 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
11769 htab
= ppc_hash_table (info
);
11773 /* Don't relocate stub sections. */
11774 if (input_section
->owner
== htab
->stub_bfd
)
11777 BFD_ASSERT (is_ppc64_elf (input_bfd
));
11779 local_got_ents
= elf_local_got_ents (input_bfd
);
11780 TOCstart
= elf_gp (output_bfd
);
11781 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11782 sym_hashes
= elf_sym_hashes (input_bfd
);
11783 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
11786 relend
= relocs
+ input_section
->reloc_count
;
11787 for (; rel
< relend
; rel
++)
11789 enum elf_ppc64_reloc_type r_type
;
11790 bfd_vma addend
, orig_addend
;
11791 bfd_reloc_status_type r
;
11792 Elf_Internal_Sym
*sym
;
11794 struct elf_link_hash_entry
*h_elf
;
11795 struct ppc_link_hash_entry
*h
;
11796 struct ppc_link_hash_entry
*fdh
;
11797 const char *sym_name
;
11798 unsigned long r_symndx
, toc_symndx
;
11799 bfd_vma toc_addend
;
11800 unsigned char tls_mask
, tls_gd
, tls_type
;
11801 unsigned char sym_type
;
11802 bfd_vma relocation
;
11803 bfd_boolean unresolved_reloc
;
11804 bfd_boolean warned
;
11807 struct ppc_stub_hash_entry
*stub_entry
;
11808 bfd_vma max_br_offset
;
11811 r_type
= ELF64_R_TYPE (rel
->r_info
);
11812 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11814 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
11815 symbol of the previous ADDR64 reloc. The symbol gives us the
11816 proper TOC base to use. */
11817 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
11819 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
11821 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
11827 unresolved_reloc
= FALSE
;
11829 orig_addend
= rel
->r_addend
;
11831 if (r_symndx
< symtab_hdr
->sh_info
)
11833 /* It's a local symbol. */
11834 struct _opd_sec_data
*opd
;
11836 sym
= local_syms
+ r_symndx
;
11837 sec
= local_sections
[r_symndx
];
11838 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
11839 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
11840 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
11841 opd
= get_opd_info (sec
);
11842 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
11844 long adjust
= opd
->adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
11849 /* If this is a relocation against the opd section sym
11850 and we have edited .opd, adjust the reloc addend so
11851 that ld -r and ld --emit-relocs output is correct.
11852 If it is a reloc against some other .opd symbol,
11853 then the symbol value will be adjusted later. */
11854 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
11855 rel
->r_addend
+= adjust
;
11857 relocation
+= adjust
;
11863 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
11864 r_symndx
, symtab_hdr
, sym_hashes
,
11865 h_elf
, sec
, relocation
,
11866 unresolved_reloc
, warned
);
11867 sym_name
= h_elf
->root
.root
.string
;
11868 sym_type
= h_elf
->type
;
11870 h
= (struct ppc_link_hash_entry
*) h_elf
;
11872 if (sec
!= NULL
&& elf_discarded_section (sec
))
11873 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
11875 ppc64_elf_howto_table
[r_type
],
11878 if (info
->relocatable
)
11881 /* TLS optimizations. Replace instruction sequences and relocs
11882 based on information we collected in tls_optimize. We edit
11883 RELOCS so that --emit-relocs will output something sensible
11884 for the final instruction stream. */
11889 tls_mask
= h
->tls_mask
;
11890 else if (local_got_ents
!= NULL
)
11892 struct plt_entry
**local_plt
= (struct plt_entry
**)
11893 (local_got_ents
+ symtab_hdr
->sh_info
);
11894 unsigned char *lgot_masks
= (unsigned char *)
11895 (local_plt
+ symtab_hdr
->sh_info
);
11896 tls_mask
= lgot_masks
[r_symndx
];
11899 && (r_type
== R_PPC64_TLS
11900 || r_type
== R_PPC64_TLSGD
11901 || r_type
== R_PPC64_TLSLD
))
11903 /* Check for toc tls entries. */
11904 unsigned char *toc_tls
;
11906 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11907 &local_syms
, rel
, input_bfd
))
11911 tls_mask
= *toc_tls
;
11914 /* Check that tls relocs are used with tls syms, and non-tls
11915 relocs are used with non-tls syms. */
11916 if (r_symndx
!= STN_UNDEF
11917 && r_type
!= R_PPC64_NONE
11919 || h
->elf
.root
.type
== bfd_link_hash_defined
11920 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
11921 && (IS_PPC64_TLS_RELOC (r_type
)
11922 != (sym_type
== STT_TLS
11923 || (sym_type
== STT_SECTION
11924 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
11927 && (r_type
== R_PPC64_TLS
11928 || r_type
== R_PPC64_TLSGD
11929 || r_type
== R_PPC64_TLSLD
))
11930 /* R_PPC64_TLS is OK against a symbol in the TOC. */
11933 info
->callbacks
->einfo
11934 (!IS_PPC64_TLS_RELOC (r_type
)
11935 ? _("%P: %H: %s used with TLS symbol %s\n")
11936 : _("%P: %H: %s used with non-TLS symbol %s\n"),
11937 input_bfd
, input_section
, rel
->r_offset
,
11938 ppc64_elf_howto_table
[r_type
]->name
,
11942 /* Ensure reloc mapping code below stays sane. */
11943 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
11944 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
11945 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
11946 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
11947 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
11948 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
11949 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
11950 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
11951 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
11952 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
11960 case R_PPC64_LO_DS_OPT
:
11961 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11962 if ((insn
& (0x3f << 26)) != 58u << 26)
11964 insn
+= (14u << 26) - (58u << 26);
11965 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11966 r_type
= R_PPC64_TOC16_LO
;
11967 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11970 case R_PPC64_TOC16
:
11971 case R_PPC64_TOC16_LO
:
11972 case R_PPC64_TOC16_DS
:
11973 case R_PPC64_TOC16_LO_DS
:
11975 /* Check for toc tls entries. */
11976 unsigned char *toc_tls
;
11979 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11980 &local_syms
, rel
, input_bfd
);
11986 tls_mask
= *toc_tls
;
11987 if (r_type
== R_PPC64_TOC16_DS
11988 || r_type
== R_PPC64_TOC16_LO_DS
)
11991 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
11996 /* If we found a GD reloc pair, then we might be
11997 doing a GD->IE transition. */
12000 tls_gd
= TLS_TPRELGD
;
12001 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12004 else if (retval
== 3)
12006 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12014 case R_PPC64_GOT_TPREL16_HI
:
12015 case R_PPC64_GOT_TPREL16_HA
:
12017 && (tls_mask
& TLS_TPREL
) == 0)
12019 rel
->r_offset
-= d_offset
;
12020 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12021 r_type
= R_PPC64_NONE
;
12022 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12026 case R_PPC64_GOT_TPREL16_DS
:
12027 case R_PPC64_GOT_TPREL16_LO_DS
:
12029 && (tls_mask
& TLS_TPREL
) == 0)
12032 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
12034 insn
|= 0x3c0d0000; /* addis 0,13,0 */
12035 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
12036 r_type
= R_PPC64_TPREL16_HA
;
12037 if (toc_symndx
!= 0)
12039 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
12040 rel
->r_addend
= toc_addend
;
12041 /* We changed the symbol. Start over in order to
12042 get h, sym, sec etc. right. */
12047 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12053 && (tls_mask
& TLS_TPREL
) == 0)
12055 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
12056 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
12059 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12060 /* Was PPC64_TLS which sits on insn boundary, now
12061 PPC64_TPREL16_LO which is at low-order half-word. */
12062 rel
->r_offset
+= d_offset
;
12063 r_type
= R_PPC64_TPREL16_LO
;
12064 if (toc_symndx
!= 0)
12066 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
12067 rel
->r_addend
= toc_addend
;
12068 /* We changed the symbol. Start over in order to
12069 get h, sym, sec etc. right. */
12074 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12078 case R_PPC64_GOT_TLSGD16_HI
:
12079 case R_PPC64_GOT_TLSGD16_HA
:
12080 tls_gd
= TLS_TPRELGD
;
12081 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12085 case R_PPC64_GOT_TLSLD16_HI
:
12086 case R_PPC64_GOT_TLSLD16_HA
:
12087 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12090 if ((tls_mask
& tls_gd
) != 0)
12091 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
12092 + R_PPC64_GOT_TPREL16_DS
);
12095 rel
->r_offset
-= d_offset
;
12096 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12097 r_type
= R_PPC64_NONE
;
12099 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12103 case R_PPC64_GOT_TLSGD16
:
12104 case R_PPC64_GOT_TLSGD16_LO
:
12105 tls_gd
= TLS_TPRELGD
;
12106 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12110 case R_PPC64_GOT_TLSLD16
:
12111 case R_PPC64_GOT_TLSLD16_LO
:
12112 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12114 unsigned int insn1
, insn2
, insn3
;
12118 offset
= (bfd_vma
) -1;
12119 /* If not using the newer R_PPC64_TLSGD/LD to mark
12120 __tls_get_addr calls, we must trust that the call
12121 stays with its arg setup insns, ie. that the next
12122 reloc is the __tls_get_addr call associated with
12123 the current reloc. Edit both insns. */
12124 if (input_section
->has_tls_get_addr_call
12125 && rel
+ 1 < relend
12126 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
12127 htab
->tls_get_addr
,
12128 htab
->tls_get_addr_fd
))
12129 offset
= rel
[1].r_offset
;
12130 if ((tls_mask
& tls_gd
) != 0)
12133 insn1
= bfd_get_32 (output_bfd
,
12134 contents
+ rel
->r_offset
- d_offset
);
12135 insn1
&= (1 << 26) - (1 << 2);
12136 insn1
|= 58 << 26; /* ld */
12137 insn2
= 0x7c636a14; /* add 3,3,13 */
12138 if (offset
!= (bfd_vma
) -1)
12139 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12140 if ((tls_mask
& TLS_EXPLICIT
) == 0)
12141 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
12142 + R_PPC64_GOT_TPREL16_DS
);
12144 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
12145 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12150 insn1
= 0x3c6d0000; /* addis 3,13,0 */
12151 insn2
= 0x38630000; /* addi 3,3,0 */
12154 /* Was an LD reloc. */
12156 sec
= local_sections
[toc_symndx
];
12158 r_symndx
< symtab_hdr
->sh_info
;
12160 if (local_sections
[r_symndx
] == sec
)
12162 if (r_symndx
>= symtab_hdr
->sh_info
)
12163 r_symndx
= STN_UNDEF
;
12164 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12165 if (r_symndx
!= STN_UNDEF
)
12166 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12167 + sec
->output_offset
12168 + sec
->output_section
->vma
);
12170 else if (toc_symndx
!= 0)
12172 r_symndx
= toc_symndx
;
12173 rel
->r_addend
= toc_addend
;
12175 r_type
= R_PPC64_TPREL16_HA
;
12176 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12177 if (offset
!= (bfd_vma
) -1)
12179 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
12180 R_PPC64_TPREL16_LO
);
12181 rel
[1].r_offset
= offset
+ d_offset
;
12182 rel
[1].r_addend
= rel
->r_addend
;
12185 bfd_put_32 (output_bfd
, insn1
,
12186 contents
+ rel
->r_offset
- d_offset
);
12187 if (offset
!= (bfd_vma
) -1)
12189 insn3
= bfd_get_32 (output_bfd
,
12190 contents
+ offset
+ 4);
12192 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12194 rel
[1].r_offset
+= 4;
12195 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12198 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12200 if ((tls_mask
& tls_gd
) == 0
12201 && (tls_gd
== 0 || toc_symndx
!= 0))
12203 /* We changed the symbol. Start over in order
12204 to get h, sym, sec etc. right. */
12211 case R_PPC64_TLSGD
:
12212 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12214 unsigned int insn2
, insn3
;
12215 bfd_vma offset
= rel
->r_offset
;
12217 if ((tls_mask
& TLS_TPRELGD
) != 0)
12220 r_type
= R_PPC64_NONE
;
12221 insn2
= 0x7c636a14; /* add 3,3,13 */
12226 if (toc_symndx
!= 0)
12228 r_symndx
= toc_symndx
;
12229 rel
->r_addend
= toc_addend
;
12231 r_type
= R_PPC64_TPREL16_LO
;
12232 rel
->r_offset
= offset
+ d_offset
;
12233 insn2
= 0x38630000; /* addi 3,3,0 */
12235 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12236 /* Zap the reloc on the _tls_get_addr call too. */
12237 BFD_ASSERT (offset
== rel
[1].r_offset
);
12238 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12239 insn3
= bfd_get_32 (output_bfd
,
12240 contents
+ offset
+ 4);
12242 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12244 rel
->r_offset
+= 4;
12245 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12248 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12249 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
12257 case R_PPC64_TLSLD
:
12258 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12260 unsigned int insn2
, insn3
;
12261 bfd_vma offset
= rel
->r_offset
;
12264 sec
= local_sections
[toc_symndx
];
12266 r_symndx
< symtab_hdr
->sh_info
;
12268 if (local_sections
[r_symndx
] == sec
)
12270 if (r_symndx
>= symtab_hdr
->sh_info
)
12271 r_symndx
= STN_UNDEF
;
12272 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12273 if (r_symndx
!= STN_UNDEF
)
12274 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12275 + sec
->output_offset
12276 + sec
->output_section
->vma
);
12278 r_type
= R_PPC64_TPREL16_LO
;
12279 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12280 rel
->r_offset
= offset
+ d_offset
;
12281 /* Zap the reloc on the _tls_get_addr call too. */
12282 BFD_ASSERT (offset
== rel
[1].r_offset
);
12283 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12284 insn2
= 0x38630000; /* addi 3,3,0 */
12285 insn3
= bfd_get_32 (output_bfd
,
12286 contents
+ offset
+ 4);
12288 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12290 rel
->r_offset
+= 4;
12291 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12294 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12300 case R_PPC64_DTPMOD64
:
12301 if (rel
+ 1 < relend
12302 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
12303 && rel
[1].r_offset
== rel
->r_offset
+ 8)
12305 if ((tls_mask
& TLS_GD
) == 0)
12307 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
12308 if ((tls_mask
& TLS_TPRELGD
) != 0)
12309 r_type
= R_PPC64_TPREL64
;
12312 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12313 r_type
= R_PPC64_NONE
;
12315 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12320 if ((tls_mask
& TLS_LD
) == 0)
12322 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12323 r_type
= R_PPC64_NONE
;
12324 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12329 case R_PPC64_TPREL64
:
12330 if ((tls_mask
& TLS_TPREL
) == 0)
12332 r_type
= R_PPC64_NONE
;
12333 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12338 /* Handle other relocations that tweak non-addend part of insn. */
12340 max_br_offset
= 1 << 25;
12341 addend
= rel
->r_addend
;
12347 /* Branch taken prediction relocations. */
12348 case R_PPC64_ADDR14_BRTAKEN
:
12349 case R_PPC64_REL14_BRTAKEN
:
12350 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
12353 /* Branch not taken prediction relocations. */
12354 case R_PPC64_ADDR14_BRNTAKEN
:
12355 case R_PPC64_REL14_BRNTAKEN
:
12356 insn
|= bfd_get_32 (output_bfd
,
12357 contents
+ rel
->r_offset
) & ~(0x01 << 21);
12360 case R_PPC64_REL14
:
12361 max_br_offset
= 1 << 15;
12364 case R_PPC64_REL24
:
12365 /* Calls to functions with a different TOC, such as calls to
12366 shared objects, need to alter the TOC pointer. This is
12367 done using a linkage stub. A REL24 branching to these
12368 linkage stubs needs to be followed by a nop, as the nop
12369 will be replaced with an instruction to restore the TOC
12374 && h
->oh
->is_func_descriptor
)
12375 fdh
= ppc_follow_link (h
->oh
);
12376 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, rel
, htab
);
12377 if (stub_entry
!= NULL
12378 && (stub_entry
->stub_type
== ppc_stub_plt_call
12379 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
12380 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
12382 bfd_boolean can_plt_call
= FALSE
;
12384 if (rel
->r_offset
+ 8 <= input_section
->size
)
12387 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
12389 || nop
== CROR_151515
|| nop
== CROR_313131
)
12392 && (h
== htab
->tls_get_addr_fd
12393 || h
== htab
->tls_get_addr
)
12394 && !htab
->no_tls_get_addr_opt
)
12396 /* Special stub used, leave nop alone. */
12399 bfd_put_32 (input_bfd
, LD_R2_40R1
,
12400 contents
+ rel
->r_offset
+ 4);
12401 can_plt_call
= TRUE
;
12407 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
12409 /* If this is a plain branch rather than a branch
12410 and link, don't require a nop. However, don't
12411 allow tail calls in a shared library as they
12412 will result in r2 being corrupted. */
12414 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
12415 if (info
->executable
&& (br
& 1) == 0)
12416 can_plt_call
= TRUE
;
12421 && strcmp (h
->elf
.root
.root
.string
,
12422 ".__libc_start_main") == 0)
12424 /* Allow crt1 branch to go via a toc adjusting stub. */
12425 can_plt_call
= TRUE
;
12429 if (strcmp (input_section
->output_section
->name
,
12431 || strcmp (input_section
->output_section
->name
,
12433 info
->callbacks
->einfo
12434 (_("%P: %H: automatic multiple TOCs "
12435 "not supported using your crt files; "
12436 "recompile with -mminimal-toc or upgrade gcc\n"),
12437 input_bfd
, input_section
, rel
->r_offset
);
12439 info
->callbacks
->einfo
12440 (_("%P: %H: sibling call optimization to `%s' "
12441 "does not allow automatic multiple TOCs; "
12442 "recompile with -mminimal-toc or "
12443 "-fno-optimize-sibling-calls, "
12444 "or make `%s' extern\n"),
12445 input_bfd
, input_section
, rel
->r_offset
,
12448 bfd_set_error (bfd_error_bad_value
);
12454 && stub_entry
->stub_type
== ppc_stub_plt_call
)
12455 unresolved_reloc
= FALSE
;
12458 if ((stub_entry
== NULL
12459 || stub_entry
->stub_type
== ppc_stub_long_branch
12460 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12461 && get_opd_info (sec
) != NULL
)
12463 /* The branch destination is the value of the opd entry. */
12464 bfd_vma off
= (relocation
+ addend
12465 - sec
->output_section
->vma
12466 - sec
->output_offset
);
12467 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
12468 if (dest
!= (bfd_vma
) -1)
12475 /* If the branch is out of reach we ought to have a long
12477 from
= (rel
->r_offset
12478 + input_section
->output_offset
12479 + input_section
->output_section
->vma
);
12481 if (stub_entry
!= NULL
12482 && (stub_entry
->stub_type
== ppc_stub_long_branch
12483 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12484 && (r_type
== R_PPC64_ADDR14_BRTAKEN
12485 || r_type
== R_PPC64_ADDR14_BRNTAKEN
12486 || (relocation
+ addend
- from
+ max_br_offset
12487 < 2 * max_br_offset
)))
12488 /* Don't use the stub if this branch is in range. */
12491 if (stub_entry
!= NULL
)
12493 /* Munge up the value and addend so that we call the stub
12494 rather than the procedure directly. */
12495 relocation
= (stub_entry
->stub_offset
12496 + stub_entry
->stub_sec
->output_offset
12497 + stub_entry
->stub_sec
->output_section
->vma
);
12505 /* Set 'a' bit. This is 0b00010 in BO field for branch
12506 on CR(BI) insns (BO == 001at or 011at), and 0b01000
12507 for branch on CTR insns (BO == 1a00t or 1a01t). */
12508 if ((insn
& (0x14 << 21)) == (0x04 << 21))
12509 insn
|= 0x02 << 21;
12510 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
12511 insn
|= 0x08 << 21;
12517 /* Invert 'y' bit if not the default. */
12518 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
12519 insn
^= 0x01 << 21;
12522 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12525 /* NOP out calls to undefined weak functions.
12526 We can thus call a weak function without first
12527 checking whether the function is defined. */
12529 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12530 && h
->elf
.dynindx
== -1
12531 && r_type
== R_PPC64_REL24
12535 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12541 /* Set `addend'. */
12546 info
->callbacks
->einfo
12547 (_("%P: %B: unknown relocation type %d for symbol %s\n"),
12548 input_bfd
, (int) r_type
, sym_name
);
12550 bfd_set_error (bfd_error_bad_value
);
12556 case R_PPC64_TLSGD
:
12557 case R_PPC64_TLSLD
:
12558 case R_PPC64_GNU_VTINHERIT
:
12559 case R_PPC64_GNU_VTENTRY
:
12562 /* GOT16 relocations. Like an ADDR16 using the symbol's
12563 address in the GOT as relocation value instead of the
12564 symbol's value itself. Also, create a GOT entry for the
12565 symbol and put the symbol value there. */
12566 case R_PPC64_GOT_TLSGD16
:
12567 case R_PPC64_GOT_TLSGD16_LO
:
12568 case R_PPC64_GOT_TLSGD16_HI
:
12569 case R_PPC64_GOT_TLSGD16_HA
:
12570 tls_type
= TLS_TLS
| TLS_GD
;
12573 case R_PPC64_GOT_TLSLD16
:
12574 case R_PPC64_GOT_TLSLD16_LO
:
12575 case R_PPC64_GOT_TLSLD16_HI
:
12576 case R_PPC64_GOT_TLSLD16_HA
:
12577 tls_type
= TLS_TLS
| TLS_LD
;
12580 case R_PPC64_GOT_TPREL16_DS
:
12581 case R_PPC64_GOT_TPREL16_LO_DS
:
12582 case R_PPC64_GOT_TPREL16_HI
:
12583 case R_PPC64_GOT_TPREL16_HA
:
12584 tls_type
= TLS_TLS
| TLS_TPREL
;
12587 case R_PPC64_GOT_DTPREL16_DS
:
12588 case R_PPC64_GOT_DTPREL16_LO_DS
:
12589 case R_PPC64_GOT_DTPREL16_HI
:
12590 case R_PPC64_GOT_DTPREL16_HA
:
12591 tls_type
= TLS_TLS
| TLS_DTPREL
;
12594 case R_PPC64_GOT16
:
12595 case R_PPC64_GOT16_LO
:
12596 case R_PPC64_GOT16_HI
:
12597 case R_PPC64_GOT16_HA
:
12598 case R_PPC64_GOT16_DS
:
12599 case R_PPC64_GOT16_LO_DS
:
12602 /* Relocation is to the entry for this symbol in the global
12607 unsigned long indx
= 0;
12608 struct got_entry
*ent
;
12610 if (tls_type
== (TLS_TLS
| TLS_LD
)
12612 || !h
->elf
.def_dynamic
))
12613 ent
= ppc64_tlsld_got (input_bfd
);
12619 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
12620 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
12623 && SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12624 /* This is actually a static link, or it is a
12625 -Bsymbolic link and the symbol is defined
12626 locally, or the symbol was forced to be local
12627 because of a version file. */
12631 indx
= h
->elf
.dynindx
;
12632 unresolved_reloc
= FALSE
;
12634 ent
= h
->elf
.got
.glist
;
12638 if (local_got_ents
== NULL
)
12640 ent
= local_got_ents
[r_symndx
];
12643 for (; ent
!= NULL
; ent
= ent
->next
)
12644 if (ent
->addend
== orig_addend
12645 && ent
->owner
== input_bfd
12646 && ent
->tls_type
== tls_type
)
12652 if (ent
->is_indirect
)
12653 ent
= ent
->got
.ent
;
12654 offp
= &ent
->got
.offset
;
12655 got
= ppc64_elf_tdata (ent
->owner
)->got
;
12659 /* The offset must always be a multiple of 8. We use the
12660 least significant bit to record whether we have already
12661 processed this entry. */
12663 if ((off
& 1) != 0)
12667 /* Generate relocs for the dynamic linker, except in
12668 the case of TLSLD where we'll use one entry per
12676 ? h
->elf
.type
== STT_GNU_IFUNC
12677 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
12678 if ((info
->shared
|| indx
!= 0)
12680 || (tls_type
== (TLS_TLS
| TLS_LD
)
12681 && !h
->elf
.def_dynamic
)
12682 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12683 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
12684 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
12686 relgot
= htab
->reliplt
;
12687 if (relgot
!= NULL
)
12689 outrel
.r_offset
= (got
->output_section
->vma
12690 + got
->output_offset
12692 outrel
.r_addend
= addend
;
12693 if (tls_type
& (TLS_LD
| TLS_GD
))
12695 outrel
.r_addend
= 0;
12696 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
12697 if (tls_type
== (TLS_TLS
| TLS_GD
))
12699 loc
= relgot
->contents
;
12700 loc
+= (relgot
->reloc_count
++
12701 * sizeof (Elf64_External_Rela
));
12702 bfd_elf64_swap_reloca_out (output_bfd
,
12704 outrel
.r_offset
+= 8;
12705 outrel
.r_addend
= addend
;
12707 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12710 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
12711 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12712 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12713 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
12714 else if (indx
!= 0)
12715 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
12719 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12721 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12723 /* Write the .got section contents for the sake
12725 loc
= got
->contents
+ off
;
12726 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
12730 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
12732 outrel
.r_addend
+= relocation
;
12733 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
12734 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
12736 loc
= relgot
->contents
;
12737 loc
+= (relgot
->reloc_count
++
12738 * sizeof (Elf64_External_Rela
));
12739 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
12742 /* Init the .got section contents here if we're not
12743 emitting a reloc. */
12746 relocation
+= addend
;
12747 if (tls_type
== (TLS_TLS
| TLS_LD
))
12749 else if (tls_type
!= 0)
12751 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12752 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12753 relocation
+= DTP_OFFSET
- TP_OFFSET
;
12755 if (tls_type
== (TLS_TLS
| TLS_GD
))
12757 bfd_put_64 (output_bfd
, relocation
,
12758 got
->contents
+ off
+ 8);
12763 bfd_put_64 (output_bfd
, relocation
,
12764 got
->contents
+ off
);
12768 if (off
>= (bfd_vma
) -2)
12771 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
12772 addend
= -(TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
);
12776 case R_PPC64_PLT16_HA
:
12777 case R_PPC64_PLT16_HI
:
12778 case R_PPC64_PLT16_LO
:
12779 case R_PPC64_PLT32
:
12780 case R_PPC64_PLT64
:
12781 /* Relocation is to the entry for this symbol in the
12782 procedure linkage table. */
12784 /* Resolve a PLT reloc against a local symbol directly,
12785 without using the procedure linkage table. */
12789 /* It's possible that we didn't make a PLT entry for this
12790 symbol. This happens when statically linking PIC code,
12791 or when using -Bsymbolic. Go find a match if there is a
12793 if (htab
->plt
!= NULL
)
12795 struct plt_entry
*ent
;
12796 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12797 if (ent
->addend
== orig_addend
12798 && ent
->plt
.offset
!= (bfd_vma
) -1)
12800 relocation
= (htab
->plt
->output_section
->vma
12801 + htab
->plt
->output_offset
12802 + ent
->plt
.offset
);
12803 unresolved_reloc
= FALSE
;
12809 /* Relocation value is TOC base. */
12810 relocation
= TOCstart
;
12811 if (r_symndx
== STN_UNDEF
)
12812 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
12813 else if (unresolved_reloc
)
12815 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
12816 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
12818 unresolved_reloc
= TRUE
;
12821 /* TOC16 relocs. We want the offset relative to the TOC base,
12822 which is the address of the start of the TOC plus 0x8000.
12823 The TOC consists of sections .got, .toc, .tocbss, and .plt,
12825 case R_PPC64_TOC16
:
12826 case R_PPC64_TOC16_LO
:
12827 case R_PPC64_TOC16_HI
:
12828 case R_PPC64_TOC16_DS
:
12829 case R_PPC64_TOC16_LO_DS
:
12830 case R_PPC64_TOC16_HA
:
12831 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
12834 /* Relocate against the beginning of the section. */
12835 case R_PPC64_SECTOFF
:
12836 case R_PPC64_SECTOFF_LO
:
12837 case R_PPC64_SECTOFF_HI
:
12838 case R_PPC64_SECTOFF_DS
:
12839 case R_PPC64_SECTOFF_LO_DS
:
12840 case R_PPC64_SECTOFF_HA
:
12842 addend
-= sec
->output_section
->vma
;
12845 case R_PPC64_REL16
:
12846 case R_PPC64_REL16_LO
:
12847 case R_PPC64_REL16_HI
:
12848 case R_PPC64_REL16_HA
:
12851 case R_PPC64_REL14
:
12852 case R_PPC64_REL14_BRNTAKEN
:
12853 case R_PPC64_REL14_BRTAKEN
:
12854 case R_PPC64_REL24
:
12857 case R_PPC64_TPREL16
:
12858 case R_PPC64_TPREL16_LO
:
12859 case R_PPC64_TPREL16_HI
:
12860 case R_PPC64_TPREL16_HA
:
12861 case R_PPC64_TPREL16_DS
:
12862 case R_PPC64_TPREL16_LO_DS
:
12863 case R_PPC64_TPREL16_HIGHER
:
12864 case R_PPC64_TPREL16_HIGHERA
:
12865 case R_PPC64_TPREL16_HIGHEST
:
12866 case R_PPC64_TPREL16_HIGHESTA
:
12868 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12869 && h
->elf
.dynindx
== -1)
12871 /* Make this relocation against an undefined weak symbol
12872 resolve to zero. This is really just a tweak, since
12873 code using weak externs ought to check that they are
12874 defined before using them. */
12875 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
12877 insn
= bfd_get_32 (output_bfd
, p
);
12878 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
12880 bfd_put_32 (output_bfd
, insn
, p
);
12883 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12885 /* The TPREL16 relocs shouldn't really be used in shared
12886 libs as they will result in DT_TEXTREL being set, but
12887 support them anyway. */
12891 case R_PPC64_DTPREL16
:
12892 case R_PPC64_DTPREL16_LO
:
12893 case R_PPC64_DTPREL16_HI
:
12894 case R_PPC64_DTPREL16_HA
:
12895 case R_PPC64_DTPREL16_DS
:
12896 case R_PPC64_DTPREL16_LO_DS
:
12897 case R_PPC64_DTPREL16_HIGHER
:
12898 case R_PPC64_DTPREL16_HIGHERA
:
12899 case R_PPC64_DTPREL16_HIGHEST
:
12900 case R_PPC64_DTPREL16_HIGHESTA
:
12901 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12904 case R_PPC64_DTPMOD64
:
12909 case R_PPC64_TPREL64
:
12910 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12913 case R_PPC64_DTPREL64
:
12914 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12917 /* Relocations that may need to be propagated if this is a
12919 case R_PPC64_REL30
:
12920 case R_PPC64_REL32
:
12921 case R_PPC64_REL64
:
12922 case R_PPC64_ADDR14
:
12923 case R_PPC64_ADDR14_BRNTAKEN
:
12924 case R_PPC64_ADDR14_BRTAKEN
:
12925 case R_PPC64_ADDR16
:
12926 case R_PPC64_ADDR16_DS
:
12927 case R_PPC64_ADDR16_HA
:
12928 case R_PPC64_ADDR16_HI
:
12929 case R_PPC64_ADDR16_HIGHER
:
12930 case R_PPC64_ADDR16_HIGHERA
:
12931 case R_PPC64_ADDR16_HIGHEST
:
12932 case R_PPC64_ADDR16_HIGHESTA
:
12933 case R_PPC64_ADDR16_LO
:
12934 case R_PPC64_ADDR16_LO_DS
:
12935 case R_PPC64_ADDR24
:
12936 case R_PPC64_ADDR32
:
12937 case R_PPC64_ADDR64
:
12938 case R_PPC64_UADDR16
:
12939 case R_PPC64_UADDR32
:
12940 case R_PPC64_UADDR64
:
12942 if ((input_section
->flags
& SEC_ALLOC
) == 0)
12945 if (NO_OPD_RELOCS
&& is_opd
)
12950 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12951 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
12952 && (must_be_dyn_reloc (info
, r_type
)
12953 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12954 || (ELIMINATE_COPY_RELOCS
12957 && h
->elf
.dynindx
!= -1
12958 && !h
->elf
.non_got_ref
12959 && !h
->elf
.def_regular
)
12962 ? h
->elf
.type
== STT_GNU_IFUNC
12963 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
12965 bfd_boolean skip
, relocate
;
12969 /* When generating a dynamic object, these relocations
12970 are copied into the output file to be resolved at run
12976 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
12977 input_section
, rel
->r_offset
);
12978 if (out_off
== (bfd_vma
) -1)
12980 else if (out_off
== (bfd_vma
) -2)
12981 skip
= TRUE
, relocate
= TRUE
;
12982 out_off
+= (input_section
->output_section
->vma
12983 + input_section
->output_offset
);
12984 outrel
.r_offset
= out_off
;
12985 outrel
.r_addend
= rel
->r_addend
;
12987 /* Optimize unaligned reloc use. */
12988 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
12989 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
12990 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
12991 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
12992 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
12993 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
12994 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
12995 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
12996 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
12999 memset (&outrel
, 0, sizeof outrel
);
13000 else if (!SYMBOL_CALLS_LOCAL (info
, &h
->elf
)
13002 && r_type
!= R_PPC64_TOC
)
13003 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
13006 /* This symbol is local, or marked to become local,
13007 or this is an opd section reloc which must point
13008 at a local function. */
13009 outrel
.r_addend
+= relocation
;
13010 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
13012 if (is_opd
&& h
!= NULL
)
13014 /* Lie about opd entries. This case occurs
13015 when building shared libraries and we
13016 reference a function in another shared
13017 lib. The same thing happens for a weak
13018 definition in an application that's
13019 overridden by a strong definition in a
13020 shared lib. (I believe this is a generic
13021 bug in binutils handling of weak syms.)
13022 In these cases we won't use the opd
13023 entry in this lib. */
13024 unresolved_reloc
= FALSE
;
13027 && r_type
== R_PPC64_ADDR64
13029 ? h
->elf
.type
== STT_GNU_IFUNC
13030 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
13031 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13034 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13036 /* We need to relocate .opd contents for ld.so.
13037 Prelink also wants simple and consistent rules
13038 for relocs. This make all RELATIVE relocs have
13039 *r_offset equal to r_addend. */
13048 ? h
->elf
.type
== STT_GNU_IFUNC
13049 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13051 info
->callbacks
->einfo
13052 (_("%P: %H: relocation %s for indirect "
13053 "function %s unsupported\n"),
13054 input_bfd
, input_section
, rel
->r_offset
,
13055 ppc64_elf_howto_table
[r_type
]->name
,
13059 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
13061 else if (sec
== NULL
|| sec
->owner
== NULL
)
13063 bfd_set_error (bfd_error_bad_value
);
13070 osec
= sec
->output_section
;
13071 indx
= elf_section_data (osec
)->dynindx
;
13075 if ((osec
->flags
& SEC_READONLY
) == 0
13076 && htab
->elf
.data_index_section
!= NULL
)
13077 osec
= htab
->elf
.data_index_section
;
13079 osec
= htab
->elf
.text_index_section
;
13080 indx
= elf_section_data (osec
)->dynindx
;
13082 BFD_ASSERT (indx
!= 0);
13084 /* We are turning this relocation into one
13085 against a section symbol, so subtract out
13086 the output section's address but not the
13087 offset of the input section in the output
13089 outrel
.r_addend
-= osec
->vma
;
13092 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
13096 sreloc
= elf_section_data (input_section
)->sreloc
;
13097 if (!htab
->elf
.dynamic_sections_created
)
13098 sreloc
= htab
->reliplt
;
13099 if (sreloc
== NULL
)
13102 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
13105 loc
= sreloc
->contents
;
13106 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13107 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
13109 /* If this reloc is against an external symbol, it will
13110 be computed at runtime, so there's no need to do
13111 anything now. However, for the sake of prelink ensure
13112 that the section contents are a known value. */
13115 unresolved_reloc
= FALSE
;
13116 /* The value chosen here is quite arbitrary as ld.so
13117 ignores section contents except for the special
13118 case of .opd where the contents might be accessed
13119 before relocation. Choose zero, as that won't
13120 cause reloc overflow. */
13123 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
13124 to improve backward compatibility with older
13126 if (r_type
== R_PPC64_ADDR64
)
13127 addend
= outrel
.r_addend
;
13128 /* Adjust pc_relative relocs to have zero in *r_offset. */
13129 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
13130 addend
= (input_section
->output_section
->vma
13131 + input_section
->output_offset
13138 case R_PPC64_GLOB_DAT
:
13139 case R_PPC64_JMP_SLOT
:
13140 case R_PPC64_JMP_IREL
:
13141 case R_PPC64_RELATIVE
:
13142 /* We shouldn't ever see these dynamic relocs in relocatable
13144 /* Fall through. */
13146 case R_PPC64_PLTGOT16
:
13147 case R_PPC64_PLTGOT16_DS
:
13148 case R_PPC64_PLTGOT16_HA
:
13149 case R_PPC64_PLTGOT16_HI
:
13150 case R_PPC64_PLTGOT16_LO
:
13151 case R_PPC64_PLTGOT16_LO_DS
:
13152 case R_PPC64_PLTREL32
:
13153 case R_PPC64_PLTREL64
:
13154 /* These ones haven't been implemented yet. */
13156 info
->callbacks
->einfo
13157 (_("%P: %B: relocation %s is not supported for symbol %s\n"),
13159 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
13161 bfd_set_error (bfd_error_invalid_operation
);
13166 /* Multi-instruction sequences that access the TOC can be
13167 optimized, eg. addis ra,r2,0; addi rb,ra,x;
13168 to nop; addi rb,r2,x; */
13174 case R_PPC64_GOT_TLSLD16_HI
:
13175 case R_PPC64_GOT_TLSGD16_HI
:
13176 case R_PPC64_GOT_TPREL16_HI
:
13177 case R_PPC64_GOT_DTPREL16_HI
:
13178 case R_PPC64_GOT16_HI
:
13179 case R_PPC64_TOC16_HI
:
13180 /* These relocs would only be useful if building up an
13181 offset to later add to r2, perhaps in an indexed
13182 addressing mode instruction. Don't try to optimize.
13183 Unfortunately, the possibility of someone building up an
13184 offset like this or even with the HA relocs, means that
13185 we need to check the high insn when optimizing the low
13189 case R_PPC64_GOT_TLSLD16_HA
:
13190 case R_PPC64_GOT_TLSGD16_HA
:
13191 case R_PPC64_GOT_TPREL16_HA
:
13192 case R_PPC64_GOT_DTPREL16_HA
:
13193 case R_PPC64_GOT16_HA
:
13194 case R_PPC64_TOC16_HA
:
13195 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
13196 && !ppc64_elf_tdata (input_bfd
)->ha_relocs_not_using_r2
)
13198 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13199 bfd_put_32 (input_bfd
, NOP
, p
);
13203 case R_PPC64_GOT_TLSLD16_LO
:
13204 case R_PPC64_GOT_TLSGD16_LO
:
13205 case R_PPC64_GOT_TPREL16_LO_DS
:
13206 case R_PPC64_GOT_DTPREL16_LO_DS
:
13207 case R_PPC64_GOT16_LO
:
13208 case R_PPC64_GOT16_LO_DS
:
13209 case R_PPC64_TOC16_LO
:
13210 case R_PPC64_TOC16_LO_DS
:
13211 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
13212 && !ppc64_elf_tdata (input_bfd
)->ha_relocs_not_using_r2
)
13214 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13215 insn
= bfd_get_32 (input_bfd
, p
);
13216 if ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
13217 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
13218 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
13219 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
13220 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
13221 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
13222 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
13223 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
13224 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
13225 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
13226 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
13227 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
13228 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
13229 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
13230 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
13231 && (insn
& 3) != 1)
13232 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
13233 && ((insn
& 3) == 0 || (insn
& 3) == 3)))
13235 insn
&= ~(0x1f << 16);
13237 bfd_put_32 (input_bfd
, insn
, p
);
13243 /* Do any further special processing. */
13249 case R_PPC64_ADDR16_HA
:
13250 case R_PPC64_REL16_HA
:
13251 case R_PPC64_ADDR16_HIGHERA
:
13252 case R_PPC64_ADDR16_HIGHESTA
:
13253 case R_PPC64_TOC16_HA
:
13254 case R_PPC64_SECTOFF_HA
:
13255 case R_PPC64_TPREL16_HA
:
13256 case R_PPC64_DTPREL16_HA
:
13257 case R_PPC64_TPREL16_HIGHER
:
13258 case R_PPC64_TPREL16_HIGHERA
:
13259 case R_PPC64_TPREL16_HIGHEST
:
13260 case R_PPC64_TPREL16_HIGHESTA
:
13261 case R_PPC64_DTPREL16_HIGHER
:
13262 case R_PPC64_DTPREL16_HIGHERA
:
13263 case R_PPC64_DTPREL16_HIGHEST
:
13264 case R_PPC64_DTPREL16_HIGHESTA
:
13265 /* It's just possible that this symbol is a weak symbol
13266 that's not actually defined anywhere. In that case,
13267 'sec' would be NULL, and we should leave the symbol
13268 alone (it will be set to zero elsewhere in the link). */
13273 case R_PPC64_GOT16_HA
:
13274 case R_PPC64_PLTGOT16_HA
:
13275 case R_PPC64_PLT16_HA
:
13276 case R_PPC64_GOT_TLSGD16_HA
:
13277 case R_PPC64_GOT_TLSLD16_HA
:
13278 case R_PPC64_GOT_TPREL16_HA
:
13279 case R_PPC64_GOT_DTPREL16_HA
:
13280 /* Add 0x10000 if sign bit in 0:15 is set.
13281 Bits 0:15 are not used. */
13285 case R_PPC64_ADDR16_DS
:
13286 case R_PPC64_ADDR16_LO_DS
:
13287 case R_PPC64_GOT16_DS
:
13288 case R_PPC64_GOT16_LO_DS
:
13289 case R_PPC64_PLT16_LO_DS
:
13290 case R_PPC64_SECTOFF_DS
:
13291 case R_PPC64_SECTOFF_LO_DS
:
13292 case R_PPC64_TOC16_DS
:
13293 case R_PPC64_TOC16_LO_DS
:
13294 case R_PPC64_PLTGOT16_DS
:
13295 case R_PPC64_PLTGOT16_LO_DS
:
13296 case R_PPC64_GOT_TPREL16_DS
:
13297 case R_PPC64_GOT_TPREL16_LO_DS
:
13298 case R_PPC64_GOT_DTPREL16_DS
:
13299 case R_PPC64_GOT_DTPREL16_LO_DS
:
13300 case R_PPC64_TPREL16_DS
:
13301 case R_PPC64_TPREL16_LO_DS
:
13302 case R_PPC64_DTPREL16_DS
:
13303 case R_PPC64_DTPREL16_LO_DS
:
13304 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
13306 /* If this reloc is against an lq insn, then the value must be
13307 a multiple of 16. This is somewhat of a hack, but the
13308 "correct" way to do this by defining _DQ forms of all the
13309 _DS relocs bloats all reloc switches in this file. It
13310 doesn't seem to make much sense to use any of these relocs
13311 in data, so testing the insn should be safe. */
13312 if ((insn
& (0x3f << 26)) == (56u << 26))
13314 if (((relocation
+ addend
) & mask
) != 0)
13316 info
->callbacks
->einfo
13317 (_("%P: %H: error: %s not a multiple of %u\n"),
13318 input_bfd
, input_section
, rel
->r_offset
,
13319 ppc64_elf_howto_table
[r_type
]->name
,
13321 bfd_set_error (bfd_error_bad_value
);
13328 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
13329 because such sections are not SEC_ALLOC and thus ld.so will
13330 not process them. */
13331 if (unresolved_reloc
13332 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
13333 && h
->elf
.def_dynamic
))
13335 info
->callbacks
->einfo
13336 (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
13337 input_bfd
, input_section
, rel
->r_offset
,
13338 ppc64_elf_howto_table
[(int) r_type
]->name
,
13339 h
->elf
.root
.root
.string
);
13343 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
13351 if (r
!= bfd_reloc_ok
)
13353 if (sym_name
== NULL
)
13354 sym_name
= "(null)";
13355 if (r
== bfd_reloc_overflow
)
13360 && h
->elf
.root
.type
== bfd_link_hash_undefweak
13361 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
13363 /* Assume this is a call protected by other code that
13364 detects the symbol is undefined. If this is the case,
13365 we can safely ignore the overflow. If not, the
13366 program is hosed anyway, and a little warning isn't
13372 if (!((*info
->callbacks
->reloc_overflow
)
13373 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
13374 ppc64_elf_howto_table
[r_type
]->name
,
13375 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
13380 info
->callbacks
->einfo
13381 (_("%P: %H: %s reloc against `%s': error %d\n"),
13382 input_bfd
, input_section
, rel
->r_offset
,
13383 ppc64_elf_howto_table
[r_type
]->name
,
13391 /* If we're emitting relocations, then shortly after this function
13392 returns, reloc offsets and addends for this section will be
13393 adjusted. Worse, reloc symbol indices will be for the output
13394 file rather than the input. Save a copy of the relocs for
13395 opd_entry_value. */
13396 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
13399 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
13400 rel
= bfd_alloc (input_bfd
, amt
);
13401 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
13402 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
13405 memcpy (rel
, relocs
, amt
);
13410 /* Adjust the value of any local symbols in opd sections. */
13413 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
13414 const char *name ATTRIBUTE_UNUSED
,
13415 Elf_Internal_Sym
*elfsym
,
13416 asection
*input_sec
,
13417 struct elf_link_hash_entry
*h
)
13419 struct _opd_sec_data
*opd
;
13426 opd
= get_opd_info (input_sec
);
13427 if (opd
== NULL
|| opd
->adjust
== NULL
)
13430 value
= elfsym
->st_value
- input_sec
->output_offset
;
13431 if (!info
->relocatable
)
13432 value
-= input_sec
->output_section
->vma
;
13434 adjust
= opd
->adjust
[value
/ 8];
13438 elfsym
->st_value
+= adjust
;
13442 /* Finish up dynamic symbol handling. We set the contents of various
13443 dynamic sections here. */
13446 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
13447 struct bfd_link_info
*info
,
13448 struct elf_link_hash_entry
*h
,
13449 Elf_Internal_Sym
*sym
)
13451 struct ppc_link_hash_table
*htab
;
13452 struct plt_entry
*ent
;
13453 Elf_Internal_Rela rela
;
13456 htab
= ppc_hash_table (info
);
13460 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13461 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13463 /* This symbol has an entry in the procedure linkage
13464 table. Set it up. */
13465 if (!htab
->elf
.dynamic_sections_created
13466 || h
->dynindx
== -1)
13468 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
13470 && (h
->root
.type
== bfd_link_hash_defined
13471 || h
->root
.type
== bfd_link_hash_defweak
));
13472 rela
.r_offset
= (htab
->iplt
->output_section
->vma
13473 + htab
->iplt
->output_offset
13474 + ent
->plt
.offset
);
13475 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13476 rela
.r_addend
= (h
->root
.u
.def
.value
13477 + h
->root
.u
.def
.section
->output_offset
13478 + h
->root
.u
.def
.section
->output_section
->vma
13480 loc
= (htab
->reliplt
->contents
13481 + (htab
->reliplt
->reloc_count
++
13482 * sizeof (Elf64_External_Rela
)));
13486 rela
.r_offset
= (htab
->plt
->output_section
->vma
13487 + htab
->plt
->output_offset
13488 + ent
->plt
.offset
);
13489 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13490 rela
.r_addend
= ent
->addend
;
13491 loc
= (htab
->relplt
->contents
13492 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
)
13493 / (PLT_ENTRY_SIZE
/ sizeof (Elf64_External_Rela
))));
13495 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13500 /* This symbol needs a copy reloc. Set it up. */
13502 if (h
->dynindx
== -1
13503 || (h
->root
.type
!= bfd_link_hash_defined
13504 && h
->root
.type
!= bfd_link_hash_defweak
)
13505 || htab
->relbss
== NULL
)
13508 rela
.r_offset
= (h
->root
.u
.def
.value
13509 + h
->root
.u
.def
.section
->output_section
->vma
13510 + h
->root
.u
.def
.section
->output_offset
);
13511 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
13513 loc
= htab
->relbss
->contents
;
13514 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13515 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13518 /* Mark some specially defined symbols as absolute. */
13519 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
13520 sym
->st_shndx
= SHN_ABS
;
13525 /* Used to decide how to sort relocs in an optimal manner for the
13526 dynamic linker, before writing them out. */
13528 static enum elf_reloc_type_class
13529 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
13531 enum elf_ppc64_reloc_type r_type
;
13533 r_type
= ELF64_R_TYPE (rela
->r_info
);
13536 case R_PPC64_RELATIVE
:
13537 return reloc_class_relative
;
13538 case R_PPC64_JMP_SLOT
:
13539 return reloc_class_plt
;
13541 return reloc_class_copy
;
13543 return reloc_class_normal
;
13547 /* Finish up the dynamic sections. */
13550 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
13551 struct bfd_link_info
*info
)
13553 struct ppc_link_hash_table
*htab
;
13557 htab
= ppc_hash_table (info
);
13561 dynobj
= htab
->elf
.dynobj
;
13562 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
13564 if (htab
->elf
.dynamic_sections_created
)
13566 Elf64_External_Dyn
*dyncon
, *dynconend
;
13568 if (sdyn
== NULL
|| htab
->got
== NULL
)
13571 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
13572 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
13573 for (; dyncon
< dynconend
; dyncon
++)
13575 Elf_Internal_Dyn dyn
;
13578 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
13585 case DT_PPC64_GLINK
:
13587 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13588 /* We stupidly defined DT_PPC64_GLINK to be the start
13589 of glink rather than the first entry point, which is
13590 what ld.so needs, and now have a bigger stub to
13591 support automatic multiple TOCs. */
13592 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
13596 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13599 dyn
.d_un
.d_ptr
= s
->vma
;
13602 case DT_PPC64_OPDSZ
:
13603 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13606 dyn
.d_un
.d_val
= s
->size
;
13611 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13616 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13620 dyn
.d_un
.d_val
= htab
->relplt
->size
;
13624 /* Don't count procedure linkage table relocs in the
13625 overall reloc count. */
13629 dyn
.d_un
.d_val
-= s
->size
;
13633 /* We may not be using the standard ELF linker script.
13634 If .rela.plt is the first .rela section, we adjust
13635 DT_RELA to not include it. */
13639 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
13641 dyn
.d_un
.d_ptr
+= s
->size
;
13645 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13649 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
13651 /* Fill in the first entry in the global offset table.
13652 We use it to hold the link-time TOCbase. */
13653 bfd_put_64 (output_bfd
,
13654 elf_gp (output_bfd
) + TOC_BASE_OFF
,
13655 htab
->got
->contents
);
13657 /* Set .got entry size. */
13658 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
13661 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
13663 /* Set .plt entry size. */
13664 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
13668 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
13669 brlt ourselves if emitrelocations. */
13670 if (htab
->brlt
!= NULL
13671 && htab
->brlt
->reloc_count
!= 0
13672 && !_bfd_elf_link_output_relocs (output_bfd
,
13674 elf_section_data (htab
->brlt
)->rela
.hdr
,
13675 elf_section_data (htab
->brlt
)->relocs
,
13679 if (htab
->glink
!= NULL
13680 && htab
->glink
->reloc_count
!= 0
13681 && !_bfd_elf_link_output_relocs (output_bfd
,
13683 elf_section_data (htab
->glink
)->rela
.hdr
,
13684 elf_section_data (htab
->glink
)->relocs
,
13689 if (htab
->glink_eh_frame
!= NULL
13690 && htab
->glink_eh_frame
->sec_info_type
== ELF_INFO_TYPE_EH_FRAME
13691 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
13692 htab
->glink_eh_frame
,
13693 htab
->glink_eh_frame
->contents
))
13696 /* We need to handle writing out multiple GOT sections ourselves,
13697 since we didn't add them to DYNOBJ. We know dynobj is the first
13699 while ((dynobj
= dynobj
->link_next
) != NULL
)
13703 if (!is_ppc64_elf (dynobj
))
13706 s
= ppc64_elf_tdata (dynobj
)->got
;
13709 && s
->output_section
!= bfd_abs_section_ptr
13710 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13711 s
->contents
, s
->output_offset
,
13714 s
= ppc64_elf_tdata (dynobj
)->relgot
;
13717 && s
->output_section
!= bfd_abs_section_ptr
13718 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13719 s
->contents
, s
->output_offset
,
13727 #include "elf64-target.h"