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
;
2604 #define ppc64_elf_tdata(bfd) \
2605 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2607 #define ppc64_tlsld_got(bfd) \
2608 (&ppc64_elf_tdata (bfd)->tlsld_got)
2610 #define is_ppc64_elf(bfd) \
2611 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2612 && elf_object_id (bfd) == PPC64_ELF_DATA)
2614 /* Override the generic function because we store some extras. */
2617 ppc64_elf_mkobject (bfd
*abfd
)
2619 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2623 /* Fix bad default arch selected for a 64 bit input bfd when the
2624 default is 32 bit. */
2627 ppc64_elf_object_p (bfd
*abfd
)
2629 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2631 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2633 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2635 /* Relies on arch after 32 bit default being 64 bit default. */
2636 abfd
->arch_info
= abfd
->arch_info
->next
;
2637 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2643 /* Support for core dump NOTE sections. */
2646 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2648 size_t offset
, size
;
2650 if (note
->descsz
!= 504)
2654 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2657 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2663 /* Make a ".reg/999" section. */
2664 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2665 size
, note
->descpos
+ offset
);
2669 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2671 if (note
->descsz
!= 136)
2674 elf_tdata (abfd
)->core_pid
2675 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2676 elf_tdata (abfd
)->core_program
2677 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2678 elf_tdata (abfd
)->core_command
2679 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2685 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2698 va_start (ap
, note_type
);
2699 memset (data
, 0, 40);
2700 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2701 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2703 return elfcore_write_note (abfd
, buf
, bufsiz
,
2704 "CORE", note_type
, data
, sizeof (data
));
2715 va_start (ap
, note_type
);
2716 memset (data
, 0, 112);
2717 pid
= va_arg (ap
, long);
2718 bfd_put_32 (abfd
, pid
, data
+ 32);
2719 cursig
= va_arg (ap
, int);
2720 bfd_put_16 (abfd
, cursig
, data
+ 12);
2721 greg
= va_arg (ap
, const void *);
2722 memcpy (data
+ 112, greg
, 384);
2723 memset (data
+ 496, 0, 8);
2725 return elfcore_write_note (abfd
, buf
, bufsiz
,
2726 "CORE", note_type
, data
, sizeof (data
));
2731 /* Add extra PPC sections. */
2733 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2735 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2736 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2737 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2738 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2739 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2740 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2741 { NULL
, 0, 0, 0, 0 }
2744 enum _ppc64_sec_type
{
2750 struct _ppc64_elf_section_data
2752 struct bfd_elf_section_data elf
;
2756 /* An array with one entry for each opd function descriptor. */
2757 struct _opd_sec_data
2759 /* Points to the function code section for local opd entries. */
2760 asection
**func_sec
;
2762 /* After editing .opd, adjust references to opd local syms. */
2766 /* An array for toc sections, indexed by offset/8. */
2767 struct _toc_sec_data
2769 /* Specifies the relocation symbol index used at a given toc offset. */
2772 /* And the relocation addend. */
2777 enum _ppc64_sec_type sec_type
:2;
2779 /* Flag set when small branches are detected. Used to
2780 select suitable defaults for the stub group size. */
2781 unsigned int has_14bit_branch
:1;
2784 #define ppc64_elf_section_data(sec) \
2785 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2788 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2790 if (!sec
->used_by_bfd
)
2792 struct _ppc64_elf_section_data
*sdata
;
2793 bfd_size_type amt
= sizeof (*sdata
);
2795 sdata
= bfd_zalloc (abfd
, amt
);
2798 sec
->used_by_bfd
= sdata
;
2801 return _bfd_elf_new_section_hook (abfd
, sec
);
2804 static struct _opd_sec_data
*
2805 get_opd_info (asection
* sec
)
2808 && ppc64_elf_section_data (sec
) != NULL
2809 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2810 return &ppc64_elf_section_data (sec
)->u
.opd
;
2814 /* Parameters for the qsort hook. */
2815 static bfd_boolean synthetic_relocatable
;
2817 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2820 compare_symbols (const void *ap
, const void *bp
)
2822 const asymbol
*a
= * (const asymbol
**) ap
;
2823 const asymbol
*b
= * (const asymbol
**) bp
;
2825 /* Section symbols first. */
2826 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2828 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2831 /* then .opd symbols. */
2832 if (strcmp (a
->section
->name
, ".opd") == 0
2833 && strcmp (b
->section
->name
, ".opd") != 0)
2835 if (strcmp (a
->section
->name
, ".opd") != 0
2836 && strcmp (b
->section
->name
, ".opd") == 0)
2839 /* then other code symbols. */
2840 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2841 == (SEC_CODE
| SEC_ALLOC
)
2842 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2843 != (SEC_CODE
| SEC_ALLOC
))
2846 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2847 != (SEC_CODE
| SEC_ALLOC
)
2848 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2849 == (SEC_CODE
| SEC_ALLOC
))
2852 if (synthetic_relocatable
)
2854 if (a
->section
->id
< b
->section
->id
)
2857 if (a
->section
->id
> b
->section
->id
)
2861 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2864 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2867 /* For syms with the same value, prefer strong dynamic global function
2868 syms over other syms. */
2869 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2872 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2875 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2878 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2881 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2884 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2887 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2890 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2896 /* Search SYMS for a symbol of the given VALUE. */
2899 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2907 mid
= (lo
+ hi
) >> 1;
2908 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2910 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2920 mid
= (lo
+ hi
) >> 1;
2921 if (syms
[mid
]->section
->id
< id
)
2923 else if (syms
[mid
]->section
->id
> id
)
2925 else if (syms
[mid
]->value
< value
)
2927 else if (syms
[mid
]->value
> value
)
2937 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2939 bfd_vma vma
= *(bfd_vma
*) ptr
;
2940 return ((section
->flags
& SEC_ALLOC
) != 0
2941 && section
->vma
<= vma
2942 && vma
< section
->vma
+ section
->size
);
2945 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2946 entry syms. Also generate @plt symbols for the glink branch table. */
2949 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2950 long static_count
, asymbol
**static_syms
,
2951 long dyn_count
, asymbol
**dyn_syms
,
2958 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2960 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2965 opd
= bfd_get_section_by_name (abfd
, ".opd");
2969 symcount
= static_count
;
2971 symcount
+= dyn_count
;
2975 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2979 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2981 /* Use both symbol tables. */
2982 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2983 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2985 else if (!relocatable
&& static_count
== 0)
2986 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2988 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2990 synthetic_relocatable
= relocatable
;
2991 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2993 if (!relocatable
&& symcount
> 1)
2996 /* Trim duplicate syms, since we may have merged the normal and
2997 dynamic symbols. Actually, we only care about syms that have
2998 different values, so trim any with the same value. */
2999 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3000 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3001 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3002 syms
[j
++] = syms
[i
];
3007 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3011 for (; i
< symcount
; ++i
)
3012 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3013 != (SEC_CODE
| SEC_ALLOC
))
3014 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3018 for (; i
< symcount
; ++i
)
3019 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3023 for (; i
< symcount
; ++i
)
3024 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3028 for (; i
< symcount
; ++i
)
3029 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3030 != (SEC_CODE
| SEC_ALLOC
))
3038 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3043 if (opdsymend
== secsymend
)
3046 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3047 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3051 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3058 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3062 while (r
< opd
->relocation
+ relcount
3063 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3066 if (r
== opd
->relocation
+ relcount
)
3069 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3072 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3075 sym
= *r
->sym_ptr_ptr
;
3076 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3077 sym
->section
->id
, sym
->value
+ r
->addend
))
3080 size
+= sizeof (asymbol
);
3081 size
+= strlen (syms
[i
]->name
) + 2;
3085 s
= *ret
= bfd_malloc (size
);
3092 names
= (char *) (s
+ count
);
3094 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3098 while (r
< opd
->relocation
+ relcount
3099 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3102 if (r
== opd
->relocation
+ relcount
)
3105 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3108 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3111 sym
= *r
->sym_ptr_ptr
;
3112 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3113 sym
->section
->id
, sym
->value
+ r
->addend
))
3118 s
->flags
|= BSF_SYNTHETIC
;
3119 s
->section
= sym
->section
;
3120 s
->value
= sym
->value
+ r
->addend
;
3123 len
= strlen (syms
[i
]->name
);
3124 memcpy (names
, syms
[i
]->name
, len
+ 1);
3126 /* Have udata.p point back to the original symbol this
3127 synthetic symbol was derived from. */
3128 s
->udata
.p
= syms
[i
];
3135 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3139 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3140 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3143 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3147 free_contents_and_exit
:
3155 for (i
= secsymend
; i
< opdsymend
; ++i
)
3159 /* Ignore bogus symbols. */
3160 if (syms
[i
]->value
> opd
->size
- 8)
3163 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3164 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3167 size
+= sizeof (asymbol
);
3168 size
+= strlen (syms
[i
]->name
) + 2;
3172 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3174 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3176 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3178 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3180 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3181 goto free_contents_and_exit
;
3183 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3184 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3187 extdynend
= extdyn
+ dynamic
->size
;
3188 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3190 Elf_Internal_Dyn dyn
;
3191 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3193 if (dyn
.d_tag
== DT_NULL
)
3196 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3198 /* The first glink stub starts at offset 32; see comment in
3199 ppc64_elf_finish_dynamic_sections. */
3200 glink_vma
= dyn
.d_un
.d_val
+ 32;
3201 /* The .glink section usually does not survive the final
3202 link; search for the section (usually .text) where the
3203 glink stubs now reside. */
3204 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3215 /* Determine __glink trampoline by reading the relative branch
3216 from the first glink stub. */
3218 if (bfd_get_section_contents (abfd
, glink
, buf
,
3219 glink_vma
+ 4 - glink
->vma
, 4))
3221 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3223 if ((insn
& ~0x3fffffc) == 0)
3224 resolv_vma
= glink_vma
+ 4 + (insn
^ 0x2000000) - 0x2000000;
3228 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3230 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3233 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3234 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3235 goto free_contents_and_exit
;
3237 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3238 size
+= plt_count
* sizeof (asymbol
);
3240 p
= relplt
->relocation
;
3241 for (i
= 0; i
< plt_count
; i
++, p
++)
3243 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3245 size
+= sizeof ("+0x") - 1 + 16;
3250 s
= *ret
= bfd_malloc (size
);
3252 goto free_contents_and_exit
;
3254 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3256 for (i
= secsymend
; i
< opdsymend
; ++i
)
3260 if (syms
[i
]->value
> opd
->size
- 8)
3263 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3264 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3268 asection
*sec
= abfd
->sections
;
3275 long mid
= (lo
+ hi
) >> 1;
3276 if (syms
[mid
]->section
->vma
< ent
)
3278 else if (syms
[mid
]->section
->vma
> ent
)
3282 sec
= syms
[mid
]->section
;
3287 if (lo
>= hi
&& lo
> codesecsym
)
3288 sec
= syms
[lo
- 1]->section
;
3290 for (; sec
!= NULL
; sec
= sec
->next
)
3294 /* SEC_LOAD may not be set if SEC is from a separate debug
3296 if ((sec
->flags
& SEC_ALLOC
) == 0)
3298 if ((sec
->flags
& SEC_CODE
) != 0)
3301 s
->flags
|= BSF_SYNTHETIC
;
3302 s
->value
= ent
- s
->section
->vma
;
3305 len
= strlen (syms
[i
]->name
);
3306 memcpy (names
, syms
[i
]->name
, len
+ 1);
3308 /* Have udata.p point back to the original symbol this
3309 synthetic symbol was derived from. */
3310 s
->udata
.p
= syms
[i
];
3316 if (glink
!= NULL
&& relplt
!= NULL
)
3320 /* Add a symbol for the main glink trampoline. */
3321 memset (s
, 0, sizeof *s
);
3323 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3325 s
->value
= resolv_vma
- glink
->vma
;
3327 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3328 names
+= sizeof ("__glink_PLTresolve");
3333 /* FIXME: It would be very much nicer to put sym@plt on the
3334 stub rather than on the glink branch table entry. The
3335 objdump disassembler would then use a sensible symbol
3336 name on plt calls. The difficulty in doing so is
3337 a) finding the stubs, and,
3338 b) matching stubs against plt entries, and,
3339 c) there can be multiple stubs for a given plt entry.
3341 Solving (a) could be done by code scanning, but older
3342 ppc64 binaries used different stubs to current code.
3343 (b) is the tricky one since you need to known the toc
3344 pointer for at least one function that uses a pic stub to
3345 be able to calculate the plt address referenced.
3346 (c) means gdb would need to set multiple breakpoints (or
3347 find the glink branch itself) when setting breakpoints
3348 for pending shared library loads. */
3349 p
= relplt
->relocation
;
3350 for (i
= 0; i
< plt_count
; i
++, p
++)
3354 *s
= **p
->sym_ptr_ptr
;
3355 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3356 we are defining a symbol, ensure one of them is set. */
3357 if ((s
->flags
& BSF_LOCAL
) == 0)
3358 s
->flags
|= BSF_GLOBAL
;
3359 s
->flags
|= BSF_SYNTHETIC
;
3361 s
->value
= glink_vma
- glink
->vma
;
3364 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3365 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3369 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3370 names
+= sizeof ("+0x") - 1;
3371 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3372 names
+= strlen (names
);
3374 memcpy (names
, "@plt", sizeof ("@plt"));
3375 names
+= sizeof ("@plt");
3390 /* The following functions are specific to the ELF linker, while
3391 functions above are used generally. Those named ppc64_elf_* are
3392 called by the main ELF linker code. They appear in this file more
3393 or less in the order in which they are called. eg.
3394 ppc64_elf_check_relocs is called early in the link process,
3395 ppc64_elf_finish_dynamic_sections is one of the last functions
3398 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3399 functions have both a function code symbol and a function descriptor
3400 symbol. A call to foo in a relocatable object file looks like:
3407 The function definition in another object file might be:
3411 . .quad .TOC.@tocbase
3417 When the linker resolves the call during a static link, the branch
3418 unsurprisingly just goes to .foo and the .opd information is unused.
3419 If the function definition is in a shared library, things are a little
3420 different: The call goes via a plt call stub, the opd information gets
3421 copied to the plt, and the linker patches the nop.
3429 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3430 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3431 . std 2,40(1) # this is the general idea
3439 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3441 The "reloc ()" notation is supposed to indicate that the linker emits
3442 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3445 What are the difficulties here? Well, firstly, the relocations
3446 examined by the linker in check_relocs are against the function code
3447 sym .foo, while the dynamic relocation in the plt is emitted against
3448 the function descriptor symbol, foo. Somewhere along the line, we need
3449 to carefully copy dynamic link information from one symbol to the other.
3450 Secondly, the generic part of the elf linker will make .foo a dynamic
3451 symbol as is normal for most other backends. We need foo dynamic
3452 instead, at least for an application final link. However, when
3453 creating a shared library containing foo, we need to have both symbols
3454 dynamic so that references to .foo are satisfied during the early
3455 stages of linking. Otherwise the linker might decide to pull in a
3456 definition from some other object, eg. a static library.
3458 Update: As of August 2004, we support a new convention. Function
3459 calls may use the function descriptor symbol, ie. "bl foo". This
3460 behaves exactly as "bl .foo". */
3462 /* Of those relocs that might be copied as dynamic relocs, this function
3463 selects those that must be copied when linking a shared library,
3464 even when the symbol is local. */
3467 must_be_dyn_reloc (struct bfd_link_info
*info
,
3468 enum elf_ppc64_reloc_type r_type
)
3480 case R_PPC64_TPREL16
:
3481 case R_PPC64_TPREL16_LO
:
3482 case R_PPC64_TPREL16_HI
:
3483 case R_PPC64_TPREL16_HA
:
3484 case R_PPC64_TPREL16_DS
:
3485 case R_PPC64_TPREL16_LO_DS
:
3486 case R_PPC64_TPREL16_HIGHER
:
3487 case R_PPC64_TPREL16_HIGHERA
:
3488 case R_PPC64_TPREL16_HIGHEST
:
3489 case R_PPC64_TPREL16_HIGHESTA
:
3490 case R_PPC64_TPREL64
:
3491 return !info
->executable
;
3495 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3496 copying dynamic variables from a shared lib into an app's dynbss
3497 section, and instead use a dynamic relocation to point into the
3498 shared lib. With code that gcc generates, it's vital that this be
3499 enabled; In the PowerPC64 ABI, the address of a function is actually
3500 the address of a function descriptor, which resides in the .opd
3501 section. gcc uses the descriptor directly rather than going via the
3502 GOT as some other ABI's do, which means that initialized function
3503 pointers must reference the descriptor. Thus, a function pointer
3504 initialized to the address of a function in a shared library will
3505 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3506 redefines the function descriptor symbol to point to the copy. This
3507 presents a problem as a plt entry for that function is also
3508 initialized from the function descriptor symbol and the copy reloc
3509 may not be initialized first. */
3510 #define ELIMINATE_COPY_RELOCS 1
3512 /* Section name for stubs is the associated section name plus this
3514 #define STUB_SUFFIX ".stub"
3517 ppc_stub_long_branch:
3518 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3519 destination, but a 24 bit branch in a stub section will reach.
3522 ppc_stub_plt_branch:
3523 Similar to the above, but a 24 bit branch in the stub section won't
3524 reach its destination.
3525 . addis %r12,%r2,xxx@toc@ha
3526 . ld %r11,xxx@toc@l(%r12)
3531 Used to call a function in a shared library. If it so happens that
3532 the plt entry referenced crosses a 64k boundary, then an extra
3533 "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr".
3534 . addis %r12,%r2,xxx@toc@ha
3536 . ld %r11,xxx+0@toc@l(%r12)
3538 . ld %r2,xxx+8@toc@l(%r12)
3539 . ld %r11,xxx+16@toc@l(%r12)
3542 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3543 code to adjust the value and save r2 to support multiple toc sections.
3544 A ppc_stub_long_branch with an r2 offset looks like:
3546 . addis %r2,%r2,off@ha
3547 . addi %r2,%r2,off@l
3550 A ppc_stub_plt_branch with an r2 offset looks like:
3552 . addis %r12,%r2,xxx@toc@ha
3553 . ld %r11,xxx@toc@l(%r12)
3554 . addis %r2,%r2,off@ha
3555 . addi %r2,%r2,off@l
3559 In cases where the "addis" instruction would add zero, the "addis" is
3560 omitted and following instructions modified slightly in some cases.
3563 enum ppc_stub_type
{
3565 ppc_stub_long_branch
,
3566 ppc_stub_long_branch_r2off
,
3567 ppc_stub_plt_branch
,
3568 ppc_stub_plt_branch_r2off
,
3572 struct ppc_stub_hash_entry
{
3574 /* Base hash table entry structure. */
3575 struct bfd_hash_entry root
;
3577 enum ppc_stub_type stub_type
;
3579 /* The stub section. */
3582 /* Offset within stub_sec of the beginning of this stub. */
3583 bfd_vma stub_offset
;
3585 /* Given the symbol's value and its section we can determine its final
3586 value when building the stubs (so the stub knows where to jump. */
3587 bfd_vma target_value
;
3588 asection
*target_section
;
3590 /* The symbol table entry, if any, that this was derived from. */
3591 struct ppc_link_hash_entry
*h
;
3592 struct plt_entry
*plt_ent
;
3594 /* And the reloc addend that this was derived from. */
3597 /* Where this stub is being called from, or, in the case of combined
3598 stub sections, the first input section in the group. */
3602 struct ppc_branch_hash_entry
{
3604 /* Base hash table entry structure. */
3605 struct bfd_hash_entry root
;
3607 /* Offset within branch lookup table. */
3608 unsigned int offset
;
3610 /* Generation marker. */
3614 struct ppc_link_hash_entry
3616 struct elf_link_hash_entry elf
;
3619 /* A pointer to the most recently used stub hash entry against this
3621 struct ppc_stub_hash_entry
*stub_cache
;
3623 /* A pointer to the next symbol starting with a '.' */
3624 struct ppc_link_hash_entry
*next_dot_sym
;
3627 /* Track dynamic relocs copied for this symbol. */
3628 struct elf_dyn_relocs
*dyn_relocs
;
3630 /* Link between function code and descriptor symbols. */
3631 struct ppc_link_hash_entry
*oh
;
3633 /* Flag function code and descriptor symbols. */
3634 unsigned int is_func
:1;
3635 unsigned int is_func_descriptor
:1;
3636 unsigned int fake
:1;
3638 /* Whether global opd/toc sym has been adjusted or not.
3639 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3640 should be set for all globals defined in any opd/toc section. */
3641 unsigned int adjust_done
:1;
3643 /* Set if we twiddled this symbol to weak at some stage. */
3644 unsigned int was_undefined
:1;
3646 /* Contexts in which symbol is used in the GOT (or TOC).
3647 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3648 corresponding relocs are encountered during check_relocs.
3649 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3650 indicate the corresponding GOT entry type is not needed.
3651 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3652 a TPREL one. We use a separate flag rather than setting TPREL
3653 just for convenience in distinguishing the two cases. */
3654 #define TLS_GD 1 /* GD reloc. */
3655 #define TLS_LD 2 /* LD reloc. */
3656 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3657 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3658 #define TLS_TLS 16 /* Any TLS reloc. */
3659 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3660 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3661 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3662 unsigned char tls_mask
;
3665 /* ppc64 ELF linker hash table. */
3667 struct ppc_link_hash_table
3669 struct elf_link_hash_table elf
;
3671 /* The stub hash table. */
3672 struct bfd_hash_table stub_hash_table
;
3674 /* Another hash table for plt_branch stubs. */
3675 struct bfd_hash_table branch_hash_table
;
3677 /* Linker stub bfd. */
3680 /* Linker call-backs. */
3681 asection
* (*add_stub_section
) (const char *, asection
*);
3682 void (*layout_sections_again
) (void);
3684 /* Array to keep track of which stub sections have been created, and
3685 information on stub grouping. */
3687 /* This is the section to which stubs in the group will be attached. */
3689 /* The stub section. */
3691 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3695 /* Temp used when calculating TOC pointers. */
3698 asection
*toc_first_sec
;
3700 /* Highest input section id. */
3703 /* Highest output section index. */
3706 /* Used when adding symbols. */
3707 struct ppc_link_hash_entry
*dot_syms
;
3709 /* List of input sections for each output section. */
3710 asection
**input_list
;
3712 /* Short-cuts to get to dynamic linker sections. */
3724 asection
*glink_eh_frame
;
3726 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3727 struct ppc_link_hash_entry
*tls_get_addr
;
3728 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3730 /* The size of reliplt used by got entry relocs. */
3731 bfd_size_type got_reli_size
;
3734 unsigned long stub_count
[ppc_stub_plt_call
];
3736 /* Number of stubs against global syms. */
3737 unsigned long stub_globals
;
3739 /* Set if PLT call stubs should load r11. */
3740 unsigned int plt_static_chain
:1;
3742 /* Set if we should emit symbols for stubs. */
3743 unsigned int emit_stub_syms
:1;
3745 /* Set if __tls_get_addr optimization should not be done. */
3746 unsigned int no_tls_get_addr_opt
:1;
3748 /* Support for multiple toc sections. */
3749 unsigned int do_multi_toc
:1;
3750 unsigned int multi_toc_needed
:1;
3751 unsigned int second_toc_pass
:1;
3752 unsigned int do_toc_opt
:1;
3755 unsigned int stub_error
:1;
3757 /* Temp used by ppc64_elf_process_dot_syms. */
3758 unsigned int twiddled_syms
:1;
3760 /* Incremented every time we size stubs. */
3761 unsigned int stub_iteration
;
3763 /* Small local sym cache. */
3764 struct sym_cache sym_cache
;
3767 /* Rename some of the generic section flags to better document how they
3770 /* Nonzero if this section has TLS related relocations. */
3771 #define has_tls_reloc sec_flg0
3773 /* Nonzero if this section has a call to __tls_get_addr. */
3774 #define has_tls_get_addr_call sec_flg1
3776 /* Nonzero if this section has any toc or got relocs. */
3777 #define has_toc_reloc sec_flg2
3779 /* Nonzero if this section has a call to another section that uses
3781 #define makes_toc_func_call sec_flg3
3783 /* Recursion protection when determining above flag. */
3784 #define call_check_in_progress sec_flg4
3785 #define call_check_done sec_flg5
3787 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3789 #define ppc_hash_table(p) \
3790 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3791 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3793 #define ppc_stub_hash_lookup(table, string, create, copy) \
3794 ((struct ppc_stub_hash_entry *) \
3795 bfd_hash_lookup ((table), (string), (create), (copy)))
3797 #define ppc_branch_hash_lookup(table, string, create, copy) \
3798 ((struct ppc_branch_hash_entry *) \
3799 bfd_hash_lookup ((table), (string), (create), (copy)))
3801 /* Create an entry in the stub hash table. */
3803 static struct bfd_hash_entry
*
3804 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3805 struct bfd_hash_table
*table
,
3808 /* Allocate the structure if it has not already been allocated by a
3812 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3817 /* Call the allocation method of the superclass. */
3818 entry
= bfd_hash_newfunc (entry
, table
, string
);
3821 struct ppc_stub_hash_entry
*eh
;
3823 /* Initialize the local fields. */
3824 eh
= (struct ppc_stub_hash_entry
*) entry
;
3825 eh
->stub_type
= ppc_stub_none
;
3826 eh
->stub_sec
= NULL
;
3827 eh
->stub_offset
= 0;
3828 eh
->target_value
= 0;
3829 eh
->target_section
= NULL
;
3837 /* Create an entry in the branch hash table. */
3839 static struct bfd_hash_entry
*
3840 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3841 struct bfd_hash_table
*table
,
3844 /* Allocate the structure if it has not already been allocated by a
3848 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3853 /* Call the allocation method of the superclass. */
3854 entry
= bfd_hash_newfunc (entry
, table
, string
);
3857 struct ppc_branch_hash_entry
*eh
;
3859 /* Initialize the local fields. */
3860 eh
= (struct ppc_branch_hash_entry
*) entry
;
3868 /* Create an entry in a ppc64 ELF linker hash table. */
3870 static struct bfd_hash_entry
*
3871 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3872 struct bfd_hash_table
*table
,
3875 /* Allocate the structure if it has not already been allocated by a
3879 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3884 /* Call the allocation method of the superclass. */
3885 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3888 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3890 memset (&eh
->u
.stub_cache
, 0,
3891 (sizeof (struct ppc_link_hash_entry
)
3892 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3894 /* When making function calls, old ABI code references function entry
3895 points (dot symbols), while new ABI code references the function
3896 descriptor symbol. We need to make any combination of reference and
3897 definition work together, without breaking archive linking.
3899 For a defined function "foo" and an undefined call to "bar":
3900 An old object defines "foo" and ".foo", references ".bar" (possibly
3902 A new object defines "foo" and references "bar".
3904 A new object thus has no problem with its undefined symbols being
3905 satisfied by definitions in an old object. On the other hand, the
3906 old object won't have ".bar" satisfied by a new object.
3908 Keep a list of newly added dot-symbols. */
3910 if (string
[0] == '.')
3912 struct ppc_link_hash_table
*htab
;
3914 htab
= (struct ppc_link_hash_table
*) table
;
3915 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3916 htab
->dot_syms
= eh
;
3923 /* Create a ppc64 ELF linker hash table. */
3925 static struct bfd_link_hash_table
*
3926 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3928 struct ppc_link_hash_table
*htab
;
3929 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3931 htab
= bfd_zmalloc (amt
);
3935 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3936 sizeof (struct ppc_link_hash_entry
),
3943 /* Init the stub hash table too. */
3944 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3945 sizeof (struct ppc_stub_hash_entry
)))
3948 /* And the branch hash table. */
3949 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3950 sizeof (struct ppc_branch_hash_entry
)))
3953 /* Initializing two fields of the union is just cosmetic. We really
3954 only care about glist, but when compiled on a 32-bit host the
3955 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3956 debugger inspection of these fields look nicer. */
3957 htab
->elf
.init_got_refcount
.refcount
= 0;
3958 htab
->elf
.init_got_refcount
.glist
= NULL
;
3959 htab
->elf
.init_plt_refcount
.refcount
= 0;
3960 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3961 htab
->elf
.init_got_offset
.offset
= 0;
3962 htab
->elf
.init_got_offset
.glist
= NULL
;
3963 htab
->elf
.init_plt_offset
.offset
= 0;
3964 htab
->elf
.init_plt_offset
.glist
= NULL
;
3966 return &htab
->elf
.root
;
3969 /* Free the derived linker hash table. */
3972 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3974 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3976 bfd_hash_table_free (&ret
->stub_hash_table
);
3977 bfd_hash_table_free (&ret
->branch_hash_table
);
3978 _bfd_generic_link_hash_table_free (hash
);
3981 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3984 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3986 struct ppc_link_hash_table
*htab
;
3988 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3990 /* Always hook our dynamic sections into the first bfd, which is the
3991 linker created stub bfd. This ensures that the GOT header is at
3992 the start of the output TOC section. */
3993 htab
= ppc_hash_table (info
);
3996 htab
->stub_bfd
= abfd
;
3997 htab
->elf
.dynobj
= abfd
;
4000 /* Build a name for an entry in the stub hash table. */
4003 ppc_stub_name (const asection
*input_section
,
4004 const asection
*sym_sec
,
4005 const struct ppc_link_hash_entry
*h
,
4006 const Elf_Internal_Rela
*rel
)
4011 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4012 offsets from a sym as a branch target? In fact, we could
4013 probably assume the addend is always zero. */
4014 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4018 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4019 stub_name
= bfd_malloc (len
);
4020 if (stub_name
== NULL
)
4023 sprintf (stub_name
, "%08x.%s+%x",
4024 input_section
->id
& 0xffffffff,
4025 h
->elf
.root
.root
.string
,
4026 (int) rel
->r_addend
& 0xffffffff);
4030 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4031 stub_name
= bfd_malloc (len
);
4032 if (stub_name
== NULL
)
4035 sprintf (stub_name
, "%08x.%x:%x+%x",
4036 input_section
->id
& 0xffffffff,
4037 sym_sec
->id
& 0xffffffff,
4038 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4039 (int) rel
->r_addend
& 0xffffffff);
4041 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4042 stub_name
[len
- 2] = 0;
4046 /* Look up an entry in the stub hash. Stub entries are cached because
4047 creating the stub name takes a bit of time. */
4049 static struct ppc_stub_hash_entry
*
4050 ppc_get_stub_entry (const asection
*input_section
,
4051 const asection
*sym_sec
,
4052 struct ppc_link_hash_entry
*h
,
4053 const Elf_Internal_Rela
*rel
,
4054 struct ppc_link_hash_table
*htab
)
4056 struct ppc_stub_hash_entry
*stub_entry
;
4057 const asection
*id_sec
;
4059 /* If this input section is part of a group of sections sharing one
4060 stub section, then use the id of the first section in the group.
4061 Stub names need to include a section id, as there may well be
4062 more than one stub used to reach say, printf, and we need to
4063 distinguish between them. */
4064 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4066 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4067 && h
->u
.stub_cache
->h
== h
4068 && h
->u
.stub_cache
->id_sec
== id_sec
)
4070 stub_entry
= h
->u
.stub_cache
;
4076 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
4077 if (stub_name
== NULL
)
4080 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4081 stub_name
, FALSE
, FALSE
);
4083 h
->u
.stub_cache
= stub_entry
;
4091 /* Add a new stub entry to the stub hash. Not all fields of the new
4092 stub entry are initialised. */
4094 static struct ppc_stub_hash_entry
*
4095 ppc_add_stub (const char *stub_name
,
4097 struct bfd_link_info
*info
)
4099 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4102 struct ppc_stub_hash_entry
*stub_entry
;
4104 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
4105 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
4106 if (stub_sec
== NULL
)
4108 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
4109 if (stub_sec
== NULL
)
4115 namelen
= strlen (link_sec
->name
);
4116 len
= namelen
+ sizeof (STUB_SUFFIX
);
4117 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
4121 memcpy (s_name
, link_sec
->name
, namelen
);
4122 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4123 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
4124 if (stub_sec
== NULL
)
4126 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
4128 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
4131 /* Enter this entry into the linker stub hash table. */
4132 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4134 if (stub_entry
== NULL
)
4136 info
->callbacks
->einfo (_("%P: %B: cannot create stub entry %s\n"),
4137 section
->owner
, stub_name
);
4141 stub_entry
->stub_sec
= stub_sec
;
4142 stub_entry
->stub_offset
= 0;
4143 stub_entry
->id_sec
= link_sec
;
4147 /* Create sections for linker generated code. */
4150 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4152 struct ppc_link_hash_table
*htab
;
4155 htab
= ppc_hash_table (info
);
4159 /* Create .sfpr for code to save and restore fp regs. */
4160 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4161 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4162 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4164 if (htab
->sfpr
== NULL
4165 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4168 /* Create .glink for lazy dynamic linking support. */
4169 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4171 if (htab
->glink
== NULL
4172 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4175 if (!info
->no_ld_generated_unwind_info
)
4177 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4178 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4179 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4182 if (htab
->glink_eh_frame
== NULL
4183 || !bfd_set_section_alignment (abfd
, htab
->glink_eh_frame
, 2))
4187 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4188 htab
->iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4189 if (htab
->iplt
== NULL
4190 || ! bfd_set_section_alignment (dynobj
, htab
->iplt
, 3))
4193 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4194 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4195 htab
->reliplt
= bfd_make_section_anyway_with_flags (dynobj
,
4198 if (htab
->reliplt
== NULL
4199 || ! bfd_set_section_alignment (dynobj
, htab
->reliplt
, 3))
4202 /* Create branch lookup table for plt_branch stubs. */
4203 flags
= (SEC_ALLOC
| SEC_LOAD
4204 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4205 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4207 if (htab
->brlt
== NULL
4208 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4214 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4215 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4216 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4219 if (htab
->relbrlt
== NULL
4220 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4226 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4227 not already done. */
4230 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4232 asection
*got
, *relgot
;
4234 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4236 if (!is_ppc64_elf (abfd
))
4243 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4246 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
4251 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4252 | SEC_LINKER_CREATED
);
4254 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4256 || !bfd_set_section_alignment (abfd
, got
, 3))
4259 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4260 flags
| SEC_READONLY
);
4262 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4265 ppc64_elf_tdata (abfd
)->got
= got
;
4266 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4270 /* Create the dynamic sections, and set up shortcuts. */
4273 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4275 struct ppc_link_hash_table
*htab
;
4277 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4280 htab
= ppc_hash_table (info
);
4285 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
4286 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
4287 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4288 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
4290 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
4292 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
4293 || (!info
->shared
&& !htab
->relbss
))
4299 /* Follow indirect and warning symbol links. */
4301 static inline struct bfd_link_hash_entry
*
4302 follow_link (struct bfd_link_hash_entry
*h
)
4304 while (h
->type
== bfd_link_hash_indirect
4305 || h
->type
== bfd_link_hash_warning
)
4310 static inline struct elf_link_hash_entry
*
4311 elf_follow_link (struct elf_link_hash_entry
*h
)
4313 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4316 static inline struct ppc_link_hash_entry
*
4317 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4319 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4322 /* Merge PLT info on FROM with that on TO. */
4325 move_plt_plist (struct ppc_link_hash_entry
*from
,
4326 struct ppc_link_hash_entry
*to
)
4328 if (from
->elf
.plt
.plist
!= NULL
)
4330 if (to
->elf
.plt
.plist
!= NULL
)
4332 struct plt_entry
**entp
;
4333 struct plt_entry
*ent
;
4335 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4337 struct plt_entry
*dent
;
4339 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4340 if (dent
->addend
== ent
->addend
)
4342 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4349 *entp
= to
->elf
.plt
.plist
;
4352 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4353 from
->elf
.plt
.plist
= NULL
;
4357 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4360 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4361 struct elf_link_hash_entry
*dir
,
4362 struct elf_link_hash_entry
*ind
)
4364 struct ppc_link_hash_entry
*edir
, *eind
;
4366 edir
= (struct ppc_link_hash_entry
*) dir
;
4367 eind
= (struct ppc_link_hash_entry
*) ind
;
4369 edir
->is_func
|= eind
->is_func
;
4370 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4371 edir
->tls_mask
|= eind
->tls_mask
;
4372 if (eind
->oh
!= NULL
)
4373 edir
->oh
= ppc_follow_link (eind
->oh
);
4375 /* If called to transfer flags for a weakdef during processing
4376 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4377 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4378 if (!(ELIMINATE_COPY_RELOCS
4379 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4380 && edir
->elf
.dynamic_adjusted
))
4381 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4383 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4384 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4385 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4386 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4388 /* If we were called to copy over info for a weak sym, that's all. */
4389 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4392 /* Copy over any dynamic relocs we may have on the indirect sym. */
4393 if (eind
->dyn_relocs
!= NULL
)
4395 if (edir
->dyn_relocs
!= NULL
)
4397 struct elf_dyn_relocs
**pp
;
4398 struct elf_dyn_relocs
*p
;
4400 /* Add reloc counts against the indirect sym to the direct sym
4401 list. Merge any entries against the same section. */
4402 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4404 struct elf_dyn_relocs
*q
;
4406 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4407 if (q
->sec
== p
->sec
)
4409 q
->pc_count
+= p
->pc_count
;
4410 q
->count
+= p
->count
;
4417 *pp
= edir
->dyn_relocs
;
4420 edir
->dyn_relocs
= eind
->dyn_relocs
;
4421 eind
->dyn_relocs
= NULL
;
4424 /* Copy over got entries that we may have already seen to the
4425 symbol which just became indirect. */
4426 if (eind
->elf
.got
.glist
!= NULL
)
4428 if (edir
->elf
.got
.glist
!= NULL
)
4430 struct got_entry
**entp
;
4431 struct got_entry
*ent
;
4433 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4435 struct got_entry
*dent
;
4437 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4438 if (dent
->addend
== ent
->addend
4439 && dent
->owner
== ent
->owner
4440 && dent
->tls_type
== ent
->tls_type
)
4442 dent
->got
.refcount
+= ent
->got
.refcount
;
4449 *entp
= edir
->elf
.got
.glist
;
4452 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4453 eind
->elf
.got
.glist
= NULL
;
4456 /* And plt entries. */
4457 move_plt_plist (eind
, edir
);
4459 if (eind
->elf
.dynindx
!= -1)
4461 if (edir
->elf
.dynindx
!= -1)
4462 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4463 edir
->elf
.dynstr_index
);
4464 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4465 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4466 eind
->elf
.dynindx
= -1;
4467 eind
->elf
.dynstr_index
= 0;
4471 /* Find the function descriptor hash entry from the given function code
4472 hash entry FH. Link the entries via their OH fields. */
4474 static struct ppc_link_hash_entry
*
4475 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4477 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4481 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4483 fdh
= (struct ppc_link_hash_entry
*)
4484 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4488 fdh
->is_func_descriptor
= 1;
4494 return ppc_follow_link (fdh
);
4497 /* Make a fake function descriptor sym for the code sym FH. */
4499 static struct ppc_link_hash_entry
*
4500 make_fdh (struct bfd_link_info
*info
,
4501 struct ppc_link_hash_entry
*fh
)
4505 struct bfd_link_hash_entry
*bh
;
4506 struct ppc_link_hash_entry
*fdh
;
4508 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4509 newsym
= bfd_make_empty_symbol (abfd
);
4510 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4511 newsym
->section
= bfd_und_section_ptr
;
4513 newsym
->flags
= BSF_WEAK
;
4516 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4517 newsym
->flags
, newsym
->section
,
4518 newsym
->value
, NULL
, FALSE
, FALSE
,
4522 fdh
= (struct ppc_link_hash_entry
*) bh
;
4523 fdh
->elf
.non_elf
= 0;
4525 fdh
->is_func_descriptor
= 1;
4532 /* Fix function descriptor symbols defined in .opd sections to be
4536 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4537 struct bfd_link_info
*info
,
4538 Elf_Internal_Sym
*isym
,
4539 const char **name ATTRIBUTE_UNUSED
,
4540 flagword
*flags ATTRIBUTE_UNUSED
,
4542 bfd_vma
*value ATTRIBUTE_UNUSED
)
4544 if ((ibfd
->flags
& DYNAMIC
) == 0
4545 && ELF_ST_BIND (isym
->st_info
) == STB_GNU_UNIQUE
)
4546 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4548 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4550 if ((ibfd
->flags
& DYNAMIC
) == 0)
4551 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4553 else if (ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
)
4555 else if (*sec
!= NULL
4556 && strcmp ((*sec
)->name
, ".opd") == 0)
4557 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4562 /* This function makes an old ABI object reference to ".bar" cause the
4563 inclusion of a new ABI object archive that defines "bar".
4564 NAME is a symbol defined in an archive. Return a symbol in the hash
4565 table that might be satisfied by the archive symbols. */
4567 static struct elf_link_hash_entry
*
4568 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4569 struct bfd_link_info
*info
,
4572 struct elf_link_hash_entry
*h
;
4576 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4578 /* Don't return this sym if it is a fake function descriptor
4579 created by add_symbol_adjust. */
4580 && !(h
->root
.type
== bfd_link_hash_undefweak
4581 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4587 len
= strlen (name
);
4588 dot_name
= bfd_alloc (abfd
, len
+ 2);
4589 if (dot_name
== NULL
)
4590 return (struct elf_link_hash_entry
*) 0 - 1;
4592 memcpy (dot_name
+ 1, name
, len
+ 1);
4593 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4594 bfd_release (abfd
, dot_name
);
4598 /* This function satisfies all old ABI object references to ".bar" if a
4599 new ABI object defines "bar". Well, at least, undefined dot symbols
4600 are made weak. This stops later archive searches from including an
4601 object if we already have a function descriptor definition. It also
4602 prevents the linker complaining about undefined symbols.
4603 We also check and correct mismatched symbol visibility here. The
4604 most restrictive visibility of the function descriptor and the
4605 function entry symbol is used. */
4608 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4610 struct ppc_link_hash_table
*htab
;
4611 struct ppc_link_hash_entry
*fdh
;
4613 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4616 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4617 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4619 if (eh
->elf
.root
.root
.string
[0] != '.')
4622 htab
= ppc_hash_table (info
);
4626 fdh
= lookup_fdh (eh
, htab
);
4629 if (!info
->relocatable
4630 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4631 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4632 && eh
->elf
.ref_regular
)
4634 /* Make an undefweak function descriptor sym, which is enough to
4635 pull in an --as-needed shared lib, but won't cause link
4636 errors. Archives are handled elsewhere. */
4637 fdh
= make_fdh (info
, eh
);
4640 fdh
->elf
.ref_regular
= 1;
4645 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4646 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4647 if (entry_vis
< descr_vis
)
4648 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4649 else if (entry_vis
> descr_vis
)
4650 eh
->elf
.other
+= descr_vis
- entry_vis
;
4652 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4653 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4654 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4656 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4657 eh
->was_undefined
= 1;
4658 htab
->twiddled_syms
= 1;
4665 /* Process list of dot-symbols we made in link_hash_newfunc. */
4668 ppc64_elf_process_dot_syms (bfd
*ibfd
, struct bfd_link_info
*info
)
4670 struct ppc_link_hash_table
*htab
;
4671 struct ppc_link_hash_entry
**p
, *eh
;
4673 if (!is_ppc64_elf (info
->output_bfd
))
4675 htab
= ppc_hash_table (info
);
4679 if (is_ppc64_elf (ibfd
))
4681 p
= &htab
->dot_syms
;
4682 while ((eh
= *p
) != NULL
)
4685 if (!add_symbol_adjust (eh
, info
))
4687 p
= &eh
->u
.next_dot_sym
;
4691 /* Clear the list for non-ppc64 input files. */
4692 p
= &htab
->dot_syms
;
4693 while ((eh
= *p
) != NULL
)
4696 p
= &eh
->u
.next_dot_sym
;
4699 /* We need to fix the undefs list for any syms we have twiddled to
4701 if (htab
->twiddled_syms
)
4703 bfd_link_repair_undef_list (&htab
->elf
.root
);
4704 htab
->twiddled_syms
= 0;
4709 /* Undo hash table changes when an --as-needed input file is determined
4710 not to be needed. */
4713 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4714 struct bfd_link_info
*info
)
4716 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4721 htab
->dot_syms
= NULL
;
4725 /* If --just-symbols against a final linked binary, then assume we need
4726 toc adjusting stubs when calling functions defined there. */
4729 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4731 if ((sec
->flags
& SEC_CODE
) != 0
4732 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4733 && is_ppc64_elf (sec
->owner
))
4735 asection
*got
= bfd_get_section_by_name (sec
->owner
, ".got");
4737 && got
->size
>= elf_backend_got_header_size
4738 && bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4739 sec
->has_toc_reloc
= 1;
4741 _bfd_elf_link_just_syms (sec
, info
);
4744 static struct plt_entry
**
4745 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4746 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4748 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4749 struct plt_entry
**local_plt
;
4750 unsigned char *local_got_tls_masks
;
4752 if (local_got_ents
== NULL
)
4754 bfd_size_type size
= symtab_hdr
->sh_info
;
4756 size
*= (sizeof (*local_got_ents
)
4757 + sizeof (*local_plt
)
4758 + sizeof (*local_got_tls_masks
));
4759 local_got_ents
= bfd_zalloc (abfd
, size
);
4760 if (local_got_ents
== NULL
)
4762 elf_local_got_ents (abfd
) = local_got_ents
;
4765 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
4767 struct got_entry
*ent
;
4769 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4770 if (ent
->addend
== r_addend
4771 && ent
->owner
== abfd
4772 && ent
->tls_type
== tls_type
)
4776 bfd_size_type amt
= sizeof (*ent
);
4777 ent
= bfd_alloc (abfd
, amt
);
4780 ent
->next
= local_got_ents
[r_symndx
];
4781 ent
->addend
= r_addend
;
4783 ent
->tls_type
= tls_type
;
4784 ent
->is_indirect
= FALSE
;
4785 ent
->got
.refcount
= 0;
4786 local_got_ents
[r_symndx
] = ent
;
4788 ent
->got
.refcount
+= 1;
4791 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4792 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4793 local_got_tls_masks
[r_symndx
] |= tls_type
;
4795 return local_plt
+ r_symndx
;
4799 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4801 struct plt_entry
*ent
;
4803 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4804 if (ent
->addend
== addend
)
4808 bfd_size_type amt
= sizeof (*ent
);
4809 ent
= bfd_alloc (abfd
, amt
);
4813 ent
->addend
= addend
;
4814 ent
->plt
.refcount
= 0;
4817 ent
->plt
.refcount
+= 1;
4822 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4824 return (r_type
== R_PPC64_REL24
4825 || r_type
== R_PPC64_REL14
4826 || r_type
== R_PPC64_REL14_BRTAKEN
4827 || r_type
== R_PPC64_REL14_BRNTAKEN
4828 || r_type
== R_PPC64_ADDR24
4829 || r_type
== R_PPC64_ADDR14
4830 || r_type
== R_PPC64_ADDR14_BRTAKEN
4831 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
4834 /* Look through the relocs for a section during the first phase, and
4835 calculate needed space in the global offset table, procedure
4836 linkage table, and dynamic reloc sections. */
4839 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4840 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4842 struct ppc_link_hash_table
*htab
;
4843 Elf_Internal_Shdr
*symtab_hdr
;
4844 struct elf_link_hash_entry
**sym_hashes
;
4845 const Elf_Internal_Rela
*rel
;
4846 const Elf_Internal_Rela
*rel_end
;
4848 asection
**opd_sym_map
;
4849 struct elf_link_hash_entry
*tga
, *dottga
;
4851 if (info
->relocatable
)
4854 /* Don't do anything special with non-loaded, non-alloced sections.
4855 In particular, any relocs in such sections should not affect GOT
4856 and PLT reference counting (ie. we don't allow them to create GOT
4857 or PLT entries), there's no possibility or desire to optimize TLS
4858 relocs, and there's not much point in propagating relocs to shared
4859 libs that the dynamic linker won't relocate. */
4860 if ((sec
->flags
& SEC_ALLOC
) == 0)
4863 BFD_ASSERT (is_ppc64_elf (abfd
));
4865 htab
= ppc_hash_table (info
);
4869 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4870 FALSE
, FALSE
, TRUE
);
4871 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4872 FALSE
, FALSE
, TRUE
);
4873 symtab_hdr
= &elf_symtab_hdr (abfd
);
4874 sym_hashes
= elf_sym_hashes (abfd
);
4877 if (strcmp (sec
->name
, ".opd") == 0)
4879 /* Garbage collection needs some extra help with .opd sections.
4880 We don't want to necessarily keep everything referenced by
4881 relocs in .opd, as that would keep all functions. Instead,
4882 if we reference an .opd symbol (a function descriptor), we
4883 want to keep the function code symbol's section. This is
4884 easy for global symbols, but for local syms we need to keep
4885 information about the associated function section. */
4888 amt
= sec
->size
* sizeof (*opd_sym_map
) / 8;
4889 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4890 if (opd_sym_map
== NULL
)
4892 ppc64_elf_section_data (sec
)->u
.opd
.func_sec
= opd_sym_map
;
4893 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4894 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4897 if (htab
->sfpr
== NULL
4898 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4901 rel_end
= relocs
+ sec
->reloc_count
;
4902 for (rel
= relocs
; rel
< rel_end
; rel
++)
4904 unsigned long r_symndx
;
4905 struct elf_link_hash_entry
*h
;
4906 enum elf_ppc64_reloc_type r_type
;
4908 struct _ppc64_elf_section_data
*ppc64_sec
;
4909 struct plt_entry
**ifunc
;
4911 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4912 if (r_symndx
< symtab_hdr
->sh_info
)
4916 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4917 h
= elf_follow_link (h
);
4924 if (h
->type
== STT_GNU_IFUNC
)
4927 ifunc
= &h
->plt
.plist
;
4932 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4937 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4939 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4940 rel
->r_addend
, PLT_IFUNC
);
4945 r_type
= ELF64_R_TYPE (rel
->r_info
);
4946 if (is_branch_reloc (r_type
))
4948 if (h
!= NULL
&& (h
== tga
|| h
== dottga
))
4951 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4952 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4953 /* We have a new-style __tls_get_addr call with a marker
4957 /* Mark this section as having an old-style call. */
4958 sec
->has_tls_get_addr_call
= 1;
4961 /* STT_GNU_IFUNC symbols must have a PLT entry. */
4963 && !update_plt_info (abfd
, ifunc
, rel
->r_addend
))
4971 /* These special tls relocs tie a call to __tls_get_addr with
4972 its parameter symbol. */
4975 case R_PPC64_GOT_TLSLD16
:
4976 case R_PPC64_GOT_TLSLD16_LO
:
4977 case R_PPC64_GOT_TLSLD16_HI
:
4978 case R_PPC64_GOT_TLSLD16_HA
:
4979 tls_type
= TLS_TLS
| TLS_LD
;
4982 case R_PPC64_GOT_TLSGD16
:
4983 case R_PPC64_GOT_TLSGD16_LO
:
4984 case R_PPC64_GOT_TLSGD16_HI
:
4985 case R_PPC64_GOT_TLSGD16_HA
:
4986 tls_type
= TLS_TLS
| TLS_GD
;
4989 case R_PPC64_GOT_TPREL16_DS
:
4990 case R_PPC64_GOT_TPREL16_LO_DS
:
4991 case R_PPC64_GOT_TPREL16_HI
:
4992 case R_PPC64_GOT_TPREL16_HA
:
4993 if (!info
->executable
)
4994 info
->flags
|= DF_STATIC_TLS
;
4995 tls_type
= TLS_TLS
| TLS_TPREL
;
4998 case R_PPC64_GOT_DTPREL16_DS
:
4999 case R_PPC64_GOT_DTPREL16_LO_DS
:
5000 case R_PPC64_GOT_DTPREL16_HI
:
5001 case R_PPC64_GOT_DTPREL16_HA
:
5002 tls_type
= TLS_TLS
| TLS_DTPREL
;
5004 sec
->has_tls_reloc
= 1;
5008 case R_PPC64_GOT16_DS
:
5009 case R_PPC64_GOT16_HA
:
5010 case R_PPC64_GOT16_HI
:
5011 case R_PPC64_GOT16_LO
:
5012 case R_PPC64_GOT16_LO_DS
:
5013 /* This symbol requires a global offset table entry. */
5014 sec
->has_toc_reloc
= 1;
5015 if (r_type
== R_PPC64_GOT_TLSLD16
5016 || r_type
== R_PPC64_GOT_TLSGD16
5017 || r_type
== R_PPC64_GOT_TPREL16_DS
5018 || r_type
== R_PPC64_GOT_DTPREL16_DS
5019 || r_type
== R_PPC64_GOT16
5020 || r_type
== R_PPC64_GOT16_DS
)
5022 htab
->do_multi_toc
= 1;
5023 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5026 if (ppc64_elf_tdata (abfd
)->got
== NULL
5027 && !create_got_section (abfd
, info
))
5032 struct ppc_link_hash_entry
*eh
;
5033 struct got_entry
*ent
;
5035 eh
= (struct ppc_link_hash_entry
*) h
;
5036 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5037 if (ent
->addend
== rel
->r_addend
5038 && ent
->owner
== abfd
5039 && ent
->tls_type
== tls_type
)
5043 bfd_size_type amt
= sizeof (*ent
);
5044 ent
= bfd_alloc (abfd
, amt
);
5047 ent
->next
= eh
->elf
.got
.glist
;
5048 ent
->addend
= rel
->r_addend
;
5050 ent
->tls_type
= tls_type
;
5051 ent
->is_indirect
= FALSE
;
5052 ent
->got
.refcount
= 0;
5053 eh
->elf
.got
.glist
= ent
;
5055 ent
->got
.refcount
+= 1;
5056 eh
->tls_mask
|= tls_type
;
5059 /* This is a global offset table entry for a local symbol. */
5060 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5061 rel
->r_addend
, tls_type
))
5065 case R_PPC64_PLT16_HA
:
5066 case R_PPC64_PLT16_HI
:
5067 case R_PPC64_PLT16_LO
:
5070 /* This symbol requires a procedure linkage table entry. We
5071 actually build the entry in adjust_dynamic_symbol,
5072 because this might be a case of linking PIC code without
5073 linking in any dynamic objects, in which case we don't
5074 need to generate a procedure linkage table after all. */
5077 /* It does not make sense to have a procedure linkage
5078 table entry for a local symbol. */
5079 bfd_set_error (bfd_error_bad_value
);
5084 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5087 if (h
->root
.root
.string
[0] == '.'
5088 && h
->root
.root
.string
[1] != '\0')
5089 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5093 /* The following relocations don't need to propagate the
5094 relocation if linking a shared object since they are
5095 section relative. */
5096 case R_PPC64_SECTOFF
:
5097 case R_PPC64_SECTOFF_LO
:
5098 case R_PPC64_SECTOFF_HI
:
5099 case R_PPC64_SECTOFF_HA
:
5100 case R_PPC64_SECTOFF_DS
:
5101 case R_PPC64_SECTOFF_LO_DS
:
5102 case R_PPC64_DTPREL16
:
5103 case R_PPC64_DTPREL16_LO
:
5104 case R_PPC64_DTPREL16_HI
:
5105 case R_PPC64_DTPREL16_HA
:
5106 case R_PPC64_DTPREL16_DS
:
5107 case R_PPC64_DTPREL16_LO_DS
:
5108 case R_PPC64_DTPREL16_HIGHER
:
5109 case R_PPC64_DTPREL16_HIGHERA
:
5110 case R_PPC64_DTPREL16_HIGHEST
:
5111 case R_PPC64_DTPREL16_HIGHESTA
:
5116 case R_PPC64_REL16_LO
:
5117 case R_PPC64_REL16_HI
:
5118 case R_PPC64_REL16_HA
:
5122 case R_PPC64_TOC16_DS
:
5123 htab
->do_multi_toc
= 1;
5124 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5125 case R_PPC64_TOC16_LO
:
5126 case R_PPC64_TOC16_HI
:
5127 case R_PPC64_TOC16_HA
:
5128 case R_PPC64_TOC16_LO_DS
:
5129 sec
->has_toc_reloc
= 1;
5132 /* This relocation describes the C++ object vtable hierarchy.
5133 Reconstruct it for later use during GC. */
5134 case R_PPC64_GNU_VTINHERIT
:
5135 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5139 /* This relocation describes which C++ vtable entries are actually
5140 used. Record for later use during GC. */
5141 case R_PPC64_GNU_VTENTRY
:
5142 BFD_ASSERT (h
!= NULL
);
5144 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5149 case R_PPC64_REL14_BRTAKEN
:
5150 case R_PPC64_REL14_BRNTAKEN
:
5152 asection
*dest
= NULL
;
5154 /* Heuristic: If jumping outside our section, chances are
5155 we are going to need a stub. */
5158 /* If the sym is weak it may be overridden later, so
5159 don't assume we know where a weak sym lives. */
5160 if (h
->root
.type
== bfd_link_hash_defined
)
5161 dest
= h
->root
.u
.def
.section
;
5165 Elf_Internal_Sym
*isym
;
5167 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5172 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5176 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5181 if (h
!= NULL
&& ifunc
== NULL
)
5183 /* We may need a .plt entry if the function this reloc
5184 refers to is in a shared lib. */
5185 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5188 if (h
->root
.root
.string
[0] == '.'
5189 && h
->root
.root
.string
[1] != '\0')
5190 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5191 if (h
== tga
|| h
== dottga
)
5192 sec
->has_tls_reloc
= 1;
5196 case R_PPC64_TPREL64
:
5197 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5198 if (!info
->executable
)
5199 info
->flags
|= DF_STATIC_TLS
;
5202 case R_PPC64_DTPMOD64
:
5203 if (rel
+ 1 < rel_end
5204 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5205 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5206 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5208 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5211 case R_PPC64_DTPREL64
:
5212 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5214 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5215 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5216 /* This is the second reloc of a dtpmod, dtprel pair.
5217 Don't mark with TLS_DTPREL. */
5221 sec
->has_tls_reloc
= 1;
5224 struct ppc_link_hash_entry
*eh
;
5225 eh
= (struct ppc_link_hash_entry
*) h
;
5226 eh
->tls_mask
|= tls_type
;
5229 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5230 rel
->r_addend
, tls_type
))
5233 ppc64_sec
= ppc64_elf_section_data (sec
);
5234 if (ppc64_sec
->sec_type
!= sec_toc
)
5238 /* One extra to simplify get_tls_mask. */
5239 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5240 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5241 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5243 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5244 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5245 if (ppc64_sec
->u
.toc
.add
== NULL
)
5247 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5248 ppc64_sec
->sec_type
= sec_toc
;
5250 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5251 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5252 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5254 /* Mark the second slot of a GD or LD entry.
5255 -1 to indicate GD and -2 to indicate LD. */
5256 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5257 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5258 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5259 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5262 case R_PPC64_TPREL16
:
5263 case R_PPC64_TPREL16_LO
:
5264 case R_PPC64_TPREL16_HI
:
5265 case R_PPC64_TPREL16_HA
:
5266 case R_PPC64_TPREL16_DS
:
5267 case R_PPC64_TPREL16_LO_DS
:
5268 case R_PPC64_TPREL16_HIGHER
:
5269 case R_PPC64_TPREL16_HIGHERA
:
5270 case R_PPC64_TPREL16_HIGHEST
:
5271 case R_PPC64_TPREL16_HIGHESTA
:
5274 if (!info
->executable
)
5275 info
->flags
|= DF_STATIC_TLS
;
5280 case R_PPC64_ADDR64
:
5281 if (opd_sym_map
!= NULL
5282 && rel
+ 1 < rel_end
5283 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5287 if (h
->root
.root
.string
[0] == '.'
5288 && h
->root
.root
.string
[1] != 0
5289 && lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
5292 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5297 Elf_Internal_Sym
*isym
;
5299 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5304 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5305 if (s
!= NULL
&& s
!= sec
)
5306 opd_sym_map
[rel
->r_offset
/ 8] = s
;
5314 case R_PPC64_ADDR14
:
5315 case R_PPC64_ADDR14_BRNTAKEN
:
5316 case R_PPC64_ADDR14_BRTAKEN
:
5317 case R_PPC64_ADDR16
:
5318 case R_PPC64_ADDR16_DS
:
5319 case R_PPC64_ADDR16_HA
:
5320 case R_PPC64_ADDR16_HI
:
5321 case R_PPC64_ADDR16_HIGHER
:
5322 case R_PPC64_ADDR16_HIGHERA
:
5323 case R_PPC64_ADDR16_HIGHEST
:
5324 case R_PPC64_ADDR16_HIGHESTA
:
5325 case R_PPC64_ADDR16_LO
:
5326 case R_PPC64_ADDR16_LO_DS
:
5327 case R_PPC64_ADDR24
:
5328 case R_PPC64_ADDR32
:
5329 case R_PPC64_UADDR16
:
5330 case R_PPC64_UADDR32
:
5331 case R_PPC64_UADDR64
:
5333 if (h
!= NULL
&& !info
->shared
)
5334 /* We may need a copy reloc. */
5337 /* Don't propagate .opd relocs. */
5338 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5341 /* If we are creating a shared library, and this is a reloc
5342 against a global symbol, or a non PC relative reloc
5343 against a local symbol, then we need to copy the reloc
5344 into the shared library. However, if we are linking with
5345 -Bsymbolic, we do not need to copy a reloc against a
5346 global symbol which is defined in an object we are
5347 including in the link (i.e., DEF_REGULAR is set). At
5348 this point we have not seen all the input files, so it is
5349 possible that DEF_REGULAR is not set now but will be set
5350 later (it is never cleared). In case of a weak definition,
5351 DEF_REGULAR may be cleared later by a strong definition in
5352 a shared library. We account for that possibility below by
5353 storing information in the dyn_relocs field of the hash
5354 table entry. A similar situation occurs when creating
5355 shared libraries and symbol visibility changes render the
5358 If on the other hand, we are creating an executable, we
5359 may need to keep relocations for symbols satisfied by a
5360 dynamic library if we manage to avoid copy relocs for the
5364 && (must_be_dyn_reloc (info
, r_type
)
5366 && (! info
->symbolic
5367 || h
->root
.type
== bfd_link_hash_defweak
5368 || !h
->def_regular
))))
5369 || (ELIMINATE_COPY_RELOCS
5372 && (h
->root
.type
== bfd_link_hash_defweak
5373 || !h
->def_regular
))
5377 struct elf_dyn_relocs
*p
;
5378 struct elf_dyn_relocs
**head
;
5380 /* We must copy these reloc types into the output file.
5381 Create a reloc section in dynobj and make room for
5385 sreloc
= _bfd_elf_make_dynamic_reloc_section
5386 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5392 /* If this is a global symbol, we count the number of
5393 relocations we need for this symbol. */
5396 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5400 /* Track dynamic relocs needed for local syms too.
5401 We really need local syms available to do this
5405 Elf_Internal_Sym
*isym
;
5407 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5412 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5416 vpp
= &elf_section_data (s
)->local_dynrel
;
5417 head
= (struct elf_dyn_relocs
**) vpp
;
5421 if (p
== NULL
|| p
->sec
!= sec
)
5423 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5434 if (!must_be_dyn_reloc (info
, r_type
))
5447 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5448 of the code entry point, and its section. */
5451 opd_entry_value (asection
*opd_sec
,
5453 asection
**code_sec
,
5456 bfd
*opd_bfd
= opd_sec
->owner
;
5457 Elf_Internal_Rela
*relocs
;
5458 Elf_Internal_Rela
*lo
, *hi
, *look
;
5461 /* No relocs implies we are linking a --just-symbols object. */
5462 if (opd_sec
->reloc_count
== 0)
5466 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, buf
, offset
, 8))
5467 return (bfd_vma
) -1;
5469 val
= bfd_get_64 (opd_bfd
, buf
);
5470 if (code_sec
!= NULL
)
5472 asection
*sec
, *likely
= NULL
;
5473 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5475 && (sec
->flags
& SEC_LOAD
) != 0
5476 && (sec
->flags
& SEC_ALLOC
) != 0)
5481 if (code_off
!= NULL
)
5482 *code_off
= val
- likely
->vma
;
5488 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5490 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
5492 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5494 /* Go find the opd reloc at the sym address. */
5496 BFD_ASSERT (lo
!= NULL
);
5497 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5501 look
= lo
+ (hi
- lo
) / 2;
5502 if (look
->r_offset
< offset
)
5504 else if (look
->r_offset
> offset
)
5508 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5510 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5511 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5513 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5516 if (symndx
< symtab_hdr
->sh_info
)
5518 Elf_Internal_Sym
*sym
;
5520 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5523 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5524 symtab_hdr
->sh_info
,
5525 0, NULL
, NULL
, NULL
);
5528 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5532 val
= sym
->st_value
;
5533 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5534 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5538 struct elf_link_hash_entry
**sym_hashes
;
5539 struct elf_link_hash_entry
*rh
;
5541 sym_hashes
= elf_sym_hashes (opd_bfd
);
5542 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5543 rh
= elf_follow_link (rh
);
5544 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5545 || rh
->root
.type
== bfd_link_hash_defweak
);
5546 val
= rh
->root
.u
.def
.value
;
5547 sec
= rh
->root
.u
.def
.section
;
5549 val
+= look
->r_addend
;
5550 if (code_off
!= NULL
)
5552 if (code_sec
!= NULL
)
5554 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5555 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5564 /* Return true if symbol is defined in a regular object file. */
5567 is_static_defined (struct elf_link_hash_entry
*h
)
5569 return ((h
->root
.type
== bfd_link_hash_defined
5570 || h
->root
.type
== bfd_link_hash_defweak
)
5571 && h
->root
.u
.def
.section
!= NULL
5572 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5575 /* If FDH is a function descriptor symbol, return the associated code
5576 entry symbol if it is defined. Return NULL otherwise. */
5578 static struct ppc_link_hash_entry
*
5579 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5581 if (fdh
->is_func_descriptor
)
5583 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5584 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5585 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5591 /* If FH is a function code entry symbol, return the associated
5592 function descriptor symbol if it is defined. Return NULL otherwise. */
5594 static struct ppc_link_hash_entry
*
5595 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5598 && fh
->oh
->is_func_descriptor
)
5600 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5601 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5602 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5608 /* Mark all our entry sym sections, both opd and code section. */
5611 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5613 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5614 struct bfd_sym_chain
*sym
;
5619 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5621 struct ppc_link_hash_entry
*eh
, *fh
;
5624 eh
= (struct ppc_link_hash_entry
*)
5625 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5628 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5629 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5632 fh
= defined_code_entry (eh
);
5635 sec
= fh
->elf
.root
.u
.def
.section
;
5636 sec
->flags
|= SEC_KEEP
;
5638 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5639 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5640 eh
->elf
.root
.u
.def
.value
,
5641 &sec
, NULL
) != (bfd_vma
) -1)
5642 sec
->flags
|= SEC_KEEP
;
5644 sec
= eh
->elf
.root
.u
.def
.section
;
5645 sec
->flags
|= SEC_KEEP
;
5649 /* Mark sections containing dynamically referenced symbols. When
5650 building shared libraries, we must assume that any visible symbol is
5654 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5656 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5657 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5658 struct ppc_link_hash_entry
*fdh
;
5660 /* Dynamic linking info is on the func descriptor sym. */
5661 fdh
= defined_func_desc (eh
);
5665 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5666 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5667 && (eh
->elf
.ref_dynamic
5668 || (!info
->executable
5669 && eh
->elf
.def_regular
5670 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5671 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5674 struct ppc_link_hash_entry
*fh
;
5676 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5678 /* Function descriptor syms cause the associated
5679 function code sym section to be marked. */
5680 fh
= defined_code_entry (eh
);
5683 code_sec
= fh
->elf
.root
.u
.def
.section
;
5684 code_sec
->flags
|= SEC_KEEP
;
5686 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5687 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5688 eh
->elf
.root
.u
.def
.value
,
5689 &code_sec
, NULL
) != (bfd_vma
) -1)
5690 code_sec
->flags
|= SEC_KEEP
;
5696 /* Return the section that should be marked against GC for a given
5700 ppc64_elf_gc_mark_hook (asection
*sec
,
5701 struct bfd_link_info
*info
,
5702 Elf_Internal_Rela
*rel
,
5703 struct elf_link_hash_entry
*h
,
5704 Elf_Internal_Sym
*sym
)
5708 /* Syms return NULL if we're marking .opd, so we avoid marking all
5709 function sections, as all functions are referenced in .opd. */
5711 if (get_opd_info (sec
) != NULL
)
5716 enum elf_ppc64_reloc_type r_type
;
5717 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5719 r_type
= ELF64_R_TYPE (rel
->r_info
);
5722 case R_PPC64_GNU_VTINHERIT
:
5723 case R_PPC64_GNU_VTENTRY
:
5727 switch (h
->root
.type
)
5729 case bfd_link_hash_defined
:
5730 case bfd_link_hash_defweak
:
5731 eh
= (struct ppc_link_hash_entry
*) h
;
5732 fdh
= defined_func_desc (eh
);
5736 /* Function descriptor syms cause the associated
5737 function code sym section to be marked. */
5738 fh
= defined_code_entry (eh
);
5741 /* They also mark their opd section. */
5742 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5744 rsec
= fh
->elf
.root
.u
.def
.section
;
5746 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5747 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5748 eh
->elf
.root
.u
.def
.value
,
5749 &rsec
, NULL
) != (bfd_vma
) -1)
5750 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5752 rsec
= h
->root
.u
.def
.section
;
5755 case bfd_link_hash_common
:
5756 rsec
= h
->root
.u
.c
.p
->section
;
5760 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5766 struct _opd_sec_data
*opd
;
5768 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5769 opd
= get_opd_info (rsec
);
5770 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5774 rsec
= opd
->func_sec
[(sym
->st_value
+ rel
->r_addend
) / 8];
5781 /* Update the .got, .plt. and dynamic reloc reference counts for the
5782 section being removed. */
5785 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5786 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5788 struct ppc_link_hash_table
*htab
;
5789 Elf_Internal_Shdr
*symtab_hdr
;
5790 struct elf_link_hash_entry
**sym_hashes
;
5791 struct got_entry
**local_got_ents
;
5792 const Elf_Internal_Rela
*rel
, *relend
;
5794 if (info
->relocatable
)
5797 if ((sec
->flags
& SEC_ALLOC
) == 0)
5800 elf_section_data (sec
)->local_dynrel
= NULL
;
5802 htab
= ppc_hash_table (info
);
5806 symtab_hdr
= &elf_symtab_hdr (abfd
);
5807 sym_hashes
= elf_sym_hashes (abfd
);
5808 local_got_ents
= elf_local_got_ents (abfd
);
5810 relend
= relocs
+ sec
->reloc_count
;
5811 for (rel
= relocs
; rel
< relend
; rel
++)
5813 unsigned long r_symndx
;
5814 enum elf_ppc64_reloc_type r_type
;
5815 struct elf_link_hash_entry
*h
= NULL
;
5816 unsigned char tls_type
= 0;
5818 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5819 r_type
= ELF64_R_TYPE (rel
->r_info
);
5820 if (r_symndx
>= symtab_hdr
->sh_info
)
5822 struct ppc_link_hash_entry
*eh
;
5823 struct elf_dyn_relocs
**pp
;
5824 struct elf_dyn_relocs
*p
;
5826 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5827 h
= elf_follow_link (h
);
5828 eh
= (struct ppc_link_hash_entry
*) h
;
5830 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5833 /* Everything must go for SEC. */
5839 if (is_branch_reloc (r_type
))
5841 struct plt_entry
**ifunc
= NULL
;
5844 if (h
->type
== STT_GNU_IFUNC
)
5845 ifunc
= &h
->plt
.plist
;
5847 else if (local_got_ents
!= NULL
)
5849 struct plt_entry
**local_plt
= (struct plt_entry
**)
5850 (local_got_ents
+ symtab_hdr
->sh_info
);
5851 unsigned char *local_got_tls_masks
= (unsigned char *)
5852 (local_plt
+ symtab_hdr
->sh_info
);
5853 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
5854 ifunc
= local_plt
+ r_symndx
;
5858 struct plt_entry
*ent
;
5860 for (ent
= *ifunc
; ent
!= NULL
; ent
= ent
->next
)
5861 if (ent
->addend
== rel
->r_addend
)
5865 if (ent
->plt
.refcount
> 0)
5866 ent
->plt
.refcount
-= 1;
5873 case R_PPC64_GOT_TLSLD16
:
5874 case R_PPC64_GOT_TLSLD16_LO
:
5875 case R_PPC64_GOT_TLSLD16_HI
:
5876 case R_PPC64_GOT_TLSLD16_HA
:
5877 tls_type
= TLS_TLS
| TLS_LD
;
5880 case R_PPC64_GOT_TLSGD16
:
5881 case R_PPC64_GOT_TLSGD16_LO
:
5882 case R_PPC64_GOT_TLSGD16_HI
:
5883 case R_PPC64_GOT_TLSGD16_HA
:
5884 tls_type
= TLS_TLS
| TLS_GD
;
5887 case R_PPC64_GOT_TPREL16_DS
:
5888 case R_PPC64_GOT_TPREL16_LO_DS
:
5889 case R_PPC64_GOT_TPREL16_HI
:
5890 case R_PPC64_GOT_TPREL16_HA
:
5891 tls_type
= TLS_TLS
| TLS_TPREL
;
5894 case R_PPC64_GOT_DTPREL16_DS
:
5895 case R_PPC64_GOT_DTPREL16_LO_DS
:
5896 case R_PPC64_GOT_DTPREL16_HI
:
5897 case R_PPC64_GOT_DTPREL16_HA
:
5898 tls_type
= TLS_TLS
| TLS_DTPREL
;
5902 case R_PPC64_GOT16_DS
:
5903 case R_PPC64_GOT16_HA
:
5904 case R_PPC64_GOT16_HI
:
5905 case R_PPC64_GOT16_LO
:
5906 case R_PPC64_GOT16_LO_DS
:
5909 struct got_entry
*ent
;
5914 ent
= local_got_ents
[r_symndx
];
5916 for (; ent
!= NULL
; ent
= ent
->next
)
5917 if (ent
->addend
== rel
->r_addend
5918 && ent
->owner
== abfd
5919 && ent
->tls_type
== tls_type
)
5923 if (ent
->got
.refcount
> 0)
5924 ent
->got
.refcount
-= 1;
5928 case R_PPC64_PLT16_HA
:
5929 case R_PPC64_PLT16_HI
:
5930 case R_PPC64_PLT16_LO
:
5934 case R_PPC64_REL14_BRNTAKEN
:
5935 case R_PPC64_REL14_BRTAKEN
:
5939 struct plt_entry
*ent
;
5941 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5942 if (ent
->addend
== rel
->r_addend
)
5944 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
5945 ent
->plt
.refcount
-= 1;
5956 /* The maximum size of .sfpr. */
5957 #define SFPR_MAX (218*4)
5959 struct sfpr_def_parms
5961 const char name
[12];
5962 unsigned char lo
, hi
;
5963 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5964 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5967 /* Auto-generate _save*, _rest* functions in .sfpr. */
5970 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5972 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5974 size_t len
= strlen (parm
->name
);
5975 bfd_boolean writing
= FALSE
;
5981 memcpy (sym
, parm
->name
, len
);
5984 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5986 struct elf_link_hash_entry
*h
;
5988 sym
[len
+ 0] = i
/ 10 + '0';
5989 sym
[len
+ 1] = i
% 10 + '0';
5990 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5994 h
->root
.type
= bfd_link_hash_defined
;
5995 h
->root
.u
.def
.section
= htab
->sfpr
;
5996 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
5999 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
6001 if (htab
->sfpr
->contents
== NULL
)
6003 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6004 if (htab
->sfpr
->contents
== NULL
)
6010 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6012 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6014 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6015 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6023 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6025 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6030 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6032 p
= savegpr0 (abfd
, p
, r
);
6033 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6035 bfd_put_32 (abfd
, BLR
, p
);
6040 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6042 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6047 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6049 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6051 p
= restgpr0 (abfd
, p
, r
);
6052 bfd_put_32 (abfd
, MTLR_R0
, p
);
6056 p
= restgpr0 (abfd
, p
, 30);
6057 p
= restgpr0 (abfd
, p
, 31);
6059 bfd_put_32 (abfd
, BLR
, p
);
6064 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6066 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6071 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6073 p
= savegpr1 (abfd
, p
, r
);
6074 bfd_put_32 (abfd
, BLR
, p
);
6079 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6081 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6086 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6088 p
= restgpr1 (abfd
, p
, r
);
6089 bfd_put_32 (abfd
, BLR
, p
);
6094 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6096 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6101 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6103 p
= savefpr (abfd
, p
, r
);
6104 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6106 bfd_put_32 (abfd
, BLR
, p
);
6111 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6113 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6118 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6120 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6122 p
= restfpr (abfd
, p
, r
);
6123 bfd_put_32 (abfd
, MTLR_R0
, p
);
6127 p
= restfpr (abfd
, p
, 30);
6128 p
= restfpr (abfd
, p
, 31);
6130 bfd_put_32 (abfd
, BLR
, p
);
6135 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6137 p
= savefpr (abfd
, p
, r
);
6138 bfd_put_32 (abfd
, BLR
, p
);
6143 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6145 p
= restfpr (abfd
, p
, r
);
6146 bfd_put_32 (abfd
, BLR
, p
);
6151 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6153 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6155 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6160 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6162 p
= savevr (abfd
, p
, r
);
6163 bfd_put_32 (abfd
, BLR
, p
);
6168 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6170 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6172 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6177 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6179 p
= restvr (abfd
, p
, r
);
6180 bfd_put_32 (abfd
, BLR
, p
);
6184 /* Called via elf_link_hash_traverse to transfer dynamic linking
6185 information on function code symbol entries to their corresponding
6186 function descriptor symbol entries. */
6189 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6191 struct bfd_link_info
*info
;
6192 struct ppc_link_hash_table
*htab
;
6193 struct plt_entry
*ent
;
6194 struct ppc_link_hash_entry
*fh
;
6195 struct ppc_link_hash_entry
*fdh
;
6196 bfd_boolean force_local
;
6198 fh
= (struct ppc_link_hash_entry
*) h
;
6199 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6203 htab
= ppc_hash_table (info
);
6207 /* Resolve undefined references to dot-symbols as the value
6208 in the function descriptor, if we have one in a regular object.
6209 This is to satisfy cases like ".quad .foo". Calls to functions
6210 in dynamic objects are handled elsewhere. */
6211 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
6212 && fh
->was_undefined
6213 && (fdh
= defined_func_desc (fh
)) != NULL
6214 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6215 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6216 fdh
->elf
.root
.u
.def
.value
,
6217 &fh
->elf
.root
.u
.def
.section
,
6218 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
6220 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6221 fh
->elf
.forced_local
= 1;
6222 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6223 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6226 /* If this is a function code symbol, transfer dynamic linking
6227 information to the function descriptor symbol. */
6231 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6232 if (ent
->plt
.refcount
> 0)
6235 || fh
->elf
.root
.root
.string
[0] != '.'
6236 || fh
->elf
.root
.root
.string
[1] == '\0')
6239 /* Find the corresponding function descriptor symbol. Create it
6240 as undefined if necessary. */
6242 fdh
= lookup_fdh (fh
, htab
);
6244 && !info
->executable
6245 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6246 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6248 fdh
= make_fdh (info
, fh
);
6253 /* Fake function descriptors are made undefweak. If the function
6254 code symbol is strong undefined, make the fake sym the same.
6255 If the function code symbol is defined, then force the fake
6256 descriptor local; We can't support overriding of symbols in a
6257 shared library on a fake descriptor. */
6261 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6263 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
6265 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
6266 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
6268 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
6269 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6271 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6276 && !fdh
->elf
.forced_local
6277 && (!info
->executable
6278 || fdh
->elf
.def_dynamic
6279 || fdh
->elf
.ref_dynamic
6280 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
6281 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
6283 if (fdh
->elf
.dynindx
== -1)
6284 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6286 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6287 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6288 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6289 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6290 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
6292 move_plt_plist (fh
, fdh
);
6293 fdh
->elf
.needs_plt
= 1;
6295 fdh
->is_func_descriptor
= 1;
6300 /* Now that the info is on the function descriptor, clear the
6301 function code sym info. Any function code syms for which we
6302 don't have a definition in a regular file, we force local.
6303 This prevents a shared library from exporting syms that have
6304 been imported from another library. Function code syms that
6305 are really in the library we must leave global to prevent the
6306 linker dragging in a definition from a static library. */
6307 force_local
= (!fh
->elf
.def_regular
6309 || !fdh
->elf
.def_regular
6310 || fdh
->elf
.forced_local
);
6311 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6316 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6317 this hook to a) provide some gcc support functions, and b) transfer
6318 dynamic linking information gathered so far on function code symbol
6319 entries, to their corresponding function descriptor symbol entries. */
6322 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6323 struct bfd_link_info
*info
)
6325 struct ppc_link_hash_table
*htab
;
6327 const struct sfpr_def_parms funcs
[] =
6329 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6330 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6331 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6332 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6333 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6334 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6335 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6336 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6337 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6338 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6339 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6340 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6343 htab
= ppc_hash_table (info
);
6347 if (htab
->sfpr
== NULL
)
6348 /* We don't have any relocs. */
6351 /* Provide any missing _save* and _rest* functions. */
6352 htab
->sfpr
->size
= 0;
6353 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
6354 if (!sfpr_define (info
, &funcs
[i
]))
6357 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6359 if (htab
->sfpr
->size
== 0)
6360 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6365 /* Adjust a symbol defined by a dynamic object and referenced by a
6366 regular object. The current definition is in some section of the
6367 dynamic object, but we're not including those sections. We have to
6368 change the definition to something the rest of the link can
6372 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6373 struct elf_link_hash_entry
*h
)
6375 struct ppc_link_hash_table
*htab
;
6378 htab
= ppc_hash_table (info
);
6382 /* Deal with function syms. */
6383 if (h
->type
== STT_FUNC
6384 || h
->type
== STT_GNU_IFUNC
6387 /* Clear procedure linkage table information for any symbol that
6388 won't need a .plt entry. */
6389 struct plt_entry
*ent
;
6390 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6391 if (ent
->plt
.refcount
> 0)
6394 || (h
->type
!= STT_GNU_IFUNC
6395 && (SYMBOL_CALLS_LOCAL (info
, h
)
6396 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6397 && h
->root
.type
== bfd_link_hash_undefweak
))))
6399 h
->plt
.plist
= NULL
;
6404 h
->plt
.plist
= NULL
;
6406 /* If this is a weak symbol, and there is a real definition, the
6407 processor independent code will have arranged for us to see the
6408 real definition first, and we can just use the same value. */
6409 if (h
->u
.weakdef
!= NULL
)
6411 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6412 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6413 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6414 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6415 if (ELIMINATE_COPY_RELOCS
)
6416 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6420 /* If we are creating a shared library, we must presume that the
6421 only references to the symbol are via the global offset table.
6422 For such cases we need not do anything here; the relocations will
6423 be handled correctly by relocate_section. */
6427 /* If there are no references to this symbol that do not use the
6428 GOT, we don't need to generate a copy reloc. */
6429 if (!h
->non_got_ref
)
6432 /* Don't generate a copy reloc for symbols defined in the executable. */
6433 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
6436 if (ELIMINATE_COPY_RELOCS
)
6438 struct ppc_link_hash_entry
* eh
;
6439 struct elf_dyn_relocs
*p
;
6441 eh
= (struct ppc_link_hash_entry
*) h
;
6442 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6444 s
= p
->sec
->output_section
;
6445 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6449 /* If we didn't find any dynamic relocs in read-only sections, then
6450 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6458 if (h
->plt
.plist
!= NULL
)
6460 /* We should never get here, but unfortunately there are versions
6461 of gcc out there that improperly (for this ABI) put initialized
6462 function pointers, vtable refs and suchlike in read-only
6463 sections. Allow them to proceed, but warn that this might
6464 break at runtime. */
6465 info
->callbacks
->einfo
6466 (_("%P: copy reloc against `%s' requires lazy plt linking; "
6467 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6468 h
->root
.root
.string
);
6471 /* This is a reference to a symbol defined by a dynamic object which
6472 is not a function. */
6476 info
->callbacks
->einfo (_("%P: dynamic variable `%s' is zero size\n"),
6477 h
->root
.root
.string
);
6481 /* We must allocate the symbol in our .dynbss section, which will
6482 become part of the .bss section of the executable. There will be
6483 an entry for this symbol in the .dynsym section. The dynamic
6484 object will contain position independent code, so all references
6485 from the dynamic object to this symbol will go through the global
6486 offset table. The dynamic linker will use the .dynsym entry to
6487 determine the address it must put in the global offset table, so
6488 both the dynamic object and the regular object will refer to the
6489 same memory location for the variable. */
6491 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6492 to copy the initial value out of the dynamic object and into the
6493 runtime process image. We need to remember the offset into the
6494 .rela.bss section we are going to use. */
6495 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6497 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
6503 return _bfd_elf_adjust_dynamic_copy (h
, s
);
6506 /* If given a function descriptor symbol, hide both the function code
6507 sym and the descriptor. */
6509 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6510 struct elf_link_hash_entry
*h
,
6511 bfd_boolean force_local
)
6513 struct ppc_link_hash_entry
*eh
;
6514 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6516 eh
= (struct ppc_link_hash_entry
*) h
;
6517 if (eh
->is_func_descriptor
)
6519 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6524 struct ppc_link_hash_table
*htab
;
6527 /* We aren't supposed to use alloca in BFD because on
6528 systems which do not have alloca the version in libiberty
6529 calls xmalloc, which might cause the program to crash
6530 when it runs out of memory. This function doesn't have a
6531 return status, so there's no way to gracefully return an
6532 error. So cheat. We know that string[-1] can be safely
6533 accessed; It's either a string in an ELF string table,
6534 or allocated in an objalloc structure. */
6536 p
= eh
->elf
.root
.root
.string
- 1;
6539 htab
= ppc_hash_table (info
);
6543 fh
= (struct ppc_link_hash_entry
*)
6544 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6547 /* Unfortunately, if it so happens that the string we were
6548 looking for was allocated immediately before this string,
6549 then we overwrote the string terminator. That's the only
6550 reason the lookup should fail. */
6553 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6554 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6556 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6557 fh
= (struct ppc_link_hash_entry
*)
6558 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6567 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6572 get_sym_h (struct elf_link_hash_entry
**hp
,
6573 Elf_Internal_Sym
**symp
,
6575 unsigned char **tls_maskp
,
6576 Elf_Internal_Sym
**locsymsp
,
6577 unsigned long r_symndx
,
6580 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6582 if (r_symndx
>= symtab_hdr
->sh_info
)
6584 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6585 struct elf_link_hash_entry
*h
;
6587 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6588 h
= elf_follow_link (h
);
6596 if (symsecp
!= NULL
)
6598 asection
*symsec
= NULL
;
6599 if (h
->root
.type
== bfd_link_hash_defined
6600 || h
->root
.type
== bfd_link_hash_defweak
)
6601 symsec
= h
->root
.u
.def
.section
;
6605 if (tls_maskp
!= NULL
)
6607 struct ppc_link_hash_entry
*eh
;
6609 eh
= (struct ppc_link_hash_entry
*) h
;
6610 *tls_maskp
= &eh
->tls_mask
;
6615 Elf_Internal_Sym
*sym
;
6616 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6618 if (locsyms
== NULL
)
6620 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6621 if (locsyms
== NULL
)
6622 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6623 symtab_hdr
->sh_info
,
6624 0, NULL
, NULL
, NULL
);
6625 if (locsyms
== NULL
)
6627 *locsymsp
= locsyms
;
6629 sym
= locsyms
+ r_symndx
;
6637 if (symsecp
!= NULL
)
6638 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6640 if (tls_maskp
!= NULL
)
6642 struct got_entry
**lgot_ents
;
6643 unsigned char *tls_mask
;
6646 lgot_ents
= elf_local_got_ents (ibfd
);
6647 if (lgot_ents
!= NULL
)
6649 struct plt_entry
**local_plt
= (struct plt_entry
**)
6650 (lgot_ents
+ symtab_hdr
->sh_info
);
6651 unsigned char *lgot_masks
= (unsigned char *)
6652 (local_plt
+ symtab_hdr
->sh_info
);
6653 tls_mask
= &lgot_masks
[r_symndx
];
6655 *tls_maskp
= tls_mask
;
6661 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6662 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6663 type suitable for optimization, and 1 otherwise. */
6666 get_tls_mask (unsigned char **tls_maskp
,
6667 unsigned long *toc_symndx
,
6668 bfd_vma
*toc_addend
,
6669 Elf_Internal_Sym
**locsymsp
,
6670 const Elf_Internal_Rela
*rel
,
6673 unsigned long r_symndx
;
6675 struct elf_link_hash_entry
*h
;
6676 Elf_Internal_Sym
*sym
;
6680 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6681 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6684 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6686 || ppc64_elf_section_data (sec
) == NULL
6687 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6690 /* Look inside a TOC section too. */
6693 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6694 off
= h
->root
.u
.def
.value
;
6697 off
= sym
->st_value
;
6698 off
+= rel
->r_addend
;
6699 BFD_ASSERT (off
% 8 == 0);
6700 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6701 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6702 if (toc_symndx
!= NULL
)
6703 *toc_symndx
= r_symndx
;
6704 if (toc_addend
!= NULL
)
6705 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6706 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6708 if ((h
== NULL
|| is_static_defined (h
))
6709 && (next_r
== -1 || next_r
== -2))
6714 /* Adjust all global syms defined in opd sections. In gcc generated
6715 code for the old ABI, these will already have been done. */
6718 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6720 struct ppc_link_hash_entry
*eh
;
6722 struct _opd_sec_data
*opd
;
6724 if (h
->root
.type
== bfd_link_hash_indirect
)
6727 if (h
->root
.type
!= bfd_link_hash_defined
6728 && h
->root
.type
!= bfd_link_hash_defweak
)
6731 eh
= (struct ppc_link_hash_entry
*) h
;
6732 if (eh
->adjust_done
)
6735 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6736 opd
= get_opd_info (sym_sec
);
6737 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6739 long adjust
= opd
->adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6742 /* This entry has been deleted. */
6743 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6746 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6747 if (elf_discarded_section (dsec
))
6749 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6753 eh
->elf
.root
.u
.def
.value
= 0;
6754 eh
->elf
.root
.u
.def
.section
= dsec
;
6757 eh
->elf
.root
.u
.def
.value
+= adjust
;
6758 eh
->adjust_done
= 1;
6763 /* Handles decrementing dynamic reloc counts for the reloc specified by
6764 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6765 have already been determined. */
6768 dec_dynrel_count (bfd_vma r_info
,
6770 struct bfd_link_info
*info
,
6771 Elf_Internal_Sym
**local_syms
,
6772 struct elf_link_hash_entry
*h
,
6775 enum elf_ppc64_reloc_type r_type
;
6776 struct elf_dyn_relocs
*p
;
6777 struct elf_dyn_relocs
**pp
;
6779 /* Can this reloc be dynamic? This switch, and later tests here
6780 should be kept in sync with the code in check_relocs. */
6781 r_type
= ELF64_R_TYPE (r_info
);
6787 case R_PPC64_TPREL16
:
6788 case R_PPC64_TPREL16_LO
:
6789 case R_PPC64_TPREL16_HI
:
6790 case R_PPC64_TPREL16_HA
:
6791 case R_PPC64_TPREL16_DS
:
6792 case R_PPC64_TPREL16_LO_DS
:
6793 case R_PPC64_TPREL16_HIGHER
:
6794 case R_PPC64_TPREL16_HIGHERA
:
6795 case R_PPC64_TPREL16_HIGHEST
:
6796 case R_PPC64_TPREL16_HIGHESTA
:
6800 case R_PPC64_TPREL64
:
6801 case R_PPC64_DTPMOD64
:
6802 case R_PPC64_DTPREL64
:
6803 case R_PPC64_ADDR64
:
6807 case R_PPC64_ADDR14
:
6808 case R_PPC64_ADDR14_BRNTAKEN
:
6809 case R_PPC64_ADDR14_BRTAKEN
:
6810 case R_PPC64_ADDR16
:
6811 case R_PPC64_ADDR16_DS
:
6812 case R_PPC64_ADDR16_HA
:
6813 case R_PPC64_ADDR16_HI
:
6814 case R_PPC64_ADDR16_HIGHER
:
6815 case R_PPC64_ADDR16_HIGHERA
:
6816 case R_PPC64_ADDR16_HIGHEST
:
6817 case R_PPC64_ADDR16_HIGHESTA
:
6818 case R_PPC64_ADDR16_LO
:
6819 case R_PPC64_ADDR16_LO_DS
:
6820 case R_PPC64_ADDR24
:
6821 case R_PPC64_ADDR32
:
6822 case R_PPC64_UADDR16
:
6823 case R_PPC64_UADDR32
:
6824 case R_PPC64_UADDR64
:
6829 if (local_syms
!= NULL
)
6831 unsigned long r_symndx
;
6832 Elf_Internal_Sym
*sym
;
6833 bfd
*ibfd
= sec
->owner
;
6835 r_symndx
= ELF64_R_SYM (r_info
);
6836 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6841 && (must_be_dyn_reloc (info
, r_type
)
6844 || h
->root
.type
== bfd_link_hash_defweak
6845 || !h
->def_regular
))))
6846 || (ELIMINATE_COPY_RELOCS
6849 && (h
->root
.type
== bfd_link_hash_defweak
6850 || !h
->def_regular
)))
6856 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6859 if (sym_sec
!= NULL
)
6861 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6862 pp
= (struct elf_dyn_relocs
**) vpp
;
6866 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6867 pp
= (struct elf_dyn_relocs
**) vpp
;
6870 /* elf_gc_sweep may have already removed all dyn relocs associated
6871 with local syms for a given section. Don't report a dynreloc
6877 while ((p
= *pp
) != NULL
)
6881 if (!must_be_dyn_reloc (info
, r_type
))
6891 info
->callbacks
->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
6893 bfd_set_error (bfd_error_bad_value
);
6897 /* Remove unused Official Procedure Descriptor entries. Currently we
6898 only remove those associated with functions in discarded link-once
6899 sections, or weakly defined functions that have been overridden. It
6900 would be possible to remove many more entries for statically linked
6904 ppc64_elf_edit_opd (struct bfd_link_info
*info
, bfd_boolean non_overlapping
)
6907 bfd_boolean some_edited
= FALSE
;
6908 asection
*need_pad
= NULL
;
6910 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6913 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6914 Elf_Internal_Shdr
*symtab_hdr
;
6915 Elf_Internal_Sym
*local_syms
;
6917 struct _opd_sec_data
*opd
;
6918 bfd_boolean need_edit
, add_aux_fields
;
6919 bfd_size_type cnt_16b
= 0;
6921 if (!is_ppc64_elf (ibfd
))
6924 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6925 if (sec
== NULL
|| sec
->size
== 0)
6928 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6931 if (sec
->output_section
== bfd_abs_section_ptr
)
6934 /* Look through the section relocs. */
6935 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6939 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6941 /* Read the relocations. */
6942 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6944 if (relstart
== NULL
)
6947 /* First run through the relocs to check they are sane, and to
6948 determine whether we need to edit this opd section. */
6952 relend
= relstart
+ sec
->reloc_count
;
6953 for (rel
= relstart
; rel
< relend
; )
6955 enum elf_ppc64_reloc_type r_type
;
6956 unsigned long r_symndx
;
6958 struct elf_link_hash_entry
*h
;
6959 Elf_Internal_Sym
*sym
;
6961 /* .opd contains a regular array of 16 or 24 byte entries. We're
6962 only interested in the reloc pointing to a function entry
6964 if (rel
->r_offset
!= offset
6965 || rel
+ 1 >= relend
6966 || (rel
+ 1)->r_offset
!= offset
+ 8)
6968 /* If someone messes with .opd alignment then after a
6969 "ld -r" we might have padding in the middle of .opd.
6970 Also, there's nothing to prevent someone putting
6971 something silly in .opd with the assembler. No .opd
6972 optimization for them! */
6974 (*_bfd_error_handler
)
6975 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6980 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6981 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6983 (*_bfd_error_handler
)
6984 (_("%B: unexpected reloc type %u in .opd section"),
6990 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6991 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6995 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6997 const char *sym_name
;
6999 sym_name
= h
->root
.root
.string
;
7001 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7004 (*_bfd_error_handler
)
7005 (_("%B: undefined sym `%s' in .opd section"),
7011 /* opd entries are always for functions defined in the
7012 current input bfd. If the symbol isn't defined in the
7013 input bfd, then we won't be using the function in this
7014 bfd; It must be defined in a linkonce section in another
7015 bfd, or is weak. It's also possible that we are
7016 discarding the function due to a linker script /DISCARD/,
7017 which we test for via the output_section. */
7018 if (sym_sec
->owner
!= ibfd
7019 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7024 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
7026 if (sec
->size
== offset
+ 24)
7031 if (rel
== relend
&& sec
->size
== offset
+ 16)
7039 if (rel
->r_offset
== offset
+ 24)
7041 else if (rel
->r_offset
!= offset
+ 16)
7043 else if (rel
+ 1 < relend
7044 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7045 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7050 else if (rel
+ 2 < relend
7051 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
7052 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
7061 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
7063 if (need_edit
|| add_aux_fields
)
7065 Elf_Internal_Rela
*write_rel
;
7066 Elf_Internal_Shdr
*rel_hdr
;
7067 bfd_byte
*rptr
, *wptr
;
7068 bfd_byte
*new_contents
;
7073 new_contents
= NULL
;
7074 amt
= sec
->size
* sizeof (long) / 8;
7075 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7076 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7077 if (opd
->adjust
== NULL
)
7079 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
7081 /* This seems a waste of time as input .opd sections are all
7082 zeros as generated by gcc, but I suppose there's no reason
7083 this will always be so. We might start putting something in
7084 the third word of .opd entries. */
7085 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7088 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7093 if (local_syms
!= NULL
7094 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7096 if (elf_section_data (sec
)->relocs
!= relstart
)
7100 sec
->contents
= loc
;
7101 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7104 elf_section_data (sec
)->relocs
= relstart
;
7106 new_contents
= sec
->contents
;
7109 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7110 if (new_contents
== NULL
)
7114 wptr
= new_contents
;
7115 rptr
= sec
->contents
;
7117 write_rel
= relstart
;
7121 for (rel
= relstart
; rel
< relend
; rel
++)
7123 unsigned long r_symndx
;
7125 struct elf_link_hash_entry
*h
;
7126 Elf_Internal_Sym
*sym
;
7128 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7129 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7133 if (rel
->r_offset
== offset
)
7135 struct ppc_link_hash_entry
*fdh
= NULL
;
7137 /* See if the .opd entry is full 24 byte or
7138 16 byte (with fd_aux entry overlapped with next
7141 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
7142 || (rel
+ 3 < relend
7143 && rel
[2].r_offset
== offset
+ 16
7144 && rel
[3].r_offset
== offset
+ 24
7145 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
7146 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
7150 && h
->root
.root
.string
[0] == '.')
7152 struct ppc_link_hash_table
*htab
;
7154 htab
= ppc_hash_table (info
);
7156 fdh
= lookup_fdh ((struct ppc_link_hash_entry
*) h
,
7159 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
7160 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7164 skip
= (sym_sec
->owner
!= ibfd
7165 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7168 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7170 /* Arrange for the function descriptor sym
7172 fdh
->elf
.root
.u
.def
.value
= 0;
7173 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7175 opd
->adjust
[rel
->r_offset
/ 8] = -1;
7179 /* We'll be keeping this opd entry. */
7183 /* Redefine the function descriptor symbol to
7184 this location in the opd section. It is
7185 necessary to update the value here rather
7186 than using an array of adjustments as we do
7187 for local symbols, because various places
7188 in the generic ELF code use the value
7189 stored in u.def.value. */
7190 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7191 fdh
->adjust_done
= 1;
7194 /* Local syms are a bit tricky. We could
7195 tweak them as they can be cached, but
7196 we'd need to look through the local syms
7197 for the function descriptor sym which we
7198 don't have at the moment. So keep an
7199 array of adjustments. */
7200 opd
->adjust
[rel
->r_offset
/ 8]
7201 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
7204 memcpy (wptr
, rptr
, opd_ent_size
);
7205 wptr
+= opd_ent_size
;
7206 if (add_aux_fields
&& opd_ent_size
== 16)
7208 memset (wptr
, '\0', 8);
7212 rptr
+= opd_ent_size
;
7213 offset
+= opd_ent_size
;
7219 && !info
->relocatable
7220 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
7226 /* We need to adjust any reloc offsets to point to the
7227 new opd entries. While we're at it, we may as well
7228 remove redundant relocs. */
7229 rel
->r_offset
+= opd
->adjust
[(offset
- opd_ent_size
) / 8];
7230 if (write_rel
!= rel
)
7231 memcpy (write_rel
, rel
, sizeof (*rel
));
7236 sec
->size
= wptr
- new_contents
;
7237 sec
->reloc_count
= write_rel
- relstart
;
7240 free (sec
->contents
);
7241 sec
->contents
= new_contents
;
7244 /* Fudge the header size too, as this is used later in
7245 elf_bfd_final_link if we are emitting relocs. */
7246 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7247 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7250 else if (elf_section_data (sec
)->relocs
!= relstart
)
7253 if (local_syms
!= NULL
7254 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7256 if (!info
->keep_memory
)
7259 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7264 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7266 /* If we are doing a final link and the last .opd entry is just 16 byte
7267 long, add a 8 byte padding after it. */
7268 if (need_pad
!= NULL
&& !info
->relocatable
)
7272 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7274 BFD_ASSERT (need_pad
->size
> 0);
7276 p
= bfd_malloc (need_pad
->size
+ 8);
7280 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
7281 p
, 0, need_pad
->size
))
7284 need_pad
->contents
= p
;
7285 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7289 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7293 need_pad
->contents
= p
;
7296 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7297 need_pad
->size
+= 8;
7303 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7306 ppc64_elf_tls_setup (struct bfd_link_info
*info
,
7307 int no_tls_get_addr_opt
,
7310 struct ppc_link_hash_table
*htab
;
7312 htab
= ppc_hash_table (info
);
7317 htab
->do_multi_toc
= 0;
7318 else if (!htab
->do_multi_toc
)
7321 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7322 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7323 FALSE
, FALSE
, TRUE
));
7324 /* Move dynamic linking info to the function descriptor sym. */
7325 if (htab
->tls_get_addr
!= NULL
)
7326 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7327 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7328 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7329 FALSE
, FALSE
, TRUE
));
7330 if (!no_tls_get_addr_opt
)
7332 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7334 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7335 FALSE
, FALSE
, TRUE
);
7337 func_desc_adjust (opt
, info
);
7338 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7339 FALSE
, FALSE
, TRUE
);
7341 && (opt_fd
->root
.type
== bfd_link_hash_defined
7342 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7344 /* If glibc supports an optimized __tls_get_addr call stub,
7345 signalled by the presence of __tls_get_addr_opt, and we'll
7346 be calling __tls_get_addr via a plt call stub, then
7347 make __tls_get_addr point to __tls_get_addr_opt. */
7348 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7349 if (htab
->elf
.dynamic_sections_created
7351 && (tga_fd
->type
== STT_FUNC
7352 || tga_fd
->needs_plt
)
7353 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7354 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
7355 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
7357 struct plt_entry
*ent
;
7359 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7360 if (ent
->plt
.refcount
> 0)
7364 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7365 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7366 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7367 if (opt_fd
->dynindx
!= -1)
7369 /* Use __tls_get_addr_opt in dynamic relocations. */
7370 opt_fd
->dynindx
= -1;
7371 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7372 opt_fd
->dynstr_index
);
7373 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7376 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
7377 tga
= &htab
->tls_get_addr
->elf
;
7378 if (opt
!= NULL
&& tga
!= NULL
)
7380 tga
->root
.type
= bfd_link_hash_indirect
;
7381 tga
->root
.u
.i
.link
= &opt
->root
;
7382 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7383 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7385 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7387 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7388 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7389 if (htab
->tls_get_addr
!= NULL
)
7391 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7392 htab
->tls_get_addr
->is_func
= 1;
7398 no_tls_get_addr_opt
= TRUE
;
7400 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
7401 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7404 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7408 branch_reloc_hash_match (const bfd
*ibfd
,
7409 const Elf_Internal_Rela
*rel
,
7410 const struct ppc_link_hash_entry
*hash1
,
7411 const struct ppc_link_hash_entry
*hash2
)
7413 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7414 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7415 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7417 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7419 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7420 struct elf_link_hash_entry
*h
;
7422 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7423 h
= elf_follow_link (h
);
7424 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7430 /* Run through all the TLS relocs looking for optimization
7431 opportunities. The linker has been hacked (see ppc64elf.em) to do
7432 a preliminary section layout so that we know the TLS segment
7433 offsets. We can't optimize earlier because some optimizations need
7434 to know the tp offset, and we need to optimize before allocating
7435 dynamic relocations. */
7438 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7442 struct ppc_link_hash_table
*htab
;
7443 unsigned char *toc_ref
;
7446 if (info
->relocatable
|| !info
->executable
)
7449 htab
= ppc_hash_table (info
);
7453 /* Make two passes over the relocs. On the first pass, mark toc
7454 entries involved with tls relocs, and check that tls relocs
7455 involved in setting up a tls_get_addr call are indeed followed by
7456 such a call. If they are not, we can't do any tls optimization.
7457 On the second pass twiddle tls_mask flags to notify
7458 relocate_section that optimization can be done, and adjust got
7459 and plt refcounts. */
7461 for (pass
= 0; pass
< 2; ++pass
)
7462 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7464 Elf_Internal_Sym
*locsyms
= NULL
;
7465 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7467 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7468 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7470 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7471 bfd_boolean found_tls_get_addr_arg
= 0;
7473 /* Read the relocations. */
7474 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7476 if (relstart
== NULL
)
7479 relend
= relstart
+ sec
->reloc_count
;
7480 for (rel
= relstart
; rel
< relend
; rel
++)
7482 enum elf_ppc64_reloc_type r_type
;
7483 unsigned long r_symndx
;
7484 struct elf_link_hash_entry
*h
;
7485 Elf_Internal_Sym
*sym
;
7487 unsigned char *tls_mask
;
7488 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7490 bfd_boolean ok_tprel
, is_local
;
7491 long toc_ref_index
= 0;
7492 int expecting_tls_get_addr
= 0;
7493 bfd_boolean ret
= FALSE
;
7495 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7496 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7500 if (elf_section_data (sec
)->relocs
!= relstart
)
7502 if (toc_ref
!= NULL
)
7505 && (elf_symtab_hdr (ibfd
).contents
7506 != (unsigned char *) locsyms
))
7513 if (h
->root
.type
== bfd_link_hash_defined
7514 || h
->root
.type
== bfd_link_hash_defweak
)
7515 value
= h
->root
.u
.def
.value
;
7516 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7520 found_tls_get_addr_arg
= 0;
7525 /* Symbols referenced by TLS relocs must be of type
7526 STT_TLS. So no need for .opd local sym adjust. */
7527 value
= sym
->st_value
;
7536 && h
->root
.type
== bfd_link_hash_undefweak
)
7540 value
+= sym_sec
->output_offset
;
7541 value
+= sym_sec
->output_section
->vma
;
7542 value
-= htab
->elf
.tls_sec
->vma
;
7543 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7544 < (bfd_vma
) 1 << 32);
7548 r_type
= ELF64_R_TYPE (rel
->r_info
);
7549 /* If this section has old-style __tls_get_addr calls
7550 without marker relocs, then check that each
7551 __tls_get_addr call reloc is preceded by a reloc
7552 that conceivably belongs to the __tls_get_addr arg
7553 setup insn. If we don't find matching arg setup
7554 relocs, don't do any tls optimization. */
7556 && sec
->has_tls_get_addr_call
7558 && (h
== &htab
->tls_get_addr
->elf
7559 || h
== &htab
->tls_get_addr_fd
->elf
)
7560 && !found_tls_get_addr_arg
7561 && is_branch_reloc (r_type
))
7563 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7564 "TLS optimization disabled\n"),
7565 ibfd
, sec
, rel
->r_offset
);
7570 found_tls_get_addr_arg
= 0;
7573 case R_PPC64_GOT_TLSLD16
:
7574 case R_PPC64_GOT_TLSLD16_LO
:
7575 expecting_tls_get_addr
= 1;
7576 found_tls_get_addr_arg
= 1;
7579 case R_PPC64_GOT_TLSLD16_HI
:
7580 case R_PPC64_GOT_TLSLD16_HA
:
7581 /* These relocs should never be against a symbol
7582 defined in a shared lib. Leave them alone if
7583 that turns out to be the case. */
7590 tls_type
= TLS_TLS
| TLS_LD
;
7593 case R_PPC64_GOT_TLSGD16
:
7594 case R_PPC64_GOT_TLSGD16_LO
:
7595 expecting_tls_get_addr
= 1;
7596 found_tls_get_addr_arg
= 1;
7599 case R_PPC64_GOT_TLSGD16_HI
:
7600 case R_PPC64_GOT_TLSGD16_HA
:
7606 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7608 tls_type
= TLS_TLS
| TLS_GD
;
7611 case R_PPC64_GOT_TPREL16_DS
:
7612 case R_PPC64_GOT_TPREL16_LO_DS
:
7613 case R_PPC64_GOT_TPREL16_HI
:
7614 case R_PPC64_GOT_TPREL16_HA
:
7619 tls_clear
= TLS_TPREL
;
7620 tls_type
= TLS_TLS
| TLS_TPREL
;
7627 found_tls_get_addr_arg
= 1;
7632 case R_PPC64_TOC16_LO
:
7633 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7636 /* Mark this toc entry as referenced by a TLS
7637 code sequence. We can do that now in the
7638 case of R_PPC64_TLS, and after checking for
7639 tls_get_addr for the TOC16 relocs. */
7640 if (toc_ref
== NULL
)
7641 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7642 if (toc_ref
== NULL
)
7646 value
= h
->root
.u
.def
.value
;
7648 value
= sym
->st_value
;
7649 value
+= rel
->r_addend
;
7650 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
7651 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7652 if (r_type
== R_PPC64_TLS
7653 || r_type
== R_PPC64_TLSGD
7654 || r_type
== R_PPC64_TLSLD
)
7656 toc_ref
[toc_ref_index
] = 1;
7660 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7665 expecting_tls_get_addr
= 2;
7668 case R_PPC64_TPREL64
:
7672 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7677 tls_set
= TLS_EXPLICIT
;
7678 tls_clear
= TLS_TPREL
;
7683 case R_PPC64_DTPMOD64
:
7687 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7689 if (rel
+ 1 < relend
7691 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7692 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7696 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7699 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7708 tls_set
= TLS_EXPLICIT
;
7719 if (!expecting_tls_get_addr
7720 || !sec
->has_tls_get_addr_call
)
7723 if (rel
+ 1 < relend
7724 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7726 htab
->tls_get_addr_fd
))
7728 if (expecting_tls_get_addr
== 2)
7730 /* Check for toc tls entries. */
7731 unsigned char *toc_tls
;
7734 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7739 if (toc_tls
!= NULL
)
7741 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
7742 found_tls_get_addr_arg
= 1;
7744 toc_ref
[toc_ref_index
] = 1;
7750 if (expecting_tls_get_addr
!= 1)
7753 /* Uh oh, we didn't find the expected call. We
7754 could just mark this symbol to exclude it
7755 from tls optimization but it's safer to skip
7756 the entire optimization. */
7757 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7758 "TLS optimization disabled\n"),
7759 ibfd
, sec
, rel
->r_offset
);
7764 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
7766 struct plt_entry
*ent
;
7767 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7770 if (ent
->addend
== 0)
7772 if (ent
->plt
.refcount
> 0)
7774 ent
->plt
.refcount
-= 1;
7775 expecting_tls_get_addr
= 0;
7781 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
7783 struct plt_entry
*ent
;
7784 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7787 if (ent
->addend
== 0)
7789 if (ent
->plt
.refcount
> 0)
7790 ent
->plt
.refcount
-= 1;
7798 if ((tls_set
& TLS_EXPLICIT
) == 0)
7800 struct got_entry
*ent
;
7802 /* Adjust got entry for this reloc. */
7806 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7808 for (; ent
!= NULL
; ent
= ent
->next
)
7809 if (ent
->addend
== rel
->r_addend
7810 && ent
->owner
== ibfd
7811 && ent
->tls_type
== tls_type
)
7818 /* We managed to get rid of a got entry. */
7819 if (ent
->got
.refcount
> 0)
7820 ent
->got
.refcount
-= 1;
7825 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7826 we'll lose one or two dyn relocs. */
7827 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7831 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7833 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7839 *tls_mask
|= tls_set
;
7840 *tls_mask
&= ~tls_clear
;
7843 if (elf_section_data (sec
)->relocs
!= relstart
)
7848 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7850 if (!info
->keep_memory
)
7853 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7857 if (toc_ref
!= NULL
)
7862 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7863 the values of any global symbols in a toc section that has been
7864 edited. Globals in toc sections should be a rarity, so this function
7865 sets a flag if any are found in toc sections other than the one just
7866 edited, so that futher hash table traversals can be avoided. */
7868 struct adjust_toc_info
7871 unsigned long *skip
;
7872 bfd_boolean global_toc_syms
;
7875 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7878 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7880 struct ppc_link_hash_entry
*eh
;
7881 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7884 if (h
->root
.type
!= bfd_link_hash_defined
7885 && h
->root
.type
!= bfd_link_hash_defweak
)
7888 eh
= (struct ppc_link_hash_entry
*) h
;
7889 if (eh
->adjust_done
)
7892 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7894 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7895 i
= toc_inf
->toc
->rawsize
>> 3;
7897 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7899 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7901 (*_bfd_error_handler
)
7902 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7905 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7906 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7909 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7910 eh
->adjust_done
= 1;
7912 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7913 toc_inf
->global_toc_syms
= TRUE
;
7918 /* Examine all relocs referencing .toc sections in order to remove
7919 unused .toc entries. */
7922 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7925 struct adjust_toc_info toc_inf
;
7926 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7928 htab
->do_toc_opt
= 1;
7929 toc_inf
.global_toc_syms
= TRUE
;
7930 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7932 asection
*toc
, *sec
;
7933 Elf_Internal_Shdr
*symtab_hdr
;
7934 Elf_Internal_Sym
*local_syms
;
7935 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7936 unsigned long *skip
, *drop
;
7937 unsigned char *used
;
7938 unsigned char *keep
, last
, some_unused
;
7940 if (!is_ppc64_elf (ibfd
))
7943 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7946 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7947 || elf_discarded_section (toc
))
7952 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7954 /* Look at sections dropped from the final link. */
7957 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7959 if (sec
->reloc_count
== 0
7960 || !elf_discarded_section (sec
)
7961 || get_opd_info (sec
)
7962 || (sec
->flags
& SEC_ALLOC
) == 0
7963 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7966 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7967 if (relstart
== NULL
)
7970 /* Run through the relocs to see which toc entries might be
7972 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7974 enum elf_ppc64_reloc_type r_type
;
7975 unsigned long r_symndx
;
7977 struct elf_link_hash_entry
*h
;
7978 Elf_Internal_Sym
*sym
;
7981 r_type
= ELF64_R_TYPE (rel
->r_info
);
7988 case R_PPC64_TOC16_LO
:
7989 case R_PPC64_TOC16_HI
:
7990 case R_PPC64_TOC16_HA
:
7991 case R_PPC64_TOC16_DS
:
7992 case R_PPC64_TOC16_LO_DS
:
7996 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7997 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8005 val
= h
->root
.u
.def
.value
;
8007 val
= sym
->st_value
;
8008 val
+= rel
->r_addend
;
8010 if (val
>= toc
->size
)
8013 /* Anything in the toc ought to be aligned to 8 bytes.
8014 If not, don't mark as unused. */
8020 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8025 skip
[val
>> 3] = ref_from_discarded
;
8028 if (elf_section_data (sec
)->relocs
!= relstart
)
8032 /* For largetoc loads of address constants, we can convert
8033 . addis rx,2,addr@got@ha
8034 . ld ry,addr@got@l(rx)
8036 . addis rx,2,addr@toc@ha
8037 . addi ry,rx,addr@toc@l
8038 when addr is within 2G of the toc pointer. This then means
8039 that the word storing "addr" in the toc is no longer needed. */
8041 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8042 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8043 && toc
->reloc_count
!= 0)
8045 /* Read toc relocs. */
8046 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8048 if (toc_relocs
== NULL
)
8051 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8053 enum elf_ppc64_reloc_type r_type
;
8054 unsigned long r_symndx
;
8056 struct elf_link_hash_entry
*h
;
8057 Elf_Internal_Sym
*sym
;
8060 r_type
= ELF64_R_TYPE (rel
->r_info
);
8061 if (r_type
!= R_PPC64_ADDR64
)
8064 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8065 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8070 || elf_discarded_section (sym_sec
))
8073 if (!SYMBOL_CALLS_LOCAL (info
, h
))
8078 if (h
->type
== STT_GNU_IFUNC
)
8080 val
= h
->root
.u
.def
.value
;
8084 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8086 val
= sym
->st_value
;
8088 val
+= rel
->r_addend
;
8089 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8091 /* We don't yet know the exact toc pointer value, but we
8092 know it will be somewhere in the toc section. Don't
8093 optimize if the difference from any possible toc
8094 pointer is outside [ff..f80008000, 7fff7fff]. */
8095 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8096 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8099 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8100 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8105 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8110 skip
[rel
->r_offset
>> 3]
8111 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8118 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8122 if (local_syms
!= NULL
8123 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8127 && elf_section_data (sec
)->relocs
!= relstart
)
8129 if (toc_relocs
!= NULL
8130 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8137 /* Now check all kept sections that might reference the toc.
8138 Check the toc itself last. */
8139 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8142 sec
= (sec
== toc
? NULL
8143 : sec
->next
== NULL
? toc
8144 : sec
->next
== toc
&& toc
->next
? toc
->next
8149 if (sec
->reloc_count
== 0
8150 || elf_discarded_section (sec
)
8151 || get_opd_info (sec
)
8152 || (sec
->flags
& SEC_ALLOC
) == 0
8153 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8156 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8158 if (relstart
== NULL
)
8161 /* Mark toc entries referenced as used. */
8164 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8166 enum elf_ppc64_reloc_type r_type
;
8167 unsigned long r_symndx
;
8169 struct elf_link_hash_entry
*h
;
8170 Elf_Internal_Sym
*sym
;
8173 r_type
= ELF64_R_TYPE (rel
->r_info
);
8177 case R_PPC64_TOC16_LO
:
8178 case R_PPC64_TOC16_HI
:
8179 case R_PPC64_TOC16_HA
:
8180 case R_PPC64_TOC16_DS
:
8181 case R_PPC64_TOC16_LO_DS
:
8182 /* In case we're taking addresses of toc entries. */
8183 case R_PPC64_ADDR64
:
8190 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8191 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8202 val
= h
->root
.u
.def
.value
;
8204 val
= sym
->st_value
;
8205 val
+= rel
->r_addend
;
8207 if (val
>= toc
->size
)
8210 if ((skip
[val
>> 3] & can_optimize
) != 0)
8217 case R_PPC64_TOC16_HA
:
8220 case R_PPC64_TOC16_LO_DS
:
8221 off
= rel
->r_offset
+ (bfd_big_endian (ibfd
) ? -2 : 3);
8222 if (!bfd_get_section_contents (ibfd
, sec
, &opc
, off
, 1))
8224 if ((opc
& (0x3f << 2)) == (58u << 2))
8229 /* Wrong sort of reloc, or not a ld. We may
8230 as well clear ref_from_discarded too. */
8235 /* For the toc section, we only mark as used if
8236 this entry itself isn't unused. */
8239 && (used
[rel
->r_offset
>> 3]
8240 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
)))
8241 /* Do all the relocs again, to catch reference
8249 if (elf_section_data (sec
)->relocs
!= relstart
)
8253 /* Merge the used and skip arrays. Assume that TOC
8254 doublewords not appearing as either used or unused belong
8255 to to an entry more than one doubleword in size. */
8256 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8257 drop
< skip
+ (toc
->size
+ 7) / 8;
8262 *drop
&= ~ref_from_discarded
;
8263 if ((*drop
& can_optimize
) != 0)
8267 else if ((*drop
& ref_from_discarded
) != 0)
8270 last
= ref_from_discarded
;
8280 bfd_byte
*contents
, *src
;
8282 Elf_Internal_Sym
*sym
;
8283 bfd_boolean local_toc_syms
= FALSE
;
8285 /* Shuffle the toc contents, and at the same time convert the
8286 skip array from booleans into offsets. */
8287 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8290 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8292 for (src
= contents
, off
= 0, drop
= skip
;
8293 src
< contents
+ toc
->size
;
8296 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8301 memcpy (src
- off
, src
, 8);
8305 toc
->rawsize
= toc
->size
;
8306 toc
->size
= src
- contents
- off
;
8308 /* Adjust addends for relocs against the toc section sym,
8309 and optimize any accesses we can. */
8310 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8312 if (sec
->reloc_count
== 0
8313 || elf_discarded_section (sec
))
8316 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8318 if (relstart
== NULL
)
8321 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8323 enum elf_ppc64_reloc_type r_type
;
8324 unsigned long r_symndx
;
8326 struct elf_link_hash_entry
*h
;
8329 r_type
= ELF64_R_TYPE (rel
->r_info
);
8336 case R_PPC64_TOC16_LO
:
8337 case R_PPC64_TOC16_HI
:
8338 case R_PPC64_TOC16_HA
:
8339 case R_PPC64_TOC16_DS
:
8340 case R_PPC64_TOC16_LO_DS
:
8341 case R_PPC64_ADDR64
:
8345 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8346 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8354 val
= h
->root
.u
.def
.value
;
8357 val
= sym
->st_value
;
8359 local_toc_syms
= TRUE
;
8362 val
+= rel
->r_addend
;
8364 if (val
> toc
->rawsize
)
8366 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8368 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8370 Elf_Internal_Rela
*tocrel
8371 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8372 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8376 case R_PPC64_TOC16_HA
:
8377 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8380 case R_PPC64_TOC16_LO_DS
:
8381 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8385 info
->callbacks
->einfo
8386 (_("%P: %H: %s relocation references "
8387 "optimized away TOC entry\n"),
8388 ibfd
, sec
, rel
->r_offset
,
8389 ppc64_elf_howto_table
[r_type
]->name
);
8390 bfd_set_error (bfd_error_bad_value
);
8393 rel
->r_addend
= tocrel
->r_addend
;
8394 elf_section_data (sec
)->relocs
= relstart
;
8398 if (h
!= NULL
|| sym
->st_value
!= 0)
8401 rel
->r_addend
-= skip
[val
>> 3];
8402 elf_section_data (sec
)->relocs
= relstart
;
8405 if (elf_section_data (sec
)->relocs
!= relstart
)
8409 /* We shouldn't have local or global symbols defined in the TOC,
8410 but handle them anyway. */
8411 if (local_syms
!= NULL
)
8412 for (sym
= local_syms
;
8413 sym
< local_syms
+ symtab_hdr
->sh_info
;
8415 if (sym
->st_value
!= 0
8416 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8420 if (sym
->st_value
> toc
->rawsize
)
8421 i
= toc
->rawsize
>> 3;
8423 i
= sym
->st_value
>> 3;
8425 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8428 (*_bfd_error_handler
)
8429 (_("%s defined on removed toc entry"),
8430 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8433 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8434 sym
->st_value
= (bfd_vma
) i
<< 3;
8437 sym
->st_value
-= skip
[i
];
8438 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8441 /* Adjust any global syms defined in this toc input section. */
8442 if (toc_inf
.global_toc_syms
)
8445 toc_inf
.skip
= skip
;
8446 toc_inf
.global_toc_syms
= FALSE
;
8447 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8451 if (toc
->reloc_count
!= 0)
8453 Elf_Internal_Shdr
*rel_hdr
;
8454 Elf_Internal_Rela
*wrel
;
8457 /* Remove unused toc relocs, and adjust those we keep. */
8458 if (toc_relocs
== NULL
)
8459 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8461 if (toc_relocs
== NULL
)
8465 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8466 if ((skip
[rel
->r_offset
>> 3]
8467 & (ref_from_discarded
| can_optimize
)) == 0)
8469 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8470 wrel
->r_info
= rel
->r_info
;
8471 wrel
->r_addend
= rel
->r_addend
;
8474 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8475 &local_syms
, NULL
, NULL
))
8478 elf_section_data (toc
)->relocs
= toc_relocs
;
8479 toc
->reloc_count
= wrel
- toc_relocs
;
8480 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8481 sz
= rel_hdr
->sh_entsize
;
8482 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8485 else if (toc_relocs
!= NULL
8486 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8489 if (local_syms
!= NULL
8490 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8492 if (!info
->keep_memory
)
8495 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8503 /* Return true iff input section I references the TOC using
8504 instructions limited to +/-32k offsets. */
8507 ppc64_elf_has_small_toc_reloc (asection
*i
)
8509 return (is_ppc64_elf (i
->owner
)
8510 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8513 /* Allocate space for one GOT entry. */
8516 allocate_got (struct elf_link_hash_entry
*h
,
8517 struct bfd_link_info
*info
,
8518 struct got_entry
*gent
)
8520 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8522 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8523 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8525 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8526 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8527 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8529 gent
->got
.offset
= got
->size
;
8530 got
->size
+= entsize
;
8532 dyn
= htab
->elf
.dynamic_sections_created
;
8534 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8535 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8536 || h
->root
.type
!= bfd_link_hash_undefweak
))
8538 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8539 relgot
->size
+= rentsize
;
8541 else if (h
->type
== STT_GNU_IFUNC
)
8543 asection
*relgot
= htab
->reliplt
;
8544 relgot
->size
+= rentsize
;
8545 htab
->got_reli_size
+= rentsize
;
8549 /* This function merges got entries in the same toc group. */
8552 merge_got_entries (struct got_entry
**pent
)
8554 struct got_entry
*ent
, *ent2
;
8556 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8557 if (!ent
->is_indirect
)
8558 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8559 if (!ent2
->is_indirect
8560 && ent2
->addend
== ent
->addend
8561 && ent2
->tls_type
== ent
->tls_type
8562 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8564 ent2
->is_indirect
= TRUE
;
8565 ent2
->got
.ent
= ent
;
8569 /* Allocate space in .plt, .got and associated reloc sections for
8573 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8575 struct bfd_link_info
*info
;
8576 struct ppc_link_hash_table
*htab
;
8578 struct ppc_link_hash_entry
*eh
;
8579 struct elf_dyn_relocs
*p
;
8580 struct got_entry
**pgent
, *gent
;
8582 if (h
->root
.type
== bfd_link_hash_indirect
)
8585 info
= (struct bfd_link_info
*) inf
;
8586 htab
= ppc_hash_table (info
);
8590 if ((htab
->elf
.dynamic_sections_created
8592 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
8593 || h
->type
== STT_GNU_IFUNC
)
8595 struct plt_entry
*pent
;
8596 bfd_boolean doneone
= FALSE
;
8597 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8598 if (pent
->plt
.refcount
> 0)
8600 if (!htab
->elf
.dynamic_sections_created
8601 || h
->dynindx
== -1)
8604 pent
->plt
.offset
= s
->size
;
8605 s
->size
+= PLT_ENTRY_SIZE
;
8610 /* If this is the first .plt entry, make room for the special
8614 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
8616 pent
->plt
.offset
= s
->size
;
8618 /* Make room for this entry. */
8619 s
->size
+= PLT_ENTRY_SIZE
;
8621 /* Make room for the .glink code. */
8624 s
->size
+= GLINK_CALL_STUB_SIZE
;
8625 /* We need bigger stubs past index 32767. */
8626 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
8630 /* We also need to make an entry in the .rela.plt section. */
8633 s
->size
+= sizeof (Elf64_External_Rela
);
8637 pent
->plt
.offset
= (bfd_vma
) -1;
8640 h
->plt
.plist
= NULL
;
8646 h
->plt
.plist
= NULL
;
8650 eh
= (struct ppc_link_hash_entry
*) h
;
8651 /* Run through the TLS GD got entries first if we're changing them
8653 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
8654 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8655 if (gent
->got
.refcount
> 0
8656 && (gent
->tls_type
& TLS_GD
) != 0)
8658 /* This was a GD entry that has been converted to TPREL. If
8659 there happens to be a TPREL entry we can use that one. */
8660 struct got_entry
*ent
;
8661 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8662 if (ent
->got
.refcount
> 0
8663 && (ent
->tls_type
& TLS_TPREL
) != 0
8664 && ent
->addend
== gent
->addend
8665 && ent
->owner
== gent
->owner
)
8667 gent
->got
.refcount
= 0;
8671 /* If not, then we'll be using our own TPREL entry. */
8672 if (gent
->got
.refcount
!= 0)
8673 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8676 /* Remove any list entry that won't generate a word in the GOT before
8677 we call merge_got_entries. Otherwise we risk merging to empty
8679 pgent
= &h
->got
.glist
;
8680 while ((gent
= *pgent
) != NULL
)
8681 if (gent
->got
.refcount
> 0)
8683 if ((gent
->tls_type
& TLS_LD
) != 0
8686 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8687 *pgent
= gent
->next
;
8690 pgent
= &gent
->next
;
8693 *pgent
= gent
->next
;
8695 if (!htab
->do_multi_toc
)
8696 merge_got_entries (&h
->got
.glist
);
8698 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8699 if (!gent
->is_indirect
)
8701 /* Make sure this symbol is output as a dynamic symbol.
8702 Undefined weak syms won't yet be marked as dynamic,
8703 nor will all TLS symbols. */
8704 if (h
->dynindx
== -1
8706 && h
->type
!= STT_GNU_IFUNC
8707 && htab
->elf
.dynamic_sections_created
)
8709 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8713 if (!is_ppc64_elf (gent
->owner
))
8716 allocate_got (h
, info
, gent
);
8719 if (eh
->dyn_relocs
== NULL
8720 || (!htab
->elf
.dynamic_sections_created
8721 && h
->type
!= STT_GNU_IFUNC
))
8724 /* In the shared -Bsymbolic case, discard space allocated for
8725 dynamic pc-relative relocs against symbols which turn out to be
8726 defined in regular objects. For the normal shared case, discard
8727 space for relocs that have become local due to symbol visibility
8732 /* Relocs that use pc_count are those that appear on a call insn,
8733 or certain REL relocs (see must_be_dyn_reloc) that can be
8734 generated via assembly. We want calls to protected symbols to
8735 resolve directly to the function rather than going via the plt.
8736 If people want function pointer comparisons to work as expected
8737 then they should avoid writing weird assembly. */
8738 if (SYMBOL_CALLS_LOCAL (info
, h
))
8740 struct elf_dyn_relocs
**pp
;
8742 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8744 p
->count
-= p
->pc_count
;
8753 /* Also discard relocs on undefined weak syms with non-default
8755 if (eh
->dyn_relocs
!= NULL
8756 && h
->root
.type
== bfd_link_hash_undefweak
)
8758 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8759 eh
->dyn_relocs
= NULL
;
8761 /* Make sure this symbol is output as a dynamic symbol.
8762 Undefined weak syms won't yet be marked as dynamic. */
8763 else if (h
->dynindx
== -1
8764 && !h
->forced_local
)
8766 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8771 else if (h
->type
== STT_GNU_IFUNC
)
8773 if (!h
->non_got_ref
)
8774 eh
->dyn_relocs
= NULL
;
8776 else if (ELIMINATE_COPY_RELOCS
)
8778 /* For the non-shared case, discard space for relocs against
8779 symbols which turn out to need copy relocs or are not
8785 /* Make sure this symbol is output as a dynamic symbol.
8786 Undefined weak syms won't yet be marked as dynamic. */
8787 if (h
->dynindx
== -1
8788 && !h
->forced_local
)
8790 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8794 /* If that succeeded, we know we'll be keeping all the
8796 if (h
->dynindx
!= -1)
8800 eh
->dyn_relocs
= NULL
;
8805 /* Finally, allocate space. */
8806 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8808 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8809 if (!htab
->elf
.dynamic_sections_created
)
8810 sreloc
= htab
->reliplt
;
8811 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8817 /* Find any dynamic relocs that apply to read-only sections. */
8820 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8822 struct ppc_link_hash_entry
*eh
;
8823 struct elf_dyn_relocs
*p
;
8825 eh
= (struct ppc_link_hash_entry
*) h
;
8826 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8828 asection
*s
= p
->sec
->output_section
;
8830 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8832 struct bfd_link_info
*info
= inf
;
8834 info
->flags
|= DF_TEXTREL
;
8836 /* Not an error, just cut short the traversal. */
8843 /* Set the sizes of the dynamic sections. */
8846 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8847 struct bfd_link_info
*info
)
8849 struct ppc_link_hash_table
*htab
;
8854 struct got_entry
*first_tlsld
;
8856 htab
= ppc_hash_table (info
);
8860 dynobj
= htab
->elf
.dynobj
;
8864 if (htab
->elf
.dynamic_sections_created
)
8866 /* Set the contents of the .interp section to the interpreter. */
8867 if (info
->executable
)
8869 s
= bfd_get_section_by_name (dynobj
, ".interp");
8872 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8873 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8877 /* Set up .got offsets for local syms, and space for local dynamic
8879 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8881 struct got_entry
**lgot_ents
;
8882 struct got_entry
**end_lgot_ents
;
8883 struct plt_entry
**local_plt
;
8884 struct plt_entry
**end_local_plt
;
8885 unsigned char *lgot_masks
;
8886 bfd_size_type locsymcount
;
8887 Elf_Internal_Shdr
*symtab_hdr
;
8890 if (!is_ppc64_elf (ibfd
))
8893 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8895 struct elf_dyn_relocs
*p
;
8897 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
8899 if (!bfd_is_abs_section (p
->sec
)
8900 && bfd_is_abs_section (p
->sec
->output_section
))
8902 /* Input section has been discarded, either because
8903 it is a copy of a linkonce section or due to
8904 linker script /DISCARD/, so we'll be discarding
8907 else if (p
->count
!= 0)
8909 srel
= elf_section_data (p
->sec
)->sreloc
;
8910 if (!htab
->elf
.dynamic_sections_created
)
8911 srel
= htab
->reliplt
;
8912 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8913 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8914 info
->flags
|= DF_TEXTREL
;
8919 lgot_ents
= elf_local_got_ents (ibfd
);
8923 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8924 locsymcount
= symtab_hdr
->sh_info
;
8925 end_lgot_ents
= lgot_ents
+ locsymcount
;
8926 local_plt
= (struct plt_entry
**) end_lgot_ents
;
8927 end_local_plt
= local_plt
+ locsymcount
;
8928 lgot_masks
= (unsigned char *) end_local_plt
;
8929 s
= ppc64_elf_tdata (ibfd
)->got
;
8930 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
8931 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
8933 struct got_entry
**pent
, *ent
;
8936 while ((ent
= *pent
) != NULL
)
8937 if (ent
->got
.refcount
> 0)
8939 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
8941 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
8946 unsigned int num
= 1;
8947 ent
->got
.offset
= s
->size
;
8948 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
8952 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
8953 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
8956 += num
* sizeof (Elf64_External_Rela
);
8958 += num
* sizeof (Elf64_External_Rela
);
8967 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
8968 for (; local_plt
< end_local_plt
; ++local_plt
)
8970 struct plt_entry
*ent
;
8972 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
8973 if (ent
->plt
.refcount
> 0)
8976 ent
->plt
.offset
= s
->size
;
8977 s
->size
+= PLT_ENTRY_SIZE
;
8979 htab
->reliplt
->size
+= sizeof (Elf64_External_Rela
);
8982 ent
->plt
.offset
= (bfd_vma
) -1;
8986 /* Allocate global sym .plt and .got entries, and space for global
8987 sym dynamic relocs. */
8988 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
8991 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8993 struct got_entry
*ent
;
8995 if (!is_ppc64_elf (ibfd
))
8998 ent
= ppc64_tlsld_got (ibfd
);
8999 if (ent
->got
.refcount
> 0)
9001 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9003 ent
->is_indirect
= TRUE
;
9004 ent
->got
.ent
= first_tlsld
;
9008 if (first_tlsld
== NULL
)
9010 s
= ppc64_elf_tdata (ibfd
)->got
;
9011 ent
->got
.offset
= s
->size
;
9016 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9017 srel
->size
+= sizeof (Elf64_External_Rela
);
9022 ent
->got
.offset
= (bfd_vma
) -1;
9025 /* We now have determined the sizes of the various dynamic sections.
9026 Allocate memory for them. */
9028 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9030 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9033 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9034 /* These haven't been allocated yet; don't strip. */
9036 else if (s
== htab
->got
9040 || s
== htab
->dynbss
)
9042 /* Strip this section if we don't need it; see the
9045 else if (s
== htab
->glink_eh_frame
)
9047 if (!bfd_is_abs_section (s
->output_section
))
9048 /* Not sized yet. */
9051 else if (CONST_STRNEQ (s
->name
, ".rela"))
9055 if (s
!= htab
->relplt
)
9058 /* We use the reloc_count field as a counter if we need
9059 to copy relocs into the output file. */
9065 /* It's not one of our sections, so don't allocate space. */
9071 /* If we don't need this section, strip it from the
9072 output file. This is mostly to handle .rela.bss and
9073 .rela.plt. We must create both sections in
9074 create_dynamic_sections, because they must be created
9075 before the linker maps input sections to output
9076 sections. The linker does that before
9077 adjust_dynamic_symbol is called, and it is that
9078 function which decides whether anything needs to go
9079 into these sections. */
9080 s
->flags
|= SEC_EXCLUDE
;
9084 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9087 /* Allocate memory for the section contents. We use bfd_zalloc
9088 here in case unused entries are not reclaimed before the
9089 section's contents are written out. This should not happen,
9090 but this way if it does we get a R_PPC64_NONE reloc in .rela
9091 sections instead of garbage.
9092 We also rely on the section contents being zero when writing
9094 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9095 if (s
->contents
== NULL
)
9099 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9101 if (!is_ppc64_elf (ibfd
))
9104 s
= ppc64_elf_tdata (ibfd
)->got
;
9105 if (s
!= NULL
&& s
!= htab
->got
)
9108 s
->flags
|= SEC_EXCLUDE
;
9111 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9112 if (s
->contents
== NULL
)
9116 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9120 s
->flags
|= SEC_EXCLUDE
;
9123 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9124 if (s
->contents
== NULL
)
9132 if (htab
->elf
.dynamic_sections_created
)
9134 /* Add some entries to the .dynamic section. We fill in the
9135 values later, in ppc64_elf_finish_dynamic_sections, but we
9136 must add the entries now so that we get the correct size for
9137 the .dynamic section. The DT_DEBUG entry is filled in by the
9138 dynamic linker and used by the debugger. */
9139 #define add_dynamic_entry(TAG, VAL) \
9140 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9142 if (info
->executable
)
9144 if (!add_dynamic_entry (DT_DEBUG
, 0))
9148 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
9150 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9151 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9152 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9153 || !add_dynamic_entry (DT_JMPREL
, 0)
9154 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9160 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9161 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9165 if (!htab
->no_tls_get_addr_opt
9166 && htab
->tls_get_addr_fd
!= NULL
9167 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
9168 && !add_dynamic_entry (DT_PPC64_TLSOPT
, 0))
9173 if (!add_dynamic_entry (DT_RELA
, 0)
9174 || !add_dynamic_entry (DT_RELASZ
, 0)
9175 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9178 /* If any dynamic relocs apply to a read-only section,
9179 then we need a DT_TEXTREL entry. */
9180 if ((info
->flags
& DF_TEXTREL
) == 0)
9181 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
9183 if ((info
->flags
& DF_TEXTREL
) != 0)
9185 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9190 #undef add_dynamic_entry
9195 /* Determine the type of stub needed, if any, for a call. */
9197 static inline enum ppc_stub_type
9198 ppc_type_of_stub (asection
*input_sec
,
9199 const Elf_Internal_Rela
*rel
,
9200 struct ppc_link_hash_entry
**hash
,
9201 struct plt_entry
**plt_ent
,
9202 bfd_vma destination
)
9204 struct ppc_link_hash_entry
*h
= *hash
;
9206 bfd_vma branch_offset
;
9207 bfd_vma max_branch_offset
;
9208 enum elf_ppc64_reloc_type r_type
;
9212 struct plt_entry
*ent
;
9213 struct ppc_link_hash_entry
*fdh
= h
;
9215 && h
->oh
->is_func_descriptor
)
9217 fdh
= ppc_follow_link (h
->oh
);
9221 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9222 if (ent
->addend
== rel
->r_addend
9223 && ent
->plt
.offset
!= (bfd_vma
) -1)
9226 return ppc_stub_plt_call
;
9229 /* Here, we know we don't have a plt entry. If we don't have a
9230 either a defined function descriptor or a defined entry symbol
9231 in a regular object file, then it is pointless trying to make
9232 any other type of stub. */
9233 if (!is_static_defined (&fdh
->elf
)
9234 && !is_static_defined (&h
->elf
))
9235 return ppc_stub_none
;
9237 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9239 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9240 struct plt_entry
**local_plt
= (struct plt_entry
**)
9241 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9242 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9244 if (local_plt
[r_symndx
] != NULL
)
9246 struct plt_entry
*ent
;
9248 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9249 if (ent
->addend
== rel
->r_addend
9250 && ent
->plt
.offset
!= (bfd_vma
) -1)
9253 return ppc_stub_plt_call
;
9258 /* Determine where the call point is. */
9259 location
= (input_sec
->output_offset
9260 + input_sec
->output_section
->vma
9263 branch_offset
= destination
- location
;
9264 r_type
= ELF64_R_TYPE (rel
->r_info
);
9266 /* Determine if a long branch stub is needed. */
9267 max_branch_offset
= 1 << 25;
9268 if (r_type
!= R_PPC64_REL24
)
9269 max_branch_offset
= 1 << 15;
9271 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
9272 /* We need a stub. Figure out whether a long_branch or plt_branch
9274 return ppc_stub_long_branch
;
9276 return ppc_stub_none
;
9279 /* Build a .plt call stub. */
9281 static inline bfd_byte
*
9282 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
, Elf_Internal_Rela
*r
,
9283 bfd_boolean plt_static_chain
)
9285 #define PPC_LO(v) ((v) & 0xffff)
9286 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9287 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9289 if (PPC_HA (offset
) != 0)
9293 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9294 r
[1].r_offset
= r
[0].r_offset
+ 8;
9295 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9296 r
[1].r_addend
= r
[0].r_addend
;
9297 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9299 r
[2].r_offset
= r
[1].r_offset
+ 4;
9300 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9301 r
[2].r_addend
= r
[0].r_addend
;
9305 r
[2].r_offset
= r
[1].r_offset
+ 8;
9306 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9307 r
[2].r_addend
= r
[0].r_addend
+ 8;
9308 if (plt_static_chain
)
9310 r
[3].r_offset
= r
[2].r_offset
+ 4;
9311 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9312 r
[3].r_addend
= r
[0].r_addend
+ 16;
9316 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9317 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9318 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
9319 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9321 bfd_put_32 (obfd
, ADDI_R12_R12
| PPC_LO (offset
), p
), p
+= 4;
9324 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9325 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
+ 8), p
), p
+= 4;
9326 if (plt_static_chain
)
9327 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
+ 16), p
), p
+= 4;
9328 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9335 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9336 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9338 r
[1].r_offset
= r
[0].r_offset
+ 4;
9339 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9340 r
[1].r_addend
= r
[0].r_addend
;
9344 r
[1].r_offset
= r
[0].r_offset
+ 8;
9345 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9346 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
9347 if (plt_static_chain
)
9349 r
[2].r_offset
= r
[1].r_offset
+ 4;
9350 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9351 r
[2].r_addend
= r
[0].r_addend
+ 8;
9355 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9356 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
), p
), p
+= 4;
9357 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9359 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9362 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9363 if (plt_static_chain
)
9364 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9365 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9366 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9371 /* Build a special .plt call stub for __tls_get_addr. */
9373 #define LD_R11_0R3 0xe9630000
9374 #define LD_R12_0R3 0xe9830000
9375 #define MR_R0_R3 0x7c601b78
9376 #define CMPDI_R11_0 0x2c2b0000
9377 #define ADD_R3_R12_R13 0x7c6c6a14
9378 #define BEQLR 0x4d820020
9379 #define MR_R3_R0 0x7c030378
9380 #define MFLR_R11 0x7d6802a6
9381 #define STD_R11_0R1 0xf9610000
9382 #define BCTRL 0x4e800421
9383 #define LD_R11_0R1 0xe9610000
9384 #define LD_R2_0R1 0xe8410000
9385 #define MTLR_R11 0x7d6803a6
9387 static inline bfd_byte
*
9388 build_tls_get_addr_stub (bfd
*obfd
, bfd_byte
*p
, int offset
,
9389 Elf_Internal_Rela
*r
, bfd_boolean plt_static_chain
)
9391 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9392 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9393 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9394 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9395 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9396 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9397 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9398 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9399 bfd_put_32 (obfd
, STD_R11_0R1
+ 32, p
), p
+= 4;
9402 r
[0].r_offset
+= 9 * 4;
9403 p
= build_plt_stub (obfd
, p
, offset
, r
, plt_static_chain
);
9404 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9406 bfd_put_32 (obfd
, LD_R11_0R1
+ 32, p
), p
+= 4;
9407 bfd_put_32 (obfd
, LD_R2_0R1
+ 40, p
), p
+= 4;
9408 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9409 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9414 static Elf_Internal_Rela
*
9415 get_relocs (asection
*sec
, int count
)
9417 Elf_Internal_Rela
*relocs
;
9418 struct bfd_elf_section_data
*elfsec_data
;
9420 elfsec_data
= elf_section_data (sec
);
9421 relocs
= elfsec_data
->relocs
;
9424 bfd_size_type relsize
;
9425 relsize
= sec
->reloc_count
* sizeof (*relocs
);
9426 relocs
= bfd_alloc (sec
->owner
, relsize
);
9429 elfsec_data
->relocs
= relocs
;
9430 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
9431 sizeof (Elf_Internal_Shdr
));
9432 if (elfsec_data
->rela
.hdr
== NULL
)
9434 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
9435 * sizeof (Elf64_External_Rela
));
9436 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
9437 sec
->reloc_count
= 0;
9439 relocs
+= sec
->reloc_count
;
9440 sec
->reloc_count
+= count
;
9445 get_r2off (struct bfd_link_info
*info
,
9446 struct ppc_stub_hash_entry
*stub_entry
)
9448 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9449 bfd_vma r2off
= htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
;
9453 /* Support linking -R objects. Get the toc pointer from the
9456 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
9457 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
9459 if (strcmp (opd
->name
, ".opd") != 0
9460 || opd
->reloc_count
!= 0)
9462 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for %s\n"),
9463 stub_entry
->h
->elf
.root
.root
.string
);
9464 bfd_set_error (bfd_error_bad_value
);
9467 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
9469 r2off
= bfd_get_64 (opd
->owner
, buf
);
9470 r2off
-= elf_gp (info
->output_bfd
);
9472 r2off
-= htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
;
9477 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9479 struct ppc_stub_hash_entry
*stub_entry
;
9480 struct ppc_branch_hash_entry
*br_entry
;
9481 struct bfd_link_info
*info
;
9482 struct ppc_link_hash_table
*htab
;
9487 Elf_Internal_Rela
*r
;
9490 /* Massage our args to the form they really have. */
9491 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9494 htab
= ppc_hash_table (info
);
9498 /* Make a note of the offset within the stubs for this entry. */
9499 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
9500 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
9502 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
9503 switch (stub_entry
->stub_type
)
9505 case ppc_stub_long_branch
:
9506 case ppc_stub_long_branch_r2off
:
9507 /* Branches are relative. This is where we are going to. */
9508 off
= dest
= (stub_entry
->target_value
9509 + stub_entry
->target_section
->output_offset
9510 + stub_entry
->target_section
->output_section
->vma
);
9512 /* And this is where we are coming from. */
9513 off
-= (stub_entry
->stub_offset
9514 + stub_entry
->stub_sec
->output_offset
9515 + stub_entry
->stub_sec
->output_section
->vma
);
9518 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9520 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9524 htab
->stub_error
= TRUE
;
9527 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9530 if (PPC_HA (r2off
) != 0)
9533 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9536 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9540 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
9542 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9544 info
->callbacks
->einfo (_("%P: long branch stub `%s' offset overflow\n"),
9545 stub_entry
->root
.string
);
9546 htab
->stub_error
= TRUE
;
9550 if (info
->emitrelocations
)
9552 r
= get_relocs (stub_entry
->stub_sec
, 1);
9555 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9556 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
9558 if (stub_entry
->h
!= NULL
)
9560 struct elf_link_hash_entry
**hashes
;
9561 unsigned long symndx
;
9562 struct ppc_link_hash_entry
*h
;
9564 hashes
= elf_sym_hashes (htab
->stub_bfd
);
9567 bfd_size_type hsize
;
9569 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
9570 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
9573 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
9574 htab
->stub_globals
= 1;
9576 symndx
= htab
->stub_globals
++;
9578 hashes
[symndx
] = &h
->elf
;
9579 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
9580 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
9581 h
= ppc_follow_link (h
->oh
);
9582 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
9583 /* H is an opd symbol. The addend must be zero. */
9587 off
= (h
->elf
.root
.u
.def
.value
9588 + h
->elf
.root
.u
.def
.section
->output_offset
9589 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
9596 case ppc_stub_plt_branch
:
9597 case ppc_stub_plt_branch_r2off
:
9598 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9599 stub_entry
->root
.string
+ 9,
9601 if (br_entry
== NULL
)
9603 info
->callbacks
->einfo (_("%P: can't find branch stub `%s'\n"),
9604 stub_entry
->root
.string
);
9605 htab
->stub_error
= TRUE
;
9609 dest
= (stub_entry
->target_value
9610 + stub_entry
->target_section
->output_offset
9611 + stub_entry
->target_section
->output_section
->vma
);
9613 bfd_put_64 (htab
->brlt
->owner
, dest
,
9614 htab
->brlt
->contents
+ br_entry
->offset
);
9616 if (br_entry
->iter
== htab
->stub_iteration
)
9620 if (htab
->relbrlt
!= NULL
)
9622 /* Create a reloc for the branch lookup table entry. */
9623 Elf_Internal_Rela rela
;
9626 rela
.r_offset
= (br_entry
->offset
9627 + htab
->brlt
->output_offset
9628 + htab
->brlt
->output_section
->vma
);
9629 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9630 rela
.r_addend
= dest
;
9632 rl
= htab
->relbrlt
->contents
;
9633 rl
+= (htab
->relbrlt
->reloc_count
++
9634 * sizeof (Elf64_External_Rela
));
9635 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
9637 else if (info
->emitrelocations
)
9639 r
= get_relocs (htab
->brlt
, 1);
9642 /* brlt, being SEC_LINKER_CREATED does not go through the
9643 normal reloc processing. Symbols and offsets are not
9644 translated from input file to output file form, so
9645 set up the offset per the output file. */
9646 r
->r_offset
= (br_entry
->offset
9647 + htab
->brlt
->output_offset
9648 + htab
->brlt
->output_section
->vma
);
9649 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9654 dest
= (br_entry
->offset
9655 + htab
->brlt
->output_offset
9656 + htab
->brlt
->output_section
->vma
);
9659 - elf_gp (htab
->brlt
->output_section
->owner
)
9660 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9662 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9664 info
->callbacks
->einfo
9665 (_("%P: linkage table error against `%s'\n"),
9666 stub_entry
->root
.string
);
9667 bfd_set_error (bfd_error_bad_value
);
9668 htab
->stub_error
= TRUE
;
9672 if (info
->emitrelocations
)
9674 r
= get_relocs (stub_entry
->stub_sec
, 1 + (PPC_HA (off
) != 0));
9677 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9678 if (bfd_big_endian (info
->output_bfd
))
9680 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
9682 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9683 r
[0].r_addend
= dest
;
9684 if (PPC_HA (off
) != 0)
9686 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9687 r
[1].r_offset
= r
[0].r_offset
+ 4;
9688 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9689 r
[1].r_addend
= r
[0].r_addend
;
9693 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
9695 if (PPC_HA (off
) != 0)
9698 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9700 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9705 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9710 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9714 htab
->stub_error
= TRUE
;
9718 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9721 if (PPC_HA (off
) != 0)
9724 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9726 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9731 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9735 if (PPC_HA (r2off
) != 0)
9738 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9741 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9744 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
9746 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
9749 case ppc_stub_plt_call
:
9750 if (stub_entry
->h
!= NULL
9751 && stub_entry
->h
->is_func_descriptor
9752 && stub_entry
->h
->oh
!= NULL
)
9754 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
9756 /* If the old-ABI "dot-symbol" is undefined make it weak so
9757 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
9758 FIXME: We used to define the symbol on one of the call
9759 stubs instead, which is why we test symbol section id
9760 against htab->top_id in various places. Likely all
9761 these checks could now disappear. */
9762 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
9763 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
9764 /* Stop undo_symbol_twiddle changing it back to undefined. */
9765 fh
->was_undefined
= 0;
9768 /* Now build the stub. */
9769 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9770 if (dest
>= (bfd_vma
) -2)
9774 if (!htab
->elf
.dynamic_sections_created
9775 || stub_entry
->h
== NULL
9776 || stub_entry
->h
->elf
.dynindx
== -1)
9779 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
9781 if (stub_entry
->h
== NULL
9782 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
9784 Elf_Internal_Rela rela
;
9787 rela
.r_offset
= dest
;
9788 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
9789 rela
.r_addend
= (stub_entry
->target_value
9790 + stub_entry
->target_section
->output_offset
9791 + stub_entry
->target_section
->output_section
->vma
);
9793 rl
= (htab
->reliplt
->contents
9794 + (htab
->reliplt
->reloc_count
++
9795 * sizeof (Elf64_External_Rela
)));
9796 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
9797 stub_entry
->plt_ent
->plt
.offset
|= 1;
9801 - elf_gp (plt
->output_section
->owner
)
9802 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9804 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9806 info
->callbacks
->einfo
9807 (_("%P: linkage table error against `%s'\n"),
9808 stub_entry
->h
!= NULL
9809 ? stub_entry
->h
->elf
.root
.root
.string
9811 bfd_set_error (bfd_error_bad_value
);
9812 htab
->stub_error
= TRUE
;
9817 if (info
->emitrelocations
)
9819 r
= get_relocs (stub_entry
->stub_sec
,
9821 + (PPC_HA (off
) != 0)
9822 + (htab
->plt_static_chain
9823 && PPC_HA (off
+ 16) == PPC_HA (off
))));
9826 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9827 if (bfd_big_endian (info
->output_bfd
))
9829 r
[0].r_addend
= dest
;
9831 if (stub_entry
->h
!= NULL
9832 && (stub_entry
->h
== htab
->tls_get_addr_fd
9833 || stub_entry
->h
== htab
->tls_get_addr
)
9834 && !htab
->no_tls_get_addr_opt
)
9835 p
= build_tls_get_addr_stub (htab
->stub_bfd
, loc
, off
, r
,
9836 htab
->plt_static_chain
);
9838 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
, r
,
9839 htab
->plt_static_chain
);
9848 stub_entry
->stub_sec
->size
+= size
;
9850 if (htab
->emit_stub_syms
)
9852 struct elf_link_hash_entry
*h
;
9855 const char *const stub_str
[] = { "long_branch",
9856 "long_branch_r2off",
9861 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
9862 len2
= strlen (stub_entry
->root
.string
);
9863 name
= bfd_malloc (len1
+ len2
+ 2);
9866 memcpy (name
, stub_entry
->root
.string
, 9);
9867 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
9868 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
9869 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
9872 if (h
->root
.type
== bfd_link_hash_new
)
9874 h
->root
.type
= bfd_link_hash_defined
;
9875 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
9876 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
9879 h
->ref_regular_nonweak
= 1;
9880 h
->forced_local
= 1;
9888 /* As above, but don't actually build the stub. Just bump offset so
9889 we know stub section sizes, and select plt_branch stubs where
9890 long_branch stubs won't do. */
9893 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9895 struct ppc_stub_hash_entry
*stub_entry
;
9896 struct bfd_link_info
*info
;
9897 struct ppc_link_hash_table
*htab
;
9901 /* Massage our args to the form they really have. */
9902 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9905 htab
= ppc_hash_table (info
);
9909 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
9912 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
9913 if (off
>= (bfd_vma
) -2)
9916 if (!htab
->elf
.dynamic_sections_created
9917 || stub_entry
->h
== NULL
9918 || stub_entry
->h
->elf
.dynindx
== -1)
9920 off
+= (plt
->output_offset
9921 + plt
->output_section
->vma
9922 - elf_gp (plt
->output_section
->owner
)
9923 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9925 size
= PLT_CALL_STUB_SIZE
;
9926 if (!htab
->plt_static_chain
)
9928 if (PPC_HA (off
) == 0)
9930 if (PPC_HA (off
+ 8 + 8 * htab
->plt_static_chain
) != PPC_HA (off
))
9932 if (stub_entry
->h
!= NULL
9933 && (stub_entry
->h
== htab
->tls_get_addr_fd
9934 || stub_entry
->h
== htab
->tls_get_addr
)
9935 && !htab
->no_tls_get_addr_opt
)
9937 if (info
->emitrelocations
)
9939 stub_entry
->stub_sec
->reloc_count
9941 + (PPC_HA (off
) != 0)
9942 + (htab
->plt_static_chain
9943 && PPC_HA (off
+ 16) == PPC_HA (off
)));
9944 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
9949 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
9953 off
= (stub_entry
->target_value
9954 + stub_entry
->target_section
->output_offset
9955 + stub_entry
->target_section
->output_section
->vma
);
9956 off
-= (stub_entry
->stub_sec
->size
9957 + stub_entry
->stub_sec
->output_offset
9958 + stub_entry
->stub_sec
->output_section
->vma
);
9960 /* Reset the stub type from the plt variant in case we now
9961 can reach with a shorter stub. */
9962 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
9963 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
9966 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9968 r2off
= get_r2off (info
, stub_entry
);
9971 htab
->stub_error
= TRUE
;
9975 if (PPC_HA (r2off
) != 0)
9980 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
9981 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9983 struct ppc_branch_hash_entry
*br_entry
;
9985 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9986 stub_entry
->root
.string
+ 9,
9988 if (br_entry
== NULL
)
9990 info
->callbacks
->einfo (_("%P: can't build branch stub `%s'\n"),
9991 stub_entry
->root
.string
);
9992 htab
->stub_error
= TRUE
;
9996 if (br_entry
->iter
!= htab
->stub_iteration
)
9998 br_entry
->iter
= htab
->stub_iteration
;
9999 br_entry
->offset
= htab
->brlt
->size
;
10000 htab
->brlt
->size
+= 8;
10002 if (htab
->relbrlt
!= NULL
)
10003 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10004 else if (info
->emitrelocations
)
10006 htab
->brlt
->reloc_count
+= 1;
10007 htab
->brlt
->flags
|= SEC_RELOC
;
10011 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
10012 off
= (br_entry
->offset
10013 + htab
->brlt
->output_offset
10014 + htab
->brlt
->output_section
->vma
10015 - elf_gp (htab
->brlt
->output_section
->owner
)
10016 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
10018 if (info
->emitrelocations
)
10020 stub_entry
->stub_sec
->reloc_count
+= 1 + (PPC_HA (off
) != 0);
10021 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10024 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10027 if (PPC_HA (off
) != 0)
10033 if (PPC_HA (off
) != 0)
10036 if (PPC_HA (r2off
) != 0)
10040 else if (info
->emitrelocations
)
10042 stub_entry
->stub_sec
->reloc_count
+= 1;
10043 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10047 stub_entry
->stub_sec
->size
+= size
;
10051 /* Set up various things so that we can make a list of input sections
10052 for each output section included in the link. Returns -1 on error,
10053 0 when no stubs will be needed, and 1 on success. */
10056 ppc64_elf_setup_section_lists
10057 (struct bfd_link_info
*info
,
10058 asection
*(*add_stub_section
) (const char *, asection
*),
10059 void (*layout_sections_again
) (void))
10062 int top_id
, top_index
, id
;
10064 asection
**input_list
;
10066 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10070 /* Stash our params away. */
10071 htab
->add_stub_section
= add_stub_section
;
10072 htab
->layout_sections_again
= layout_sections_again
;
10074 if (htab
->brlt
== NULL
)
10077 /* Find the top input section id. */
10078 for (input_bfd
= info
->input_bfds
, top_id
= 3;
10080 input_bfd
= input_bfd
->link_next
)
10082 for (section
= input_bfd
->sections
;
10084 section
= section
->next
)
10086 if (top_id
< section
->id
)
10087 top_id
= section
->id
;
10091 htab
->top_id
= top_id
;
10092 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
10093 htab
->stub_group
= bfd_zmalloc (amt
);
10094 if (htab
->stub_group
== NULL
)
10097 /* Set toc_off for com, und, abs and ind sections. */
10098 for (id
= 0; id
< 3; id
++)
10099 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
10101 /* We can't use output_bfd->section_count here to find the top output
10102 section index as some sections may have been removed, and
10103 strip_excluded_output_sections doesn't renumber the indices. */
10104 for (section
= info
->output_bfd
->sections
, top_index
= 0;
10106 section
= section
->next
)
10108 if (top_index
< section
->index
)
10109 top_index
= section
->index
;
10112 htab
->top_index
= top_index
;
10113 amt
= sizeof (asection
*) * (top_index
+ 1);
10114 input_list
= bfd_zmalloc (amt
);
10115 htab
->input_list
= input_list
;
10116 if (input_list
== NULL
)
10122 /* Set up for first pass at multitoc partitioning. */
10125 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10127 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10129 elf_gp (info
->output_bfd
) = ppc64_elf_toc (info
->output_bfd
);
10130 htab
->toc_curr
= elf_gp (info
->output_bfd
);
10131 htab
->toc_bfd
= NULL
;
10132 htab
->toc_first_sec
= NULL
;
10135 /* The linker repeatedly calls this function for each TOC input section
10136 and linker generated GOT section. Group input bfds such that the toc
10137 within a group is less than 64k in size. */
10140 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10142 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10143 bfd_vma addr
, off
, limit
;
10148 if (!htab
->second_toc_pass
)
10150 /* Keep track of the first .toc or .got section for this input bfd. */
10151 if (htab
->toc_bfd
!= isec
->owner
)
10153 htab
->toc_bfd
= isec
->owner
;
10154 htab
->toc_first_sec
= isec
;
10157 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10158 off
= addr
- htab
->toc_curr
;
10159 limit
= 0x80008000;
10160 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10162 if (off
+ isec
->size
> limit
)
10164 addr
= (htab
->toc_first_sec
->output_offset
10165 + htab
->toc_first_sec
->output_section
->vma
);
10166 htab
->toc_curr
= addr
;
10169 /* toc_curr is the base address of this toc group. Set elf_gp
10170 for the input section to be the offset relative to the
10171 output toc base plus 0x8000. Making the input elf_gp an
10172 offset allows us to move the toc as a whole without
10173 recalculating input elf_gp. */
10174 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
10175 off
+= TOC_BASE_OFF
;
10177 /* Die if someone uses a linker script that doesn't keep input
10178 file .toc and .got together. */
10179 if (elf_gp (isec
->owner
) != 0
10180 && elf_gp (isec
->owner
) != off
)
10183 elf_gp (isec
->owner
) = off
;
10187 /* During the second pass toc_first_sec points to the start of
10188 a toc group, and toc_curr is used to track the old elf_gp.
10189 We use toc_bfd to ensure we only look at each bfd once. */
10190 if (htab
->toc_bfd
== isec
->owner
)
10192 htab
->toc_bfd
= isec
->owner
;
10194 if (htab
->toc_first_sec
== NULL
10195 || htab
->toc_curr
!= elf_gp (isec
->owner
))
10197 htab
->toc_curr
= elf_gp (isec
->owner
);
10198 htab
->toc_first_sec
= isec
;
10200 addr
= (htab
->toc_first_sec
->output_offset
10201 + htab
->toc_first_sec
->output_section
->vma
);
10202 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
10203 elf_gp (isec
->owner
) = off
;
10208 /* Called via elf_link_hash_traverse to merge GOT entries for global
10212 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
10214 if (h
->root
.type
== bfd_link_hash_indirect
)
10217 merge_got_entries (&h
->got
.glist
);
10222 /* Called via elf_link_hash_traverse to allocate GOT entries for global
10226 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
10228 struct got_entry
*gent
;
10230 if (h
->root
.type
== bfd_link_hash_indirect
)
10233 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
10234 if (!gent
->is_indirect
)
10235 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
10239 /* Called on the first multitoc pass after the last call to
10240 ppc64_elf_next_toc_section. This function removes duplicate GOT
10244 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
10246 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10247 struct bfd
*ibfd
, *ibfd2
;
10248 bfd_boolean done_something
;
10250 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
10252 if (!htab
->do_multi_toc
)
10255 /* Merge global sym got entries within a toc group. */
10256 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
10258 /* And tlsld_got. */
10259 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10261 struct got_entry
*ent
, *ent2
;
10263 if (!is_ppc64_elf (ibfd
))
10266 ent
= ppc64_tlsld_got (ibfd
);
10267 if (!ent
->is_indirect
10268 && ent
->got
.offset
!= (bfd_vma
) -1)
10270 for (ibfd2
= ibfd
->link_next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link_next
)
10272 if (!is_ppc64_elf (ibfd2
))
10275 ent2
= ppc64_tlsld_got (ibfd2
);
10276 if (!ent2
->is_indirect
10277 && ent2
->got
.offset
!= (bfd_vma
) -1
10278 && elf_gp (ibfd2
) == elf_gp (ibfd
))
10280 ent2
->is_indirect
= TRUE
;
10281 ent2
->got
.ent
= ent
;
10287 /* Zap sizes of got sections. */
10288 htab
->reliplt
->rawsize
= htab
->reliplt
->size
;
10289 htab
->reliplt
->size
-= htab
->got_reli_size
;
10290 htab
->got_reli_size
= 0;
10292 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10294 asection
*got
, *relgot
;
10296 if (!is_ppc64_elf (ibfd
))
10299 got
= ppc64_elf_tdata (ibfd
)->got
;
10302 got
->rawsize
= got
->size
;
10304 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
10305 relgot
->rawsize
= relgot
->size
;
10310 /* Now reallocate the got, local syms first. We don't need to
10311 allocate section contents again since we never increase size. */
10312 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10314 struct got_entry
**lgot_ents
;
10315 struct got_entry
**end_lgot_ents
;
10316 struct plt_entry
**local_plt
;
10317 struct plt_entry
**end_local_plt
;
10318 unsigned char *lgot_masks
;
10319 bfd_size_type locsymcount
;
10320 Elf_Internal_Shdr
*symtab_hdr
;
10321 asection
*s
, *srel
;
10323 if (!is_ppc64_elf (ibfd
))
10326 lgot_ents
= elf_local_got_ents (ibfd
);
10330 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10331 locsymcount
= symtab_hdr
->sh_info
;
10332 end_lgot_ents
= lgot_ents
+ locsymcount
;
10333 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10334 end_local_plt
= local_plt
+ locsymcount
;
10335 lgot_masks
= (unsigned char *) end_local_plt
;
10336 s
= ppc64_elf_tdata (ibfd
)->got
;
10337 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10338 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10340 struct got_entry
*ent
;
10342 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
10344 unsigned int num
= 1;
10345 ent
->got
.offset
= s
->size
;
10346 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10348 s
->size
+= num
* 8;
10350 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
10351 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
10353 htab
->reliplt
->size
10354 += num
* sizeof (Elf64_External_Rela
);
10355 htab
->got_reli_size
10356 += num
* sizeof (Elf64_External_Rela
);
10362 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
10364 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10366 struct got_entry
*ent
;
10368 if (!is_ppc64_elf (ibfd
))
10371 ent
= ppc64_tlsld_got (ibfd
);
10372 if (!ent
->is_indirect
10373 && ent
->got
.offset
!= (bfd_vma
) -1)
10375 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
10376 ent
->got
.offset
= s
->size
;
10380 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10381 srel
->size
+= sizeof (Elf64_External_Rela
);
10386 done_something
= htab
->reliplt
->rawsize
!= htab
->reliplt
->size
;
10387 if (!done_something
)
10388 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10392 if (!is_ppc64_elf (ibfd
))
10395 got
= ppc64_elf_tdata (ibfd
)->got
;
10398 done_something
= got
->rawsize
!= got
->size
;
10399 if (done_something
)
10404 if (done_something
)
10405 (*htab
->layout_sections_again
) ();
10407 /* Set up for second pass over toc sections to recalculate elf_gp
10408 on input sections. */
10409 htab
->toc_bfd
= NULL
;
10410 htab
->toc_first_sec
= NULL
;
10411 htab
->second_toc_pass
= TRUE
;
10412 return done_something
;
10415 /* Called after second pass of multitoc partitioning. */
10418 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
10420 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10422 /* After the second pass, toc_curr tracks the TOC offset used
10423 for code sections below in ppc64_elf_next_input_section. */
10424 htab
->toc_curr
= TOC_BASE_OFF
;
10427 /* No toc references were found in ISEC. If the code in ISEC makes no
10428 calls, then there's no need to use toc adjusting stubs when branching
10429 into ISEC. Actually, indirect calls from ISEC are OK as they will
10430 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
10431 needed, and 2 if a cyclical call-graph was found but no other reason
10432 for a stub was detected. If called from the top level, a return of
10433 2 means the same as a return of 0. */
10436 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
10440 /* Mark this section as checked. */
10441 isec
->call_check_done
= 1;
10443 /* We know none of our code bearing sections will need toc stubs. */
10444 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
10447 if (isec
->size
== 0)
10450 if (isec
->output_section
== NULL
)
10454 if (isec
->reloc_count
!= 0)
10456 Elf_Internal_Rela
*relstart
, *rel
;
10457 Elf_Internal_Sym
*local_syms
;
10458 struct ppc_link_hash_table
*htab
;
10460 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
10461 info
->keep_memory
);
10462 if (relstart
== NULL
)
10465 /* Look for branches to outside of this section. */
10467 htab
= ppc_hash_table (info
);
10471 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
10473 enum elf_ppc64_reloc_type r_type
;
10474 unsigned long r_symndx
;
10475 struct elf_link_hash_entry
*h
;
10476 struct ppc_link_hash_entry
*eh
;
10477 Elf_Internal_Sym
*sym
;
10479 struct _opd_sec_data
*opd
;
10483 r_type
= ELF64_R_TYPE (rel
->r_info
);
10484 if (r_type
!= R_PPC64_REL24
10485 && r_type
!= R_PPC64_REL14
10486 && r_type
!= R_PPC64_REL14_BRTAKEN
10487 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
10490 r_symndx
= ELF64_R_SYM (rel
->r_info
);
10491 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
10498 /* Calls to dynamic lib functions go through a plt call stub
10500 eh
= (struct ppc_link_hash_entry
*) h
;
10502 && (eh
->elf
.plt
.plist
!= NULL
10504 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
10510 if (sym_sec
== NULL
)
10511 /* Ignore other undefined symbols. */
10514 /* Assume branches to other sections not included in the
10515 link need stubs too, to cover -R and absolute syms. */
10516 if (sym_sec
->output_section
== NULL
)
10523 sym_value
= sym
->st_value
;
10526 if (h
->root
.type
!= bfd_link_hash_defined
10527 && h
->root
.type
!= bfd_link_hash_defweak
)
10529 sym_value
= h
->root
.u
.def
.value
;
10531 sym_value
+= rel
->r_addend
;
10533 /* If this branch reloc uses an opd sym, find the code section. */
10534 opd
= get_opd_info (sym_sec
);
10537 if (h
== NULL
&& opd
->adjust
!= NULL
)
10541 adjust
= opd
->adjust
[sym
->st_value
/ 8];
10543 /* Assume deleted functions won't ever be called. */
10545 sym_value
+= adjust
;
10548 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
10549 if (dest
== (bfd_vma
) -1)
10554 + sym_sec
->output_offset
10555 + sym_sec
->output_section
->vma
);
10557 /* Ignore branch to self. */
10558 if (sym_sec
== isec
)
10561 /* If the called function uses the toc, we need a stub. */
10562 if (sym_sec
->has_toc_reloc
10563 || sym_sec
->makes_toc_func_call
)
10569 /* Assume any branch that needs a long branch stub might in fact
10570 need a plt_branch stub. A plt_branch stub uses r2. */
10571 else if (dest
- (isec
->output_offset
10572 + isec
->output_section
->vma
10573 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
10579 /* If calling back to a section in the process of being
10580 tested, we can't say for sure that no toc adjusting stubs
10581 are needed, so don't return zero. */
10582 else if (sym_sec
->call_check_in_progress
)
10585 /* Branches to another section that itself doesn't have any TOC
10586 references are OK. Recursively call ourselves to check. */
10587 else if (!sym_sec
->call_check_done
)
10591 /* Mark current section as indeterminate, so that other
10592 sections that call back to current won't be marked as
10594 isec
->call_check_in_progress
= 1;
10595 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
10596 isec
->call_check_in_progress
= 0;
10607 if (local_syms
!= NULL
10608 && (elf_symtab_hdr (isec
->owner
).contents
10609 != (unsigned char *) local_syms
))
10611 if (elf_section_data (isec
)->relocs
!= relstart
)
10616 && isec
->map_head
.s
!= NULL
10617 && (strcmp (isec
->output_section
->name
, ".init") == 0
10618 || strcmp (isec
->output_section
->name
, ".fini") == 0))
10620 if (isec
->map_head
.s
->has_toc_reloc
10621 || isec
->map_head
.s
->makes_toc_func_call
)
10623 else if (!isec
->map_head
.s
->call_check_done
)
10626 isec
->call_check_in_progress
= 1;
10627 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
10628 isec
->call_check_in_progress
= 0;
10635 isec
->makes_toc_func_call
= 1;
10640 /* The linker repeatedly calls this function for each input section,
10641 in the order that input sections are linked into output sections.
10642 Build lists of input sections to determine groupings between which
10643 we may insert linker stubs. */
10646 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
10648 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10653 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
10654 && isec
->output_section
->index
<= htab
->top_index
)
10656 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
10657 /* Steal the link_sec pointer for our list. */
10658 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
10659 /* This happens to make the list in reverse order,
10660 which is what we want. */
10661 PREV_SEC (isec
) = *list
;
10665 if (htab
->multi_toc_needed
)
10667 /* If a code section has a function that uses the TOC then we need
10668 to use the right TOC (obviously). Also, make sure that .opd gets
10669 the correct TOC value for R_PPC64_TOC relocs that don't have or
10670 can't find their function symbol (shouldn't ever happen now).
10671 Also specially treat .fixup for the linux kernel. .fixup
10672 contains branches, but only back to the function that hit an
10674 if (isec
->has_toc_reloc
10675 || (isec
->flags
& SEC_CODE
) == 0
10676 || strcmp (isec
->name
, ".fixup") == 0)
10678 if (elf_gp (isec
->owner
) != 0)
10679 htab
->toc_curr
= elf_gp (isec
->owner
);
10683 if (!isec
->call_check_done
10684 && toc_adjusting_stub_needed (info
, isec
) < 0)
10686 /* If we make a local call from this section, ie. a branch
10687 without a following nop, then we have no place to put a
10688 toc restoring insn. We must use the same toc group as
10690 Testing makes_toc_func_call actually tests for *any*
10691 calls to functions that need a good toc pointer. A more
10692 precise test would be better, as this one will set
10693 incorrect values for pasted .init/.fini fragments.
10694 (Fixed later in check_pasted_section.) */
10695 if (isec
->makes_toc_func_call
10696 && elf_gp (isec
->owner
) != 0)
10697 htab
->toc_curr
= elf_gp (isec
->owner
);
10701 /* Functions that don't use the TOC can belong in any TOC group.
10702 Use the last TOC base. */
10703 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
10707 /* Check that all .init and .fini sections use the same toc, if they
10708 have toc relocs. */
10711 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
10713 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
10717 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10718 bfd_vma toc_off
= 0;
10721 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10722 if (i
->has_toc_reloc
)
10725 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10726 else if (toc_off
!= htab
->stub_group
[i
->id
].toc_off
)
10731 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10732 if (i
->makes_toc_func_call
)
10734 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10738 /* Make sure the whole pasted function uses the same toc offset. */
10740 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10741 htab
->stub_group
[i
->id
].toc_off
= toc_off
;
10747 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
10749 return (check_pasted_section (info
, ".init")
10750 & check_pasted_section (info
, ".fini"));
10753 /* See whether we can group stub sections together. Grouping stub
10754 sections may result in fewer stubs. More importantly, we need to
10755 put all .init* and .fini* stubs at the beginning of the .init or
10756 .fini output sections respectively, because glibc splits the
10757 _init and _fini functions into multiple parts. Putting a stub in
10758 the middle of a function is not a good idea. */
10761 group_sections (struct ppc_link_hash_table
*htab
,
10762 bfd_size_type stub_group_size
,
10763 bfd_boolean stubs_always_before_branch
)
10766 bfd_size_type stub14_group_size
;
10767 bfd_boolean suppress_size_errors
;
10769 suppress_size_errors
= FALSE
;
10770 stub14_group_size
= stub_group_size
;
10771 if (stub_group_size
== 1)
10773 /* Default values. */
10774 if (stubs_always_before_branch
)
10776 stub_group_size
= 0x1e00000;
10777 stub14_group_size
= 0x7800;
10781 stub_group_size
= 0x1c00000;
10782 stub14_group_size
= 0x7000;
10784 suppress_size_errors
= TRUE
;
10787 list
= htab
->input_list
+ htab
->top_index
;
10790 asection
*tail
= *list
;
10791 while (tail
!= NULL
)
10795 bfd_size_type total
;
10796 bfd_boolean big_sec
;
10800 total
= tail
->size
;
10801 big_sec
= total
> (ppc64_elf_section_data (tail
) != NULL
10802 && ppc64_elf_section_data (tail
)->has_14bit_branch
10803 ? stub14_group_size
: stub_group_size
);
10804 if (big_sec
&& !suppress_size_errors
)
10805 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
10806 tail
->owner
, tail
);
10807 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
10809 while ((prev
= PREV_SEC (curr
)) != NULL
10810 && ((total
+= curr
->output_offset
- prev
->output_offset
)
10811 < (ppc64_elf_section_data (prev
) != NULL
10812 && ppc64_elf_section_data (prev
)->has_14bit_branch
10813 ? stub14_group_size
: stub_group_size
))
10814 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10817 /* OK, the size from the start of CURR to the end is less
10818 than stub_group_size and thus can be handled by one stub
10819 section. (or the tail section is itself larger than
10820 stub_group_size, in which case we may be toast.) We
10821 should really be keeping track of the total size of stubs
10822 added here, as stubs contribute to the final output
10823 section size. That's a little tricky, and this way will
10824 only break if stubs added make the total size more than
10825 2^25, ie. for the default stub_group_size, if stubs total
10826 more than 2097152 bytes, or nearly 75000 plt call stubs. */
10829 prev
= PREV_SEC (tail
);
10830 /* Set up this stub group. */
10831 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10833 while (tail
!= curr
&& (tail
= prev
) != NULL
);
10835 /* But wait, there's more! Input sections up to stub_group_size
10836 bytes before the stub section can be handled by it too.
10837 Don't do this if we have a really large section after the
10838 stubs, as adding more stubs increases the chance that
10839 branches may not reach into the stub section. */
10840 if (!stubs_always_before_branch
&& !big_sec
)
10843 while (prev
!= NULL
10844 && ((total
+= tail
->output_offset
- prev
->output_offset
)
10845 < (ppc64_elf_section_data (prev
) != NULL
10846 && ppc64_elf_section_data (prev
)->has_14bit_branch
10847 ? stub14_group_size
: stub_group_size
))
10848 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10851 prev
= PREV_SEC (tail
);
10852 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10858 while (list
-- != htab
->input_list
);
10859 free (htab
->input_list
);
10863 static const unsigned char glink_eh_frame_cie
[] =
10865 0, 0, 0, 16, /* length. */
10866 0, 0, 0, 0, /* id. */
10867 1, /* CIE version. */
10868 'z', 'R', 0, /* Augmentation string. */
10869 4, /* Code alignment. */
10870 0x78, /* Data alignment. */
10872 1, /* Augmentation size. */
10873 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
10874 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
10877 /* Stripping output sections is normally done before dynamic section
10878 symbols have been allocated. This function is called later, and
10879 handles cases like htab->brlt which is mapped to its own output
10883 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
10885 if (isec
->size
== 0
10886 && isec
->output_section
->size
== 0
10887 && !bfd_section_removed_from_list (info
->output_bfd
,
10888 isec
->output_section
)
10889 && elf_section_data (isec
->output_section
)->dynindx
== 0)
10891 isec
->output_section
->flags
|= SEC_EXCLUDE
;
10892 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
10893 info
->output_bfd
->section_count
--;
10897 /* Determine and set the size of the stub section for a final link.
10899 The basic idea here is to examine all the relocations looking for
10900 PC-relative calls to a target that is unreachable with a "bl"
10904 ppc64_elf_size_stubs (struct bfd_link_info
*info
, bfd_signed_vma group_size
,
10905 bfd_boolean plt_static_chain
)
10907 bfd_size_type stub_group_size
;
10908 bfd_boolean stubs_always_before_branch
;
10909 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10914 htab
->plt_static_chain
= plt_static_chain
;
10915 stubs_always_before_branch
= group_size
< 0;
10916 if (group_size
< 0)
10917 stub_group_size
= -group_size
;
10919 stub_group_size
= group_size
;
10921 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
10926 unsigned int bfd_indx
;
10927 asection
*stub_sec
;
10929 htab
->stub_iteration
+= 1;
10931 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
10933 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
10935 Elf_Internal_Shdr
*symtab_hdr
;
10937 Elf_Internal_Sym
*local_syms
= NULL
;
10939 if (!is_ppc64_elf (input_bfd
))
10942 /* We'll need the symbol table in a second. */
10943 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
10944 if (symtab_hdr
->sh_info
== 0)
10947 /* Walk over each section attached to the input bfd. */
10948 for (section
= input_bfd
->sections
;
10950 section
= section
->next
)
10952 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
10954 /* If there aren't any relocs, then there's nothing more
10956 if ((section
->flags
& SEC_RELOC
) == 0
10957 || (section
->flags
& SEC_ALLOC
) == 0
10958 || (section
->flags
& SEC_LOAD
) == 0
10959 || (section
->flags
& SEC_CODE
) == 0
10960 || section
->reloc_count
== 0)
10963 /* If this section is a link-once section that will be
10964 discarded, then don't create any stubs. */
10965 if (section
->output_section
== NULL
10966 || section
->output_section
->owner
!= info
->output_bfd
)
10969 /* Get the relocs. */
10971 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
10972 info
->keep_memory
);
10973 if (internal_relocs
== NULL
)
10974 goto error_ret_free_local
;
10976 /* Now examine each relocation. */
10977 irela
= internal_relocs
;
10978 irelaend
= irela
+ section
->reloc_count
;
10979 for (; irela
< irelaend
; irela
++)
10981 enum elf_ppc64_reloc_type r_type
;
10982 unsigned int r_indx
;
10983 enum ppc_stub_type stub_type
;
10984 struct ppc_stub_hash_entry
*stub_entry
;
10985 asection
*sym_sec
, *code_sec
;
10986 bfd_vma sym_value
, code_value
;
10987 bfd_vma destination
;
10988 bfd_boolean ok_dest
;
10989 struct ppc_link_hash_entry
*hash
;
10990 struct ppc_link_hash_entry
*fdh
;
10991 struct elf_link_hash_entry
*h
;
10992 Elf_Internal_Sym
*sym
;
10994 const asection
*id_sec
;
10995 struct _opd_sec_data
*opd
;
10996 struct plt_entry
*plt_ent
;
10998 r_type
= ELF64_R_TYPE (irela
->r_info
);
10999 r_indx
= ELF64_R_SYM (irela
->r_info
);
11001 if (r_type
>= R_PPC64_max
)
11003 bfd_set_error (bfd_error_bad_value
);
11004 goto error_ret_free_internal
;
11007 /* Only look for stubs on branch instructions. */
11008 if (r_type
!= R_PPC64_REL24
11009 && r_type
!= R_PPC64_REL14
11010 && r_type
!= R_PPC64_REL14_BRTAKEN
11011 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11014 /* Now determine the call target, its name, value,
11016 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
11017 r_indx
, input_bfd
))
11018 goto error_ret_free_internal
;
11019 hash
= (struct ppc_link_hash_entry
*) h
;
11026 sym_value
= sym
->st_value
;
11029 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
11030 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
11032 sym_value
= hash
->elf
.root
.u
.def
.value
;
11033 if (sym_sec
->output_section
!= NULL
)
11036 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
11037 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
11039 /* Recognise an old ABI func code entry sym, and
11040 use the func descriptor sym instead if it is
11042 if (hash
->elf
.root
.root
.string
[0] == '.'
11043 && (fdh
= lookup_fdh (hash
, htab
)) != NULL
)
11045 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
11046 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
11048 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
11049 sym_value
= fdh
->elf
.root
.u
.def
.value
;
11050 if (sym_sec
->output_section
!= NULL
)
11059 bfd_set_error (bfd_error_bad_value
);
11060 goto error_ret_free_internal
;
11066 sym_value
+= irela
->r_addend
;
11067 destination
= (sym_value
11068 + sym_sec
->output_offset
11069 + sym_sec
->output_section
->vma
);
11072 code_sec
= sym_sec
;
11073 code_value
= sym_value
;
11074 opd
= get_opd_info (sym_sec
);
11079 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11081 long adjust
= opd
->adjust
[sym_value
/ 8];
11084 code_value
+= adjust
;
11085 sym_value
+= adjust
;
11087 dest
= opd_entry_value (sym_sec
, sym_value
,
11088 &code_sec
, &code_value
);
11089 if (dest
!= (bfd_vma
) -1)
11091 destination
= dest
;
11094 /* Fixup old ABI sym to point at code
11096 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11097 hash
->elf
.root
.u
.def
.section
= code_sec
;
11098 hash
->elf
.root
.u
.def
.value
= code_value
;
11103 /* Determine what (if any) linker stub is needed. */
11105 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11106 &plt_ent
, destination
);
11108 if (stub_type
!= ppc_stub_plt_call
)
11110 /* Check whether we need a TOC adjusting stub.
11111 Since the linker pastes together pieces from
11112 different object files when creating the
11113 _init and _fini functions, it may be that a
11114 call to what looks like a local sym is in
11115 fact a call needing a TOC adjustment. */
11116 if (code_sec
!= NULL
11117 && code_sec
->output_section
!= NULL
11118 && (htab
->stub_group
[code_sec
->id
].toc_off
11119 != htab
->stub_group
[section
->id
].toc_off
)
11120 && (code_sec
->has_toc_reloc
11121 || code_sec
->makes_toc_func_call
))
11122 stub_type
= ppc_stub_long_branch_r2off
;
11125 if (stub_type
== ppc_stub_none
)
11128 /* __tls_get_addr calls might be eliminated. */
11129 if (stub_type
!= ppc_stub_plt_call
11131 && (hash
== htab
->tls_get_addr
11132 || hash
== htab
->tls_get_addr_fd
)
11133 && section
->has_tls_reloc
11134 && irela
!= internal_relocs
)
11136 /* Get tls info. */
11137 unsigned char *tls_mask
;
11139 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
11140 irela
- 1, input_bfd
))
11141 goto error_ret_free_internal
;
11142 if (*tls_mask
!= 0)
11146 /* Support for grouping stub sections. */
11147 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
11149 /* Get the name of this stub. */
11150 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
11152 goto error_ret_free_internal
;
11154 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
11155 stub_name
, FALSE
, FALSE
);
11156 if (stub_entry
!= NULL
)
11158 /* The proper stub has already been created. */
11163 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
11164 if (stub_entry
== NULL
)
11167 error_ret_free_internal
:
11168 if (elf_section_data (section
)->relocs
== NULL
)
11169 free (internal_relocs
);
11170 error_ret_free_local
:
11171 if (local_syms
!= NULL
11172 && (symtab_hdr
->contents
11173 != (unsigned char *) local_syms
))
11178 stub_entry
->stub_type
= stub_type
;
11179 if (stub_type
!= ppc_stub_plt_call
)
11181 stub_entry
->target_value
= code_value
;
11182 stub_entry
->target_section
= code_sec
;
11186 stub_entry
->target_value
= sym_value
;
11187 stub_entry
->target_section
= sym_sec
;
11189 stub_entry
->h
= hash
;
11190 stub_entry
->plt_ent
= plt_ent
;
11191 stub_entry
->addend
= irela
->r_addend
;
11193 if (stub_entry
->h
!= NULL
)
11194 htab
->stub_globals
+= 1;
11197 /* We're done with the internal relocs, free them. */
11198 if (elf_section_data (section
)->relocs
!= internal_relocs
)
11199 free (internal_relocs
);
11202 if (local_syms
!= NULL
11203 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
11205 if (!info
->keep_memory
)
11208 symtab_hdr
->contents
= (unsigned char *) local_syms
;
11212 /* We may have added some stubs. Find out the new size of the
11214 for (stub_sec
= htab
->stub_bfd
->sections
;
11216 stub_sec
= stub_sec
->next
)
11217 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11219 stub_sec
->rawsize
= stub_sec
->size
;
11220 stub_sec
->size
= 0;
11221 stub_sec
->reloc_count
= 0;
11222 stub_sec
->flags
&= ~SEC_RELOC
;
11225 htab
->brlt
->size
= 0;
11226 htab
->brlt
->reloc_count
= 0;
11227 htab
->brlt
->flags
&= ~SEC_RELOC
;
11228 if (htab
->relbrlt
!= NULL
)
11229 htab
->relbrlt
->size
= 0;
11231 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
11233 if (info
->emitrelocations
11234 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11236 htab
->glink
->reloc_count
= 1;
11237 htab
->glink
->flags
|= SEC_RELOC
;
11240 if (htab
->glink_eh_frame
!= NULL
11241 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
11242 && (htab
->glink_eh_frame
->flags
& SEC_EXCLUDE
) == 0)
11244 bfd_size_type size
= 0;
11246 for (stub_sec
= htab
->stub_bfd
->sections
;
11248 stub_sec
= stub_sec
->next
)
11249 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11251 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11254 size
+= sizeof (glink_eh_frame_cie
);
11255 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
11256 htab
->glink_eh_frame
->size
= size
;
11259 for (stub_sec
= htab
->stub_bfd
->sections
;
11261 stub_sec
= stub_sec
->next
)
11262 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11263 && stub_sec
->rawsize
!= stub_sec
->size
)
11266 /* Exit from this loop when no stubs have been added, and no stubs
11267 have changed size. */
11268 if (stub_sec
== NULL
11269 && (htab
->glink_eh_frame
== NULL
11270 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
11273 /* Ask the linker to do its stuff. */
11274 (*htab
->layout_sections_again
) ();
11277 maybe_strip_output (info
, htab
->brlt
);
11278 if (htab
->glink_eh_frame
!= NULL
)
11279 maybe_strip_output (info
, htab
->glink_eh_frame
);
11284 /* Called after we have determined section placement. If sections
11285 move, we'll be called again. Provide a value for TOCstart. */
11288 ppc64_elf_toc (bfd
*obfd
)
11293 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
11294 order. The TOC starts where the first of these sections starts. */
11295 s
= bfd_get_section_by_name (obfd
, ".got");
11296 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11297 s
= bfd_get_section_by_name (obfd
, ".toc");
11298 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11299 s
= bfd_get_section_by_name (obfd
, ".tocbss");
11300 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11301 s
= bfd_get_section_by_name (obfd
, ".plt");
11302 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11304 /* This may happen for
11305 o references to TOC base (SYM@toc / TOC[tc0]) without a
11307 o bad linker script
11308 o --gc-sections and empty TOC sections
11310 FIXME: Warn user? */
11312 /* Look for a likely section. We probably won't even be
11314 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11315 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
11317 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11320 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11321 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
11322 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11325 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11326 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
11330 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11331 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
11337 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
11342 /* Build all the stubs associated with the current output file.
11343 The stubs are kept in a hash table attached to the main linker
11344 hash table. This function is called via gldelf64ppc_finish. */
11347 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
11348 struct bfd_link_info
*info
,
11351 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11352 asection
*stub_sec
;
11354 int stub_sec_count
= 0;
11359 htab
->emit_stub_syms
= emit_stub_syms
;
11361 /* Allocate memory to hold the linker stubs. */
11362 for (stub_sec
= htab
->stub_bfd
->sections
;
11364 stub_sec
= stub_sec
->next
)
11365 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11366 && stub_sec
->size
!= 0)
11368 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
11369 if (stub_sec
->contents
== NULL
)
11371 /* We want to check that built size is the same as calculated
11372 size. rawsize is a convenient location to use. */
11373 stub_sec
->rawsize
= stub_sec
->size
;
11374 stub_sec
->size
= 0;
11377 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11382 /* Build the .glink plt call stub. */
11383 if (htab
->emit_stub_syms
)
11385 struct elf_link_hash_entry
*h
;
11386 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
11387 TRUE
, FALSE
, FALSE
);
11390 if (h
->root
.type
== bfd_link_hash_new
)
11392 h
->root
.type
= bfd_link_hash_defined
;
11393 h
->root
.u
.def
.section
= htab
->glink
;
11394 h
->root
.u
.def
.value
= 8;
11395 h
->ref_regular
= 1;
11396 h
->def_regular
= 1;
11397 h
->ref_regular_nonweak
= 1;
11398 h
->forced_local
= 1;
11402 plt0
= htab
->plt
->output_section
->vma
+ htab
->plt
->output_offset
- 16;
11403 if (info
->emitrelocations
)
11405 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
11408 r
->r_offset
= (htab
->glink
->output_offset
11409 + htab
->glink
->output_section
->vma
);
11410 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
11411 r
->r_addend
= plt0
;
11413 p
= htab
->glink
->contents
;
11414 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
11415 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
11417 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
11419 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
11421 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
11423 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
11425 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
11427 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
11429 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
11431 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
11433 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
11435 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
11437 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
11439 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
11441 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
11445 /* Build the .glink lazy link call stubs. */
11447 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
11451 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
11456 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
11458 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
11461 bfd_put_32 (htab
->glink
->owner
,
11462 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
11466 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
11469 if (htab
->brlt
->size
!= 0)
11471 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
11473 if (htab
->brlt
->contents
== NULL
)
11476 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
11478 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
11479 htab
->relbrlt
->size
);
11480 if (htab
->relbrlt
->contents
== NULL
)
11484 if (htab
->glink_eh_frame
!= NULL
11485 && htab
->glink_eh_frame
->size
!= 0)
11489 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
11492 htab
->glink_eh_frame
->contents
= p
;
11494 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
11496 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
11497 /* CIE length (rewrite in case little-endian). */
11498 bfd_put_32 (htab
->elf
.dynobj
, sizeof (glink_eh_frame_cie
) - 4, p
);
11499 p
+= sizeof (glink_eh_frame_cie
);
11501 for (stub_sec
= htab
->stub_bfd
->sections
;
11503 stub_sec
= stub_sec
->next
)
11504 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11507 bfd_put_32 (htab
->elf
.dynobj
, 16, p
);
11510 val
= p
- htab
->glink_eh_frame
->contents
;
11511 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11513 /* Offset to stub section. */
11514 val
= (stub_sec
->output_section
->vma
11515 + stub_sec
->output_offset
);
11516 val
-= (htab
->glink_eh_frame
->output_section
->vma
11517 + htab
->glink_eh_frame
->output_offset
);
11518 val
-= p
- htab
->glink_eh_frame
->contents
;
11519 if (val
+ 0x80000000 > 0xffffffff)
11521 info
->callbacks
->einfo
11522 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
11526 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11528 /* stub section size. */
11529 bfd_put_32 (htab
->elf
.dynobj
, stub_sec
->rawsize
, p
);
11531 /* Augmentation. */
11536 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11539 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
11542 val
= p
- htab
->glink_eh_frame
->contents
;
11543 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11545 /* Offset to .glink. */
11546 val
= (htab
->glink
->output_section
->vma
11547 + htab
->glink
->output_offset
11549 val
-= (htab
->glink_eh_frame
->output_section
->vma
11550 + htab
->glink_eh_frame
->output_offset
);
11551 val
-= p
- htab
->glink_eh_frame
->contents
;
11552 if (val
+ 0x80000000 > 0xffffffff)
11554 info
->callbacks
->einfo
11555 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
11556 htab
->glink
->name
);
11559 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
11562 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->rawsize
- 8, p
);
11564 /* Augmentation. */
11567 *p
++ = DW_CFA_advance_loc
+ 1;
11568 *p
++ = DW_CFA_register
;
11571 *p
++ = DW_CFA_advance_loc
+ 4;
11572 *p
++ = DW_CFA_restore_extended
;
11575 htab
->glink_eh_frame
->size
= p
- htab
->glink_eh_frame
->contents
;
11578 /* Build the stubs as directed by the stub hash table. */
11579 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
11581 if (htab
->relbrlt
!= NULL
)
11582 htab
->relbrlt
->reloc_count
= 0;
11584 for (stub_sec
= htab
->stub_bfd
->sections
;
11586 stub_sec
= stub_sec
->next
)
11587 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11589 stub_sec_count
+= 1;
11590 if (stub_sec
->rawsize
!= stub_sec
->size
)
11594 if (stub_sec
!= NULL
11595 || htab
->glink
->rawsize
!= htab
->glink
->size
11596 || (htab
->glink_eh_frame
!= NULL
11597 && htab
->glink_eh_frame
->rawsize
!= htab
->glink_eh_frame
->size
))
11599 htab
->stub_error
= TRUE
;
11600 info
->callbacks
->einfo (_("%P: stubs don't match calculated size\n"));
11603 if (htab
->stub_error
)
11608 *stats
= bfd_malloc (500);
11609 if (*stats
== NULL
)
11612 sprintf (*stats
, _("linker stubs in %u group%s\n"
11614 " toc adjust %lu\n"
11615 " long branch %lu\n"
11616 " long toc adj %lu\n"
11619 stub_sec_count
== 1 ? "" : "s",
11620 htab
->stub_count
[ppc_stub_long_branch
- 1],
11621 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
11622 htab
->stub_count
[ppc_stub_plt_branch
- 1],
11623 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
11624 htab
->stub_count
[ppc_stub_plt_call
- 1]);
11629 /* This function undoes the changes made by add_symbol_adjust. */
11632 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11634 struct ppc_link_hash_entry
*eh
;
11636 if (h
->root
.type
== bfd_link_hash_indirect
)
11639 eh
= (struct ppc_link_hash_entry
*) h
;
11640 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
11643 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
11648 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
11650 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11653 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
11656 /* What to do when ld finds relocations against symbols defined in
11657 discarded sections. */
11659 static unsigned int
11660 ppc64_elf_action_discarded (asection
*sec
)
11662 if (strcmp (".opd", sec
->name
) == 0)
11665 if (strcmp (".toc", sec
->name
) == 0)
11668 if (strcmp (".toc1", sec
->name
) == 0)
11671 return _bfd_elf_default_action_discarded (sec
);
11674 /* REL points to a low-part reloc on a largetoc instruction sequence.
11675 Find the matching high-part reloc instruction and verify that it
11676 is addis REG,x,imm. If so, set *REG to x and return a pointer to
11677 the high-part reloc. */
11679 static const Elf_Internal_Rela
*
11680 ha_reloc_match (const Elf_Internal_Rela
*relocs
,
11681 const Elf_Internal_Rela
*rel
,
11683 bfd_boolean match_addend
,
11684 const bfd
*input_bfd
,
11685 const bfd_byte
*contents
)
11687 enum elf_ppc64_reloc_type r_type
, r_type_ha
;
11688 bfd_vma r_info_ha
, r_addend
;
11690 r_type
= ELF64_R_TYPE (rel
->r_info
);
11693 case R_PPC64_GOT_TLSLD16_LO
:
11694 case R_PPC64_GOT_TLSGD16_LO
:
11695 case R_PPC64_GOT_TPREL16_LO_DS
:
11696 case R_PPC64_GOT_DTPREL16_LO_DS
:
11697 case R_PPC64_GOT16_LO
:
11698 case R_PPC64_TOC16_LO
:
11699 r_type_ha
= r_type
+ 2;
11701 case R_PPC64_GOT16_LO_DS
:
11702 r_type_ha
= R_PPC64_GOT16_HA
;
11704 case R_PPC64_TOC16_LO_DS
:
11705 r_type_ha
= R_PPC64_TOC16_HA
;
11710 r_info_ha
= ELF64_R_INFO (ELF64_R_SYM (rel
->r_info
), r_type_ha
);
11711 r_addend
= rel
->r_addend
;
11713 while (--rel
>= relocs
)
11714 if (rel
->r_info
== r_info_ha
11716 || rel
->r_addend
== r_addend
))
11718 const bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
11719 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
11720 if ((insn
& (0x3f << 26)) == (15u << 26) /* addis rt,x,imm */
11721 && (insn
& (0x1f << 21)) == (*reg
<< 21))
11723 *reg
= (insn
>> 16) & 0x1f;
11731 /* The RELOCATE_SECTION function is called by the ELF backend linker
11732 to handle the relocations for a section.
11734 The relocs are always passed as Rela structures; if the section
11735 actually uses Rel structures, the r_addend field will always be
11738 This function is responsible for adjust the section contents as
11739 necessary, and (if using Rela relocs and generating a
11740 relocatable output file) adjusting the reloc addend as
11743 This function does not have to worry about setting the reloc
11744 address or the reloc symbol index.
11746 LOCAL_SYMS is a pointer to the swapped in local symbols.
11748 LOCAL_SECTIONS is an array giving the section in the input file
11749 corresponding to the st_shndx field of each local symbol.
11751 The global hash table entry for the global symbols can be found
11752 via elf_sym_hashes (input_bfd).
11754 When generating relocatable output, this function must handle
11755 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
11756 going to be the section symbol corresponding to the output
11757 section, which means that the addend must be adjusted
11761 ppc64_elf_relocate_section (bfd
*output_bfd
,
11762 struct bfd_link_info
*info
,
11764 asection
*input_section
,
11765 bfd_byte
*contents
,
11766 Elf_Internal_Rela
*relocs
,
11767 Elf_Internal_Sym
*local_syms
,
11768 asection
**local_sections
)
11770 struct ppc_link_hash_table
*htab
;
11771 Elf_Internal_Shdr
*symtab_hdr
;
11772 struct elf_link_hash_entry
**sym_hashes
;
11773 Elf_Internal_Rela
*rel
;
11774 Elf_Internal_Rela
*relend
;
11775 Elf_Internal_Rela outrel
;
11777 struct got_entry
**local_got_ents
;
11778 unsigned char *ha_opt
;
11780 bfd_boolean no_ha_opt
;
11781 bfd_boolean ret
= TRUE
;
11782 bfd_boolean is_opd
;
11783 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
11784 bfd_boolean is_power4
= FALSE
;
11785 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
11787 /* Initialize howto table if needed. */
11788 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
11791 htab
= ppc_hash_table (info
);
11795 /* Don't relocate stub sections. */
11796 if (input_section
->owner
== htab
->stub_bfd
)
11799 BFD_ASSERT (is_ppc64_elf (input_bfd
));
11801 local_got_ents
= elf_local_got_ents (input_bfd
);
11802 TOCstart
= elf_gp (output_bfd
);
11803 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11804 sym_hashes
= elf_sym_hashes (input_bfd
);
11805 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
11810 relend
= relocs
+ input_section
->reloc_count
;
11811 for (; rel
< relend
; rel
++)
11813 enum elf_ppc64_reloc_type r_type
;
11814 bfd_vma addend
, orig_addend
;
11815 bfd_reloc_status_type r
;
11816 Elf_Internal_Sym
*sym
;
11818 struct elf_link_hash_entry
*h_elf
;
11819 struct ppc_link_hash_entry
*h
;
11820 struct ppc_link_hash_entry
*fdh
;
11821 const char *sym_name
;
11822 unsigned long r_symndx
, toc_symndx
;
11823 bfd_vma toc_addend
;
11824 unsigned char tls_mask
, tls_gd
, tls_type
;
11825 unsigned char sym_type
;
11826 bfd_vma relocation
;
11827 bfd_boolean unresolved_reloc
;
11828 bfd_boolean warned
;
11831 struct ppc_stub_hash_entry
*stub_entry
;
11832 bfd_vma max_br_offset
;
11835 r_type
= ELF64_R_TYPE (rel
->r_info
);
11836 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11838 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
11839 symbol of the previous ADDR64 reloc. The symbol gives us the
11840 proper TOC base to use. */
11841 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
11843 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
11845 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
11851 unresolved_reloc
= FALSE
;
11853 orig_addend
= rel
->r_addend
;
11855 if (r_symndx
< symtab_hdr
->sh_info
)
11857 /* It's a local symbol. */
11858 struct _opd_sec_data
*opd
;
11860 sym
= local_syms
+ r_symndx
;
11861 sec
= local_sections
[r_symndx
];
11862 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
11863 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
11864 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
11865 opd
= get_opd_info (sec
);
11866 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
11868 long adjust
= opd
->adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
11873 /* If this is a relocation against the opd section sym
11874 and we have edited .opd, adjust the reloc addend so
11875 that ld -r and ld --emit-relocs output is correct.
11876 If it is a reloc against some other .opd symbol,
11877 then the symbol value will be adjusted later. */
11878 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
11879 rel
->r_addend
+= adjust
;
11881 relocation
+= adjust
;
11887 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
11888 r_symndx
, symtab_hdr
, sym_hashes
,
11889 h_elf
, sec
, relocation
,
11890 unresolved_reloc
, warned
);
11891 sym_name
= h_elf
->root
.root
.string
;
11892 sym_type
= h_elf
->type
;
11894 h
= (struct ppc_link_hash_entry
*) h_elf
;
11896 if (sec
!= NULL
&& elf_discarded_section (sec
))
11897 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
11899 ppc64_elf_howto_table
[r_type
],
11902 if (info
->relocatable
)
11905 /* TLS optimizations. Replace instruction sequences and relocs
11906 based on information we collected in tls_optimize. We edit
11907 RELOCS so that --emit-relocs will output something sensible
11908 for the final instruction stream. */
11913 tls_mask
= h
->tls_mask
;
11914 else if (local_got_ents
!= NULL
)
11916 struct plt_entry
**local_plt
= (struct plt_entry
**)
11917 (local_got_ents
+ symtab_hdr
->sh_info
);
11918 unsigned char *lgot_masks
= (unsigned char *)
11919 (local_plt
+ symtab_hdr
->sh_info
);
11920 tls_mask
= lgot_masks
[r_symndx
];
11923 && (r_type
== R_PPC64_TLS
11924 || r_type
== R_PPC64_TLSGD
11925 || r_type
== R_PPC64_TLSLD
))
11927 /* Check for toc tls entries. */
11928 unsigned char *toc_tls
;
11930 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11931 &local_syms
, rel
, input_bfd
))
11935 tls_mask
= *toc_tls
;
11938 /* Check that tls relocs are used with tls syms, and non-tls
11939 relocs are used with non-tls syms. */
11940 if (r_symndx
!= STN_UNDEF
11941 && r_type
!= R_PPC64_NONE
11943 || h
->elf
.root
.type
== bfd_link_hash_defined
11944 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
11945 && (IS_PPC64_TLS_RELOC (r_type
)
11946 != (sym_type
== STT_TLS
11947 || (sym_type
== STT_SECTION
11948 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
11951 && (r_type
== R_PPC64_TLS
11952 || r_type
== R_PPC64_TLSGD
11953 || r_type
== R_PPC64_TLSLD
))
11954 /* R_PPC64_TLS is OK against a symbol in the TOC. */
11957 info
->callbacks
->einfo
11958 (!IS_PPC64_TLS_RELOC (r_type
)
11959 ? _("%P: %H: %s used with TLS symbol %s\n")
11960 : _("%P: %H: %s used with non-TLS symbol %s\n"),
11961 input_bfd
, input_section
, rel
->r_offset
,
11962 ppc64_elf_howto_table
[r_type
]->name
,
11966 /* Ensure reloc mapping code below stays sane. */
11967 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
11968 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
11969 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
11970 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
11971 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
11972 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
11973 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
11974 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
11975 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
11976 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
11984 case R_PPC64_LO_DS_OPT
:
11985 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11986 if ((insn
& (0x3f << 26)) != 58u << 26)
11988 insn
+= (14u << 26) - (58u << 26);
11989 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11990 r_type
= R_PPC64_TOC16_LO
;
11991 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11994 case R_PPC64_TOC16
:
11995 case R_PPC64_TOC16_LO
:
11996 case R_PPC64_TOC16_DS
:
11997 case R_PPC64_TOC16_LO_DS
:
11999 /* Check for toc tls entries. */
12000 unsigned char *toc_tls
;
12003 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
12004 &local_syms
, rel
, input_bfd
);
12010 tls_mask
= *toc_tls
;
12011 if (r_type
== R_PPC64_TOC16_DS
12012 || r_type
== R_PPC64_TOC16_LO_DS
)
12015 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
12020 /* If we found a GD reloc pair, then we might be
12021 doing a GD->IE transition. */
12024 tls_gd
= TLS_TPRELGD
;
12025 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12028 else if (retval
== 3)
12030 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12038 case R_PPC64_GOT_TPREL16_HI
:
12039 case R_PPC64_GOT_TPREL16_HA
:
12041 && (tls_mask
& TLS_TPREL
) == 0)
12043 rel
->r_offset
-= d_offset
;
12044 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12045 r_type
= R_PPC64_NONE
;
12046 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12050 case R_PPC64_GOT_TPREL16_DS
:
12051 case R_PPC64_GOT_TPREL16_LO_DS
:
12053 && (tls_mask
& TLS_TPREL
) == 0)
12056 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
12058 insn
|= 0x3c0d0000; /* addis 0,13,0 */
12059 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
12060 r_type
= R_PPC64_TPREL16_HA
;
12061 if (toc_symndx
!= 0)
12063 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
12064 rel
->r_addend
= toc_addend
;
12065 /* We changed the symbol. Start over in order to
12066 get h, sym, sec etc. right. */
12071 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12077 && (tls_mask
& TLS_TPREL
) == 0)
12079 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
12080 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
12083 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12084 /* Was PPC64_TLS which sits on insn boundary, now
12085 PPC64_TPREL16_LO which is at low-order half-word. */
12086 rel
->r_offset
+= d_offset
;
12087 r_type
= R_PPC64_TPREL16_LO
;
12088 if (toc_symndx
!= 0)
12090 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
12091 rel
->r_addend
= toc_addend
;
12092 /* We changed the symbol. Start over in order to
12093 get h, sym, sec etc. right. */
12098 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12102 case R_PPC64_GOT_TLSGD16_HI
:
12103 case R_PPC64_GOT_TLSGD16_HA
:
12104 tls_gd
= TLS_TPRELGD
;
12105 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12109 case R_PPC64_GOT_TLSLD16_HI
:
12110 case R_PPC64_GOT_TLSLD16_HA
:
12111 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12114 if ((tls_mask
& tls_gd
) != 0)
12115 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
12116 + R_PPC64_GOT_TPREL16_DS
);
12119 rel
->r_offset
-= d_offset
;
12120 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12121 r_type
= R_PPC64_NONE
;
12123 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12127 case R_PPC64_GOT_TLSGD16
:
12128 case R_PPC64_GOT_TLSGD16_LO
:
12129 tls_gd
= TLS_TPRELGD
;
12130 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12134 case R_PPC64_GOT_TLSLD16
:
12135 case R_PPC64_GOT_TLSLD16_LO
:
12136 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12138 unsigned int insn1
, insn2
, insn3
;
12142 offset
= (bfd_vma
) -1;
12143 /* If not using the newer R_PPC64_TLSGD/LD to mark
12144 __tls_get_addr calls, we must trust that the call
12145 stays with its arg setup insns, ie. that the next
12146 reloc is the __tls_get_addr call associated with
12147 the current reloc. Edit both insns. */
12148 if (input_section
->has_tls_get_addr_call
12149 && rel
+ 1 < relend
12150 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
12151 htab
->tls_get_addr
,
12152 htab
->tls_get_addr_fd
))
12153 offset
= rel
[1].r_offset
;
12154 if ((tls_mask
& tls_gd
) != 0)
12157 insn1
= bfd_get_32 (output_bfd
,
12158 contents
+ rel
->r_offset
- d_offset
);
12159 insn1
&= (1 << 26) - (1 << 2);
12160 insn1
|= 58 << 26; /* ld */
12161 insn2
= 0x7c636a14; /* add 3,3,13 */
12162 if (offset
!= (bfd_vma
) -1)
12163 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12164 if ((tls_mask
& TLS_EXPLICIT
) == 0)
12165 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
12166 + R_PPC64_GOT_TPREL16_DS
);
12168 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
12169 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12174 insn1
= 0x3c6d0000; /* addis 3,13,0 */
12175 insn2
= 0x38630000; /* addi 3,3,0 */
12178 /* Was an LD reloc. */
12180 sec
= local_sections
[toc_symndx
];
12182 r_symndx
< symtab_hdr
->sh_info
;
12184 if (local_sections
[r_symndx
] == sec
)
12186 if (r_symndx
>= symtab_hdr
->sh_info
)
12187 r_symndx
= STN_UNDEF
;
12188 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12189 if (r_symndx
!= STN_UNDEF
)
12190 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12191 + sec
->output_offset
12192 + sec
->output_section
->vma
);
12194 else if (toc_symndx
!= 0)
12196 r_symndx
= toc_symndx
;
12197 rel
->r_addend
= toc_addend
;
12199 r_type
= R_PPC64_TPREL16_HA
;
12200 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12201 if (offset
!= (bfd_vma
) -1)
12203 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
12204 R_PPC64_TPREL16_LO
);
12205 rel
[1].r_offset
= offset
+ d_offset
;
12206 rel
[1].r_addend
= rel
->r_addend
;
12209 bfd_put_32 (output_bfd
, insn1
,
12210 contents
+ rel
->r_offset
- d_offset
);
12211 if (offset
!= (bfd_vma
) -1)
12213 insn3
= bfd_get_32 (output_bfd
,
12214 contents
+ offset
+ 4);
12216 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12218 rel
[1].r_offset
+= 4;
12219 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12222 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12224 if ((tls_mask
& tls_gd
) == 0
12225 && (tls_gd
== 0 || toc_symndx
!= 0))
12227 /* We changed the symbol. Start over in order
12228 to get h, sym, sec etc. right. */
12235 case R_PPC64_TLSGD
:
12236 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12238 unsigned int insn2
, insn3
;
12239 bfd_vma offset
= rel
->r_offset
;
12241 if ((tls_mask
& TLS_TPRELGD
) != 0)
12244 r_type
= R_PPC64_NONE
;
12245 insn2
= 0x7c636a14; /* add 3,3,13 */
12250 if (toc_symndx
!= 0)
12252 r_symndx
= toc_symndx
;
12253 rel
->r_addend
= toc_addend
;
12255 r_type
= R_PPC64_TPREL16_LO
;
12256 rel
->r_offset
= offset
+ d_offset
;
12257 insn2
= 0x38630000; /* addi 3,3,0 */
12259 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12260 /* Zap the reloc on the _tls_get_addr call too. */
12261 BFD_ASSERT (offset
== rel
[1].r_offset
);
12262 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12263 insn3
= bfd_get_32 (output_bfd
,
12264 contents
+ offset
+ 4);
12266 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12268 rel
->r_offset
+= 4;
12269 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12272 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12273 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
12281 case R_PPC64_TLSLD
:
12282 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12284 unsigned int insn2
, insn3
;
12285 bfd_vma offset
= rel
->r_offset
;
12288 sec
= local_sections
[toc_symndx
];
12290 r_symndx
< symtab_hdr
->sh_info
;
12292 if (local_sections
[r_symndx
] == sec
)
12294 if (r_symndx
>= symtab_hdr
->sh_info
)
12295 r_symndx
= STN_UNDEF
;
12296 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12297 if (r_symndx
!= STN_UNDEF
)
12298 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12299 + sec
->output_offset
12300 + sec
->output_section
->vma
);
12302 r_type
= R_PPC64_TPREL16_LO
;
12303 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12304 rel
->r_offset
= offset
+ d_offset
;
12305 /* Zap the reloc on the _tls_get_addr call too. */
12306 BFD_ASSERT (offset
== rel
[1].r_offset
);
12307 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12308 insn2
= 0x38630000; /* addi 3,3,0 */
12309 insn3
= bfd_get_32 (output_bfd
,
12310 contents
+ offset
+ 4);
12312 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12314 rel
->r_offset
+= 4;
12315 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12318 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12324 case R_PPC64_DTPMOD64
:
12325 if (rel
+ 1 < relend
12326 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
12327 && rel
[1].r_offset
== rel
->r_offset
+ 8)
12329 if ((tls_mask
& TLS_GD
) == 0)
12331 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
12332 if ((tls_mask
& TLS_TPRELGD
) != 0)
12333 r_type
= R_PPC64_TPREL64
;
12336 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12337 r_type
= R_PPC64_NONE
;
12339 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12344 if ((tls_mask
& TLS_LD
) == 0)
12346 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12347 r_type
= R_PPC64_NONE
;
12348 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12353 case R_PPC64_TPREL64
:
12354 if ((tls_mask
& TLS_TPREL
) == 0)
12356 r_type
= R_PPC64_NONE
;
12357 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12362 /* Handle other relocations that tweak non-addend part of insn. */
12364 max_br_offset
= 1 << 25;
12365 addend
= rel
->r_addend
;
12371 /* Branch taken prediction relocations. */
12372 case R_PPC64_ADDR14_BRTAKEN
:
12373 case R_PPC64_REL14_BRTAKEN
:
12374 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
12377 /* Branch not taken prediction relocations. */
12378 case R_PPC64_ADDR14_BRNTAKEN
:
12379 case R_PPC64_REL14_BRNTAKEN
:
12380 insn
|= bfd_get_32 (output_bfd
,
12381 contents
+ rel
->r_offset
) & ~(0x01 << 21);
12384 case R_PPC64_REL14
:
12385 max_br_offset
= 1 << 15;
12388 case R_PPC64_REL24
:
12389 /* Calls to functions with a different TOC, such as calls to
12390 shared objects, need to alter the TOC pointer. This is
12391 done using a linkage stub. A REL24 branching to these
12392 linkage stubs needs to be followed by a nop, as the nop
12393 will be replaced with an instruction to restore the TOC
12398 && h
->oh
->is_func_descriptor
)
12399 fdh
= ppc_follow_link (h
->oh
);
12400 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, rel
, htab
);
12401 if (stub_entry
!= NULL
12402 && (stub_entry
->stub_type
== ppc_stub_plt_call
12403 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
12404 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
12406 bfd_boolean can_plt_call
= FALSE
;
12408 if (rel
->r_offset
+ 8 <= input_section
->size
)
12411 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
12413 || nop
== CROR_151515
|| nop
== CROR_313131
)
12416 && (h
== htab
->tls_get_addr_fd
12417 || h
== htab
->tls_get_addr
)
12418 && !htab
->no_tls_get_addr_opt
)
12420 /* Special stub used, leave nop alone. */
12423 bfd_put_32 (input_bfd
, LD_R2_40R1
,
12424 contents
+ rel
->r_offset
+ 4);
12425 can_plt_call
= TRUE
;
12431 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
12433 /* If this is a plain branch rather than a branch
12434 and link, don't require a nop. However, don't
12435 allow tail calls in a shared library as they
12436 will result in r2 being corrupted. */
12438 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
12439 if (info
->executable
&& (br
& 1) == 0)
12440 can_plt_call
= TRUE
;
12445 && strcmp (h
->elf
.root
.root
.string
,
12446 ".__libc_start_main") == 0)
12448 /* Allow crt1 branch to go via a toc adjusting stub. */
12449 can_plt_call
= TRUE
;
12453 if (strcmp (input_section
->output_section
->name
,
12455 || strcmp (input_section
->output_section
->name
,
12457 info
->callbacks
->einfo
12458 (_("%P: %H: automatic multiple TOCs "
12459 "not supported using your crt files; "
12460 "recompile with -mminimal-toc or upgrade gcc\n"),
12461 input_bfd
, input_section
, rel
->r_offset
);
12463 info
->callbacks
->einfo
12464 (_("%P: %H: sibling call optimization to `%s' "
12465 "does not allow automatic multiple TOCs; "
12466 "recompile with -mminimal-toc or "
12467 "-fno-optimize-sibling-calls, "
12468 "or make `%s' extern\n"),
12469 input_bfd
, input_section
, rel
->r_offset
,
12472 bfd_set_error (bfd_error_bad_value
);
12478 && stub_entry
->stub_type
== ppc_stub_plt_call
)
12479 unresolved_reloc
= FALSE
;
12482 if ((stub_entry
== NULL
12483 || stub_entry
->stub_type
== ppc_stub_long_branch
12484 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12485 && get_opd_info (sec
) != NULL
)
12487 /* The branch destination is the value of the opd entry. */
12488 bfd_vma off
= (relocation
+ addend
12489 - sec
->output_section
->vma
12490 - sec
->output_offset
);
12491 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
12492 if (dest
!= (bfd_vma
) -1)
12499 /* If the branch is out of reach we ought to have a long
12501 from
= (rel
->r_offset
12502 + input_section
->output_offset
12503 + input_section
->output_section
->vma
);
12505 if (stub_entry
!= NULL
12506 && (stub_entry
->stub_type
== ppc_stub_long_branch
12507 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12508 && (r_type
== R_PPC64_ADDR14_BRTAKEN
12509 || r_type
== R_PPC64_ADDR14_BRNTAKEN
12510 || (relocation
+ addend
- from
+ max_br_offset
12511 < 2 * max_br_offset
)))
12512 /* Don't use the stub if this branch is in range. */
12515 if (stub_entry
!= NULL
)
12517 /* Munge up the value and addend so that we call the stub
12518 rather than the procedure directly. */
12519 relocation
= (stub_entry
->stub_offset
12520 + stub_entry
->stub_sec
->output_offset
12521 + stub_entry
->stub_sec
->output_section
->vma
);
12529 /* Set 'a' bit. This is 0b00010 in BO field for branch
12530 on CR(BI) insns (BO == 001at or 011at), and 0b01000
12531 for branch on CTR insns (BO == 1a00t or 1a01t). */
12532 if ((insn
& (0x14 << 21)) == (0x04 << 21))
12533 insn
|= 0x02 << 21;
12534 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
12535 insn
|= 0x08 << 21;
12541 /* Invert 'y' bit if not the default. */
12542 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
12543 insn
^= 0x01 << 21;
12546 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12549 /* NOP out calls to undefined weak functions.
12550 We can thus call a weak function without first
12551 checking whether the function is defined. */
12553 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12554 && h
->elf
.dynindx
== -1
12555 && r_type
== R_PPC64_REL24
12559 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12565 /* Set `addend'. */
12570 info
->callbacks
->einfo
12571 (_("%P: %B: unknown relocation type %d for symbol %s\n"),
12572 input_bfd
, (int) r_type
, sym_name
);
12574 bfd_set_error (bfd_error_bad_value
);
12580 case R_PPC64_TLSGD
:
12581 case R_PPC64_TLSLD
:
12582 case R_PPC64_GNU_VTINHERIT
:
12583 case R_PPC64_GNU_VTENTRY
:
12586 /* GOT16 relocations. Like an ADDR16 using the symbol's
12587 address in the GOT as relocation value instead of the
12588 symbol's value itself. Also, create a GOT entry for the
12589 symbol and put the symbol value there. */
12590 case R_PPC64_GOT_TLSGD16
:
12591 case R_PPC64_GOT_TLSGD16_LO
:
12592 case R_PPC64_GOT_TLSGD16_HI
:
12593 case R_PPC64_GOT_TLSGD16_HA
:
12594 tls_type
= TLS_TLS
| TLS_GD
;
12597 case R_PPC64_GOT_TLSLD16
:
12598 case R_PPC64_GOT_TLSLD16_LO
:
12599 case R_PPC64_GOT_TLSLD16_HI
:
12600 case R_PPC64_GOT_TLSLD16_HA
:
12601 tls_type
= TLS_TLS
| TLS_LD
;
12604 case R_PPC64_GOT_TPREL16_DS
:
12605 case R_PPC64_GOT_TPREL16_LO_DS
:
12606 case R_PPC64_GOT_TPREL16_HI
:
12607 case R_PPC64_GOT_TPREL16_HA
:
12608 tls_type
= TLS_TLS
| TLS_TPREL
;
12611 case R_PPC64_GOT_DTPREL16_DS
:
12612 case R_PPC64_GOT_DTPREL16_LO_DS
:
12613 case R_PPC64_GOT_DTPREL16_HI
:
12614 case R_PPC64_GOT_DTPREL16_HA
:
12615 tls_type
= TLS_TLS
| TLS_DTPREL
;
12618 case R_PPC64_GOT16
:
12619 case R_PPC64_GOT16_LO
:
12620 case R_PPC64_GOT16_HI
:
12621 case R_PPC64_GOT16_HA
:
12622 case R_PPC64_GOT16_DS
:
12623 case R_PPC64_GOT16_LO_DS
:
12626 /* Relocation is to the entry for this symbol in the global
12631 unsigned long indx
= 0;
12632 struct got_entry
*ent
;
12634 if (tls_type
== (TLS_TLS
| TLS_LD
)
12636 || !h
->elf
.def_dynamic
))
12637 ent
= ppc64_tlsld_got (input_bfd
);
12643 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
12644 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
12647 && SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12648 /* This is actually a static link, or it is a
12649 -Bsymbolic link and the symbol is defined
12650 locally, or the symbol was forced to be local
12651 because of a version file. */
12655 indx
= h
->elf
.dynindx
;
12656 unresolved_reloc
= FALSE
;
12658 ent
= h
->elf
.got
.glist
;
12662 if (local_got_ents
== NULL
)
12664 ent
= local_got_ents
[r_symndx
];
12667 for (; ent
!= NULL
; ent
= ent
->next
)
12668 if (ent
->addend
== orig_addend
12669 && ent
->owner
== input_bfd
12670 && ent
->tls_type
== tls_type
)
12676 if (ent
->is_indirect
)
12677 ent
= ent
->got
.ent
;
12678 offp
= &ent
->got
.offset
;
12679 got
= ppc64_elf_tdata (ent
->owner
)->got
;
12683 /* The offset must always be a multiple of 8. We use the
12684 least significant bit to record whether we have already
12685 processed this entry. */
12687 if ((off
& 1) != 0)
12691 /* Generate relocs for the dynamic linker, except in
12692 the case of TLSLD where we'll use one entry per
12700 ? h
->elf
.type
== STT_GNU_IFUNC
12701 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
12702 if ((info
->shared
|| indx
!= 0)
12704 || (tls_type
== (TLS_TLS
| TLS_LD
)
12705 && !h
->elf
.def_dynamic
)
12706 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12707 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
12708 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
12710 relgot
= htab
->reliplt
;
12711 if (relgot
!= NULL
)
12713 outrel
.r_offset
= (got
->output_section
->vma
12714 + got
->output_offset
12716 outrel
.r_addend
= addend
;
12717 if (tls_type
& (TLS_LD
| TLS_GD
))
12719 outrel
.r_addend
= 0;
12720 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
12721 if (tls_type
== (TLS_TLS
| TLS_GD
))
12723 loc
= relgot
->contents
;
12724 loc
+= (relgot
->reloc_count
++
12725 * sizeof (Elf64_External_Rela
));
12726 bfd_elf64_swap_reloca_out (output_bfd
,
12728 outrel
.r_offset
+= 8;
12729 outrel
.r_addend
= addend
;
12731 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12734 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
12735 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12736 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12737 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
12738 else if (indx
!= 0)
12739 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
12743 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12745 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12747 /* Write the .got section contents for the sake
12749 loc
= got
->contents
+ off
;
12750 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
12754 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
12756 outrel
.r_addend
+= relocation
;
12757 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
12758 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
12760 loc
= relgot
->contents
;
12761 loc
+= (relgot
->reloc_count
++
12762 * sizeof (Elf64_External_Rela
));
12763 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
12766 /* Init the .got section contents here if we're not
12767 emitting a reloc. */
12770 relocation
+= addend
;
12771 if (tls_type
== (TLS_TLS
| TLS_LD
))
12773 else if (tls_type
!= 0)
12775 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12776 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12777 relocation
+= DTP_OFFSET
- TP_OFFSET
;
12779 if (tls_type
== (TLS_TLS
| TLS_GD
))
12781 bfd_put_64 (output_bfd
, relocation
,
12782 got
->contents
+ off
+ 8);
12787 bfd_put_64 (output_bfd
, relocation
,
12788 got
->contents
+ off
);
12792 if (off
>= (bfd_vma
) -2)
12795 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
12796 addend
= -(TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
);
12800 case R_PPC64_PLT16_HA
:
12801 case R_PPC64_PLT16_HI
:
12802 case R_PPC64_PLT16_LO
:
12803 case R_PPC64_PLT32
:
12804 case R_PPC64_PLT64
:
12805 /* Relocation is to the entry for this symbol in the
12806 procedure linkage table. */
12808 /* Resolve a PLT reloc against a local symbol directly,
12809 without using the procedure linkage table. */
12813 /* It's possible that we didn't make a PLT entry for this
12814 symbol. This happens when statically linking PIC code,
12815 or when using -Bsymbolic. Go find a match if there is a
12817 if (htab
->plt
!= NULL
)
12819 struct plt_entry
*ent
;
12820 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12821 if (ent
->addend
== orig_addend
12822 && ent
->plt
.offset
!= (bfd_vma
) -1)
12824 relocation
= (htab
->plt
->output_section
->vma
12825 + htab
->plt
->output_offset
12826 + ent
->plt
.offset
);
12827 unresolved_reloc
= FALSE
;
12833 /* Relocation value is TOC base. */
12834 relocation
= TOCstart
;
12835 if (r_symndx
== STN_UNDEF
)
12836 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
12837 else if (unresolved_reloc
)
12839 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
12840 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
12842 unresolved_reloc
= TRUE
;
12845 /* TOC16 relocs. We want the offset relative to the TOC base,
12846 which is the address of the start of the TOC plus 0x8000.
12847 The TOC consists of sections .got, .toc, .tocbss, and .plt,
12849 case R_PPC64_TOC16
:
12850 case R_PPC64_TOC16_LO
:
12851 case R_PPC64_TOC16_HI
:
12852 case R_PPC64_TOC16_DS
:
12853 case R_PPC64_TOC16_LO_DS
:
12854 case R_PPC64_TOC16_HA
:
12855 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
12858 /* Relocate against the beginning of the section. */
12859 case R_PPC64_SECTOFF
:
12860 case R_PPC64_SECTOFF_LO
:
12861 case R_PPC64_SECTOFF_HI
:
12862 case R_PPC64_SECTOFF_DS
:
12863 case R_PPC64_SECTOFF_LO_DS
:
12864 case R_PPC64_SECTOFF_HA
:
12866 addend
-= sec
->output_section
->vma
;
12869 case R_PPC64_REL16
:
12870 case R_PPC64_REL16_LO
:
12871 case R_PPC64_REL16_HI
:
12872 case R_PPC64_REL16_HA
:
12875 case R_PPC64_REL14
:
12876 case R_PPC64_REL14_BRNTAKEN
:
12877 case R_PPC64_REL14_BRTAKEN
:
12878 case R_PPC64_REL24
:
12881 case R_PPC64_TPREL16
:
12882 case R_PPC64_TPREL16_LO
:
12883 case R_PPC64_TPREL16_HI
:
12884 case R_PPC64_TPREL16_HA
:
12885 case R_PPC64_TPREL16_DS
:
12886 case R_PPC64_TPREL16_LO_DS
:
12887 case R_PPC64_TPREL16_HIGHER
:
12888 case R_PPC64_TPREL16_HIGHERA
:
12889 case R_PPC64_TPREL16_HIGHEST
:
12890 case R_PPC64_TPREL16_HIGHESTA
:
12892 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12893 && h
->elf
.dynindx
== -1)
12895 /* Make this relocation against an undefined weak symbol
12896 resolve to zero. This is really just a tweak, since
12897 code using weak externs ought to check that they are
12898 defined before using them. */
12899 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
12901 insn
= bfd_get_32 (output_bfd
, p
);
12902 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
12904 bfd_put_32 (output_bfd
, insn
, p
);
12907 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12909 /* The TPREL16 relocs shouldn't really be used in shared
12910 libs as they will result in DT_TEXTREL being set, but
12911 support them anyway. */
12915 case R_PPC64_DTPREL16
:
12916 case R_PPC64_DTPREL16_LO
:
12917 case R_PPC64_DTPREL16_HI
:
12918 case R_PPC64_DTPREL16_HA
:
12919 case R_PPC64_DTPREL16_DS
:
12920 case R_PPC64_DTPREL16_LO_DS
:
12921 case R_PPC64_DTPREL16_HIGHER
:
12922 case R_PPC64_DTPREL16_HIGHERA
:
12923 case R_PPC64_DTPREL16_HIGHEST
:
12924 case R_PPC64_DTPREL16_HIGHESTA
:
12925 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12928 case R_PPC64_DTPMOD64
:
12933 case R_PPC64_TPREL64
:
12934 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12937 case R_PPC64_DTPREL64
:
12938 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12941 /* Relocations that may need to be propagated if this is a
12943 case R_PPC64_REL30
:
12944 case R_PPC64_REL32
:
12945 case R_PPC64_REL64
:
12946 case R_PPC64_ADDR14
:
12947 case R_PPC64_ADDR14_BRNTAKEN
:
12948 case R_PPC64_ADDR14_BRTAKEN
:
12949 case R_PPC64_ADDR16
:
12950 case R_PPC64_ADDR16_DS
:
12951 case R_PPC64_ADDR16_HA
:
12952 case R_PPC64_ADDR16_HI
:
12953 case R_PPC64_ADDR16_HIGHER
:
12954 case R_PPC64_ADDR16_HIGHERA
:
12955 case R_PPC64_ADDR16_HIGHEST
:
12956 case R_PPC64_ADDR16_HIGHESTA
:
12957 case R_PPC64_ADDR16_LO
:
12958 case R_PPC64_ADDR16_LO_DS
:
12959 case R_PPC64_ADDR24
:
12960 case R_PPC64_ADDR32
:
12961 case R_PPC64_ADDR64
:
12962 case R_PPC64_UADDR16
:
12963 case R_PPC64_UADDR32
:
12964 case R_PPC64_UADDR64
:
12966 if ((input_section
->flags
& SEC_ALLOC
) == 0)
12969 if (NO_OPD_RELOCS
&& is_opd
)
12974 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12975 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
12976 && (must_be_dyn_reloc (info
, r_type
)
12977 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12978 || (ELIMINATE_COPY_RELOCS
12981 && h
->elf
.dynindx
!= -1
12982 && !h
->elf
.non_got_ref
12983 && !h
->elf
.def_regular
)
12986 ? h
->elf
.type
== STT_GNU_IFUNC
12987 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
12989 bfd_boolean skip
, relocate
;
12993 /* When generating a dynamic object, these relocations
12994 are copied into the output file to be resolved at run
13000 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
13001 input_section
, rel
->r_offset
);
13002 if (out_off
== (bfd_vma
) -1)
13004 else if (out_off
== (bfd_vma
) -2)
13005 skip
= TRUE
, relocate
= TRUE
;
13006 out_off
+= (input_section
->output_section
->vma
13007 + input_section
->output_offset
);
13008 outrel
.r_offset
= out_off
;
13009 outrel
.r_addend
= rel
->r_addend
;
13011 /* Optimize unaligned reloc use. */
13012 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
13013 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
13014 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
13015 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
13016 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
13017 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
13018 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
13019 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
13020 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
13023 memset (&outrel
, 0, sizeof outrel
);
13024 else if (!SYMBOL_CALLS_LOCAL (info
, &h
->elf
)
13026 && r_type
!= R_PPC64_TOC
)
13027 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
13030 /* This symbol is local, or marked to become local,
13031 or this is an opd section reloc which must point
13032 at a local function. */
13033 outrel
.r_addend
+= relocation
;
13034 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
13036 if (is_opd
&& h
!= NULL
)
13038 /* Lie about opd entries. This case occurs
13039 when building shared libraries and we
13040 reference a function in another shared
13041 lib. The same thing happens for a weak
13042 definition in an application that's
13043 overridden by a strong definition in a
13044 shared lib. (I believe this is a generic
13045 bug in binutils handling of weak syms.)
13046 In these cases we won't use the opd
13047 entry in this lib. */
13048 unresolved_reloc
= FALSE
;
13051 && r_type
== R_PPC64_ADDR64
13053 ? h
->elf
.type
== STT_GNU_IFUNC
13054 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
13055 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13058 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13060 /* We need to relocate .opd contents for ld.so.
13061 Prelink also wants simple and consistent rules
13062 for relocs. This make all RELATIVE relocs have
13063 *r_offset equal to r_addend. */
13072 ? h
->elf
.type
== STT_GNU_IFUNC
13073 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13075 info
->callbacks
->einfo
13076 (_("%P: %H: relocation %s for indirect "
13077 "function %s unsupported\n"),
13078 input_bfd
, input_section
, rel
->r_offset
,
13079 ppc64_elf_howto_table
[r_type
]->name
,
13083 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
13085 else if (sec
== NULL
|| sec
->owner
== NULL
)
13087 bfd_set_error (bfd_error_bad_value
);
13094 osec
= sec
->output_section
;
13095 indx
= elf_section_data (osec
)->dynindx
;
13099 if ((osec
->flags
& SEC_READONLY
) == 0
13100 && htab
->elf
.data_index_section
!= NULL
)
13101 osec
= htab
->elf
.data_index_section
;
13103 osec
= htab
->elf
.text_index_section
;
13104 indx
= elf_section_data (osec
)->dynindx
;
13106 BFD_ASSERT (indx
!= 0);
13108 /* We are turning this relocation into one
13109 against a section symbol, so subtract out
13110 the output section's address but not the
13111 offset of the input section in the output
13113 outrel
.r_addend
-= osec
->vma
;
13116 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
13120 sreloc
= elf_section_data (input_section
)->sreloc
;
13121 if (!htab
->elf
.dynamic_sections_created
)
13122 sreloc
= htab
->reliplt
;
13123 if (sreloc
== NULL
)
13126 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
13129 loc
= sreloc
->contents
;
13130 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13131 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
13133 /* If this reloc is against an external symbol, it will
13134 be computed at runtime, so there's no need to do
13135 anything now. However, for the sake of prelink ensure
13136 that the section contents are a known value. */
13139 unresolved_reloc
= FALSE
;
13140 /* The value chosen here is quite arbitrary as ld.so
13141 ignores section contents except for the special
13142 case of .opd where the contents might be accessed
13143 before relocation. Choose zero, as that won't
13144 cause reloc overflow. */
13147 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
13148 to improve backward compatibility with older
13150 if (r_type
== R_PPC64_ADDR64
)
13151 addend
= outrel
.r_addend
;
13152 /* Adjust pc_relative relocs to have zero in *r_offset. */
13153 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
13154 addend
= (input_section
->output_section
->vma
13155 + input_section
->output_offset
13162 case R_PPC64_GLOB_DAT
:
13163 case R_PPC64_JMP_SLOT
:
13164 case R_PPC64_JMP_IREL
:
13165 case R_PPC64_RELATIVE
:
13166 /* We shouldn't ever see these dynamic relocs in relocatable
13168 /* Fall through. */
13170 case R_PPC64_PLTGOT16
:
13171 case R_PPC64_PLTGOT16_DS
:
13172 case R_PPC64_PLTGOT16_HA
:
13173 case R_PPC64_PLTGOT16_HI
:
13174 case R_PPC64_PLTGOT16_LO
:
13175 case R_PPC64_PLTGOT16_LO_DS
:
13176 case R_PPC64_PLTREL32
:
13177 case R_PPC64_PLTREL64
:
13178 /* These ones haven't been implemented yet. */
13180 info
->callbacks
->einfo
13181 (_("%P: %B: relocation %s is not supported for symbol %s\n"),
13183 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
13185 bfd_set_error (bfd_error_invalid_operation
);
13190 /* Multi-instruction sequences that access the TOC can be
13191 optimized, eg. addis ra,r2,0; addi rb,ra,x;
13192 to nop; addi rb,r2,x; */
13198 case R_PPC64_GOT_TLSLD16_HI
:
13199 case R_PPC64_GOT_TLSGD16_HI
:
13200 case R_PPC64_GOT_TPREL16_HI
:
13201 case R_PPC64_GOT_DTPREL16_HI
:
13202 case R_PPC64_GOT16_HI
:
13203 case R_PPC64_TOC16_HI
:
13204 /* These relocs would only be useful if building up an
13205 offset to later add to r2, perhaps in an indexed
13206 addressing mode instruction. Don't try to optimize.
13207 Unfortunately, the possibility of someone building up an
13208 offset like this or even with the HA relocs, means that
13209 we need to check the high insn when optimizing the low
13213 case R_PPC64_GOT_TLSLD16_HA
:
13214 case R_PPC64_GOT_TLSGD16_HA
:
13215 case R_PPC64_GOT_TPREL16_HA
:
13216 case R_PPC64_GOT_DTPREL16_HA
:
13217 case R_PPC64_GOT16_HA
:
13218 case R_PPC64_TOC16_HA
:
13219 /* nop is done later. */
13222 case R_PPC64_GOT_TLSLD16_LO
:
13223 case R_PPC64_GOT_TLSGD16_LO
:
13224 case R_PPC64_GOT_TPREL16_LO_DS
:
13225 case R_PPC64_GOT_DTPREL16_LO_DS
:
13226 case R_PPC64_GOT16_LO
:
13227 case R_PPC64_GOT16_LO_DS
:
13228 case R_PPC64_TOC16_LO
:
13229 case R_PPC64_TOC16_LO_DS
:
13230 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
13232 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13233 insn
= bfd_get_32 (input_bfd
, p
);
13234 if ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
13235 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
13236 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
13237 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
13238 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
13239 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
13240 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
13241 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
13242 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
13243 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
13244 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
13245 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
13246 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
13247 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
13248 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
13249 && (insn
& 3) != 1)
13250 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
13251 && ((insn
& 3) == 0 || (insn
& 3) == 3)))
13253 unsigned int reg
= (insn
>> 16) & 0x1f;
13254 const Elf_Internal_Rela
*ha
;
13255 bfd_boolean match_addend
;
13257 match_addend
= (sym
!= NULL
13258 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
);
13259 ha
= ha_reloc_match (relocs
, rel
, ®
, match_addend
,
13260 input_bfd
, contents
);
13263 insn
&= ~(0x1f << 16);
13265 bfd_put_32 (input_bfd
, insn
, p
);
13266 if (ha_opt
== NULL
)
13268 ha_opt
= bfd_zmalloc (input_section
->reloc_count
);
13269 if (ha_opt
== NULL
)
13272 ha_opt
[ha
- relocs
] = 1;
13275 /* If we don't find a matching high part insn,
13276 something is fishy. Refuse to nop any high
13277 part insn in this section. */
13284 /* Do any further special processing. */
13290 case R_PPC64_ADDR16_HA
:
13291 case R_PPC64_REL16_HA
:
13292 case R_PPC64_ADDR16_HIGHERA
:
13293 case R_PPC64_ADDR16_HIGHESTA
:
13294 case R_PPC64_TOC16_HA
:
13295 case R_PPC64_SECTOFF_HA
:
13296 case R_PPC64_TPREL16_HA
:
13297 case R_PPC64_DTPREL16_HA
:
13298 case R_PPC64_TPREL16_HIGHER
:
13299 case R_PPC64_TPREL16_HIGHERA
:
13300 case R_PPC64_TPREL16_HIGHEST
:
13301 case R_PPC64_TPREL16_HIGHESTA
:
13302 case R_PPC64_DTPREL16_HIGHER
:
13303 case R_PPC64_DTPREL16_HIGHERA
:
13304 case R_PPC64_DTPREL16_HIGHEST
:
13305 case R_PPC64_DTPREL16_HIGHESTA
:
13306 /* It's just possible that this symbol is a weak symbol
13307 that's not actually defined anywhere. In that case,
13308 'sec' would be NULL, and we should leave the symbol
13309 alone (it will be set to zero elsewhere in the link). */
13314 case R_PPC64_GOT16_HA
:
13315 case R_PPC64_PLTGOT16_HA
:
13316 case R_PPC64_PLT16_HA
:
13317 case R_PPC64_GOT_TLSGD16_HA
:
13318 case R_PPC64_GOT_TLSLD16_HA
:
13319 case R_PPC64_GOT_TPREL16_HA
:
13320 case R_PPC64_GOT_DTPREL16_HA
:
13321 /* Add 0x10000 if sign bit in 0:15 is set.
13322 Bits 0:15 are not used. */
13326 case R_PPC64_ADDR16_DS
:
13327 case R_PPC64_ADDR16_LO_DS
:
13328 case R_PPC64_GOT16_DS
:
13329 case R_PPC64_GOT16_LO_DS
:
13330 case R_PPC64_PLT16_LO_DS
:
13331 case R_PPC64_SECTOFF_DS
:
13332 case R_PPC64_SECTOFF_LO_DS
:
13333 case R_PPC64_TOC16_DS
:
13334 case R_PPC64_TOC16_LO_DS
:
13335 case R_PPC64_PLTGOT16_DS
:
13336 case R_PPC64_PLTGOT16_LO_DS
:
13337 case R_PPC64_GOT_TPREL16_DS
:
13338 case R_PPC64_GOT_TPREL16_LO_DS
:
13339 case R_PPC64_GOT_DTPREL16_DS
:
13340 case R_PPC64_GOT_DTPREL16_LO_DS
:
13341 case R_PPC64_TPREL16_DS
:
13342 case R_PPC64_TPREL16_LO_DS
:
13343 case R_PPC64_DTPREL16_DS
:
13344 case R_PPC64_DTPREL16_LO_DS
:
13345 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
13347 /* If this reloc is against an lq insn, then the value must be
13348 a multiple of 16. This is somewhat of a hack, but the
13349 "correct" way to do this by defining _DQ forms of all the
13350 _DS relocs bloats all reloc switches in this file. It
13351 doesn't seem to make much sense to use any of these relocs
13352 in data, so testing the insn should be safe. */
13353 if ((insn
& (0x3f << 26)) == (56u << 26))
13355 if (((relocation
+ addend
) & mask
) != 0)
13357 info
->callbacks
->einfo
13358 (_("%P: %H: error: %s not a multiple of %u\n"),
13359 input_bfd
, input_section
, rel
->r_offset
,
13360 ppc64_elf_howto_table
[r_type
]->name
,
13362 bfd_set_error (bfd_error_bad_value
);
13369 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
13370 because such sections are not SEC_ALLOC and thus ld.so will
13371 not process them. */
13372 if (unresolved_reloc
13373 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
13374 && h
->elf
.def_dynamic
))
13376 info
->callbacks
->einfo
13377 (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
13378 input_bfd
, input_section
, rel
->r_offset
,
13379 ppc64_elf_howto_table
[(int) r_type
]->name
,
13380 h
->elf
.root
.root
.string
);
13384 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
13392 if (r
!= bfd_reloc_ok
)
13394 if (sym_name
== NULL
)
13395 sym_name
= "(null)";
13396 if (r
== bfd_reloc_overflow
)
13401 && h
->elf
.root
.type
== bfd_link_hash_undefweak
13402 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
13404 /* Assume this is a call protected by other code that
13405 detects the symbol is undefined. If this is the case,
13406 we can safely ignore the overflow. If not, the
13407 program is hosed anyway, and a little warning isn't
13413 if (!((*info
->callbacks
->reloc_overflow
)
13414 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
13415 ppc64_elf_howto_table
[r_type
]->name
,
13416 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
13421 info
->callbacks
->einfo
13422 (_("%P: %H: %s reloc against `%s': error %d\n"),
13423 input_bfd
, input_section
, rel
->r_offset
,
13424 ppc64_elf_howto_table
[r_type
]->name
,
13432 if (ha_opt
!= NULL
)
13436 unsigned char *opt
= ha_opt
;
13438 relend
= relocs
+ input_section
->reloc_count
;
13439 for (; rel
< relend
; opt
++, rel
++)
13442 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13443 bfd_put_32 (input_bfd
, NOP
, p
);
13449 /* If we're emitting relocations, then shortly after this function
13450 returns, reloc offsets and addends for this section will be
13451 adjusted. Worse, reloc symbol indices will be for the output
13452 file rather than the input. Save a copy of the relocs for
13453 opd_entry_value. */
13454 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
13457 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
13458 rel
= bfd_alloc (input_bfd
, amt
);
13459 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
13460 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
13463 memcpy (rel
, relocs
, amt
);
13468 /* Adjust the value of any local symbols in opd sections. */
13471 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
13472 const char *name ATTRIBUTE_UNUSED
,
13473 Elf_Internal_Sym
*elfsym
,
13474 asection
*input_sec
,
13475 struct elf_link_hash_entry
*h
)
13477 struct _opd_sec_data
*opd
;
13484 opd
= get_opd_info (input_sec
);
13485 if (opd
== NULL
|| opd
->adjust
== NULL
)
13488 value
= elfsym
->st_value
- input_sec
->output_offset
;
13489 if (!info
->relocatable
)
13490 value
-= input_sec
->output_section
->vma
;
13492 adjust
= opd
->adjust
[value
/ 8];
13496 elfsym
->st_value
+= adjust
;
13500 /* Finish up dynamic symbol handling. We set the contents of various
13501 dynamic sections here. */
13504 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
13505 struct bfd_link_info
*info
,
13506 struct elf_link_hash_entry
*h
,
13507 Elf_Internal_Sym
*sym
)
13509 struct ppc_link_hash_table
*htab
;
13510 struct plt_entry
*ent
;
13511 Elf_Internal_Rela rela
;
13514 htab
= ppc_hash_table (info
);
13518 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13519 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13521 /* This symbol has an entry in the procedure linkage
13522 table. Set it up. */
13523 if (!htab
->elf
.dynamic_sections_created
13524 || h
->dynindx
== -1)
13526 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
13528 && (h
->root
.type
== bfd_link_hash_defined
13529 || h
->root
.type
== bfd_link_hash_defweak
));
13530 rela
.r_offset
= (htab
->iplt
->output_section
->vma
13531 + htab
->iplt
->output_offset
13532 + ent
->plt
.offset
);
13533 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13534 rela
.r_addend
= (h
->root
.u
.def
.value
13535 + h
->root
.u
.def
.section
->output_offset
13536 + h
->root
.u
.def
.section
->output_section
->vma
13538 loc
= (htab
->reliplt
->contents
13539 + (htab
->reliplt
->reloc_count
++
13540 * sizeof (Elf64_External_Rela
)));
13544 rela
.r_offset
= (htab
->plt
->output_section
->vma
13545 + htab
->plt
->output_offset
13546 + ent
->plt
.offset
);
13547 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13548 rela
.r_addend
= ent
->addend
;
13549 loc
= (htab
->relplt
->contents
13550 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
)
13551 / (PLT_ENTRY_SIZE
/ sizeof (Elf64_External_Rela
))));
13553 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13558 /* This symbol needs a copy reloc. Set it up. */
13560 if (h
->dynindx
== -1
13561 || (h
->root
.type
!= bfd_link_hash_defined
13562 && h
->root
.type
!= bfd_link_hash_defweak
)
13563 || htab
->relbss
== NULL
)
13566 rela
.r_offset
= (h
->root
.u
.def
.value
13567 + h
->root
.u
.def
.section
->output_section
->vma
13568 + h
->root
.u
.def
.section
->output_offset
);
13569 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
13571 loc
= htab
->relbss
->contents
;
13572 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13573 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13576 /* Mark some specially defined symbols as absolute. */
13577 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
13578 sym
->st_shndx
= SHN_ABS
;
13583 /* Used to decide how to sort relocs in an optimal manner for the
13584 dynamic linker, before writing them out. */
13586 static enum elf_reloc_type_class
13587 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
13589 enum elf_ppc64_reloc_type r_type
;
13591 r_type
= ELF64_R_TYPE (rela
->r_info
);
13594 case R_PPC64_RELATIVE
:
13595 return reloc_class_relative
;
13596 case R_PPC64_JMP_SLOT
:
13597 return reloc_class_plt
;
13599 return reloc_class_copy
;
13601 return reloc_class_normal
;
13605 /* Finish up the dynamic sections. */
13608 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
13609 struct bfd_link_info
*info
)
13611 struct ppc_link_hash_table
*htab
;
13615 htab
= ppc_hash_table (info
);
13619 dynobj
= htab
->elf
.dynobj
;
13620 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
13622 if (htab
->elf
.dynamic_sections_created
)
13624 Elf64_External_Dyn
*dyncon
, *dynconend
;
13626 if (sdyn
== NULL
|| htab
->got
== NULL
)
13629 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
13630 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
13631 for (; dyncon
< dynconend
; dyncon
++)
13633 Elf_Internal_Dyn dyn
;
13636 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
13643 case DT_PPC64_GLINK
:
13645 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13646 /* We stupidly defined DT_PPC64_GLINK to be the start
13647 of glink rather than the first entry point, which is
13648 what ld.so needs, and now have a bigger stub to
13649 support automatic multiple TOCs. */
13650 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
13654 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13657 dyn
.d_un
.d_ptr
= s
->vma
;
13660 case DT_PPC64_OPDSZ
:
13661 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13664 dyn
.d_un
.d_val
= s
->size
;
13669 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13674 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13678 dyn
.d_un
.d_val
= htab
->relplt
->size
;
13682 /* Don't count procedure linkage table relocs in the
13683 overall reloc count. */
13687 dyn
.d_un
.d_val
-= s
->size
;
13691 /* We may not be using the standard ELF linker script.
13692 If .rela.plt is the first .rela section, we adjust
13693 DT_RELA to not include it. */
13697 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
13699 dyn
.d_un
.d_ptr
+= s
->size
;
13703 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13707 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
13709 /* Fill in the first entry in the global offset table.
13710 We use it to hold the link-time TOCbase. */
13711 bfd_put_64 (output_bfd
,
13712 elf_gp (output_bfd
) + TOC_BASE_OFF
,
13713 htab
->got
->contents
);
13715 /* Set .got entry size. */
13716 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
13719 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
13721 /* Set .plt entry size. */
13722 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
13726 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
13727 brlt ourselves if emitrelocations. */
13728 if (htab
->brlt
!= NULL
13729 && htab
->brlt
->reloc_count
!= 0
13730 && !_bfd_elf_link_output_relocs (output_bfd
,
13732 elf_section_data (htab
->brlt
)->rela
.hdr
,
13733 elf_section_data (htab
->brlt
)->relocs
,
13737 if (htab
->glink
!= NULL
13738 && htab
->glink
->reloc_count
!= 0
13739 && !_bfd_elf_link_output_relocs (output_bfd
,
13741 elf_section_data (htab
->glink
)->rela
.hdr
,
13742 elf_section_data (htab
->glink
)->relocs
,
13747 if (htab
->glink_eh_frame
!= NULL
13748 && htab
->glink_eh_frame
->sec_info_type
== ELF_INFO_TYPE_EH_FRAME
13749 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
13750 htab
->glink_eh_frame
,
13751 htab
->glink_eh_frame
->contents
))
13754 /* We need to handle writing out multiple GOT sections ourselves,
13755 since we didn't add them to DYNOBJ. We know dynobj is the first
13757 while ((dynobj
= dynobj
->link_next
) != NULL
)
13761 if (!is_ppc64_elf (dynobj
))
13764 s
= ppc64_elf_tdata (dynobj
)->got
;
13767 && s
->output_section
!= bfd_abs_section_ptr
13768 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13769 s
->contents
, s
->output_offset
,
13772 s
= ppc64_elf_tdata (dynobj
)->relgot
;
13775 && s
->output_section
!= bfd_abs_section_ptr
13776 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13777 s
->contents
, s
->output_offset
,
13785 #include "elf64-target.h"