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"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_vma opd_entry_value
57 (asection
*, bfd_vma
, asection
**, bfd_vma
*);
59 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_TARGET_ID PPC64_ELF_DATA
65 #define ELF_MACHINE_CODE EM_PPC64
66 #define ELF_MAXPAGESIZE 0x10000
67 #define ELF_COMMONPAGESIZE 0x1000
68 #define elf_info_to_howto ppc64_elf_info_to_howto
70 #define elf_backend_want_got_sym 0
71 #define elf_backend_want_plt_sym 0
72 #define elf_backend_plt_alignment 3
73 #define elf_backend_plt_not_loaded 1
74 #define elf_backend_got_header_size 8
75 #define elf_backend_can_gc_sections 1
76 #define elf_backend_can_refcount 1
77 #define elf_backend_rela_normal 1
78 #define elf_backend_default_execstack 0
80 #define bfd_elf64_mkobject ppc64_elf_mkobject
81 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
82 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
83 #define bfd_elf64_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
84 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
85 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
86 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
87 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
88 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
90 #define elf_backend_object_p ppc64_elf_object_p
91 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
92 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
93 #define elf_backend_write_core_note ppc64_elf_write_core_note
94 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
95 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
96 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
97 #define elf_backend_check_directives ppc64_elf_process_dot_syms
98 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
99 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
100 #define elf_backend_check_relocs ppc64_elf_check_relocs
101 #define elf_backend_gc_keep ppc64_elf_gc_keep
102 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
103 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
104 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
105 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
106 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
107 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
108 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
109 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
110 #define elf_backend_action_discarded ppc64_elf_action_discarded
111 #define elf_backend_relocate_section ppc64_elf_relocate_section
112 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
113 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
114 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
115 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
116 #define elf_backend_special_sections ppc64_elf_special_sections
117 #define elf_backend_post_process_headers _bfd_elf_set_osabi
119 /* The name of the dynamic interpreter. This is put in the .interp
121 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
123 /* The size in bytes of an entry in the procedure linkage table. */
124 #define PLT_ENTRY_SIZE 24
126 /* The initial size of the plt reserved for the dynamic linker. */
127 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
129 /* TOC base pointers offset from start of TOC. */
130 #define TOC_BASE_OFF 0x8000
132 /* Offset of tp and dtp pointers from start of TLS block. */
133 #define TP_OFFSET 0x7000
134 #define DTP_OFFSET 0x8000
136 /* .plt call stub instructions. The normal stub is like this, but
137 sometimes the .plt entry crosses a 64k boundary and we need to
138 insert an addi to adjust r12. */
139 #define PLT_CALL_STUB_SIZE (7*4)
140 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
141 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
142 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
143 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
144 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
145 /* ld %r11,xxx+16@l(%r12) */
146 #define BCTR 0x4e800420 /* bctr */
149 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
150 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
151 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
152 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
154 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
155 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
157 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
159 /* glink call stub instructions. We enter with the index in R0. */
160 #define GLINK_CALL_STUB_SIZE (16*4)
164 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
165 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
167 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
168 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
169 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
170 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
178 #define NOP 0x60000000
180 /* Some other nops. */
181 #define CROR_151515 0x4def7b82
182 #define CROR_313131 0x4ffffb82
184 /* .glink entries for the first 32k functions are two instructions. */
185 #define LI_R0_0 0x38000000 /* li %r0,0 */
186 #define B_DOT 0x48000000 /* b . */
188 /* After that, we need two instructions to load the index, followed by
190 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
191 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
193 /* Instructions used by the save and restore reg functions. */
194 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
195 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
196 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
197 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
198 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
199 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
200 #define LI_R12_0 0x39800000 /* li %r12,0 */
201 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
202 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
203 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
204 #define BLR 0x4e800020 /* blr */
206 /* Since .opd is an array of descriptors and each entry will end up
207 with identical R_PPC64_RELATIVE relocs, there is really no need to
208 propagate .opd relocs; The dynamic linker should be taught to
209 relocate .opd without reloc entries. */
210 #ifndef NO_OPD_RELOCS
211 #define NO_OPD_RELOCS 0
214 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
216 /* Relocation HOWTO's. */
217 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
219 static reloc_howto_type ppc64_elf_howto_raw
[] = {
220 /* This reloc does nothing. */
221 HOWTO (R_PPC64_NONE
, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 FALSE
, /* pc_relative */
227 complain_overflow_dont
, /* complain_on_overflow */
228 bfd_elf_generic_reloc
, /* special_function */
229 "R_PPC64_NONE", /* name */
230 FALSE
, /* partial_inplace */
233 FALSE
), /* pcrel_offset */
235 /* A standard 32 bit relocation. */
236 HOWTO (R_PPC64_ADDR32
, /* type */
238 2, /* size (0 = byte, 1 = short, 2 = long) */
240 FALSE
, /* pc_relative */
242 complain_overflow_bitfield
, /* complain_on_overflow */
243 bfd_elf_generic_reloc
, /* special_function */
244 "R_PPC64_ADDR32", /* name */
245 FALSE
, /* partial_inplace */
247 0xffffffff, /* dst_mask */
248 FALSE
), /* pcrel_offset */
250 /* An absolute 26 bit branch; the lower two bits must be zero.
251 FIXME: we don't check that, we just clear them. */
252 HOWTO (R_PPC64_ADDR24
, /* type */
254 2, /* size (0 = byte, 1 = short, 2 = long) */
256 FALSE
, /* pc_relative */
258 complain_overflow_bitfield
, /* complain_on_overflow */
259 bfd_elf_generic_reloc
, /* special_function */
260 "R_PPC64_ADDR24", /* name */
261 FALSE
, /* partial_inplace */
263 0x03fffffc, /* dst_mask */
264 FALSE
), /* pcrel_offset */
266 /* A standard 16 bit relocation. */
267 HOWTO (R_PPC64_ADDR16
, /* type */
269 1, /* size (0 = byte, 1 = short, 2 = long) */
271 FALSE
, /* pc_relative */
273 complain_overflow_bitfield
, /* complain_on_overflow */
274 bfd_elf_generic_reloc
, /* special_function */
275 "R_PPC64_ADDR16", /* name */
276 FALSE
, /* partial_inplace */
278 0xffff, /* dst_mask */
279 FALSE
), /* pcrel_offset */
281 /* A 16 bit relocation without overflow. */
282 HOWTO (R_PPC64_ADDR16_LO
, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_dont
,/* complain_on_overflow */
289 bfd_elf_generic_reloc
, /* special_function */
290 "R_PPC64_ADDR16_LO", /* name */
291 FALSE
, /* partial_inplace */
293 0xffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 /* Bits 16-31 of an address. */
297 HOWTO (R_PPC64_ADDR16_HI
, /* type */
299 1, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE
, /* pc_relative */
303 complain_overflow_dont
, /* complain_on_overflow */
304 bfd_elf_generic_reloc
, /* special_function */
305 "R_PPC64_ADDR16_HI", /* name */
306 FALSE
, /* partial_inplace */
308 0xffff, /* dst_mask */
309 FALSE
), /* pcrel_offset */
311 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
312 bits, treated as a signed number, is negative. */
313 HOWTO (R_PPC64_ADDR16_HA
, /* type */
315 1, /* size (0 = byte, 1 = short, 2 = long) */
317 FALSE
, /* pc_relative */
319 complain_overflow_dont
, /* complain_on_overflow */
320 ppc64_elf_ha_reloc
, /* special_function */
321 "R_PPC64_ADDR16_HA", /* name */
322 FALSE
, /* partial_inplace */
324 0xffff, /* dst_mask */
325 FALSE
), /* pcrel_offset */
327 /* An absolute 16 bit branch; the lower two bits must be zero.
328 FIXME: we don't check that, we just clear them. */
329 HOWTO (R_PPC64_ADDR14
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 FALSE
, /* pc_relative */
335 complain_overflow_bitfield
, /* complain_on_overflow */
336 ppc64_elf_branch_reloc
, /* special_function */
337 "R_PPC64_ADDR14", /* name */
338 FALSE
, /* partial_inplace */
340 0x0000fffc, /* dst_mask */
341 FALSE
), /* pcrel_offset */
343 /* An absolute 16 bit branch, for which bit 10 should be set to
344 indicate that the branch is expected to be taken. The lower two
345 bits must be zero. */
346 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 FALSE
, /* pc_relative */
352 complain_overflow_bitfield
, /* complain_on_overflow */
353 ppc64_elf_brtaken_reloc
, /* special_function */
354 "R_PPC64_ADDR14_BRTAKEN",/* name */
355 FALSE
, /* partial_inplace */
357 0x0000fffc, /* dst_mask */
358 FALSE
), /* pcrel_offset */
360 /* An absolute 16 bit branch, for which bit 10 should be set to
361 indicate that the branch is not expected to be taken. The lower
362 two bits must be zero. */
363 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 FALSE
, /* pc_relative */
369 complain_overflow_bitfield
, /* complain_on_overflow */
370 ppc64_elf_brtaken_reloc
, /* special_function */
371 "R_PPC64_ADDR14_BRNTAKEN",/* name */
372 FALSE
, /* partial_inplace */
374 0x0000fffc, /* dst_mask */
375 FALSE
), /* pcrel_offset */
377 /* A relative 26 bit branch; the lower two bits must be zero. */
378 HOWTO (R_PPC64_REL24
, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 TRUE
, /* pc_relative */
384 complain_overflow_signed
, /* complain_on_overflow */
385 ppc64_elf_branch_reloc
, /* special_function */
386 "R_PPC64_REL24", /* name */
387 FALSE
, /* partial_inplace */
389 0x03fffffc, /* dst_mask */
390 TRUE
), /* pcrel_offset */
392 /* A relative 16 bit branch; the lower two bits must be zero. */
393 HOWTO (R_PPC64_REL14
, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 TRUE
, /* pc_relative */
399 complain_overflow_signed
, /* complain_on_overflow */
400 ppc64_elf_branch_reloc
, /* special_function */
401 "R_PPC64_REL14", /* name */
402 FALSE
, /* partial_inplace */
404 0x0000fffc, /* dst_mask */
405 TRUE
), /* pcrel_offset */
407 /* A relative 16 bit branch. Bit 10 should be set to indicate that
408 the branch is expected to be taken. The lower two bits must be
410 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
412 2, /* size (0 = byte, 1 = short, 2 = long) */
414 TRUE
, /* pc_relative */
416 complain_overflow_signed
, /* complain_on_overflow */
417 ppc64_elf_brtaken_reloc
, /* special_function */
418 "R_PPC64_REL14_BRTAKEN", /* name */
419 FALSE
, /* partial_inplace */
421 0x0000fffc, /* dst_mask */
422 TRUE
), /* pcrel_offset */
424 /* A relative 16 bit branch. Bit 10 should be set to indicate that
425 the branch is not expected to be taken. The lower two bits must
427 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 TRUE
, /* pc_relative */
433 complain_overflow_signed
, /* complain_on_overflow */
434 ppc64_elf_brtaken_reloc
, /* special_function */
435 "R_PPC64_REL14_BRNTAKEN",/* name */
436 FALSE
, /* partial_inplace */
438 0x0000fffc, /* dst_mask */
439 TRUE
), /* pcrel_offset */
441 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
443 HOWTO (R_PPC64_GOT16
, /* type */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE
, /* pc_relative */
449 complain_overflow_signed
, /* complain_on_overflow */
450 ppc64_elf_unhandled_reloc
, /* special_function */
451 "R_PPC64_GOT16", /* name */
452 FALSE
, /* partial_inplace */
454 0xffff, /* dst_mask */
455 FALSE
), /* pcrel_offset */
457 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
459 HOWTO (R_PPC64_GOT16_LO
, /* type */
461 1, /* size (0 = byte, 1 = short, 2 = long) */
463 FALSE
, /* pc_relative */
465 complain_overflow_dont
, /* complain_on_overflow */
466 ppc64_elf_unhandled_reloc
, /* special_function */
467 "R_PPC64_GOT16_LO", /* name */
468 FALSE
, /* partial_inplace */
470 0xffff, /* dst_mask */
471 FALSE
), /* pcrel_offset */
473 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
475 HOWTO (R_PPC64_GOT16_HI
, /* type */
477 1, /* size (0 = byte, 1 = short, 2 = long) */
479 FALSE
, /* pc_relative */
481 complain_overflow_dont
,/* complain_on_overflow */
482 ppc64_elf_unhandled_reloc
, /* special_function */
483 "R_PPC64_GOT16_HI", /* name */
484 FALSE
, /* partial_inplace */
486 0xffff, /* dst_mask */
487 FALSE
), /* pcrel_offset */
489 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
491 HOWTO (R_PPC64_GOT16_HA
, /* type */
493 1, /* size (0 = byte, 1 = short, 2 = long) */
495 FALSE
, /* pc_relative */
497 complain_overflow_dont
,/* complain_on_overflow */
498 ppc64_elf_unhandled_reloc
, /* special_function */
499 "R_PPC64_GOT16_HA", /* name */
500 FALSE
, /* partial_inplace */
502 0xffff, /* dst_mask */
503 FALSE
), /* pcrel_offset */
505 /* This is used only by the dynamic linker. The symbol should exist
506 both in the object being run and in some shared library. The
507 dynamic linker copies the data addressed by the symbol from the
508 shared library into the object, because the object being
509 run has to have the data at some particular address. */
510 HOWTO (R_PPC64_COPY
, /* type */
512 0, /* this one is variable size */
514 FALSE
, /* pc_relative */
516 complain_overflow_dont
, /* complain_on_overflow */
517 ppc64_elf_unhandled_reloc
, /* special_function */
518 "R_PPC64_COPY", /* name */
519 FALSE
, /* partial_inplace */
522 FALSE
), /* pcrel_offset */
524 /* Like R_PPC64_ADDR64, but used when setting global offset table
526 HOWTO (R_PPC64_GLOB_DAT
, /* type */
528 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
530 FALSE
, /* pc_relative */
532 complain_overflow_dont
, /* complain_on_overflow */
533 ppc64_elf_unhandled_reloc
, /* special_function */
534 "R_PPC64_GLOB_DAT", /* name */
535 FALSE
, /* partial_inplace */
537 ONES (64), /* dst_mask */
538 FALSE
), /* pcrel_offset */
540 /* Created by the link editor. Marks a procedure linkage table
541 entry for a symbol. */
542 HOWTO (R_PPC64_JMP_SLOT
, /* type */
544 0, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_dont
, /* complain_on_overflow */
549 ppc64_elf_unhandled_reloc
, /* special_function */
550 "R_PPC64_JMP_SLOT", /* name */
551 FALSE
, /* partial_inplace */
554 FALSE
), /* pcrel_offset */
556 /* Used only by the dynamic linker. When the object is run, this
557 doubleword64 is set to the load address of the object, plus the
559 HOWTO (R_PPC64_RELATIVE
, /* type */
561 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
563 FALSE
, /* pc_relative */
565 complain_overflow_dont
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_PPC64_RELATIVE", /* name */
568 FALSE
, /* partial_inplace */
570 ONES (64), /* dst_mask */
571 FALSE
), /* pcrel_offset */
573 /* Like R_PPC64_ADDR32, but may be unaligned. */
574 HOWTO (R_PPC64_UADDR32
, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 FALSE
, /* pc_relative */
580 complain_overflow_bitfield
, /* complain_on_overflow */
581 bfd_elf_generic_reloc
, /* special_function */
582 "R_PPC64_UADDR32", /* name */
583 FALSE
, /* partial_inplace */
585 0xffffffff, /* dst_mask */
586 FALSE
), /* pcrel_offset */
588 /* Like R_PPC64_ADDR16, but may be unaligned. */
589 HOWTO (R_PPC64_UADDR16
, /* type */
591 1, /* size (0 = byte, 1 = short, 2 = long) */
593 FALSE
, /* pc_relative */
595 complain_overflow_bitfield
, /* complain_on_overflow */
596 bfd_elf_generic_reloc
, /* special_function */
597 "R_PPC64_UADDR16", /* name */
598 FALSE
, /* partial_inplace */
600 0xffff, /* dst_mask */
601 FALSE
), /* pcrel_offset */
603 /* 32-bit PC relative. */
604 HOWTO (R_PPC64_REL32
, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 TRUE
, /* pc_relative */
610 /* FIXME: Verify. Was complain_overflow_bitfield. */
611 complain_overflow_signed
, /* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 "R_PPC64_REL32", /* name */
614 FALSE
, /* partial_inplace */
616 0xffffffff, /* dst_mask */
617 TRUE
), /* pcrel_offset */
619 /* 32-bit relocation to the symbol's procedure linkage table. */
620 HOWTO (R_PPC64_PLT32
, /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE
, /* pc_relative */
626 complain_overflow_bitfield
, /* complain_on_overflow */
627 ppc64_elf_unhandled_reloc
, /* special_function */
628 "R_PPC64_PLT32", /* name */
629 FALSE
, /* partial_inplace */
631 0xffffffff, /* dst_mask */
632 FALSE
), /* pcrel_offset */
634 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
635 FIXME: R_PPC64_PLTREL32 not supported. */
636 HOWTO (R_PPC64_PLTREL32
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 TRUE
, /* pc_relative */
642 complain_overflow_signed
, /* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 "R_PPC64_PLTREL32", /* name */
645 FALSE
, /* partial_inplace */
647 0xffffffff, /* dst_mask */
648 TRUE
), /* pcrel_offset */
650 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
652 HOWTO (R_PPC64_PLT16_LO
, /* type */
654 1, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE
, /* pc_relative */
658 complain_overflow_dont
, /* complain_on_overflow */
659 ppc64_elf_unhandled_reloc
, /* special_function */
660 "R_PPC64_PLT16_LO", /* name */
661 FALSE
, /* partial_inplace */
663 0xffff, /* dst_mask */
664 FALSE
), /* pcrel_offset */
666 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
668 HOWTO (R_PPC64_PLT16_HI
, /* type */
670 1, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_dont
, /* complain_on_overflow */
675 ppc64_elf_unhandled_reloc
, /* special_function */
676 "R_PPC64_PLT16_HI", /* name */
677 FALSE
, /* partial_inplace */
679 0xffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
682 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
684 HOWTO (R_PPC64_PLT16_HA
, /* type */
686 1, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE
, /* pc_relative */
690 complain_overflow_dont
, /* complain_on_overflow */
691 ppc64_elf_unhandled_reloc
, /* special_function */
692 "R_PPC64_PLT16_HA", /* name */
693 FALSE
, /* partial_inplace */
695 0xffff, /* dst_mask */
696 FALSE
), /* pcrel_offset */
698 /* 16-bit section relative relocation. */
699 HOWTO (R_PPC64_SECTOFF
, /* type */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
703 FALSE
, /* pc_relative */
705 complain_overflow_bitfield
, /* complain_on_overflow */
706 ppc64_elf_sectoff_reloc
, /* special_function */
707 "R_PPC64_SECTOFF", /* name */
708 FALSE
, /* partial_inplace */
710 0xffff, /* dst_mask */
711 FALSE
), /* pcrel_offset */
713 /* Like R_PPC64_SECTOFF, but no overflow warning. */
714 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
716 1, /* size (0 = byte, 1 = short, 2 = long) */
718 FALSE
, /* pc_relative */
720 complain_overflow_dont
, /* complain_on_overflow */
721 ppc64_elf_sectoff_reloc
, /* special_function */
722 "R_PPC64_SECTOFF_LO", /* name */
723 FALSE
, /* partial_inplace */
725 0xffff, /* dst_mask */
726 FALSE
), /* pcrel_offset */
728 /* 16-bit upper half section relative relocation. */
729 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
731 1, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE
, /* pc_relative */
735 complain_overflow_dont
, /* complain_on_overflow */
736 ppc64_elf_sectoff_reloc
, /* special_function */
737 "R_PPC64_SECTOFF_HI", /* name */
738 FALSE
, /* partial_inplace */
740 0xffff, /* dst_mask */
741 FALSE
), /* pcrel_offset */
743 /* 16-bit upper half adjusted section relative relocation. */
744 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
746 1, /* size (0 = byte, 1 = short, 2 = long) */
748 FALSE
, /* pc_relative */
750 complain_overflow_dont
, /* complain_on_overflow */
751 ppc64_elf_sectoff_ha_reloc
, /* special_function */
752 "R_PPC64_SECTOFF_HA", /* name */
753 FALSE
, /* partial_inplace */
755 0xffff, /* dst_mask */
756 FALSE
), /* pcrel_offset */
758 /* Like R_PPC64_REL24 without touching the two least significant bits. */
759 HOWTO (R_PPC64_REL30
, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 TRUE
, /* pc_relative */
765 complain_overflow_dont
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_PPC64_REL30", /* name */
768 FALSE
, /* partial_inplace */
770 0xfffffffc, /* dst_mask */
771 TRUE
), /* pcrel_offset */
773 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
775 /* A standard 64-bit relocation. */
776 HOWTO (R_PPC64_ADDR64
, /* type */
778 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
780 FALSE
, /* pc_relative */
782 complain_overflow_dont
, /* complain_on_overflow */
783 bfd_elf_generic_reloc
, /* special_function */
784 "R_PPC64_ADDR64", /* name */
785 FALSE
, /* partial_inplace */
787 ONES (64), /* dst_mask */
788 FALSE
), /* pcrel_offset */
790 /* The bits 32-47 of an address. */
791 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
793 1, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_dont
, /* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_PPC64_ADDR16_HIGHER", /* name */
800 FALSE
, /* partial_inplace */
802 0xffff, /* dst_mask */
803 FALSE
), /* pcrel_offset */
805 /* The bits 32-47 of an address, plus 1 if the contents of the low
806 16 bits, treated as a signed number, is negative. */
807 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
809 1, /* size (0 = byte, 1 = short, 2 = long) */
811 FALSE
, /* pc_relative */
813 complain_overflow_dont
, /* complain_on_overflow */
814 ppc64_elf_ha_reloc
, /* special_function */
815 "R_PPC64_ADDR16_HIGHERA", /* name */
816 FALSE
, /* partial_inplace */
818 0xffff, /* dst_mask */
819 FALSE
), /* pcrel_offset */
821 /* The bits 48-63 of an address. */
822 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
824 1, /* size (0 = byte, 1 = short, 2 = long) */
826 FALSE
, /* pc_relative */
828 complain_overflow_dont
, /* complain_on_overflow */
829 bfd_elf_generic_reloc
, /* special_function */
830 "R_PPC64_ADDR16_HIGHEST", /* name */
831 FALSE
, /* partial_inplace */
833 0xffff, /* dst_mask */
834 FALSE
), /* pcrel_offset */
836 /* The bits 48-63 of an address, plus 1 if the contents of the low
837 16 bits, treated as a signed number, is negative. */
838 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
840 1, /* size (0 = byte, 1 = short, 2 = long) */
842 FALSE
, /* pc_relative */
844 complain_overflow_dont
, /* complain_on_overflow */
845 ppc64_elf_ha_reloc
, /* special_function */
846 "R_PPC64_ADDR16_HIGHESTA", /* name */
847 FALSE
, /* partial_inplace */
849 0xffff, /* dst_mask */
850 FALSE
), /* pcrel_offset */
852 /* Like ADDR64, but may be unaligned. */
853 HOWTO (R_PPC64_UADDR64
, /* type */
855 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
857 FALSE
, /* pc_relative */
859 complain_overflow_dont
, /* complain_on_overflow */
860 bfd_elf_generic_reloc
, /* special_function */
861 "R_PPC64_UADDR64", /* name */
862 FALSE
, /* partial_inplace */
864 ONES (64), /* dst_mask */
865 FALSE
), /* pcrel_offset */
867 /* 64-bit relative relocation. */
868 HOWTO (R_PPC64_REL64
, /* type */
870 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
872 TRUE
, /* pc_relative */
874 complain_overflow_dont
, /* complain_on_overflow */
875 bfd_elf_generic_reloc
, /* special_function */
876 "R_PPC64_REL64", /* name */
877 FALSE
, /* partial_inplace */
879 ONES (64), /* dst_mask */
880 TRUE
), /* pcrel_offset */
882 /* 64-bit relocation to the symbol's procedure linkage table. */
883 HOWTO (R_PPC64_PLT64
, /* type */
885 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
887 FALSE
, /* pc_relative */
889 complain_overflow_dont
, /* complain_on_overflow */
890 ppc64_elf_unhandled_reloc
, /* special_function */
891 "R_PPC64_PLT64", /* name */
892 FALSE
, /* partial_inplace */
894 ONES (64), /* dst_mask */
895 FALSE
), /* pcrel_offset */
897 /* 64-bit PC relative relocation to the symbol's procedure linkage
899 /* FIXME: R_PPC64_PLTREL64 not supported. */
900 HOWTO (R_PPC64_PLTREL64
, /* type */
902 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
904 TRUE
, /* pc_relative */
906 complain_overflow_dont
, /* complain_on_overflow */
907 ppc64_elf_unhandled_reloc
, /* special_function */
908 "R_PPC64_PLTREL64", /* name */
909 FALSE
, /* partial_inplace */
911 ONES (64), /* dst_mask */
912 TRUE
), /* pcrel_offset */
914 /* 16 bit TOC-relative relocation. */
916 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
917 HOWTO (R_PPC64_TOC16
, /* type */
919 1, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE
, /* pc_relative */
923 complain_overflow_signed
, /* complain_on_overflow */
924 ppc64_elf_toc_reloc
, /* special_function */
925 "R_PPC64_TOC16", /* name */
926 FALSE
, /* partial_inplace */
928 0xffff, /* dst_mask */
929 FALSE
), /* pcrel_offset */
931 /* 16 bit TOC-relative relocation without overflow. */
933 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
934 HOWTO (R_PPC64_TOC16_LO
, /* type */
936 1, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
, /* complain_on_overflow */
941 ppc64_elf_toc_reloc
, /* special_function */
942 "R_PPC64_TOC16_LO", /* name */
943 FALSE
, /* partial_inplace */
945 0xffff, /* dst_mask */
946 FALSE
), /* pcrel_offset */
948 /* 16 bit TOC-relative relocation, high 16 bits. */
950 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
951 HOWTO (R_PPC64_TOC16_HI
, /* type */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 ppc64_elf_toc_reloc
, /* special_function */
959 "R_PPC64_TOC16_HI", /* name */
960 FALSE
, /* partial_inplace */
962 0xffff, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
966 contents of the low 16 bits, treated as a signed number, is
969 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
970 HOWTO (R_PPC64_TOC16_HA
, /* type */
972 1, /* size (0 = byte, 1 = short, 2 = long) */
974 FALSE
, /* pc_relative */
976 complain_overflow_dont
, /* complain_on_overflow */
977 ppc64_elf_toc_ha_reloc
, /* special_function */
978 "R_PPC64_TOC16_HA", /* name */
979 FALSE
, /* partial_inplace */
981 0xffff, /* dst_mask */
982 FALSE
), /* pcrel_offset */
984 /* 64-bit relocation; insert value of TOC base (.TOC.). */
986 /* R_PPC64_TOC 51 doubleword64 .TOC. */
987 HOWTO (R_PPC64_TOC
, /* type */
989 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
991 FALSE
, /* pc_relative */
993 complain_overflow_bitfield
, /* complain_on_overflow */
994 ppc64_elf_toc64_reloc
, /* special_function */
995 "R_PPC64_TOC", /* name */
996 FALSE
, /* partial_inplace */
998 ONES (64), /* dst_mask */
999 FALSE
), /* pcrel_offset */
1001 /* Like R_PPC64_GOT16, but also informs the link editor that the
1002 value to relocate may (!) refer to a PLT entry which the link
1003 editor (a) may replace with the symbol value. If the link editor
1004 is unable to fully resolve the symbol, it may (b) create a PLT
1005 entry and store the address to the new PLT entry in the GOT.
1006 This permits lazy resolution of function symbols at run time.
1007 The link editor may also skip all of this and just (c) emit a
1008 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1009 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1010 HOWTO (R_PPC64_PLTGOT16
, /* type */
1012 1, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_signed
, /* complain_on_overflow */
1017 ppc64_elf_unhandled_reloc
, /* special_function */
1018 "R_PPC64_PLTGOT16", /* name */
1019 FALSE
, /* partial_inplace */
1021 0xffff, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* Like R_PPC64_PLTGOT16, but without overflow. */
1025 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1026 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_dont
, /* complain_on_overflow */
1033 ppc64_elf_unhandled_reloc
, /* special_function */
1034 "R_PPC64_PLTGOT16_LO", /* name */
1035 FALSE
, /* partial_inplace */
1037 0xffff, /* dst_mask */
1038 FALSE
), /* pcrel_offset */
1040 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1041 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1042 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1043 16, /* rightshift */
1044 1, /* size (0 = byte, 1 = short, 2 = long) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_dont
, /* complain_on_overflow */
1049 ppc64_elf_unhandled_reloc
, /* special_function */
1050 "R_PPC64_PLTGOT16_HI", /* name */
1051 FALSE
, /* partial_inplace */
1053 0xffff, /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1056 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1057 1 if the contents of the low 16 bits, treated as a signed number,
1059 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1060 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1061 16, /* rightshift */
1062 1, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE
, /* pc_relative */
1066 complain_overflow_dont
,/* complain_on_overflow */
1067 ppc64_elf_unhandled_reloc
, /* special_function */
1068 "R_PPC64_PLTGOT16_HA", /* name */
1069 FALSE
, /* partial_inplace */
1071 0xffff, /* dst_mask */
1072 FALSE
), /* pcrel_offset */
1074 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1075 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1077 1, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE
, /* pc_relative */
1081 complain_overflow_bitfield
, /* complain_on_overflow */
1082 bfd_elf_generic_reloc
, /* special_function */
1083 "R_PPC64_ADDR16_DS", /* name */
1084 FALSE
, /* partial_inplace */
1086 0xfffc, /* dst_mask */
1087 FALSE
), /* pcrel_offset */
1089 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1090 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1092 1, /* size (0 = byte, 1 = short, 2 = long) */
1094 FALSE
, /* pc_relative */
1096 complain_overflow_dont
,/* complain_on_overflow */
1097 bfd_elf_generic_reloc
, /* special_function */
1098 "R_PPC64_ADDR16_LO_DS",/* name */
1099 FALSE
, /* partial_inplace */
1101 0xfffc, /* dst_mask */
1102 FALSE
), /* pcrel_offset */
1104 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1105 HOWTO (R_PPC64_GOT16_DS
, /* type */
1107 1, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_signed
, /* complain_on_overflow */
1112 ppc64_elf_unhandled_reloc
, /* special_function */
1113 "R_PPC64_GOT16_DS", /* name */
1114 FALSE
, /* partial_inplace */
1116 0xfffc, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1120 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1122 1, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 ppc64_elf_unhandled_reloc
, /* special_function */
1128 "R_PPC64_GOT16_LO_DS", /* name */
1129 FALSE
, /* partial_inplace */
1131 0xfffc, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1135 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1137 1, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 ppc64_elf_unhandled_reloc
, /* special_function */
1143 "R_PPC64_PLT16_LO_DS", /* name */
1144 FALSE
, /* partial_inplace */
1146 0xfffc, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1150 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_bitfield
, /* complain_on_overflow */
1157 ppc64_elf_sectoff_reloc
, /* special_function */
1158 "R_PPC64_SECTOFF_DS", /* name */
1159 FALSE
, /* partial_inplace */
1161 0xfffc, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1165 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 ppc64_elf_sectoff_reloc
, /* special_function */
1173 "R_PPC64_SECTOFF_LO_DS",/* name */
1174 FALSE
, /* partial_inplace */
1176 0xfffc, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1180 HOWTO (R_PPC64_TOC16_DS
, /* type */
1182 1, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE
, /* pc_relative */
1186 complain_overflow_signed
, /* complain_on_overflow */
1187 ppc64_elf_toc_reloc
, /* special_function */
1188 "R_PPC64_TOC16_DS", /* name */
1189 FALSE
, /* partial_inplace */
1191 0xfffc, /* dst_mask */
1192 FALSE
), /* pcrel_offset */
1194 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1195 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1197 1, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 ppc64_elf_toc_reloc
, /* special_function */
1203 "R_PPC64_TOC16_LO_DS", /* name */
1204 FALSE
, /* partial_inplace */
1206 0xfffc, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1210 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1211 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1213 1, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE
, /* pc_relative */
1217 complain_overflow_signed
, /* complain_on_overflow */
1218 ppc64_elf_unhandled_reloc
, /* special_function */
1219 "R_PPC64_PLTGOT16_DS", /* name */
1220 FALSE
, /* partial_inplace */
1222 0xfffc, /* dst_mask */
1223 FALSE
), /* pcrel_offset */
1225 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1226 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1227 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1229 1, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE
, /* pc_relative */
1233 complain_overflow_dont
, /* complain_on_overflow */
1234 ppc64_elf_unhandled_reloc
, /* special_function */
1235 "R_PPC64_PLTGOT16_LO_DS",/* name */
1236 FALSE
, /* partial_inplace */
1238 0xfffc, /* dst_mask */
1239 FALSE
), /* pcrel_offset */
1241 /* Marker relocs for TLS. */
1244 2, /* size (0 = byte, 1 = short, 2 = long) */
1246 FALSE
, /* pc_relative */
1248 complain_overflow_dont
, /* complain_on_overflow */
1249 bfd_elf_generic_reloc
, /* special_function */
1250 "R_PPC64_TLS", /* name */
1251 FALSE
, /* partial_inplace */
1254 FALSE
), /* pcrel_offset */
1256 HOWTO (R_PPC64_TLSGD
,
1258 2, /* size (0 = byte, 1 = short, 2 = long) */
1260 FALSE
, /* pc_relative */
1262 complain_overflow_dont
, /* complain_on_overflow */
1263 bfd_elf_generic_reloc
, /* special_function */
1264 "R_PPC64_TLSGD", /* name */
1265 FALSE
, /* partial_inplace */
1268 FALSE
), /* pcrel_offset */
1270 HOWTO (R_PPC64_TLSLD
,
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1274 FALSE
, /* pc_relative */
1276 complain_overflow_dont
, /* complain_on_overflow */
1277 bfd_elf_generic_reloc
, /* special_function */
1278 "R_PPC64_TLSLD", /* name */
1279 FALSE
, /* partial_inplace */
1282 FALSE
), /* pcrel_offset */
1284 /* Computes the load module index of the load module that contains the
1285 definition of its TLS sym. */
1286 HOWTO (R_PPC64_DTPMOD64
,
1288 4, /* size (0 = byte, 1 = short, 2 = long) */
1290 FALSE
, /* pc_relative */
1292 complain_overflow_dont
, /* complain_on_overflow */
1293 ppc64_elf_unhandled_reloc
, /* special_function */
1294 "R_PPC64_DTPMOD64", /* name */
1295 FALSE
, /* partial_inplace */
1297 ONES (64), /* dst_mask */
1298 FALSE
), /* pcrel_offset */
1300 /* Computes a dtv-relative displacement, the difference between the value
1301 of sym+add and the base address of the thread-local storage block that
1302 contains the definition of sym, minus 0x8000. */
1303 HOWTO (R_PPC64_DTPREL64
,
1305 4, /* size (0 = byte, 1 = short, 2 = long) */
1307 FALSE
, /* pc_relative */
1309 complain_overflow_dont
, /* complain_on_overflow */
1310 ppc64_elf_unhandled_reloc
, /* special_function */
1311 "R_PPC64_DTPREL64", /* name */
1312 FALSE
, /* partial_inplace */
1314 ONES (64), /* dst_mask */
1315 FALSE
), /* pcrel_offset */
1317 /* A 16 bit dtprel reloc. */
1318 HOWTO (R_PPC64_DTPREL16
,
1320 1, /* size (0 = byte, 1 = short, 2 = long) */
1322 FALSE
, /* pc_relative */
1324 complain_overflow_signed
, /* complain_on_overflow */
1325 ppc64_elf_unhandled_reloc
, /* special_function */
1326 "R_PPC64_DTPREL16", /* name */
1327 FALSE
, /* partial_inplace */
1329 0xffff, /* dst_mask */
1330 FALSE
), /* pcrel_offset */
1332 /* Like DTPREL16, but no overflow. */
1333 HOWTO (R_PPC64_DTPREL16_LO
,
1335 1, /* size (0 = byte, 1 = short, 2 = long) */
1337 FALSE
, /* pc_relative */
1339 complain_overflow_dont
, /* complain_on_overflow */
1340 ppc64_elf_unhandled_reloc
, /* special_function */
1341 "R_PPC64_DTPREL16_LO", /* name */
1342 FALSE
, /* partial_inplace */
1344 0xffff, /* dst_mask */
1345 FALSE
), /* pcrel_offset */
1347 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1348 HOWTO (R_PPC64_DTPREL16_HI
,
1349 16, /* rightshift */
1350 1, /* size (0 = byte, 1 = short, 2 = long) */
1352 FALSE
, /* pc_relative */
1354 complain_overflow_dont
, /* complain_on_overflow */
1355 ppc64_elf_unhandled_reloc
, /* special_function */
1356 "R_PPC64_DTPREL16_HI", /* name */
1357 FALSE
, /* partial_inplace */
1359 0xffff, /* dst_mask */
1360 FALSE
), /* pcrel_offset */
1362 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1363 HOWTO (R_PPC64_DTPREL16_HA
,
1364 16, /* rightshift */
1365 1, /* size (0 = byte, 1 = short, 2 = long) */
1367 FALSE
, /* pc_relative */
1369 complain_overflow_dont
, /* complain_on_overflow */
1370 ppc64_elf_unhandled_reloc
, /* special_function */
1371 "R_PPC64_DTPREL16_HA", /* name */
1372 FALSE
, /* partial_inplace */
1374 0xffff, /* dst_mask */
1375 FALSE
), /* pcrel_offset */
1377 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1378 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1379 32, /* rightshift */
1380 1, /* size (0 = byte, 1 = short, 2 = long) */
1382 FALSE
, /* pc_relative */
1384 complain_overflow_dont
, /* complain_on_overflow */
1385 ppc64_elf_unhandled_reloc
, /* special_function */
1386 "R_PPC64_DTPREL16_HIGHER", /* name */
1387 FALSE
, /* partial_inplace */
1389 0xffff, /* dst_mask */
1390 FALSE
), /* pcrel_offset */
1392 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1393 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1394 32, /* rightshift */
1395 1, /* size (0 = byte, 1 = short, 2 = long) */
1397 FALSE
, /* pc_relative */
1399 complain_overflow_dont
, /* complain_on_overflow */
1400 ppc64_elf_unhandled_reloc
, /* special_function */
1401 "R_PPC64_DTPREL16_HIGHERA", /* name */
1402 FALSE
, /* partial_inplace */
1404 0xffff, /* dst_mask */
1405 FALSE
), /* pcrel_offset */
1407 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1408 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1409 48, /* rightshift */
1410 1, /* size (0 = byte, 1 = short, 2 = long) */
1412 FALSE
, /* pc_relative */
1414 complain_overflow_dont
, /* complain_on_overflow */
1415 ppc64_elf_unhandled_reloc
, /* special_function */
1416 "R_PPC64_DTPREL16_HIGHEST", /* name */
1417 FALSE
, /* partial_inplace */
1419 0xffff, /* dst_mask */
1420 FALSE
), /* pcrel_offset */
1422 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1423 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1424 48, /* rightshift */
1425 1, /* size (0 = byte, 1 = short, 2 = long) */
1427 FALSE
, /* pc_relative */
1429 complain_overflow_dont
, /* complain_on_overflow */
1430 ppc64_elf_unhandled_reloc
, /* special_function */
1431 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1432 FALSE
, /* partial_inplace */
1434 0xffff, /* dst_mask */
1435 FALSE
), /* pcrel_offset */
1437 /* Like DTPREL16, but for insns with a DS field. */
1438 HOWTO (R_PPC64_DTPREL16_DS
,
1440 1, /* size (0 = byte, 1 = short, 2 = long) */
1442 FALSE
, /* pc_relative */
1444 complain_overflow_signed
, /* complain_on_overflow */
1445 ppc64_elf_unhandled_reloc
, /* special_function */
1446 "R_PPC64_DTPREL16_DS", /* name */
1447 FALSE
, /* partial_inplace */
1449 0xfffc, /* dst_mask */
1450 FALSE
), /* pcrel_offset */
1452 /* Like DTPREL16_DS, but no overflow. */
1453 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1455 1, /* size (0 = byte, 1 = short, 2 = long) */
1457 FALSE
, /* pc_relative */
1459 complain_overflow_dont
, /* complain_on_overflow */
1460 ppc64_elf_unhandled_reloc
, /* special_function */
1461 "R_PPC64_DTPREL16_LO_DS", /* name */
1462 FALSE
, /* partial_inplace */
1464 0xfffc, /* dst_mask */
1465 FALSE
), /* pcrel_offset */
1467 /* Computes a tp-relative displacement, the difference between the value of
1468 sym+add and the value of the thread pointer (r13). */
1469 HOWTO (R_PPC64_TPREL64
,
1471 4, /* size (0 = byte, 1 = short, 2 = long) */
1473 FALSE
, /* pc_relative */
1475 complain_overflow_dont
, /* complain_on_overflow */
1476 ppc64_elf_unhandled_reloc
, /* special_function */
1477 "R_PPC64_TPREL64", /* name */
1478 FALSE
, /* partial_inplace */
1480 ONES (64), /* dst_mask */
1481 FALSE
), /* pcrel_offset */
1483 /* A 16 bit tprel reloc. */
1484 HOWTO (R_PPC64_TPREL16
,
1486 1, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE
, /* pc_relative */
1490 complain_overflow_signed
, /* complain_on_overflow */
1491 ppc64_elf_unhandled_reloc
, /* special_function */
1492 "R_PPC64_TPREL16", /* name */
1493 FALSE
, /* partial_inplace */
1495 0xffff, /* dst_mask */
1496 FALSE
), /* pcrel_offset */
1498 /* Like TPREL16, but no overflow. */
1499 HOWTO (R_PPC64_TPREL16_LO
,
1501 1, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_dont
, /* complain_on_overflow */
1506 ppc64_elf_unhandled_reloc
, /* special_function */
1507 "R_PPC64_TPREL16_LO", /* name */
1508 FALSE
, /* partial_inplace */
1510 0xffff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1513 /* Like TPREL16_LO, but next higher group of 16 bits. */
1514 HOWTO (R_PPC64_TPREL16_HI
,
1515 16, /* rightshift */
1516 1, /* size (0 = byte, 1 = short, 2 = long) */
1518 FALSE
, /* pc_relative */
1520 complain_overflow_dont
, /* complain_on_overflow */
1521 ppc64_elf_unhandled_reloc
, /* special_function */
1522 "R_PPC64_TPREL16_HI", /* name */
1523 FALSE
, /* partial_inplace */
1525 0xffff, /* dst_mask */
1526 FALSE
), /* pcrel_offset */
1528 /* Like TPREL16_HI, but adjust for low 16 bits. */
1529 HOWTO (R_PPC64_TPREL16_HA
,
1530 16, /* rightshift */
1531 1, /* size (0 = byte, 1 = short, 2 = long) */
1533 FALSE
, /* pc_relative */
1535 complain_overflow_dont
, /* complain_on_overflow */
1536 ppc64_elf_unhandled_reloc
, /* special_function */
1537 "R_PPC64_TPREL16_HA", /* name */
1538 FALSE
, /* partial_inplace */
1540 0xffff, /* dst_mask */
1541 FALSE
), /* pcrel_offset */
1543 /* Like TPREL16_HI, but next higher group of 16 bits. */
1544 HOWTO (R_PPC64_TPREL16_HIGHER
,
1545 32, /* rightshift */
1546 1, /* size (0 = byte, 1 = short, 2 = long) */
1548 FALSE
, /* pc_relative */
1550 complain_overflow_dont
, /* complain_on_overflow */
1551 ppc64_elf_unhandled_reloc
, /* special_function */
1552 "R_PPC64_TPREL16_HIGHER", /* name */
1553 FALSE
, /* partial_inplace */
1555 0xffff, /* dst_mask */
1556 FALSE
), /* pcrel_offset */
1558 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1559 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1560 32, /* rightshift */
1561 1, /* size (0 = byte, 1 = short, 2 = long) */
1563 FALSE
, /* pc_relative */
1565 complain_overflow_dont
, /* complain_on_overflow */
1566 ppc64_elf_unhandled_reloc
, /* special_function */
1567 "R_PPC64_TPREL16_HIGHERA", /* name */
1568 FALSE
, /* partial_inplace */
1570 0xffff, /* dst_mask */
1571 FALSE
), /* pcrel_offset */
1573 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1574 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1575 48, /* rightshift */
1576 1, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE
, /* pc_relative */
1580 complain_overflow_dont
, /* complain_on_overflow */
1581 ppc64_elf_unhandled_reloc
, /* special_function */
1582 "R_PPC64_TPREL16_HIGHEST", /* name */
1583 FALSE
, /* partial_inplace */
1585 0xffff, /* dst_mask */
1586 FALSE
), /* pcrel_offset */
1588 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1589 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1590 48, /* rightshift */
1591 1, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE
, /* pc_relative */
1595 complain_overflow_dont
, /* complain_on_overflow */
1596 ppc64_elf_unhandled_reloc
, /* special_function */
1597 "R_PPC64_TPREL16_HIGHESTA", /* name */
1598 FALSE
, /* partial_inplace */
1600 0xffff, /* dst_mask */
1601 FALSE
), /* pcrel_offset */
1603 /* Like TPREL16, but for insns with a DS field. */
1604 HOWTO (R_PPC64_TPREL16_DS
,
1606 1, /* size (0 = byte, 1 = short, 2 = long) */
1608 FALSE
, /* pc_relative */
1610 complain_overflow_signed
, /* complain_on_overflow */
1611 ppc64_elf_unhandled_reloc
, /* special_function */
1612 "R_PPC64_TPREL16_DS", /* name */
1613 FALSE
, /* partial_inplace */
1615 0xfffc, /* dst_mask */
1616 FALSE
), /* pcrel_offset */
1618 /* Like TPREL16_DS, but no overflow. */
1619 HOWTO (R_PPC64_TPREL16_LO_DS
,
1621 1, /* size (0 = byte, 1 = short, 2 = long) */
1623 FALSE
, /* pc_relative */
1625 complain_overflow_dont
, /* complain_on_overflow */
1626 ppc64_elf_unhandled_reloc
, /* special_function */
1627 "R_PPC64_TPREL16_LO_DS", /* name */
1628 FALSE
, /* partial_inplace */
1630 0xfffc, /* dst_mask */
1631 FALSE
), /* pcrel_offset */
1633 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1634 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1635 to the first entry relative to the TOC base (r2). */
1636 HOWTO (R_PPC64_GOT_TLSGD16
,
1638 1, /* size (0 = byte, 1 = short, 2 = long) */
1640 FALSE
, /* pc_relative */
1642 complain_overflow_signed
, /* complain_on_overflow */
1643 ppc64_elf_unhandled_reloc
, /* special_function */
1644 "R_PPC64_GOT_TLSGD16", /* name */
1645 FALSE
, /* partial_inplace */
1647 0xffff, /* dst_mask */
1648 FALSE
), /* pcrel_offset */
1650 /* Like GOT_TLSGD16, but no overflow. */
1651 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1653 1, /* size (0 = byte, 1 = short, 2 = long) */
1655 FALSE
, /* pc_relative */
1657 complain_overflow_dont
, /* complain_on_overflow */
1658 ppc64_elf_unhandled_reloc
, /* special_function */
1659 "R_PPC64_GOT_TLSGD16_LO", /* name */
1660 FALSE
, /* partial_inplace */
1662 0xffff, /* dst_mask */
1663 FALSE
), /* pcrel_offset */
1665 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1666 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1667 16, /* rightshift */
1668 1, /* size (0 = byte, 1 = short, 2 = long) */
1670 FALSE
, /* pc_relative */
1672 complain_overflow_dont
, /* complain_on_overflow */
1673 ppc64_elf_unhandled_reloc
, /* special_function */
1674 "R_PPC64_GOT_TLSGD16_HI", /* name */
1675 FALSE
, /* partial_inplace */
1677 0xffff, /* dst_mask */
1678 FALSE
), /* pcrel_offset */
1680 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1681 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1682 16, /* rightshift */
1683 1, /* size (0 = byte, 1 = short, 2 = long) */
1685 FALSE
, /* pc_relative */
1687 complain_overflow_dont
, /* complain_on_overflow */
1688 ppc64_elf_unhandled_reloc
, /* special_function */
1689 "R_PPC64_GOT_TLSGD16_HA", /* name */
1690 FALSE
, /* partial_inplace */
1692 0xffff, /* dst_mask */
1693 FALSE
), /* pcrel_offset */
1695 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1696 with values (sym+add)@dtpmod and zero, and computes the offset to the
1697 first entry relative to the TOC base (r2). */
1698 HOWTO (R_PPC64_GOT_TLSLD16
,
1700 1, /* size (0 = byte, 1 = short, 2 = long) */
1702 FALSE
, /* pc_relative */
1704 complain_overflow_signed
, /* complain_on_overflow */
1705 ppc64_elf_unhandled_reloc
, /* special_function */
1706 "R_PPC64_GOT_TLSLD16", /* name */
1707 FALSE
, /* partial_inplace */
1709 0xffff, /* dst_mask */
1710 FALSE
), /* pcrel_offset */
1712 /* Like GOT_TLSLD16, but no overflow. */
1713 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1715 1, /* size (0 = byte, 1 = short, 2 = long) */
1717 FALSE
, /* pc_relative */
1719 complain_overflow_dont
, /* complain_on_overflow */
1720 ppc64_elf_unhandled_reloc
, /* special_function */
1721 "R_PPC64_GOT_TLSLD16_LO", /* name */
1722 FALSE
, /* partial_inplace */
1724 0xffff, /* dst_mask */
1725 FALSE
), /* pcrel_offset */
1727 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1728 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1729 16, /* rightshift */
1730 1, /* size (0 = byte, 1 = short, 2 = long) */
1732 FALSE
, /* pc_relative */
1734 complain_overflow_dont
, /* complain_on_overflow */
1735 ppc64_elf_unhandled_reloc
, /* special_function */
1736 "R_PPC64_GOT_TLSLD16_HI", /* name */
1737 FALSE
, /* partial_inplace */
1739 0xffff, /* dst_mask */
1740 FALSE
), /* pcrel_offset */
1742 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1743 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1744 16, /* rightshift */
1745 1, /* size (0 = byte, 1 = short, 2 = long) */
1747 FALSE
, /* pc_relative */
1749 complain_overflow_dont
, /* complain_on_overflow */
1750 ppc64_elf_unhandled_reloc
, /* special_function */
1751 "R_PPC64_GOT_TLSLD16_HA", /* name */
1752 FALSE
, /* partial_inplace */
1754 0xffff, /* dst_mask */
1755 FALSE
), /* pcrel_offset */
1757 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1758 the offset to the entry relative to the TOC base (r2). */
1759 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1761 1, /* size (0 = byte, 1 = short, 2 = long) */
1763 FALSE
, /* pc_relative */
1765 complain_overflow_signed
, /* complain_on_overflow */
1766 ppc64_elf_unhandled_reloc
, /* special_function */
1767 "R_PPC64_GOT_DTPREL16_DS", /* name */
1768 FALSE
, /* partial_inplace */
1770 0xfffc, /* dst_mask */
1771 FALSE
), /* pcrel_offset */
1773 /* Like GOT_DTPREL16_DS, but no overflow. */
1774 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1776 1, /* size (0 = byte, 1 = short, 2 = long) */
1778 FALSE
, /* pc_relative */
1780 complain_overflow_dont
, /* complain_on_overflow */
1781 ppc64_elf_unhandled_reloc
, /* special_function */
1782 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1783 FALSE
, /* partial_inplace */
1785 0xfffc, /* dst_mask */
1786 FALSE
), /* pcrel_offset */
1788 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1789 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1790 16, /* rightshift */
1791 1, /* size (0 = byte, 1 = short, 2 = long) */
1793 FALSE
, /* pc_relative */
1795 complain_overflow_dont
, /* complain_on_overflow */
1796 ppc64_elf_unhandled_reloc
, /* special_function */
1797 "R_PPC64_GOT_DTPREL16_HI", /* name */
1798 FALSE
, /* partial_inplace */
1800 0xffff, /* dst_mask */
1801 FALSE
), /* pcrel_offset */
1803 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1804 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1805 16, /* rightshift */
1806 1, /* size (0 = byte, 1 = short, 2 = long) */
1808 FALSE
, /* pc_relative */
1810 complain_overflow_dont
, /* complain_on_overflow */
1811 ppc64_elf_unhandled_reloc
, /* special_function */
1812 "R_PPC64_GOT_DTPREL16_HA", /* name */
1813 FALSE
, /* partial_inplace */
1815 0xffff, /* dst_mask */
1816 FALSE
), /* pcrel_offset */
1818 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1819 offset to the entry relative to the TOC base (r2). */
1820 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1822 1, /* size (0 = byte, 1 = short, 2 = long) */
1824 FALSE
, /* pc_relative */
1826 complain_overflow_signed
, /* complain_on_overflow */
1827 ppc64_elf_unhandled_reloc
, /* special_function */
1828 "R_PPC64_GOT_TPREL16_DS", /* name */
1829 FALSE
, /* partial_inplace */
1831 0xfffc, /* dst_mask */
1832 FALSE
), /* pcrel_offset */
1834 /* Like GOT_TPREL16_DS, but no overflow. */
1835 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1837 1, /* size (0 = byte, 1 = short, 2 = long) */
1839 FALSE
, /* pc_relative */
1841 complain_overflow_dont
, /* complain_on_overflow */
1842 ppc64_elf_unhandled_reloc
, /* special_function */
1843 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1844 FALSE
, /* partial_inplace */
1846 0xfffc, /* dst_mask */
1847 FALSE
), /* pcrel_offset */
1849 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1850 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1851 16, /* rightshift */
1852 1, /* size (0 = byte, 1 = short, 2 = long) */
1854 FALSE
, /* pc_relative */
1856 complain_overflow_dont
, /* complain_on_overflow */
1857 ppc64_elf_unhandled_reloc
, /* special_function */
1858 "R_PPC64_GOT_TPREL16_HI", /* name */
1859 FALSE
, /* partial_inplace */
1861 0xffff, /* dst_mask */
1862 FALSE
), /* pcrel_offset */
1864 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1865 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1866 16, /* rightshift */
1867 1, /* size (0 = byte, 1 = short, 2 = long) */
1869 FALSE
, /* pc_relative */
1871 complain_overflow_dont
, /* complain_on_overflow */
1872 ppc64_elf_unhandled_reloc
, /* special_function */
1873 "R_PPC64_GOT_TPREL16_HA", /* name */
1874 FALSE
, /* partial_inplace */
1876 0xffff, /* dst_mask */
1877 FALSE
), /* pcrel_offset */
1879 HOWTO (R_PPC64_JMP_IREL
, /* type */
1881 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1883 FALSE
, /* pc_relative */
1885 complain_overflow_dont
, /* complain_on_overflow */
1886 ppc64_elf_unhandled_reloc
, /* special_function */
1887 "R_PPC64_JMP_IREL", /* name */
1888 FALSE
, /* partial_inplace */
1891 FALSE
), /* pcrel_offset */
1893 HOWTO (R_PPC64_IRELATIVE
, /* type */
1895 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1897 FALSE
, /* pc_relative */
1899 complain_overflow_dont
, /* complain_on_overflow */
1900 bfd_elf_generic_reloc
, /* special_function */
1901 "R_PPC64_IRELATIVE", /* name */
1902 FALSE
, /* partial_inplace */
1904 ONES (64), /* dst_mask */
1905 FALSE
), /* pcrel_offset */
1907 /* A 16 bit relative relocation. */
1908 HOWTO (R_PPC64_REL16
, /* type */
1910 1, /* size (0 = byte, 1 = short, 2 = long) */
1912 TRUE
, /* pc_relative */
1914 complain_overflow_bitfield
, /* complain_on_overflow */
1915 bfd_elf_generic_reloc
, /* special_function */
1916 "R_PPC64_REL16", /* name */
1917 FALSE
, /* partial_inplace */
1919 0xffff, /* dst_mask */
1920 TRUE
), /* pcrel_offset */
1922 /* A 16 bit relative relocation without overflow. */
1923 HOWTO (R_PPC64_REL16_LO
, /* type */
1925 1, /* size (0 = byte, 1 = short, 2 = long) */
1927 TRUE
, /* pc_relative */
1929 complain_overflow_dont
,/* complain_on_overflow */
1930 bfd_elf_generic_reloc
, /* special_function */
1931 "R_PPC64_REL16_LO", /* name */
1932 FALSE
, /* partial_inplace */
1934 0xffff, /* dst_mask */
1935 TRUE
), /* pcrel_offset */
1937 /* The high order 16 bits of a relative address. */
1938 HOWTO (R_PPC64_REL16_HI
, /* type */
1939 16, /* rightshift */
1940 1, /* size (0 = byte, 1 = short, 2 = long) */
1942 TRUE
, /* pc_relative */
1944 complain_overflow_dont
, /* complain_on_overflow */
1945 bfd_elf_generic_reloc
, /* special_function */
1946 "R_PPC64_REL16_HI", /* name */
1947 FALSE
, /* partial_inplace */
1949 0xffff, /* dst_mask */
1950 TRUE
), /* pcrel_offset */
1952 /* The high order 16 bits of a relative address, plus 1 if the contents of
1953 the low 16 bits, treated as a signed number, is negative. */
1954 HOWTO (R_PPC64_REL16_HA
, /* type */
1955 16, /* rightshift */
1956 1, /* size (0 = byte, 1 = short, 2 = long) */
1958 TRUE
, /* pc_relative */
1960 complain_overflow_dont
, /* complain_on_overflow */
1961 ppc64_elf_ha_reloc
, /* special_function */
1962 "R_PPC64_REL16_HA", /* name */
1963 FALSE
, /* partial_inplace */
1965 0xffff, /* dst_mask */
1966 TRUE
), /* pcrel_offset */
1968 /* GNU extension to record C++ vtable hierarchy. */
1969 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1971 0, /* size (0 = byte, 1 = short, 2 = long) */
1973 FALSE
, /* pc_relative */
1975 complain_overflow_dont
, /* complain_on_overflow */
1976 NULL
, /* special_function */
1977 "R_PPC64_GNU_VTINHERIT", /* name */
1978 FALSE
, /* partial_inplace */
1981 FALSE
), /* pcrel_offset */
1983 /* GNU extension to record C++ vtable member usage. */
1984 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1986 0, /* size (0 = byte, 1 = short, 2 = long) */
1988 FALSE
, /* pc_relative */
1990 complain_overflow_dont
, /* complain_on_overflow */
1991 NULL
, /* special_function */
1992 "R_PPC64_GNU_VTENTRY", /* name */
1993 FALSE
, /* partial_inplace */
1996 FALSE
), /* pcrel_offset */
2000 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2004 ppc_howto_init (void)
2006 unsigned int i
, type
;
2009 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2012 type
= ppc64_elf_howto_raw
[i
].type
;
2013 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
2014 / sizeof (ppc64_elf_howto_table
[0])));
2015 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2019 static reloc_howto_type
*
2020 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2021 bfd_reloc_code_real_type code
)
2023 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2025 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2026 /* Initialize howto table if needed. */
2034 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2036 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2038 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2040 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2042 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2044 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2046 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2048 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2050 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2052 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2054 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2056 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2058 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2060 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2062 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2064 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2066 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2068 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2070 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2072 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2074 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2076 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2078 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2080 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2082 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2084 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2086 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2088 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2090 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2092 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2094 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2096 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2098 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2100 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2102 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2104 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2106 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2108 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2110 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2112 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2114 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2116 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2118 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2120 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2122 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2124 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2126 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2128 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2130 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2132 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2134 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2136 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2138 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2140 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2142 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2144 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2146 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2148 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2150 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2152 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2154 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2156 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2158 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2160 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2162 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2164 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2166 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2168 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2170 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2172 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2174 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2176 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2178 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2180 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2182 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2184 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2186 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2188 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2190 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2192 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2194 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2196 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2198 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2200 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2202 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2204 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2206 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2208 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2210 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2212 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2214 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2216 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2218 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2220 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2222 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2224 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2226 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2228 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2230 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2232 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2234 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2236 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2238 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2240 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2242 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2244 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2246 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2250 return ppc64_elf_howto_table
[r
];
2253 static reloc_howto_type
*
2254 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2260 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2262 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2263 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2264 return &ppc64_elf_howto_raw
[i
];
2269 /* Set the howto pointer for a PowerPC ELF reloc. */
2272 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2273 Elf_Internal_Rela
*dst
)
2277 /* Initialize howto table if needed. */
2278 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2281 type
= ELF64_R_TYPE (dst
->r_info
);
2282 if (type
>= (sizeof (ppc64_elf_howto_table
)
2283 / sizeof (ppc64_elf_howto_table
[0])))
2285 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2287 type
= R_PPC64_NONE
;
2289 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2292 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2294 static bfd_reloc_status_type
2295 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2296 void *data
, asection
*input_section
,
2297 bfd
*output_bfd
, char **error_message
)
2299 /* If this is a relocatable link (output_bfd test tells us), just
2300 call the generic function. Any adjustment will be done at final
2302 if (output_bfd
!= NULL
)
2303 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2304 input_section
, output_bfd
, error_message
);
2306 /* Adjust the addend for sign extension of the low 16 bits.
2307 We won't actually be using the low 16 bits, so trashing them
2309 reloc_entry
->addend
+= 0x8000;
2310 return bfd_reloc_continue
;
2313 static bfd_reloc_status_type
2314 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2315 void *data
, asection
*input_section
,
2316 bfd
*output_bfd
, char **error_message
)
2318 if (output_bfd
!= NULL
)
2319 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2320 input_section
, output_bfd
, error_message
);
2322 if (strcmp (symbol
->section
->name
, ".opd") == 0
2323 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2325 bfd_vma dest
= opd_entry_value (symbol
->section
,
2326 symbol
->value
+ reloc_entry
->addend
,
2328 if (dest
!= (bfd_vma
) -1)
2329 reloc_entry
->addend
= dest
- (symbol
->value
2330 + symbol
->section
->output_section
->vma
2331 + symbol
->section
->output_offset
);
2333 return bfd_reloc_continue
;
2336 static bfd_reloc_status_type
2337 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2338 void *data
, asection
*input_section
,
2339 bfd
*output_bfd
, char **error_message
)
2342 enum elf_ppc64_reloc_type r_type
;
2343 bfd_size_type octets
;
2344 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2345 bfd_boolean is_power4
= FALSE
;
2347 /* If this is a relocatable link (output_bfd test tells us), just
2348 call the generic function. Any adjustment will be done at final
2350 if (output_bfd
!= NULL
)
2351 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2352 input_section
, output_bfd
, error_message
);
2354 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2355 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2356 insn
&= ~(0x01 << 21);
2357 r_type
= reloc_entry
->howto
->type
;
2358 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2359 || r_type
== R_PPC64_REL14_BRTAKEN
)
2360 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2364 /* Set 'a' bit. This is 0b00010 in BO field for branch
2365 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2366 for branch on CTR insns (BO == 1a00t or 1a01t). */
2367 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2369 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2379 if (!bfd_is_com_section (symbol
->section
))
2380 target
= symbol
->value
;
2381 target
+= symbol
->section
->output_section
->vma
;
2382 target
+= symbol
->section
->output_offset
;
2383 target
+= reloc_entry
->addend
;
2385 from
= (reloc_entry
->address
2386 + input_section
->output_offset
2387 + input_section
->output_section
->vma
);
2389 /* Invert 'y' bit if not the default. */
2390 if ((bfd_signed_vma
) (target
- from
) < 0)
2393 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2395 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2396 input_section
, output_bfd
, error_message
);
2399 static bfd_reloc_status_type
2400 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2401 void *data
, asection
*input_section
,
2402 bfd
*output_bfd
, char **error_message
)
2404 /* If this is a relocatable link (output_bfd test tells us), just
2405 call the generic function. Any adjustment will be done at final
2407 if (output_bfd
!= NULL
)
2408 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2409 input_section
, output_bfd
, error_message
);
2411 /* Subtract the symbol section base address. */
2412 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2413 return bfd_reloc_continue
;
2416 static bfd_reloc_status_type
2417 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2418 void *data
, asection
*input_section
,
2419 bfd
*output_bfd
, char **error_message
)
2421 /* If this is a relocatable link (output_bfd test tells us), just
2422 call the generic function. Any adjustment will be done at final
2424 if (output_bfd
!= NULL
)
2425 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2426 input_section
, output_bfd
, error_message
);
2428 /* Subtract the symbol section base address. */
2429 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2431 /* Adjust the addend for sign extension of the low 16 bits. */
2432 reloc_entry
->addend
+= 0x8000;
2433 return bfd_reloc_continue
;
2436 static bfd_reloc_status_type
2437 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2438 void *data
, asection
*input_section
,
2439 bfd
*output_bfd
, char **error_message
)
2443 /* If this is a relocatable link (output_bfd test tells us), just
2444 call the generic function. Any adjustment will be done at final
2446 if (output_bfd
!= NULL
)
2447 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2448 input_section
, output_bfd
, error_message
);
2450 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2452 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2454 /* Subtract the TOC base address. */
2455 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2456 return bfd_reloc_continue
;
2459 static bfd_reloc_status_type
2460 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2461 void *data
, asection
*input_section
,
2462 bfd
*output_bfd
, char **error_message
)
2466 /* If this is a relocatable link (output_bfd test tells us), just
2467 call the generic function. Any adjustment will be done at final
2469 if (output_bfd
!= NULL
)
2470 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2471 input_section
, output_bfd
, error_message
);
2473 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2475 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2477 /* Subtract the TOC base address. */
2478 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2480 /* Adjust the addend for sign extension of the low 16 bits. */
2481 reloc_entry
->addend
+= 0x8000;
2482 return bfd_reloc_continue
;
2485 static bfd_reloc_status_type
2486 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2487 void *data
, asection
*input_section
,
2488 bfd
*output_bfd
, char **error_message
)
2491 bfd_size_type octets
;
2493 /* If this is a relocatable link (output_bfd test tells us), just
2494 call the generic function. Any adjustment will be done at final
2496 if (output_bfd
!= NULL
)
2497 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2498 input_section
, output_bfd
, error_message
);
2500 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2502 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2504 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2505 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2506 return bfd_reloc_ok
;
2509 static bfd_reloc_status_type
2510 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2511 void *data
, asection
*input_section
,
2512 bfd
*output_bfd
, char **error_message
)
2514 /* If this is a relocatable link (output_bfd test tells us), just
2515 call the generic function. Any adjustment will be done at final
2517 if (output_bfd
!= NULL
)
2518 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2519 input_section
, output_bfd
, error_message
);
2521 if (error_message
!= NULL
)
2523 static char buf
[60];
2524 sprintf (buf
, "generic linker can't handle %s",
2525 reloc_entry
->howto
->name
);
2526 *error_message
= buf
;
2528 return bfd_reloc_dangerous
;
2531 /* Track GOT entries needed for a given symbol. We might need more
2532 than one got entry per symbol. */
2535 struct got_entry
*next
;
2537 /* The symbol addend that we'll be placing in the GOT. */
2540 /* Unlike other ELF targets, we use separate GOT entries for the same
2541 symbol referenced from different input files. This is to support
2542 automatic multiple TOC/GOT sections, where the TOC base can vary
2543 from one input file to another. After partitioning into TOC groups
2544 we merge entries within the group.
2546 Point to the BFD owning this GOT entry. */
2549 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2550 TLS_TPREL or TLS_DTPREL for tls entries. */
2551 unsigned char tls_type
;
2553 /* Non-zero if got.ent points to real entry. */
2554 unsigned char is_indirect
;
2556 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2559 bfd_signed_vma refcount
;
2561 struct got_entry
*ent
;
2565 /* The same for PLT. */
2568 struct plt_entry
*next
;
2574 bfd_signed_vma refcount
;
2579 struct ppc64_elf_obj_tdata
2581 struct elf_obj_tdata elf
;
2583 /* Shortcuts to dynamic linker sections. */
2587 /* Used during garbage collection. We attach global symbols defined
2588 on removed .opd entries to this section so that the sym is removed. */
2589 asection
*deleted_section
;
2591 /* TLS local dynamic got entry handling. Support for multiple GOT
2592 sections means we potentially need one of these for each input bfd. */
2593 struct got_entry tlsld_got
;
2595 /* A copy of relocs before they are modified for --emit-relocs. */
2596 Elf_Internal_Rela
*opd_relocs
;
2598 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2599 the reloc to be in the range -32768 to 32767. */
2600 unsigned int has_small_toc_reloc
;
2603 #define ppc64_elf_tdata(bfd) \
2604 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2606 #define ppc64_tlsld_got(bfd) \
2607 (&ppc64_elf_tdata (bfd)->tlsld_got)
2609 #define is_ppc64_elf(bfd) \
2610 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2611 && elf_object_id (bfd) == PPC64_ELF_DATA)
2613 /* Override the generic function because we store some extras. */
2616 ppc64_elf_mkobject (bfd
*abfd
)
2618 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2622 /* Fix bad default arch selected for a 64 bit input bfd when the
2623 default is 32 bit. */
2626 ppc64_elf_object_p (bfd
*abfd
)
2628 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2630 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2632 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2634 /* Relies on arch after 32 bit default being 64 bit default. */
2635 abfd
->arch_info
= abfd
->arch_info
->next
;
2636 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2642 /* Support for core dump NOTE sections. */
2645 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2647 size_t offset
, size
;
2649 if (note
->descsz
!= 504)
2653 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2656 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2662 /* Make a ".reg/999" section. */
2663 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2664 size
, note
->descpos
+ offset
);
2668 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2670 if (note
->descsz
!= 136)
2673 elf_tdata (abfd
)->core_pid
2674 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2675 elf_tdata (abfd
)->core_program
2676 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2677 elf_tdata (abfd
)->core_command
2678 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2684 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2697 va_start (ap
, note_type
);
2698 memset (data
, 0, 40);
2699 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2700 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2702 return elfcore_write_note (abfd
, buf
, bufsiz
,
2703 "CORE", note_type
, data
, sizeof (data
));
2714 va_start (ap
, note_type
);
2715 memset (data
, 0, 112);
2716 pid
= va_arg (ap
, long);
2717 bfd_put_32 (abfd
, pid
, data
+ 32);
2718 cursig
= va_arg (ap
, int);
2719 bfd_put_16 (abfd
, cursig
, data
+ 12);
2720 greg
= va_arg (ap
, const void *);
2721 memcpy (data
+ 112, greg
, 384);
2722 memset (data
+ 496, 0, 8);
2724 return elfcore_write_note (abfd
, buf
, bufsiz
,
2725 "CORE", note_type
, data
, sizeof (data
));
2730 /* Add extra PPC sections. */
2732 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2734 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2735 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2736 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2737 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2738 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2739 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2740 { NULL
, 0, 0, 0, 0 }
2743 enum _ppc64_sec_type
{
2749 struct _ppc64_elf_section_data
2751 struct bfd_elf_section_data elf
;
2755 /* An array with one entry for each opd function descriptor. */
2756 struct _opd_sec_data
2758 /* Points to the function code section for local opd entries. */
2759 asection
**func_sec
;
2761 /* After editing .opd, adjust references to opd local syms. */
2765 /* An array for toc sections, indexed by offset/8. */
2766 struct _toc_sec_data
2768 /* Specifies the relocation symbol index used at a given toc offset. */
2771 /* And the relocation addend. */
2776 enum _ppc64_sec_type sec_type
:2;
2778 /* Flag set when small branches are detected. Used to
2779 select suitable defaults for the stub group size. */
2780 unsigned int has_14bit_branch
:1;
2783 #define ppc64_elf_section_data(sec) \
2784 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2787 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2789 if (!sec
->used_by_bfd
)
2791 struct _ppc64_elf_section_data
*sdata
;
2792 bfd_size_type amt
= sizeof (*sdata
);
2794 sdata
= bfd_zalloc (abfd
, amt
);
2797 sec
->used_by_bfd
= sdata
;
2800 return _bfd_elf_new_section_hook (abfd
, sec
);
2803 static struct _opd_sec_data
*
2804 get_opd_info (asection
* sec
)
2807 && ppc64_elf_section_data (sec
) != NULL
2808 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2809 return &ppc64_elf_section_data (sec
)->u
.opd
;
2813 /* Parameters for the qsort hook. */
2814 static bfd_boolean synthetic_relocatable
;
2816 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2819 compare_symbols (const void *ap
, const void *bp
)
2821 const asymbol
*a
= * (const asymbol
**) ap
;
2822 const asymbol
*b
= * (const asymbol
**) bp
;
2824 /* Section symbols first. */
2825 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2827 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2830 /* then .opd symbols. */
2831 if (strcmp (a
->section
->name
, ".opd") == 0
2832 && strcmp (b
->section
->name
, ".opd") != 0)
2834 if (strcmp (a
->section
->name
, ".opd") != 0
2835 && strcmp (b
->section
->name
, ".opd") == 0)
2838 /* then other code symbols. */
2839 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2840 == (SEC_CODE
| SEC_ALLOC
)
2841 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2842 != (SEC_CODE
| SEC_ALLOC
))
2845 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2846 != (SEC_CODE
| SEC_ALLOC
)
2847 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2848 == (SEC_CODE
| SEC_ALLOC
))
2851 if (synthetic_relocatable
)
2853 if (a
->section
->id
< b
->section
->id
)
2856 if (a
->section
->id
> b
->section
->id
)
2860 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2863 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2866 /* For syms with the same value, prefer strong dynamic global function
2867 syms over other syms. */
2868 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2871 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2874 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2877 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2880 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2883 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2886 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2889 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2895 /* Search SYMS for a symbol of the given VALUE. */
2898 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2906 mid
= (lo
+ hi
) >> 1;
2907 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2909 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2919 mid
= (lo
+ hi
) >> 1;
2920 if (syms
[mid
]->section
->id
< id
)
2922 else if (syms
[mid
]->section
->id
> id
)
2924 else if (syms
[mid
]->value
< value
)
2926 else if (syms
[mid
]->value
> value
)
2936 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2938 bfd_vma vma
= *(bfd_vma
*) ptr
;
2939 return ((section
->flags
& SEC_ALLOC
) != 0
2940 && section
->vma
<= vma
2941 && vma
< section
->vma
+ section
->size
);
2944 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2945 entry syms. Also generate @plt symbols for the glink branch table. */
2948 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2949 long static_count
, asymbol
**static_syms
,
2950 long dyn_count
, asymbol
**dyn_syms
,
2957 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2959 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2964 opd
= bfd_get_section_by_name (abfd
, ".opd");
2968 symcount
= static_count
;
2970 symcount
+= dyn_count
;
2974 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2978 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2980 /* Use both symbol tables. */
2981 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2982 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2984 else if (!relocatable
&& static_count
== 0)
2985 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2987 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2989 synthetic_relocatable
= relocatable
;
2990 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2992 if (!relocatable
&& symcount
> 1)
2995 /* Trim duplicate syms, since we may have merged the normal and
2996 dynamic symbols. Actually, we only care about syms that have
2997 different values, so trim any with the same value. */
2998 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2999 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3000 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3001 syms
[j
++] = syms
[i
];
3006 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3010 for (; i
< symcount
; ++i
)
3011 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3012 != (SEC_CODE
| SEC_ALLOC
))
3013 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3017 for (; i
< symcount
; ++i
)
3018 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3022 for (; i
< symcount
; ++i
)
3023 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3027 for (; i
< symcount
; ++i
)
3028 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3029 != (SEC_CODE
| SEC_ALLOC
))
3037 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3042 if (opdsymend
== secsymend
)
3045 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3046 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3050 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3057 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3061 while (r
< opd
->relocation
+ relcount
3062 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3065 if (r
== opd
->relocation
+ relcount
)
3068 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3071 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3074 sym
= *r
->sym_ptr_ptr
;
3075 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3076 sym
->section
->id
, sym
->value
+ r
->addend
))
3079 size
+= sizeof (asymbol
);
3080 size
+= strlen (syms
[i
]->name
) + 2;
3084 s
= *ret
= bfd_malloc (size
);
3091 names
= (char *) (s
+ count
);
3093 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3097 while (r
< opd
->relocation
+ relcount
3098 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3101 if (r
== opd
->relocation
+ relcount
)
3104 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3107 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3110 sym
= *r
->sym_ptr_ptr
;
3111 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3112 sym
->section
->id
, sym
->value
+ r
->addend
))
3117 s
->flags
|= BSF_SYNTHETIC
;
3118 s
->section
= sym
->section
;
3119 s
->value
= sym
->value
+ r
->addend
;
3122 len
= strlen (syms
[i
]->name
);
3123 memcpy (names
, syms
[i
]->name
, len
+ 1);
3125 /* Have udata.p point back to the original symbol this
3126 synthetic symbol was derived from. */
3127 s
->udata
.p
= syms
[i
];
3134 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3138 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3139 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3142 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3146 free_contents_and_exit
:
3154 for (i
= secsymend
; i
< opdsymend
; ++i
)
3158 /* Ignore bogus symbols. */
3159 if (syms
[i
]->value
> opd
->size
- 8)
3162 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3163 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3166 size
+= sizeof (asymbol
);
3167 size
+= strlen (syms
[i
]->name
) + 2;
3171 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3173 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3175 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3177 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3179 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3180 goto free_contents_and_exit
;
3182 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3183 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3186 extdynend
= extdyn
+ dynamic
->size
;
3187 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3189 Elf_Internal_Dyn dyn
;
3190 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3192 if (dyn
.d_tag
== DT_NULL
)
3195 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3197 /* The first glink stub starts at offset 32; see comment in
3198 ppc64_elf_finish_dynamic_sections. */
3199 glink_vma
= dyn
.d_un
.d_val
+ 32;
3200 /* The .glink section usually does not survive the final
3201 link; search for the section (usually .text) where the
3202 glink stubs now reside. */
3203 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3214 /* Determine __glink trampoline by reading the relative branch
3215 from the first glink stub. */
3217 if (bfd_get_section_contents (abfd
, glink
, buf
,
3218 glink_vma
+ 4 - glink
->vma
, 4))
3220 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3222 if ((insn
& ~0x3fffffc) == 0)
3223 resolv_vma
= glink_vma
+ 4 + (insn
^ 0x2000000) - 0x2000000;
3227 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3229 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3232 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3233 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3234 goto free_contents_and_exit
;
3236 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3237 size
+= plt_count
* sizeof (asymbol
);
3239 p
= relplt
->relocation
;
3240 for (i
= 0; i
< plt_count
; i
++, p
++)
3242 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3244 size
+= sizeof ("+0x") - 1 + 16;
3249 s
= *ret
= bfd_malloc (size
);
3251 goto free_contents_and_exit
;
3253 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3255 for (i
= secsymend
; i
< opdsymend
; ++i
)
3259 if (syms
[i
]->value
> opd
->size
- 8)
3262 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3263 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3267 asection
*sec
= abfd
->sections
;
3274 long mid
= (lo
+ hi
) >> 1;
3275 if (syms
[mid
]->section
->vma
< ent
)
3277 else if (syms
[mid
]->section
->vma
> ent
)
3281 sec
= syms
[mid
]->section
;
3286 if (lo
>= hi
&& lo
> codesecsym
)
3287 sec
= syms
[lo
- 1]->section
;
3289 for (; sec
!= NULL
; sec
= sec
->next
)
3293 /* SEC_LOAD may not be set if SEC is from a separate debug
3295 if ((sec
->flags
& SEC_ALLOC
) == 0)
3297 if ((sec
->flags
& SEC_CODE
) != 0)
3300 s
->flags
|= BSF_SYNTHETIC
;
3301 s
->value
= ent
- s
->section
->vma
;
3304 len
= strlen (syms
[i
]->name
);
3305 memcpy (names
, syms
[i
]->name
, len
+ 1);
3307 /* Have udata.p point back to the original symbol this
3308 synthetic symbol was derived from. */
3309 s
->udata
.p
= syms
[i
];
3315 if (glink
!= NULL
&& relplt
!= NULL
)
3319 /* Add a symbol for the main glink trampoline. */
3320 memset (s
, 0, sizeof *s
);
3322 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3324 s
->value
= resolv_vma
- glink
->vma
;
3326 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3327 names
+= sizeof ("__glink_PLTresolve");
3332 /* FIXME: It would be very much nicer to put sym@plt on the
3333 stub rather than on the glink branch table entry. The
3334 objdump disassembler would then use a sensible symbol
3335 name on plt calls. The difficulty in doing so is
3336 a) finding the stubs, and,
3337 b) matching stubs against plt entries, and,
3338 c) there can be multiple stubs for a given plt entry.
3340 Solving (a) could be done by code scanning, but older
3341 ppc64 binaries used different stubs to current code.
3342 (b) is the tricky one since you need to known the toc
3343 pointer for at least one function that uses a pic stub to
3344 be able to calculate the plt address referenced.
3345 (c) means gdb would need to set multiple breakpoints (or
3346 find the glink branch itself) when setting breakpoints
3347 for pending shared library loads. */
3348 p
= relplt
->relocation
;
3349 for (i
= 0; i
< plt_count
; i
++, p
++)
3353 *s
= **p
->sym_ptr_ptr
;
3354 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3355 we are defining a symbol, ensure one of them is set. */
3356 if ((s
->flags
& BSF_LOCAL
) == 0)
3357 s
->flags
|= BSF_GLOBAL
;
3358 s
->flags
|= BSF_SYNTHETIC
;
3360 s
->value
= glink_vma
- glink
->vma
;
3363 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3364 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3368 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3369 names
+= sizeof ("+0x") - 1;
3370 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3371 names
+= strlen (names
);
3373 memcpy (names
, "@plt", sizeof ("@plt"));
3374 names
+= sizeof ("@plt");
3389 /* The following functions are specific to the ELF linker, while
3390 functions above are used generally. Those named ppc64_elf_* are
3391 called by the main ELF linker code. They appear in this file more
3392 or less in the order in which they are called. eg.
3393 ppc64_elf_check_relocs is called early in the link process,
3394 ppc64_elf_finish_dynamic_sections is one of the last functions
3397 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3398 functions have both a function code symbol and a function descriptor
3399 symbol. A call to foo in a relocatable object file looks like:
3406 The function definition in another object file might be:
3410 . .quad .TOC.@tocbase
3416 When the linker resolves the call during a static link, the branch
3417 unsurprisingly just goes to .foo and the .opd information is unused.
3418 If the function definition is in a shared library, things are a little
3419 different: The call goes via a plt call stub, the opd information gets
3420 copied to the plt, and the linker patches the nop.
3428 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3429 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3430 . std 2,40(1) # this is the general idea
3438 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3440 The "reloc ()" notation is supposed to indicate that the linker emits
3441 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3444 What are the difficulties here? Well, firstly, the relocations
3445 examined by the linker in check_relocs are against the function code
3446 sym .foo, while the dynamic relocation in the plt is emitted against
3447 the function descriptor symbol, foo. Somewhere along the line, we need
3448 to carefully copy dynamic link information from one symbol to the other.
3449 Secondly, the generic part of the elf linker will make .foo a dynamic
3450 symbol as is normal for most other backends. We need foo dynamic
3451 instead, at least for an application final link. However, when
3452 creating a shared library containing foo, we need to have both symbols
3453 dynamic so that references to .foo are satisfied during the early
3454 stages of linking. Otherwise the linker might decide to pull in a
3455 definition from some other object, eg. a static library.
3457 Update: As of August 2004, we support a new convention. Function
3458 calls may use the function descriptor symbol, ie. "bl foo". This
3459 behaves exactly as "bl .foo". */
3461 /* Of those relocs that might be copied as dynamic relocs, this function
3462 selects those that must be copied when linking a shared library,
3463 even when the symbol is local. */
3466 must_be_dyn_reloc (struct bfd_link_info
*info
,
3467 enum elf_ppc64_reloc_type r_type
)
3479 case R_PPC64_TPREL16
:
3480 case R_PPC64_TPREL16_LO
:
3481 case R_PPC64_TPREL16_HI
:
3482 case R_PPC64_TPREL16_HA
:
3483 case R_PPC64_TPREL16_DS
:
3484 case R_PPC64_TPREL16_LO_DS
:
3485 case R_PPC64_TPREL16_HIGHER
:
3486 case R_PPC64_TPREL16_HIGHERA
:
3487 case R_PPC64_TPREL16_HIGHEST
:
3488 case R_PPC64_TPREL16_HIGHESTA
:
3489 case R_PPC64_TPREL64
:
3490 return !info
->executable
;
3494 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3495 copying dynamic variables from a shared lib into an app's dynbss
3496 section, and instead use a dynamic relocation to point into the
3497 shared lib. With code that gcc generates, it's vital that this be
3498 enabled; In the PowerPC64 ABI, the address of a function is actually
3499 the address of a function descriptor, which resides in the .opd
3500 section. gcc uses the descriptor directly rather than going via the
3501 GOT as some other ABI's do, which means that initialized function
3502 pointers must reference the descriptor. Thus, a function pointer
3503 initialized to the address of a function in a shared library will
3504 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3505 redefines the function descriptor symbol to point to the copy. This
3506 presents a problem as a plt entry for that function is also
3507 initialized from the function descriptor symbol and the copy reloc
3508 may not be initialized first. */
3509 #define ELIMINATE_COPY_RELOCS 1
3511 /* Section name for stubs is the associated section name plus this
3513 #define STUB_SUFFIX ".stub"
3516 ppc_stub_long_branch:
3517 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3518 destination, but a 24 bit branch in a stub section will reach.
3521 ppc_stub_plt_branch:
3522 Similar to the above, but a 24 bit branch in the stub section won't
3523 reach its destination.
3524 . addis %r12,%r2,xxx@toc@ha
3525 . ld %r11,xxx@toc@l(%r12)
3530 Used to call a function in a shared library. If it so happens that
3531 the plt entry referenced crosses a 64k boundary, then an extra
3532 "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr".
3533 . addis %r12,%r2,xxx@toc@ha
3535 . ld %r11,xxx+0@toc@l(%r12)
3537 . ld %r2,xxx+8@toc@l(%r12)
3538 . ld %r11,xxx+16@toc@l(%r12)
3541 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3542 code to adjust the value and save r2 to support multiple toc sections.
3543 A ppc_stub_long_branch with an r2 offset looks like:
3545 . addis %r2,%r2,off@ha
3546 . addi %r2,%r2,off@l
3549 A ppc_stub_plt_branch with an r2 offset looks like:
3551 . addis %r12,%r2,xxx@toc@ha
3552 . ld %r11,xxx@toc@l(%r12)
3553 . addis %r2,%r2,off@ha
3554 . addi %r2,%r2,off@l
3558 In cases where the "addis" instruction would add zero, the "addis" is
3559 omitted and following instructions modified slightly in some cases.
3562 enum ppc_stub_type
{
3564 ppc_stub_long_branch
,
3565 ppc_stub_long_branch_r2off
,
3566 ppc_stub_plt_branch
,
3567 ppc_stub_plt_branch_r2off
,
3571 struct ppc_stub_hash_entry
{
3573 /* Base hash table entry structure. */
3574 struct bfd_hash_entry root
;
3576 enum ppc_stub_type stub_type
;
3578 /* The stub section. */
3581 /* Offset within stub_sec of the beginning of this stub. */
3582 bfd_vma stub_offset
;
3584 /* Given the symbol's value and its section we can determine its final
3585 value when building the stubs (so the stub knows where to jump. */
3586 bfd_vma target_value
;
3587 asection
*target_section
;
3589 /* The symbol table entry, if any, that this was derived from. */
3590 struct ppc_link_hash_entry
*h
;
3591 struct plt_entry
*plt_ent
;
3593 /* And the reloc addend that this was derived from. */
3596 /* Where this stub is being called from, or, in the case of combined
3597 stub sections, the first input section in the group. */
3601 struct ppc_branch_hash_entry
{
3603 /* Base hash table entry structure. */
3604 struct bfd_hash_entry root
;
3606 /* Offset within branch lookup table. */
3607 unsigned int offset
;
3609 /* Generation marker. */
3613 struct ppc_link_hash_entry
3615 struct elf_link_hash_entry elf
;
3618 /* A pointer to the most recently used stub hash entry against this
3620 struct ppc_stub_hash_entry
*stub_cache
;
3622 /* A pointer to the next symbol starting with a '.' */
3623 struct ppc_link_hash_entry
*next_dot_sym
;
3626 /* Track dynamic relocs copied for this symbol. */
3627 struct elf_dyn_relocs
*dyn_relocs
;
3629 /* Link between function code and descriptor symbols. */
3630 struct ppc_link_hash_entry
*oh
;
3632 /* Flag function code and descriptor symbols. */
3633 unsigned int is_func
:1;
3634 unsigned int is_func_descriptor
:1;
3635 unsigned int fake
:1;
3637 /* Whether global opd/toc sym has been adjusted or not.
3638 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3639 should be set for all globals defined in any opd/toc section. */
3640 unsigned int adjust_done
:1;
3642 /* Set if we twiddled this symbol to weak at some stage. */
3643 unsigned int was_undefined
:1;
3645 /* Contexts in which symbol is used in the GOT (or TOC).
3646 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3647 corresponding relocs are encountered during check_relocs.
3648 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3649 indicate the corresponding GOT entry type is not needed.
3650 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3651 a TPREL one. We use a separate flag rather than setting TPREL
3652 just for convenience in distinguishing the two cases. */
3653 #define TLS_GD 1 /* GD reloc. */
3654 #define TLS_LD 2 /* LD reloc. */
3655 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3656 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3657 #define TLS_TLS 16 /* Any TLS reloc. */
3658 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3659 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3660 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3661 unsigned char tls_mask
;
3664 /* ppc64 ELF linker hash table. */
3666 struct ppc_link_hash_table
3668 struct elf_link_hash_table elf
;
3670 /* The stub hash table. */
3671 struct bfd_hash_table stub_hash_table
;
3673 /* Another hash table for plt_branch stubs. */
3674 struct bfd_hash_table branch_hash_table
;
3676 /* Linker stub bfd. */
3679 /* Linker call-backs. */
3680 asection
* (*add_stub_section
) (const char *, asection
*);
3681 void (*layout_sections_again
) (void);
3683 /* Array to keep track of which stub sections have been created, and
3684 information on stub grouping. */
3686 /* This is the section to which stubs in the group will be attached. */
3688 /* The stub section. */
3690 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3694 /* Temp used when calculating TOC pointers. */
3697 asection
*toc_first_sec
;
3699 /* Highest input section id. */
3702 /* Highest output section index. */
3705 /* Used when adding symbols. */
3706 struct ppc_link_hash_entry
*dot_syms
;
3708 /* List of input sections for each output section. */
3709 asection
**input_list
;
3711 /* Short-cuts to get to dynamic linker sections. */
3724 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3725 struct ppc_link_hash_entry
*tls_get_addr
;
3726 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3728 /* The size of reliplt used by got entry relocs. */
3729 bfd_size_type got_reli_size
;
3732 unsigned long stub_count
[ppc_stub_plt_call
];
3734 /* Number of stubs against global syms. */
3735 unsigned long stub_globals
;
3737 /* Set if PLT call stubs should load r11. */
3738 unsigned int plt_static_chain
:1;
3740 /* Set if we should emit symbols for stubs. */
3741 unsigned int emit_stub_syms
:1;
3743 /* Set if __tls_get_addr optimization should not be done. */
3744 unsigned int no_tls_get_addr_opt
:1;
3746 /* Support for multiple toc sections. */
3747 unsigned int do_multi_toc
:1;
3748 unsigned int multi_toc_needed
:1;
3749 unsigned int second_toc_pass
:1;
3750 unsigned int do_toc_opt
:1;
3753 unsigned int stub_error
:1;
3755 /* Temp used by ppc64_elf_process_dot_syms. */
3756 unsigned int twiddled_syms
:1;
3758 /* Incremented every time we size stubs. */
3759 unsigned int stub_iteration
;
3761 /* Small local sym cache. */
3762 struct sym_cache sym_cache
;
3765 /* Rename some of the generic section flags to better document how they
3768 /* Nonzero if this section has TLS related relocations. */
3769 #define has_tls_reloc sec_flg0
3771 /* Nonzero if this section has a call to __tls_get_addr. */
3772 #define has_tls_get_addr_call sec_flg1
3774 /* Nonzero if this section has any toc or got relocs. */
3775 #define has_toc_reloc sec_flg2
3777 /* Nonzero if this section has a call to another section that uses
3779 #define makes_toc_func_call sec_flg3
3781 /* Recursion protection when determining above flag. */
3782 #define call_check_in_progress sec_flg4
3783 #define call_check_done sec_flg5
3785 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3787 #define ppc_hash_table(p) \
3788 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3789 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3791 #define ppc_stub_hash_lookup(table, string, create, copy) \
3792 ((struct ppc_stub_hash_entry *) \
3793 bfd_hash_lookup ((table), (string), (create), (copy)))
3795 #define ppc_branch_hash_lookup(table, string, create, copy) \
3796 ((struct ppc_branch_hash_entry *) \
3797 bfd_hash_lookup ((table), (string), (create), (copy)))
3799 /* Create an entry in the stub hash table. */
3801 static struct bfd_hash_entry
*
3802 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3803 struct bfd_hash_table
*table
,
3806 /* Allocate the structure if it has not already been allocated by a
3810 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3815 /* Call the allocation method of the superclass. */
3816 entry
= bfd_hash_newfunc (entry
, table
, string
);
3819 struct ppc_stub_hash_entry
*eh
;
3821 /* Initialize the local fields. */
3822 eh
= (struct ppc_stub_hash_entry
*) entry
;
3823 eh
->stub_type
= ppc_stub_none
;
3824 eh
->stub_sec
= NULL
;
3825 eh
->stub_offset
= 0;
3826 eh
->target_value
= 0;
3827 eh
->target_section
= NULL
;
3835 /* Create an entry in the branch hash table. */
3837 static struct bfd_hash_entry
*
3838 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3839 struct bfd_hash_table
*table
,
3842 /* Allocate the structure if it has not already been allocated by a
3846 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3851 /* Call the allocation method of the superclass. */
3852 entry
= bfd_hash_newfunc (entry
, table
, string
);
3855 struct ppc_branch_hash_entry
*eh
;
3857 /* Initialize the local fields. */
3858 eh
= (struct ppc_branch_hash_entry
*) entry
;
3866 /* Create an entry in a ppc64 ELF linker hash table. */
3868 static struct bfd_hash_entry
*
3869 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3870 struct bfd_hash_table
*table
,
3873 /* Allocate the structure if it has not already been allocated by a
3877 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3882 /* Call the allocation method of the superclass. */
3883 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3886 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3888 memset (&eh
->u
.stub_cache
, 0,
3889 (sizeof (struct ppc_link_hash_entry
)
3890 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3892 /* When making function calls, old ABI code references function entry
3893 points (dot symbols), while new ABI code references the function
3894 descriptor symbol. We need to make any combination of reference and
3895 definition work together, without breaking archive linking.
3897 For a defined function "foo" and an undefined call to "bar":
3898 An old object defines "foo" and ".foo", references ".bar" (possibly
3900 A new object defines "foo" and references "bar".
3902 A new object thus has no problem with its undefined symbols being
3903 satisfied by definitions in an old object. On the other hand, the
3904 old object won't have ".bar" satisfied by a new object.
3906 Keep a list of newly added dot-symbols. */
3908 if (string
[0] == '.')
3910 struct ppc_link_hash_table
*htab
;
3912 htab
= (struct ppc_link_hash_table
*) table
;
3913 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3914 htab
->dot_syms
= eh
;
3921 /* Create a ppc64 ELF linker hash table. */
3923 static struct bfd_link_hash_table
*
3924 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3926 struct ppc_link_hash_table
*htab
;
3927 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3929 htab
= bfd_zmalloc (amt
);
3933 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3934 sizeof (struct ppc_link_hash_entry
),
3941 /* Init the stub hash table too. */
3942 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3943 sizeof (struct ppc_stub_hash_entry
)))
3946 /* And the branch hash table. */
3947 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3948 sizeof (struct ppc_branch_hash_entry
)))
3951 /* Initializing two fields of the union is just cosmetic. We really
3952 only care about glist, but when compiled on a 32-bit host the
3953 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3954 debugger inspection of these fields look nicer. */
3955 htab
->elf
.init_got_refcount
.refcount
= 0;
3956 htab
->elf
.init_got_refcount
.glist
= NULL
;
3957 htab
->elf
.init_plt_refcount
.refcount
= 0;
3958 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3959 htab
->elf
.init_got_offset
.offset
= 0;
3960 htab
->elf
.init_got_offset
.glist
= NULL
;
3961 htab
->elf
.init_plt_offset
.offset
= 0;
3962 htab
->elf
.init_plt_offset
.glist
= NULL
;
3964 return &htab
->elf
.root
;
3967 /* Free the derived linker hash table. */
3970 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3972 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3974 bfd_hash_table_free (&ret
->stub_hash_table
);
3975 bfd_hash_table_free (&ret
->branch_hash_table
);
3976 _bfd_generic_link_hash_table_free (hash
);
3979 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3982 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3984 struct ppc_link_hash_table
*htab
;
3986 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3988 /* Always hook our dynamic sections into the first bfd, which is the
3989 linker created stub bfd. This ensures that the GOT header is at
3990 the start of the output TOC section. */
3991 htab
= ppc_hash_table (info
);
3994 htab
->stub_bfd
= abfd
;
3995 htab
->elf
.dynobj
= abfd
;
3998 /* Build a name for an entry in the stub hash table. */
4001 ppc_stub_name (const asection
*input_section
,
4002 const asection
*sym_sec
,
4003 const struct ppc_link_hash_entry
*h
,
4004 const Elf_Internal_Rela
*rel
)
4009 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4010 offsets from a sym as a branch target? In fact, we could
4011 probably assume the addend is always zero. */
4012 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4016 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4017 stub_name
= bfd_malloc (len
);
4018 if (stub_name
== NULL
)
4021 sprintf (stub_name
, "%08x.%s+%x",
4022 input_section
->id
& 0xffffffff,
4023 h
->elf
.root
.root
.string
,
4024 (int) rel
->r_addend
& 0xffffffff);
4028 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4029 stub_name
= bfd_malloc (len
);
4030 if (stub_name
== NULL
)
4033 sprintf (stub_name
, "%08x.%x:%x+%x",
4034 input_section
->id
& 0xffffffff,
4035 sym_sec
->id
& 0xffffffff,
4036 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4037 (int) rel
->r_addend
& 0xffffffff);
4039 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4040 stub_name
[len
- 2] = 0;
4044 /* Look up an entry in the stub hash. Stub entries are cached because
4045 creating the stub name takes a bit of time. */
4047 static struct ppc_stub_hash_entry
*
4048 ppc_get_stub_entry (const asection
*input_section
,
4049 const asection
*sym_sec
,
4050 struct ppc_link_hash_entry
*h
,
4051 const Elf_Internal_Rela
*rel
,
4052 struct ppc_link_hash_table
*htab
)
4054 struct ppc_stub_hash_entry
*stub_entry
;
4055 const asection
*id_sec
;
4057 /* If this input section is part of a group of sections sharing one
4058 stub section, then use the id of the first section in the group.
4059 Stub names need to include a section id, as there may well be
4060 more than one stub used to reach say, printf, and we need to
4061 distinguish between them. */
4062 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4064 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4065 && h
->u
.stub_cache
->h
== h
4066 && h
->u
.stub_cache
->id_sec
== id_sec
)
4068 stub_entry
= h
->u
.stub_cache
;
4074 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
4075 if (stub_name
== NULL
)
4078 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4079 stub_name
, FALSE
, FALSE
);
4081 h
->u
.stub_cache
= stub_entry
;
4089 /* Add a new stub entry to the stub hash. Not all fields of the new
4090 stub entry are initialised. */
4092 static struct ppc_stub_hash_entry
*
4093 ppc_add_stub (const char *stub_name
,
4095 struct bfd_link_info
*info
)
4097 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4100 struct ppc_stub_hash_entry
*stub_entry
;
4102 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
4103 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
4104 if (stub_sec
== NULL
)
4106 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
4107 if (stub_sec
== NULL
)
4113 namelen
= strlen (link_sec
->name
);
4114 len
= namelen
+ sizeof (STUB_SUFFIX
);
4115 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
4119 memcpy (s_name
, link_sec
->name
, namelen
);
4120 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4121 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
4122 if (stub_sec
== NULL
)
4124 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
4126 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
4129 /* Enter this entry into the linker stub hash table. */
4130 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4132 if (stub_entry
== NULL
)
4134 info
->callbacks
->einfo (_("%B: cannot create stub entry %s\n"),
4135 section
->owner
, stub_name
);
4139 stub_entry
->stub_sec
= stub_sec
;
4140 stub_entry
->stub_offset
= 0;
4141 stub_entry
->id_sec
= link_sec
;
4145 /* Create sections for linker generated code. */
4148 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4150 struct ppc_link_hash_table
*htab
;
4153 htab
= ppc_hash_table (info
);
4157 /* Create .sfpr for code to save and restore fp regs. */
4158 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4159 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4160 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4162 if (htab
->sfpr
== NULL
4163 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4166 /* Create .glink for lazy dynamic linking support. */
4167 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4169 if (htab
->glink
== NULL
4170 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4173 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4174 htab
->iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4175 if (htab
->iplt
== NULL
4176 || ! bfd_set_section_alignment (dynobj
, htab
->iplt
, 3))
4179 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4180 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4181 htab
->reliplt
= bfd_make_section_anyway_with_flags (dynobj
,
4184 if (htab
->reliplt
== NULL
4185 || ! bfd_set_section_alignment (dynobj
, htab
->reliplt
, 3))
4188 /* Create branch lookup table for plt_branch stubs. */
4189 flags
= (SEC_ALLOC
| SEC_LOAD
4190 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4191 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4193 if (htab
->brlt
== NULL
4194 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4200 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4201 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4202 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4205 if (htab
->relbrlt
== NULL
4206 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4212 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4213 not already done. */
4216 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4218 asection
*got
, *relgot
;
4220 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4222 if (!is_ppc64_elf (abfd
))
4229 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4232 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
4237 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4238 | SEC_LINKER_CREATED
);
4240 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4242 || !bfd_set_section_alignment (abfd
, got
, 3))
4245 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4246 flags
| SEC_READONLY
);
4248 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4251 ppc64_elf_tdata (abfd
)->got
= got
;
4252 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4256 /* Create the dynamic sections, and set up shortcuts. */
4259 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4261 struct ppc_link_hash_table
*htab
;
4263 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4266 htab
= ppc_hash_table (info
);
4271 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
4272 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
4273 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4274 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
4276 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
4278 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
4279 || (!info
->shared
&& !htab
->relbss
))
4285 /* Follow indirect and warning symbol links. */
4287 static inline struct bfd_link_hash_entry
*
4288 follow_link (struct bfd_link_hash_entry
*h
)
4290 while (h
->type
== bfd_link_hash_indirect
4291 || h
->type
== bfd_link_hash_warning
)
4296 static inline struct elf_link_hash_entry
*
4297 elf_follow_link (struct elf_link_hash_entry
*h
)
4299 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4302 static inline struct ppc_link_hash_entry
*
4303 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4305 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4308 /* Merge PLT info on FROM with that on TO. */
4311 move_plt_plist (struct ppc_link_hash_entry
*from
,
4312 struct ppc_link_hash_entry
*to
)
4314 if (from
->elf
.plt
.plist
!= NULL
)
4316 if (to
->elf
.plt
.plist
!= NULL
)
4318 struct plt_entry
**entp
;
4319 struct plt_entry
*ent
;
4321 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4323 struct plt_entry
*dent
;
4325 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4326 if (dent
->addend
== ent
->addend
)
4328 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4335 *entp
= to
->elf
.plt
.plist
;
4338 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4339 from
->elf
.plt
.plist
= NULL
;
4343 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4346 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4347 struct elf_link_hash_entry
*dir
,
4348 struct elf_link_hash_entry
*ind
)
4350 struct ppc_link_hash_entry
*edir
, *eind
;
4352 edir
= (struct ppc_link_hash_entry
*) dir
;
4353 eind
= (struct ppc_link_hash_entry
*) ind
;
4355 edir
->is_func
|= eind
->is_func
;
4356 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4357 edir
->tls_mask
|= eind
->tls_mask
;
4358 if (eind
->oh
!= NULL
)
4359 edir
->oh
= ppc_follow_link (eind
->oh
);
4361 /* If called to transfer flags for a weakdef during processing
4362 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4363 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4364 if (!(ELIMINATE_COPY_RELOCS
4365 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4366 && edir
->elf
.dynamic_adjusted
))
4367 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4369 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4370 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4371 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4372 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4374 /* If we were called to copy over info for a weak sym, that's all. */
4375 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4378 /* Copy over any dynamic relocs we may have on the indirect sym. */
4379 if (eind
->dyn_relocs
!= NULL
)
4381 if (edir
->dyn_relocs
!= NULL
)
4383 struct elf_dyn_relocs
**pp
;
4384 struct elf_dyn_relocs
*p
;
4386 /* Add reloc counts against the indirect sym to the direct sym
4387 list. Merge any entries against the same section. */
4388 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4390 struct elf_dyn_relocs
*q
;
4392 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4393 if (q
->sec
== p
->sec
)
4395 q
->pc_count
+= p
->pc_count
;
4396 q
->count
+= p
->count
;
4403 *pp
= edir
->dyn_relocs
;
4406 edir
->dyn_relocs
= eind
->dyn_relocs
;
4407 eind
->dyn_relocs
= NULL
;
4410 /* Copy over got entries that we may have already seen to the
4411 symbol which just became indirect. */
4412 if (eind
->elf
.got
.glist
!= NULL
)
4414 if (edir
->elf
.got
.glist
!= NULL
)
4416 struct got_entry
**entp
;
4417 struct got_entry
*ent
;
4419 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4421 struct got_entry
*dent
;
4423 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4424 if (dent
->addend
== ent
->addend
4425 && dent
->owner
== ent
->owner
4426 && dent
->tls_type
== ent
->tls_type
)
4428 dent
->got
.refcount
+= ent
->got
.refcount
;
4435 *entp
= edir
->elf
.got
.glist
;
4438 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4439 eind
->elf
.got
.glist
= NULL
;
4442 /* And plt entries. */
4443 move_plt_plist (eind
, edir
);
4445 if (eind
->elf
.dynindx
!= -1)
4447 if (edir
->elf
.dynindx
!= -1)
4448 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4449 edir
->elf
.dynstr_index
);
4450 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4451 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4452 eind
->elf
.dynindx
= -1;
4453 eind
->elf
.dynstr_index
= 0;
4457 /* Find the function descriptor hash entry from the given function code
4458 hash entry FH. Link the entries via their OH fields. */
4460 static struct ppc_link_hash_entry
*
4461 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4463 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4467 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4469 fdh
= (struct ppc_link_hash_entry
*)
4470 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4474 fdh
->is_func_descriptor
= 1;
4480 return ppc_follow_link (fdh
);
4483 /* Make a fake function descriptor sym for the code sym FH. */
4485 static struct ppc_link_hash_entry
*
4486 make_fdh (struct bfd_link_info
*info
,
4487 struct ppc_link_hash_entry
*fh
)
4491 struct bfd_link_hash_entry
*bh
;
4492 struct ppc_link_hash_entry
*fdh
;
4494 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4495 newsym
= bfd_make_empty_symbol (abfd
);
4496 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4497 newsym
->section
= bfd_und_section_ptr
;
4499 newsym
->flags
= BSF_WEAK
;
4502 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4503 newsym
->flags
, newsym
->section
,
4504 newsym
->value
, NULL
, FALSE
, FALSE
,
4508 fdh
= (struct ppc_link_hash_entry
*) bh
;
4509 fdh
->elf
.non_elf
= 0;
4511 fdh
->is_func_descriptor
= 1;
4518 /* Fix function descriptor symbols defined in .opd sections to be
4522 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4523 struct bfd_link_info
*info
,
4524 Elf_Internal_Sym
*isym
,
4525 const char **name ATTRIBUTE_UNUSED
,
4526 flagword
*flags ATTRIBUTE_UNUSED
,
4528 bfd_vma
*value ATTRIBUTE_UNUSED
)
4530 if ((ibfd
->flags
& DYNAMIC
) == 0
4531 && ELF_ST_BIND (isym
->st_info
) == STB_GNU_UNIQUE
)
4532 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4534 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4536 if ((ibfd
->flags
& DYNAMIC
) == 0)
4537 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4539 else if (ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
)
4541 else if (*sec
!= NULL
4542 && strcmp ((*sec
)->name
, ".opd") == 0)
4543 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4548 /* This function makes an old ABI object reference to ".bar" cause the
4549 inclusion of a new ABI object archive that defines "bar".
4550 NAME is a symbol defined in an archive. Return a symbol in the hash
4551 table that might be satisfied by the archive symbols. */
4553 static struct elf_link_hash_entry
*
4554 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4555 struct bfd_link_info
*info
,
4558 struct elf_link_hash_entry
*h
;
4562 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4564 /* Don't return this sym if it is a fake function descriptor
4565 created by add_symbol_adjust. */
4566 && !(h
->root
.type
== bfd_link_hash_undefweak
4567 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4573 len
= strlen (name
);
4574 dot_name
= bfd_alloc (abfd
, len
+ 2);
4575 if (dot_name
== NULL
)
4576 return (struct elf_link_hash_entry
*) 0 - 1;
4578 memcpy (dot_name
+ 1, name
, len
+ 1);
4579 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4580 bfd_release (abfd
, dot_name
);
4584 /* This function satisfies all old ABI object references to ".bar" if a
4585 new ABI object defines "bar". Well, at least, undefined dot symbols
4586 are made weak. This stops later archive searches from including an
4587 object if we already have a function descriptor definition. It also
4588 prevents the linker complaining about undefined symbols.
4589 We also check and correct mismatched symbol visibility here. The
4590 most restrictive visibility of the function descriptor and the
4591 function entry symbol is used. */
4594 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4596 struct ppc_link_hash_table
*htab
;
4597 struct ppc_link_hash_entry
*fdh
;
4599 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4602 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4603 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4605 if (eh
->elf
.root
.root
.string
[0] != '.')
4608 htab
= ppc_hash_table (info
);
4612 fdh
= lookup_fdh (eh
, htab
);
4615 if (!info
->relocatable
4616 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4617 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4618 && eh
->elf
.ref_regular
)
4620 /* Make an undefweak function descriptor sym, which is enough to
4621 pull in an --as-needed shared lib, but won't cause link
4622 errors. Archives are handled elsewhere. */
4623 fdh
= make_fdh (info
, eh
);
4626 fdh
->elf
.ref_regular
= 1;
4631 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4632 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4633 if (entry_vis
< descr_vis
)
4634 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4635 else if (entry_vis
> descr_vis
)
4636 eh
->elf
.other
+= descr_vis
- entry_vis
;
4638 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4639 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4640 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4642 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4643 eh
->was_undefined
= 1;
4644 htab
->twiddled_syms
= 1;
4651 /* Process list of dot-symbols we made in link_hash_newfunc. */
4654 ppc64_elf_process_dot_syms (bfd
*ibfd
, struct bfd_link_info
*info
)
4656 struct ppc_link_hash_table
*htab
;
4657 struct ppc_link_hash_entry
**p
, *eh
;
4659 if (!is_ppc64_elf (info
->output_bfd
))
4661 htab
= ppc_hash_table (info
);
4665 if (is_ppc64_elf (ibfd
))
4667 p
= &htab
->dot_syms
;
4668 while ((eh
= *p
) != NULL
)
4671 if (!add_symbol_adjust (eh
, info
))
4673 p
= &eh
->u
.next_dot_sym
;
4677 /* Clear the list for non-ppc64 input files. */
4678 p
= &htab
->dot_syms
;
4679 while ((eh
= *p
) != NULL
)
4682 p
= &eh
->u
.next_dot_sym
;
4685 /* We need to fix the undefs list for any syms we have twiddled to
4687 if (htab
->twiddled_syms
)
4689 bfd_link_repair_undef_list (&htab
->elf
.root
);
4690 htab
->twiddled_syms
= 0;
4695 /* Undo hash table changes when an --as-needed input file is determined
4696 not to be needed. */
4699 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4700 struct bfd_link_info
*info
)
4702 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4707 htab
->dot_syms
= NULL
;
4711 /* If --just-symbols against a final linked binary, then assume we need
4712 toc adjusting stubs when calling functions defined there. */
4715 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4717 if ((sec
->flags
& SEC_CODE
) != 0
4718 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4719 && is_ppc64_elf (sec
->owner
))
4721 asection
*got
= bfd_get_section_by_name (sec
->owner
, ".got");
4723 && got
->size
>= elf_backend_got_header_size
4724 && bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4725 sec
->has_toc_reloc
= 1;
4727 _bfd_elf_link_just_syms (sec
, info
);
4730 static struct plt_entry
**
4731 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4732 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4734 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4735 struct plt_entry
**local_plt
;
4736 unsigned char *local_got_tls_masks
;
4738 if (local_got_ents
== NULL
)
4740 bfd_size_type size
= symtab_hdr
->sh_info
;
4742 size
*= (sizeof (*local_got_ents
)
4743 + sizeof (*local_plt
)
4744 + sizeof (*local_got_tls_masks
));
4745 local_got_ents
= bfd_zalloc (abfd
, size
);
4746 if (local_got_ents
== NULL
)
4748 elf_local_got_ents (abfd
) = local_got_ents
;
4751 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
4753 struct got_entry
*ent
;
4755 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4756 if (ent
->addend
== r_addend
4757 && ent
->owner
== abfd
4758 && ent
->tls_type
== tls_type
)
4762 bfd_size_type amt
= sizeof (*ent
);
4763 ent
= bfd_alloc (abfd
, amt
);
4766 ent
->next
= local_got_ents
[r_symndx
];
4767 ent
->addend
= r_addend
;
4769 ent
->tls_type
= tls_type
;
4770 ent
->is_indirect
= FALSE
;
4771 ent
->got
.refcount
= 0;
4772 local_got_ents
[r_symndx
] = ent
;
4774 ent
->got
.refcount
+= 1;
4777 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4778 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4779 local_got_tls_masks
[r_symndx
] |= tls_type
;
4781 return local_plt
+ r_symndx
;
4785 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4787 struct plt_entry
*ent
;
4789 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4790 if (ent
->addend
== addend
)
4794 bfd_size_type amt
= sizeof (*ent
);
4795 ent
= bfd_alloc (abfd
, amt
);
4799 ent
->addend
= addend
;
4800 ent
->plt
.refcount
= 0;
4803 ent
->plt
.refcount
+= 1;
4808 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4810 return (r_type
== R_PPC64_REL24
4811 || r_type
== R_PPC64_REL14
4812 || r_type
== R_PPC64_REL14_BRTAKEN
4813 || r_type
== R_PPC64_REL14_BRNTAKEN
4814 || r_type
== R_PPC64_ADDR24
4815 || r_type
== R_PPC64_ADDR14
4816 || r_type
== R_PPC64_ADDR14_BRTAKEN
4817 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
4820 /* Look through the relocs for a section during the first phase, and
4821 calculate needed space in the global offset table, procedure
4822 linkage table, and dynamic reloc sections. */
4825 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4826 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4828 struct ppc_link_hash_table
*htab
;
4829 Elf_Internal_Shdr
*symtab_hdr
;
4830 struct elf_link_hash_entry
**sym_hashes
;
4831 const Elf_Internal_Rela
*rel
;
4832 const Elf_Internal_Rela
*rel_end
;
4834 asection
**opd_sym_map
;
4835 struct elf_link_hash_entry
*tga
, *dottga
;
4837 if (info
->relocatable
)
4840 /* Don't do anything special with non-loaded, non-alloced sections.
4841 In particular, any relocs in such sections should not affect GOT
4842 and PLT reference counting (ie. we don't allow them to create GOT
4843 or PLT entries), there's no possibility or desire to optimize TLS
4844 relocs, and there's not much point in propagating relocs to shared
4845 libs that the dynamic linker won't relocate. */
4846 if ((sec
->flags
& SEC_ALLOC
) == 0)
4849 BFD_ASSERT (is_ppc64_elf (abfd
));
4851 htab
= ppc_hash_table (info
);
4855 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4856 FALSE
, FALSE
, TRUE
);
4857 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4858 FALSE
, FALSE
, TRUE
);
4859 symtab_hdr
= &elf_symtab_hdr (abfd
);
4860 sym_hashes
= elf_sym_hashes (abfd
);
4863 if (strcmp (sec
->name
, ".opd") == 0)
4865 /* Garbage collection needs some extra help with .opd sections.
4866 We don't want to necessarily keep everything referenced by
4867 relocs in .opd, as that would keep all functions. Instead,
4868 if we reference an .opd symbol (a function descriptor), we
4869 want to keep the function code symbol's section. This is
4870 easy for global symbols, but for local syms we need to keep
4871 information about the associated function section. */
4874 amt
= sec
->size
* sizeof (*opd_sym_map
) / 8;
4875 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4876 if (opd_sym_map
== NULL
)
4878 ppc64_elf_section_data (sec
)->u
.opd
.func_sec
= opd_sym_map
;
4879 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4880 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4883 if (htab
->sfpr
== NULL
4884 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4887 rel_end
= relocs
+ sec
->reloc_count
;
4888 for (rel
= relocs
; rel
< rel_end
; rel
++)
4890 unsigned long r_symndx
;
4891 struct elf_link_hash_entry
*h
;
4892 enum elf_ppc64_reloc_type r_type
;
4894 struct _ppc64_elf_section_data
*ppc64_sec
;
4895 struct plt_entry
**ifunc
;
4897 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4898 if (r_symndx
< symtab_hdr
->sh_info
)
4902 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4903 h
= elf_follow_link (h
);
4910 if (h
->type
== STT_GNU_IFUNC
)
4913 ifunc
= &h
->plt
.plist
;
4918 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4923 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4925 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4926 rel
->r_addend
, PLT_IFUNC
);
4931 r_type
= ELF64_R_TYPE (rel
->r_info
);
4932 if (is_branch_reloc (r_type
))
4934 if (h
!= NULL
&& (h
== tga
|| h
== dottga
))
4937 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4938 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4939 /* We have a new-style __tls_get_addr call with a marker
4943 /* Mark this section as having an old-style call. */
4944 sec
->has_tls_get_addr_call
= 1;
4947 /* STT_GNU_IFUNC symbols must have a PLT entry. */
4949 && !update_plt_info (abfd
, ifunc
, rel
->r_addend
))
4957 /* These special tls relocs tie a call to __tls_get_addr with
4958 its parameter symbol. */
4961 case R_PPC64_GOT_TLSLD16
:
4962 case R_PPC64_GOT_TLSLD16_LO
:
4963 case R_PPC64_GOT_TLSLD16_HI
:
4964 case R_PPC64_GOT_TLSLD16_HA
:
4965 tls_type
= TLS_TLS
| TLS_LD
;
4968 case R_PPC64_GOT_TLSGD16
:
4969 case R_PPC64_GOT_TLSGD16_LO
:
4970 case R_PPC64_GOT_TLSGD16_HI
:
4971 case R_PPC64_GOT_TLSGD16_HA
:
4972 tls_type
= TLS_TLS
| TLS_GD
;
4975 case R_PPC64_GOT_TPREL16_DS
:
4976 case R_PPC64_GOT_TPREL16_LO_DS
:
4977 case R_PPC64_GOT_TPREL16_HI
:
4978 case R_PPC64_GOT_TPREL16_HA
:
4979 if (!info
->executable
)
4980 info
->flags
|= DF_STATIC_TLS
;
4981 tls_type
= TLS_TLS
| TLS_TPREL
;
4984 case R_PPC64_GOT_DTPREL16_DS
:
4985 case R_PPC64_GOT_DTPREL16_LO_DS
:
4986 case R_PPC64_GOT_DTPREL16_HI
:
4987 case R_PPC64_GOT_DTPREL16_HA
:
4988 tls_type
= TLS_TLS
| TLS_DTPREL
;
4990 sec
->has_tls_reloc
= 1;
4994 case R_PPC64_GOT16_DS
:
4995 case R_PPC64_GOT16_HA
:
4996 case R_PPC64_GOT16_HI
:
4997 case R_PPC64_GOT16_LO
:
4998 case R_PPC64_GOT16_LO_DS
:
4999 /* This symbol requires a global offset table entry. */
5000 sec
->has_toc_reloc
= 1;
5001 if (r_type
== R_PPC64_GOT_TLSLD16
5002 || r_type
== R_PPC64_GOT_TLSGD16
5003 || r_type
== R_PPC64_GOT_TPREL16_DS
5004 || r_type
== R_PPC64_GOT_DTPREL16_DS
5005 || r_type
== R_PPC64_GOT16
5006 || r_type
== R_PPC64_GOT16_DS
)
5008 htab
->do_multi_toc
= 1;
5009 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5012 if (ppc64_elf_tdata (abfd
)->got
== NULL
5013 && !create_got_section (abfd
, info
))
5018 struct ppc_link_hash_entry
*eh
;
5019 struct got_entry
*ent
;
5021 eh
= (struct ppc_link_hash_entry
*) h
;
5022 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5023 if (ent
->addend
== rel
->r_addend
5024 && ent
->owner
== abfd
5025 && ent
->tls_type
== tls_type
)
5029 bfd_size_type amt
= sizeof (*ent
);
5030 ent
= bfd_alloc (abfd
, amt
);
5033 ent
->next
= eh
->elf
.got
.glist
;
5034 ent
->addend
= rel
->r_addend
;
5036 ent
->tls_type
= tls_type
;
5037 ent
->is_indirect
= FALSE
;
5038 ent
->got
.refcount
= 0;
5039 eh
->elf
.got
.glist
= ent
;
5041 ent
->got
.refcount
+= 1;
5042 eh
->tls_mask
|= tls_type
;
5045 /* This is a global offset table entry for a local symbol. */
5046 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5047 rel
->r_addend
, tls_type
))
5051 case R_PPC64_PLT16_HA
:
5052 case R_PPC64_PLT16_HI
:
5053 case R_PPC64_PLT16_LO
:
5056 /* This symbol requires a procedure linkage table entry. We
5057 actually build the entry in adjust_dynamic_symbol,
5058 because this might be a case of linking PIC code without
5059 linking in any dynamic objects, in which case we don't
5060 need to generate a procedure linkage table after all. */
5063 /* It does not make sense to have a procedure linkage
5064 table entry for a local symbol. */
5065 bfd_set_error (bfd_error_bad_value
);
5070 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5073 if (h
->root
.root
.string
[0] == '.'
5074 && h
->root
.root
.string
[1] != '\0')
5075 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5079 /* The following relocations don't need to propagate the
5080 relocation if linking a shared object since they are
5081 section relative. */
5082 case R_PPC64_SECTOFF
:
5083 case R_PPC64_SECTOFF_LO
:
5084 case R_PPC64_SECTOFF_HI
:
5085 case R_PPC64_SECTOFF_HA
:
5086 case R_PPC64_SECTOFF_DS
:
5087 case R_PPC64_SECTOFF_LO_DS
:
5088 case R_PPC64_DTPREL16
:
5089 case R_PPC64_DTPREL16_LO
:
5090 case R_PPC64_DTPREL16_HI
:
5091 case R_PPC64_DTPREL16_HA
:
5092 case R_PPC64_DTPREL16_DS
:
5093 case R_PPC64_DTPREL16_LO_DS
:
5094 case R_PPC64_DTPREL16_HIGHER
:
5095 case R_PPC64_DTPREL16_HIGHERA
:
5096 case R_PPC64_DTPREL16_HIGHEST
:
5097 case R_PPC64_DTPREL16_HIGHESTA
:
5102 case R_PPC64_REL16_LO
:
5103 case R_PPC64_REL16_HI
:
5104 case R_PPC64_REL16_HA
:
5108 case R_PPC64_TOC16_DS
:
5109 htab
->do_multi_toc
= 1;
5110 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5111 case R_PPC64_TOC16_LO
:
5112 case R_PPC64_TOC16_HI
:
5113 case R_PPC64_TOC16_HA
:
5114 case R_PPC64_TOC16_LO_DS
:
5115 sec
->has_toc_reloc
= 1;
5118 /* This relocation describes the C++ object vtable hierarchy.
5119 Reconstruct it for later use during GC. */
5120 case R_PPC64_GNU_VTINHERIT
:
5121 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5125 /* This relocation describes which C++ vtable entries are actually
5126 used. Record for later use during GC. */
5127 case R_PPC64_GNU_VTENTRY
:
5128 BFD_ASSERT (h
!= NULL
);
5130 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5135 case R_PPC64_REL14_BRTAKEN
:
5136 case R_PPC64_REL14_BRNTAKEN
:
5138 asection
*dest
= NULL
;
5140 /* Heuristic: If jumping outside our section, chances are
5141 we are going to need a stub. */
5144 /* If the sym is weak it may be overridden later, so
5145 don't assume we know where a weak sym lives. */
5146 if (h
->root
.type
== bfd_link_hash_defined
)
5147 dest
= h
->root
.u
.def
.section
;
5151 Elf_Internal_Sym
*isym
;
5153 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5158 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5162 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5167 if (h
!= NULL
&& ifunc
== NULL
)
5169 /* We may need a .plt entry if the function this reloc
5170 refers to is in a shared lib. */
5171 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5174 if (h
->root
.root
.string
[0] == '.'
5175 && h
->root
.root
.string
[1] != '\0')
5176 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5177 if (h
== tga
|| h
== dottga
)
5178 sec
->has_tls_reloc
= 1;
5182 case R_PPC64_TPREL64
:
5183 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5184 if (!info
->executable
)
5185 info
->flags
|= DF_STATIC_TLS
;
5188 case R_PPC64_DTPMOD64
:
5189 if (rel
+ 1 < rel_end
5190 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5191 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5192 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5194 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5197 case R_PPC64_DTPREL64
:
5198 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5200 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5201 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5202 /* This is the second reloc of a dtpmod, dtprel pair.
5203 Don't mark with TLS_DTPREL. */
5207 sec
->has_tls_reloc
= 1;
5210 struct ppc_link_hash_entry
*eh
;
5211 eh
= (struct ppc_link_hash_entry
*) h
;
5212 eh
->tls_mask
|= tls_type
;
5215 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5216 rel
->r_addend
, tls_type
))
5219 ppc64_sec
= ppc64_elf_section_data (sec
);
5220 if (ppc64_sec
->sec_type
!= sec_toc
)
5224 /* One extra to simplify get_tls_mask. */
5225 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5226 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5227 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5229 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5230 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5231 if (ppc64_sec
->u
.toc
.add
== NULL
)
5233 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5234 ppc64_sec
->sec_type
= sec_toc
;
5236 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5237 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5238 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5240 /* Mark the second slot of a GD or LD entry.
5241 -1 to indicate GD and -2 to indicate LD. */
5242 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5243 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5244 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5245 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5248 case R_PPC64_TPREL16
:
5249 case R_PPC64_TPREL16_LO
:
5250 case R_PPC64_TPREL16_HI
:
5251 case R_PPC64_TPREL16_HA
:
5252 case R_PPC64_TPREL16_DS
:
5253 case R_PPC64_TPREL16_LO_DS
:
5254 case R_PPC64_TPREL16_HIGHER
:
5255 case R_PPC64_TPREL16_HIGHERA
:
5256 case R_PPC64_TPREL16_HIGHEST
:
5257 case R_PPC64_TPREL16_HIGHESTA
:
5260 if (!info
->executable
)
5261 info
->flags
|= DF_STATIC_TLS
;
5266 case R_PPC64_ADDR64
:
5267 if (opd_sym_map
!= NULL
5268 && rel
+ 1 < rel_end
5269 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5273 if (h
->root
.root
.string
[0] == '.'
5274 && h
->root
.root
.string
[1] != 0
5275 && lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
5278 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5283 Elf_Internal_Sym
*isym
;
5285 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5290 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5291 if (s
!= NULL
&& s
!= sec
)
5292 opd_sym_map
[rel
->r_offset
/ 8] = s
;
5300 case R_PPC64_ADDR14
:
5301 case R_PPC64_ADDR14_BRNTAKEN
:
5302 case R_PPC64_ADDR14_BRTAKEN
:
5303 case R_PPC64_ADDR16
:
5304 case R_PPC64_ADDR16_DS
:
5305 case R_PPC64_ADDR16_HA
:
5306 case R_PPC64_ADDR16_HI
:
5307 case R_PPC64_ADDR16_HIGHER
:
5308 case R_PPC64_ADDR16_HIGHERA
:
5309 case R_PPC64_ADDR16_HIGHEST
:
5310 case R_PPC64_ADDR16_HIGHESTA
:
5311 case R_PPC64_ADDR16_LO
:
5312 case R_PPC64_ADDR16_LO_DS
:
5313 case R_PPC64_ADDR24
:
5314 case R_PPC64_ADDR32
:
5315 case R_PPC64_UADDR16
:
5316 case R_PPC64_UADDR32
:
5317 case R_PPC64_UADDR64
:
5319 if (h
!= NULL
&& !info
->shared
)
5320 /* We may need a copy reloc. */
5323 /* Don't propagate .opd relocs. */
5324 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5327 /* If we are creating a shared library, and this is a reloc
5328 against a global symbol, or a non PC relative reloc
5329 against a local symbol, then we need to copy the reloc
5330 into the shared library. However, if we are linking with
5331 -Bsymbolic, we do not need to copy a reloc against a
5332 global symbol which is defined in an object we are
5333 including in the link (i.e., DEF_REGULAR is set). At
5334 this point we have not seen all the input files, so it is
5335 possible that DEF_REGULAR is not set now but will be set
5336 later (it is never cleared). In case of a weak definition,
5337 DEF_REGULAR may be cleared later by a strong definition in
5338 a shared library. We account for that possibility below by
5339 storing information in the dyn_relocs field of the hash
5340 table entry. A similar situation occurs when creating
5341 shared libraries and symbol visibility changes render the
5344 If on the other hand, we are creating an executable, we
5345 may need to keep relocations for symbols satisfied by a
5346 dynamic library if we manage to avoid copy relocs for the
5350 && (must_be_dyn_reloc (info
, r_type
)
5352 && (! info
->symbolic
5353 || h
->root
.type
== bfd_link_hash_defweak
5354 || !h
->def_regular
))))
5355 || (ELIMINATE_COPY_RELOCS
5358 && (h
->root
.type
== bfd_link_hash_defweak
5359 || !h
->def_regular
))
5363 struct elf_dyn_relocs
*p
;
5364 struct elf_dyn_relocs
**head
;
5366 /* We must copy these reloc types into the output file.
5367 Create a reloc section in dynobj and make room for
5371 sreloc
= _bfd_elf_make_dynamic_reloc_section
5372 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5378 /* If this is a global symbol, we count the number of
5379 relocations we need for this symbol. */
5382 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5386 /* Track dynamic relocs needed for local syms too.
5387 We really need local syms available to do this
5391 Elf_Internal_Sym
*isym
;
5393 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5398 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5402 vpp
= &elf_section_data (s
)->local_dynrel
;
5403 head
= (struct elf_dyn_relocs
**) vpp
;
5407 if (p
== NULL
|| p
->sec
!= sec
)
5409 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5420 if (!must_be_dyn_reloc (info
, r_type
))
5433 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5434 of the code entry point, and its section. */
5437 opd_entry_value (asection
*opd_sec
,
5439 asection
**code_sec
,
5442 bfd
*opd_bfd
= opd_sec
->owner
;
5443 Elf_Internal_Rela
*relocs
;
5444 Elf_Internal_Rela
*lo
, *hi
, *look
;
5447 /* No relocs implies we are linking a --just-symbols object. */
5448 if (opd_sec
->reloc_count
== 0)
5452 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, buf
, offset
, 8))
5453 return (bfd_vma
) -1;
5455 val
= bfd_get_64 (opd_bfd
, buf
);
5456 if (code_sec
!= NULL
)
5458 asection
*sec
, *likely
= NULL
;
5459 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5461 && (sec
->flags
& SEC_LOAD
) != 0
5462 && (sec
->flags
& SEC_ALLOC
) != 0)
5467 if (code_off
!= NULL
)
5468 *code_off
= val
- likely
->vma
;
5474 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5476 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
5478 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5480 /* Go find the opd reloc at the sym address. */
5482 BFD_ASSERT (lo
!= NULL
);
5483 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5487 look
= lo
+ (hi
- lo
) / 2;
5488 if (look
->r_offset
< offset
)
5490 else if (look
->r_offset
> offset
)
5494 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5496 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5497 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5499 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5502 if (symndx
< symtab_hdr
->sh_info
)
5504 Elf_Internal_Sym
*sym
;
5506 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5509 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5510 symtab_hdr
->sh_info
,
5511 0, NULL
, NULL
, NULL
);
5514 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5518 val
= sym
->st_value
;
5519 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5520 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5524 struct elf_link_hash_entry
**sym_hashes
;
5525 struct elf_link_hash_entry
*rh
;
5527 sym_hashes
= elf_sym_hashes (opd_bfd
);
5528 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5529 rh
= elf_follow_link (rh
);
5530 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5531 || rh
->root
.type
== bfd_link_hash_defweak
);
5532 val
= rh
->root
.u
.def
.value
;
5533 sec
= rh
->root
.u
.def
.section
;
5535 val
+= look
->r_addend
;
5536 if (code_off
!= NULL
)
5538 if (code_sec
!= NULL
)
5540 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5541 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5550 /* Return true if symbol is defined in a regular object file. */
5553 is_static_defined (struct elf_link_hash_entry
*h
)
5555 return ((h
->root
.type
== bfd_link_hash_defined
5556 || h
->root
.type
== bfd_link_hash_defweak
)
5557 && h
->root
.u
.def
.section
!= NULL
5558 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5561 /* If FDH is a function descriptor symbol, return the associated code
5562 entry symbol if it is defined. Return NULL otherwise. */
5564 static struct ppc_link_hash_entry
*
5565 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5567 if (fdh
->is_func_descriptor
)
5569 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5570 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5571 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5577 /* If FH is a function code entry symbol, return the associated
5578 function descriptor symbol if it is defined. Return NULL otherwise. */
5580 static struct ppc_link_hash_entry
*
5581 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5584 && fh
->oh
->is_func_descriptor
)
5586 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5587 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5588 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5594 /* Mark all our entry sym sections, both opd and code section. */
5597 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5599 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5600 struct bfd_sym_chain
*sym
;
5605 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5607 struct ppc_link_hash_entry
*eh
, *fh
;
5610 eh
= (struct ppc_link_hash_entry
*)
5611 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5614 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5615 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5618 fh
= defined_code_entry (eh
);
5621 sec
= fh
->elf
.root
.u
.def
.section
;
5622 sec
->flags
|= SEC_KEEP
;
5624 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5625 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5626 eh
->elf
.root
.u
.def
.value
,
5627 &sec
, NULL
) != (bfd_vma
) -1)
5628 sec
->flags
|= SEC_KEEP
;
5630 sec
= eh
->elf
.root
.u
.def
.section
;
5631 sec
->flags
|= SEC_KEEP
;
5635 /* Mark sections containing dynamically referenced symbols. When
5636 building shared libraries, we must assume that any visible symbol is
5640 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5642 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5643 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5644 struct ppc_link_hash_entry
*fdh
;
5646 /* Dynamic linking info is on the func descriptor sym. */
5647 fdh
= defined_func_desc (eh
);
5651 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5652 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5653 && (eh
->elf
.ref_dynamic
5654 || (!info
->executable
5655 && eh
->elf
.def_regular
5656 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5657 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5660 struct ppc_link_hash_entry
*fh
;
5662 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5664 /* Function descriptor syms cause the associated
5665 function code sym section to be marked. */
5666 fh
= defined_code_entry (eh
);
5669 code_sec
= fh
->elf
.root
.u
.def
.section
;
5670 code_sec
->flags
|= SEC_KEEP
;
5672 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5673 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5674 eh
->elf
.root
.u
.def
.value
,
5675 &code_sec
, NULL
) != (bfd_vma
) -1)
5676 code_sec
->flags
|= SEC_KEEP
;
5682 /* Return the section that should be marked against GC for a given
5686 ppc64_elf_gc_mark_hook (asection
*sec
,
5687 struct bfd_link_info
*info
,
5688 Elf_Internal_Rela
*rel
,
5689 struct elf_link_hash_entry
*h
,
5690 Elf_Internal_Sym
*sym
)
5694 /* Syms return NULL if we're marking .opd, so we avoid marking all
5695 function sections, as all functions are referenced in .opd. */
5697 if (get_opd_info (sec
) != NULL
)
5702 enum elf_ppc64_reloc_type r_type
;
5703 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5705 r_type
= ELF64_R_TYPE (rel
->r_info
);
5708 case R_PPC64_GNU_VTINHERIT
:
5709 case R_PPC64_GNU_VTENTRY
:
5713 switch (h
->root
.type
)
5715 case bfd_link_hash_defined
:
5716 case bfd_link_hash_defweak
:
5717 eh
= (struct ppc_link_hash_entry
*) h
;
5718 fdh
= defined_func_desc (eh
);
5722 /* Function descriptor syms cause the associated
5723 function code sym section to be marked. */
5724 fh
= defined_code_entry (eh
);
5727 /* They also mark their opd section. */
5728 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5730 rsec
= fh
->elf
.root
.u
.def
.section
;
5732 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5733 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5734 eh
->elf
.root
.u
.def
.value
,
5735 &rsec
, NULL
) != (bfd_vma
) -1)
5736 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5738 rsec
= h
->root
.u
.def
.section
;
5741 case bfd_link_hash_common
:
5742 rsec
= h
->root
.u
.c
.p
->section
;
5746 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5752 struct _opd_sec_data
*opd
;
5754 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5755 opd
= get_opd_info (rsec
);
5756 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5760 rsec
= opd
->func_sec
[(sym
->st_value
+ rel
->r_addend
) / 8];
5767 /* Update the .got, .plt. and dynamic reloc reference counts for the
5768 section being removed. */
5771 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5772 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5774 struct ppc_link_hash_table
*htab
;
5775 Elf_Internal_Shdr
*symtab_hdr
;
5776 struct elf_link_hash_entry
**sym_hashes
;
5777 struct got_entry
**local_got_ents
;
5778 const Elf_Internal_Rela
*rel
, *relend
;
5780 if (info
->relocatable
)
5783 if ((sec
->flags
& SEC_ALLOC
) == 0)
5786 elf_section_data (sec
)->local_dynrel
= NULL
;
5788 htab
= ppc_hash_table (info
);
5792 symtab_hdr
= &elf_symtab_hdr (abfd
);
5793 sym_hashes
= elf_sym_hashes (abfd
);
5794 local_got_ents
= elf_local_got_ents (abfd
);
5796 relend
= relocs
+ sec
->reloc_count
;
5797 for (rel
= relocs
; rel
< relend
; rel
++)
5799 unsigned long r_symndx
;
5800 enum elf_ppc64_reloc_type r_type
;
5801 struct elf_link_hash_entry
*h
= NULL
;
5802 unsigned char tls_type
= 0;
5804 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5805 r_type
= ELF64_R_TYPE (rel
->r_info
);
5806 if (r_symndx
>= symtab_hdr
->sh_info
)
5808 struct ppc_link_hash_entry
*eh
;
5809 struct elf_dyn_relocs
**pp
;
5810 struct elf_dyn_relocs
*p
;
5812 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5813 h
= elf_follow_link (h
);
5814 eh
= (struct ppc_link_hash_entry
*) h
;
5816 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5819 /* Everything must go for SEC. */
5825 if (is_branch_reloc (r_type
))
5827 struct plt_entry
**ifunc
= NULL
;
5830 if (h
->type
== STT_GNU_IFUNC
)
5831 ifunc
= &h
->plt
.plist
;
5833 else if (local_got_ents
!= NULL
)
5835 struct plt_entry
**local_plt
= (struct plt_entry
**)
5836 (local_got_ents
+ symtab_hdr
->sh_info
);
5837 unsigned char *local_got_tls_masks
= (unsigned char *)
5838 (local_plt
+ symtab_hdr
->sh_info
);
5839 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
5840 ifunc
= local_plt
+ r_symndx
;
5844 struct plt_entry
*ent
;
5846 for (ent
= *ifunc
; ent
!= NULL
; ent
= ent
->next
)
5847 if (ent
->addend
== rel
->r_addend
)
5851 if (ent
->plt
.refcount
> 0)
5852 ent
->plt
.refcount
-= 1;
5859 case R_PPC64_GOT_TLSLD16
:
5860 case R_PPC64_GOT_TLSLD16_LO
:
5861 case R_PPC64_GOT_TLSLD16_HI
:
5862 case R_PPC64_GOT_TLSLD16_HA
:
5863 tls_type
= TLS_TLS
| TLS_LD
;
5866 case R_PPC64_GOT_TLSGD16
:
5867 case R_PPC64_GOT_TLSGD16_LO
:
5868 case R_PPC64_GOT_TLSGD16_HI
:
5869 case R_PPC64_GOT_TLSGD16_HA
:
5870 tls_type
= TLS_TLS
| TLS_GD
;
5873 case R_PPC64_GOT_TPREL16_DS
:
5874 case R_PPC64_GOT_TPREL16_LO_DS
:
5875 case R_PPC64_GOT_TPREL16_HI
:
5876 case R_PPC64_GOT_TPREL16_HA
:
5877 tls_type
= TLS_TLS
| TLS_TPREL
;
5880 case R_PPC64_GOT_DTPREL16_DS
:
5881 case R_PPC64_GOT_DTPREL16_LO_DS
:
5882 case R_PPC64_GOT_DTPREL16_HI
:
5883 case R_PPC64_GOT_DTPREL16_HA
:
5884 tls_type
= TLS_TLS
| TLS_DTPREL
;
5888 case R_PPC64_GOT16_DS
:
5889 case R_PPC64_GOT16_HA
:
5890 case R_PPC64_GOT16_HI
:
5891 case R_PPC64_GOT16_LO
:
5892 case R_PPC64_GOT16_LO_DS
:
5895 struct got_entry
*ent
;
5900 ent
= local_got_ents
[r_symndx
];
5902 for (; ent
!= NULL
; ent
= ent
->next
)
5903 if (ent
->addend
== rel
->r_addend
5904 && ent
->owner
== abfd
5905 && ent
->tls_type
== tls_type
)
5909 if (ent
->got
.refcount
> 0)
5910 ent
->got
.refcount
-= 1;
5914 case R_PPC64_PLT16_HA
:
5915 case R_PPC64_PLT16_HI
:
5916 case R_PPC64_PLT16_LO
:
5920 case R_PPC64_REL14_BRNTAKEN
:
5921 case R_PPC64_REL14_BRTAKEN
:
5925 struct plt_entry
*ent
;
5927 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5928 if (ent
->addend
== rel
->r_addend
)
5930 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
5931 ent
->plt
.refcount
-= 1;
5942 /* The maximum size of .sfpr. */
5943 #define SFPR_MAX (218*4)
5945 struct sfpr_def_parms
5947 const char name
[12];
5948 unsigned char lo
, hi
;
5949 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5950 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5953 /* Auto-generate _save*, _rest* functions in .sfpr. */
5956 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5958 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5960 size_t len
= strlen (parm
->name
);
5961 bfd_boolean writing
= FALSE
;
5967 memcpy (sym
, parm
->name
, len
);
5970 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5972 struct elf_link_hash_entry
*h
;
5974 sym
[len
+ 0] = i
/ 10 + '0';
5975 sym
[len
+ 1] = i
% 10 + '0';
5976 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5980 h
->root
.type
= bfd_link_hash_defined
;
5981 h
->root
.u
.def
.section
= htab
->sfpr
;
5982 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
5985 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
5987 if (htab
->sfpr
->contents
== NULL
)
5989 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5990 if (htab
->sfpr
->contents
== NULL
)
5996 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5998 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6000 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6001 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6009 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6011 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6016 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6018 p
= savegpr0 (abfd
, p
, r
);
6019 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6021 bfd_put_32 (abfd
, BLR
, p
);
6026 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6028 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6033 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6035 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6037 p
= restgpr0 (abfd
, p
, r
);
6038 bfd_put_32 (abfd
, MTLR_R0
, p
);
6042 p
= restgpr0 (abfd
, p
, 30);
6043 p
= restgpr0 (abfd
, p
, 31);
6045 bfd_put_32 (abfd
, BLR
, p
);
6050 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6052 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6057 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6059 p
= savegpr1 (abfd
, p
, r
);
6060 bfd_put_32 (abfd
, BLR
, p
);
6065 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6067 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6072 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6074 p
= restgpr1 (abfd
, p
, r
);
6075 bfd_put_32 (abfd
, BLR
, p
);
6080 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6082 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6087 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6089 p
= savefpr (abfd
, p
, r
);
6090 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6092 bfd_put_32 (abfd
, BLR
, p
);
6097 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6099 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6104 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6106 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6108 p
= restfpr (abfd
, p
, r
);
6109 bfd_put_32 (abfd
, MTLR_R0
, p
);
6113 p
= restfpr (abfd
, p
, 30);
6114 p
= restfpr (abfd
, p
, 31);
6116 bfd_put_32 (abfd
, BLR
, p
);
6121 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6123 p
= savefpr (abfd
, p
, r
);
6124 bfd_put_32 (abfd
, BLR
, p
);
6129 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6131 p
= restfpr (abfd
, p
, r
);
6132 bfd_put_32 (abfd
, BLR
, p
);
6137 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6139 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6141 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6146 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6148 p
= savevr (abfd
, p
, r
);
6149 bfd_put_32 (abfd
, BLR
, p
);
6154 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6156 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6158 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6163 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6165 p
= restvr (abfd
, p
, r
);
6166 bfd_put_32 (abfd
, BLR
, p
);
6170 /* Called via elf_link_hash_traverse to transfer dynamic linking
6171 information on function code symbol entries to their corresponding
6172 function descriptor symbol entries. */
6175 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6177 struct bfd_link_info
*info
;
6178 struct ppc_link_hash_table
*htab
;
6179 struct plt_entry
*ent
;
6180 struct ppc_link_hash_entry
*fh
;
6181 struct ppc_link_hash_entry
*fdh
;
6182 bfd_boolean force_local
;
6184 fh
= (struct ppc_link_hash_entry
*) h
;
6185 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6189 htab
= ppc_hash_table (info
);
6193 /* Resolve undefined references to dot-symbols as the value
6194 in the function descriptor, if we have one in a regular object.
6195 This is to satisfy cases like ".quad .foo". Calls to functions
6196 in dynamic objects are handled elsewhere. */
6197 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
6198 && fh
->was_undefined
6199 && (fdh
= defined_func_desc (fh
)) != NULL
6200 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6201 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6202 fdh
->elf
.root
.u
.def
.value
,
6203 &fh
->elf
.root
.u
.def
.section
,
6204 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
6206 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6207 fh
->elf
.forced_local
= 1;
6208 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6209 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6212 /* If this is a function code symbol, transfer dynamic linking
6213 information to the function descriptor symbol. */
6217 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6218 if (ent
->plt
.refcount
> 0)
6221 || fh
->elf
.root
.root
.string
[0] != '.'
6222 || fh
->elf
.root
.root
.string
[1] == '\0')
6225 /* Find the corresponding function descriptor symbol. Create it
6226 as undefined if necessary. */
6228 fdh
= lookup_fdh (fh
, htab
);
6230 && !info
->executable
6231 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6232 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6234 fdh
= make_fdh (info
, fh
);
6239 /* Fake function descriptors are made undefweak. If the function
6240 code symbol is strong undefined, make the fake sym the same.
6241 If the function code symbol is defined, then force the fake
6242 descriptor local; We can't support overriding of symbols in a
6243 shared library on a fake descriptor. */
6247 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6249 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
6251 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
6252 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
6254 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
6255 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6257 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6262 && !fdh
->elf
.forced_local
6263 && (!info
->executable
6264 || fdh
->elf
.def_dynamic
6265 || fdh
->elf
.ref_dynamic
6266 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
6267 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
6269 if (fdh
->elf
.dynindx
== -1)
6270 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6272 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6273 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6274 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6275 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6276 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
6278 move_plt_plist (fh
, fdh
);
6279 fdh
->elf
.needs_plt
= 1;
6281 fdh
->is_func_descriptor
= 1;
6286 /* Now that the info is on the function descriptor, clear the
6287 function code sym info. Any function code syms for which we
6288 don't have a definition in a regular file, we force local.
6289 This prevents a shared library from exporting syms that have
6290 been imported from another library. Function code syms that
6291 are really in the library we must leave global to prevent the
6292 linker dragging in a definition from a static library. */
6293 force_local
= (!fh
->elf
.def_regular
6295 || !fdh
->elf
.def_regular
6296 || fdh
->elf
.forced_local
);
6297 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6302 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6303 this hook to a) provide some gcc support functions, and b) transfer
6304 dynamic linking information gathered so far on function code symbol
6305 entries, to their corresponding function descriptor symbol entries. */
6308 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6309 struct bfd_link_info
*info
)
6311 struct ppc_link_hash_table
*htab
;
6313 const struct sfpr_def_parms funcs
[] =
6315 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6316 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6317 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6318 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6319 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6320 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6321 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6322 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6323 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6324 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6325 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6326 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6329 htab
= ppc_hash_table (info
);
6333 if (htab
->sfpr
== NULL
)
6334 /* We don't have any relocs. */
6337 /* Provide any missing _save* and _rest* functions. */
6338 htab
->sfpr
->size
= 0;
6339 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
6340 if (!sfpr_define (info
, &funcs
[i
]))
6343 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6345 if (htab
->sfpr
->size
== 0)
6346 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6351 /* Adjust a symbol defined by a dynamic object and referenced by a
6352 regular object. The current definition is in some section of the
6353 dynamic object, but we're not including those sections. We have to
6354 change the definition to something the rest of the link can
6358 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6359 struct elf_link_hash_entry
*h
)
6361 struct ppc_link_hash_table
*htab
;
6364 htab
= ppc_hash_table (info
);
6368 /* Deal with function syms. */
6369 if (h
->type
== STT_FUNC
6370 || h
->type
== STT_GNU_IFUNC
6373 /* Clear procedure linkage table information for any symbol that
6374 won't need a .plt entry. */
6375 struct plt_entry
*ent
;
6376 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6377 if (ent
->plt
.refcount
> 0)
6380 || (h
->type
!= STT_GNU_IFUNC
6381 && (SYMBOL_CALLS_LOCAL (info
, h
)
6382 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6383 && h
->root
.type
== bfd_link_hash_undefweak
))))
6385 h
->plt
.plist
= NULL
;
6390 h
->plt
.plist
= NULL
;
6392 /* If this is a weak symbol, and there is a real definition, the
6393 processor independent code will have arranged for us to see the
6394 real definition first, and we can just use the same value. */
6395 if (h
->u
.weakdef
!= NULL
)
6397 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6398 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6399 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6400 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6401 if (ELIMINATE_COPY_RELOCS
)
6402 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6406 /* If we are creating a shared library, we must presume that the
6407 only references to the symbol are via the global offset table.
6408 For such cases we need not do anything here; the relocations will
6409 be handled correctly by relocate_section. */
6413 /* If there are no references to this symbol that do not use the
6414 GOT, we don't need to generate a copy reloc. */
6415 if (!h
->non_got_ref
)
6418 /* Don't generate a copy reloc for symbols defined in the executable. */
6419 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
6422 if (ELIMINATE_COPY_RELOCS
)
6424 struct ppc_link_hash_entry
* eh
;
6425 struct elf_dyn_relocs
*p
;
6427 eh
= (struct ppc_link_hash_entry
*) h
;
6428 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6430 s
= p
->sec
->output_section
;
6431 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6435 /* If we didn't find any dynamic relocs in read-only sections, then
6436 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6444 if (h
->plt
.plist
!= NULL
)
6446 /* We should never get here, but unfortunately there are versions
6447 of gcc out there that improperly (for this ABI) put initialized
6448 function pointers, vtable refs and suchlike in read-only
6449 sections. Allow them to proceed, but warn that this might
6450 break at runtime. */
6451 info
->callbacks
->einfo
6452 (_("copy reloc against `%s' requires lazy plt linking; "
6453 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6454 h
->root
.root
.string
);
6457 /* This is a reference to a symbol defined by a dynamic object which
6458 is not a function. */
6462 info
->callbacks
->einfo (_("dynamic variable `%s' is zero size\n"),
6463 h
->root
.root
.string
);
6467 /* We must allocate the symbol in our .dynbss section, which will
6468 become part of the .bss section of the executable. There will be
6469 an entry for this symbol in the .dynsym section. The dynamic
6470 object will contain position independent code, so all references
6471 from the dynamic object to this symbol will go through the global
6472 offset table. The dynamic linker will use the .dynsym entry to
6473 determine the address it must put in the global offset table, so
6474 both the dynamic object and the regular object will refer to the
6475 same memory location for the variable. */
6477 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6478 to copy the initial value out of the dynamic object and into the
6479 runtime process image. We need to remember the offset into the
6480 .rela.bss section we are going to use. */
6481 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6483 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
6489 return _bfd_elf_adjust_dynamic_copy (h
, s
);
6492 /* If given a function descriptor symbol, hide both the function code
6493 sym and the descriptor. */
6495 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6496 struct elf_link_hash_entry
*h
,
6497 bfd_boolean force_local
)
6499 struct ppc_link_hash_entry
*eh
;
6500 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6502 eh
= (struct ppc_link_hash_entry
*) h
;
6503 if (eh
->is_func_descriptor
)
6505 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6510 struct ppc_link_hash_table
*htab
;
6513 /* We aren't supposed to use alloca in BFD because on
6514 systems which do not have alloca the version in libiberty
6515 calls xmalloc, which might cause the program to crash
6516 when it runs out of memory. This function doesn't have a
6517 return status, so there's no way to gracefully return an
6518 error. So cheat. We know that string[-1] can be safely
6519 accessed; It's either a string in an ELF string table,
6520 or allocated in an objalloc structure. */
6522 p
= eh
->elf
.root
.root
.string
- 1;
6525 htab
= ppc_hash_table (info
);
6529 fh
= (struct ppc_link_hash_entry
*)
6530 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6533 /* Unfortunately, if it so happens that the string we were
6534 looking for was allocated immediately before this string,
6535 then we overwrote the string terminator. That's the only
6536 reason the lookup should fail. */
6539 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6540 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6542 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6543 fh
= (struct ppc_link_hash_entry
*)
6544 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6553 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6558 get_sym_h (struct elf_link_hash_entry
**hp
,
6559 Elf_Internal_Sym
**symp
,
6561 unsigned char **tls_maskp
,
6562 Elf_Internal_Sym
**locsymsp
,
6563 unsigned long r_symndx
,
6566 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6568 if (r_symndx
>= symtab_hdr
->sh_info
)
6570 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6571 struct elf_link_hash_entry
*h
;
6573 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6574 h
= elf_follow_link (h
);
6582 if (symsecp
!= NULL
)
6584 asection
*symsec
= NULL
;
6585 if (h
->root
.type
== bfd_link_hash_defined
6586 || h
->root
.type
== bfd_link_hash_defweak
)
6587 symsec
= h
->root
.u
.def
.section
;
6591 if (tls_maskp
!= NULL
)
6593 struct ppc_link_hash_entry
*eh
;
6595 eh
= (struct ppc_link_hash_entry
*) h
;
6596 *tls_maskp
= &eh
->tls_mask
;
6601 Elf_Internal_Sym
*sym
;
6602 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6604 if (locsyms
== NULL
)
6606 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6607 if (locsyms
== NULL
)
6608 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6609 symtab_hdr
->sh_info
,
6610 0, NULL
, NULL
, NULL
);
6611 if (locsyms
== NULL
)
6613 *locsymsp
= locsyms
;
6615 sym
= locsyms
+ r_symndx
;
6623 if (symsecp
!= NULL
)
6624 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6626 if (tls_maskp
!= NULL
)
6628 struct got_entry
**lgot_ents
;
6629 unsigned char *tls_mask
;
6632 lgot_ents
= elf_local_got_ents (ibfd
);
6633 if (lgot_ents
!= NULL
)
6635 struct plt_entry
**local_plt
= (struct plt_entry
**)
6636 (lgot_ents
+ symtab_hdr
->sh_info
);
6637 unsigned char *lgot_masks
= (unsigned char *)
6638 (local_plt
+ symtab_hdr
->sh_info
);
6639 tls_mask
= &lgot_masks
[r_symndx
];
6641 *tls_maskp
= tls_mask
;
6647 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6648 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6649 type suitable for optimization, and 1 otherwise. */
6652 get_tls_mask (unsigned char **tls_maskp
,
6653 unsigned long *toc_symndx
,
6654 bfd_vma
*toc_addend
,
6655 Elf_Internal_Sym
**locsymsp
,
6656 const Elf_Internal_Rela
*rel
,
6659 unsigned long r_symndx
;
6661 struct elf_link_hash_entry
*h
;
6662 Elf_Internal_Sym
*sym
;
6666 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6667 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6670 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6672 || ppc64_elf_section_data (sec
) == NULL
6673 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6676 /* Look inside a TOC section too. */
6679 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6680 off
= h
->root
.u
.def
.value
;
6683 off
= sym
->st_value
;
6684 off
+= rel
->r_addend
;
6685 BFD_ASSERT (off
% 8 == 0);
6686 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6687 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6688 if (toc_symndx
!= NULL
)
6689 *toc_symndx
= r_symndx
;
6690 if (toc_addend
!= NULL
)
6691 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6692 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6694 if ((h
== NULL
|| is_static_defined (h
))
6695 && (next_r
== -1 || next_r
== -2))
6700 /* Adjust all global syms defined in opd sections. In gcc generated
6701 code for the old ABI, these will already have been done. */
6704 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6706 struct ppc_link_hash_entry
*eh
;
6708 struct _opd_sec_data
*opd
;
6710 if (h
->root
.type
== bfd_link_hash_indirect
)
6713 if (h
->root
.type
!= bfd_link_hash_defined
6714 && h
->root
.type
!= bfd_link_hash_defweak
)
6717 eh
= (struct ppc_link_hash_entry
*) h
;
6718 if (eh
->adjust_done
)
6721 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6722 opd
= get_opd_info (sym_sec
);
6723 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6725 long adjust
= opd
->adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6728 /* This entry has been deleted. */
6729 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6732 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6733 if (elf_discarded_section (dsec
))
6735 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6739 eh
->elf
.root
.u
.def
.value
= 0;
6740 eh
->elf
.root
.u
.def
.section
= dsec
;
6743 eh
->elf
.root
.u
.def
.value
+= adjust
;
6744 eh
->adjust_done
= 1;
6749 /* Handles decrementing dynamic reloc counts for the reloc specified by
6750 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6751 have already been determined. */
6754 dec_dynrel_count (bfd_vma r_info
,
6756 struct bfd_link_info
*info
,
6757 Elf_Internal_Sym
**local_syms
,
6758 struct elf_link_hash_entry
*h
,
6761 enum elf_ppc64_reloc_type r_type
;
6762 struct elf_dyn_relocs
*p
;
6763 struct elf_dyn_relocs
**pp
;
6765 /* Can this reloc be dynamic? This switch, and later tests here
6766 should be kept in sync with the code in check_relocs. */
6767 r_type
= ELF64_R_TYPE (r_info
);
6773 case R_PPC64_TPREL16
:
6774 case R_PPC64_TPREL16_LO
:
6775 case R_PPC64_TPREL16_HI
:
6776 case R_PPC64_TPREL16_HA
:
6777 case R_PPC64_TPREL16_DS
:
6778 case R_PPC64_TPREL16_LO_DS
:
6779 case R_PPC64_TPREL16_HIGHER
:
6780 case R_PPC64_TPREL16_HIGHERA
:
6781 case R_PPC64_TPREL16_HIGHEST
:
6782 case R_PPC64_TPREL16_HIGHESTA
:
6786 case R_PPC64_TPREL64
:
6787 case R_PPC64_DTPMOD64
:
6788 case R_PPC64_DTPREL64
:
6789 case R_PPC64_ADDR64
:
6793 case R_PPC64_ADDR14
:
6794 case R_PPC64_ADDR14_BRNTAKEN
:
6795 case R_PPC64_ADDR14_BRTAKEN
:
6796 case R_PPC64_ADDR16
:
6797 case R_PPC64_ADDR16_DS
:
6798 case R_PPC64_ADDR16_HA
:
6799 case R_PPC64_ADDR16_HI
:
6800 case R_PPC64_ADDR16_HIGHER
:
6801 case R_PPC64_ADDR16_HIGHERA
:
6802 case R_PPC64_ADDR16_HIGHEST
:
6803 case R_PPC64_ADDR16_HIGHESTA
:
6804 case R_PPC64_ADDR16_LO
:
6805 case R_PPC64_ADDR16_LO_DS
:
6806 case R_PPC64_ADDR24
:
6807 case R_PPC64_ADDR32
:
6808 case R_PPC64_UADDR16
:
6809 case R_PPC64_UADDR32
:
6810 case R_PPC64_UADDR64
:
6815 if (local_syms
!= NULL
)
6817 unsigned long r_symndx
;
6818 Elf_Internal_Sym
*sym
;
6819 bfd
*ibfd
= sec
->owner
;
6821 r_symndx
= ELF64_R_SYM (r_info
);
6822 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6827 && (must_be_dyn_reloc (info
, r_type
)
6830 || h
->root
.type
== bfd_link_hash_defweak
6831 || !h
->def_regular
))))
6832 || (ELIMINATE_COPY_RELOCS
6835 && (h
->root
.type
== bfd_link_hash_defweak
6836 || !h
->def_regular
)))
6842 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6845 if (sym_sec
!= NULL
)
6847 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6848 pp
= (struct elf_dyn_relocs
**) vpp
;
6852 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6853 pp
= (struct elf_dyn_relocs
**) vpp
;
6856 /* elf_gc_sweep may have already removed all dyn relocs associated
6857 with local syms for a given section. Don't report a dynreloc
6863 while ((p
= *pp
) != NULL
)
6867 if (!must_be_dyn_reloc (info
, r_type
))
6877 info
->callbacks
->einfo (_("dynreloc miscount for %B, section %A\n"),
6879 bfd_set_error (bfd_error_bad_value
);
6883 /* Remove unused Official Procedure Descriptor entries. Currently we
6884 only remove those associated with functions in discarded link-once
6885 sections, or weakly defined functions that have been overridden. It
6886 would be possible to remove many more entries for statically linked
6890 ppc64_elf_edit_opd (struct bfd_link_info
*info
, bfd_boolean non_overlapping
)
6893 bfd_boolean some_edited
= FALSE
;
6894 asection
*need_pad
= NULL
;
6896 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6899 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6900 Elf_Internal_Shdr
*symtab_hdr
;
6901 Elf_Internal_Sym
*local_syms
;
6903 struct _opd_sec_data
*opd
;
6904 bfd_boolean need_edit
, add_aux_fields
;
6905 bfd_size_type cnt_16b
= 0;
6907 if (!is_ppc64_elf (ibfd
))
6910 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6911 if (sec
== NULL
|| sec
->size
== 0)
6914 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6917 if (sec
->output_section
== bfd_abs_section_ptr
)
6920 /* Look through the section relocs. */
6921 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6925 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6927 /* Read the relocations. */
6928 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6930 if (relstart
== NULL
)
6933 /* First run through the relocs to check they are sane, and to
6934 determine whether we need to edit this opd section. */
6938 relend
= relstart
+ sec
->reloc_count
;
6939 for (rel
= relstart
; rel
< relend
; )
6941 enum elf_ppc64_reloc_type r_type
;
6942 unsigned long r_symndx
;
6944 struct elf_link_hash_entry
*h
;
6945 Elf_Internal_Sym
*sym
;
6947 /* .opd contains a regular array of 16 or 24 byte entries. We're
6948 only interested in the reloc pointing to a function entry
6950 if (rel
->r_offset
!= offset
6951 || rel
+ 1 >= relend
6952 || (rel
+ 1)->r_offset
!= offset
+ 8)
6954 /* If someone messes with .opd alignment then after a
6955 "ld -r" we might have padding in the middle of .opd.
6956 Also, there's nothing to prevent someone putting
6957 something silly in .opd with the assembler. No .opd
6958 optimization for them! */
6960 (*_bfd_error_handler
)
6961 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6966 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6967 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6969 (*_bfd_error_handler
)
6970 (_("%B: unexpected reloc type %u in .opd section"),
6976 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6977 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6981 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6983 const char *sym_name
;
6985 sym_name
= h
->root
.root
.string
;
6987 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6990 (*_bfd_error_handler
)
6991 (_("%B: undefined sym `%s' in .opd section"),
6997 /* opd entries are always for functions defined in the
6998 current input bfd. If the symbol isn't defined in the
6999 input bfd, then we won't be using the function in this
7000 bfd; It must be defined in a linkonce section in another
7001 bfd, or is weak. It's also possible that we are
7002 discarding the function due to a linker script /DISCARD/,
7003 which we test for via the output_section. */
7004 if (sym_sec
->owner
!= ibfd
7005 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7010 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
7012 if (sec
->size
== offset
+ 24)
7017 if (rel
== relend
&& sec
->size
== offset
+ 16)
7025 if (rel
->r_offset
== offset
+ 24)
7027 else if (rel
->r_offset
!= offset
+ 16)
7029 else if (rel
+ 1 < relend
7030 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7031 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7036 else if (rel
+ 2 < relend
7037 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
7038 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
7047 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
7049 if (need_edit
|| add_aux_fields
)
7051 Elf_Internal_Rela
*write_rel
;
7052 Elf_Internal_Shdr
*rel_hdr
;
7053 bfd_byte
*rptr
, *wptr
;
7054 bfd_byte
*new_contents
;
7059 new_contents
= NULL
;
7060 amt
= sec
->size
* sizeof (long) / 8;
7061 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7062 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7063 if (opd
->adjust
== NULL
)
7065 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
7067 /* This seems a waste of time as input .opd sections are all
7068 zeros as generated by gcc, but I suppose there's no reason
7069 this will always be so. We might start putting something in
7070 the third word of .opd entries. */
7071 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7074 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7079 if (local_syms
!= NULL
7080 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7082 if (elf_section_data (sec
)->relocs
!= relstart
)
7086 sec
->contents
= loc
;
7087 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7090 elf_section_data (sec
)->relocs
= relstart
;
7092 new_contents
= sec
->contents
;
7095 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7096 if (new_contents
== NULL
)
7100 wptr
= new_contents
;
7101 rptr
= sec
->contents
;
7103 write_rel
= relstart
;
7107 for (rel
= relstart
; rel
< relend
; rel
++)
7109 unsigned long r_symndx
;
7111 struct elf_link_hash_entry
*h
;
7112 Elf_Internal_Sym
*sym
;
7114 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7115 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7119 if (rel
->r_offset
== offset
)
7121 struct ppc_link_hash_entry
*fdh
= NULL
;
7123 /* See if the .opd entry is full 24 byte or
7124 16 byte (with fd_aux entry overlapped with next
7127 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
7128 || (rel
+ 3 < relend
7129 && rel
[2].r_offset
== offset
+ 16
7130 && rel
[3].r_offset
== offset
+ 24
7131 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
7132 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
7136 && h
->root
.root
.string
[0] == '.')
7138 struct ppc_link_hash_table
*htab
;
7140 htab
= ppc_hash_table (info
);
7142 fdh
= lookup_fdh ((struct ppc_link_hash_entry
*) h
,
7145 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
7146 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7150 skip
= (sym_sec
->owner
!= ibfd
7151 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7154 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7156 /* Arrange for the function descriptor sym
7158 fdh
->elf
.root
.u
.def
.value
= 0;
7159 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7161 opd
->adjust
[rel
->r_offset
/ 8] = -1;
7165 /* We'll be keeping this opd entry. */
7169 /* Redefine the function descriptor symbol to
7170 this location in the opd section. It is
7171 necessary to update the value here rather
7172 than using an array of adjustments as we do
7173 for local symbols, because various places
7174 in the generic ELF code use the value
7175 stored in u.def.value. */
7176 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7177 fdh
->adjust_done
= 1;
7180 /* Local syms are a bit tricky. We could
7181 tweak them as they can be cached, but
7182 we'd need to look through the local syms
7183 for the function descriptor sym which we
7184 don't have at the moment. So keep an
7185 array of adjustments. */
7186 opd
->adjust
[rel
->r_offset
/ 8]
7187 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
7190 memcpy (wptr
, rptr
, opd_ent_size
);
7191 wptr
+= opd_ent_size
;
7192 if (add_aux_fields
&& opd_ent_size
== 16)
7194 memset (wptr
, '\0', 8);
7198 rptr
+= opd_ent_size
;
7199 offset
+= opd_ent_size
;
7205 && !info
->relocatable
7206 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
7212 /* We need to adjust any reloc offsets to point to the
7213 new opd entries. While we're at it, we may as well
7214 remove redundant relocs. */
7215 rel
->r_offset
+= opd
->adjust
[(offset
- opd_ent_size
) / 8];
7216 if (write_rel
!= rel
)
7217 memcpy (write_rel
, rel
, sizeof (*rel
));
7222 sec
->size
= wptr
- new_contents
;
7223 sec
->reloc_count
= write_rel
- relstart
;
7226 free (sec
->contents
);
7227 sec
->contents
= new_contents
;
7230 /* Fudge the header size too, as this is used later in
7231 elf_bfd_final_link if we are emitting relocs. */
7232 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7233 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7236 else if (elf_section_data (sec
)->relocs
!= relstart
)
7239 if (local_syms
!= NULL
7240 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7242 if (!info
->keep_memory
)
7245 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7250 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7252 /* If we are doing a final link and the last .opd entry is just 16 byte
7253 long, add a 8 byte padding after it. */
7254 if (need_pad
!= NULL
&& !info
->relocatable
)
7258 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7260 BFD_ASSERT (need_pad
->size
> 0);
7262 p
= bfd_malloc (need_pad
->size
+ 8);
7266 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
7267 p
, 0, need_pad
->size
))
7270 need_pad
->contents
= p
;
7271 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7275 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7279 need_pad
->contents
= p
;
7282 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7283 need_pad
->size
+= 8;
7289 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7292 ppc64_elf_tls_setup (struct bfd_link_info
*info
,
7293 int no_tls_get_addr_opt
,
7296 struct ppc_link_hash_table
*htab
;
7298 htab
= ppc_hash_table (info
);
7303 htab
->do_multi_toc
= 0;
7304 else if (!htab
->do_multi_toc
)
7307 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7308 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7309 FALSE
, FALSE
, TRUE
));
7310 /* Move dynamic linking info to the function descriptor sym. */
7311 if (htab
->tls_get_addr
!= NULL
)
7312 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7313 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7314 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7315 FALSE
, FALSE
, TRUE
));
7316 if (!no_tls_get_addr_opt
)
7318 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7320 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7321 FALSE
, FALSE
, TRUE
);
7323 func_desc_adjust (opt
, info
);
7324 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7325 FALSE
, FALSE
, TRUE
);
7327 && (opt_fd
->root
.type
== bfd_link_hash_defined
7328 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7330 /* If glibc supports an optimized __tls_get_addr call stub,
7331 signalled by the presence of __tls_get_addr_opt, and we'll
7332 be calling __tls_get_addr via a plt call stub, then
7333 make __tls_get_addr point to __tls_get_addr_opt. */
7334 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7335 if (htab
->elf
.dynamic_sections_created
7337 && (tga_fd
->type
== STT_FUNC
7338 || tga_fd
->needs_plt
)
7339 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7340 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
7341 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
7343 struct plt_entry
*ent
;
7345 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7346 if (ent
->plt
.refcount
> 0)
7350 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7351 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7352 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7353 if (opt_fd
->dynindx
!= -1)
7355 /* Use __tls_get_addr_opt in dynamic relocations. */
7356 opt_fd
->dynindx
= -1;
7357 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7358 opt_fd
->dynstr_index
);
7359 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7362 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
7363 tga
= &htab
->tls_get_addr
->elf
;
7364 if (opt
!= NULL
&& tga
!= NULL
)
7366 tga
->root
.type
= bfd_link_hash_indirect
;
7367 tga
->root
.u
.i
.link
= &opt
->root
;
7368 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7369 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7371 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7373 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7374 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7375 if (htab
->tls_get_addr
!= NULL
)
7377 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7378 htab
->tls_get_addr
->is_func
= 1;
7384 no_tls_get_addr_opt
= TRUE
;
7386 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
7387 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7390 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7394 branch_reloc_hash_match (const bfd
*ibfd
,
7395 const Elf_Internal_Rela
*rel
,
7396 const struct ppc_link_hash_entry
*hash1
,
7397 const struct ppc_link_hash_entry
*hash2
)
7399 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7400 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7401 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7403 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7405 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7406 struct elf_link_hash_entry
*h
;
7408 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7409 h
= elf_follow_link (h
);
7410 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7416 /* Run through all the TLS relocs looking for optimization
7417 opportunities. The linker has been hacked (see ppc64elf.em) to do
7418 a preliminary section layout so that we know the TLS segment
7419 offsets. We can't optimize earlier because some optimizations need
7420 to know the tp offset, and we need to optimize before allocating
7421 dynamic relocations. */
7424 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7428 struct ppc_link_hash_table
*htab
;
7429 unsigned char *toc_ref
;
7432 if (info
->relocatable
|| !info
->executable
)
7435 htab
= ppc_hash_table (info
);
7439 /* Make two passes over the relocs. On the first pass, mark toc
7440 entries involved with tls relocs, and check that tls relocs
7441 involved in setting up a tls_get_addr call are indeed followed by
7442 such a call. If they are not, we can't do any tls optimization.
7443 On the second pass twiddle tls_mask flags to notify
7444 relocate_section that optimization can be done, and adjust got
7445 and plt refcounts. */
7447 for (pass
= 0; pass
< 2; ++pass
)
7448 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7450 Elf_Internal_Sym
*locsyms
= NULL
;
7451 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7453 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7454 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7456 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7457 bfd_boolean found_tls_get_addr_arg
= 0;
7459 /* Read the relocations. */
7460 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7462 if (relstart
== NULL
)
7465 relend
= relstart
+ sec
->reloc_count
;
7466 for (rel
= relstart
; rel
< relend
; rel
++)
7468 enum elf_ppc64_reloc_type r_type
;
7469 unsigned long r_symndx
;
7470 struct elf_link_hash_entry
*h
;
7471 Elf_Internal_Sym
*sym
;
7473 unsigned char *tls_mask
;
7474 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7476 bfd_boolean ok_tprel
, is_local
;
7477 long toc_ref_index
= 0;
7478 int expecting_tls_get_addr
= 0;
7479 bfd_boolean ret
= FALSE
;
7481 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7482 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7486 if (elf_section_data (sec
)->relocs
!= relstart
)
7488 if (toc_ref
!= NULL
)
7491 && (elf_symtab_hdr (ibfd
).contents
7492 != (unsigned char *) locsyms
))
7499 if (h
->root
.type
== bfd_link_hash_defined
7500 || h
->root
.type
== bfd_link_hash_defweak
)
7501 value
= h
->root
.u
.def
.value
;
7502 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7506 found_tls_get_addr_arg
= 0;
7511 /* Symbols referenced by TLS relocs must be of type
7512 STT_TLS. So no need for .opd local sym adjust. */
7513 value
= sym
->st_value
;
7522 && h
->root
.type
== bfd_link_hash_undefweak
)
7526 value
+= sym_sec
->output_offset
;
7527 value
+= sym_sec
->output_section
->vma
;
7528 value
-= htab
->elf
.tls_sec
->vma
;
7529 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7530 < (bfd_vma
) 1 << 32);
7534 r_type
= ELF64_R_TYPE (rel
->r_info
);
7535 /* If this section has old-style __tls_get_addr calls
7536 without marker relocs, then check that each
7537 __tls_get_addr call reloc is preceded by a reloc
7538 that conceivably belongs to the __tls_get_addr arg
7539 setup insn. If we don't find matching arg setup
7540 relocs, don't do any tls optimization. */
7542 && sec
->has_tls_get_addr_call
7544 && (h
== &htab
->tls_get_addr
->elf
7545 || h
== &htab
->tls_get_addr_fd
->elf
)
7546 && !found_tls_get_addr_arg
7547 && is_branch_reloc (r_type
))
7549 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7550 "TLS optimization disabled\n"),
7551 ibfd
, sec
, rel
->r_offset
);
7556 found_tls_get_addr_arg
= 0;
7559 case R_PPC64_GOT_TLSLD16
:
7560 case R_PPC64_GOT_TLSLD16_LO
:
7561 expecting_tls_get_addr
= 1;
7562 found_tls_get_addr_arg
= 1;
7565 case R_PPC64_GOT_TLSLD16_HI
:
7566 case R_PPC64_GOT_TLSLD16_HA
:
7567 /* These relocs should never be against a symbol
7568 defined in a shared lib. Leave them alone if
7569 that turns out to be the case. */
7576 tls_type
= TLS_TLS
| TLS_LD
;
7579 case R_PPC64_GOT_TLSGD16
:
7580 case R_PPC64_GOT_TLSGD16_LO
:
7581 expecting_tls_get_addr
= 1;
7582 found_tls_get_addr_arg
= 1;
7585 case R_PPC64_GOT_TLSGD16_HI
:
7586 case R_PPC64_GOT_TLSGD16_HA
:
7592 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7594 tls_type
= TLS_TLS
| TLS_GD
;
7597 case R_PPC64_GOT_TPREL16_DS
:
7598 case R_PPC64_GOT_TPREL16_LO_DS
:
7599 case R_PPC64_GOT_TPREL16_HI
:
7600 case R_PPC64_GOT_TPREL16_HA
:
7605 tls_clear
= TLS_TPREL
;
7606 tls_type
= TLS_TLS
| TLS_TPREL
;
7613 found_tls_get_addr_arg
= 1;
7618 case R_PPC64_TOC16_LO
:
7619 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7622 /* Mark this toc entry as referenced by a TLS
7623 code sequence. We can do that now in the
7624 case of R_PPC64_TLS, and after checking for
7625 tls_get_addr for the TOC16 relocs. */
7626 if (toc_ref
== NULL
)
7627 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7628 if (toc_ref
== NULL
)
7632 value
= h
->root
.u
.def
.value
;
7634 value
= sym
->st_value
;
7635 value
+= rel
->r_addend
;
7636 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
7637 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7638 if (r_type
== R_PPC64_TLS
7639 || r_type
== R_PPC64_TLSGD
7640 || r_type
== R_PPC64_TLSLD
)
7642 toc_ref
[toc_ref_index
] = 1;
7646 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7651 expecting_tls_get_addr
= 2;
7654 case R_PPC64_TPREL64
:
7658 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7663 tls_set
= TLS_EXPLICIT
;
7664 tls_clear
= TLS_TPREL
;
7669 case R_PPC64_DTPMOD64
:
7673 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7675 if (rel
+ 1 < relend
7677 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7678 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7682 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7685 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7694 tls_set
= TLS_EXPLICIT
;
7705 if (!expecting_tls_get_addr
7706 || !sec
->has_tls_get_addr_call
)
7709 if (rel
+ 1 < relend
7710 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7712 htab
->tls_get_addr_fd
))
7714 if (expecting_tls_get_addr
== 2)
7716 /* Check for toc tls entries. */
7717 unsigned char *toc_tls
;
7720 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7725 if (toc_tls
!= NULL
)
7727 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
7728 found_tls_get_addr_arg
= 1;
7730 toc_ref
[toc_ref_index
] = 1;
7736 if (expecting_tls_get_addr
!= 1)
7739 /* Uh oh, we didn't find the expected call. We
7740 could just mark this symbol to exclude it
7741 from tls optimization but it's safer to skip
7742 the entire optimization. */
7743 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7744 "TLS optimization disabled\n"),
7745 ibfd
, sec
, rel
->r_offset
);
7750 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
7752 struct plt_entry
*ent
;
7753 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7756 if (ent
->addend
== 0)
7758 if (ent
->plt
.refcount
> 0)
7760 ent
->plt
.refcount
-= 1;
7761 expecting_tls_get_addr
= 0;
7767 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
7769 struct plt_entry
*ent
;
7770 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7773 if (ent
->addend
== 0)
7775 if (ent
->plt
.refcount
> 0)
7776 ent
->plt
.refcount
-= 1;
7784 if ((tls_set
& TLS_EXPLICIT
) == 0)
7786 struct got_entry
*ent
;
7788 /* Adjust got entry for this reloc. */
7792 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7794 for (; ent
!= NULL
; ent
= ent
->next
)
7795 if (ent
->addend
== rel
->r_addend
7796 && ent
->owner
== ibfd
7797 && ent
->tls_type
== tls_type
)
7804 /* We managed to get rid of a got entry. */
7805 if (ent
->got
.refcount
> 0)
7806 ent
->got
.refcount
-= 1;
7811 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7812 we'll lose one or two dyn relocs. */
7813 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7817 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7819 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7825 *tls_mask
|= tls_set
;
7826 *tls_mask
&= ~tls_clear
;
7829 if (elf_section_data (sec
)->relocs
!= relstart
)
7834 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7836 if (!info
->keep_memory
)
7839 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7843 if (toc_ref
!= NULL
)
7848 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7849 the values of any global symbols in a toc section that has been
7850 edited. Globals in toc sections should be a rarity, so this function
7851 sets a flag if any are found in toc sections other than the one just
7852 edited, so that futher hash table traversals can be avoided. */
7854 struct adjust_toc_info
7857 unsigned long *skip
;
7858 bfd_boolean global_toc_syms
;
7861 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7864 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7866 struct ppc_link_hash_entry
*eh
;
7867 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7870 if (h
->root
.type
== bfd_link_hash_indirect
)
7873 if (h
->root
.type
!= bfd_link_hash_defined
7874 && h
->root
.type
!= bfd_link_hash_defweak
)
7877 eh
= (struct ppc_link_hash_entry
*) h
;
7878 if (eh
->adjust_done
)
7881 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7883 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7884 i
= toc_inf
->toc
->rawsize
>> 3;
7886 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7888 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7890 (*_bfd_error_handler
)
7891 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7894 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7895 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7898 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7899 eh
->adjust_done
= 1;
7901 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7902 toc_inf
->global_toc_syms
= TRUE
;
7907 /* Examine all relocs referencing .toc sections in order to remove
7908 unused .toc entries. */
7911 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7914 struct adjust_toc_info toc_inf
;
7915 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7917 htab
->do_toc_opt
= 1;
7918 toc_inf
.global_toc_syms
= TRUE
;
7919 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7921 asection
*toc
, *sec
;
7922 Elf_Internal_Shdr
*symtab_hdr
;
7923 Elf_Internal_Sym
*local_syms
;
7924 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7925 unsigned long *skip
, *drop
;
7926 unsigned char *used
;
7927 unsigned char *keep
, last
, some_unused
;
7929 if (!is_ppc64_elf (ibfd
))
7932 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7935 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7936 || elf_discarded_section (toc
))
7941 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7943 /* Look at sections dropped from the final link. */
7946 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7948 if (sec
->reloc_count
== 0
7949 || !elf_discarded_section (sec
)
7950 || get_opd_info (sec
)
7951 || (sec
->flags
& SEC_ALLOC
) == 0
7952 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7955 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7956 if (relstart
== NULL
)
7959 /* Run through the relocs to see which toc entries might be
7961 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7963 enum elf_ppc64_reloc_type r_type
;
7964 unsigned long r_symndx
;
7966 struct elf_link_hash_entry
*h
;
7967 Elf_Internal_Sym
*sym
;
7970 r_type
= ELF64_R_TYPE (rel
->r_info
);
7977 case R_PPC64_TOC16_LO
:
7978 case R_PPC64_TOC16_HI
:
7979 case R_PPC64_TOC16_HA
:
7980 case R_PPC64_TOC16_DS
:
7981 case R_PPC64_TOC16_LO_DS
:
7985 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7986 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7994 val
= h
->root
.u
.def
.value
;
7996 val
= sym
->st_value
;
7997 val
+= rel
->r_addend
;
7999 if (val
>= toc
->size
)
8002 /* Anything in the toc ought to be aligned to 8 bytes.
8003 If not, don't mark as unused. */
8009 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8014 skip
[val
>> 3] = ref_from_discarded
;
8017 if (elf_section_data (sec
)->relocs
!= relstart
)
8021 /* For largetoc loads of address constants, we can convert
8022 . addis rx,2,addr@got@ha
8023 . ld ry,addr@got@l(rx)
8025 . addis rx,2,addr@toc@ha
8026 . addi ry,rx,addr@toc@l
8027 when addr is within 2G of the toc pointer. This then means
8028 that the word storing "addr" in the toc is no longer needed. */
8030 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8031 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8032 && toc
->reloc_count
!= 0)
8034 /* Read toc relocs. */
8035 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8037 if (toc_relocs
== NULL
)
8040 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8042 enum elf_ppc64_reloc_type r_type
;
8043 unsigned long r_symndx
;
8045 struct elf_link_hash_entry
*h
;
8046 Elf_Internal_Sym
*sym
;
8049 r_type
= ELF64_R_TYPE (rel
->r_info
);
8050 if (r_type
!= R_PPC64_ADDR64
)
8053 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8054 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8059 || elf_discarded_section (sym_sec
))
8062 if (!SYMBOL_CALLS_LOCAL (info
, h
))
8067 if (h
->type
== STT_GNU_IFUNC
)
8069 val
= h
->root
.u
.def
.value
;
8073 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8075 val
= sym
->st_value
;
8077 val
+= rel
->r_addend
;
8078 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8080 /* We don't yet know the exact toc pointer value, but we
8081 know it will be somewhere in the toc section. Don't
8082 optimize if the difference from any possible toc
8083 pointer is outside [ff..f80008000, 7fff7fff]. */
8084 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8085 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8088 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8089 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8094 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8099 skip
[rel
->r_offset
>> 3]
8100 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8107 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8111 if (local_syms
!= NULL
8112 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8116 && elf_section_data (sec
)->relocs
!= relstart
)
8118 if (toc_relocs
!= NULL
8119 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8126 /* Now check all kept sections that might reference the toc.
8127 Check the toc itself last. */
8128 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8131 sec
= (sec
== toc
? NULL
8132 : sec
->next
== NULL
? toc
8133 : sec
->next
== toc
&& toc
->next
? toc
->next
8138 if (sec
->reloc_count
== 0
8139 || elf_discarded_section (sec
)
8140 || get_opd_info (sec
)
8141 || (sec
->flags
& SEC_ALLOC
) == 0
8142 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8145 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8147 if (relstart
== NULL
)
8150 /* Mark toc entries referenced as used. */
8153 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8155 enum elf_ppc64_reloc_type r_type
;
8156 unsigned long r_symndx
;
8158 struct elf_link_hash_entry
*h
;
8159 Elf_Internal_Sym
*sym
;
8162 r_type
= ELF64_R_TYPE (rel
->r_info
);
8166 case R_PPC64_TOC16_LO
:
8167 case R_PPC64_TOC16_HI
:
8168 case R_PPC64_TOC16_HA
:
8169 case R_PPC64_TOC16_DS
:
8170 case R_PPC64_TOC16_LO_DS
:
8171 /* In case we're taking addresses of toc entries. */
8172 case R_PPC64_ADDR64
:
8179 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8180 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8191 val
= h
->root
.u
.def
.value
;
8193 val
= sym
->st_value
;
8194 val
+= rel
->r_addend
;
8196 if (val
>= toc
->size
)
8199 if ((skip
[val
>> 3] & can_optimize
) != 0)
8206 case R_PPC64_TOC16_HA
:
8209 case R_PPC64_TOC16_LO_DS
:
8210 off
= rel
->r_offset
+ (bfd_big_endian (ibfd
) ? -2 : 3);
8211 if (!bfd_get_section_contents (ibfd
, sec
, &opc
, off
, 1))
8213 if ((opc
& (0x3f << 2)) == (58u << 2))
8218 /* Wrong sort of reloc, or not a ld. We may
8219 as well clear ref_from_discarded too. */
8224 /* For the toc section, we only mark as used if
8225 this entry itself isn't unused. */
8228 && (used
[rel
->r_offset
>> 3]
8229 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
)))
8230 /* Do all the relocs again, to catch reference
8238 if (elf_section_data (sec
)->relocs
!= relstart
)
8242 /* Merge the used and skip arrays. Assume that TOC
8243 doublewords not appearing as either used or unused belong
8244 to to an entry more than one doubleword in size. */
8245 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8246 drop
< skip
+ (toc
->size
+ 7) / 8;
8251 *drop
&= ~ref_from_discarded
;
8252 if ((*drop
& can_optimize
) != 0)
8259 last
= ref_from_discarded
;
8269 bfd_byte
*contents
, *src
;
8271 Elf_Internal_Sym
*sym
;
8272 bfd_boolean local_toc_syms
= FALSE
;
8274 /* Shuffle the toc contents, and at the same time convert the
8275 skip array from booleans into offsets. */
8276 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8279 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8281 for (src
= contents
, off
= 0, drop
= skip
;
8282 src
< contents
+ toc
->size
;
8285 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8290 memcpy (src
- off
, src
, 8);
8294 toc
->rawsize
= toc
->size
;
8295 toc
->size
= src
- contents
- off
;
8297 /* Adjust addends for relocs against the toc section sym,
8298 and optimize any accesses we can. */
8299 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8301 if (sec
->reloc_count
== 0
8302 || elf_discarded_section (sec
))
8305 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8307 if (relstart
== NULL
)
8310 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8312 enum elf_ppc64_reloc_type r_type
;
8313 unsigned long r_symndx
;
8315 struct elf_link_hash_entry
*h
;
8318 r_type
= ELF64_R_TYPE (rel
->r_info
);
8325 case R_PPC64_TOC16_LO
:
8326 case R_PPC64_TOC16_HI
:
8327 case R_PPC64_TOC16_HA
:
8328 case R_PPC64_TOC16_DS
:
8329 case R_PPC64_TOC16_LO_DS
:
8330 case R_PPC64_ADDR64
:
8334 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8335 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8343 val
= h
->root
.u
.def
.value
;
8346 val
= sym
->st_value
;
8348 local_toc_syms
= TRUE
;
8351 val
+= rel
->r_addend
;
8353 if (val
> toc
->rawsize
)
8355 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8357 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8359 Elf_Internal_Rela
*tocrel
8360 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8361 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8365 case R_PPC64_TOC16_HA
:
8366 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8369 case R_PPC64_TOC16_LO_DS
:
8370 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8376 rel
->r_addend
= tocrel
->r_addend
;
8377 elf_section_data (sec
)->relocs
= relstart
;
8381 if (h
!= NULL
|| sym
->st_value
!= 0)
8384 rel
->r_addend
-= skip
[val
>> 3];
8385 elf_section_data (sec
)->relocs
= relstart
;
8388 if (elf_section_data (sec
)->relocs
!= relstart
)
8392 /* We shouldn't have local or global symbols defined in the TOC,
8393 but handle them anyway. */
8394 if (local_syms
!= NULL
)
8395 for (sym
= local_syms
;
8396 sym
< local_syms
+ symtab_hdr
->sh_info
;
8398 if (sym
->st_value
!= 0
8399 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8403 if (sym
->st_value
> toc
->rawsize
)
8404 i
= toc
->rawsize
>> 3;
8406 i
= sym
->st_value
>> 3;
8408 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8411 (*_bfd_error_handler
)
8412 (_("%s defined on removed toc entry"),
8413 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8416 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8417 sym
->st_value
= (bfd_vma
) i
<< 3;
8420 sym
->st_value
-= skip
[i
];
8421 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8424 /* Adjust any global syms defined in this toc input section. */
8425 if (toc_inf
.global_toc_syms
)
8428 toc_inf
.skip
= skip
;
8429 toc_inf
.global_toc_syms
= FALSE
;
8430 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8434 if (toc
->reloc_count
!= 0)
8436 Elf_Internal_Shdr
*rel_hdr
;
8437 Elf_Internal_Rela
*wrel
;
8440 /* Remove unused toc relocs, and adjust those we keep. */
8441 if (toc_relocs
== NULL
)
8442 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8444 if (toc_relocs
== NULL
)
8448 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8449 if ((skip
[rel
->r_offset
>> 3]
8450 & (ref_from_discarded
| can_optimize
)) == 0)
8452 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8453 wrel
->r_info
= rel
->r_info
;
8454 wrel
->r_addend
= rel
->r_addend
;
8457 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8458 &local_syms
, NULL
, NULL
))
8461 elf_section_data (toc
)->relocs
= toc_relocs
;
8462 toc
->reloc_count
= wrel
- toc_relocs
;
8463 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8464 sz
= rel_hdr
->sh_entsize
;
8465 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8468 else if (toc_relocs
!= NULL
8469 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8472 if (local_syms
!= NULL
8473 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8475 if (!info
->keep_memory
)
8478 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8486 /* Return true iff input section I references the TOC using
8487 instructions limited to +/-32k offsets. */
8490 ppc64_elf_has_small_toc_reloc (asection
*i
)
8492 return (is_ppc64_elf (i
->owner
)
8493 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8496 /* Allocate space for one GOT entry. */
8499 allocate_got (struct elf_link_hash_entry
*h
,
8500 struct bfd_link_info
*info
,
8501 struct got_entry
*gent
)
8503 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8505 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8506 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8508 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8509 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8510 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8512 gent
->got
.offset
= got
->size
;
8513 got
->size
+= entsize
;
8515 dyn
= htab
->elf
.dynamic_sections_created
;
8517 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8518 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8519 || h
->root
.type
!= bfd_link_hash_undefweak
))
8521 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8522 relgot
->size
+= rentsize
;
8524 else if (h
->type
== STT_GNU_IFUNC
)
8526 asection
*relgot
= htab
->reliplt
;
8527 relgot
->size
+= rentsize
;
8528 htab
->got_reli_size
+= rentsize
;
8532 /* This function merges got entries in the same toc group. */
8535 merge_got_entries (struct got_entry
**pent
)
8537 struct got_entry
*ent
, *ent2
;
8539 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8540 if (!ent
->is_indirect
)
8541 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8542 if (!ent2
->is_indirect
8543 && ent2
->addend
== ent
->addend
8544 && ent2
->tls_type
== ent
->tls_type
8545 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8547 ent2
->is_indirect
= TRUE
;
8548 ent2
->got
.ent
= ent
;
8552 /* Allocate space in .plt, .got and associated reloc sections for
8556 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8558 struct bfd_link_info
*info
;
8559 struct ppc_link_hash_table
*htab
;
8561 struct ppc_link_hash_entry
*eh
;
8562 struct elf_dyn_relocs
*p
;
8563 struct got_entry
**pgent
, *gent
;
8565 if (h
->root
.type
== bfd_link_hash_indirect
)
8568 info
= (struct bfd_link_info
*) inf
;
8569 htab
= ppc_hash_table (info
);
8573 if ((htab
->elf
.dynamic_sections_created
8575 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
8576 || h
->type
== STT_GNU_IFUNC
)
8578 struct plt_entry
*pent
;
8579 bfd_boolean doneone
= FALSE
;
8580 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8581 if (pent
->plt
.refcount
> 0)
8583 if (!htab
->elf
.dynamic_sections_created
8584 || h
->dynindx
== -1)
8587 pent
->plt
.offset
= s
->size
;
8588 s
->size
+= PLT_ENTRY_SIZE
;
8593 /* If this is the first .plt entry, make room for the special
8597 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
8599 pent
->plt
.offset
= s
->size
;
8601 /* Make room for this entry. */
8602 s
->size
+= PLT_ENTRY_SIZE
;
8604 /* Make room for the .glink code. */
8607 s
->size
+= GLINK_CALL_STUB_SIZE
;
8608 /* We need bigger stubs past index 32767. */
8609 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
8613 /* We also need to make an entry in the .rela.plt section. */
8616 s
->size
+= sizeof (Elf64_External_Rela
);
8620 pent
->plt
.offset
= (bfd_vma
) -1;
8623 h
->plt
.plist
= NULL
;
8629 h
->plt
.plist
= NULL
;
8633 eh
= (struct ppc_link_hash_entry
*) h
;
8634 /* Run through the TLS GD got entries first if we're changing them
8636 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
8637 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8638 if (gent
->got
.refcount
> 0
8639 && (gent
->tls_type
& TLS_GD
) != 0)
8641 /* This was a GD entry that has been converted to TPREL. If
8642 there happens to be a TPREL entry we can use that one. */
8643 struct got_entry
*ent
;
8644 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8645 if (ent
->got
.refcount
> 0
8646 && (ent
->tls_type
& TLS_TPREL
) != 0
8647 && ent
->addend
== gent
->addend
8648 && ent
->owner
== gent
->owner
)
8650 gent
->got
.refcount
= 0;
8654 /* If not, then we'll be using our own TPREL entry. */
8655 if (gent
->got
.refcount
!= 0)
8656 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8659 /* Remove any list entry that won't generate a word in the GOT before
8660 we call merge_got_entries. Otherwise we risk merging to empty
8662 pgent
= &h
->got
.glist
;
8663 while ((gent
= *pgent
) != NULL
)
8664 if (gent
->got
.refcount
> 0)
8666 if ((gent
->tls_type
& TLS_LD
) != 0
8669 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8670 *pgent
= gent
->next
;
8673 pgent
= &gent
->next
;
8676 *pgent
= gent
->next
;
8678 if (!htab
->do_multi_toc
)
8679 merge_got_entries (&h
->got
.glist
);
8681 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8682 if (!gent
->is_indirect
)
8684 /* Make sure this symbol is output as a dynamic symbol.
8685 Undefined weak syms won't yet be marked as dynamic,
8686 nor will all TLS symbols. */
8687 if (h
->dynindx
== -1
8689 && h
->type
!= STT_GNU_IFUNC
8690 && htab
->elf
.dynamic_sections_created
)
8692 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8696 if (!is_ppc64_elf (gent
->owner
))
8699 allocate_got (h
, info
, gent
);
8702 if (eh
->dyn_relocs
== NULL
8703 || (!htab
->elf
.dynamic_sections_created
8704 && h
->type
!= STT_GNU_IFUNC
))
8707 /* In the shared -Bsymbolic case, discard space allocated for
8708 dynamic pc-relative relocs against symbols which turn out to be
8709 defined in regular objects. For the normal shared case, discard
8710 space for relocs that have become local due to symbol visibility
8715 /* Relocs that use pc_count are those that appear on a call insn,
8716 or certain REL relocs (see must_be_dyn_reloc) that can be
8717 generated via assembly. We want calls to protected symbols to
8718 resolve directly to the function rather than going via the plt.
8719 If people want function pointer comparisons to work as expected
8720 then they should avoid writing weird assembly. */
8721 if (SYMBOL_CALLS_LOCAL (info
, h
))
8723 struct elf_dyn_relocs
**pp
;
8725 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8727 p
->count
-= p
->pc_count
;
8736 /* Also discard relocs on undefined weak syms with non-default
8738 if (eh
->dyn_relocs
!= NULL
8739 && h
->root
.type
== bfd_link_hash_undefweak
)
8741 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8742 eh
->dyn_relocs
= NULL
;
8744 /* Make sure this symbol is output as a dynamic symbol.
8745 Undefined weak syms won't yet be marked as dynamic. */
8746 else if (h
->dynindx
== -1
8747 && !h
->forced_local
)
8749 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8754 else if (h
->type
== STT_GNU_IFUNC
)
8756 if (!h
->non_got_ref
)
8757 eh
->dyn_relocs
= NULL
;
8759 else if (ELIMINATE_COPY_RELOCS
)
8761 /* For the non-shared case, discard space for relocs against
8762 symbols which turn out to need copy relocs or are not
8768 /* Make sure this symbol is output as a dynamic symbol.
8769 Undefined weak syms won't yet be marked as dynamic. */
8770 if (h
->dynindx
== -1
8771 && !h
->forced_local
)
8773 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8777 /* If that succeeded, we know we'll be keeping all the
8779 if (h
->dynindx
!= -1)
8783 eh
->dyn_relocs
= NULL
;
8788 /* Finally, allocate space. */
8789 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8791 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8792 if (!htab
->elf
.dynamic_sections_created
)
8793 sreloc
= htab
->reliplt
;
8794 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8800 /* Find any dynamic relocs that apply to read-only sections. */
8803 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8805 struct ppc_link_hash_entry
*eh
;
8806 struct elf_dyn_relocs
*p
;
8808 eh
= (struct ppc_link_hash_entry
*) h
;
8809 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8811 asection
*s
= p
->sec
->output_section
;
8813 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8815 struct bfd_link_info
*info
= inf
;
8817 info
->flags
|= DF_TEXTREL
;
8819 /* Not an error, just cut short the traversal. */
8826 /* Set the sizes of the dynamic sections. */
8829 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8830 struct bfd_link_info
*info
)
8832 struct ppc_link_hash_table
*htab
;
8837 struct got_entry
*first_tlsld
;
8839 htab
= ppc_hash_table (info
);
8843 dynobj
= htab
->elf
.dynobj
;
8847 if (htab
->elf
.dynamic_sections_created
)
8849 /* Set the contents of the .interp section to the interpreter. */
8850 if (info
->executable
)
8852 s
= bfd_get_section_by_name (dynobj
, ".interp");
8855 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8856 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8860 /* Set up .got offsets for local syms, and space for local dynamic
8862 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8864 struct got_entry
**lgot_ents
;
8865 struct got_entry
**end_lgot_ents
;
8866 struct plt_entry
**local_plt
;
8867 struct plt_entry
**end_local_plt
;
8868 unsigned char *lgot_masks
;
8869 bfd_size_type locsymcount
;
8870 Elf_Internal_Shdr
*symtab_hdr
;
8873 if (!is_ppc64_elf (ibfd
))
8876 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8878 struct elf_dyn_relocs
*p
;
8880 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
8882 if (!bfd_is_abs_section (p
->sec
)
8883 && bfd_is_abs_section (p
->sec
->output_section
))
8885 /* Input section has been discarded, either because
8886 it is a copy of a linkonce section or due to
8887 linker script /DISCARD/, so we'll be discarding
8890 else if (p
->count
!= 0)
8892 srel
= elf_section_data (p
->sec
)->sreloc
;
8893 if (!htab
->elf
.dynamic_sections_created
)
8894 srel
= htab
->reliplt
;
8895 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8896 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8897 info
->flags
|= DF_TEXTREL
;
8902 lgot_ents
= elf_local_got_ents (ibfd
);
8906 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8907 locsymcount
= symtab_hdr
->sh_info
;
8908 end_lgot_ents
= lgot_ents
+ locsymcount
;
8909 local_plt
= (struct plt_entry
**) end_lgot_ents
;
8910 end_local_plt
= local_plt
+ locsymcount
;
8911 lgot_masks
= (unsigned char *) end_local_plt
;
8912 s
= ppc64_elf_tdata (ibfd
)->got
;
8913 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
8914 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
8916 struct got_entry
**pent
, *ent
;
8919 while ((ent
= *pent
) != NULL
)
8920 if (ent
->got
.refcount
> 0)
8922 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
8924 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
8929 unsigned int num
= 1;
8930 ent
->got
.offset
= s
->size
;
8931 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
8935 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
8936 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
8939 += num
* sizeof (Elf64_External_Rela
);
8941 += num
* sizeof (Elf64_External_Rela
);
8950 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
8951 for (; local_plt
< end_local_plt
; ++local_plt
)
8953 struct plt_entry
*ent
;
8955 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
8956 if (ent
->plt
.refcount
> 0)
8959 ent
->plt
.offset
= s
->size
;
8960 s
->size
+= PLT_ENTRY_SIZE
;
8962 htab
->reliplt
->size
+= sizeof (Elf64_External_Rela
);
8965 ent
->plt
.offset
= (bfd_vma
) -1;
8969 /* Allocate global sym .plt and .got entries, and space for global
8970 sym dynamic relocs. */
8971 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
8974 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8976 struct got_entry
*ent
;
8978 if (!is_ppc64_elf (ibfd
))
8981 ent
= ppc64_tlsld_got (ibfd
);
8982 if (ent
->got
.refcount
> 0)
8984 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
8986 ent
->is_indirect
= TRUE
;
8987 ent
->got
.ent
= first_tlsld
;
8991 if (first_tlsld
== NULL
)
8993 s
= ppc64_elf_tdata (ibfd
)->got
;
8994 ent
->got
.offset
= s
->size
;
8999 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9000 srel
->size
+= sizeof (Elf64_External_Rela
);
9005 ent
->got
.offset
= (bfd_vma
) -1;
9008 /* We now have determined the sizes of the various dynamic sections.
9009 Allocate memory for them. */
9011 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9013 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9016 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9017 /* These haven't been allocated yet; don't strip. */
9019 else if (s
== htab
->got
9023 || s
== htab
->dynbss
)
9025 /* Strip this section if we don't need it; see the
9028 else if (CONST_STRNEQ (s
->name
, ".rela"))
9032 if (s
!= htab
->relplt
)
9035 /* We use the reloc_count field as a counter if we need
9036 to copy relocs into the output file. */
9042 /* It's not one of our sections, so don't allocate space. */
9048 /* If we don't need this section, strip it from the
9049 output file. This is mostly to handle .rela.bss and
9050 .rela.plt. We must create both sections in
9051 create_dynamic_sections, because they must be created
9052 before the linker maps input sections to output
9053 sections. The linker does that before
9054 adjust_dynamic_symbol is called, and it is that
9055 function which decides whether anything needs to go
9056 into these sections. */
9057 s
->flags
|= SEC_EXCLUDE
;
9061 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9064 /* Allocate memory for the section contents. We use bfd_zalloc
9065 here in case unused entries are not reclaimed before the
9066 section's contents are written out. This should not happen,
9067 but this way if it does we get a R_PPC64_NONE reloc in .rela
9068 sections instead of garbage.
9069 We also rely on the section contents being zero when writing
9071 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9072 if (s
->contents
== NULL
)
9076 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9078 if (!is_ppc64_elf (ibfd
))
9081 s
= ppc64_elf_tdata (ibfd
)->got
;
9082 if (s
!= NULL
&& s
!= htab
->got
)
9085 s
->flags
|= SEC_EXCLUDE
;
9088 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9089 if (s
->contents
== NULL
)
9093 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9097 s
->flags
|= SEC_EXCLUDE
;
9100 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9101 if (s
->contents
== NULL
)
9109 if (htab
->elf
.dynamic_sections_created
)
9111 /* Add some entries to the .dynamic section. We fill in the
9112 values later, in ppc64_elf_finish_dynamic_sections, but we
9113 must add the entries now so that we get the correct size for
9114 the .dynamic section. The DT_DEBUG entry is filled in by the
9115 dynamic linker and used by the debugger. */
9116 #define add_dynamic_entry(TAG, VAL) \
9117 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9119 if (info
->executable
)
9121 if (!add_dynamic_entry (DT_DEBUG
, 0))
9125 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
9127 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9128 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9129 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9130 || !add_dynamic_entry (DT_JMPREL
, 0)
9131 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9137 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9138 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9142 if (!htab
->no_tls_get_addr_opt
9143 && htab
->tls_get_addr_fd
!= NULL
9144 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
9145 && !add_dynamic_entry (DT_PPC64_TLSOPT
, 0))
9150 if (!add_dynamic_entry (DT_RELA
, 0)
9151 || !add_dynamic_entry (DT_RELASZ
, 0)
9152 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9155 /* If any dynamic relocs apply to a read-only section,
9156 then we need a DT_TEXTREL entry. */
9157 if ((info
->flags
& DF_TEXTREL
) == 0)
9158 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
9160 if ((info
->flags
& DF_TEXTREL
) != 0)
9162 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9167 #undef add_dynamic_entry
9172 /* Determine the type of stub needed, if any, for a call. */
9174 static inline enum ppc_stub_type
9175 ppc_type_of_stub (asection
*input_sec
,
9176 const Elf_Internal_Rela
*rel
,
9177 struct ppc_link_hash_entry
**hash
,
9178 struct plt_entry
**plt_ent
,
9179 bfd_vma destination
)
9181 struct ppc_link_hash_entry
*h
= *hash
;
9183 bfd_vma branch_offset
;
9184 bfd_vma max_branch_offset
;
9185 enum elf_ppc64_reloc_type r_type
;
9189 struct plt_entry
*ent
;
9190 struct ppc_link_hash_entry
*fdh
= h
;
9192 && h
->oh
->is_func_descriptor
)
9194 fdh
= ppc_follow_link (h
->oh
);
9198 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9199 if (ent
->addend
== rel
->r_addend
9200 && ent
->plt
.offset
!= (bfd_vma
) -1)
9203 return ppc_stub_plt_call
;
9206 /* Here, we know we don't have a plt entry. If we don't have a
9207 either a defined function descriptor or a defined entry symbol
9208 in a regular object file, then it is pointless trying to make
9209 any other type of stub. */
9210 if (!is_static_defined (&fdh
->elf
)
9211 && !is_static_defined (&h
->elf
))
9212 return ppc_stub_none
;
9214 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9216 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9217 struct plt_entry
**local_plt
= (struct plt_entry
**)
9218 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9219 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9221 if (local_plt
[r_symndx
] != NULL
)
9223 struct plt_entry
*ent
;
9225 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9226 if (ent
->addend
== rel
->r_addend
9227 && ent
->plt
.offset
!= (bfd_vma
) -1)
9230 return ppc_stub_plt_call
;
9235 /* Determine where the call point is. */
9236 location
= (input_sec
->output_offset
9237 + input_sec
->output_section
->vma
9240 branch_offset
= destination
- location
;
9241 r_type
= ELF64_R_TYPE (rel
->r_info
);
9243 /* Determine if a long branch stub is needed. */
9244 max_branch_offset
= 1 << 25;
9245 if (r_type
!= R_PPC64_REL24
)
9246 max_branch_offset
= 1 << 15;
9248 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
9249 /* We need a stub. Figure out whether a long_branch or plt_branch
9251 return ppc_stub_long_branch
;
9253 return ppc_stub_none
;
9256 /* Build a .plt call stub. */
9258 static inline bfd_byte
*
9259 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
, Elf_Internal_Rela
*r
,
9260 bfd_boolean plt_static_chain
)
9262 #define PPC_LO(v) ((v) & 0xffff)
9263 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9264 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9266 if (PPC_HA (offset
) != 0)
9270 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9271 r
[1].r_offset
= r
[0].r_offset
+ 8;
9272 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9273 r
[1].r_addend
= r
[0].r_addend
;
9274 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9276 r
[2].r_offset
= r
[1].r_offset
+ 4;
9277 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9278 r
[2].r_addend
= r
[0].r_addend
;
9282 r
[2].r_offset
= r
[1].r_offset
+ 8;
9283 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9284 r
[2].r_addend
= r
[0].r_addend
+ 8;
9285 r
[3].r_offset
= r
[2].r_offset
+ 4;
9286 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9287 r
[3].r_addend
= r
[0].r_addend
+ 16;
9290 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9291 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9292 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
9293 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9295 bfd_put_32 (obfd
, ADDI_R12_R12
| PPC_LO (offset
), p
), p
+= 4;
9298 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9299 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
+ 8), p
), p
+= 4;
9300 if (plt_static_chain
)
9301 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
+ 16), p
), p
+= 4;
9302 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9309 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9310 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9312 r
[1].r_offset
= r
[0].r_offset
+ 4;
9313 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9314 r
[1].r_addend
= r
[0].r_addend
;
9318 r
[1].r_offset
= r
[0].r_offset
+ 8;
9319 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9320 r
[1].r_addend
= r
[0].r_addend
+ 16;
9321 r
[2].r_offset
= r
[1].r_offset
+ 4;
9322 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9323 r
[2].r_addend
= r
[0].r_addend
+ 8;
9326 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9327 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
), p
), p
+= 4;
9328 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9330 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9333 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9334 if (plt_static_chain
)
9335 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9336 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9337 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9342 /* Build a special .plt call stub for __tls_get_addr. */
9344 #define LD_R11_0R3 0xe9630000
9345 #define LD_R12_0R3 0xe9830000
9346 #define MR_R0_R3 0x7c601b78
9347 #define CMPDI_R11_0 0x2c2b0000
9348 #define ADD_R3_R12_R13 0x7c6c6a14
9349 #define BEQLR 0x4d820020
9350 #define MR_R3_R0 0x7c030378
9351 #define MFLR_R11 0x7d6802a6
9352 #define STD_R11_0R1 0xf9610000
9353 #define BCTRL 0x4e800421
9354 #define LD_R11_0R1 0xe9610000
9355 #define LD_R2_0R1 0xe8410000
9356 #define MTLR_R11 0x7d6803a6
9358 static inline bfd_byte
*
9359 build_tls_get_addr_stub (bfd
*obfd
, bfd_byte
*p
, int offset
,
9360 Elf_Internal_Rela
*r
, bfd_boolean plt_static_chain
)
9362 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9363 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9364 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9365 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9366 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9367 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9368 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9369 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9370 bfd_put_32 (obfd
, STD_R11_0R1
+ 32, p
), p
+= 4;
9373 r
[0].r_offset
+= 9 * 4;
9374 p
= build_plt_stub (obfd
, p
, offset
, r
, plt_static_chain
);
9375 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9377 bfd_put_32 (obfd
, LD_R11_0R1
+ 32, p
), p
+= 4;
9378 bfd_put_32 (obfd
, LD_R2_0R1
+ 40, p
), p
+= 4;
9379 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9380 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9385 static Elf_Internal_Rela
*
9386 get_relocs (asection
*sec
, int count
)
9388 Elf_Internal_Rela
*relocs
;
9389 struct bfd_elf_section_data
*elfsec_data
;
9391 elfsec_data
= elf_section_data (sec
);
9392 relocs
= elfsec_data
->relocs
;
9395 bfd_size_type relsize
;
9396 relsize
= sec
->reloc_count
* sizeof (*relocs
);
9397 relocs
= bfd_alloc (sec
->owner
, relsize
);
9400 elfsec_data
->relocs
= relocs
;
9401 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
9402 sizeof (Elf_Internal_Shdr
));
9403 if (elfsec_data
->rela
.hdr
== NULL
)
9405 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
9406 * sizeof (Elf64_External_Rela
));
9407 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
9408 sec
->reloc_count
= 0;
9410 relocs
+= sec
->reloc_count
;
9411 sec
->reloc_count
+= count
;
9416 get_r2off (struct bfd_link_info
*info
,
9417 struct ppc_stub_hash_entry
*stub_entry
)
9419 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9420 bfd_vma r2off
= htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
;
9424 /* Support linking -R objects. Get the toc pointer from the
9427 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
9428 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
9430 if (strcmp (opd
->name
, ".opd") != 0
9431 || opd
->reloc_count
!= 0)
9433 info
->callbacks
->einfo (_("cannot find opd entry toc for %s\n"),
9434 stub_entry
->h
->elf
.root
.root
.string
);
9435 bfd_set_error (bfd_error_bad_value
);
9438 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
9440 r2off
= bfd_get_64 (opd
->owner
, buf
);
9441 r2off
-= elf_gp (info
->output_bfd
);
9443 r2off
-= htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
;
9448 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9450 struct ppc_stub_hash_entry
*stub_entry
;
9451 struct ppc_branch_hash_entry
*br_entry
;
9452 struct bfd_link_info
*info
;
9453 struct ppc_link_hash_table
*htab
;
9458 Elf_Internal_Rela
*r
;
9461 /* Massage our args to the form they really have. */
9462 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9465 htab
= ppc_hash_table (info
);
9469 /* Make a note of the offset within the stubs for this entry. */
9470 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
9471 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
9473 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
9474 switch (stub_entry
->stub_type
)
9476 case ppc_stub_long_branch
:
9477 case ppc_stub_long_branch_r2off
:
9478 /* Branches are relative. This is where we are going to. */
9479 off
= dest
= (stub_entry
->target_value
9480 + stub_entry
->target_section
->output_offset
9481 + stub_entry
->target_section
->output_section
->vma
);
9483 /* And this is where we are coming from. */
9484 off
-= (stub_entry
->stub_offset
9485 + stub_entry
->stub_sec
->output_offset
9486 + stub_entry
->stub_sec
->output_section
->vma
);
9489 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9491 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9495 htab
->stub_error
= TRUE
;
9498 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9501 if (PPC_HA (r2off
) != 0)
9504 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9507 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9511 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
9513 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9515 info
->callbacks
->einfo (_("long branch stub `%s' offset overflow\n"),
9516 stub_entry
->root
.string
);
9517 htab
->stub_error
= TRUE
;
9521 if (info
->emitrelocations
)
9523 r
= get_relocs (stub_entry
->stub_sec
, 1);
9526 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9527 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
9529 if (stub_entry
->h
!= NULL
)
9531 struct elf_link_hash_entry
**hashes
;
9532 unsigned long symndx
;
9533 struct ppc_link_hash_entry
*h
;
9535 hashes
= elf_sym_hashes (htab
->stub_bfd
);
9538 bfd_size_type hsize
;
9540 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
9541 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
9544 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
9545 htab
->stub_globals
= 1;
9547 symndx
= htab
->stub_globals
++;
9549 hashes
[symndx
] = &h
->elf
;
9550 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
9551 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
9552 h
= ppc_follow_link (h
->oh
);
9553 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
9554 /* H is an opd symbol. The addend must be zero. */
9558 off
= (h
->elf
.root
.u
.def
.value
9559 + h
->elf
.root
.u
.def
.section
->output_offset
9560 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
9567 case ppc_stub_plt_branch
:
9568 case ppc_stub_plt_branch_r2off
:
9569 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9570 stub_entry
->root
.string
+ 9,
9572 if (br_entry
== NULL
)
9574 info
->callbacks
->einfo (_("can't find branch stub `%s'\n"),
9575 stub_entry
->root
.string
);
9576 htab
->stub_error
= TRUE
;
9580 dest
= (stub_entry
->target_value
9581 + stub_entry
->target_section
->output_offset
9582 + stub_entry
->target_section
->output_section
->vma
);
9584 bfd_put_64 (htab
->brlt
->owner
, dest
,
9585 htab
->brlt
->contents
+ br_entry
->offset
);
9587 if (br_entry
->iter
== htab
->stub_iteration
)
9591 if (htab
->relbrlt
!= NULL
)
9593 /* Create a reloc for the branch lookup table entry. */
9594 Elf_Internal_Rela rela
;
9597 rela
.r_offset
= (br_entry
->offset
9598 + htab
->brlt
->output_offset
9599 + htab
->brlt
->output_section
->vma
);
9600 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9601 rela
.r_addend
= dest
;
9603 rl
= htab
->relbrlt
->contents
;
9604 rl
+= (htab
->relbrlt
->reloc_count
++
9605 * sizeof (Elf64_External_Rela
));
9606 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
9608 else if (info
->emitrelocations
)
9610 r
= get_relocs (htab
->brlt
, 1);
9613 /* brlt, being SEC_LINKER_CREATED does not go through the
9614 normal reloc processing. Symbols and offsets are not
9615 translated from input file to output file form, so
9616 set up the offset per the output file. */
9617 r
->r_offset
= (br_entry
->offset
9618 + htab
->brlt
->output_offset
9619 + htab
->brlt
->output_section
->vma
);
9620 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9625 dest
= (br_entry
->offset
9626 + htab
->brlt
->output_offset
9627 + htab
->brlt
->output_section
->vma
);
9630 - elf_gp (htab
->brlt
->output_section
->owner
)
9631 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9633 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9635 info
->callbacks
->einfo
9636 (_("linkage table error against `%s'\n"),
9637 stub_entry
->root
.string
);
9638 bfd_set_error (bfd_error_bad_value
);
9639 htab
->stub_error
= TRUE
;
9643 if (info
->emitrelocations
)
9645 r
= get_relocs (stub_entry
->stub_sec
, 1 + (PPC_HA (off
) != 0));
9648 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9649 if (bfd_big_endian (info
->output_bfd
))
9651 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
9653 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9654 r
[0].r_addend
= dest
;
9655 if (PPC_HA (off
) != 0)
9657 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9658 r
[1].r_offset
= r
[0].r_offset
+ 4;
9659 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9660 r
[1].r_addend
= r
[0].r_addend
;
9664 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
9666 if (PPC_HA (off
) != 0)
9669 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9671 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9676 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9681 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9685 htab
->stub_error
= TRUE
;
9689 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9692 if (PPC_HA (off
) != 0)
9695 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9697 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9702 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9706 if (PPC_HA (r2off
) != 0)
9709 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9712 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9715 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
9717 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
9720 case ppc_stub_plt_call
:
9721 if (stub_entry
->h
!= NULL
9722 && stub_entry
->h
->is_func_descriptor
9723 && stub_entry
->h
->oh
!= NULL
)
9725 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
9727 /* If the old-ABI "dot-symbol" is undefined make it weak so
9728 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
9729 FIXME: We used to define the symbol on one of the call
9730 stubs instead, which is why we test symbol section id
9731 against htab->top_id in various places. Likely all
9732 these checks could now disappear. */
9733 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
9734 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
9735 /* Stop undo_symbol_twiddle changing it back to undefined. */
9736 fh
->was_undefined
= 0;
9739 /* Now build the stub. */
9740 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9741 if (dest
>= (bfd_vma
) -2)
9745 if (!htab
->elf
.dynamic_sections_created
9746 || stub_entry
->h
== NULL
9747 || stub_entry
->h
->elf
.dynindx
== -1)
9750 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
9752 if (stub_entry
->h
== NULL
9753 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
9755 Elf_Internal_Rela rela
;
9758 rela
.r_offset
= dest
;
9759 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
9760 rela
.r_addend
= (stub_entry
->target_value
9761 + stub_entry
->target_section
->output_offset
9762 + stub_entry
->target_section
->output_section
->vma
);
9764 rl
= (htab
->reliplt
->contents
9765 + (htab
->reliplt
->reloc_count
++
9766 * sizeof (Elf64_External_Rela
)));
9767 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
9768 stub_entry
->plt_ent
->plt
.offset
|= 1;
9772 - elf_gp (plt
->output_section
->owner
)
9773 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9775 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9777 info
->callbacks
->einfo
9778 (_("linkage table error against `%s'\n"),
9779 stub_entry
->h
!= NULL
9780 ? stub_entry
->h
->elf
.root
.root
.string
9782 bfd_set_error (bfd_error_bad_value
);
9783 htab
->stub_error
= TRUE
;
9788 if (info
->emitrelocations
)
9790 r
= get_relocs (stub_entry
->stub_sec
,
9791 (2 + (PPC_HA (off
) != 0)
9792 + (PPC_HA (off
+ 16) == PPC_HA (off
))));
9795 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9796 if (bfd_big_endian (info
->output_bfd
))
9798 r
[0].r_addend
= dest
;
9800 if (stub_entry
->h
!= NULL
9801 && (stub_entry
->h
== htab
->tls_get_addr_fd
9802 || stub_entry
->h
== htab
->tls_get_addr
)
9803 && !htab
->no_tls_get_addr_opt
)
9804 p
= build_tls_get_addr_stub (htab
->stub_bfd
, loc
, off
, r
,
9805 htab
->plt_static_chain
);
9807 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
, r
,
9808 htab
->plt_static_chain
);
9817 stub_entry
->stub_sec
->size
+= size
;
9819 if (htab
->emit_stub_syms
)
9821 struct elf_link_hash_entry
*h
;
9824 const char *const stub_str
[] = { "long_branch",
9825 "long_branch_r2off",
9830 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
9831 len2
= strlen (stub_entry
->root
.string
);
9832 name
= bfd_malloc (len1
+ len2
+ 2);
9835 memcpy (name
, stub_entry
->root
.string
, 9);
9836 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
9837 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
9838 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
9841 if (h
->root
.type
== bfd_link_hash_new
)
9843 h
->root
.type
= bfd_link_hash_defined
;
9844 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
9845 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
9848 h
->ref_regular_nonweak
= 1;
9849 h
->forced_local
= 1;
9857 /* As above, but don't actually build the stub. Just bump offset so
9858 we know stub section sizes, and select plt_branch stubs where
9859 long_branch stubs won't do. */
9862 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9864 struct ppc_stub_hash_entry
*stub_entry
;
9865 struct bfd_link_info
*info
;
9866 struct ppc_link_hash_table
*htab
;
9870 /* Massage our args to the form they really have. */
9871 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9874 htab
= ppc_hash_table (info
);
9878 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
9881 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
9882 if (off
>= (bfd_vma
) -2)
9885 if (!htab
->elf
.dynamic_sections_created
9886 || stub_entry
->h
== NULL
9887 || stub_entry
->h
->elf
.dynindx
== -1)
9889 off
+= (plt
->output_offset
9890 + plt
->output_section
->vma
9891 - elf_gp (plt
->output_section
->owner
)
9892 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9894 size
= PLT_CALL_STUB_SIZE
;
9895 if (!htab
->plt_static_chain
)
9897 if (PPC_HA (off
) == 0)
9899 if (PPC_HA (off
+ 16) != PPC_HA (off
))
9901 if (stub_entry
->h
!= NULL
9902 && (stub_entry
->h
== htab
->tls_get_addr_fd
9903 || stub_entry
->h
== htab
->tls_get_addr
)
9904 && !htab
->no_tls_get_addr_opt
)
9906 if (info
->emitrelocations
)
9908 stub_entry
->stub_sec
->reloc_count
9909 += 2 + (PPC_HA (off
) != 0) + (PPC_HA (off
+ 16) == PPC_HA (off
));
9910 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
9915 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
9919 off
= (stub_entry
->target_value
9920 + stub_entry
->target_section
->output_offset
9921 + stub_entry
->target_section
->output_section
->vma
);
9922 off
-= (stub_entry
->stub_sec
->size
9923 + stub_entry
->stub_sec
->output_offset
9924 + stub_entry
->stub_sec
->output_section
->vma
);
9926 /* Reset the stub type from the plt variant in case we now
9927 can reach with a shorter stub. */
9928 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
9929 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
9932 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9934 r2off
= get_r2off (info
, stub_entry
);
9937 htab
->stub_error
= TRUE
;
9941 if (PPC_HA (r2off
) != 0)
9946 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
9947 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9949 struct ppc_branch_hash_entry
*br_entry
;
9951 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9952 stub_entry
->root
.string
+ 9,
9954 if (br_entry
== NULL
)
9956 info
->callbacks
->einfo (_("can't build branch stub `%s'\n"),
9957 stub_entry
->root
.string
);
9958 htab
->stub_error
= TRUE
;
9962 if (br_entry
->iter
!= htab
->stub_iteration
)
9964 br_entry
->iter
= htab
->stub_iteration
;
9965 br_entry
->offset
= htab
->brlt
->size
;
9966 htab
->brlt
->size
+= 8;
9968 if (htab
->relbrlt
!= NULL
)
9969 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
9970 else if (info
->emitrelocations
)
9972 htab
->brlt
->reloc_count
+= 1;
9973 htab
->brlt
->flags
|= SEC_RELOC
;
9977 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
9978 off
= (br_entry
->offset
9979 + htab
->brlt
->output_offset
9980 + htab
->brlt
->output_section
->vma
9981 - elf_gp (htab
->brlt
->output_section
->owner
)
9982 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9984 if (info
->emitrelocations
)
9986 stub_entry
->stub_sec
->reloc_count
+= 1 + (PPC_HA (off
) != 0);
9987 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
9990 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
9993 if (PPC_HA (off
) != 0)
9999 if (PPC_HA (off
) != 0)
10002 if (PPC_HA (r2off
) != 0)
10006 else if (info
->emitrelocations
)
10008 stub_entry
->stub_sec
->reloc_count
+= 1;
10009 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10013 stub_entry
->stub_sec
->size
+= size
;
10017 /* Set up various things so that we can make a list of input sections
10018 for each output section included in the link. Returns -1 on error,
10019 0 when no stubs will be needed, and 1 on success. */
10022 ppc64_elf_setup_section_lists
10023 (struct bfd_link_info
*info
,
10024 asection
*(*add_stub_section
) (const char *, asection
*),
10025 void (*layout_sections_again
) (void))
10028 int top_id
, top_index
, id
;
10030 asection
**input_list
;
10032 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10036 /* Stash our params away. */
10037 htab
->add_stub_section
= add_stub_section
;
10038 htab
->layout_sections_again
= layout_sections_again
;
10040 if (htab
->brlt
== NULL
)
10043 /* Find the top input section id. */
10044 for (input_bfd
= info
->input_bfds
, top_id
= 3;
10046 input_bfd
= input_bfd
->link_next
)
10048 for (section
= input_bfd
->sections
;
10050 section
= section
->next
)
10052 if (top_id
< section
->id
)
10053 top_id
= section
->id
;
10057 htab
->top_id
= top_id
;
10058 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
10059 htab
->stub_group
= bfd_zmalloc (amt
);
10060 if (htab
->stub_group
== NULL
)
10063 /* Set toc_off for com, und, abs and ind sections. */
10064 for (id
= 0; id
< 3; id
++)
10065 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
10067 /* We can't use output_bfd->section_count here to find the top output
10068 section index as some sections may have been removed, and
10069 strip_excluded_output_sections doesn't renumber the indices. */
10070 for (section
= info
->output_bfd
->sections
, top_index
= 0;
10072 section
= section
->next
)
10074 if (top_index
< section
->index
)
10075 top_index
= section
->index
;
10078 htab
->top_index
= top_index
;
10079 amt
= sizeof (asection
*) * (top_index
+ 1);
10080 input_list
= bfd_zmalloc (amt
);
10081 htab
->input_list
= input_list
;
10082 if (input_list
== NULL
)
10088 /* Set up for first pass at multitoc partitioning. */
10091 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10093 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10095 elf_gp (info
->output_bfd
) = ppc64_elf_toc (info
->output_bfd
);
10096 htab
->toc_curr
= elf_gp (info
->output_bfd
);
10097 htab
->toc_bfd
= NULL
;
10098 htab
->toc_first_sec
= NULL
;
10101 /* The linker repeatedly calls this function for each TOC input section
10102 and linker generated GOT section. Group input bfds such that the toc
10103 within a group is less than 64k in size. */
10106 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10108 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10109 bfd_vma addr
, off
, limit
;
10114 if (!htab
->second_toc_pass
)
10116 /* Keep track of the first .toc or .got section for this input bfd. */
10117 if (htab
->toc_bfd
!= isec
->owner
)
10119 htab
->toc_bfd
= isec
->owner
;
10120 htab
->toc_first_sec
= isec
;
10123 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10124 off
= addr
- htab
->toc_curr
;
10125 limit
= 0x80008000;
10126 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10128 if (off
+ isec
->size
> limit
)
10130 addr
= (htab
->toc_first_sec
->output_offset
10131 + htab
->toc_first_sec
->output_section
->vma
);
10132 htab
->toc_curr
= addr
;
10135 /* toc_curr is the base address of this toc group. Set elf_gp
10136 for the input section to be the offset relative to the
10137 output toc base plus 0x8000. Making the input elf_gp an
10138 offset allows us to move the toc as a whole without
10139 recalculating input elf_gp. */
10140 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
10141 off
+= TOC_BASE_OFF
;
10143 /* Die if someone uses a linker script that doesn't keep input
10144 file .toc and .got together. */
10145 if (elf_gp (isec
->owner
) != 0
10146 && elf_gp (isec
->owner
) != off
)
10149 elf_gp (isec
->owner
) = off
;
10153 /* During the second pass toc_first_sec points to the start of
10154 a toc group, and toc_curr is used to track the old elf_gp.
10155 We use toc_bfd to ensure we only look at each bfd once. */
10156 if (htab
->toc_bfd
== isec
->owner
)
10158 htab
->toc_bfd
= isec
->owner
;
10160 if (htab
->toc_first_sec
== NULL
10161 || htab
->toc_curr
!= elf_gp (isec
->owner
))
10163 htab
->toc_curr
= elf_gp (isec
->owner
);
10164 htab
->toc_first_sec
= isec
;
10166 addr
= (htab
->toc_first_sec
->output_offset
10167 + htab
->toc_first_sec
->output_section
->vma
);
10168 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
10169 elf_gp (isec
->owner
) = off
;
10174 /* Called via elf_link_hash_traverse to merge GOT entries for global
10178 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
10180 if (h
->root
.type
== bfd_link_hash_indirect
)
10183 merge_got_entries (&h
->got
.glist
);
10188 /* Called via elf_link_hash_traverse to allocate GOT entries for global
10192 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
10194 struct got_entry
*gent
;
10196 if (h
->root
.type
== bfd_link_hash_indirect
)
10199 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
10200 if (!gent
->is_indirect
)
10201 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
10205 /* Called on the first multitoc pass after the last call to
10206 ppc64_elf_next_toc_section. This function removes duplicate GOT
10210 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
10212 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10213 struct bfd
*ibfd
, *ibfd2
;
10214 bfd_boolean done_something
;
10216 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
10218 if (!htab
->do_multi_toc
)
10221 /* Merge global sym got entries within a toc group. */
10222 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
10224 /* And tlsld_got. */
10225 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10227 struct got_entry
*ent
, *ent2
;
10229 if (!is_ppc64_elf (ibfd
))
10232 ent
= ppc64_tlsld_got (ibfd
);
10233 if (!ent
->is_indirect
10234 && ent
->got
.offset
!= (bfd_vma
) -1)
10236 for (ibfd2
= ibfd
->link_next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link_next
)
10238 if (!is_ppc64_elf (ibfd2
))
10241 ent2
= ppc64_tlsld_got (ibfd2
);
10242 if (!ent2
->is_indirect
10243 && ent2
->got
.offset
!= (bfd_vma
) -1
10244 && elf_gp (ibfd2
) == elf_gp (ibfd
))
10246 ent2
->is_indirect
= TRUE
;
10247 ent2
->got
.ent
= ent
;
10253 /* Zap sizes of got sections. */
10254 htab
->reliplt
->rawsize
= htab
->reliplt
->size
;
10255 htab
->reliplt
->size
-= htab
->got_reli_size
;
10256 htab
->got_reli_size
= 0;
10258 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10260 asection
*got
, *relgot
;
10262 if (!is_ppc64_elf (ibfd
))
10265 got
= ppc64_elf_tdata (ibfd
)->got
;
10268 got
->rawsize
= got
->size
;
10270 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
10271 relgot
->rawsize
= relgot
->size
;
10276 /* Now reallocate the got, local syms first. We don't need to
10277 allocate section contents again since we never increase size. */
10278 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10280 struct got_entry
**lgot_ents
;
10281 struct got_entry
**end_lgot_ents
;
10282 struct plt_entry
**local_plt
;
10283 struct plt_entry
**end_local_plt
;
10284 unsigned char *lgot_masks
;
10285 bfd_size_type locsymcount
;
10286 Elf_Internal_Shdr
*symtab_hdr
;
10287 asection
*s
, *srel
;
10289 if (!is_ppc64_elf (ibfd
))
10292 lgot_ents
= elf_local_got_ents (ibfd
);
10296 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10297 locsymcount
= symtab_hdr
->sh_info
;
10298 end_lgot_ents
= lgot_ents
+ locsymcount
;
10299 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10300 end_local_plt
= local_plt
+ locsymcount
;
10301 lgot_masks
= (unsigned char *) end_local_plt
;
10302 s
= ppc64_elf_tdata (ibfd
)->got
;
10303 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10304 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10306 struct got_entry
*ent
;
10308 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
10310 unsigned int num
= 1;
10311 ent
->got
.offset
= s
->size
;
10312 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10314 s
->size
+= num
* 8;
10316 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
10317 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
10319 htab
->reliplt
->size
10320 += num
* sizeof (Elf64_External_Rela
);
10321 htab
->got_reli_size
10322 += num
* sizeof (Elf64_External_Rela
);
10328 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
10330 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10332 struct got_entry
*ent
;
10334 if (!is_ppc64_elf (ibfd
))
10337 ent
= ppc64_tlsld_got (ibfd
);
10338 if (!ent
->is_indirect
10339 && ent
->got
.offset
!= (bfd_vma
) -1)
10341 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
10342 ent
->got
.offset
= s
->size
;
10346 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10347 srel
->size
+= sizeof (Elf64_External_Rela
);
10352 done_something
= htab
->reliplt
->rawsize
!= htab
->reliplt
->size
;
10353 if (!done_something
)
10354 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10358 if (!is_ppc64_elf (ibfd
))
10361 got
= ppc64_elf_tdata (ibfd
)->got
;
10364 done_something
= got
->rawsize
!= got
->size
;
10365 if (done_something
)
10370 if (done_something
)
10371 (*htab
->layout_sections_again
) ();
10373 /* Set up for second pass over toc sections to recalculate elf_gp
10374 on input sections. */
10375 htab
->toc_bfd
= NULL
;
10376 htab
->toc_first_sec
= NULL
;
10377 htab
->second_toc_pass
= TRUE
;
10378 return done_something
;
10381 /* Called after second pass of multitoc partitioning. */
10384 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
10386 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10388 /* After the second pass, toc_curr tracks the TOC offset used
10389 for code sections below in ppc64_elf_next_input_section. */
10390 htab
->toc_curr
= TOC_BASE_OFF
;
10393 /* No toc references were found in ISEC. If the code in ISEC makes no
10394 calls, then there's no need to use toc adjusting stubs when branching
10395 into ISEC. Actually, indirect calls from ISEC are OK as they will
10396 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
10397 needed, and 2 if a cyclical call-graph was found but no other reason
10398 for a stub was detected. If called from the top level, a return of
10399 2 means the same as a return of 0. */
10402 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
10406 /* Mark this section as checked. */
10407 isec
->call_check_done
= 1;
10409 /* We know none of our code bearing sections will need toc stubs. */
10410 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
10413 if (isec
->size
== 0)
10416 if (isec
->output_section
== NULL
)
10420 if (isec
->reloc_count
!= 0)
10422 Elf_Internal_Rela
*relstart
, *rel
;
10423 Elf_Internal_Sym
*local_syms
;
10424 struct ppc_link_hash_table
*htab
;
10426 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
10427 info
->keep_memory
);
10428 if (relstart
== NULL
)
10431 /* Look for branches to outside of this section. */
10433 htab
= ppc_hash_table (info
);
10437 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
10439 enum elf_ppc64_reloc_type r_type
;
10440 unsigned long r_symndx
;
10441 struct elf_link_hash_entry
*h
;
10442 struct ppc_link_hash_entry
*eh
;
10443 Elf_Internal_Sym
*sym
;
10445 struct _opd_sec_data
*opd
;
10449 r_type
= ELF64_R_TYPE (rel
->r_info
);
10450 if (r_type
!= R_PPC64_REL24
10451 && r_type
!= R_PPC64_REL14
10452 && r_type
!= R_PPC64_REL14_BRTAKEN
10453 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
10456 r_symndx
= ELF64_R_SYM (rel
->r_info
);
10457 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
10464 /* Calls to dynamic lib functions go through a plt call stub
10466 eh
= (struct ppc_link_hash_entry
*) h
;
10468 && (eh
->elf
.plt
.plist
!= NULL
10470 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
10476 if (sym_sec
== NULL
)
10477 /* Ignore other undefined symbols. */
10480 /* Assume branches to other sections not included in the
10481 link need stubs too, to cover -R and absolute syms. */
10482 if (sym_sec
->output_section
== NULL
)
10489 sym_value
= sym
->st_value
;
10492 if (h
->root
.type
!= bfd_link_hash_defined
10493 && h
->root
.type
!= bfd_link_hash_defweak
)
10495 sym_value
= h
->root
.u
.def
.value
;
10497 sym_value
+= rel
->r_addend
;
10499 /* If this branch reloc uses an opd sym, find the code section. */
10500 opd
= get_opd_info (sym_sec
);
10503 if (h
== NULL
&& opd
->adjust
!= NULL
)
10507 adjust
= opd
->adjust
[sym
->st_value
/ 8];
10509 /* Assume deleted functions won't ever be called. */
10511 sym_value
+= adjust
;
10514 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
10515 if (dest
== (bfd_vma
) -1)
10520 + sym_sec
->output_offset
10521 + sym_sec
->output_section
->vma
);
10523 /* Ignore branch to self. */
10524 if (sym_sec
== isec
)
10527 /* If the called function uses the toc, we need a stub. */
10528 if (sym_sec
->has_toc_reloc
10529 || sym_sec
->makes_toc_func_call
)
10535 /* Assume any branch that needs a long branch stub might in fact
10536 need a plt_branch stub. A plt_branch stub uses r2. */
10537 else if (dest
- (isec
->output_offset
10538 + isec
->output_section
->vma
10539 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
10545 /* If calling back to a section in the process of being
10546 tested, we can't say for sure that no toc adjusting stubs
10547 are needed, so don't return zero. */
10548 else if (sym_sec
->call_check_in_progress
)
10551 /* Branches to another section that itself doesn't have any TOC
10552 references are OK. Recursively call ourselves to check. */
10553 else if (!sym_sec
->call_check_done
)
10557 /* Mark current section as indeterminate, so that other
10558 sections that call back to current won't be marked as
10560 isec
->call_check_in_progress
= 1;
10561 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
10562 isec
->call_check_in_progress
= 0;
10573 if (local_syms
!= NULL
10574 && (elf_symtab_hdr (isec
->owner
).contents
10575 != (unsigned char *) local_syms
))
10577 if (elf_section_data (isec
)->relocs
!= relstart
)
10582 && isec
->map_head
.s
!= NULL
10583 && (strcmp (isec
->output_section
->name
, ".init") == 0
10584 || strcmp (isec
->output_section
->name
, ".fini") == 0))
10586 if (isec
->map_head
.s
->has_toc_reloc
10587 || isec
->map_head
.s
->makes_toc_func_call
)
10589 else if (!isec
->map_head
.s
->call_check_done
)
10592 isec
->call_check_in_progress
= 1;
10593 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
10594 isec
->call_check_in_progress
= 0;
10601 isec
->makes_toc_func_call
= 1;
10606 /* The linker repeatedly calls this function for each input section,
10607 in the order that input sections are linked into output sections.
10608 Build lists of input sections to determine groupings between which
10609 we may insert linker stubs. */
10612 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
10614 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10619 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
10620 && isec
->output_section
->index
<= htab
->top_index
)
10622 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
10623 /* Steal the link_sec pointer for our list. */
10624 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
10625 /* This happens to make the list in reverse order,
10626 which is what we want. */
10627 PREV_SEC (isec
) = *list
;
10631 if (htab
->multi_toc_needed
)
10633 /* If a code section has a function that uses the TOC then we need
10634 to use the right TOC (obviously). Also, make sure that .opd gets
10635 the correct TOC value for R_PPC64_TOC relocs that don't have or
10636 can't find their function symbol (shouldn't ever happen now).
10637 Also specially treat .fixup for the linux kernel. .fixup
10638 contains branches, but only back to the function that hit an
10640 if (isec
->has_toc_reloc
10641 || (isec
->flags
& SEC_CODE
) == 0
10642 || strcmp (isec
->name
, ".fixup") == 0)
10644 if (elf_gp (isec
->owner
) != 0)
10645 htab
->toc_curr
= elf_gp (isec
->owner
);
10649 if (!isec
->call_check_done
10650 && toc_adjusting_stub_needed (info
, isec
) < 0)
10652 /* If we make a local call from this section, ie. a branch
10653 without a following nop, then we have no place to put a
10654 toc restoring insn. We must use the same toc group as
10656 Testing makes_toc_func_call actually tests for *any*
10657 calls to functions that need a good toc pointer. A more
10658 precise test would be better, as this one will set
10659 incorrect values for pasted .init/.fini fragments.
10660 (Fixed later in check_pasted_section.) */
10661 if (isec
->makes_toc_func_call
10662 && elf_gp (isec
->owner
) != 0)
10663 htab
->toc_curr
= elf_gp (isec
->owner
);
10667 /* Functions that don't use the TOC can belong in any TOC group.
10668 Use the last TOC base. */
10669 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
10673 /* Check that all .init and .fini sections use the same toc, if they
10674 have toc relocs. */
10677 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
10679 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
10683 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10684 bfd_vma toc_off
= 0;
10687 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10688 if (i
->has_toc_reloc
)
10691 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10692 else if (toc_off
!= htab
->stub_group
[i
->id
].toc_off
)
10697 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10698 if (i
->makes_toc_func_call
)
10700 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10704 /* Make sure the whole pasted function uses the same toc offset. */
10706 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10707 htab
->stub_group
[i
->id
].toc_off
= toc_off
;
10713 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
10715 return (check_pasted_section (info
, ".init")
10716 & check_pasted_section (info
, ".fini"));
10719 /* See whether we can group stub sections together. Grouping stub
10720 sections may result in fewer stubs. More importantly, we need to
10721 put all .init* and .fini* stubs at the beginning of the .init or
10722 .fini output sections respectively, because glibc splits the
10723 _init and _fini functions into multiple parts. Putting a stub in
10724 the middle of a function is not a good idea. */
10727 group_sections (struct ppc_link_hash_table
*htab
,
10728 bfd_size_type stub_group_size
,
10729 bfd_boolean stubs_always_before_branch
)
10732 bfd_size_type stub14_group_size
;
10733 bfd_boolean suppress_size_errors
;
10735 suppress_size_errors
= FALSE
;
10736 stub14_group_size
= stub_group_size
;
10737 if (stub_group_size
== 1)
10739 /* Default values. */
10740 if (stubs_always_before_branch
)
10742 stub_group_size
= 0x1e00000;
10743 stub14_group_size
= 0x7800;
10747 stub_group_size
= 0x1c00000;
10748 stub14_group_size
= 0x7000;
10750 suppress_size_errors
= TRUE
;
10753 list
= htab
->input_list
+ htab
->top_index
;
10756 asection
*tail
= *list
;
10757 while (tail
!= NULL
)
10761 bfd_size_type total
;
10762 bfd_boolean big_sec
;
10766 total
= tail
->size
;
10767 big_sec
= total
> (ppc64_elf_section_data (tail
) != NULL
10768 && ppc64_elf_section_data (tail
)->has_14bit_branch
10769 ? stub14_group_size
: stub_group_size
);
10770 if (big_sec
&& !suppress_size_errors
)
10771 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
10772 tail
->owner
, tail
);
10773 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
10775 while ((prev
= PREV_SEC (curr
)) != NULL
10776 && ((total
+= curr
->output_offset
- prev
->output_offset
)
10777 < (ppc64_elf_section_data (prev
) != NULL
10778 && ppc64_elf_section_data (prev
)->has_14bit_branch
10779 ? stub14_group_size
: stub_group_size
))
10780 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10783 /* OK, the size from the start of CURR to the end is less
10784 than stub_group_size and thus can be handled by one stub
10785 section. (or the tail section is itself larger than
10786 stub_group_size, in which case we may be toast.) We
10787 should really be keeping track of the total size of stubs
10788 added here, as stubs contribute to the final output
10789 section size. That's a little tricky, and this way will
10790 only break if stubs added make the total size more than
10791 2^25, ie. for the default stub_group_size, if stubs total
10792 more than 2097152 bytes, or nearly 75000 plt call stubs. */
10795 prev
= PREV_SEC (tail
);
10796 /* Set up this stub group. */
10797 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10799 while (tail
!= curr
&& (tail
= prev
) != NULL
);
10801 /* But wait, there's more! Input sections up to stub_group_size
10802 bytes before the stub section can be handled by it too.
10803 Don't do this if we have a really large section after the
10804 stubs, as adding more stubs increases the chance that
10805 branches may not reach into the stub section. */
10806 if (!stubs_always_before_branch
&& !big_sec
)
10809 while (prev
!= NULL
10810 && ((total
+= tail
->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 prev
= PREV_SEC (tail
);
10818 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10824 while (list
-- != htab
->input_list
);
10825 free (htab
->input_list
);
10829 /* Determine and set the size of the stub section for a final link.
10831 The basic idea here is to examine all the relocations looking for
10832 PC-relative calls to a target that is unreachable with a "bl"
10836 ppc64_elf_size_stubs (struct bfd_link_info
*info
, bfd_signed_vma group_size
,
10837 bfd_boolean plt_static_chain
)
10839 bfd_size_type stub_group_size
;
10840 bfd_boolean stubs_always_before_branch
;
10841 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10846 htab
->plt_static_chain
= plt_static_chain
;
10847 stubs_always_before_branch
= group_size
< 0;
10848 if (group_size
< 0)
10849 stub_group_size
= -group_size
;
10851 stub_group_size
= group_size
;
10853 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
10858 unsigned int bfd_indx
;
10859 asection
*stub_sec
;
10861 htab
->stub_iteration
+= 1;
10863 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
10865 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
10867 Elf_Internal_Shdr
*symtab_hdr
;
10869 Elf_Internal_Sym
*local_syms
= NULL
;
10871 if (!is_ppc64_elf (input_bfd
))
10874 /* We'll need the symbol table in a second. */
10875 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
10876 if (symtab_hdr
->sh_info
== 0)
10879 /* Walk over each section attached to the input bfd. */
10880 for (section
= input_bfd
->sections
;
10882 section
= section
->next
)
10884 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
10886 /* If there aren't any relocs, then there's nothing more
10888 if ((section
->flags
& SEC_RELOC
) == 0
10889 || (section
->flags
& SEC_ALLOC
) == 0
10890 || (section
->flags
& SEC_LOAD
) == 0
10891 || (section
->flags
& SEC_CODE
) == 0
10892 || section
->reloc_count
== 0)
10895 /* If this section is a link-once section that will be
10896 discarded, then don't create any stubs. */
10897 if (section
->output_section
== NULL
10898 || section
->output_section
->owner
!= info
->output_bfd
)
10901 /* Get the relocs. */
10903 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
10904 info
->keep_memory
);
10905 if (internal_relocs
== NULL
)
10906 goto error_ret_free_local
;
10908 /* Now examine each relocation. */
10909 irela
= internal_relocs
;
10910 irelaend
= irela
+ section
->reloc_count
;
10911 for (; irela
< irelaend
; irela
++)
10913 enum elf_ppc64_reloc_type r_type
;
10914 unsigned int r_indx
;
10915 enum ppc_stub_type stub_type
;
10916 struct ppc_stub_hash_entry
*stub_entry
;
10917 asection
*sym_sec
, *code_sec
;
10918 bfd_vma sym_value
, code_value
;
10919 bfd_vma destination
;
10920 bfd_boolean ok_dest
;
10921 struct ppc_link_hash_entry
*hash
;
10922 struct ppc_link_hash_entry
*fdh
;
10923 struct elf_link_hash_entry
*h
;
10924 Elf_Internal_Sym
*sym
;
10926 const asection
*id_sec
;
10927 struct _opd_sec_data
*opd
;
10928 struct plt_entry
*plt_ent
;
10930 r_type
= ELF64_R_TYPE (irela
->r_info
);
10931 r_indx
= ELF64_R_SYM (irela
->r_info
);
10933 if (r_type
>= R_PPC64_max
)
10935 bfd_set_error (bfd_error_bad_value
);
10936 goto error_ret_free_internal
;
10939 /* Only look for stubs on branch instructions. */
10940 if (r_type
!= R_PPC64_REL24
10941 && r_type
!= R_PPC64_REL14
10942 && r_type
!= R_PPC64_REL14_BRTAKEN
10943 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
10946 /* Now determine the call target, its name, value,
10948 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
10949 r_indx
, input_bfd
))
10950 goto error_ret_free_internal
;
10951 hash
= (struct ppc_link_hash_entry
*) h
;
10958 sym_value
= sym
->st_value
;
10961 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
10962 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
10964 sym_value
= hash
->elf
.root
.u
.def
.value
;
10965 if (sym_sec
->output_section
!= NULL
)
10968 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
10969 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
10971 /* Recognise an old ABI func code entry sym, and
10972 use the func descriptor sym instead if it is
10974 if (hash
->elf
.root
.root
.string
[0] == '.'
10975 && (fdh
= lookup_fdh (hash
, htab
)) != NULL
)
10977 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
10978 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
10980 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
10981 sym_value
= fdh
->elf
.root
.u
.def
.value
;
10982 if (sym_sec
->output_section
!= NULL
)
10991 bfd_set_error (bfd_error_bad_value
);
10992 goto error_ret_free_internal
;
10998 sym_value
+= irela
->r_addend
;
10999 destination
= (sym_value
11000 + sym_sec
->output_offset
11001 + sym_sec
->output_section
->vma
);
11004 code_sec
= sym_sec
;
11005 code_value
= sym_value
;
11006 opd
= get_opd_info (sym_sec
);
11011 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11013 long adjust
= opd
->adjust
[sym_value
/ 8];
11016 code_value
+= adjust
;
11017 sym_value
+= adjust
;
11019 dest
= opd_entry_value (sym_sec
, sym_value
,
11020 &code_sec
, &code_value
);
11021 if (dest
!= (bfd_vma
) -1)
11023 destination
= dest
;
11026 /* Fixup old ABI sym to point at code
11028 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11029 hash
->elf
.root
.u
.def
.section
= code_sec
;
11030 hash
->elf
.root
.u
.def
.value
= code_value
;
11035 /* Determine what (if any) linker stub is needed. */
11037 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11038 &plt_ent
, destination
);
11040 if (stub_type
!= ppc_stub_plt_call
)
11042 /* Check whether we need a TOC adjusting stub.
11043 Since the linker pastes together pieces from
11044 different object files when creating the
11045 _init and _fini functions, it may be that a
11046 call to what looks like a local sym is in
11047 fact a call needing a TOC adjustment. */
11048 if (code_sec
!= NULL
11049 && code_sec
->output_section
!= NULL
11050 && (htab
->stub_group
[code_sec
->id
].toc_off
11051 != htab
->stub_group
[section
->id
].toc_off
)
11052 && (code_sec
->has_toc_reloc
11053 || code_sec
->makes_toc_func_call
))
11054 stub_type
= ppc_stub_long_branch_r2off
;
11057 if (stub_type
== ppc_stub_none
)
11060 /* __tls_get_addr calls might be eliminated. */
11061 if (stub_type
!= ppc_stub_plt_call
11063 && (hash
== htab
->tls_get_addr
11064 || hash
== htab
->tls_get_addr_fd
)
11065 && section
->has_tls_reloc
11066 && irela
!= internal_relocs
)
11068 /* Get tls info. */
11069 unsigned char *tls_mask
;
11071 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
11072 irela
- 1, input_bfd
))
11073 goto error_ret_free_internal
;
11074 if (*tls_mask
!= 0)
11078 /* Support for grouping stub sections. */
11079 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
11081 /* Get the name of this stub. */
11082 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
11084 goto error_ret_free_internal
;
11086 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
11087 stub_name
, FALSE
, FALSE
);
11088 if (stub_entry
!= NULL
)
11090 /* The proper stub has already been created. */
11095 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
11096 if (stub_entry
== NULL
)
11099 error_ret_free_internal
:
11100 if (elf_section_data (section
)->relocs
== NULL
)
11101 free (internal_relocs
);
11102 error_ret_free_local
:
11103 if (local_syms
!= NULL
11104 && (symtab_hdr
->contents
11105 != (unsigned char *) local_syms
))
11110 stub_entry
->stub_type
= stub_type
;
11111 if (stub_type
!= ppc_stub_plt_call
)
11113 stub_entry
->target_value
= code_value
;
11114 stub_entry
->target_section
= code_sec
;
11118 stub_entry
->target_value
= sym_value
;
11119 stub_entry
->target_section
= sym_sec
;
11121 stub_entry
->h
= hash
;
11122 stub_entry
->plt_ent
= plt_ent
;
11123 stub_entry
->addend
= irela
->r_addend
;
11125 if (stub_entry
->h
!= NULL
)
11126 htab
->stub_globals
+= 1;
11129 /* We're done with the internal relocs, free them. */
11130 if (elf_section_data (section
)->relocs
!= internal_relocs
)
11131 free (internal_relocs
);
11134 if (local_syms
!= NULL
11135 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
11137 if (!info
->keep_memory
)
11140 symtab_hdr
->contents
= (unsigned char *) local_syms
;
11144 /* We may have added some stubs. Find out the new size of the
11146 for (stub_sec
= htab
->stub_bfd
->sections
;
11148 stub_sec
= stub_sec
->next
)
11149 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11151 stub_sec
->rawsize
= stub_sec
->size
;
11152 stub_sec
->size
= 0;
11153 stub_sec
->reloc_count
= 0;
11154 stub_sec
->flags
&= ~SEC_RELOC
;
11157 htab
->brlt
->size
= 0;
11158 htab
->brlt
->reloc_count
= 0;
11159 htab
->brlt
->flags
&= ~SEC_RELOC
;
11160 if (htab
->relbrlt
!= NULL
)
11161 htab
->relbrlt
->size
= 0;
11163 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
11165 if (info
->emitrelocations
11166 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11168 htab
->glink
->reloc_count
= 1;
11169 htab
->glink
->flags
|= SEC_RELOC
;
11172 for (stub_sec
= htab
->stub_bfd
->sections
;
11174 stub_sec
= stub_sec
->next
)
11175 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11176 && stub_sec
->rawsize
!= stub_sec
->size
)
11179 /* Exit from this loop when no stubs have been added, and no stubs
11180 have changed size. */
11181 if (stub_sec
== NULL
)
11184 /* Ask the linker to do its stuff. */
11185 (*htab
->layout_sections_again
) ();
11188 /* It would be nice to strip htab->brlt from the output if the
11189 section is empty, but it's too late. If we strip sections here,
11190 the dynamic symbol table is corrupted since the section symbol
11191 for the stripped section isn't written. */
11196 /* Called after we have determined section placement. If sections
11197 move, we'll be called again. Provide a value for TOCstart. */
11200 ppc64_elf_toc (bfd
*obfd
)
11205 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
11206 order. The TOC starts where the first of these sections starts. */
11207 s
= bfd_get_section_by_name (obfd
, ".got");
11208 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11209 s
= bfd_get_section_by_name (obfd
, ".toc");
11210 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11211 s
= bfd_get_section_by_name (obfd
, ".tocbss");
11212 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11213 s
= bfd_get_section_by_name (obfd
, ".plt");
11214 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11216 /* This may happen for
11217 o references to TOC base (SYM@toc / TOC[tc0]) without a
11219 o bad linker script
11220 o --gc-sections and empty TOC sections
11222 FIXME: Warn user? */
11224 /* Look for a likely section. We probably won't even be
11226 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11227 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
11229 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11232 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11233 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
11234 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11237 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11238 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
11242 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11243 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
11249 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
11254 /* Build all the stubs associated with the current output file.
11255 The stubs are kept in a hash table attached to the main linker
11256 hash table. This function is called via gldelf64ppc_finish. */
11259 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
11260 struct bfd_link_info
*info
,
11263 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11264 asection
*stub_sec
;
11266 int stub_sec_count
= 0;
11271 htab
->emit_stub_syms
= emit_stub_syms
;
11273 /* Allocate memory to hold the linker stubs. */
11274 for (stub_sec
= htab
->stub_bfd
->sections
;
11276 stub_sec
= stub_sec
->next
)
11277 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11278 && stub_sec
->size
!= 0)
11280 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
11281 if (stub_sec
->contents
== NULL
)
11283 /* We want to check that built size is the same as calculated
11284 size. rawsize is a convenient location to use. */
11285 stub_sec
->rawsize
= stub_sec
->size
;
11286 stub_sec
->size
= 0;
11289 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11294 /* Build the .glink plt call stub. */
11295 if (htab
->emit_stub_syms
)
11297 struct elf_link_hash_entry
*h
;
11298 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
11299 TRUE
, FALSE
, FALSE
);
11302 if (h
->root
.type
== bfd_link_hash_new
)
11304 h
->root
.type
= bfd_link_hash_defined
;
11305 h
->root
.u
.def
.section
= htab
->glink
;
11306 h
->root
.u
.def
.value
= 8;
11307 h
->ref_regular
= 1;
11308 h
->def_regular
= 1;
11309 h
->ref_regular_nonweak
= 1;
11310 h
->forced_local
= 1;
11314 plt0
= htab
->plt
->output_section
->vma
+ htab
->plt
->output_offset
- 16;
11315 if (info
->emitrelocations
)
11317 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
11320 r
->r_offset
= (htab
->glink
->output_offset
11321 + htab
->glink
->output_section
->vma
);
11322 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
11323 r
->r_addend
= plt0
;
11325 p
= htab
->glink
->contents
;
11326 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
11327 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
11329 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
11331 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
11333 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
11335 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
11337 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
11339 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
11341 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
11343 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
11345 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
11347 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
11349 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
11351 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
11353 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
11357 /* Build the .glink lazy link call stubs. */
11359 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
11363 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
11368 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
11370 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
11373 bfd_put_32 (htab
->glink
->owner
,
11374 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
11378 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
11381 if (htab
->brlt
->size
!= 0)
11383 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
11385 if (htab
->brlt
->contents
== NULL
)
11388 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
11390 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
11391 htab
->relbrlt
->size
);
11392 if (htab
->relbrlt
->contents
== NULL
)
11396 /* Build the stubs as directed by the stub hash table. */
11397 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
11399 if (htab
->relbrlt
!= NULL
)
11400 htab
->relbrlt
->reloc_count
= 0;
11402 for (stub_sec
= htab
->stub_bfd
->sections
;
11404 stub_sec
= stub_sec
->next
)
11405 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11407 stub_sec_count
+= 1;
11408 if (stub_sec
->rawsize
!= stub_sec
->size
)
11412 if (stub_sec
!= NULL
11413 || htab
->glink
->rawsize
!= htab
->glink
->size
)
11415 htab
->stub_error
= TRUE
;
11416 info
->callbacks
->einfo (_("stubs don't match calculated size\n"));
11419 if (htab
->stub_error
)
11424 *stats
= bfd_malloc (500);
11425 if (*stats
== NULL
)
11428 sprintf (*stats
, _("linker stubs in %u group%s\n"
11430 " toc adjust %lu\n"
11431 " long branch %lu\n"
11432 " long toc adj %lu\n"
11435 stub_sec_count
== 1 ? "" : "s",
11436 htab
->stub_count
[ppc_stub_long_branch
- 1],
11437 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
11438 htab
->stub_count
[ppc_stub_plt_branch
- 1],
11439 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
11440 htab
->stub_count
[ppc_stub_plt_call
- 1]);
11445 /* This function undoes the changes made by add_symbol_adjust. */
11448 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11450 struct ppc_link_hash_entry
*eh
;
11452 if (h
->root
.type
== bfd_link_hash_indirect
)
11455 eh
= (struct ppc_link_hash_entry
*) h
;
11456 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
11459 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
11464 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
11466 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11469 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
11472 /* What to do when ld finds relocations against symbols defined in
11473 discarded sections. */
11475 static unsigned int
11476 ppc64_elf_action_discarded (asection
*sec
)
11478 if (strcmp (".opd", sec
->name
) == 0)
11481 if (strcmp (".toc", sec
->name
) == 0)
11484 if (strcmp (".toc1", sec
->name
) == 0)
11487 return _bfd_elf_default_action_discarded (sec
);
11490 /* REL points to a low-part reloc on a largetoc instruction sequence.
11491 Find the matching high-part reloc instruction and verify that it
11492 is addis REG,x,imm. If so, set *REG to x and return a pointer to
11493 the high-part reloc. */
11495 static const Elf_Internal_Rela
*
11496 ha_reloc_match (const Elf_Internal_Rela
*relocs
,
11497 const Elf_Internal_Rela
*rel
,
11499 bfd_boolean match_addend
,
11500 const bfd
*input_bfd
,
11501 const bfd_byte
*contents
)
11503 enum elf_ppc64_reloc_type r_type
, r_type_ha
;
11504 bfd_vma r_info_ha
, r_addend
;
11506 r_type
= ELF64_R_TYPE (rel
->r_info
);
11509 case R_PPC64_GOT_TLSLD16_LO
:
11510 case R_PPC64_GOT_TLSGD16_LO
:
11511 case R_PPC64_GOT_TPREL16_LO_DS
:
11512 case R_PPC64_GOT_DTPREL16_LO_DS
:
11513 case R_PPC64_GOT16_LO
:
11514 case R_PPC64_TOC16_LO
:
11515 r_type_ha
= r_type
+ 2;
11517 case R_PPC64_GOT16_LO_DS
:
11518 r_type_ha
= R_PPC64_GOT16_HA
;
11520 case R_PPC64_TOC16_LO_DS
:
11521 r_type_ha
= R_PPC64_TOC16_HA
;
11526 r_info_ha
= ELF64_R_INFO (ELF64_R_SYM (rel
->r_info
), r_type_ha
);
11527 r_addend
= rel
->r_addend
;
11529 while (--rel
>= relocs
)
11530 if (rel
->r_info
== r_info_ha
11532 || rel
->r_addend
== r_addend
))
11534 const bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
11535 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
11536 if ((insn
& (0x3f << 26)) == (15u << 26) /* addis rt,x,imm */
11537 && (insn
& (0x1f << 21)) == (*reg
<< 21))
11539 *reg
= (insn
>> 16) & 0x1f;
11547 /* The RELOCATE_SECTION function is called by the ELF backend linker
11548 to handle the relocations for a section.
11550 The relocs are always passed as Rela structures; if the section
11551 actually uses Rel structures, the r_addend field will always be
11554 This function is responsible for adjust the section contents as
11555 necessary, and (if using Rela relocs and generating a
11556 relocatable output file) adjusting the reloc addend as
11559 This function does not have to worry about setting the reloc
11560 address or the reloc symbol index.
11562 LOCAL_SYMS is a pointer to the swapped in local symbols.
11564 LOCAL_SECTIONS is an array giving the section in the input file
11565 corresponding to the st_shndx field of each local symbol.
11567 The global hash table entry for the global symbols can be found
11568 via elf_sym_hashes (input_bfd).
11570 When generating relocatable output, this function must handle
11571 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
11572 going to be the section symbol corresponding to the output
11573 section, which means that the addend must be adjusted
11577 ppc64_elf_relocate_section (bfd
*output_bfd
,
11578 struct bfd_link_info
*info
,
11580 asection
*input_section
,
11581 bfd_byte
*contents
,
11582 Elf_Internal_Rela
*relocs
,
11583 Elf_Internal_Sym
*local_syms
,
11584 asection
**local_sections
)
11586 struct ppc_link_hash_table
*htab
;
11587 Elf_Internal_Shdr
*symtab_hdr
;
11588 struct elf_link_hash_entry
**sym_hashes
;
11589 Elf_Internal_Rela
*rel
;
11590 Elf_Internal_Rela
*relend
;
11591 Elf_Internal_Rela outrel
;
11593 struct got_entry
**local_got_ents
;
11594 unsigned char *ha_opt
;
11596 bfd_boolean no_ha_opt
;
11597 bfd_boolean ret
= TRUE
;
11598 bfd_boolean is_opd
;
11599 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
11600 bfd_boolean is_power4
= FALSE
;
11601 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
11603 /* Initialize howto table if needed. */
11604 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
11607 htab
= ppc_hash_table (info
);
11611 /* Don't relocate stub sections. */
11612 if (input_section
->owner
== htab
->stub_bfd
)
11615 BFD_ASSERT (is_ppc64_elf (input_bfd
));
11617 local_got_ents
= elf_local_got_ents (input_bfd
);
11618 TOCstart
= elf_gp (output_bfd
);
11619 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11620 sym_hashes
= elf_sym_hashes (input_bfd
);
11621 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
11626 relend
= relocs
+ input_section
->reloc_count
;
11627 for (; rel
< relend
; rel
++)
11629 enum elf_ppc64_reloc_type r_type
;
11630 bfd_vma addend
, orig_addend
;
11631 bfd_reloc_status_type r
;
11632 Elf_Internal_Sym
*sym
;
11634 struct elf_link_hash_entry
*h_elf
;
11635 struct ppc_link_hash_entry
*h
;
11636 struct ppc_link_hash_entry
*fdh
;
11637 const char *sym_name
;
11638 unsigned long r_symndx
, toc_symndx
;
11639 bfd_vma toc_addend
;
11640 unsigned char tls_mask
, tls_gd
, tls_type
;
11641 unsigned char sym_type
;
11642 bfd_vma relocation
;
11643 bfd_boolean unresolved_reloc
;
11644 bfd_boolean warned
;
11647 struct ppc_stub_hash_entry
*stub_entry
;
11648 bfd_vma max_br_offset
;
11651 r_type
= ELF64_R_TYPE (rel
->r_info
);
11652 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11654 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
11655 symbol of the previous ADDR64 reloc. The symbol gives us the
11656 proper TOC base to use. */
11657 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
11659 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
11661 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
11667 unresolved_reloc
= FALSE
;
11669 orig_addend
= rel
->r_addend
;
11671 if (r_symndx
< symtab_hdr
->sh_info
)
11673 /* It's a local symbol. */
11674 struct _opd_sec_data
*opd
;
11676 sym
= local_syms
+ r_symndx
;
11677 sec
= local_sections
[r_symndx
];
11678 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
11679 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
11680 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
11681 opd
= get_opd_info (sec
);
11682 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
11684 long adjust
= opd
->adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
11689 /* If this is a relocation against the opd section sym
11690 and we have edited .opd, adjust the reloc addend so
11691 that ld -r and ld --emit-relocs output is correct.
11692 If it is a reloc against some other .opd symbol,
11693 then the symbol value will be adjusted later. */
11694 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
11695 rel
->r_addend
+= adjust
;
11697 relocation
+= adjust
;
11703 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
11704 r_symndx
, symtab_hdr
, sym_hashes
,
11705 h_elf
, sec
, relocation
,
11706 unresolved_reloc
, warned
);
11707 sym_name
= h_elf
->root
.root
.string
;
11708 sym_type
= h_elf
->type
;
11710 h
= (struct ppc_link_hash_entry
*) h_elf
;
11712 if (sec
!= NULL
&& elf_discarded_section (sec
))
11713 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
11715 ppc64_elf_howto_table
[r_type
],
11718 if (info
->relocatable
)
11721 /* TLS optimizations. Replace instruction sequences and relocs
11722 based on information we collected in tls_optimize. We edit
11723 RELOCS so that --emit-relocs will output something sensible
11724 for the final instruction stream. */
11729 tls_mask
= h
->tls_mask
;
11730 else if (local_got_ents
!= NULL
)
11732 struct plt_entry
**local_plt
= (struct plt_entry
**)
11733 (local_got_ents
+ symtab_hdr
->sh_info
);
11734 unsigned char *lgot_masks
= (unsigned char *)
11735 (local_plt
+ symtab_hdr
->sh_info
);
11736 tls_mask
= lgot_masks
[r_symndx
];
11739 && (r_type
== R_PPC64_TLS
11740 || r_type
== R_PPC64_TLSGD
11741 || r_type
== R_PPC64_TLSLD
))
11743 /* Check for toc tls entries. */
11744 unsigned char *toc_tls
;
11746 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11747 &local_syms
, rel
, input_bfd
))
11751 tls_mask
= *toc_tls
;
11754 /* Check that tls relocs are used with tls syms, and non-tls
11755 relocs are used with non-tls syms. */
11756 if (r_symndx
!= STN_UNDEF
11757 && r_type
!= R_PPC64_NONE
11759 || h
->elf
.root
.type
== bfd_link_hash_defined
11760 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
11761 && (IS_PPC64_TLS_RELOC (r_type
)
11762 != (sym_type
== STT_TLS
11763 || (sym_type
== STT_SECTION
11764 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
11767 && (r_type
== R_PPC64_TLS
11768 || r_type
== R_PPC64_TLSGD
11769 || r_type
== R_PPC64_TLSLD
))
11770 /* R_PPC64_TLS is OK against a symbol in the TOC. */
11773 info
->callbacks
->einfo
11774 (!IS_PPC64_TLS_RELOC (r_type
)
11775 ? _("%H: %s used with TLS symbol %s\n")
11776 : _("%H: %s used with non-TLS symbol %s\n"),
11777 input_bfd
, input_section
, rel
->r_offset
,
11778 ppc64_elf_howto_table
[r_type
]->name
,
11782 /* Ensure reloc mapping code below stays sane. */
11783 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
11784 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
11785 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
11786 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
11787 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
11788 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
11789 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
11790 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
11791 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
11792 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
11800 case R_PPC64_LO_DS_OPT
:
11801 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11802 if ((insn
& (0x3f << 26)) != 58u << 26)
11804 insn
+= (14u << 26) - (58u << 26);
11805 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11806 r_type
= R_PPC64_TOC16_LO
;
11807 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11810 case R_PPC64_TOC16
:
11811 case R_PPC64_TOC16_LO
:
11812 case R_PPC64_TOC16_DS
:
11813 case R_PPC64_TOC16_LO_DS
:
11815 /* Check for toc tls entries. */
11816 unsigned char *toc_tls
;
11819 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11820 &local_syms
, rel
, input_bfd
);
11826 tls_mask
= *toc_tls
;
11827 if (r_type
== R_PPC64_TOC16_DS
11828 || r_type
== R_PPC64_TOC16_LO_DS
)
11831 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
11836 /* If we found a GD reloc pair, then we might be
11837 doing a GD->IE transition. */
11840 tls_gd
= TLS_TPRELGD
;
11841 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
11844 else if (retval
== 3)
11846 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
11854 case R_PPC64_GOT_TPREL16_HI
:
11855 case R_PPC64_GOT_TPREL16_HA
:
11857 && (tls_mask
& TLS_TPREL
) == 0)
11859 rel
->r_offset
-= d_offset
;
11860 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
11861 r_type
= R_PPC64_NONE
;
11862 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11866 case R_PPC64_GOT_TPREL16_DS
:
11867 case R_PPC64_GOT_TPREL16_LO_DS
:
11869 && (tls_mask
& TLS_TPREL
) == 0)
11872 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11874 insn
|= 0x3c0d0000; /* addis 0,13,0 */
11875 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11876 r_type
= R_PPC64_TPREL16_HA
;
11877 if (toc_symndx
!= 0)
11879 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
11880 rel
->r_addend
= toc_addend
;
11881 /* We changed the symbol. Start over in order to
11882 get h, sym, sec etc. right. */
11887 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11893 && (tls_mask
& TLS_TPREL
) == 0)
11895 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
11896 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
11899 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
11900 /* Was PPC64_TLS which sits on insn boundary, now
11901 PPC64_TPREL16_LO which is at low-order half-word. */
11902 rel
->r_offset
+= d_offset
;
11903 r_type
= R_PPC64_TPREL16_LO
;
11904 if (toc_symndx
!= 0)
11906 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
11907 rel
->r_addend
= toc_addend
;
11908 /* We changed the symbol. Start over in order to
11909 get h, sym, sec etc. right. */
11914 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11918 case R_PPC64_GOT_TLSGD16_HI
:
11919 case R_PPC64_GOT_TLSGD16_HA
:
11920 tls_gd
= TLS_TPRELGD
;
11921 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
11925 case R_PPC64_GOT_TLSLD16_HI
:
11926 case R_PPC64_GOT_TLSLD16_HA
:
11927 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
11930 if ((tls_mask
& tls_gd
) != 0)
11931 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
11932 + R_PPC64_GOT_TPREL16_DS
);
11935 rel
->r_offset
-= d_offset
;
11936 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
11937 r_type
= R_PPC64_NONE
;
11939 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11943 case R_PPC64_GOT_TLSGD16
:
11944 case R_PPC64_GOT_TLSGD16_LO
:
11945 tls_gd
= TLS_TPRELGD
;
11946 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
11950 case R_PPC64_GOT_TLSLD16
:
11951 case R_PPC64_GOT_TLSLD16_LO
:
11952 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
11954 unsigned int insn1
, insn2
, insn3
;
11958 offset
= (bfd_vma
) -1;
11959 /* If not using the newer R_PPC64_TLSGD/LD to mark
11960 __tls_get_addr calls, we must trust that the call
11961 stays with its arg setup insns, ie. that the next
11962 reloc is the __tls_get_addr call associated with
11963 the current reloc. Edit both insns. */
11964 if (input_section
->has_tls_get_addr_call
11965 && rel
+ 1 < relend
11966 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
11967 htab
->tls_get_addr
,
11968 htab
->tls_get_addr_fd
))
11969 offset
= rel
[1].r_offset
;
11970 if ((tls_mask
& tls_gd
) != 0)
11973 insn1
= bfd_get_32 (output_bfd
,
11974 contents
+ rel
->r_offset
- d_offset
);
11975 insn1
&= (1 << 26) - (1 << 2);
11976 insn1
|= 58 << 26; /* ld */
11977 insn2
= 0x7c636a14; /* add 3,3,13 */
11978 if (offset
!= (bfd_vma
) -1)
11979 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
11980 if ((tls_mask
& TLS_EXPLICIT
) == 0)
11981 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
11982 + R_PPC64_GOT_TPREL16_DS
);
11984 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
11985 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11990 insn1
= 0x3c6d0000; /* addis 3,13,0 */
11991 insn2
= 0x38630000; /* addi 3,3,0 */
11994 /* Was an LD reloc. */
11996 sec
= local_sections
[toc_symndx
];
11998 r_symndx
< symtab_hdr
->sh_info
;
12000 if (local_sections
[r_symndx
] == sec
)
12002 if (r_symndx
>= symtab_hdr
->sh_info
)
12003 r_symndx
= STN_UNDEF
;
12004 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12005 if (r_symndx
!= STN_UNDEF
)
12006 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12007 + sec
->output_offset
12008 + sec
->output_section
->vma
);
12010 else if (toc_symndx
!= 0)
12012 r_symndx
= toc_symndx
;
12013 rel
->r_addend
= toc_addend
;
12015 r_type
= R_PPC64_TPREL16_HA
;
12016 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12017 if (offset
!= (bfd_vma
) -1)
12019 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
12020 R_PPC64_TPREL16_LO
);
12021 rel
[1].r_offset
= offset
+ d_offset
;
12022 rel
[1].r_addend
= rel
->r_addend
;
12025 bfd_put_32 (output_bfd
, insn1
,
12026 contents
+ rel
->r_offset
- d_offset
);
12027 if (offset
!= (bfd_vma
) -1)
12029 insn3
= bfd_get_32 (output_bfd
,
12030 contents
+ offset
+ 4);
12032 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12034 rel
[1].r_offset
+= 4;
12035 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12038 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12040 if ((tls_mask
& tls_gd
) == 0
12041 && (tls_gd
== 0 || toc_symndx
!= 0))
12043 /* We changed the symbol. Start over in order
12044 to get h, sym, sec etc. right. */
12051 case R_PPC64_TLSGD
:
12052 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12054 unsigned int insn2
, insn3
;
12055 bfd_vma offset
= rel
->r_offset
;
12057 if ((tls_mask
& TLS_TPRELGD
) != 0)
12060 r_type
= R_PPC64_NONE
;
12061 insn2
= 0x7c636a14; /* add 3,3,13 */
12066 if (toc_symndx
!= 0)
12068 r_symndx
= toc_symndx
;
12069 rel
->r_addend
= toc_addend
;
12071 r_type
= R_PPC64_TPREL16_LO
;
12072 rel
->r_offset
= offset
+ d_offset
;
12073 insn2
= 0x38630000; /* addi 3,3,0 */
12075 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12076 /* Zap the reloc on the _tls_get_addr call too. */
12077 BFD_ASSERT (offset
== rel
[1].r_offset
);
12078 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12079 insn3
= bfd_get_32 (output_bfd
,
12080 contents
+ offset
+ 4);
12082 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12084 rel
->r_offset
+= 4;
12085 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12088 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12089 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
12097 case R_PPC64_TLSLD
:
12098 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12100 unsigned int insn2
, insn3
;
12101 bfd_vma offset
= rel
->r_offset
;
12104 sec
= local_sections
[toc_symndx
];
12106 r_symndx
< symtab_hdr
->sh_info
;
12108 if (local_sections
[r_symndx
] == sec
)
12110 if (r_symndx
>= symtab_hdr
->sh_info
)
12111 r_symndx
= STN_UNDEF
;
12112 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12113 if (r_symndx
!= STN_UNDEF
)
12114 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12115 + sec
->output_offset
12116 + sec
->output_section
->vma
);
12118 r_type
= R_PPC64_TPREL16_LO
;
12119 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12120 rel
->r_offset
= offset
+ d_offset
;
12121 /* Zap the reloc on the _tls_get_addr call too. */
12122 BFD_ASSERT (offset
== rel
[1].r_offset
);
12123 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12124 insn2
= 0x38630000; /* addi 3,3,0 */
12125 insn3
= bfd_get_32 (output_bfd
,
12126 contents
+ offset
+ 4);
12128 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12130 rel
->r_offset
+= 4;
12131 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12134 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12140 case R_PPC64_DTPMOD64
:
12141 if (rel
+ 1 < relend
12142 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
12143 && rel
[1].r_offset
== rel
->r_offset
+ 8)
12145 if ((tls_mask
& TLS_GD
) == 0)
12147 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
12148 if ((tls_mask
& TLS_TPRELGD
) != 0)
12149 r_type
= R_PPC64_TPREL64
;
12152 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12153 r_type
= R_PPC64_NONE
;
12155 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12160 if ((tls_mask
& TLS_LD
) == 0)
12162 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12163 r_type
= R_PPC64_NONE
;
12164 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12169 case R_PPC64_TPREL64
:
12170 if ((tls_mask
& TLS_TPREL
) == 0)
12172 r_type
= R_PPC64_NONE
;
12173 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12178 /* Handle other relocations that tweak non-addend part of insn. */
12180 max_br_offset
= 1 << 25;
12181 addend
= rel
->r_addend
;
12187 /* Branch taken prediction relocations. */
12188 case R_PPC64_ADDR14_BRTAKEN
:
12189 case R_PPC64_REL14_BRTAKEN
:
12190 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
12193 /* Branch not taken prediction relocations. */
12194 case R_PPC64_ADDR14_BRNTAKEN
:
12195 case R_PPC64_REL14_BRNTAKEN
:
12196 insn
|= bfd_get_32 (output_bfd
,
12197 contents
+ rel
->r_offset
) & ~(0x01 << 21);
12200 case R_PPC64_REL14
:
12201 max_br_offset
= 1 << 15;
12204 case R_PPC64_REL24
:
12205 /* Calls to functions with a different TOC, such as calls to
12206 shared objects, need to alter the TOC pointer. This is
12207 done using a linkage stub. A REL24 branching to these
12208 linkage stubs needs to be followed by a nop, as the nop
12209 will be replaced with an instruction to restore the TOC
12214 && h
->oh
->is_func_descriptor
)
12215 fdh
= ppc_follow_link (h
->oh
);
12216 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, rel
, htab
);
12217 if (stub_entry
!= NULL
12218 && (stub_entry
->stub_type
== ppc_stub_plt_call
12219 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
12220 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
12222 bfd_boolean can_plt_call
= FALSE
;
12224 if (rel
->r_offset
+ 8 <= input_section
->size
)
12227 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
12229 || nop
== CROR_151515
|| nop
== CROR_313131
)
12232 && (h
== htab
->tls_get_addr_fd
12233 || h
== htab
->tls_get_addr
)
12234 && !htab
->no_tls_get_addr_opt
)
12236 /* Special stub used, leave nop alone. */
12239 bfd_put_32 (input_bfd
, LD_R2_40R1
,
12240 contents
+ rel
->r_offset
+ 4);
12241 can_plt_call
= TRUE
;
12247 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
12249 /* If this is a plain branch rather than a branch
12250 and link, don't require a nop. However, don't
12251 allow tail calls in a shared library as they
12252 will result in r2 being corrupted. */
12254 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
12255 if (info
->executable
&& (br
& 1) == 0)
12256 can_plt_call
= TRUE
;
12261 && strcmp (h
->elf
.root
.root
.string
,
12262 ".__libc_start_main") == 0)
12264 /* Allow crt1 branch to go via a toc adjusting stub. */
12265 can_plt_call
= TRUE
;
12269 if (strcmp (input_section
->output_section
->name
,
12271 || strcmp (input_section
->output_section
->name
,
12273 info
->callbacks
->einfo
12274 (_("%H: automatic multiple TOCs "
12275 "not supported using your crt files; "
12276 "recompile with -mminimal-toc or upgrade gcc\n"),
12277 input_bfd
, input_section
, rel
->r_offset
);
12279 info
->callbacks
->einfo
12280 (_("%H: sibling call optimization to `%s' "
12281 "does not allow automatic multiple TOCs; "
12282 "recompile with -mminimal-toc or "
12283 "-fno-optimize-sibling-calls, "
12284 "or make `%s' extern\n"),
12285 input_bfd
, input_section
, rel
->r_offset
,
12288 bfd_set_error (bfd_error_bad_value
);
12294 && stub_entry
->stub_type
== ppc_stub_plt_call
)
12295 unresolved_reloc
= FALSE
;
12298 if ((stub_entry
== NULL
12299 || stub_entry
->stub_type
== ppc_stub_long_branch
12300 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12301 && get_opd_info (sec
) != NULL
)
12303 /* The branch destination is the value of the opd entry. */
12304 bfd_vma off
= (relocation
+ addend
12305 - sec
->output_section
->vma
12306 - sec
->output_offset
);
12307 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
12308 if (dest
!= (bfd_vma
) -1)
12315 /* If the branch is out of reach we ought to have a long
12317 from
= (rel
->r_offset
12318 + input_section
->output_offset
12319 + input_section
->output_section
->vma
);
12321 if (stub_entry
!= NULL
12322 && (stub_entry
->stub_type
== ppc_stub_long_branch
12323 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12324 && (r_type
== R_PPC64_ADDR14_BRTAKEN
12325 || r_type
== R_PPC64_ADDR14_BRNTAKEN
12326 || (relocation
+ addend
- from
+ max_br_offset
12327 < 2 * max_br_offset
)))
12328 /* Don't use the stub if this branch is in range. */
12331 if (stub_entry
!= NULL
)
12333 /* Munge up the value and addend so that we call the stub
12334 rather than the procedure directly. */
12335 relocation
= (stub_entry
->stub_offset
12336 + stub_entry
->stub_sec
->output_offset
12337 + stub_entry
->stub_sec
->output_section
->vma
);
12345 /* Set 'a' bit. This is 0b00010 in BO field for branch
12346 on CR(BI) insns (BO == 001at or 011at), and 0b01000
12347 for branch on CTR insns (BO == 1a00t or 1a01t). */
12348 if ((insn
& (0x14 << 21)) == (0x04 << 21))
12349 insn
|= 0x02 << 21;
12350 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
12351 insn
|= 0x08 << 21;
12357 /* Invert 'y' bit if not the default. */
12358 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
12359 insn
^= 0x01 << 21;
12362 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12365 /* NOP out calls to undefined weak functions.
12366 We can thus call a weak function without first
12367 checking whether the function is defined. */
12369 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12370 && h
->elf
.dynindx
== -1
12371 && r_type
== R_PPC64_REL24
12375 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12381 /* Set `addend'. */
12386 info
->callbacks
->einfo
12387 (_("%B: unknown relocation type %d for symbol %s\n"),
12388 input_bfd
, (int) r_type
, sym_name
);
12390 bfd_set_error (bfd_error_bad_value
);
12396 case R_PPC64_TLSGD
:
12397 case R_PPC64_TLSLD
:
12398 case R_PPC64_GNU_VTINHERIT
:
12399 case R_PPC64_GNU_VTENTRY
:
12402 /* GOT16 relocations. Like an ADDR16 using the symbol's
12403 address in the GOT as relocation value instead of the
12404 symbol's value itself. Also, create a GOT entry for the
12405 symbol and put the symbol value there. */
12406 case R_PPC64_GOT_TLSGD16
:
12407 case R_PPC64_GOT_TLSGD16_LO
:
12408 case R_PPC64_GOT_TLSGD16_HI
:
12409 case R_PPC64_GOT_TLSGD16_HA
:
12410 tls_type
= TLS_TLS
| TLS_GD
;
12413 case R_PPC64_GOT_TLSLD16
:
12414 case R_PPC64_GOT_TLSLD16_LO
:
12415 case R_PPC64_GOT_TLSLD16_HI
:
12416 case R_PPC64_GOT_TLSLD16_HA
:
12417 tls_type
= TLS_TLS
| TLS_LD
;
12420 case R_PPC64_GOT_TPREL16_DS
:
12421 case R_PPC64_GOT_TPREL16_LO_DS
:
12422 case R_PPC64_GOT_TPREL16_HI
:
12423 case R_PPC64_GOT_TPREL16_HA
:
12424 tls_type
= TLS_TLS
| TLS_TPREL
;
12427 case R_PPC64_GOT_DTPREL16_DS
:
12428 case R_PPC64_GOT_DTPREL16_LO_DS
:
12429 case R_PPC64_GOT_DTPREL16_HI
:
12430 case R_PPC64_GOT_DTPREL16_HA
:
12431 tls_type
= TLS_TLS
| TLS_DTPREL
;
12434 case R_PPC64_GOT16
:
12435 case R_PPC64_GOT16_LO
:
12436 case R_PPC64_GOT16_HI
:
12437 case R_PPC64_GOT16_HA
:
12438 case R_PPC64_GOT16_DS
:
12439 case R_PPC64_GOT16_LO_DS
:
12442 /* Relocation is to the entry for this symbol in the global
12447 unsigned long indx
= 0;
12448 struct got_entry
*ent
;
12450 if (tls_type
== (TLS_TLS
| TLS_LD
)
12452 || !h
->elf
.def_dynamic
))
12453 ent
= ppc64_tlsld_got (input_bfd
);
12459 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
12460 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
12463 && SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12464 /* This is actually a static link, or it is a
12465 -Bsymbolic link and the symbol is defined
12466 locally, or the symbol was forced to be local
12467 because of a version file. */
12471 indx
= h
->elf
.dynindx
;
12472 unresolved_reloc
= FALSE
;
12474 ent
= h
->elf
.got
.glist
;
12478 if (local_got_ents
== NULL
)
12480 ent
= local_got_ents
[r_symndx
];
12483 for (; ent
!= NULL
; ent
= ent
->next
)
12484 if (ent
->addend
== orig_addend
12485 && ent
->owner
== input_bfd
12486 && ent
->tls_type
== tls_type
)
12492 if (ent
->is_indirect
)
12493 ent
= ent
->got
.ent
;
12494 offp
= &ent
->got
.offset
;
12495 got
= ppc64_elf_tdata (ent
->owner
)->got
;
12499 /* The offset must always be a multiple of 8. We use the
12500 least significant bit to record whether we have already
12501 processed this entry. */
12503 if ((off
& 1) != 0)
12507 /* Generate relocs for the dynamic linker, except in
12508 the case of TLSLD where we'll use one entry per
12516 ? h
->elf
.type
== STT_GNU_IFUNC
12517 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
12518 if ((info
->shared
|| indx
!= 0)
12520 || (tls_type
== (TLS_TLS
| TLS_LD
)
12521 && !h
->elf
.def_dynamic
)
12522 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12523 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
12524 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
12526 relgot
= htab
->reliplt
;
12527 if (relgot
!= NULL
)
12529 outrel
.r_offset
= (got
->output_section
->vma
12530 + got
->output_offset
12532 outrel
.r_addend
= addend
;
12533 if (tls_type
& (TLS_LD
| TLS_GD
))
12535 outrel
.r_addend
= 0;
12536 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
12537 if (tls_type
== (TLS_TLS
| TLS_GD
))
12539 loc
= relgot
->contents
;
12540 loc
+= (relgot
->reloc_count
++
12541 * sizeof (Elf64_External_Rela
));
12542 bfd_elf64_swap_reloca_out (output_bfd
,
12544 outrel
.r_offset
+= 8;
12545 outrel
.r_addend
= addend
;
12547 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12550 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
12551 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12552 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12553 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
12554 else if (indx
!= 0)
12555 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
12559 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12561 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12563 /* Write the .got section contents for the sake
12565 loc
= got
->contents
+ off
;
12566 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
12570 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
12572 outrel
.r_addend
+= relocation
;
12573 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
12574 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
12576 loc
= relgot
->contents
;
12577 loc
+= (relgot
->reloc_count
++
12578 * sizeof (Elf64_External_Rela
));
12579 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
12582 /* Init the .got section contents here if we're not
12583 emitting a reloc. */
12586 relocation
+= addend
;
12587 if (tls_type
== (TLS_TLS
| TLS_LD
))
12589 else if (tls_type
!= 0)
12591 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12592 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12593 relocation
+= DTP_OFFSET
- TP_OFFSET
;
12595 if (tls_type
== (TLS_TLS
| TLS_GD
))
12597 bfd_put_64 (output_bfd
, relocation
,
12598 got
->contents
+ off
+ 8);
12603 bfd_put_64 (output_bfd
, relocation
,
12604 got
->contents
+ off
);
12608 if (off
>= (bfd_vma
) -2)
12611 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
12612 addend
= -(TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
);
12616 case R_PPC64_PLT16_HA
:
12617 case R_PPC64_PLT16_HI
:
12618 case R_PPC64_PLT16_LO
:
12619 case R_PPC64_PLT32
:
12620 case R_PPC64_PLT64
:
12621 /* Relocation is to the entry for this symbol in the
12622 procedure linkage table. */
12624 /* Resolve a PLT reloc against a local symbol directly,
12625 without using the procedure linkage table. */
12629 /* It's possible that we didn't make a PLT entry for this
12630 symbol. This happens when statically linking PIC code,
12631 or when using -Bsymbolic. Go find a match if there is a
12633 if (htab
->plt
!= NULL
)
12635 struct plt_entry
*ent
;
12636 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12637 if (ent
->addend
== orig_addend
12638 && ent
->plt
.offset
!= (bfd_vma
) -1)
12640 relocation
= (htab
->plt
->output_section
->vma
12641 + htab
->plt
->output_offset
12642 + ent
->plt
.offset
);
12643 unresolved_reloc
= FALSE
;
12649 /* Relocation value is TOC base. */
12650 relocation
= TOCstart
;
12651 if (r_symndx
== STN_UNDEF
)
12652 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
12653 else if (unresolved_reloc
)
12655 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
12656 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
12658 unresolved_reloc
= TRUE
;
12661 /* TOC16 relocs. We want the offset relative to the TOC base,
12662 which is the address of the start of the TOC plus 0x8000.
12663 The TOC consists of sections .got, .toc, .tocbss, and .plt,
12665 case R_PPC64_TOC16
:
12666 case R_PPC64_TOC16_LO
:
12667 case R_PPC64_TOC16_HI
:
12668 case R_PPC64_TOC16_DS
:
12669 case R_PPC64_TOC16_LO_DS
:
12670 case R_PPC64_TOC16_HA
:
12671 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
12674 /* Relocate against the beginning of the section. */
12675 case R_PPC64_SECTOFF
:
12676 case R_PPC64_SECTOFF_LO
:
12677 case R_PPC64_SECTOFF_HI
:
12678 case R_PPC64_SECTOFF_DS
:
12679 case R_PPC64_SECTOFF_LO_DS
:
12680 case R_PPC64_SECTOFF_HA
:
12682 addend
-= sec
->output_section
->vma
;
12685 case R_PPC64_REL16
:
12686 case R_PPC64_REL16_LO
:
12687 case R_PPC64_REL16_HI
:
12688 case R_PPC64_REL16_HA
:
12691 case R_PPC64_REL14
:
12692 case R_PPC64_REL14_BRNTAKEN
:
12693 case R_PPC64_REL14_BRTAKEN
:
12694 case R_PPC64_REL24
:
12697 case R_PPC64_TPREL16
:
12698 case R_PPC64_TPREL16_LO
:
12699 case R_PPC64_TPREL16_HI
:
12700 case R_PPC64_TPREL16_HA
:
12701 case R_PPC64_TPREL16_DS
:
12702 case R_PPC64_TPREL16_LO_DS
:
12703 case R_PPC64_TPREL16_HIGHER
:
12704 case R_PPC64_TPREL16_HIGHERA
:
12705 case R_PPC64_TPREL16_HIGHEST
:
12706 case R_PPC64_TPREL16_HIGHESTA
:
12708 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12709 && h
->elf
.dynindx
== -1)
12711 /* Make this relocation against an undefined weak symbol
12712 resolve to zero. This is really just a tweak, since
12713 code using weak externs ought to check that they are
12714 defined before using them. */
12715 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
12717 insn
= bfd_get_32 (output_bfd
, p
);
12718 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
12720 bfd_put_32 (output_bfd
, insn
, p
);
12723 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12725 /* The TPREL16 relocs shouldn't really be used in shared
12726 libs as they will result in DT_TEXTREL being set, but
12727 support them anyway. */
12731 case R_PPC64_DTPREL16
:
12732 case R_PPC64_DTPREL16_LO
:
12733 case R_PPC64_DTPREL16_HI
:
12734 case R_PPC64_DTPREL16_HA
:
12735 case R_PPC64_DTPREL16_DS
:
12736 case R_PPC64_DTPREL16_LO_DS
:
12737 case R_PPC64_DTPREL16_HIGHER
:
12738 case R_PPC64_DTPREL16_HIGHERA
:
12739 case R_PPC64_DTPREL16_HIGHEST
:
12740 case R_PPC64_DTPREL16_HIGHESTA
:
12741 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12744 case R_PPC64_DTPMOD64
:
12749 case R_PPC64_TPREL64
:
12750 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12753 case R_PPC64_DTPREL64
:
12754 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12757 /* Relocations that may need to be propagated if this is a
12759 case R_PPC64_REL30
:
12760 case R_PPC64_REL32
:
12761 case R_PPC64_REL64
:
12762 case R_PPC64_ADDR14
:
12763 case R_PPC64_ADDR14_BRNTAKEN
:
12764 case R_PPC64_ADDR14_BRTAKEN
:
12765 case R_PPC64_ADDR16
:
12766 case R_PPC64_ADDR16_DS
:
12767 case R_PPC64_ADDR16_HA
:
12768 case R_PPC64_ADDR16_HI
:
12769 case R_PPC64_ADDR16_HIGHER
:
12770 case R_PPC64_ADDR16_HIGHERA
:
12771 case R_PPC64_ADDR16_HIGHEST
:
12772 case R_PPC64_ADDR16_HIGHESTA
:
12773 case R_PPC64_ADDR16_LO
:
12774 case R_PPC64_ADDR16_LO_DS
:
12775 case R_PPC64_ADDR24
:
12776 case R_PPC64_ADDR32
:
12777 case R_PPC64_ADDR64
:
12778 case R_PPC64_UADDR16
:
12779 case R_PPC64_UADDR32
:
12780 case R_PPC64_UADDR64
:
12782 if ((input_section
->flags
& SEC_ALLOC
) == 0)
12785 if (NO_OPD_RELOCS
&& is_opd
)
12790 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12791 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
12792 && (must_be_dyn_reloc (info
, r_type
)
12793 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12794 || (ELIMINATE_COPY_RELOCS
12797 && h
->elf
.dynindx
!= -1
12798 && !h
->elf
.non_got_ref
12799 && !h
->elf
.def_regular
)
12802 ? h
->elf
.type
== STT_GNU_IFUNC
12803 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
12805 bfd_boolean skip
, relocate
;
12809 /* When generating a dynamic object, these relocations
12810 are copied into the output file to be resolved at run
12816 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
12817 input_section
, rel
->r_offset
);
12818 if (out_off
== (bfd_vma
) -1)
12820 else if (out_off
== (bfd_vma
) -2)
12821 skip
= TRUE
, relocate
= TRUE
;
12822 out_off
+= (input_section
->output_section
->vma
12823 + input_section
->output_offset
);
12824 outrel
.r_offset
= out_off
;
12825 outrel
.r_addend
= rel
->r_addend
;
12827 /* Optimize unaligned reloc use. */
12828 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
12829 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
12830 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
12831 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
12832 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
12833 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
12834 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
12835 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
12836 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
12839 memset (&outrel
, 0, sizeof outrel
);
12840 else if (!SYMBOL_CALLS_LOCAL (info
, &h
->elf
)
12842 && r_type
!= R_PPC64_TOC
)
12843 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
12846 /* This symbol is local, or marked to become local,
12847 or this is an opd section reloc which must point
12848 at a local function. */
12849 outrel
.r_addend
+= relocation
;
12850 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
12852 if (is_opd
&& h
!= NULL
)
12854 /* Lie about opd entries. This case occurs
12855 when building shared libraries and we
12856 reference a function in another shared
12857 lib. The same thing happens for a weak
12858 definition in an application that's
12859 overridden by a strong definition in a
12860 shared lib. (I believe this is a generic
12861 bug in binutils handling of weak syms.)
12862 In these cases we won't use the opd
12863 entry in this lib. */
12864 unresolved_reloc
= FALSE
;
12867 && r_type
== R_PPC64_ADDR64
12869 ? h
->elf
.type
== STT_GNU_IFUNC
12870 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
12871 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12874 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12876 /* We need to relocate .opd contents for ld.so.
12877 Prelink also wants simple and consistent rules
12878 for relocs. This make all RELATIVE relocs have
12879 *r_offset equal to r_addend. */
12888 ? h
->elf
.type
== STT_GNU_IFUNC
12889 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12891 info
->callbacks
->einfo
12892 (_("%H: relocation %s for indirect "
12893 "function %s unsupported\n"),
12894 input_bfd
, input_section
, rel
->r_offset
,
12895 ppc64_elf_howto_table
[r_type
]->name
,
12899 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
12901 else if (sec
== NULL
|| sec
->owner
== NULL
)
12903 bfd_set_error (bfd_error_bad_value
);
12910 osec
= sec
->output_section
;
12911 indx
= elf_section_data (osec
)->dynindx
;
12915 if ((osec
->flags
& SEC_READONLY
) == 0
12916 && htab
->elf
.data_index_section
!= NULL
)
12917 osec
= htab
->elf
.data_index_section
;
12919 osec
= htab
->elf
.text_index_section
;
12920 indx
= elf_section_data (osec
)->dynindx
;
12922 BFD_ASSERT (indx
!= 0);
12924 /* We are turning this relocation into one
12925 against a section symbol, so subtract out
12926 the output section's address but not the
12927 offset of the input section in the output
12929 outrel
.r_addend
-= osec
->vma
;
12932 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
12936 sreloc
= elf_section_data (input_section
)->sreloc
;
12937 if (!htab
->elf
.dynamic_sections_created
)
12938 sreloc
= htab
->reliplt
;
12939 if (sreloc
== NULL
)
12942 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
12945 loc
= sreloc
->contents
;
12946 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
12947 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
12949 /* If this reloc is against an external symbol, it will
12950 be computed at runtime, so there's no need to do
12951 anything now. However, for the sake of prelink ensure
12952 that the section contents are a known value. */
12955 unresolved_reloc
= FALSE
;
12956 /* The value chosen here is quite arbitrary as ld.so
12957 ignores section contents except for the special
12958 case of .opd where the contents might be accessed
12959 before relocation. Choose zero, as that won't
12960 cause reloc overflow. */
12963 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
12964 to improve backward compatibility with older
12966 if (r_type
== R_PPC64_ADDR64
)
12967 addend
= outrel
.r_addend
;
12968 /* Adjust pc_relative relocs to have zero in *r_offset. */
12969 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
12970 addend
= (input_section
->output_section
->vma
12971 + input_section
->output_offset
12978 case R_PPC64_GLOB_DAT
:
12979 case R_PPC64_JMP_SLOT
:
12980 case R_PPC64_JMP_IREL
:
12981 case R_PPC64_RELATIVE
:
12982 /* We shouldn't ever see these dynamic relocs in relocatable
12984 /* Fall through. */
12986 case R_PPC64_PLTGOT16
:
12987 case R_PPC64_PLTGOT16_DS
:
12988 case R_PPC64_PLTGOT16_HA
:
12989 case R_PPC64_PLTGOT16_HI
:
12990 case R_PPC64_PLTGOT16_LO
:
12991 case R_PPC64_PLTGOT16_LO_DS
:
12992 case R_PPC64_PLTREL32
:
12993 case R_PPC64_PLTREL64
:
12994 /* These ones haven't been implemented yet. */
12996 info
->callbacks
->einfo
12997 (_("%B: relocation %s is not supported for symbol %s\n"),
12999 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
13001 bfd_set_error (bfd_error_invalid_operation
);
13006 /* Multi-instruction sequences that access the TOC can be
13007 optimized, eg. addis ra,r2,0; addi rb,ra,x;
13008 to nop; addi rb,r2,x; */
13014 case R_PPC64_GOT_TLSLD16_HI
:
13015 case R_PPC64_GOT_TLSGD16_HI
:
13016 case R_PPC64_GOT_TPREL16_HI
:
13017 case R_PPC64_GOT_DTPREL16_HI
:
13018 case R_PPC64_GOT16_HI
:
13019 case R_PPC64_TOC16_HI
:
13020 /* These relocs would only be useful if building up an
13021 offset to later add to r2, perhaps in an indexed
13022 addressing mode instruction. Don't try to optimize.
13023 Unfortunately, the possibility of someone building up an
13024 offset like this or even with the HA relocs, means that
13025 we need to check the high insn when optimizing the low
13029 case R_PPC64_GOT_TLSLD16_HA
:
13030 case R_PPC64_GOT_TLSGD16_HA
:
13031 case R_PPC64_GOT_TPREL16_HA
:
13032 case R_PPC64_GOT_DTPREL16_HA
:
13033 case R_PPC64_GOT16_HA
:
13034 case R_PPC64_TOC16_HA
:
13035 /* nop is done later. */
13038 case R_PPC64_GOT_TLSLD16_LO
:
13039 case R_PPC64_GOT_TLSGD16_LO
:
13040 case R_PPC64_GOT_TPREL16_LO_DS
:
13041 case R_PPC64_GOT_DTPREL16_LO_DS
:
13042 case R_PPC64_GOT16_LO
:
13043 case R_PPC64_GOT16_LO_DS
:
13044 case R_PPC64_TOC16_LO
:
13045 case R_PPC64_TOC16_LO_DS
:
13046 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
13048 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13049 insn
= bfd_get_32 (input_bfd
, p
);
13050 if ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
13051 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
13052 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
13053 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
13054 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
13055 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
13056 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
13057 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
13058 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
13059 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
13060 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
13061 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
13062 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
13063 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
13064 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
13065 && (insn
& 3) != 1)
13066 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
13067 && ((insn
& 3) == 0 || (insn
& 3) == 3)))
13069 unsigned int reg
= (insn
>> 16) & 0x1f;
13070 const Elf_Internal_Rela
*ha
;
13071 bfd_boolean match_addend
;
13073 match_addend
= (sym
!= NULL
13074 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
);
13075 ha
= ha_reloc_match (relocs
, rel
, ®
, match_addend
,
13076 input_bfd
, contents
);
13079 insn
&= ~(0x1f << 16);
13081 bfd_put_32 (input_bfd
, insn
, p
);
13082 if (ha_opt
== NULL
)
13084 ha_opt
= bfd_zmalloc (input_section
->reloc_count
);
13085 if (ha_opt
== NULL
)
13088 ha_opt
[ha
- relocs
] = 1;
13091 /* If we don't find a matching high part insn,
13092 something is fishy. Refuse to nop any high
13093 part insn in this section. */
13100 /* Do any further special processing. */
13106 case R_PPC64_ADDR16_HA
:
13107 case R_PPC64_REL16_HA
:
13108 case R_PPC64_ADDR16_HIGHERA
:
13109 case R_PPC64_ADDR16_HIGHESTA
:
13110 case R_PPC64_TOC16_HA
:
13111 case R_PPC64_SECTOFF_HA
:
13112 case R_PPC64_TPREL16_HA
:
13113 case R_PPC64_DTPREL16_HA
:
13114 case R_PPC64_TPREL16_HIGHER
:
13115 case R_PPC64_TPREL16_HIGHERA
:
13116 case R_PPC64_TPREL16_HIGHEST
:
13117 case R_PPC64_TPREL16_HIGHESTA
:
13118 case R_PPC64_DTPREL16_HIGHER
:
13119 case R_PPC64_DTPREL16_HIGHERA
:
13120 case R_PPC64_DTPREL16_HIGHEST
:
13121 case R_PPC64_DTPREL16_HIGHESTA
:
13122 /* It's just possible that this symbol is a weak symbol
13123 that's not actually defined anywhere. In that case,
13124 'sec' would be NULL, and we should leave the symbol
13125 alone (it will be set to zero elsewhere in the link). */
13130 case R_PPC64_GOT16_HA
:
13131 case R_PPC64_PLTGOT16_HA
:
13132 case R_PPC64_PLT16_HA
:
13133 case R_PPC64_GOT_TLSGD16_HA
:
13134 case R_PPC64_GOT_TLSLD16_HA
:
13135 case R_PPC64_GOT_TPREL16_HA
:
13136 case R_PPC64_GOT_DTPREL16_HA
:
13137 /* Add 0x10000 if sign bit in 0:15 is set.
13138 Bits 0:15 are not used. */
13142 case R_PPC64_ADDR16_DS
:
13143 case R_PPC64_ADDR16_LO_DS
:
13144 case R_PPC64_GOT16_DS
:
13145 case R_PPC64_GOT16_LO_DS
:
13146 case R_PPC64_PLT16_LO_DS
:
13147 case R_PPC64_SECTOFF_DS
:
13148 case R_PPC64_SECTOFF_LO_DS
:
13149 case R_PPC64_TOC16_DS
:
13150 case R_PPC64_TOC16_LO_DS
:
13151 case R_PPC64_PLTGOT16_DS
:
13152 case R_PPC64_PLTGOT16_LO_DS
:
13153 case R_PPC64_GOT_TPREL16_DS
:
13154 case R_PPC64_GOT_TPREL16_LO_DS
:
13155 case R_PPC64_GOT_DTPREL16_DS
:
13156 case R_PPC64_GOT_DTPREL16_LO_DS
:
13157 case R_PPC64_TPREL16_DS
:
13158 case R_PPC64_TPREL16_LO_DS
:
13159 case R_PPC64_DTPREL16_DS
:
13160 case R_PPC64_DTPREL16_LO_DS
:
13161 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
13163 /* If this reloc is against an lq insn, then the value must be
13164 a multiple of 16. This is somewhat of a hack, but the
13165 "correct" way to do this by defining _DQ forms of all the
13166 _DS relocs bloats all reloc switches in this file. It
13167 doesn't seem to make much sense to use any of these relocs
13168 in data, so testing the insn should be safe. */
13169 if ((insn
& (0x3f << 26)) == (56u << 26))
13171 if (((relocation
+ addend
) & mask
) != 0)
13173 info
->callbacks
->einfo
13174 (_("%H: error: %s not a multiple of %u\n"),
13175 input_bfd
, input_section
, rel
->r_offset
,
13176 ppc64_elf_howto_table
[r_type
]->name
,
13178 bfd_set_error (bfd_error_bad_value
);
13185 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
13186 because such sections are not SEC_ALLOC and thus ld.so will
13187 not process them. */
13188 if (unresolved_reloc
13189 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
13190 && h
->elf
.def_dynamic
))
13192 info
->callbacks
->einfo
13193 (_("%H: unresolvable %s relocation against symbol `%s'\n"),
13194 input_bfd
, input_section
, rel
->r_offset
,
13195 ppc64_elf_howto_table
[(int) r_type
]->name
,
13196 h
->elf
.root
.root
.string
);
13200 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
13208 if (r
!= bfd_reloc_ok
)
13210 if (sym_name
== NULL
)
13211 sym_name
= "(null)";
13212 if (r
== bfd_reloc_overflow
)
13217 && h
->elf
.root
.type
== bfd_link_hash_undefweak
13218 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
13220 /* Assume this is a call protected by other code that
13221 detects the symbol is undefined. If this is the case,
13222 we can safely ignore the overflow. If not, the
13223 program is hosed anyway, and a little warning isn't
13229 if (!((*info
->callbacks
->reloc_overflow
)
13230 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
13231 ppc64_elf_howto_table
[r_type
]->name
,
13232 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
13237 info
->callbacks
->einfo
13238 (_("%H: %s reloc against `%s': error %d\n"),
13239 input_bfd
, input_section
, rel
->r_offset
,
13240 ppc64_elf_howto_table
[r_type
]->name
,
13248 if (ha_opt
!= NULL
)
13252 unsigned char *opt
= ha_opt
;
13254 relend
= relocs
+ input_section
->reloc_count
;
13255 for (; rel
< relend
; opt
++, rel
++)
13258 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13259 bfd_put_32 (input_bfd
, NOP
, p
);
13265 /* If we're emitting relocations, then shortly after this function
13266 returns, reloc offsets and addends for this section will be
13267 adjusted. Worse, reloc symbol indices will be for the output
13268 file rather than the input. Save a copy of the relocs for
13269 opd_entry_value. */
13270 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
13273 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
13274 rel
= bfd_alloc (input_bfd
, amt
);
13275 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
13276 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
13279 memcpy (rel
, relocs
, amt
);
13284 /* Adjust the value of any local symbols in opd sections. */
13287 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
13288 const char *name ATTRIBUTE_UNUSED
,
13289 Elf_Internal_Sym
*elfsym
,
13290 asection
*input_sec
,
13291 struct elf_link_hash_entry
*h
)
13293 struct _opd_sec_data
*opd
;
13300 opd
= get_opd_info (input_sec
);
13301 if (opd
== NULL
|| opd
->adjust
== NULL
)
13304 value
= elfsym
->st_value
- input_sec
->output_offset
;
13305 if (!info
->relocatable
)
13306 value
-= input_sec
->output_section
->vma
;
13308 adjust
= opd
->adjust
[value
/ 8];
13312 elfsym
->st_value
+= adjust
;
13316 /* Finish up dynamic symbol handling. We set the contents of various
13317 dynamic sections here. */
13320 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
13321 struct bfd_link_info
*info
,
13322 struct elf_link_hash_entry
*h
,
13323 Elf_Internal_Sym
*sym
)
13325 struct ppc_link_hash_table
*htab
;
13326 struct plt_entry
*ent
;
13327 Elf_Internal_Rela rela
;
13330 htab
= ppc_hash_table (info
);
13334 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13335 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13337 /* This symbol has an entry in the procedure linkage
13338 table. Set it up. */
13339 if (!htab
->elf
.dynamic_sections_created
13340 || h
->dynindx
== -1)
13342 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
13344 && (h
->root
.type
== bfd_link_hash_defined
13345 || h
->root
.type
== bfd_link_hash_defweak
));
13346 rela
.r_offset
= (htab
->iplt
->output_section
->vma
13347 + htab
->iplt
->output_offset
13348 + ent
->plt
.offset
);
13349 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13350 rela
.r_addend
= (h
->root
.u
.def
.value
13351 + h
->root
.u
.def
.section
->output_offset
13352 + h
->root
.u
.def
.section
->output_section
->vma
13354 loc
= (htab
->reliplt
->contents
13355 + (htab
->reliplt
->reloc_count
++
13356 * sizeof (Elf64_External_Rela
)));
13360 rela
.r_offset
= (htab
->plt
->output_section
->vma
13361 + htab
->plt
->output_offset
13362 + ent
->plt
.offset
);
13363 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13364 rela
.r_addend
= ent
->addend
;
13365 loc
= (htab
->relplt
->contents
13366 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
)
13367 / (PLT_ENTRY_SIZE
/ sizeof (Elf64_External_Rela
))));
13369 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13374 /* This symbol needs a copy reloc. Set it up. */
13376 if (h
->dynindx
== -1
13377 || (h
->root
.type
!= bfd_link_hash_defined
13378 && h
->root
.type
!= bfd_link_hash_defweak
)
13379 || htab
->relbss
== NULL
)
13382 rela
.r_offset
= (h
->root
.u
.def
.value
13383 + h
->root
.u
.def
.section
->output_section
->vma
13384 + h
->root
.u
.def
.section
->output_offset
);
13385 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
13387 loc
= htab
->relbss
->contents
;
13388 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13389 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13392 /* Mark some specially defined symbols as absolute. */
13393 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
13394 sym
->st_shndx
= SHN_ABS
;
13399 /* Used to decide how to sort relocs in an optimal manner for the
13400 dynamic linker, before writing them out. */
13402 static enum elf_reloc_type_class
13403 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
13405 enum elf_ppc64_reloc_type r_type
;
13407 r_type
= ELF64_R_TYPE (rela
->r_info
);
13410 case R_PPC64_RELATIVE
:
13411 return reloc_class_relative
;
13412 case R_PPC64_JMP_SLOT
:
13413 return reloc_class_plt
;
13415 return reloc_class_copy
;
13417 return reloc_class_normal
;
13421 /* Finish up the dynamic sections. */
13424 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
13425 struct bfd_link_info
*info
)
13427 struct ppc_link_hash_table
*htab
;
13431 htab
= ppc_hash_table (info
);
13435 dynobj
= htab
->elf
.dynobj
;
13436 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
13438 if (htab
->elf
.dynamic_sections_created
)
13440 Elf64_External_Dyn
*dyncon
, *dynconend
;
13442 if (sdyn
== NULL
|| htab
->got
== NULL
)
13445 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
13446 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
13447 for (; dyncon
< dynconend
; dyncon
++)
13449 Elf_Internal_Dyn dyn
;
13452 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
13459 case DT_PPC64_GLINK
:
13461 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13462 /* We stupidly defined DT_PPC64_GLINK to be the start
13463 of glink rather than the first entry point, which is
13464 what ld.so needs, and now have a bigger stub to
13465 support automatic multiple TOCs. */
13466 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
13470 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13473 dyn
.d_un
.d_ptr
= s
->vma
;
13476 case DT_PPC64_OPDSZ
:
13477 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13480 dyn
.d_un
.d_val
= s
->size
;
13485 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13490 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13494 dyn
.d_un
.d_val
= htab
->relplt
->size
;
13498 /* Don't count procedure linkage table relocs in the
13499 overall reloc count. */
13503 dyn
.d_un
.d_val
-= s
->size
;
13507 /* We may not be using the standard ELF linker script.
13508 If .rela.plt is the first .rela section, we adjust
13509 DT_RELA to not include it. */
13513 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
13515 dyn
.d_un
.d_ptr
+= s
->size
;
13519 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13523 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
13525 /* Fill in the first entry in the global offset table.
13526 We use it to hold the link-time TOCbase. */
13527 bfd_put_64 (output_bfd
,
13528 elf_gp (output_bfd
) + TOC_BASE_OFF
,
13529 htab
->got
->contents
);
13531 /* Set .got entry size. */
13532 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
13535 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
13537 /* Set .plt entry size. */
13538 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
13542 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
13543 brlt ourselves if emitrelocations. */
13544 if (htab
->brlt
!= NULL
13545 && htab
->brlt
->reloc_count
!= 0
13546 && !_bfd_elf_link_output_relocs (output_bfd
,
13548 elf_section_data (htab
->brlt
)->rela
.hdr
,
13549 elf_section_data (htab
->brlt
)->relocs
,
13553 if (htab
->glink
!= NULL
13554 && htab
->glink
->reloc_count
!= 0
13555 && !_bfd_elf_link_output_relocs (output_bfd
,
13557 elf_section_data (htab
->glink
)->rela
.hdr
,
13558 elf_section_data (htab
->glink
)->relocs
,
13562 /* We need to handle writing out multiple GOT sections ourselves,
13563 since we didn't add them to DYNOBJ. We know dynobj is the first
13565 while ((dynobj
= dynobj
->link_next
) != NULL
)
13569 if (!is_ppc64_elf (dynobj
))
13572 s
= ppc64_elf_tdata (dynobj
)->got
;
13575 && s
->output_section
!= bfd_abs_section_ptr
13576 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13577 s
->contents
, s
->output_offset
,
13580 s
= ppc64_elf_tdata (dynobj
)->relgot
;
13583 && s
->output_section
!= bfd_abs_section_ptr
13584 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13585 s
->contents
, s
->output_offset
,
13593 #include "elf64-target.h"