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 ppc64_elf_merge_private_bfd_data
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 /* Merge backend specific data from an object file to the output
2731 object file when linking. */
2734 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2736 /* Check if we have the same endianess. */
2737 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2738 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2739 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2743 if (bfd_big_endian (ibfd
))
2744 msg
= _("%B: compiled for a big endian system "
2745 "and target is little endian");
2747 msg
= _("%B: compiled for a little endian system "
2748 "and target is big endian");
2750 (*_bfd_error_handler
) (msg
, ibfd
);
2752 bfd_set_error (bfd_error_wrong_format
);
2759 /* Add extra PPC sections. */
2761 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2763 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2764 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2765 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2766 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2767 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2768 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2769 { NULL
, 0, 0, 0, 0 }
2772 enum _ppc64_sec_type
{
2778 struct _ppc64_elf_section_data
2780 struct bfd_elf_section_data elf
;
2784 /* An array with one entry for each opd function descriptor. */
2785 struct _opd_sec_data
2787 /* Points to the function code section for local opd entries. */
2788 asection
**func_sec
;
2790 /* After editing .opd, adjust references to opd local syms. */
2794 /* An array for toc sections, indexed by offset/8. */
2795 struct _toc_sec_data
2797 /* Specifies the relocation symbol index used at a given toc offset. */
2800 /* And the relocation addend. */
2805 enum _ppc64_sec_type sec_type
:2;
2807 /* Flag set when small branches are detected. Used to
2808 select suitable defaults for the stub group size. */
2809 unsigned int has_14bit_branch
:1;
2812 #define ppc64_elf_section_data(sec) \
2813 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2816 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2818 if (!sec
->used_by_bfd
)
2820 struct _ppc64_elf_section_data
*sdata
;
2821 bfd_size_type amt
= sizeof (*sdata
);
2823 sdata
= bfd_zalloc (abfd
, amt
);
2826 sec
->used_by_bfd
= sdata
;
2829 return _bfd_elf_new_section_hook (abfd
, sec
);
2832 static struct _opd_sec_data
*
2833 get_opd_info (asection
* sec
)
2836 && ppc64_elf_section_data (sec
) != NULL
2837 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2838 return &ppc64_elf_section_data (sec
)->u
.opd
;
2842 /* Parameters for the qsort hook. */
2843 static bfd_boolean synthetic_relocatable
;
2845 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2848 compare_symbols (const void *ap
, const void *bp
)
2850 const asymbol
*a
= * (const asymbol
**) ap
;
2851 const asymbol
*b
= * (const asymbol
**) bp
;
2853 /* Section symbols first. */
2854 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2856 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2859 /* then .opd symbols. */
2860 if (strcmp (a
->section
->name
, ".opd") == 0
2861 && strcmp (b
->section
->name
, ".opd") != 0)
2863 if (strcmp (a
->section
->name
, ".opd") != 0
2864 && strcmp (b
->section
->name
, ".opd") == 0)
2867 /* then other code symbols. */
2868 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2869 == (SEC_CODE
| SEC_ALLOC
)
2870 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2871 != (SEC_CODE
| SEC_ALLOC
))
2874 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2875 != (SEC_CODE
| SEC_ALLOC
)
2876 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2877 == (SEC_CODE
| SEC_ALLOC
))
2880 if (synthetic_relocatable
)
2882 if (a
->section
->id
< b
->section
->id
)
2885 if (a
->section
->id
> b
->section
->id
)
2889 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2892 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2895 /* For syms with the same value, prefer strong dynamic global function
2896 syms over other syms. */
2897 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2900 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2903 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2906 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2909 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2912 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2915 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2918 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2924 /* Search SYMS for a symbol of the given VALUE. */
2927 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2935 mid
= (lo
+ hi
) >> 1;
2936 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2938 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2948 mid
= (lo
+ hi
) >> 1;
2949 if (syms
[mid
]->section
->id
< id
)
2951 else if (syms
[mid
]->section
->id
> id
)
2953 else if (syms
[mid
]->value
< value
)
2955 else if (syms
[mid
]->value
> value
)
2965 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2967 bfd_vma vma
= *(bfd_vma
*) ptr
;
2968 return ((section
->flags
& SEC_ALLOC
) != 0
2969 && section
->vma
<= vma
2970 && vma
< section
->vma
+ section
->size
);
2973 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2974 entry syms. Also generate @plt symbols for the glink branch table. */
2977 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2978 long static_count
, asymbol
**static_syms
,
2979 long dyn_count
, asymbol
**dyn_syms
,
2986 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2988 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2993 opd
= bfd_get_section_by_name (abfd
, ".opd");
2997 symcount
= static_count
;
2999 symcount
+= dyn_count
;
3003 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3007 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3009 /* Use both symbol tables. */
3010 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3011 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
3013 else if (!relocatable
&& static_count
== 0)
3014 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3016 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3018 synthetic_relocatable
= relocatable
;
3019 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3021 if (!relocatable
&& symcount
> 1)
3024 /* Trim duplicate syms, since we may have merged the normal and
3025 dynamic symbols. Actually, we only care about syms that have
3026 different values, so trim any with the same value. */
3027 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3028 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3029 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3030 syms
[j
++] = syms
[i
];
3035 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3039 for (; i
< symcount
; ++i
)
3040 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3041 != (SEC_CODE
| SEC_ALLOC
))
3042 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3046 for (; i
< symcount
; ++i
)
3047 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3051 for (; i
< symcount
; ++i
)
3052 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3056 for (; i
< symcount
; ++i
)
3057 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3058 != (SEC_CODE
| SEC_ALLOC
))
3066 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3071 if (opdsymend
== secsymend
)
3074 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3075 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3079 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3086 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3090 while (r
< opd
->relocation
+ relcount
3091 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3094 if (r
== opd
->relocation
+ relcount
)
3097 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3100 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3103 sym
= *r
->sym_ptr_ptr
;
3104 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3105 sym
->section
->id
, sym
->value
+ r
->addend
))
3108 size
+= sizeof (asymbol
);
3109 size
+= strlen (syms
[i
]->name
) + 2;
3113 s
= *ret
= bfd_malloc (size
);
3120 names
= (char *) (s
+ count
);
3122 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3126 while (r
< opd
->relocation
+ relcount
3127 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3130 if (r
== opd
->relocation
+ relcount
)
3133 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3136 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3139 sym
= *r
->sym_ptr_ptr
;
3140 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3141 sym
->section
->id
, sym
->value
+ r
->addend
))
3146 s
->flags
|= BSF_SYNTHETIC
;
3147 s
->section
= sym
->section
;
3148 s
->value
= sym
->value
+ r
->addend
;
3151 len
= strlen (syms
[i
]->name
);
3152 memcpy (names
, syms
[i
]->name
, len
+ 1);
3154 /* Have udata.p point back to the original symbol this
3155 synthetic symbol was derived from. */
3156 s
->udata
.p
= syms
[i
];
3163 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3167 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3168 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3171 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3175 free_contents_and_exit
:
3183 for (i
= secsymend
; i
< opdsymend
; ++i
)
3187 /* Ignore bogus symbols. */
3188 if (syms
[i
]->value
> opd
->size
- 8)
3191 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3192 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3195 size
+= sizeof (asymbol
);
3196 size
+= strlen (syms
[i
]->name
) + 2;
3200 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3202 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3204 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3206 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3208 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3209 goto free_contents_and_exit
;
3211 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3212 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3215 extdynend
= extdyn
+ dynamic
->size
;
3216 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3218 Elf_Internal_Dyn dyn
;
3219 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3221 if (dyn
.d_tag
== DT_NULL
)
3224 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3226 /* The first glink stub starts at offset 32; see comment in
3227 ppc64_elf_finish_dynamic_sections. */
3228 glink_vma
= dyn
.d_un
.d_val
+ 32;
3229 /* The .glink section usually does not survive the final
3230 link; search for the section (usually .text) where the
3231 glink stubs now reside. */
3232 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3243 /* Determine __glink trampoline by reading the relative branch
3244 from the first glink stub. */
3246 if (bfd_get_section_contents (abfd
, glink
, buf
,
3247 glink_vma
+ 4 - glink
->vma
, 4))
3249 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3251 if ((insn
& ~0x3fffffc) == 0)
3252 resolv_vma
= glink_vma
+ 4 + (insn
^ 0x2000000) - 0x2000000;
3256 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3258 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3261 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3262 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3263 goto free_contents_and_exit
;
3265 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3266 size
+= plt_count
* sizeof (asymbol
);
3268 p
= relplt
->relocation
;
3269 for (i
= 0; i
< plt_count
; i
++, p
++)
3271 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3273 size
+= sizeof ("+0x") - 1 + 16;
3278 s
= *ret
= bfd_malloc (size
);
3280 goto free_contents_and_exit
;
3282 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3284 for (i
= secsymend
; i
< opdsymend
; ++i
)
3288 if (syms
[i
]->value
> opd
->size
- 8)
3291 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3292 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3296 asection
*sec
= abfd
->sections
;
3303 long mid
= (lo
+ hi
) >> 1;
3304 if (syms
[mid
]->section
->vma
< ent
)
3306 else if (syms
[mid
]->section
->vma
> ent
)
3310 sec
= syms
[mid
]->section
;
3315 if (lo
>= hi
&& lo
> codesecsym
)
3316 sec
= syms
[lo
- 1]->section
;
3318 for (; sec
!= NULL
; sec
= sec
->next
)
3322 /* SEC_LOAD may not be set if SEC is from a separate debug
3324 if ((sec
->flags
& SEC_ALLOC
) == 0)
3326 if ((sec
->flags
& SEC_CODE
) != 0)
3329 s
->flags
|= BSF_SYNTHETIC
;
3330 s
->value
= ent
- s
->section
->vma
;
3333 len
= strlen (syms
[i
]->name
);
3334 memcpy (names
, syms
[i
]->name
, len
+ 1);
3336 /* Have udata.p point back to the original symbol this
3337 synthetic symbol was derived from. */
3338 s
->udata
.p
= syms
[i
];
3344 if (glink
!= NULL
&& relplt
!= NULL
)
3348 /* Add a symbol for the main glink trampoline. */
3349 memset (s
, 0, sizeof *s
);
3351 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3353 s
->value
= resolv_vma
- glink
->vma
;
3355 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3356 names
+= sizeof ("__glink_PLTresolve");
3361 /* FIXME: It would be very much nicer to put sym@plt on the
3362 stub rather than on the glink branch table entry. The
3363 objdump disassembler would then use a sensible symbol
3364 name on plt calls. The difficulty in doing so is
3365 a) finding the stubs, and,
3366 b) matching stubs against plt entries, and,
3367 c) there can be multiple stubs for a given plt entry.
3369 Solving (a) could be done by code scanning, but older
3370 ppc64 binaries used different stubs to current code.
3371 (b) is the tricky one since you need to known the toc
3372 pointer for at least one function that uses a pic stub to
3373 be able to calculate the plt address referenced.
3374 (c) means gdb would need to set multiple breakpoints (or
3375 find the glink branch itself) when setting breakpoints
3376 for pending shared library loads. */
3377 p
= relplt
->relocation
;
3378 for (i
= 0; i
< plt_count
; i
++, p
++)
3382 *s
= **p
->sym_ptr_ptr
;
3383 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3384 we are defining a symbol, ensure one of them is set. */
3385 if ((s
->flags
& BSF_LOCAL
) == 0)
3386 s
->flags
|= BSF_GLOBAL
;
3387 s
->flags
|= BSF_SYNTHETIC
;
3389 s
->value
= glink_vma
- glink
->vma
;
3392 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3393 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3397 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3398 names
+= sizeof ("+0x") - 1;
3399 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3400 names
+= strlen (names
);
3402 memcpy (names
, "@plt", sizeof ("@plt"));
3403 names
+= sizeof ("@plt");
3418 /* The following functions are specific to the ELF linker, while
3419 functions above are used generally. Those named ppc64_elf_* are
3420 called by the main ELF linker code. They appear in this file more
3421 or less in the order in which they are called. eg.
3422 ppc64_elf_check_relocs is called early in the link process,
3423 ppc64_elf_finish_dynamic_sections is one of the last functions
3426 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3427 functions have both a function code symbol and a function descriptor
3428 symbol. A call to foo in a relocatable object file looks like:
3435 The function definition in another object file might be:
3439 . .quad .TOC.@tocbase
3445 When the linker resolves the call during a static link, the branch
3446 unsurprisingly just goes to .foo and the .opd information is unused.
3447 If the function definition is in a shared library, things are a little
3448 different: The call goes via a plt call stub, the opd information gets
3449 copied to the plt, and the linker patches the nop.
3457 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3458 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3459 . std 2,40(1) # this is the general idea
3467 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3469 The "reloc ()" notation is supposed to indicate that the linker emits
3470 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3473 What are the difficulties here? Well, firstly, the relocations
3474 examined by the linker in check_relocs are against the function code
3475 sym .foo, while the dynamic relocation in the plt is emitted against
3476 the function descriptor symbol, foo. Somewhere along the line, we need
3477 to carefully copy dynamic link information from one symbol to the other.
3478 Secondly, the generic part of the elf linker will make .foo a dynamic
3479 symbol as is normal for most other backends. We need foo dynamic
3480 instead, at least for an application final link. However, when
3481 creating a shared library containing foo, we need to have both symbols
3482 dynamic so that references to .foo are satisfied during the early
3483 stages of linking. Otherwise the linker might decide to pull in a
3484 definition from some other object, eg. a static library.
3486 Update: As of August 2004, we support a new convention. Function
3487 calls may use the function descriptor symbol, ie. "bl foo". This
3488 behaves exactly as "bl .foo". */
3490 /* The linker needs to keep track of the number of relocs that it
3491 decides to copy as dynamic relocs in check_relocs for each symbol.
3492 This is so that it can later discard them if they are found to be
3493 unnecessary. We store the information in a field extending the
3494 regular ELF linker hash table. */
3496 struct ppc_dyn_relocs
3498 struct ppc_dyn_relocs
*next
;
3500 /* The input section of the reloc. */
3503 /* Total number of relocs copied for the input section. */
3504 bfd_size_type count
;
3506 /* Number of pc-relative relocs copied for the input section. */
3507 bfd_size_type pc_count
;
3510 /* Of those relocs that might be copied as dynamic relocs, this function
3511 selects those that must be copied when linking a shared library,
3512 even when the symbol is local. */
3515 must_be_dyn_reloc (struct bfd_link_info
*info
,
3516 enum elf_ppc64_reloc_type r_type
)
3528 case R_PPC64_TPREL16
:
3529 case R_PPC64_TPREL16_LO
:
3530 case R_PPC64_TPREL16_HI
:
3531 case R_PPC64_TPREL16_HA
:
3532 case R_PPC64_TPREL16_DS
:
3533 case R_PPC64_TPREL16_LO_DS
:
3534 case R_PPC64_TPREL16_HIGHER
:
3535 case R_PPC64_TPREL16_HIGHERA
:
3536 case R_PPC64_TPREL16_HIGHEST
:
3537 case R_PPC64_TPREL16_HIGHESTA
:
3538 case R_PPC64_TPREL64
:
3539 return !info
->executable
;
3543 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3544 copying dynamic variables from a shared lib into an app's dynbss
3545 section, and instead use a dynamic relocation to point into the
3546 shared lib. With code that gcc generates, it's vital that this be
3547 enabled; In the PowerPC64 ABI, the address of a function is actually
3548 the address of a function descriptor, which resides in the .opd
3549 section. gcc uses the descriptor directly rather than going via the
3550 GOT as some other ABI's do, which means that initialized function
3551 pointers must reference the descriptor. Thus, a function pointer
3552 initialized to the address of a function in a shared library will
3553 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3554 redefines the function descriptor symbol to point to the copy. This
3555 presents a problem as a plt entry for that function is also
3556 initialized from the function descriptor symbol and the copy reloc
3557 may not be initialized first. */
3558 #define ELIMINATE_COPY_RELOCS 1
3560 /* Section name for stubs is the associated section name plus this
3562 #define STUB_SUFFIX ".stub"
3565 ppc_stub_long_branch:
3566 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3567 destination, but a 24 bit branch in a stub section will reach.
3570 ppc_stub_plt_branch:
3571 Similar to the above, but a 24 bit branch in the stub section won't
3572 reach its destination.
3573 . addis %r12,%r2,xxx@toc@ha
3574 . ld %r11,xxx@toc@l(%r12)
3579 Used to call a function in a shared library. If it so happens that
3580 the plt entry referenced crosses a 64k boundary, then an extra
3581 "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr".
3582 . addis %r12,%r2,xxx@toc@ha
3584 . ld %r11,xxx+0@toc@l(%r12)
3586 . ld %r2,xxx+8@toc@l(%r12)
3587 . ld %r11,xxx+16@toc@l(%r12)
3590 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3591 code to adjust the value and save r2 to support multiple toc sections.
3592 A ppc_stub_long_branch with an r2 offset looks like:
3594 . addis %r2,%r2,off@ha
3595 . addi %r2,%r2,off@l
3598 A ppc_stub_plt_branch with an r2 offset looks like:
3600 . addis %r12,%r2,xxx@toc@ha
3601 . ld %r11,xxx@toc@l(%r12)
3602 . addis %r2,%r2,off@ha
3603 . addi %r2,%r2,off@l
3607 In cases where the "addis" instruction would add zero, the "addis" is
3608 omitted and following instructions modified slightly in some cases.
3611 enum ppc_stub_type
{
3613 ppc_stub_long_branch
,
3614 ppc_stub_long_branch_r2off
,
3615 ppc_stub_plt_branch
,
3616 ppc_stub_plt_branch_r2off
,
3620 struct ppc_stub_hash_entry
{
3622 /* Base hash table entry structure. */
3623 struct bfd_hash_entry root
;
3625 enum ppc_stub_type stub_type
;
3627 /* The stub section. */
3630 /* Offset within stub_sec of the beginning of this stub. */
3631 bfd_vma stub_offset
;
3633 /* Given the symbol's value and its section we can determine its final
3634 value when building the stubs (so the stub knows where to jump. */
3635 bfd_vma target_value
;
3636 asection
*target_section
;
3638 /* The symbol table entry, if any, that this was derived from. */
3639 struct ppc_link_hash_entry
*h
;
3640 struct plt_entry
*plt_ent
;
3642 /* And the reloc addend that this was derived from. */
3645 /* Where this stub is being called from, or, in the case of combined
3646 stub sections, the first input section in the group. */
3650 struct ppc_branch_hash_entry
{
3652 /* Base hash table entry structure. */
3653 struct bfd_hash_entry root
;
3655 /* Offset within branch lookup table. */
3656 unsigned int offset
;
3658 /* Generation marker. */
3662 struct ppc_link_hash_entry
3664 struct elf_link_hash_entry elf
;
3667 /* A pointer to the most recently used stub hash entry against this
3669 struct ppc_stub_hash_entry
*stub_cache
;
3671 /* A pointer to the next symbol starting with a '.' */
3672 struct ppc_link_hash_entry
*next_dot_sym
;
3675 /* Track dynamic relocs copied for this symbol. */
3676 struct ppc_dyn_relocs
*dyn_relocs
;
3678 /* Link between function code and descriptor symbols. */
3679 struct ppc_link_hash_entry
*oh
;
3681 /* Flag function code and descriptor symbols. */
3682 unsigned int is_func
:1;
3683 unsigned int is_func_descriptor
:1;
3684 unsigned int fake
:1;
3686 /* Whether global opd/toc sym has been adjusted or not.
3687 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3688 should be set for all globals defined in any opd/toc section. */
3689 unsigned int adjust_done
:1;
3691 /* Set if we twiddled this symbol to weak at some stage. */
3692 unsigned int was_undefined
:1;
3694 /* Contexts in which symbol is used in the GOT (or TOC).
3695 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3696 corresponding relocs are encountered during check_relocs.
3697 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3698 indicate the corresponding GOT entry type is not needed.
3699 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3700 a TPREL one. We use a separate flag rather than setting TPREL
3701 just for convenience in distinguishing the two cases. */
3702 #define TLS_GD 1 /* GD reloc. */
3703 #define TLS_LD 2 /* LD reloc. */
3704 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3705 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3706 #define TLS_TLS 16 /* Any TLS reloc. */
3707 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3708 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3709 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3710 unsigned char tls_mask
;
3713 /* ppc64 ELF linker hash table. */
3715 struct ppc_link_hash_table
3717 struct elf_link_hash_table elf
;
3719 /* The stub hash table. */
3720 struct bfd_hash_table stub_hash_table
;
3722 /* Another hash table for plt_branch stubs. */
3723 struct bfd_hash_table branch_hash_table
;
3725 /* Linker stub bfd. */
3728 /* Linker call-backs. */
3729 asection
* (*add_stub_section
) (const char *, asection
*);
3730 void (*layout_sections_again
) (void);
3732 /* Array to keep track of which stub sections have been created, and
3733 information on stub grouping. */
3735 /* This is the section to which stubs in the group will be attached. */
3737 /* The stub section. */
3739 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3743 /* Temp used when calculating TOC pointers. */
3746 asection
*toc_first_sec
;
3748 /* Highest input section id. */
3751 /* Highest output section index. */
3754 /* Used when adding symbols. */
3755 struct ppc_link_hash_entry
*dot_syms
;
3757 /* List of input sections for each output section. */
3758 asection
**input_list
;
3760 /* Short-cuts to get to dynamic linker sections. */
3773 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3774 struct ppc_link_hash_entry
*tls_get_addr
;
3775 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3777 /* The size of reliplt used by got entry relocs. */
3778 bfd_size_type got_reli_size
;
3781 unsigned long stub_count
[ppc_stub_plt_call
];
3783 /* Number of stubs against global syms. */
3784 unsigned long stub_globals
;
3786 /* Set if we should emit symbols for stubs. */
3787 unsigned int emit_stub_syms
:1;
3789 /* Set if __tls_get_addr optimization should not be done. */
3790 unsigned int no_tls_get_addr_opt
:1;
3792 /* Support for multiple toc sections. */
3793 unsigned int do_multi_toc
:1;
3794 unsigned int multi_toc_needed
:1;
3795 unsigned int second_toc_pass
:1;
3796 unsigned int do_toc_opt
:1;
3799 unsigned int stub_error
:1;
3801 /* Temp used by ppc64_elf_process_dot_syms. */
3802 unsigned int twiddled_syms
:1;
3804 /* Incremented every time we size stubs. */
3805 unsigned int stub_iteration
;
3807 /* Small local sym cache. */
3808 struct sym_cache sym_cache
;
3811 /* Rename some of the generic section flags to better document how they
3814 /* Nonzero if this section has TLS related relocations. */
3815 #define has_tls_reloc sec_flg0
3817 /* Nonzero if this section has a call to __tls_get_addr. */
3818 #define has_tls_get_addr_call sec_flg1
3820 /* Nonzero if this section has any toc or got relocs. */
3821 #define has_toc_reloc sec_flg2
3823 /* Nonzero if this section has a call to another section that uses
3825 #define makes_toc_func_call sec_flg3
3827 /* Recursion protection when determining above flag. */
3828 #define call_check_in_progress sec_flg4
3829 #define call_check_done sec_flg5
3831 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3833 #define ppc_hash_table(p) \
3834 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3835 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3837 #define ppc_stub_hash_lookup(table, string, create, copy) \
3838 ((struct ppc_stub_hash_entry *) \
3839 bfd_hash_lookup ((table), (string), (create), (copy)))
3841 #define ppc_branch_hash_lookup(table, string, create, copy) \
3842 ((struct ppc_branch_hash_entry *) \
3843 bfd_hash_lookup ((table), (string), (create), (copy)))
3845 /* Create an entry in the stub hash table. */
3847 static struct bfd_hash_entry
*
3848 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3849 struct bfd_hash_table
*table
,
3852 /* Allocate the structure if it has not already been allocated by a
3856 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3861 /* Call the allocation method of the superclass. */
3862 entry
= bfd_hash_newfunc (entry
, table
, string
);
3865 struct ppc_stub_hash_entry
*eh
;
3867 /* Initialize the local fields. */
3868 eh
= (struct ppc_stub_hash_entry
*) entry
;
3869 eh
->stub_type
= ppc_stub_none
;
3870 eh
->stub_sec
= NULL
;
3871 eh
->stub_offset
= 0;
3872 eh
->target_value
= 0;
3873 eh
->target_section
= NULL
;
3881 /* Create an entry in the branch hash table. */
3883 static struct bfd_hash_entry
*
3884 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3885 struct bfd_hash_table
*table
,
3888 /* Allocate the structure if it has not already been allocated by a
3892 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3897 /* Call the allocation method of the superclass. */
3898 entry
= bfd_hash_newfunc (entry
, table
, string
);
3901 struct ppc_branch_hash_entry
*eh
;
3903 /* Initialize the local fields. */
3904 eh
= (struct ppc_branch_hash_entry
*) entry
;
3912 /* Create an entry in a ppc64 ELF linker hash table. */
3914 static struct bfd_hash_entry
*
3915 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3916 struct bfd_hash_table
*table
,
3919 /* Allocate the structure if it has not already been allocated by a
3923 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3928 /* Call the allocation method of the superclass. */
3929 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3932 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3934 memset (&eh
->u
.stub_cache
, 0,
3935 (sizeof (struct ppc_link_hash_entry
)
3936 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3938 /* When making function calls, old ABI code references function entry
3939 points (dot symbols), while new ABI code references the function
3940 descriptor symbol. We need to make any combination of reference and
3941 definition work together, without breaking archive linking.
3943 For a defined function "foo" and an undefined call to "bar":
3944 An old object defines "foo" and ".foo", references ".bar" (possibly
3946 A new object defines "foo" and references "bar".
3948 A new object thus has no problem with its undefined symbols being
3949 satisfied by definitions in an old object. On the other hand, the
3950 old object won't have ".bar" satisfied by a new object.
3952 Keep a list of newly added dot-symbols. */
3954 if (string
[0] == '.')
3956 struct ppc_link_hash_table
*htab
;
3958 htab
= (struct ppc_link_hash_table
*) table
;
3959 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3960 htab
->dot_syms
= eh
;
3967 /* Create a ppc64 ELF linker hash table. */
3969 static struct bfd_link_hash_table
*
3970 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3972 struct ppc_link_hash_table
*htab
;
3973 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3975 htab
= bfd_zmalloc (amt
);
3979 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3980 sizeof (struct ppc_link_hash_entry
),
3987 /* Init the stub hash table too. */
3988 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3989 sizeof (struct ppc_stub_hash_entry
)))
3992 /* And the branch hash table. */
3993 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3994 sizeof (struct ppc_branch_hash_entry
)))
3997 /* Initializing two fields of the union is just cosmetic. We really
3998 only care about glist, but when compiled on a 32-bit host the
3999 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4000 debugger inspection of these fields look nicer. */
4001 htab
->elf
.init_got_refcount
.refcount
= 0;
4002 htab
->elf
.init_got_refcount
.glist
= NULL
;
4003 htab
->elf
.init_plt_refcount
.refcount
= 0;
4004 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4005 htab
->elf
.init_got_offset
.offset
= 0;
4006 htab
->elf
.init_got_offset
.glist
= NULL
;
4007 htab
->elf
.init_plt_offset
.offset
= 0;
4008 htab
->elf
.init_plt_offset
.glist
= NULL
;
4010 return &htab
->elf
.root
;
4013 /* Free the derived linker hash table. */
4016 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
4018 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
4020 bfd_hash_table_free (&ret
->stub_hash_table
);
4021 bfd_hash_table_free (&ret
->branch_hash_table
);
4022 _bfd_generic_link_hash_table_free (hash
);
4025 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4028 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
4030 struct ppc_link_hash_table
*htab
;
4032 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4034 /* Always hook our dynamic sections into the first bfd, which is the
4035 linker created stub bfd. This ensures that the GOT header is at
4036 the start of the output TOC section. */
4037 htab
= ppc_hash_table (info
);
4040 htab
->stub_bfd
= abfd
;
4041 htab
->elf
.dynobj
= abfd
;
4044 /* Build a name for an entry in the stub hash table. */
4047 ppc_stub_name (const asection
*input_section
,
4048 const asection
*sym_sec
,
4049 const struct ppc_link_hash_entry
*h
,
4050 const Elf_Internal_Rela
*rel
)
4055 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4056 offsets from a sym as a branch target? In fact, we could
4057 probably assume the addend is always zero. */
4058 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4062 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4063 stub_name
= bfd_malloc (len
);
4064 if (stub_name
== NULL
)
4067 sprintf (stub_name
, "%08x.%s+%x",
4068 input_section
->id
& 0xffffffff,
4069 h
->elf
.root
.root
.string
,
4070 (int) rel
->r_addend
& 0xffffffff);
4074 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4075 stub_name
= bfd_malloc (len
);
4076 if (stub_name
== NULL
)
4079 sprintf (stub_name
, "%08x.%x:%x+%x",
4080 input_section
->id
& 0xffffffff,
4081 sym_sec
->id
& 0xffffffff,
4082 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4083 (int) rel
->r_addend
& 0xffffffff);
4085 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4086 stub_name
[len
- 2] = 0;
4090 /* Look up an entry in the stub hash. Stub entries are cached because
4091 creating the stub name takes a bit of time. */
4093 static struct ppc_stub_hash_entry
*
4094 ppc_get_stub_entry (const asection
*input_section
,
4095 const asection
*sym_sec
,
4096 struct ppc_link_hash_entry
*h
,
4097 const Elf_Internal_Rela
*rel
,
4098 struct ppc_link_hash_table
*htab
)
4100 struct ppc_stub_hash_entry
*stub_entry
;
4101 const asection
*id_sec
;
4103 /* If this input section is part of a group of sections sharing one
4104 stub section, then use the id of the first section in the group.
4105 Stub names need to include a section id, as there may well be
4106 more than one stub used to reach say, printf, and we need to
4107 distinguish between them. */
4108 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4110 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4111 && h
->u
.stub_cache
->h
== h
4112 && h
->u
.stub_cache
->id_sec
== id_sec
)
4114 stub_entry
= h
->u
.stub_cache
;
4120 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
4121 if (stub_name
== NULL
)
4124 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4125 stub_name
, FALSE
, FALSE
);
4127 h
->u
.stub_cache
= stub_entry
;
4135 /* Add a new stub entry to the stub hash. Not all fields of the new
4136 stub entry are initialised. */
4138 static struct ppc_stub_hash_entry
*
4139 ppc_add_stub (const char *stub_name
,
4141 struct bfd_link_info
*info
)
4143 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4146 struct ppc_stub_hash_entry
*stub_entry
;
4148 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
4149 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
4150 if (stub_sec
== NULL
)
4152 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
4153 if (stub_sec
== NULL
)
4159 namelen
= strlen (link_sec
->name
);
4160 len
= namelen
+ sizeof (STUB_SUFFIX
);
4161 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
4165 memcpy (s_name
, link_sec
->name
, namelen
);
4166 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4167 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
4168 if (stub_sec
== NULL
)
4170 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
4172 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
4175 /* Enter this entry into the linker stub hash table. */
4176 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4178 if (stub_entry
== NULL
)
4180 info
->callbacks
->einfo (_("%B: cannot create stub entry %s\n"),
4181 section
->owner
, stub_name
);
4185 stub_entry
->stub_sec
= stub_sec
;
4186 stub_entry
->stub_offset
= 0;
4187 stub_entry
->id_sec
= link_sec
;
4191 /* Create sections for linker generated code. */
4194 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4196 struct ppc_link_hash_table
*htab
;
4199 htab
= ppc_hash_table (info
);
4203 /* Create .sfpr for code to save and restore fp regs. */
4204 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4205 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4206 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4208 if (htab
->sfpr
== NULL
4209 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4212 /* Create .glink for lazy dynamic linking support. */
4213 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4215 if (htab
->glink
== NULL
4216 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4219 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4220 htab
->iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4221 if (htab
->iplt
== NULL
4222 || ! bfd_set_section_alignment (dynobj
, htab
->iplt
, 3))
4225 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4226 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4227 htab
->reliplt
= bfd_make_section_anyway_with_flags (dynobj
,
4230 if (htab
->reliplt
== NULL
4231 || ! bfd_set_section_alignment (dynobj
, htab
->reliplt
, 3))
4234 /* Create branch lookup table for plt_branch stubs. */
4235 flags
= (SEC_ALLOC
| SEC_LOAD
4236 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4237 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4239 if (htab
->brlt
== NULL
4240 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4246 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4247 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4248 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4251 if (htab
->relbrlt
== NULL
4252 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4258 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4259 not already done. */
4262 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4264 asection
*got
, *relgot
;
4266 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4268 if (!is_ppc64_elf (abfd
))
4275 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4278 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
4283 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4284 | SEC_LINKER_CREATED
);
4286 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4288 || !bfd_set_section_alignment (abfd
, got
, 3))
4291 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4292 flags
| SEC_READONLY
);
4294 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4297 ppc64_elf_tdata (abfd
)->got
= got
;
4298 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4302 /* Create the dynamic sections, and set up shortcuts. */
4305 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4307 struct ppc_link_hash_table
*htab
;
4309 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4312 htab
= ppc_hash_table (info
);
4317 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
4318 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
4319 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4320 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
4322 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
4324 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
4325 || (!info
->shared
&& !htab
->relbss
))
4331 /* Follow indirect and warning symbol links. */
4333 static inline struct bfd_link_hash_entry
*
4334 follow_link (struct bfd_link_hash_entry
*h
)
4336 while (h
->type
== bfd_link_hash_indirect
4337 || h
->type
== bfd_link_hash_warning
)
4342 static inline struct elf_link_hash_entry
*
4343 elf_follow_link (struct elf_link_hash_entry
*h
)
4345 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4348 static inline struct ppc_link_hash_entry
*
4349 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4351 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4354 /* Merge PLT info on FROM with that on TO. */
4357 move_plt_plist (struct ppc_link_hash_entry
*from
,
4358 struct ppc_link_hash_entry
*to
)
4360 if (from
->elf
.plt
.plist
!= NULL
)
4362 if (to
->elf
.plt
.plist
!= NULL
)
4364 struct plt_entry
**entp
;
4365 struct plt_entry
*ent
;
4367 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4369 struct plt_entry
*dent
;
4371 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4372 if (dent
->addend
== ent
->addend
)
4374 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4381 *entp
= to
->elf
.plt
.plist
;
4384 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4385 from
->elf
.plt
.plist
= NULL
;
4389 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4392 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4393 struct elf_link_hash_entry
*dir
,
4394 struct elf_link_hash_entry
*ind
)
4396 struct ppc_link_hash_entry
*edir
, *eind
;
4398 edir
= (struct ppc_link_hash_entry
*) dir
;
4399 eind
= (struct ppc_link_hash_entry
*) ind
;
4401 /* Copy over any dynamic relocs we may have on the indirect sym. */
4402 if (eind
->dyn_relocs
!= NULL
)
4404 if (edir
->dyn_relocs
!= NULL
)
4406 struct ppc_dyn_relocs
**pp
;
4407 struct ppc_dyn_relocs
*p
;
4409 /* Add reloc counts against the indirect sym to the direct sym
4410 list. Merge any entries against the same section. */
4411 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4413 struct ppc_dyn_relocs
*q
;
4415 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4416 if (q
->sec
== p
->sec
)
4418 q
->pc_count
+= p
->pc_count
;
4419 q
->count
+= p
->count
;
4426 *pp
= edir
->dyn_relocs
;
4429 edir
->dyn_relocs
= eind
->dyn_relocs
;
4430 eind
->dyn_relocs
= NULL
;
4433 edir
->is_func
|= eind
->is_func
;
4434 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4435 edir
->tls_mask
|= eind
->tls_mask
;
4436 if (eind
->oh
!= NULL
)
4437 edir
->oh
= ppc_follow_link (eind
->oh
);
4439 /* If called to transfer flags for a weakdef during processing
4440 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4441 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4442 if (!(ELIMINATE_COPY_RELOCS
4443 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4444 && edir
->elf
.dynamic_adjusted
))
4445 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4447 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4448 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4449 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4450 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4452 /* If we were called to copy over info for a weak sym, that's all. */
4453 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4456 /* Copy over got entries that we may have already seen to the
4457 symbol which just became indirect. */
4458 if (eind
->elf
.got
.glist
!= NULL
)
4460 if (edir
->elf
.got
.glist
!= NULL
)
4462 struct got_entry
**entp
;
4463 struct got_entry
*ent
;
4465 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4467 struct got_entry
*dent
;
4469 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4470 if (dent
->addend
== ent
->addend
4471 && dent
->owner
== ent
->owner
4472 && dent
->tls_type
== ent
->tls_type
)
4474 dent
->got
.refcount
+= ent
->got
.refcount
;
4481 *entp
= edir
->elf
.got
.glist
;
4484 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4485 eind
->elf
.got
.glist
= NULL
;
4488 /* And plt entries. */
4489 move_plt_plist (eind
, edir
);
4491 if (eind
->elf
.dynindx
!= -1)
4493 if (edir
->elf
.dynindx
!= -1)
4494 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4495 edir
->elf
.dynstr_index
);
4496 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4497 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4498 eind
->elf
.dynindx
= -1;
4499 eind
->elf
.dynstr_index
= 0;
4503 /* Find the function descriptor hash entry from the given function code
4504 hash entry FH. Link the entries via their OH fields. */
4506 static struct ppc_link_hash_entry
*
4507 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4509 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4513 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4515 fdh
= (struct ppc_link_hash_entry
*)
4516 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4520 fdh
->is_func_descriptor
= 1;
4526 return ppc_follow_link (fdh
);
4529 /* Make a fake function descriptor sym for the code sym FH. */
4531 static struct ppc_link_hash_entry
*
4532 make_fdh (struct bfd_link_info
*info
,
4533 struct ppc_link_hash_entry
*fh
)
4537 struct bfd_link_hash_entry
*bh
;
4538 struct ppc_link_hash_entry
*fdh
;
4540 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4541 newsym
= bfd_make_empty_symbol (abfd
);
4542 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4543 newsym
->section
= bfd_und_section_ptr
;
4545 newsym
->flags
= BSF_WEAK
;
4548 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4549 newsym
->flags
, newsym
->section
,
4550 newsym
->value
, NULL
, FALSE
, FALSE
,
4554 fdh
= (struct ppc_link_hash_entry
*) bh
;
4555 fdh
->elf
.non_elf
= 0;
4557 fdh
->is_func_descriptor
= 1;
4564 /* Fix function descriptor symbols defined in .opd sections to be
4568 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4569 struct bfd_link_info
*info
,
4570 Elf_Internal_Sym
*isym
,
4571 const char **name ATTRIBUTE_UNUSED
,
4572 flagword
*flags ATTRIBUTE_UNUSED
,
4574 bfd_vma
*value ATTRIBUTE_UNUSED
)
4576 if ((ibfd
->flags
& DYNAMIC
) == 0
4577 && ELF_ST_BIND (isym
->st_info
) == STB_GNU_UNIQUE
)
4578 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4580 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4582 if ((ibfd
->flags
& DYNAMIC
) == 0)
4583 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
4585 else if (ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
)
4587 else if (*sec
!= NULL
4588 && strcmp ((*sec
)->name
, ".opd") == 0)
4589 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4594 /* This function makes an old ABI object reference to ".bar" cause the
4595 inclusion of a new ABI object archive that defines "bar".
4596 NAME is a symbol defined in an archive. Return a symbol in the hash
4597 table that might be satisfied by the archive symbols. */
4599 static struct elf_link_hash_entry
*
4600 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4601 struct bfd_link_info
*info
,
4604 struct elf_link_hash_entry
*h
;
4608 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4610 /* Don't return this sym if it is a fake function descriptor
4611 created by add_symbol_adjust. */
4612 && !(h
->root
.type
== bfd_link_hash_undefweak
4613 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4619 len
= strlen (name
);
4620 dot_name
= bfd_alloc (abfd
, len
+ 2);
4621 if (dot_name
== NULL
)
4622 return (struct elf_link_hash_entry
*) 0 - 1;
4624 memcpy (dot_name
+ 1, name
, len
+ 1);
4625 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4626 bfd_release (abfd
, dot_name
);
4630 /* This function satisfies all old ABI object references to ".bar" if a
4631 new ABI object defines "bar". Well, at least, undefined dot symbols
4632 are made weak. This stops later archive searches from including an
4633 object if we already have a function descriptor definition. It also
4634 prevents the linker complaining about undefined symbols.
4635 We also check and correct mismatched symbol visibility here. The
4636 most restrictive visibility of the function descriptor and the
4637 function entry symbol is used. */
4640 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4642 struct ppc_link_hash_table
*htab
;
4643 struct ppc_link_hash_entry
*fdh
;
4645 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4648 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4649 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4651 if (eh
->elf
.root
.root
.string
[0] != '.')
4654 htab
= ppc_hash_table (info
);
4658 fdh
= lookup_fdh (eh
, htab
);
4661 if (!info
->relocatable
4662 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4663 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4664 && eh
->elf
.ref_regular
)
4666 /* Make an undefweak function descriptor sym, which is enough to
4667 pull in an --as-needed shared lib, but won't cause link
4668 errors. Archives are handled elsewhere. */
4669 fdh
= make_fdh (info
, eh
);
4672 fdh
->elf
.ref_regular
= 1;
4677 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4678 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4679 if (entry_vis
< descr_vis
)
4680 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4681 else if (entry_vis
> descr_vis
)
4682 eh
->elf
.other
+= descr_vis
- entry_vis
;
4684 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4685 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4686 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4688 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4689 eh
->was_undefined
= 1;
4690 htab
->twiddled_syms
= 1;
4697 /* Process list of dot-symbols we made in link_hash_newfunc. */
4700 ppc64_elf_process_dot_syms (bfd
*ibfd
, struct bfd_link_info
*info
)
4702 struct ppc_link_hash_table
*htab
;
4703 struct ppc_link_hash_entry
**p
, *eh
;
4705 if (!is_ppc64_elf (info
->output_bfd
))
4707 htab
= ppc_hash_table (info
);
4711 if (is_ppc64_elf (ibfd
))
4713 p
= &htab
->dot_syms
;
4714 while ((eh
= *p
) != NULL
)
4717 if (!add_symbol_adjust (eh
, info
))
4719 p
= &eh
->u
.next_dot_sym
;
4723 /* Clear the list for non-ppc64 input files. */
4724 p
= &htab
->dot_syms
;
4725 while ((eh
= *p
) != NULL
)
4728 p
= &eh
->u
.next_dot_sym
;
4731 /* We need to fix the undefs list for any syms we have twiddled to
4733 if (htab
->twiddled_syms
)
4735 bfd_link_repair_undef_list (&htab
->elf
.root
);
4736 htab
->twiddled_syms
= 0;
4741 /* Undo hash table changes when an --as-needed input file is determined
4742 not to be needed. */
4745 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4746 struct bfd_link_info
*info
)
4748 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4753 htab
->dot_syms
= NULL
;
4757 /* If --just-symbols against a final linked binary, then assume we need
4758 toc adjusting stubs when calling functions defined there. */
4761 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4763 if ((sec
->flags
& SEC_CODE
) != 0
4764 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4765 && is_ppc64_elf (sec
->owner
))
4767 asection
*got
= bfd_get_section_by_name (sec
->owner
, ".got");
4769 && got
->size
>= elf_backend_got_header_size
4770 && bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4771 sec
->has_toc_reloc
= 1;
4773 _bfd_elf_link_just_syms (sec
, info
);
4776 static struct plt_entry
**
4777 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4778 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4780 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4781 struct plt_entry
**local_plt
;
4782 unsigned char *local_got_tls_masks
;
4784 if (local_got_ents
== NULL
)
4786 bfd_size_type size
= symtab_hdr
->sh_info
;
4788 size
*= (sizeof (*local_got_ents
)
4789 + sizeof (*local_plt
)
4790 + sizeof (*local_got_tls_masks
));
4791 local_got_ents
= bfd_zalloc (abfd
, size
);
4792 if (local_got_ents
== NULL
)
4794 elf_local_got_ents (abfd
) = local_got_ents
;
4797 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
4799 struct got_entry
*ent
;
4801 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4802 if (ent
->addend
== r_addend
4803 && ent
->owner
== abfd
4804 && ent
->tls_type
== tls_type
)
4808 bfd_size_type amt
= sizeof (*ent
);
4809 ent
= bfd_alloc (abfd
, amt
);
4812 ent
->next
= local_got_ents
[r_symndx
];
4813 ent
->addend
= r_addend
;
4815 ent
->tls_type
= tls_type
;
4816 ent
->is_indirect
= FALSE
;
4817 ent
->got
.refcount
= 0;
4818 local_got_ents
[r_symndx
] = ent
;
4820 ent
->got
.refcount
+= 1;
4823 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4824 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4825 local_got_tls_masks
[r_symndx
] |= tls_type
;
4827 return local_plt
+ r_symndx
;
4831 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4833 struct plt_entry
*ent
;
4835 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4836 if (ent
->addend
== addend
)
4840 bfd_size_type amt
= sizeof (*ent
);
4841 ent
= bfd_alloc (abfd
, amt
);
4845 ent
->addend
= addend
;
4846 ent
->plt
.refcount
= 0;
4849 ent
->plt
.refcount
+= 1;
4854 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4856 return (r_type
== R_PPC64_REL24
4857 || r_type
== R_PPC64_REL14
4858 || r_type
== R_PPC64_REL14_BRTAKEN
4859 || r_type
== R_PPC64_REL14_BRNTAKEN
4860 || r_type
== R_PPC64_ADDR24
4861 || r_type
== R_PPC64_ADDR14
4862 || r_type
== R_PPC64_ADDR14_BRTAKEN
4863 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
4866 /* Look through the relocs for a section during the first phase, and
4867 calculate needed space in the global offset table, procedure
4868 linkage table, and dynamic reloc sections. */
4871 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4872 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4874 struct ppc_link_hash_table
*htab
;
4875 Elf_Internal_Shdr
*symtab_hdr
;
4876 struct elf_link_hash_entry
**sym_hashes
;
4877 const Elf_Internal_Rela
*rel
;
4878 const Elf_Internal_Rela
*rel_end
;
4880 asection
**opd_sym_map
;
4881 struct elf_link_hash_entry
*tga
, *dottga
;
4883 if (info
->relocatable
)
4886 /* Don't do anything special with non-loaded, non-alloced sections.
4887 In particular, any relocs in such sections should not affect GOT
4888 and PLT reference counting (ie. we don't allow them to create GOT
4889 or PLT entries), there's no possibility or desire to optimize TLS
4890 relocs, and there's not much point in propagating relocs to shared
4891 libs that the dynamic linker won't relocate. */
4892 if ((sec
->flags
& SEC_ALLOC
) == 0)
4895 BFD_ASSERT (is_ppc64_elf (abfd
));
4897 htab
= ppc_hash_table (info
);
4901 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4902 FALSE
, FALSE
, TRUE
);
4903 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4904 FALSE
, FALSE
, TRUE
);
4905 symtab_hdr
= &elf_symtab_hdr (abfd
);
4906 sym_hashes
= elf_sym_hashes (abfd
);
4909 if (strcmp (sec
->name
, ".opd") == 0)
4911 /* Garbage collection needs some extra help with .opd sections.
4912 We don't want to necessarily keep everything referenced by
4913 relocs in .opd, as that would keep all functions. Instead,
4914 if we reference an .opd symbol (a function descriptor), we
4915 want to keep the function code symbol's section. This is
4916 easy for global symbols, but for local syms we need to keep
4917 information about the associated function section. */
4920 amt
= sec
->size
* sizeof (*opd_sym_map
) / 8;
4921 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4922 if (opd_sym_map
== NULL
)
4924 ppc64_elf_section_data (sec
)->u
.opd
.func_sec
= opd_sym_map
;
4925 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4926 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4929 if (htab
->sfpr
== NULL
4930 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4933 rel_end
= relocs
+ sec
->reloc_count
;
4934 for (rel
= relocs
; rel
< rel_end
; rel
++)
4936 unsigned long r_symndx
;
4937 struct elf_link_hash_entry
*h
;
4938 enum elf_ppc64_reloc_type r_type
;
4940 struct _ppc64_elf_section_data
*ppc64_sec
;
4941 struct plt_entry
**ifunc
;
4943 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4944 if (r_symndx
< symtab_hdr
->sh_info
)
4948 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4949 h
= elf_follow_link (h
);
4956 if (h
->type
== STT_GNU_IFUNC
)
4959 ifunc
= &h
->plt
.plist
;
4964 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4969 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4971 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4972 rel
->r_addend
, PLT_IFUNC
);
4977 r_type
= ELF64_R_TYPE (rel
->r_info
);
4978 if (is_branch_reloc (r_type
))
4980 if (h
!= NULL
&& (h
== tga
|| h
== dottga
))
4983 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4984 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4985 /* We have a new-style __tls_get_addr call with a marker
4989 /* Mark this section as having an old-style call. */
4990 sec
->has_tls_get_addr_call
= 1;
4993 /* STT_GNU_IFUNC symbols must have a PLT entry. */
4995 && !update_plt_info (abfd
, ifunc
, rel
->r_addend
))
5003 /* These special tls relocs tie a call to __tls_get_addr with
5004 its parameter symbol. */
5007 case R_PPC64_GOT_TLSLD16
:
5008 case R_PPC64_GOT_TLSLD16_LO
:
5009 case R_PPC64_GOT_TLSLD16_HI
:
5010 case R_PPC64_GOT_TLSLD16_HA
:
5011 tls_type
= TLS_TLS
| TLS_LD
;
5014 case R_PPC64_GOT_TLSGD16
:
5015 case R_PPC64_GOT_TLSGD16_LO
:
5016 case R_PPC64_GOT_TLSGD16_HI
:
5017 case R_PPC64_GOT_TLSGD16_HA
:
5018 tls_type
= TLS_TLS
| TLS_GD
;
5021 case R_PPC64_GOT_TPREL16_DS
:
5022 case R_PPC64_GOT_TPREL16_LO_DS
:
5023 case R_PPC64_GOT_TPREL16_HI
:
5024 case R_PPC64_GOT_TPREL16_HA
:
5025 if (!info
->executable
)
5026 info
->flags
|= DF_STATIC_TLS
;
5027 tls_type
= TLS_TLS
| TLS_TPREL
;
5030 case R_PPC64_GOT_DTPREL16_DS
:
5031 case R_PPC64_GOT_DTPREL16_LO_DS
:
5032 case R_PPC64_GOT_DTPREL16_HI
:
5033 case R_PPC64_GOT_DTPREL16_HA
:
5034 tls_type
= TLS_TLS
| TLS_DTPREL
;
5036 sec
->has_tls_reloc
= 1;
5040 case R_PPC64_GOT16_DS
:
5041 case R_PPC64_GOT16_HA
:
5042 case R_PPC64_GOT16_HI
:
5043 case R_PPC64_GOT16_LO
:
5044 case R_PPC64_GOT16_LO_DS
:
5045 /* This symbol requires a global offset table entry. */
5046 sec
->has_toc_reloc
= 1;
5047 if (r_type
== R_PPC64_GOT_TLSLD16
5048 || r_type
== R_PPC64_GOT_TLSGD16
5049 || r_type
== R_PPC64_GOT_TPREL16_DS
5050 || r_type
== R_PPC64_GOT_DTPREL16_DS
5051 || r_type
== R_PPC64_GOT16
5052 || r_type
== R_PPC64_GOT16_DS
)
5054 htab
->do_multi_toc
= 1;
5055 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5058 if (ppc64_elf_tdata (abfd
)->got
== NULL
5059 && !create_got_section (abfd
, info
))
5064 struct ppc_link_hash_entry
*eh
;
5065 struct got_entry
*ent
;
5067 eh
= (struct ppc_link_hash_entry
*) h
;
5068 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5069 if (ent
->addend
== rel
->r_addend
5070 && ent
->owner
== abfd
5071 && ent
->tls_type
== tls_type
)
5075 bfd_size_type amt
= sizeof (*ent
);
5076 ent
= bfd_alloc (abfd
, amt
);
5079 ent
->next
= eh
->elf
.got
.glist
;
5080 ent
->addend
= rel
->r_addend
;
5082 ent
->tls_type
= tls_type
;
5083 ent
->is_indirect
= FALSE
;
5084 ent
->got
.refcount
= 0;
5085 eh
->elf
.got
.glist
= ent
;
5087 ent
->got
.refcount
+= 1;
5088 eh
->tls_mask
|= tls_type
;
5091 /* This is a global offset table entry for a local symbol. */
5092 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5093 rel
->r_addend
, tls_type
))
5097 case R_PPC64_PLT16_HA
:
5098 case R_PPC64_PLT16_HI
:
5099 case R_PPC64_PLT16_LO
:
5102 /* This symbol requires a procedure linkage table entry. We
5103 actually build the entry in adjust_dynamic_symbol,
5104 because this might be a case of linking PIC code without
5105 linking in any dynamic objects, in which case we don't
5106 need to generate a procedure linkage table after all. */
5109 /* It does not make sense to have a procedure linkage
5110 table entry for a local symbol. */
5111 bfd_set_error (bfd_error_bad_value
);
5116 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5119 if (h
->root
.root
.string
[0] == '.'
5120 && h
->root
.root
.string
[1] != '\0')
5121 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5125 /* The following relocations don't need to propagate the
5126 relocation if linking a shared object since they are
5127 section relative. */
5128 case R_PPC64_SECTOFF
:
5129 case R_PPC64_SECTOFF_LO
:
5130 case R_PPC64_SECTOFF_HI
:
5131 case R_PPC64_SECTOFF_HA
:
5132 case R_PPC64_SECTOFF_DS
:
5133 case R_PPC64_SECTOFF_LO_DS
:
5134 case R_PPC64_DTPREL16
:
5135 case R_PPC64_DTPREL16_LO
:
5136 case R_PPC64_DTPREL16_HI
:
5137 case R_PPC64_DTPREL16_HA
:
5138 case R_PPC64_DTPREL16_DS
:
5139 case R_PPC64_DTPREL16_LO_DS
:
5140 case R_PPC64_DTPREL16_HIGHER
:
5141 case R_PPC64_DTPREL16_HIGHERA
:
5142 case R_PPC64_DTPREL16_HIGHEST
:
5143 case R_PPC64_DTPREL16_HIGHESTA
:
5148 case R_PPC64_REL16_LO
:
5149 case R_PPC64_REL16_HI
:
5150 case R_PPC64_REL16_HA
:
5154 case R_PPC64_TOC16_DS
:
5155 htab
->do_multi_toc
= 1;
5156 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5157 case R_PPC64_TOC16_LO
:
5158 case R_PPC64_TOC16_HI
:
5159 case R_PPC64_TOC16_HA
:
5160 case R_PPC64_TOC16_LO_DS
:
5161 sec
->has_toc_reloc
= 1;
5164 /* This relocation describes the C++ object vtable hierarchy.
5165 Reconstruct it for later use during GC. */
5166 case R_PPC64_GNU_VTINHERIT
:
5167 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5171 /* This relocation describes which C++ vtable entries are actually
5172 used. Record for later use during GC. */
5173 case R_PPC64_GNU_VTENTRY
:
5174 BFD_ASSERT (h
!= NULL
);
5176 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5181 case R_PPC64_REL14_BRTAKEN
:
5182 case R_PPC64_REL14_BRNTAKEN
:
5184 asection
*dest
= NULL
;
5186 /* Heuristic: If jumping outside our section, chances are
5187 we are going to need a stub. */
5190 /* If the sym is weak it may be overridden later, so
5191 don't assume we know where a weak sym lives. */
5192 if (h
->root
.type
== bfd_link_hash_defined
)
5193 dest
= h
->root
.u
.def
.section
;
5197 Elf_Internal_Sym
*isym
;
5199 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5204 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5208 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5213 if (h
!= NULL
&& ifunc
== NULL
)
5215 /* We may need a .plt entry if the function this reloc
5216 refers to is in a shared lib. */
5217 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5220 if (h
->root
.root
.string
[0] == '.'
5221 && h
->root
.root
.string
[1] != '\0')
5222 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5223 if (h
== tga
|| h
== dottga
)
5224 sec
->has_tls_reloc
= 1;
5228 case R_PPC64_TPREL64
:
5229 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5230 if (!info
->executable
)
5231 info
->flags
|= DF_STATIC_TLS
;
5234 case R_PPC64_DTPMOD64
:
5235 if (rel
+ 1 < rel_end
5236 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5237 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5238 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5240 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5243 case R_PPC64_DTPREL64
:
5244 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5246 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5247 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5248 /* This is the second reloc of a dtpmod, dtprel pair.
5249 Don't mark with TLS_DTPREL. */
5253 sec
->has_tls_reloc
= 1;
5256 struct ppc_link_hash_entry
*eh
;
5257 eh
= (struct ppc_link_hash_entry
*) h
;
5258 eh
->tls_mask
|= tls_type
;
5261 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5262 rel
->r_addend
, tls_type
))
5265 ppc64_sec
= ppc64_elf_section_data (sec
);
5266 if (ppc64_sec
->sec_type
!= sec_toc
)
5270 /* One extra to simplify get_tls_mask. */
5271 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5272 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5273 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5275 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5276 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5277 if (ppc64_sec
->u
.toc
.add
== NULL
)
5279 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5280 ppc64_sec
->sec_type
= sec_toc
;
5282 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5283 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5284 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5286 /* Mark the second slot of a GD or LD entry.
5287 -1 to indicate GD and -2 to indicate LD. */
5288 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5289 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5290 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5291 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5294 case R_PPC64_TPREL16
:
5295 case R_PPC64_TPREL16_LO
:
5296 case R_PPC64_TPREL16_HI
:
5297 case R_PPC64_TPREL16_HA
:
5298 case R_PPC64_TPREL16_DS
:
5299 case R_PPC64_TPREL16_LO_DS
:
5300 case R_PPC64_TPREL16_HIGHER
:
5301 case R_PPC64_TPREL16_HIGHERA
:
5302 case R_PPC64_TPREL16_HIGHEST
:
5303 case R_PPC64_TPREL16_HIGHESTA
:
5306 if (!info
->executable
)
5307 info
->flags
|= DF_STATIC_TLS
;
5312 case R_PPC64_ADDR64
:
5313 if (opd_sym_map
!= NULL
5314 && rel
+ 1 < rel_end
5315 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5319 if (h
->root
.root
.string
[0] == '.'
5320 && h
->root
.root
.string
[1] != 0
5321 && lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
5324 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5329 Elf_Internal_Sym
*isym
;
5331 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5336 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5337 if (s
!= NULL
&& s
!= sec
)
5338 opd_sym_map
[rel
->r_offset
/ 8] = s
;
5346 case R_PPC64_ADDR14
:
5347 case R_PPC64_ADDR14_BRNTAKEN
:
5348 case R_PPC64_ADDR14_BRTAKEN
:
5349 case R_PPC64_ADDR16
:
5350 case R_PPC64_ADDR16_DS
:
5351 case R_PPC64_ADDR16_HA
:
5352 case R_PPC64_ADDR16_HI
:
5353 case R_PPC64_ADDR16_HIGHER
:
5354 case R_PPC64_ADDR16_HIGHERA
:
5355 case R_PPC64_ADDR16_HIGHEST
:
5356 case R_PPC64_ADDR16_HIGHESTA
:
5357 case R_PPC64_ADDR16_LO
:
5358 case R_PPC64_ADDR16_LO_DS
:
5359 case R_PPC64_ADDR24
:
5360 case R_PPC64_ADDR32
:
5361 case R_PPC64_UADDR16
:
5362 case R_PPC64_UADDR32
:
5363 case R_PPC64_UADDR64
:
5365 if (h
!= NULL
&& !info
->shared
)
5366 /* We may need a copy reloc. */
5369 /* Don't propagate .opd relocs. */
5370 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5373 /* If we are creating a shared library, and this is a reloc
5374 against a global symbol, or a non PC relative reloc
5375 against a local symbol, then we need to copy the reloc
5376 into the shared library. However, if we are linking with
5377 -Bsymbolic, we do not need to copy a reloc against a
5378 global symbol which is defined in an object we are
5379 including in the link (i.e., DEF_REGULAR is set). At
5380 this point we have not seen all the input files, so it is
5381 possible that DEF_REGULAR is not set now but will be set
5382 later (it is never cleared). In case of a weak definition,
5383 DEF_REGULAR may be cleared later by a strong definition in
5384 a shared library. We account for that possibility below by
5385 storing information in the dyn_relocs field of the hash
5386 table entry. A similar situation occurs when creating
5387 shared libraries and symbol visibility changes render the
5390 If on the other hand, we are creating an executable, we
5391 may need to keep relocations for symbols satisfied by a
5392 dynamic library if we manage to avoid copy relocs for the
5396 && (must_be_dyn_reloc (info
, r_type
)
5398 && (! info
->symbolic
5399 || h
->root
.type
== bfd_link_hash_defweak
5400 || !h
->def_regular
))))
5401 || (ELIMINATE_COPY_RELOCS
5404 && (h
->root
.type
== bfd_link_hash_defweak
5405 || !h
->def_regular
))
5409 struct ppc_dyn_relocs
*p
;
5410 struct ppc_dyn_relocs
**head
;
5412 /* We must copy these reloc types into the output file.
5413 Create a reloc section in dynobj and make room for
5417 sreloc
= _bfd_elf_make_dynamic_reloc_section
5418 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5424 /* If this is a global symbol, we count the number of
5425 relocations we need for this symbol. */
5428 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5432 /* Track dynamic relocs needed for local syms too.
5433 We really need local syms available to do this
5437 Elf_Internal_Sym
*isym
;
5439 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5444 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5448 vpp
= &elf_section_data (s
)->local_dynrel
;
5449 head
= (struct ppc_dyn_relocs
**) vpp
;
5453 if (p
== NULL
|| p
->sec
!= sec
)
5455 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5466 if (!must_be_dyn_reloc (info
, r_type
))
5479 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5480 of the code entry point, and its section. */
5483 opd_entry_value (asection
*opd_sec
,
5485 asection
**code_sec
,
5488 bfd
*opd_bfd
= opd_sec
->owner
;
5489 Elf_Internal_Rela
*relocs
;
5490 Elf_Internal_Rela
*lo
, *hi
, *look
;
5493 /* No relocs implies we are linking a --just-symbols object. */
5494 if (opd_sec
->reloc_count
== 0)
5498 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, buf
, offset
, 8))
5499 return (bfd_vma
) -1;
5501 val
= bfd_get_64 (opd_bfd
, buf
);
5502 if (code_sec
!= NULL
)
5504 asection
*sec
, *likely
= NULL
;
5505 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5507 && (sec
->flags
& SEC_LOAD
) != 0
5508 && (sec
->flags
& SEC_ALLOC
) != 0)
5513 if (code_off
!= NULL
)
5514 *code_off
= val
- likely
->vma
;
5520 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5522 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
5524 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5526 /* Go find the opd reloc at the sym address. */
5528 BFD_ASSERT (lo
!= NULL
);
5529 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5533 look
= lo
+ (hi
- lo
) / 2;
5534 if (look
->r_offset
< offset
)
5536 else if (look
->r_offset
> offset
)
5540 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5542 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5543 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5545 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5548 if (symndx
< symtab_hdr
->sh_info
)
5550 Elf_Internal_Sym
*sym
;
5552 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5555 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5556 symtab_hdr
->sh_info
,
5557 0, NULL
, NULL
, NULL
);
5560 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5564 val
= sym
->st_value
;
5565 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5566 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5570 struct elf_link_hash_entry
**sym_hashes
;
5571 struct elf_link_hash_entry
*rh
;
5573 sym_hashes
= elf_sym_hashes (opd_bfd
);
5574 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5575 rh
= elf_follow_link (rh
);
5576 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5577 || rh
->root
.type
== bfd_link_hash_defweak
);
5578 val
= rh
->root
.u
.def
.value
;
5579 sec
= rh
->root
.u
.def
.section
;
5581 val
+= look
->r_addend
;
5582 if (code_off
!= NULL
)
5584 if (code_sec
!= NULL
)
5586 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5587 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5596 /* Return true if symbol is defined in a regular object file. */
5599 is_static_defined (struct elf_link_hash_entry
*h
)
5601 return ((h
->root
.type
== bfd_link_hash_defined
5602 || h
->root
.type
== bfd_link_hash_defweak
)
5603 && h
->root
.u
.def
.section
!= NULL
5604 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5607 /* If FDH is a function descriptor symbol, return the associated code
5608 entry symbol if it is defined. Return NULL otherwise. */
5610 static struct ppc_link_hash_entry
*
5611 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5613 if (fdh
->is_func_descriptor
)
5615 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5616 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5617 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5623 /* If FH is a function code entry symbol, return the associated
5624 function descriptor symbol if it is defined. Return NULL otherwise. */
5626 static struct ppc_link_hash_entry
*
5627 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5630 && fh
->oh
->is_func_descriptor
)
5632 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5633 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5634 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5640 /* Mark all our entry sym sections, both opd and code section. */
5643 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5645 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5646 struct bfd_sym_chain
*sym
;
5651 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5653 struct ppc_link_hash_entry
*eh
, *fh
;
5656 eh
= (struct ppc_link_hash_entry
*)
5657 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5660 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5661 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5664 fh
= defined_code_entry (eh
);
5667 sec
= fh
->elf
.root
.u
.def
.section
;
5668 sec
->flags
|= SEC_KEEP
;
5670 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5671 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5672 eh
->elf
.root
.u
.def
.value
,
5673 &sec
, NULL
) != (bfd_vma
) -1)
5674 sec
->flags
|= SEC_KEEP
;
5676 sec
= eh
->elf
.root
.u
.def
.section
;
5677 sec
->flags
|= SEC_KEEP
;
5681 /* Mark sections containing dynamically referenced symbols. When
5682 building shared libraries, we must assume that any visible symbol is
5686 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5688 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5689 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5690 struct ppc_link_hash_entry
*fdh
;
5692 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5693 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5695 /* Dynamic linking info is on the func descriptor sym. */
5696 fdh
= defined_func_desc (eh
);
5700 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5701 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5702 && (eh
->elf
.ref_dynamic
5703 || (!info
->executable
5704 && eh
->elf
.def_regular
5705 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5706 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5709 struct ppc_link_hash_entry
*fh
;
5711 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5713 /* Function descriptor syms cause the associated
5714 function code sym section to be marked. */
5715 fh
= defined_code_entry (eh
);
5718 code_sec
= fh
->elf
.root
.u
.def
.section
;
5719 code_sec
->flags
|= SEC_KEEP
;
5721 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5722 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5723 eh
->elf
.root
.u
.def
.value
,
5724 &code_sec
, NULL
) != (bfd_vma
) -1)
5725 code_sec
->flags
|= SEC_KEEP
;
5731 /* Return the section that should be marked against GC for a given
5735 ppc64_elf_gc_mark_hook (asection
*sec
,
5736 struct bfd_link_info
*info
,
5737 Elf_Internal_Rela
*rel
,
5738 struct elf_link_hash_entry
*h
,
5739 Elf_Internal_Sym
*sym
)
5743 /* Syms return NULL if we're marking .opd, so we avoid marking all
5744 function sections, as all functions are referenced in .opd. */
5746 if (get_opd_info (sec
) != NULL
)
5751 enum elf_ppc64_reloc_type r_type
;
5752 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5754 r_type
= ELF64_R_TYPE (rel
->r_info
);
5757 case R_PPC64_GNU_VTINHERIT
:
5758 case R_PPC64_GNU_VTENTRY
:
5762 switch (h
->root
.type
)
5764 case bfd_link_hash_defined
:
5765 case bfd_link_hash_defweak
:
5766 eh
= (struct ppc_link_hash_entry
*) h
;
5767 fdh
= defined_func_desc (eh
);
5771 /* Function descriptor syms cause the associated
5772 function code sym section to be marked. */
5773 fh
= defined_code_entry (eh
);
5776 /* They also mark their opd section. */
5777 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5779 rsec
= fh
->elf
.root
.u
.def
.section
;
5781 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5782 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5783 eh
->elf
.root
.u
.def
.value
,
5784 &rsec
, NULL
) != (bfd_vma
) -1)
5785 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5787 rsec
= h
->root
.u
.def
.section
;
5790 case bfd_link_hash_common
:
5791 rsec
= h
->root
.u
.c
.p
->section
;
5795 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5801 struct _opd_sec_data
*opd
;
5803 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5804 opd
= get_opd_info (rsec
);
5805 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5809 rsec
= opd
->func_sec
[(sym
->st_value
+ rel
->r_addend
) / 8];
5816 /* Update the .got, .plt. and dynamic reloc reference counts for the
5817 section being removed. */
5820 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5821 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5823 struct ppc_link_hash_table
*htab
;
5824 Elf_Internal_Shdr
*symtab_hdr
;
5825 struct elf_link_hash_entry
**sym_hashes
;
5826 struct got_entry
**local_got_ents
;
5827 const Elf_Internal_Rela
*rel
, *relend
;
5829 if (info
->relocatable
)
5832 if ((sec
->flags
& SEC_ALLOC
) == 0)
5835 elf_section_data (sec
)->local_dynrel
= NULL
;
5837 htab
= ppc_hash_table (info
);
5841 symtab_hdr
= &elf_symtab_hdr (abfd
);
5842 sym_hashes
= elf_sym_hashes (abfd
);
5843 local_got_ents
= elf_local_got_ents (abfd
);
5845 relend
= relocs
+ sec
->reloc_count
;
5846 for (rel
= relocs
; rel
< relend
; rel
++)
5848 unsigned long r_symndx
;
5849 enum elf_ppc64_reloc_type r_type
;
5850 struct elf_link_hash_entry
*h
= NULL
;
5851 unsigned char tls_type
= 0;
5853 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5854 r_type
= ELF64_R_TYPE (rel
->r_info
);
5855 if (r_symndx
>= symtab_hdr
->sh_info
)
5857 struct ppc_link_hash_entry
*eh
;
5858 struct ppc_dyn_relocs
**pp
;
5859 struct ppc_dyn_relocs
*p
;
5861 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5862 h
= elf_follow_link (h
);
5863 eh
= (struct ppc_link_hash_entry
*) h
;
5865 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5868 /* Everything must go for SEC. */
5874 if (is_branch_reloc (r_type
))
5876 struct plt_entry
**ifunc
= NULL
;
5879 if (h
->type
== STT_GNU_IFUNC
)
5880 ifunc
= &h
->plt
.plist
;
5882 else if (local_got_ents
!= NULL
)
5884 struct plt_entry
**local_plt
= (struct plt_entry
**)
5885 (local_got_ents
+ symtab_hdr
->sh_info
);
5886 unsigned char *local_got_tls_masks
= (unsigned char *)
5887 (local_plt
+ symtab_hdr
->sh_info
);
5888 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
5889 ifunc
= local_plt
+ r_symndx
;
5893 struct plt_entry
*ent
;
5895 for (ent
= *ifunc
; ent
!= NULL
; ent
= ent
->next
)
5896 if (ent
->addend
== rel
->r_addend
)
5900 if (ent
->plt
.refcount
> 0)
5901 ent
->plt
.refcount
-= 1;
5908 case R_PPC64_GOT_TLSLD16
:
5909 case R_PPC64_GOT_TLSLD16_LO
:
5910 case R_PPC64_GOT_TLSLD16_HI
:
5911 case R_PPC64_GOT_TLSLD16_HA
:
5912 tls_type
= TLS_TLS
| TLS_LD
;
5915 case R_PPC64_GOT_TLSGD16
:
5916 case R_PPC64_GOT_TLSGD16_LO
:
5917 case R_PPC64_GOT_TLSGD16_HI
:
5918 case R_PPC64_GOT_TLSGD16_HA
:
5919 tls_type
= TLS_TLS
| TLS_GD
;
5922 case R_PPC64_GOT_TPREL16_DS
:
5923 case R_PPC64_GOT_TPREL16_LO_DS
:
5924 case R_PPC64_GOT_TPREL16_HI
:
5925 case R_PPC64_GOT_TPREL16_HA
:
5926 tls_type
= TLS_TLS
| TLS_TPREL
;
5929 case R_PPC64_GOT_DTPREL16_DS
:
5930 case R_PPC64_GOT_DTPREL16_LO_DS
:
5931 case R_PPC64_GOT_DTPREL16_HI
:
5932 case R_PPC64_GOT_DTPREL16_HA
:
5933 tls_type
= TLS_TLS
| TLS_DTPREL
;
5937 case R_PPC64_GOT16_DS
:
5938 case R_PPC64_GOT16_HA
:
5939 case R_PPC64_GOT16_HI
:
5940 case R_PPC64_GOT16_LO
:
5941 case R_PPC64_GOT16_LO_DS
:
5944 struct got_entry
*ent
;
5949 ent
= local_got_ents
[r_symndx
];
5951 for (; ent
!= NULL
; ent
= ent
->next
)
5952 if (ent
->addend
== rel
->r_addend
5953 && ent
->owner
== abfd
5954 && ent
->tls_type
== tls_type
)
5958 if (ent
->got
.refcount
> 0)
5959 ent
->got
.refcount
-= 1;
5963 case R_PPC64_PLT16_HA
:
5964 case R_PPC64_PLT16_HI
:
5965 case R_PPC64_PLT16_LO
:
5969 case R_PPC64_REL14_BRNTAKEN
:
5970 case R_PPC64_REL14_BRTAKEN
:
5974 struct plt_entry
*ent
;
5976 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5977 if (ent
->addend
== rel
->r_addend
)
5979 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
5980 ent
->plt
.refcount
-= 1;
5991 /* The maximum size of .sfpr. */
5992 #define SFPR_MAX (218*4)
5994 struct sfpr_def_parms
5996 const char name
[12];
5997 unsigned char lo
, hi
;
5998 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5999 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6002 /* Auto-generate _save*, _rest* functions in .sfpr. */
6005 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
6007 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6009 size_t len
= strlen (parm
->name
);
6010 bfd_boolean writing
= FALSE
;
6016 memcpy (sym
, parm
->name
, len
);
6019 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6021 struct elf_link_hash_entry
*h
;
6023 sym
[len
+ 0] = i
/ 10 + '0';
6024 sym
[len
+ 1] = i
% 10 + '0';
6025 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
6029 h
->root
.type
= bfd_link_hash_defined
;
6030 h
->root
.u
.def
.section
= htab
->sfpr
;
6031 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
6034 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
6036 if (htab
->sfpr
->contents
== NULL
)
6038 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6039 if (htab
->sfpr
->contents
== NULL
)
6045 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6047 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6049 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6050 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6058 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6060 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6065 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6067 p
= savegpr0 (abfd
, p
, r
);
6068 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6070 bfd_put_32 (abfd
, BLR
, p
);
6075 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6077 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6082 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6084 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6086 p
= restgpr0 (abfd
, p
, r
);
6087 bfd_put_32 (abfd
, MTLR_R0
, p
);
6091 p
= restgpr0 (abfd
, p
, 30);
6092 p
= restgpr0 (abfd
, p
, 31);
6094 bfd_put_32 (abfd
, BLR
, p
);
6099 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6101 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6106 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6108 p
= savegpr1 (abfd
, p
, r
);
6109 bfd_put_32 (abfd
, BLR
, p
);
6114 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6116 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6121 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6123 p
= restgpr1 (abfd
, p
, r
);
6124 bfd_put_32 (abfd
, BLR
, p
);
6129 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6131 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6136 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6138 p
= savefpr (abfd
, p
, r
);
6139 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
6141 bfd_put_32 (abfd
, BLR
, p
);
6146 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6148 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6153 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6155 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
6157 p
= restfpr (abfd
, p
, r
);
6158 bfd_put_32 (abfd
, MTLR_R0
, p
);
6162 p
= restfpr (abfd
, p
, 30);
6163 p
= restfpr (abfd
, p
, 31);
6165 bfd_put_32 (abfd
, BLR
, p
);
6170 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6172 p
= savefpr (abfd
, p
, r
);
6173 bfd_put_32 (abfd
, BLR
, p
);
6178 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6180 p
= restfpr (abfd
, p
, r
);
6181 bfd_put_32 (abfd
, BLR
, p
);
6186 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6188 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6190 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6195 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6197 p
= savevr (abfd
, p
, r
);
6198 bfd_put_32 (abfd
, BLR
, p
);
6203 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6205 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6207 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6212 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6214 p
= restvr (abfd
, p
, r
);
6215 bfd_put_32 (abfd
, BLR
, p
);
6219 /* Called via elf_link_hash_traverse to transfer dynamic linking
6220 information on function code symbol entries to their corresponding
6221 function descriptor symbol entries. */
6224 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6226 struct bfd_link_info
*info
;
6227 struct ppc_link_hash_table
*htab
;
6228 struct plt_entry
*ent
;
6229 struct ppc_link_hash_entry
*fh
;
6230 struct ppc_link_hash_entry
*fdh
;
6231 bfd_boolean force_local
;
6233 fh
= (struct ppc_link_hash_entry
*) h
;
6234 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6237 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
6238 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
6241 htab
= ppc_hash_table (info
);
6245 /* Resolve undefined references to dot-symbols as the value
6246 in the function descriptor, if we have one in a regular object.
6247 This is to satisfy cases like ".quad .foo". Calls to functions
6248 in dynamic objects are handled elsewhere. */
6249 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
6250 && fh
->was_undefined
6251 && (fdh
= defined_func_desc (fh
)) != NULL
6252 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6253 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6254 fdh
->elf
.root
.u
.def
.value
,
6255 &fh
->elf
.root
.u
.def
.section
,
6256 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
6258 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6259 fh
->elf
.forced_local
= 1;
6260 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6261 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6264 /* If this is a function code symbol, transfer dynamic linking
6265 information to the function descriptor symbol. */
6269 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6270 if (ent
->plt
.refcount
> 0)
6273 || fh
->elf
.root
.root
.string
[0] != '.'
6274 || fh
->elf
.root
.root
.string
[1] == '\0')
6277 /* Find the corresponding function descriptor symbol. Create it
6278 as undefined if necessary. */
6280 fdh
= lookup_fdh (fh
, htab
);
6282 && !info
->executable
6283 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6284 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6286 fdh
= make_fdh (info
, fh
);
6291 /* Fake function descriptors are made undefweak. If the function
6292 code symbol is strong undefined, make the fake sym the same.
6293 If the function code symbol is defined, then force the fake
6294 descriptor local; We can't support overriding of symbols in a
6295 shared library on a fake descriptor. */
6299 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6301 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
6303 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
6304 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
6306 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
6307 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6309 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6314 && !fdh
->elf
.forced_local
6315 && (!info
->executable
6316 || fdh
->elf
.def_dynamic
6317 || fdh
->elf
.ref_dynamic
6318 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
6319 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
6321 if (fdh
->elf
.dynindx
== -1)
6322 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6324 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6325 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6326 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6327 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6328 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
6330 move_plt_plist (fh
, fdh
);
6331 fdh
->elf
.needs_plt
= 1;
6333 fdh
->is_func_descriptor
= 1;
6338 /* Now that the info is on the function descriptor, clear the
6339 function code sym info. Any function code syms for which we
6340 don't have a definition in a regular file, we force local.
6341 This prevents a shared library from exporting syms that have
6342 been imported from another library. Function code syms that
6343 are really in the library we must leave global to prevent the
6344 linker dragging in a definition from a static library. */
6345 force_local
= (!fh
->elf
.def_regular
6347 || !fdh
->elf
.def_regular
6348 || fdh
->elf
.forced_local
);
6349 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6354 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6355 this hook to a) provide some gcc support functions, and b) transfer
6356 dynamic linking information gathered so far on function code symbol
6357 entries, to their corresponding function descriptor symbol entries. */
6360 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6361 struct bfd_link_info
*info
)
6363 struct ppc_link_hash_table
*htab
;
6365 const struct sfpr_def_parms funcs
[] =
6367 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6368 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6369 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6370 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6371 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6372 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6373 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6374 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6375 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6376 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6377 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6378 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6381 htab
= ppc_hash_table (info
);
6385 if (htab
->sfpr
== NULL
)
6386 /* We don't have any relocs. */
6389 /* Provide any missing _save* and _rest* functions. */
6390 htab
->sfpr
->size
= 0;
6391 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
6392 if (!sfpr_define (info
, &funcs
[i
]))
6395 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6397 if (htab
->sfpr
->size
== 0)
6398 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6403 /* Adjust a symbol defined by a dynamic object and referenced by a
6404 regular object. The current definition is in some section of the
6405 dynamic object, but we're not including those sections. We have to
6406 change the definition to something the rest of the link can
6410 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6411 struct elf_link_hash_entry
*h
)
6413 struct ppc_link_hash_table
*htab
;
6416 htab
= ppc_hash_table (info
);
6420 /* Deal with function syms. */
6421 if (h
->type
== STT_FUNC
6422 || h
->type
== STT_GNU_IFUNC
6425 /* Clear procedure linkage table information for any symbol that
6426 won't need a .plt entry. */
6427 struct plt_entry
*ent
;
6428 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6429 if (ent
->plt
.refcount
> 0)
6432 || (h
->type
!= STT_GNU_IFUNC
6433 && (SYMBOL_CALLS_LOCAL (info
, h
)
6434 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6435 && h
->root
.type
== bfd_link_hash_undefweak
))))
6437 h
->plt
.plist
= NULL
;
6442 h
->plt
.plist
= NULL
;
6444 /* If this is a weak symbol, and there is a real definition, the
6445 processor independent code will have arranged for us to see the
6446 real definition first, and we can just use the same value. */
6447 if (h
->u
.weakdef
!= NULL
)
6449 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6450 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6451 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6452 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6453 if (ELIMINATE_COPY_RELOCS
)
6454 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
6458 /* If we are creating a shared library, we must presume that the
6459 only references to the symbol are via the global offset table.
6460 For such cases we need not do anything here; the relocations will
6461 be handled correctly by relocate_section. */
6465 /* If there are no references to this symbol that do not use the
6466 GOT, we don't need to generate a copy reloc. */
6467 if (!h
->non_got_ref
)
6470 /* Don't generate a copy reloc for symbols defined in the executable. */
6471 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
6474 if (ELIMINATE_COPY_RELOCS
)
6476 struct ppc_link_hash_entry
* eh
;
6477 struct ppc_dyn_relocs
*p
;
6479 eh
= (struct ppc_link_hash_entry
*) h
;
6480 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6482 s
= p
->sec
->output_section
;
6483 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6487 /* If we didn't find any dynamic relocs in read-only sections, then
6488 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6496 if (h
->plt
.plist
!= NULL
)
6498 /* We should never get here, but unfortunately there are versions
6499 of gcc out there that improperly (for this ABI) put initialized
6500 function pointers, vtable refs and suchlike in read-only
6501 sections. Allow them to proceed, but warn that this might
6502 break at runtime. */
6503 info
->callbacks
->einfo
6504 (_("copy reloc against `%s' requires lazy plt linking; "
6505 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6506 h
->root
.root
.string
);
6509 /* This is a reference to a symbol defined by a dynamic object which
6510 is not a function. */
6514 info
->callbacks
->einfo (_("dynamic variable `%s' is zero size\n"),
6515 h
->root
.root
.string
);
6519 /* We must allocate the symbol in our .dynbss section, which will
6520 become part of the .bss section of the executable. There will be
6521 an entry for this symbol in the .dynsym section. The dynamic
6522 object will contain position independent code, so all references
6523 from the dynamic object to this symbol will go through the global
6524 offset table. The dynamic linker will use the .dynsym entry to
6525 determine the address it must put in the global offset table, so
6526 both the dynamic object and the regular object will refer to the
6527 same memory location for the variable. */
6529 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6530 to copy the initial value out of the dynamic object and into the
6531 runtime process image. We need to remember the offset into the
6532 .rela.bss section we are going to use. */
6533 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6535 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
6541 return _bfd_elf_adjust_dynamic_copy (h
, s
);
6544 /* If given a function descriptor symbol, hide both the function code
6545 sym and the descriptor. */
6547 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6548 struct elf_link_hash_entry
*h
,
6549 bfd_boolean force_local
)
6551 struct ppc_link_hash_entry
*eh
;
6552 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6554 eh
= (struct ppc_link_hash_entry
*) h
;
6555 if (eh
->is_func_descriptor
)
6557 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6562 struct ppc_link_hash_table
*htab
;
6565 /* We aren't supposed to use alloca in BFD because on
6566 systems which do not have alloca the version in libiberty
6567 calls xmalloc, which might cause the program to crash
6568 when it runs out of memory. This function doesn't have a
6569 return status, so there's no way to gracefully return an
6570 error. So cheat. We know that string[-1] can be safely
6571 accessed; It's either a string in an ELF string table,
6572 or allocated in an objalloc structure. */
6574 p
= eh
->elf
.root
.root
.string
- 1;
6577 htab
= ppc_hash_table (info
);
6581 fh
= (struct ppc_link_hash_entry
*)
6582 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6585 /* Unfortunately, if it so happens that the string we were
6586 looking for was allocated immediately before this string,
6587 then we overwrote the string terminator. That's the only
6588 reason the lookup should fail. */
6591 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6592 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6594 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6595 fh
= (struct ppc_link_hash_entry
*)
6596 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6605 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6610 get_sym_h (struct elf_link_hash_entry
**hp
,
6611 Elf_Internal_Sym
**symp
,
6613 unsigned char **tls_maskp
,
6614 Elf_Internal_Sym
**locsymsp
,
6615 unsigned long r_symndx
,
6618 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6620 if (r_symndx
>= symtab_hdr
->sh_info
)
6622 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6623 struct elf_link_hash_entry
*h
;
6625 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6626 h
= elf_follow_link (h
);
6634 if (symsecp
!= NULL
)
6636 asection
*symsec
= NULL
;
6637 if (h
->root
.type
== bfd_link_hash_defined
6638 || h
->root
.type
== bfd_link_hash_defweak
)
6639 symsec
= h
->root
.u
.def
.section
;
6643 if (tls_maskp
!= NULL
)
6645 struct ppc_link_hash_entry
*eh
;
6647 eh
= (struct ppc_link_hash_entry
*) h
;
6648 *tls_maskp
= &eh
->tls_mask
;
6653 Elf_Internal_Sym
*sym
;
6654 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6656 if (locsyms
== NULL
)
6658 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6659 if (locsyms
== NULL
)
6660 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6661 symtab_hdr
->sh_info
,
6662 0, NULL
, NULL
, NULL
);
6663 if (locsyms
== NULL
)
6665 *locsymsp
= locsyms
;
6667 sym
= locsyms
+ r_symndx
;
6675 if (symsecp
!= NULL
)
6676 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6678 if (tls_maskp
!= NULL
)
6680 struct got_entry
**lgot_ents
;
6681 unsigned char *tls_mask
;
6684 lgot_ents
= elf_local_got_ents (ibfd
);
6685 if (lgot_ents
!= NULL
)
6687 struct plt_entry
**local_plt
= (struct plt_entry
**)
6688 (lgot_ents
+ symtab_hdr
->sh_info
);
6689 unsigned char *lgot_masks
= (unsigned char *)
6690 (local_plt
+ symtab_hdr
->sh_info
);
6691 tls_mask
= &lgot_masks
[r_symndx
];
6693 *tls_maskp
= tls_mask
;
6699 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6700 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6701 type suitable for optimization, and 1 otherwise. */
6704 get_tls_mask (unsigned char **tls_maskp
,
6705 unsigned long *toc_symndx
,
6706 bfd_vma
*toc_addend
,
6707 Elf_Internal_Sym
**locsymsp
,
6708 const Elf_Internal_Rela
*rel
,
6711 unsigned long r_symndx
;
6713 struct elf_link_hash_entry
*h
;
6714 Elf_Internal_Sym
*sym
;
6718 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6719 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6722 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6724 || ppc64_elf_section_data (sec
) == NULL
6725 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6728 /* Look inside a TOC section too. */
6731 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6732 off
= h
->root
.u
.def
.value
;
6735 off
= sym
->st_value
;
6736 off
+= rel
->r_addend
;
6737 BFD_ASSERT (off
% 8 == 0);
6738 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6739 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6740 if (toc_symndx
!= NULL
)
6741 *toc_symndx
= r_symndx
;
6742 if (toc_addend
!= NULL
)
6743 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6744 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6746 if ((h
== NULL
|| is_static_defined (h
))
6747 && (next_r
== -1 || next_r
== -2))
6752 /* Adjust all global syms defined in opd sections. In gcc generated
6753 code for the old ABI, these will already have been done. */
6756 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6758 struct ppc_link_hash_entry
*eh
;
6760 struct _opd_sec_data
*opd
;
6762 if (h
->root
.type
== bfd_link_hash_indirect
)
6765 if (h
->root
.type
== bfd_link_hash_warning
)
6766 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6768 if (h
->root
.type
!= bfd_link_hash_defined
6769 && h
->root
.type
!= bfd_link_hash_defweak
)
6772 eh
= (struct ppc_link_hash_entry
*) h
;
6773 if (eh
->adjust_done
)
6776 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6777 opd
= get_opd_info (sym_sec
);
6778 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6780 long adjust
= opd
->adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6783 /* This entry has been deleted. */
6784 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6787 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6788 if (elf_discarded_section (dsec
))
6790 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6794 eh
->elf
.root
.u
.def
.value
= 0;
6795 eh
->elf
.root
.u
.def
.section
= dsec
;
6798 eh
->elf
.root
.u
.def
.value
+= adjust
;
6799 eh
->adjust_done
= 1;
6804 /* Handles decrementing dynamic reloc counts for the reloc specified by
6805 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6806 have already been determined. */
6809 dec_dynrel_count (bfd_vma r_info
,
6811 struct bfd_link_info
*info
,
6812 Elf_Internal_Sym
**local_syms
,
6813 struct elf_link_hash_entry
*h
,
6816 enum elf_ppc64_reloc_type r_type
;
6817 struct ppc_dyn_relocs
*p
;
6818 struct ppc_dyn_relocs
**pp
;
6820 /* Can this reloc be dynamic? This switch, and later tests here
6821 should be kept in sync with the code in check_relocs. */
6822 r_type
= ELF64_R_TYPE (r_info
);
6828 case R_PPC64_TPREL16
:
6829 case R_PPC64_TPREL16_LO
:
6830 case R_PPC64_TPREL16_HI
:
6831 case R_PPC64_TPREL16_HA
:
6832 case R_PPC64_TPREL16_DS
:
6833 case R_PPC64_TPREL16_LO_DS
:
6834 case R_PPC64_TPREL16_HIGHER
:
6835 case R_PPC64_TPREL16_HIGHERA
:
6836 case R_PPC64_TPREL16_HIGHEST
:
6837 case R_PPC64_TPREL16_HIGHESTA
:
6841 case R_PPC64_TPREL64
:
6842 case R_PPC64_DTPMOD64
:
6843 case R_PPC64_DTPREL64
:
6844 case R_PPC64_ADDR64
:
6848 case R_PPC64_ADDR14
:
6849 case R_PPC64_ADDR14_BRNTAKEN
:
6850 case R_PPC64_ADDR14_BRTAKEN
:
6851 case R_PPC64_ADDR16
:
6852 case R_PPC64_ADDR16_DS
:
6853 case R_PPC64_ADDR16_HA
:
6854 case R_PPC64_ADDR16_HI
:
6855 case R_PPC64_ADDR16_HIGHER
:
6856 case R_PPC64_ADDR16_HIGHERA
:
6857 case R_PPC64_ADDR16_HIGHEST
:
6858 case R_PPC64_ADDR16_HIGHESTA
:
6859 case R_PPC64_ADDR16_LO
:
6860 case R_PPC64_ADDR16_LO_DS
:
6861 case R_PPC64_ADDR24
:
6862 case R_PPC64_ADDR32
:
6863 case R_PPC64_UADDR16
:
6864 case R_PPC64_UADDR32
:
6865 case R_PPC64_UADDR64
:
6870 if (local_syms
!= NULL
)
6872 unsigned long r_symndx
;
6873 Elf_Internal_Sym
*sym
;
6874 bfd
*ibfd
= sec
->owner
;
6876 r_symndx
= ELF64_R_SYM (r_info
);
6877 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6882 && (must_be_dyn_reloc (info
, r_type
)
6885 || h
->root
.type
== bfd_link_hash_defweak
6886 || !h
->def_regular
))))
6887 || (ELIMINATE_COPY_RELOCS
6890 && (h
->root
.type
== bfd_link_hash_defweak
6891 || !h
->def_regular
)))
6897 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6900 if (sym_sec
!= NULL
)
6902 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6903 pp
= (struct ppc_dyn_relocs
**) vpp
;
6907 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6908 pp
= (struct ppc_dyn_relocs
**) vpp
;
6911 /* elf_gc_sweep may have already removed all dyn relocs associated
6912 with local syms for a given section. Don't report a dynreloc
6918 while ((p
= *pp
) != NULL
)
6922 if (!must_be_dyn_reloc (info
, r_type
))
6932 info
->callbacks
->einfo (_("dynreloc miscount for %B, section %A\n"),
6934 bfd_set_error (bfd_error_bad_value
);
6938 /* Remove unused Official Procedure Descriptor entries. Currently we
6939 only remove those associated with functions in discarded link-once
6940 sections, or weakly defined functions that have been overridden. It
6941 would be possible to remove many more entries for statically linked
6945 ppc64_elf_edit_opd (struct bfd_link_info
*info
, bfd_boolean non_overlapping
)
6948 bfd_boolean some_edited
= FALSE
;
6949 asection
*need_pad
= NULL
;
6951 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6954 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6955 Elf_Internal_Shdr
*symtab_hdr
;
6956 Elf_Internal_Sym
*local_syms
;
6958 struct _opd_sec_data
*opd
;
6959 bfd_boolean need_edit
, add_aux_fields
;
6960 bfd_size_type cnt_16b
= 0;
6962 if (!is_ppc64_elf (ibfd
))
6965 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6966 if (sec
== NULL
|| sec
->size
== 0)
6969 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6972 if (sec
->output_section
== bfd_abs_section_ptr
)
6975 /* Look through the section relocs. */
6976 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6980 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6982 /* Read the relocations. */
6983 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6985 if (relstart
== NULL
)
6988 /* First run through the relocs to check they are sane, and to
6989 determine whether we need to edit this opd section. */
6993 relend
= relstart
+ sec
->reloc_count
;
6994 for (rel
= relstart
; rel
< relend
; )
6996 enum elf_ppc64_reloc_type r_type
;
6997 unsigned long r_symndx
;
6999 struct elf_link_hash_entry
*h
;
7000 Elf_Internal_Sym
*sym
;
7002 /* .opd contains a regular array of 16 or 24 byte entries. We're
7003 only interested in the reloc pointing to a function entry
7005 if (rel
->r_offset
!= offset
7006 || rel
+ 1 >= relend
7007 || (rel
+ 1)->r_offset
!= offset
+ 8)
7009 /* If someone messes with .opd alignment then after a
7010 "ld -r" we might have padding in the middle of .opd.
7011 Also, there's nothing to prevent someone putting
7012 something silly in .opd with the assembler. No .opd
7013 optimization for them! */
7015 (*_bfd_error_handler
)
7016 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
7021 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7022 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7024 (*_bfd_error_handler
)
7025 (_("%B: unexpected reloc type %u in .opd section"),
7031 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7032 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7036 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7038 const char *sym_name
;
7040 sym_name
= h
->root
.root
.string
;
7042 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7045 (*_bfd_error_handler
)
7046 (_("%B: undefined sym `%s' in .opd section"),
7052 /* opd entries are always for functions defined in the
7053 current input bfd. If the symbol isn't defined in the
7054 input bfd, then we won't be using the function in this
7055 bfd; It must be defined in a linkonce section in another
7056 bfd, or is weak. It's also possible that we are
7057 discarding the function due to a linker script /DISCARD/,
7058 which we test for via the output_section. */
7059 if (sym_sec
->owner
!= ibfd
7060 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7065 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
7067 if (sec
->size
== offset
+ 24)
7072 if (rel
== relend
&& sec
->size
== offset
+ 16)
7080 if (rel
->r_offset
== offset
+ 24)
7082 else if (rel
->r_offset
!= offset
+ 16)
7084 else if (rel
+ 1 < relend
7085 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7086 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7091 else if (rel
+ 2 < relend
7092 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
7093 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
7102 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
7104 if (need_edit
|| add_aux_fields
)
7106 Elf_Internal_Rela
*write_rel
;
7107 Elf_Internal_Shdr
*rel_hdr
;
7108 bfd_byte
*rptr
, *wptr
;
7109 bfd_byte
*new_contents
;
7114 new_contents
= NULL
;
7115 amt
= sec
->size
* sizeof (long) / 8;
7116 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7117 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7118 if (opd
->adjust
== NULL
)
7120 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
7122 /* This seems a waste of time as input .opd sections are all
7123 zeros as generated by gcc, but I suppose there's no reason
7124 this will always be so. We might start putting something in
7125 the third word of .opd entries. */
7126 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7129 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7134 if (local_syms
!= NULL
7135 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7137 if (elf_section_data (sec
)->relocs
!= relstart
)
7141 sec
->contents
= loc
;
7142 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7145 elf_section_data (sec
)->relocs
= relstart
;
7147 new_contents
= sec
->contents
;
7150 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7151 if (new_contents
== NULL
)
7155 wptr
= new_contents
;
7156 rptr
= sec
->contents
;
7158 write_rel
= relstart
;
7162 for (rel
= relstart
; rel
< relend
; rel
++)
7164 unsigned long r_symndx
;
7166 struct elf_link_hash_entry
*h
;
7167 Elf_Internal_Sym
*sym
;
7169 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7170 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7174 if (rel
->r_offset
== offset
)
7176 struct ppc_link_hash_entry
*fdh
= NULL
;
7178 /* See if the .opd entry is full 24 byte or
7179 16 byte (with fd_aux entry overlapped with next
7182 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
7183 || (rel
+ 3 < relend
7184 && rel
[2].r_offset
== offset
+ 16
7185 && rel
[3].r_offset
== offset
+ 24
7186 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
7187 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
7191 && h
->root
.root
.string
[0] == '.')
7193 struct ppc_link_hash_table
*htab
;
7195 htab
= ppc_hash_table (info
);
7197 fdh
= lookup_fdh ((struct ppc_link_hash_entry
*) h
,
7200 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
7201 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7205 skip
= (sym_sec
->owner
!= ibfd
7206 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7209 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7211 /* Arrange for the function descriptor sym
7213 fdh
->elf
.root
.u
.def
.value
= 0;
7214 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7216 opd
->adjust
[rel
->r_offset
/ 8] = -1;
7220 /* We'll be keeping this opd entry. */
7224 /* Redefine the function descriptor symbol to
7225 this location in the opd section. It is
7226 necessary to update the value here rather
7227 than using an array of adjustments as we do
7228 for local symbols, because various places
7229 in the generic ELF code use the value
7230 stored in u.def.value. */
7231 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7232 fdh
->adjust_done
= 1;
7235 /* Local syms are a bit tricky. We could
7236 tweak them as they can be cached, but
7237 we'd need to look through the local syms
7238 for the function descriptor sym which we
7239 don't have at the moment. So keep an
7240 array of adjustments. */
7241 opd
->adjust
[rel
->r_offset
/ 8]
7242 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
7245 memcpy (wptr
, rptr
, opd_ent_size
);
7246 wptr
+= opd_ent_size
;
7247 if (add_aux_fields
&& opd_ent_size
== 16)
7249 memset (wptr
, '\0', 8);
7253 rptr
+= opd_ent_size
;
7254 offset
+= opd_ent_size
;
7260 && !info
->relocatable
7261 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
7267 /* We need to adjust any reloc offsets to point to the
7268 new opd entries. While we're at it, we may as well
7269 remove redundant relocs. */
7270 rel
->r_offset
+= opd
->adjust
[(offset
- opd_ent_size
) / 8];
7271 if (write_rel
!= rel
)
7272 memcpy (write_rel
, rel
, sizeof (*rel
));
7277 sec
->size
= wptr
- new_contents
;
7278 sec
->reloc_count
= write_rel
- relstart
;
7281 free (sec
->contents
);
7282 sec
->contents
= new_contents
;
7285 /* Fudge the header size too, as this is used later in
7286 elf_bfd_final_link if we are emitting relocs. */
7287 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7288 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7291 else if (elf_section_data (sec
)->relocs
!= relstart
)
7294 if (local_syms
!= NULL
7295 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7297 if (!info
->keep_memory
)
7300 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7305 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7307 /* If we are doing a final link and the last .opd entry is just 16 byte
7308 long, add a 8 byte padding after it. */
7309 if (need_pad
!= NULL
&& !info
->relocatable
)
7313 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7315 BFD_ASSERT (need_pad
->size
> 0);
7317 p
= bfd_malloc (need_pad
->size
+ 8);
7321 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
7322 p
, 0, need_pad
->size
))
7325 need_pad
->contents
= p
;
7326 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7330 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7334 need_pad
->contents
= p
;
7337 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7338 need_pad
->size
+= 8;
7344 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7347 ppc64_elf_tls_setup (struct bfd_link_info
*info
,
7348 int no_tls_get_addr_opt
,
7351 struct ppc_link_hash_table
*htab
;
7353 htab
= ppc_hash_table (info
);
7358 htab
->do_multi_toc
= 0;
7359 else if (!htab
->do_multi_toc
)
7362 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7363 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7364 FALSE
, FALSE
, TRUE
));
7365 /* Move dynamic linking info to the function descriptor sym. */
7366 if (htab
->tls_get_addr
!= NULL
)
7367 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7368 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7369 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7370 FALSE
, FALSE
, TRUE
));
7371 if (!no_tls_get_addr_opt
)
7373 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7375 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7376 FALSE
, FALSE
, TRUE
);
7378 func_desc_adjust (opt
, info
);
7379 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7380 FALSE
, FALSE
, TRUE
);
7382 && (opt_fd
->root
.type
== bfd_link_hash_defined
7383 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7385 /* If glibc supports an optimized __tls_get_addr call stub,
7386 signalled by the presence of __tls_get_addr_opt, and we'll
7387 be calling __tls_get_addr via a plt call stub, then
7388 make __tls_get_addr point to __tls_get_addr_opt. */
7389 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7390 if (htab
->elf
.dynamic_sections_created
7392 && (tga_fd
->type
== STT_FUNC
7393 || tga_fd
->needs_plt
)
7394 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7395 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
7396 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
7398 struct plt_entry
*ent
;
7400 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7401 if (ent
->plt
.refcount
> 0)
7405 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7406 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7407 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7408 if (opt_fd
->dynindx
!= -1)
7410 /* Use __tls_get_addr_opt in dynamic relocations. */
7411 opt_fd
->dynindx
= -1;
7412 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7413 opt_fd
->dynstr_index
);
7414 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7417 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
7418 tga
= &htab
->tls_get_addr
->elf
;
7419 if (opt
!= NULL
&& tga
!= NULL
)
7421 tga
->root
.type
= bfd_link_hash_indirect
;
7422 tga
->root
.u
.i
.link
= &opt
->root
;
7423 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7424 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7426 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7428 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7429 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7430 if (htab
->tls_get_addr
!= NULL
)
7432 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7433 htab
->tls_get_addr
->is_func
= 1;
7439 no_tls_get_addr_opt
= TRUE
;
7441 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
7442 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7445 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7449 branch_reloc_hash_match (const bfd
*ibfd
,
7450 const Elf_Internal_Rela
*rel
,
7451 const struct ppc_link_hash_entry
*hash1
,
7452 const struct ppc_link_hash_entry
*hash2
)
7454 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7455 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7456 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7458 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7460 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7461 struct elf_link_hash_entry
*h
;
7463 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7464 h
= elf_follow_link (h
);
7465 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7471 /* Run through all the TLS relocs looking for optimization
7472 opportunities. The linker has been hacked (see ppc64elf.em) to do
7473 a preliminary section layout so that we know the TLS segment
7474 offsets. We can't optimize earlier because some optimizations need
7475 to know the tp offset, and we need to optimize before allocating
7476 dynamic relocations. */
7479 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7483 struct ppc_link_hash_table
*htab
;
7484 unsigned char *toc_ref
;
7487 if (info
->relocatable
|| !info
->executable
)
7490 htab
= ppc_hash_table (info
);
7494 /* Make two passes over the relocs. On the first pass, mark toc
7495 entries involved with tls relocs, and check that tls relocs
7496 involved in setting up a tls_get_addr call are indeed followed by
7497 such a call. If they are not, we can't do any tls optimization.
7498 On the second pass twiddle tls_mask flags to notify
7499 relocate_section that optimization can be done, and adjust got
7500 and plt refcounts. */
7502 for (pass
= 0; pass
< 2; ++pass
)
7503 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7505 Elf_Internal_Sym
*locsyms
= NULL
;
7506 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7508 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7509 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7511 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7512 bfd_boolean found_tls_get_addr_arg
= 0;
7514 /* Read the relocations. */
7515 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7517 if (relstart
== NULL
)
7520 relend
= relstart
+ sec
->reloc_count
;
7521 for (rel
= relstart
; rel
< relend
; rel
++)
7523 enum elf_ppc64_reloc_type r_type
;
7524 unsigned long r_symndx
;
7525 struct elf_link_hash_entry
*h
;
7526 Elf_Internal_Sym
*sym
;
7528 unsigned char *tls_mask
;
7529 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7531 bfd_boolean ok_tprel
, is_local
;
7532 long toc_ref_index
= 0;
7533 int expecting_tls_get_addr
= 0;
7534 bfd_boolean ret
= FALSE
;
7536 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7537 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7541 if (elf_section_data (sec
)->relocs
!= relstart
)
7543 if (toc_ref
!= NULL
)
7546 && (elf_symtab_hdr (ibfd
).contents
7547 != (unsigned char *) locsyms
))
7554 if (h
->root
.type
== bfd_link_hash_defined
7555 || h
->root
.type
== bfd_link_hash_defweak
)
7556 value
= h
->root
.u
.def
.value
;
7557 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7561 found_tls_get_addr_arg
= 0;
7566 /* Symbols referenced by TLS relocs must be of type
7567 STT_TLS. So no need for .opd local sym adjust. */
7568 value
= sym
->st_value
;
7577 && h
->root
.type
== bfd_link_hash_undefweak
)
7581 value
+= sym_sec
->output_offset
;
7582 value
+= sym_sec
->output_section
->vma
;
7583 value
-= htab
->elf
.tls_sec
->vma
;
7584 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7585 < (bfd_vma
) 1 << 32);
7589 r_type
= ELF64_R_TYPE (rel
->r_info
);
7590 /* If this section has old-style __tls_get_addr calls
7591 without marker relocs, then check that each
7592 __tls_get_addr call reloc is preceded by a reloc
7593 that conceivably belongs to the __tls_get_addr arg
7594 setup insn. If we don't find matching arg setup
7595 relocs, don't do any tls optimization. */
7597 && sec
->has_tls_get_addr_call
7599 && (h
== &htab
->tls_get_addr
->elf
7600 || h
== &htab
->tls_get_addr_fd
->elf
)
7601 && !found_tls_get_addr_arg
7602 && is_branch_reloc (r_type
))
7604 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7605 "TLS optimization disabled\n"),
7606 ibfd
, sec
, rel
->r_offset
);
7611 found_tls_get_addr_arg
= 0;
7614 case R_PPC64_GOT_TLSLD16
:
7615 case R_PPC64_GOT_TLSLD16_LO
:
7616 expecting_tls_get_addr
= 1;
7617 found_tls_get_addr_arg
= 1;
7620 case R_PPC64_GOT_TLSLD16_HI
:
7621 case R_PPC64_GOT_TLSLD16_HA
:
7622 /* These relocs should never be against a symbol
7623 defined in a shared lib. Leave them alone if
7624 that turns out to be the case. */
7631 tls_type
= TLS_TLS
| TLS_LD
;
7634 case R_PPC64_GOT_TLSGD16
:
7635 case R_PPC64_GOT_TLSGD16_LO
:
7636 expecting_tls_get_addr
= 1;
7637 found_tls_get_addr_arg
= 1;
7640 case R_PPC64_GOT_TLSGD16_HI
:
7641 case R_PPC64_GOT_TLSGD16_HA
:
7647 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7649 tls_type
= TLS_TLS
| TLS_GD
;
7652 case R_PPC64_GOT_TPREL16_DS
:
7653 case R_PPC64_GOT_TPREL16_LO_DS
:
7654 case R_PPC64_GOT_TPREL16_HI
:
7655 case R_PPC64_GOT_TPREL16_HA
:
7660 tls_clear
= TLS_TPREL
;
7661 tls_type
= TLS_TLS
| TLS_TPREL
;
7668 found_tls_get_addr_arg
= 1;
7673 case R_PPC64_TOC16_LO
:
7674 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7677 /* Mark this toc entry as referenced by a TLS
7678 code sequence. We can do that now in the
7679 case of R_PPC64_TLS, and after checking for
7680 tls_get_addr for the TOC16 relocs. */
7681 if (toc_ref
== NULL
)
7682 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7683 if (toc_ref
== NULL
)
7687 value
= h
->root
.u
.def
.value
;
7689 value
= sym
->st_value
;
7690 value
+= rel
->r_addend
;
7691 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
7692 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7693 if (r_type
== R_PPC64_TLS
7694 || r_type
== R_PPC64_TLSGD
7695 || r_type
== R_PPC64_TLSLD
)
7697 toc_ref
[toc_ref_index
] = 1;
7701 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7706 expecting_tls_get_addr
= 2;
7709 case R_PPC64_TPREL64
:
7713 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7718 tls_set
= TLS_EXPLICIT
;
7719 tls_clear
= TLS_TPREL
;
7724 case R_PPC64_DTPMOD64
:
7728 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7730 if (rel
+ 1 < relend
7732 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7733 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7737 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7740 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7749 tls_set
= TLS_EXPLICIT
;
7760 if (!expecting_tls_get_addr
7761 || !sec
->has_tls_get_addr_call
)
7764 if (rel
+ 1 < relend
7765 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7767 htab
->tls_get_addr_fd
))
7769 if (expecting_tls_get_addr
== 2)
7771 /* Check for toc tls entries. */
7772 unsigned char *toc_tls
;
7775 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7780 if (toc_tls
!= NULL
)
7782 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
7783 found_tls_get_addr_arg
= 1;
7785 toc_ref
[toc_ref_index
] = 1;
7791 if (expecting_tls_get_addr
!= 1)
7794 /* Uh oh, we didn't find the expected call. We
7795 could just mark this symbol to exclude it
7796 from tls optimization but it's safer to skip
7797 the entire optimization. */
7798 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7799 "TLS optimization disabled\n"),
7800 ibfd
, sec
, rel
->r_offset
);
7805 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
7807 struct plt_entry
*ent
;
7808 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7811 if (ent
->addend
== 0)
7813 if (ent
->plt
.refcount
> 0)
7815 ent
->plt
.refcount
-= 1;
7816 expecting_tls_get_addr
= 0;
7822 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
7824 struct plt_entry
*ent
;
7825 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7828 if (ent
->addend
== 0)
7830 if (ent
->plt
.refcount
> 0)
7831 ent
->plt
.refcount
-= 1;
7839 if ((tls_set
& TLS_EXPLICIT
) == 0)
7841 struct got_entry
*ent
;
7843 /* Adjust got entry for this reloc. */
7847 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7849 for (; ent
!= NULL
; ent
= ent
->next
)
7850 if (ent
->addend
== rel
->r_addend
7851 && ent
->owner
== ibfd
7852 && ent
->tls_type
== tls_type
)
7859 /* We managed to get rid of a got entry. */
7860 if (ent
->got
.refcount
> 0)
7861 ent
->got
.refcount
-= 1;
7866 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7867 we'll lose one or two dyn relocs. */
7868 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7872 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7874 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7880 *tls_mask
|= tls_set
;
7881 *tls_mask
&= ~tls_clear
;
7884 if (elf_section_data (sec
)->relocs
!= relstart
)
7889 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7891 if (!info
->keep_memory
)
7894 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7898 if (toc_ref
!= NULL
)
7903 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7904 the values of any global symbols in a toc section that has been
7905 edited. Globals in toc sections should be a rarity, so this function
7906 sets a flag if any are found in toc sections other than the one just
7907 edited, so that futher hash table traversals can be avoided. */
7909 struct adjust_toc_info
7912 unsigned long *skip
;
7913 bfd_boolean global_toc_syms
;
7916 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7919 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7921 struct ppc_link_hash_entry
*eh
;
7922 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7925 if (h
->root
.type
== bfd_link_hash_indirect
)
7928 if (h
->root
.type
== bfd_link_hash_warning
)
7929 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7931 if (h
->root
.type
!= bfd_link_hash_defined
7932 && h
->root
.type
!= bfd_link_hash_defweak
)
7935 eh
= (struct ppc_link_hash_entry
*) h
;
7936 if (eh
->adjust_done
)
7939 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7941 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7942 i
= toc_inf
->toc
->rawsize
>> 3;
7944 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7946 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7948 (*_bfd_error_handler
)
7949 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7952 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7953 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7956 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7957 eh
->adjust_done
= 1;
7959 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7960 toc_inf
->global_toc_syms
= TRUE
;
7965 /* Examine all relocs referencing .toc sections in order to remove
7966 unused .toc entries. */
7969 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7972 struct adjust_toc_info toc_inf
;
7973 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7975 htab
->do_toc_opt
= 1;
7976 toc_inf
.global_toc_syms
= TRUE
;
7977 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7979 asection
*toc
, *sec
;
7980 Elf_Internal_Shdr
*symtab_hdr
;
7981 Elf_Internal_Sym
*local_syms
;
7982 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7983 unsigned long *skip
, *drop
;
7984 unsigned char *used
;
7985 unsigned char *keep
, last
, some_unused
;
7987 if (!is_ppc64_elf (ibfd
))
7990 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7993 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7994 || elf_discarded_section (toc
))
7999 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8001 /* Look at sections dropped from the final link. */
8004 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8006 if (sec
->reloc_count
== 0
8007 || !elf_discarded_section (sec
)
8008 || get_opd_info (sec
)
8009 || (sec
->flags
& SEC_ALLOC
) == 0
8010 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8013 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
8014 if (relstart
== NULL
)
8017 /* Run through the relocs to see which toc entries might be
8019 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8021 enum elf_ppc64_reloc_type r_type
;
8022 unsigned long r_symndx
;
8024 struct elf_link_hash_entry
*h
;
8025 Elf_Internal_Sym
*sym
;
8028 r_type
= ELF64_R_TYPE (rel
->r_info
);
8035 case R_PPC64_TOC16_LO
:
8036 case R_PPC64_TOC16_HI
:
8037 case R_PPC64_TOC16_HA
:
8038 case R_PPC64_TOC16_DS
:
8039 case R_PPC64_TOC16_LO_DS
:
8043 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8044 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8052 val
= h
->root
.u
.def
.value
;
8054 val
= sym
->st_value
;
8055 val
+= rel
->r_addend
;
8057 if (val
>= toc
->size
)
8060 /* Anything in the toc ought to be aligned to 8 bytes.
8061 If not, don't mark as unused. */
8067 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8072 skip
[val
>> 3] = ref_from_discarded
;
8075 if (elf_section_data (sec
)->relocs
!= relstart
)
8079 /* For largetoc loads of address constants, we can convert
8080 . addis rx,2,addr@got@ha
8081 . ld ry,addr@got@l(rx)
8083 . addis rx,2,addr@toc@ha
8084 . addi ry,rx,addr@toc@l
8085 when addr is within 2G of the toc pointer. This then means
8086 that the word storing "addr" in the toc is no longer needed. */
8088 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8089 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8090 && toc
->reloc_count
!= 0)
8092 /* Read toc relocs. */
8093 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8095 if (toc_relocs
== NULL
)
8098 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8100 enum elf_ppc64_reloc_type r_type
;
8101 unsigned long r_symndx
;
8103 struct elf_link_hash_entry
*h
;
8104 Elf_Internal_Sym
*sym
;
8107 r_type
= ELF64_R_TYPE (rel
->r_info
);
8108 if (r_type
!= R_PPC64_ADDR64
)
8111 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8112 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8117 || elf_discarded_section (sym_sec
))
8120 if (!SYMBOL_CALLS_LOCAL (info
, h
))
8125 if (h
->type
== STT_GNU_IFUNC
)
8127 val
= h
->root
.u
.def
.value
;
8131 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8133 val
= sym
->st_value
;
8135 val
+= rel
->r_addend
;
8136 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8138 /* We don't yet know the exact toc pointer value, but we
8139 know it will be somewhere in the toc section. Don't
8140 optimize if the difference from any possible toc
8141 pointer is outside [ff..f80008000, 7fff7fff]. */
8142 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8143 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8146 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8147 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8152 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8157 skip
[rel
->r_offset
>> 3]
8158 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8165 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8169 if (local_syms
!= NULL
8170 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8174 && elf_section_data (sec
)->relocs
!= relstart
)
8176 if (toc_relocs
!= NULL
8177 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8184 /* Now check all kept sections that might reference the toc.
8185 Check the toc itself last. */
8186 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8189 sec
= (sec
== toc
? NULL
8190 : sec
->next
== NULL
? toc
8191 : sec
->next
== toc
&& toc
->next
? toc
->next
8196 if (sec
->reloc_count
== 0
8197 || elf_discarded_section (sec
)
8198 || get_opd_info (sec
)
8199 || (sec
->flags
& SEC_ALLOC
) == 0
8200 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8203 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8205 if (relstart
== NULL
)
8208 /* Mark toc entries referenced as used. */
8211 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8213 enum elf_ppc64_reloc_type r_type
;
8214 unsigned long r_symndx
;
8216 struct elf_link_hash_entry
*h
;
8217 Elf_Internal_Sym
*sym
;
8220 r_type
= ELF64_R_TYPE (rel
->r_info
);
8224 case R_PPC64_TOC16_LO
:
8225 case R_PPC64_TOC16_HI
:
8226 case R_PPC64_TOC16_HA
:
8227 case R_PPC64_TOC16_DS
:
8228 case R_PPC64_TOC16_LO_DS
:
8229 /* In case we're taking addresses of toc entries. */
8230 case R_PPC64_ADDR64
:
8237 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8238 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8249 val
= h
->root
.u
.def
.value
;
8251 val
= sym
->st_value
;
8252 val
+= rel
->r_addend
;
8254 if (val
>= toc
->size
)
8257 if ((skip
[val
>> 3] & can_optimize
) != 0)
8264 case R_PPC64_TOC16_HA
:
8267 case R_PPC64_TOC16_LO_DS
:
8268 off
= rel
->r_offset
+ (bfd_big_endian (ibfd
) ? -2 : 3);
8269 if (!bfd_get_section_contents (ibfd
, sec
, &opc
, off
, 1))
8271 if ((opc
& (0x3f << 2)) == (58u << 2))
8276 /* Wrong sort of reloc, or not a ld. We may
8277 as well clear ref_from_discarded too. */
8282 /* For the toc section, we only mark as used if
8283 this entry itself isn't unused. */
8286 && (used
[rel
->r_offset
>> 3]
8287 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
)))
8288 /* Do all the relocs again, to catch reference
8296 if (elf_section_data (sec
)->relocs
!= relstart
)
8300 /* Merge the used and skip arrays. Assume that TOC
8301 doublewords not appearing as either used or unused belong
8302 to to an entry more than one doubleword in size. */
8303 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8304 drop
< skip
+ (toc
->size
+ 7) / 8;
8309 *drop
&= ~ref_from_discarded
;
8310 if ((*drop
& can_optimize
) != 0)
8317 last
= ref_from_discarded
;
8327 bfd_byte
*contents
, *src
;
8329 Elf_Internal_Sym
*sym
;
8330 bfd_boolean local_toc_syms
= FALSE
;
8332 /* Shuffle the toc contents, and at the same time convert the
8333 skip array from booleans into offsets. */
8334 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8337 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8339 for (src
= contents
, off
= 0, drop
= skip
;
8340 src
< contents
+ toc
->size
;
8343 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8348 memcpy (src
- off
, src
, 8);
8352 toc
->rawsize
= toc
->size
;
8353 toc
->size
= src
- contents
- off
;
8355 /* Adjust addends for relocs against the toc section sym,
8356 and optimize any accesses we can. */
8357 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8359 if (sec
->reloc_count
== 0
8360 || elf_discarded_section (sec
))
8363 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8365 if (relstart
== NULL
)
8368 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8370 enum elf_ppc64_reloc_type r_type
;
8371 unsigned long r_symndx
;
8373 struct elf_link_hash_entry
*h
;
8376 r_type
= ELF64_R_TYPE (rel
->r_info
);
8383 case R_PPC64_TOC16_LO
:
8384 case R_PPC64_TOC16_HI
:
8385 case R_PPC64_TOC16_HA
:
8386 case R_PPC64_TOC16_DS
:
8387 case R_PPC64_TOC16_LO_DS
:
8388 case R_PPC64_ADDR64
:
8392 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8393 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8401 val
= h
->root
.u
.def
.value
;
8404 val
= sym
->st_value
;
8406 local_toc_syms
= TRUE
;
8409 val
+= rel
->r_addend
;
8411 if (val
> toc
->rawsize
)
8413 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8415 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8417 Elf_Internal_Rela
*tocrel
8418 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8419 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8423 case R_PPC64_TOC16_HA
:
8424 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8427 case R_PPC64_TOC16_LO_DS
:
8428 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8434 rel
->r_addend
= tocrel
->r_addend
;
8435 elf_section_data (sec
)->relocs
= relstart
;
8439 if (h
!= NULL
|| sym
->st_value
!= 0)
8442 rel
->r_addend
-= skip
[val
>> 3];
8443 elf_section_data (sec
)->relocs
= relstart
;
8446 if (elf_section_data (sec
)->relocs
!= relstart
)
8450 /* We shouldn't have local or global symbols defined in the TOC,
8451 but handle them anyway. */
8452 if (local_syms
!= NULL
)
8453 for (sym
= local_syms
;
8454 sym
< local_syms
+ symtab_hdr
->sh_info
;
8456 if (sym
->st_value
!= 0
8457 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8461 if (sym
->st_value
> toc
->rawsize
)
8462 i
= toc
->rawsize
>> 3;
8464 i
= sym
->st_value
>> 3;
8466 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8469 (*_bfd_error_handler
)
8470 (_("%s defined on removed toc entry"),
8471 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8474 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8475 sym
->st_value
= (bfd_vma
) i
<< 3;
8478 sym
->st_value
-= skip
[i
];
8479 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8482 /* Adjust any global syms defined in this toc input section. */
8483 if (toc_inf
.global_toc_syms
)
8486 toc_inf
.skip
= skip
;
8487 toc_inf
.global_toc_syms
= FALSE
;
8488 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8492 if (toc
->reloc_count
!= 0)
8494 Elf_Internal_Shdr
*rel_hdr
;
8495 Elf_Internal_Rela
*wrel
;
8498 /* Remove unused toc relocs, and adjust those we keep. */
8499 if (toc_relocs
== NULL
)
8500 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8502 if (toc_relocs
== NULL
)
8506 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8507 if ((skip
[rel
->r_offset
>> 3]
8508 & (ref_from_discarded
| can_optimize
)) == 0)
8510 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8511 wrel
->r_info
= rel
->r_info
;
8512 wrel
->r_addend
= rel
->r_addend
;
8515 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8516 &local_syms
, NULL
, NULL
))
8519 elf_section_data (toc
)->relocs
= toc_relocs
;
8520 toc
->reloc_count
= wrel
- toc_relocs
;
8521 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8522 sz
= rel_hdr
->sh_entsize
;
8523 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8526 else if (toc_relocs
!= NULL
8527 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8530 if (local_syms
!= NULL
8531 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8533 if (!info
->keep_memory
)
8536 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8544 /* Return true iff input section I references the TOC using
8545 instructions limited to +/-32k offsets. */
8548 ppc64_elf_has_small_toc_reloc (asection
*i
)
8550 return (is_ppc64_elf (i
->owner
)
8551 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8554 /* Allocate space for one GOT entry. */
8557 allocate_got (struct elf_link_hash_entry
*h
,
8558 struct bfd_link_info
*info
,
8559 struct got_entry
*gent
)
8561 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8563 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8564 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8566 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8567 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8568 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8570 gent
->got
.offset
= got
->size
;
8571 got
->size
+= entsize
;
8573 dyn
= htab
->elf
.dynamic_sections_created
;
8575 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
8576 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8577 || h
->root
.type
!= bfd_link_hash_undefweak
))
8579 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8580 relgot
->size
+= rentsize
;
8582 else if (h
->type
== STT_GNU_IFUNC
)
8584 asection
*relgot
= htab
->reliplt
;
8585 relgot
->size
+= rentsize
;
8586 htab
->got_reli_size
+= rentsize
;
8590 /* This function merges got entries in the same toc group. */
8593 merge_got_entries (struct got_entry
**pent
)
8595 struct got_entry
*ent
, *ent2
;
8597 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8598 if (!ent
->is_indirect
)
8599 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8600 if (!ent2
->is_indirect
8601 && ent2
->addend
== ent
->addend
8602 && ent2
->tls_type
== ent
->tls_type
8603 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8605 ent2
->is_indirect
= TRUE
;
8606 ent2
->got
.ent
= ent
;
8610 /* Allocate space in .plt, .got and associated reloc sections for
8614 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8616 struct bfd_link_info
*info
;
8617 struct ppc_link_hash_table
*htab
;
8619 struct ppc_link_hash_entry
*eh
;
8620 struct ppc_dyn_relocs
*p
;
8621 struct got_entry
**pgent
, *gent
;
8623 if (h
->root
.type
== bfd_link_hash_indirect
)
8626 if (h
->root
.type
== bfd_link_hash_warning
)
8627 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8629 info
= (struct bfd_link_info
*) inf
;
8630 htab
= ppc_hash_table (info
);
8634 if ((htab
->elf
.dynamic_sections_created
8636 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
8637 || h
->type
== STT_GNU_IFUNC
)
8639 struct plt_entry
*pent
;
8640 bfd_boolean doneone
= FALSE
;
8641 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8642 if (pent
->plt
.refcount
> 0)
8644 if (!htab
->elf
.dynamic_sections_created
8645 || h
->dynindx
== -1)
8648 pent
->plt
.offset
= s
->size
;
8649 s
->size
+= PLT_ENTRY_SIZE
;
8654 /* If this is the first .plt entry, make room for the special
8658 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
8660 pent
->plt
.offset
= s
->size
;
8662 /* Make room for this entry. */
8663 s
->size
+= PLT_ENTRY_SIZE
;
8665 /* Make room for the .glink code. */
8668 s
->size
+= GLINK_CALL_STUB_SIZE
;
8669 /* We need bigger stubs past index 32767. */
8670 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
8674 /* We also need to make an entry in the .rela.plt section. */
8677 s
->size
+= sizeof (Elf64_External_Rela
);
8681 pent
->plt
.offset
= (bfd_vma
) -1;
8684 h
->plt
.plist
= NULL
;
8690 h
->plt
.plist
= NULL
;
8694 eh
= (struct ppc_link_hash_entry
*) h
;
8695 /* Run through the TLS GD got entries first if we're changing them
8697 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
8698 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8699 if (gent
->got
.refcount
> 0
8700 && (gent
->tls_type
& TLS_GD
) != 0)
8702 /* This was a GD entry that has been converted to TPREL. If
8703 there happens to be a TPREL entry we can use that one. */
8704 struct got_entry
*ent
;
8705 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8706 if (ent
->got
.refcount
> 0
8707 && (ent
->tls_type
& TLS_TPREL
) != 0
8708 && ent
->addend
== gent
->addend
8709 && ent
->owner
== gent
->owner
)
8711 gent
->got
.refcount
= 0;
8715 /* If not, then we'll be using our own TPREL entry. */
8716 if (gent
->got
.refcount
!= 0)
8717 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8720 /* Remove any list entry that won't generate a word in the GOT before
8721 we call merge_got_entries. Otherwise we risk merging to empty
8723 pgent
= &h
->got
.glist
;
8724 while ((gent
= *pgent
) != NULL
)
8725 if (gent
->got
.refcount
> 0)
8727 if ((gent
->tls_type
& TLS_LD
) != 0
8730 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8731 *pgent
= gent
->next
;
8734 pgent
= &gent
->next
;
8737 *pgent
= gent
->next
;
8739 if (!htab
->do_multi_toc
)
8740 merge_got_entries (&h
->got
.glist
);
8742 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8743 if (!gent
->is_indirect
)
8745 /* Make sure this symbol is output as a dynamic symbol.
8746 Undefined weak syms won't yet be marked as dynamic,
8747 nor will all TLS symbols. */
8748 if (h
->dynindx
== -1
8750 && h
->type
!= STT_GNU_IFUNC
8751 && htab
->elf
.dynamic_sections_created
)
8753 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8757 if (!is_ppc64_elf (gent
->owner
))
8760 allocate_got (h
, info
, gent
);
8763 if (eh
->dyn_relocs
== NULL
8764 || (!htab
->elf
.dynamic_sections_created
8765 && h
->type
!= STT_GNU_IFUNC
))
8768 /* In the shared -Bsymbolic case, discard space allocated for
8769 dynamic pc-relative relocs against symbols which turn out to be
8770 defined in regular objects. For the normal shared case, discard
8771 space for relocs that have become local due to symbol visibility
8776 /* Relocs that use pc_count are those that appear on a call insn,
8777 or certain REL relocs (see must_be_dyn_reloc) that can be
8778 generated via assembly. We want calls to protected symbols to
8779 resolve directly to the function rather than going via the plt.
8780 If people want function pointer comparisons to work as expected
8781 then they should avoid writing weird assembly. */
8782 if (SYMBOL_CALLS_LOCAL (info
, h
))
8784 struct ppc_dyn_relocs
**pp
;
8786 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8788 p
->count
-= p
->pc_count
;
8797 /* Also discard relocs on undefined weak syms with non-default
8799 if (eh
->dyn_relocs
!= NULL
8800 && h
->root
.type
== bfd_link_hash_undefweak
)
8802 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8803 eh
->dyn_relocs
= NULL
;
8805 /* Make sure this symbol is output as a dynamic symbol.
8806 Undefined weak syms won't yet be marked as dynamic. */
8807 else if (h
->dynindx
== -1
8808 && !h
->forced_local
)
8810 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8815 else if (h
->type
== STT_GNU_IFUNC
)
8817 if (!h
->non_got_ref
)
8818 eh
->dyn_relocs
= NULL
;
8820 else if (ELIMINATE_COPY_RELOCS
)
8822 /* For the non-shared case, discard space for relocs against
8823 symbols which turn out to need copy relocs or are not
8829 /* Make sure this symbol is output as a dynamic symbol.
8830 Undefined weak syms won't yet be marked as dynamic. */
8831 if (h
->dynindx
== -1
8832 && !h
->forced_local
)
8834 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8838 /* If that succeeded, we know we'll be keeping all the
8840 if (h
->dynindx
!= -1)
8844 eh
->dyn_relocs
= NULL
;
8849 /* Finally, allocate space. */
8850 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8852 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8853 if (!htab
->elf
.dynamic_sections_created
)
8854 sreloc
= htab
->reliplt
;
8855 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8861 /* Find any dynamic relocs that apply to read-only sections. */
8864 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8866 struct ppc_link_hash_entry
*eh
;
8867 struct ppc_dyn_relocs
*p
;
8869 if (h
->root
.type
== bfd_link_hash_warning
)
8870 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8872 eh
= (struct ppc_link_hash_entry
*) h
;
8873 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8875 asection
*s
= p
->sec
->output_section
;
8877 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
8879 struct bfd_link_info
*info
= inf
;
8881 info
->flags
|= DF_TEXTREL
;
8883 /* Not an error, just cut short the traversal. */
8890 /* Set the sizes of the dynamic sections. */
8893 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
8894 struct bfd_link_info
*info
)
8896 struct ppc_link_hash_table
*htab
;
8901 struct got_entry
*first_tlsld
;
8903 htab
= ppc_hash_table (info
);
8907 dynobj
= htab
->elf
.dynobj
;
8911 if (htab
->elf
.dynamic_sections_created
)
8913 /* Set the contents of the .interp section to the interpreter. */
8914 if (info
->executable
)
8916 s
= bfd_get_section_by_name (dynobj
, ".interp");
8919 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
8920 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
8924 /* Set up .got offsets for local syms, and space for local dynamic
8926 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8928 struct got_entry
**lgot_ents
;
8929 struct got_entry
**end_lgot_ents
;
8930 struct plt_entry
**local_plt
;
8931 struct plt_entry
**end_local_plt
;
8932 unsigned char *lgot_masks
;
8933 bfd_size_type locsymcount
;
8934 Elf_Internal_Shdr
*symtab_hdr
;
8937 if (!is_ppc64_elf (ibfd
))
8940 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
8942 struct ppc_dyn_relocs
*p
;
8944 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
8946 if (!bfd_is_abs_section (p
->sec
)
8947 && bfd_is_abs_section (p
->sec
->output_section
))
8949 /* Input section has been discarded, either because
8950 it is a copy of a linkonce section or due to
8951 linker script /DISCARD/, so we'll be discarding
8954 else if (p
->count
!= 0)
8956 srel
= elf_section_data (p
->sec
)->sreloc
;
8957 if (!htab
->elf
.dynamic_sections_created
)
8958 srel
= htab
->reliplt
;
8959 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8960 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
8961 info
->flags
|= DF_TEXTREL
;
8966 lgot_ents
= elf_local_got_ents (ibfd
);
8970 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8971 locsymcount
= symtab_hdr
->sh_info
;
8972 end_lgot_ents
= lgot_ents
+ locsymcount
;
8973 local_plt
= (struct plt_entry
**) end_lgot_ents
;
8974 end_local_plt
= local_plt
+ locsymcount
;
8975 lgot_masks
= (unsigned char *) end_local_plt
;
8976 s
= ppc64_elf_tdata (ibfd
)->got
;
8977 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
8978 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
8980 struct got_entry
**pent
, *ent
;
8983 while ((ent
= *pent
) != NULL
)
8984 if (ent
->got
.refcount
> 0)
8986 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
8988 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
8993 unsigned int num
= 1;
8994 ent
->got
.offset
= s
->size
;
8995 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
8999 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
9000 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
9003 += num
* sizeof (Elf64_External_Rela
);
9005 += num
* sizeof (Elf64_External_Rela
);
9014 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
9015 for (; local_plt
< end_local_plt
; ++local_plt
)
9017 struct plt_entry
*ent
;
9019 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9020 if (ent
->plt
.refcount
> 0)
9023 ent
->plt
.offset
= s
->size
;
9024 s
->size
+= PLT_ENTRY_SIZE
;
9026 htab
->reliplt
->size
+= sizeof (Elf64_External_Rela
);
9029 ent
->plt
.offset
= (bfd_vma
) -1;
9033 /* Allocate global sym .plt and .got entries, and space for global
9034 sym dynamic relocs. */
9035 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9038 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9040 struct got_entry
*ent
;
9042 if (!is_ppc64_elf (ibfd
))
9045 ent
= ppc64_tlsld_got (ibfd
);
9046 if (ent
->got
.refcount
> 0)
9048 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9050 ent
->is_indirect
= TRUE
;
9051 ent
->got
.ent
= first_tlsld
;
9055 if (first_tlsld
== NULL
)
9057 s
= ppc64_elf_tdata (ibfd
)->got
;
9058 ent
->got
.offset
= s
->size
;
9063 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9064 srel
->size
+= sizeof (Elf64_External_Rela
);
9069 ent
->got
.offset
= (bfd_vma
) -1;
9072 /* We now have determined the sizes of the various dynamic sections.
9073 Allocate memory for them. */
9075 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9077 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9080 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9081 /* These haven't been allocated yet; don't strip. */
9083 else if (s
== htab
->got
9087 || s
== htab
->dynbss
)
9089 /* Strip this section if we don't need it; see the
9092 else if (CONST_STRNEQ (s
->name
, ".rela"))
9096 if (s
!= htab
->relplt
)
9099 /* We use the reloc_count field as a counter if we need
9100 to copy relocs into the output file. */
9106 /* It's not one of our sections, so don't allocate space. */
9112 /* If we don't need this section, strip it from the
9113 output file. This is mostly to handle .rela.bss and
9114 .rela.plt. We must create both sections in
9115 create_dynamic_sections, because they must be created
9116 before the linker maps input sections to output
9117 sections. The linker does that before
9118 adjust_dynamic_symbol is called, and it is that
9119 function which decides whether anything needs to go
9120 into these sections. */
9121 s
->flags
|= SEC_EXCLUDE
;
9125 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9128 /* Allocate memory for the section contents. We use bfd_zalloc
9129 here in case unused entries are not reclaimed before the
9130 section's contents are written out. This should not happen,
9131 but this way if it does we get a R_PPC64_NONE reloc in .rela
9132 sections instead of garbage.
9133 We also rely on the section contents being zero when writing
9135 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9136 if (s
->contents
== NULL
)
9140 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9142 if (!is_ppc64_elf (ibfd
))
9145 s
= ppc64_elf_tdata (ibfd
)->got
;
9146 if (s
!= NULL
&& s
!= htab
->got
)
9149 s
->flags
|= SEC_EXCLUDE
;
9152 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9153 if (s
->contents
== NULL
)
9157 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9161 s
->flags
|= SEC_EXCLUDE
;
9164 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9165 if (s
->contents
== NULL
)
9173 if (htab
->elf
.dynamic_sections_created
)
9175 /* Add some entries to the .dynamic section. We fill in the
9176 values later, in ppc64_elf_finish_dynamic_sections, but we
9177 must add the entries now so that we get the correct size for
9178 the .dynamic section. The DT_DEBUG entry is filled in by the
9179 dynamic linker and used by the debugger. */
9180 #define add_dynamic_entry(TAG, VAL) \
9181 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9183 if (info
->executable
)
9185 if (!add_dynamic_entry (DT_DEBUG
, 0))
9189 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
9191 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9192 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9193 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9194 || !add_dynamic_entry (DT_JMPREL
, 0)
9195 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9201 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9202 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9206 if (!htab
->no_tls_get_addr_opt
9207 && htab
->tls_get_addr_fd
!= NULL
9208 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
9209 && !add_dynamic_entry (DT_PPC64_TLSOPT
, 0))
9214 if (!add_dynamic_entry (DT_RELA
, 0)
9215 || !add_dynamic_entry (DT_RELASZ
, 0)
9216 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9219 /* If any dynamic relocs apply to a read-only section,
9220 then we need a DT_TEXTREL entry. */
9221 if ((info
->flags
& DF_TEXTREL
) == 0)
9222 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
9224 if ((info
->flags
& DF_TEXTREL
) != 0)
9226 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9231 #undef add_dynamic_entry
9236 /* Determine the type of stub needed, if any, for a call. */
9238 static inline enum ppc_stub_type
9239 ppc_type_of_stub (asection
*input_sec
,
9240 const Elf_Internal_Rela
*rel
,
9241 struct ppc_link_hash_entry
**hash
,
9242 struct plt_entry
**plt_ent
,
9243 bfd_vma destination
)
9245 struct ppc_link_hash_entry
*h
= *hash
;
9247 bfd_vma branch_offset
;
9248 bfd_vma max_branch_offset
;
9249 enum elf_ppc64_reloc_type r_type
;
9253 struct plt_entry
*ent
;
9254 struct ppc_link_hash_entry
*fdh
= h
;
9256 && h
->oh
->is_func_descriptor
)
9258 fdh
= ppc_follow_link (h
->oh
);
9262 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9263 if (ent
->addend
== rel
->r_addend
9264 && ent
->plt
.offset
!= (bfd_vma
) -1)
9267 return ppc_stub_plt_call
;
9270 /* Here, we know we don't have a plt entry. If we don't have a
9271 either a defined function descriptor or a defined entry symbol
9272 in a regular object file, then it is pointless trying to make
9273 any other type of stub. */
9274 if (!is_static_defined (&fdh
->elf
)
9275 && !is_static_defined (&h
->elf
))
9276 return ppc_stub_none
;
9278 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9280 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9281 struct plt_entry
**local_plt
= (struct plt_entry
**)
9282 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9283 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9285 if (local_plt
[r_symndx
] != NULL
)
9287 struct plt_entry
*ent
;
9289 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9290 if (ent
->addend
== rel
->r_addend
9291 && ent
->plt
.offset
!= (bfd_vma
) -1)
9294 return ppc_stub_plt_call
;
9299 /* Determine where the call point is. */
9300 location
= (input_sec
->output_offset
9301 + input_sec
->output_section
->vma
9304 branch_offset
= destination
- location
;
9305 r_type
= ELF64_R_TYPE (rel
->r_info
);
9307 /* Determine if a long branch stub is needed. */
9308 max_branch_offset
= 1 << 25;
9309 if (r_type
!= R_PPC64_REL24
)
9310 max_branch_offset
= 1 << 15;
9312 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
9313 /* We need a stub. Figure out whether a long_branch or plt_branch
9315 return ppc_stub_long_branch
;
9317 return ppc_stub_none
;
9320 /* Build a .plt call stub. */
9322 static inline bfd_byte
*
9323 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
, Elf_Internal_Rela
*r
)
9325 #define PPC_LO(v) ((v) & 0xffff)
9326 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9327 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9329 if (PPC_HA (offset
) != 0)
9333 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9334 r
[1].r_offset
= r
[0].r_offset
+ 8;
9335 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9336 r
[1].r_addend
= r
[0].r_addend
;
9337 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9339 r
[2].r_offset
= r
[1].r_offset
+ 4;
9340 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9341 r
[2].r_addend
= r
[0].r_addend
;
9345 r
[2].r_offset
= r
[1].r_offset
+ 8;
9346 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9347 r
[2].r_addend
= r
[0].r_addend
+ 8;
9348 r
[3].r_offset
= r
[2].r_offset
+ 4;
9349 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9350 r
[3].r_addend
= r
[0].r_addend
+ 16;
9353 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9354 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9355 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
9356 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9358 bfd_put_32 (obfd
, ADDI_R12_R12
| PPC_LO (offset
), p
), p
+= 4;
9361 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9362 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
+ 8), p
), p
+= 4;
9363 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
+ 16), p
), p
+= 4;
9364 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9371 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9372 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9374 r
[1].r_offset
= r
[0].r_offset
+ 4;
9375 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9376 r
[1].r_addend
= r
[0].r_addend
;
9380 r
[1].r_offset
= r
[0].r_offset
+ 8;
9381 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9382 r
[1].r_addend
= r
[0].r_addend
+ 16;
9383 r
[2].r_offset
= r
[1].r_offset
+ 4;
9384 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9385 r
[2].r_addend
= r
[0].r_addend
+ 8;
9388 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
9389 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
), p
), p
+= 4;
9390 if (PPC_HA (offset
+ 16) != PPC_HA (offset
))
9392 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9395 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
9396 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9397 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9398 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9403 /* Build a special .plt call stub for __tls_get_addr. */
9405 #define LD_R11_0R3 0xe9630000
9406 #define LD_R12_0R3 0xe9830000
9407 #define MR_R0_R3 0x7c601b78
9408 #define CMPDI_R11_0 0x2c2b0000
9409 #define ADD_R3_R12_R13 0x7c6c6a14
9410 #define BEQLR 0x4d820020
9411 #define MR_R3_R0 0x7c030378
9412 #define MFLR_R11 0x7d6802a6
9413 #define STD_R11_0R1 0xf9610000
9414 #define BCTRL 0x4e800421
9415 #define LD_R11_0R1 0xe9610000
9416 #define LD_R2_0R1 0xe8410000
9417 #define MTLR_R11 0x7d6803a6
9419 static inline bfd_byte
*
9420 build_tls_get_addr_stub (bfd
*obfd
, bfd_byte
*p
, int offset
,
9421 Elf_Internal_Rela
*r
)
9423 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9424 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9425 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9426 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9427 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9428 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9429 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9430 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9431 bfd_put_32 (obfd
, STD_R11_0R1
+ 32, p
), p
+= 4;
9434 r
[0].r_offset
+= 9 * 4;
9435 p
= build_plt_stub (obfd
, p
, offset
, r
);
9436 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9438 bfd_put_32 (obfd
, LD_R11_0R1
+ 32, p
), p
+= 4;
9439 bfd_put_32 (obfd
, LD_R2_0R1
+ 40, p
), p
+= 4;
9440 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9441 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9446 static Elf_Internal_Rela
*
9447 get_relocs (asection
*sec
, int count
)
9449 Elf_Internal_Rela
*relocs
;
9450 struct bfd_elf_section_data
*elfsec_data
;
9452 elfsec_data
= elf_section_data (sec
);
9453 relocs
= elfsec_data
->relocs
;
9456 bfd_size_type relsize
;
9457 relsize
= sec
->reloc_count
* sizeof (*relocs
);
9458 relocs
= bfd_alloc (sec
->owner
, relsize
);
9461 elfsec_data
->relocs
= relocs
;
9462 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
9463 sizeof (Elf_Internal_Shdr
));
9464 if (elfsec_data
->rela
.hdr
== NULL
)
9466 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
9467 * sizeof (Elf64_External_Rela
));
9468 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
9469 sec
->reloc_count
= 0;
9471 relocs
+= sec
->reloc_count
;
9472 sec
->reloc_count
+= count
;
9477 get_r2off (struct bfd_link_info
*info
,
9478 struct ppc_stub_hash_entry
*stub_entry
)
9480 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9481 bfd_vma r2off
= htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
;
9485 /* Support linking -R objects. Get the toc pointer from the
9488 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
9489 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
9491 if (strcmp (opd
->name
, ".opd") != 0
9492 || opd
->reloc_count
!= 0)
9494 info
->callbacks
->einfo (_("cannot find opd entry toc for %s\n"),
9495 stub_entry
->h
->elf
.root
.root
.string
);
9496 bfd_set_error (bfd_error_bad_value
);
9499 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
9501 r2off
= bfd_get_64 (opd
->owner
, buf
);
9502 r2off
-= elf_gp (info
->output_bfd
);
9504 r2off
-= htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
;
9509 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9511 struct ppc_stub_hash_entry
*stub_entry
;
9512 struct ppc_branch_hash_entry
*br_entry
;
9513 struct bfd_link_info
*info
;
9514 struct ppc_link_hash_table
*htab
;
9519 Elf_Internal_Rela
*r
;
9522 /* Massage our args to the form they really have. */
9523 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9526 htab
= ppc_hash_table (info
);
9530 /* Make a note of the offset within the stubs for this entry. */
9531 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
9532 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
9534 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
9535 switch (stub_entry
->stub_type
)
9537 case ppc_stub_long_branch
:
9538 case ppc_stub_long_branch_r2off
:
9539 /* Branches are relative. This is where we are going to. */
9540 off
= dest
= (stub_entry
->target_value
9541 + stub_entry
->target_section
->output_offset
9542 + stub_entry
->target_section
->output_section
->vma
);
9544 /* And this is where we are coming from. */
9545 off
-= (stub_entry
->stub_offset
9546 + stub_entry
->stub_sec
->output_offset
9547 + stub_entry
->stub_sec
->output_section
->vma
);
9550 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9552 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9556 htab
->stub_error
= TRUE
;
9559 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9562 if (PPC_HA (r2off
) != 0)
9565 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9568 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9572 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
9574 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
9576 info
->callbacks
->einfo (_("long branch stub `%s' offset overflow\n"),
9577 stub_entry
->root
.string
);
9578 htab
->stub_error
= TRUE
;
9582 if (info
->emitrelocations
)
9584 r
= get_relocs (stub_entry
->stub_sec
, 1);
9587 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9588 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
9590 if (stub_entry
->h
!= NULL
)
9592 struct elf_link_hash_entry
**hashes
;
9593 unsigned long symndx
;
9594 struct ppc_link_hash_entry
*h
;
9596 hashes
= elf_sym_hashes (htab
->stub_bfd
);
9599 bfd_size_type hsize
;
9601 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
9602 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
9605 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
9606 htab
->stub_globals
= 1;
9608 symndx
= htab
->stub_globals
++;
9610 hashes
[symndx
] = &h
->elf
;
9611 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
9612 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
9613 h
= ppc_follow_link (h
->oh
);
9614 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
9615 /* H is an opd symbol. The addend must be zero. */
9619 off
= (h
->elf
.root
.u
.def
.value
9620 + h
->elf
.root
.u
.def
.section
->output_offset
9621 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
9628 case ppc_stub_plt_branch
:
9629 case ppc_stub_plt_branch_r2off
:
9630 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
9631 stub_entry
->root
.string
+ 9,
9633 if (br_entry
== NULL
)
9635 info
->callbacks
->einfo (_("can't find branch stub `%s'\n"),
9636 stub_entry
->root
.string
);
9637 htab
->stub_error
= TRUE
;
9641 dest
= (stub_entry
->target_value
9642 + stub_entry
->target_section
->output_offset
9643 + stub_entry
->target_section
->output_section
->vma
);
9645 bfd_put_64 (htab
->brlt
->owner
, dest
,
9646 htab
->brlt
->contents
+ br_entry
->offset
);
9648 if (br_entry
->iter
== htab
->stub_iteration
)
9652 if (htab
->relbrlt
!= NULL
)
9654 /* Create a reloc for the branch lookup table entry. */
9655 Elf_Internal_Rela rela
;
9658 rela
.r_offset
= (br_entry
->offset
9659 + htab
->brlt
->output_offset
9660 + htab
->brlt
->output_section
->vma
);
9661 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9662 rela
.r_addend
= dest
;
9664 rl
= htab
->relbrlt
->contents
;
9665 rl
+= (htab
->relbrlt
->reloc_count
++
9666 * sizeof (Elf64_External_Rela
));
9667 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
9669 else if (info
->emitrelocations
)
9671 r
= get_relocs (htab
->brlt
, 1);
9674 /* brlt, being SEC_LINKER_CREATED does not go through the
9675 normal reloc processing. Symbols and offsets are not
9676 translated from input file to output file form, so
9677 set up the offset per the output file. */
9678 r
->r_offset
= (br_entry
->offset
9679 + htab
->brlt
->output_offset
9680 + htab
->brlt
->output_section
->vma
);
9681 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
9686 dest
= (br_entry
->offset
9687 + htab
->brlt
->output_offset
9688 + htab
->brlt
->output_section
->vma
);
9691 - elf_gp (htab
->brlt
->output_section
->owner
)
9692 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9694 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9696 info
->callbacks
->einfo
9697 (_("linkage table error against `%s'\n"),
9698 stub_entry
->root
.string
);
9699 bfd_set_error (bfd_error_bad_value
);
9700 htab
->stub_error
= TRUE
;
9704 if (info
->emitrelocations
)
9706 r
= get_relocs (stub_entry
->stub_sec
, 1 + (PPC_HA (off
) != 0));
9709 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9710 if (bfd_big_endian (info
->output_bfd
))
9712 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
9714 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9715 r
[0].r_addend
= dest
;
9716 if (PPC_HA (off
) != 0)
9718 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9719 r
[1].r_offset
= r
[0].r_offset
+ 4;
9720 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9721 r
[1].r_addend
= r
[0].r_addend
;
9725 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
9727 if (PPC_HA (off
) != 0)
9730 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9732 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9737 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9742 bfd_vma r2off
= get_r2off (info
, stub_entry
);
9746 htab
->stub_error
= TRUE
;
9750 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
9753 if (PPC_HA (off
) != 0)
9756 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (off
), loc
);
9758 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (off
), loc
);
9763 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R2
| PPC_LO (off
), loc
);
9767 if (PPC_HA (r2off
) != 0)
9770 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
9773 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
9776 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
9778 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
9781 case ppc_stub_plt_call
:
9782 if (stub_entry
->h
!= NULL
9783 && stub_entry
->h
->is_func_descriptor
9784 && stub_entry
->h
->oh
!= NULL
)
9786 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
9788 /* If the old-ABI "dot-symbol" is undefined make it weak so
9789 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
9790 FIXME: We used to define the symbol on one of the call
9791 stubs instead, which is why we test symbol section id
9792 against htab->top_id in various places. Likely all
9793 these checks could now disappear. */
9794 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
9795 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
9796 /* Stop undo_symbol_twiddle changing it back to undefined. */
9797 fh
->was_undefined
= 0;
9800 /* Now build the stub. */
9801 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9802 if (dest
>= (bfd_vma
) -2)
9806 if (!htab
->elf
.dynamic_sections_created
9807 || stub_entry
->h
== NULL
9808 || stub_entry
->h
->elf
.dynindx
== -1)
9811 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
9813 if (stub_entry
->h
== NULL
9814 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
9816 Elf_Internal_Rela rela
;
9819 rela
.r_offset
= dest
;
9820 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
9821 rela
.r_addend
= (stub_entry
->target_value
9822 + stub_entry
->target_section
->output_offset
9823 + stub_entry
->target_section
->output_section
->vma
);
9825 rl
= (htab
->reliplt
->contents
9826 + (htab
->reliplt
->reloc_count
++
9827 * sizeof (Elf64_External_Rela
)));
9828 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
9829 stub_entry
->plt_ent
->plt
.offset
|= 1;
9833 - elf_gp (plt
->output_section
->owner
)
9834 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9836 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
9838 info
->callbacks
->einfo
9839 (_("linkage table error against `%s'\n"),
9840 stub_entry
->h
!= NULL
9841 ? stub_entry
->h
->elf
.root
.root
.string
9843 bfd_set_error (bfd_error_bad_value
);
9844 htab
->stub_error
= TRUE
;
9849 if (info
->emitrelocations
)
9851 r
= get_relocs (stub_entry
->stub_sec
,
9852 (2 + (PPC_HA (off
) != 0)
9853 + (PPC_HA (off
+ 16) == PPC_HA (off
))));
9856 r
[0].r_offset
= loc
- stub_entry
->stub_sec
->contents
;
9857 if (bfd_big_endian (info
->output_bfd
))
9859 r
[0].r_addend
= dest
;
9861 if (stub_entry
->h
!= NULL
9862 && (stub_entry
->h
== htab
->tls_get_addr_fd
9863 || stub_entry
->h
== htab
->tls_get_addr
)
9864 && !htab
->no_tls_get_addr_opt
)
9865 p
= build_tls_get_addr_stub (htab
->stub_bfd
, loc
, off
, r
);
9867 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
, r
);
9876 stub_entry
->stub_sec
->size
+= size
;
9878 if (htab
->emit_stub_syms
)
9880 struct elf_link_hash_entry
*h
;
9883 const char *const stub_str
[] = { "long_branch",
9884 "long_branch_r2off",
9889 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
9890 len2
= strlen (stub_entry
->root
.string
);
9891 name
= bfd_malloc (len1
+ len2
+ 2);
9894 memcpy (name
, stub_entry
->root
.string
, 9);
9895 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
9896 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
9897 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
9900 if (h
->root
.type
== bfd_link_hash_new
)
9902 h
->root
.type
= bfd_link_hash_defined
;
9903 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
9904 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
9907 h
->ref_regular_nonweak
= 1;
9908 h
->forced_local
= 1;
9916 /* As above, but don't actually build the stub. Just bump offset so
9917 we know stub section sizes, and select plt_branch stubs where
9918 long_branch stubs won't do. */
9921 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
9923 struct ppc_stub_hash_entry
*stub_entry
;
9924 struct bfd_link_info
*info
;
9925 struct ppc_link_hash_table
*htab
;
9929 /* Massage our args to the form they really have. */
9930 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
9933 htab
= ppc_hash_table (info
);
9937 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
9940 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
9941 if (off
>= (bfd_vma
) -2)
9944 if (!htab
->elf
.dynamic_sections_created
9945 || stub_entry
->h
== NULL
9946 || stub_entry
->h
->elf
.dynindx
== -1)
9948 off
+= (plt
->output_offset
9949 + plt
->output_section
->vma
9950 - elf_gp (plt
->output_section
->owner
)
9951 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
9953 size
= PLT_CALL_STUB_SIZE
;
9954 if (PPC_HA (off
) == 0)
9956 if (PPC_HA (off
+ 16) != PPC_HA (off
))
9958 if (stub_entry
->h
!= NULL
9959 && (stub_entry
->h
== htab
->tls_get_addr_fd
9960 || stub_entry
->h
== htab
->tls_get_addr
)
9961 && !htab
->no_tls_get_addr_opt
)
9963 if (info
->emitrelocations
)
9965 stub_entry
->stub_sec
->reloc_count
9966 += 2 + (PPC_HA (off
) != 0) + (PPC_HA (off
+ 16) == PPC_HA (off
));
9967 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
9972 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
9976 off
= (stub_entry
->target_value
9977 + stub_entry
->target_section
->output_offset
9978 + stub_entry
->target_section
->output_section
->vma
);
9979 off
-= (stub_entry
->stub_sec
->size
9980 + stub_entry
->stub_sec
->output_offset
9981 + stub_entry
->stub_sec
->output_section
->vma
);
9983 /* Reset the stub type from the plt variant in case we now
9984 can reach with a shorter stub. */
9985 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
9986 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
9989 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
9991 r2off
= get_r2off (info
, stub_entry
);
9994 htab
->stub_error
= TRUE
;
9998 if (PPC_HA (r2off
) != 0)
10003 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
10004 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10006 struct ppc_branch_hash_entry
*br_entry
;
10008 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10009 stub_entry
->root
.string
+ 9,
10011 if (br_entry
== NULL
)
10013 info
->callbacks
->einfo (_("can't build branch stub `%s'\n"),
10014 stub_entry
->root
.string
);
10015 htab
->stub_error
= TRUE
;
10019 if (br_entry
->iter
!= htab
->stub_iteration
)
10021 br_entry
->iter
= htab
->stub_iteration
;
10022 br_entry
->offset
= htab
->brlt
->size
;
10023 htab
->brlt
->size
+= 8;
10025 if (htab
->relbrlt
!= NULL
)
10026 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10027 else if (info
->emitrelocations
)
10029 htab
->brlt
->reloc_count
+= 1;
10030 htab
->brlt
->flags
|= SEC_RELOC
;
10034 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
10035 off
= (br_entry
->offset
10036 + htab
->brlt
->output_offset
10037 + htab
->brlt
->output_section
->vma
10038 - elf_gp (htab
->brlt
->output_section
->owner
)
10039 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
10041 if (info
->emitrelocations
)
10043 stub_entry
->stub_sec
->reloc_count
+= 1 + (PPC_HA (off
) != 0);
10044 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10047 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10050 if (PPC_HA (off
) != 0)
10056 if (PPC_HA (off
) != 0)
10059 if (PPC_HA (r2off
) != 0)
10063 else if (info
->emitrelocations
)
10065 stub_entry
->stub_sec
->reloc_count
+= 1;
10066 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
10070 stub_entry
->stub_sec
->size
+= size
;
10074 /* Set up various things so that we can make a list of input sections
10075 for each output section included in the link. Returns -1 on error,
10076 0 when no stubs will be needed, and 1 on success. */
10079 ppc64_elf_setup_section_lists
10080 (struct bfd_link_info
*info
,
10081 asection
*(*add_stub_section
) (const char *, asection
*),
10082 void (*layout_sections_again
) (void))
10085 int top_id
, top_index
, id
;
10087 asection
**input_list
;
10089 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10093 /* Stash our params away. */
10094 htab
->add_stub_section
= add_stub_section
;
10095 htab
->layout_sections_again
= layout_sections_again
;
10097 if (htab
->brlt
== NULL
)
10100 /* Find the top input section id. */
10101 for (input_bfd
= info
->input_bfds
, top_id
= 3;
10103 input_bfd
= input_bfd
->link_next
)
10105 for (section
= input_bfd
->sections
;
10107 section
= section
->next
)
10109 if (top_id
< section
->id
)
10110 top_id
= section
->id
;
10114 htab
->top_id
= top_id
;
10115 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
10116 htab
->stub_group
= bfd_zmalloc (amt
);
10117 if (htab
->stub_group
== NULL
)
10120 /* Set toc_off for com, und, abs and ind sections. */
10121 for (id
= 0; id
< 3; id
++)
10122 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
10124 /* We can't use output_bfd->section_count here to find the top output
10125 section index as some sections may have been removed, and
10126 strip_excluded_output_sections doesn't renumber the indices. */
10127 for (section
= info
->output_bfd
->sections
, top_index
= 0;
10129 section
= section
->next
)
10131 if (top_index
< section
->index
)
10132 top_index
= section
->index
;
10135 htab
->top_index
= top_index
;
10136 amt
= sizeof (asection
*) * (top_index
+ 1);
10137 input_list
= bfd_zmalloc (amt
);
10138 htab
->input_list
= input_list
;
10139 if (input_list
== NULL
)
10145 /* Set up for first pass at multitoc partitioning. */
10148 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10150 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10152 elf_gp (info
->output_bfd
) = ppc64_elf_toc (info
->output_bfd
);
10153 htab
->toc_curr
= elf_gp (info
->output_bfd
);
10154 htab
->toc_bfd
= NULL
;
10155 htab
->toc_first_sec
= NULL
;
10158 /* The linker repeatedly calls this function for each TOC input section
10159 and linker generated GOT section. Group input bfds such that the toc
10160 within a group is less than 64k in size. */
10163 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10165 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10166 bfd_vma addr
, off
, limit
;
10171 if (!htab
->second_toc_pass
)
10173 /* Keep track of the first .toc or .got section for this input bfd. */
10174 if (htab
->toc_bfd
!= isec
->owner
)
10176 htab
->toc_bfd
= isec
->owner
;
10177 htab
->toc_first_sec
= isec
;
10180 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10181 off
= addr
- htab
->toc_curr
;
10182 limit
= 0x80008000;
10183 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10185 if (off
+ isec
->size
> limit
)
10187 addr
= (htab
->toc_first_sec
->output_offset
10188 + htab
->toc_first_sec
->output_section
->vma
);
10189 htab
->toc_curr
= addr
;
10192 /* toc_curr is the base address of this toc group. Set elf_gp
10193 for the input section to be the offset relative to the
10194 output toc base plus 0x8000. Making the input elf_gp an
10195 offset allows us to move the toc as a whole without
10196 recalculating input elf_gp. */
10197 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
10198 off
+= TOC_BASE_OFF
;
10200 /* Die if someone uses a linker script that doesn't keep input
10201 file .toc and .got together. */
10202 if (elf_gp (isec
->owner
) != 0
10203 && elf_gp (isec
->owner
) != off
)
10206 elf_gp (isec
->owner
) = off
;
10210 /* During the second pass toc_first_sec points to the start of
10211 a toc group, and toc_curr is used to track the old elf_gp.
10212 We use toc_bfd to ensure we only look at each bfd once. */
10213 if (htab
->toc_bfd
== isec
->owner
)
10215 htab
->toc_bfd
= isec
->owner
;
10217 if (htab
->toc_first_sec
== NULL
10218 || htab
->toc_curr
!= elf_gp (isec
->owner
))
10220 htab
->toc_curr
= elf_gp (isec
->owner
);
10221 htab
->toc_first_sec
= isec
;
10223 addr
= (htab
->toc_first_sec
->output_offset
10224 + htab
->toc_first_sec
->output_section
->vma
);
10225 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
10226 elf_gp (isec
->owner
) = off
;
10231 /* Called via elf_link_hash_traverse to merge GOT entries for global
10235 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
10237 if (h
->root
.type
== bfd_link_hash_indirect
)
10240 if (h
->root
.type
== bfd_link_hash_warning
)
10241 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10243 merge_got_entries (&h
->got
.glist
);
10248 /* Called via elf_link_hash_traverse to allocate GOT entries for global
10252 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
10254 struct got_entry
*gent
;
10256 if (h
->root
.type
== bfd_link_hash_indirect
)
10259 if (h
->root
.type
== bfd_link_hash_warning
)
10260 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10262 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
10263 if (!gent
->is_indirect
)
10264 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
10268 /* Called on the first multitoc pass after the last call to
10269 ppc64_elf_next_toc_section. This function removes duplicate GOT
10273 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
10275 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10276 struct bfd
*ibfd
, *ibfd2
;
10277 bfd_boolean done_something
;
10279 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
10281 if (!htab
->do_multi_toc
)
10284 /* Merge global sym got entries within a toc group. */
10285 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
10287 /* And tlsld_got. */
10288 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10290 struct got_entry
*ent
, *ent2
;
10292 if (!is_ppc64_elf (ibfd
))
10295 ent
= ppc64_tlsld_got (ibfd
);
10296 if (!ent
->is_indirect
10297 && ent
->got
.offset
!= (bfd_vma
) -1)
10299 for (ibfd2
= ibfd
->link_next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link_next
)
10301 if (!is_ppc64_elf (ibfd2
))
10304 ent2
= ppc64_tlsld_got (ibfd2
);
10305 if (!ent2
->is_indirect
10306 && ent2
->got
.offset
!= (bfd_vma
) -1
10307 && elf_gp (ibfd2
) == elf_gp (ibfd
))
10309 ent2
->is_indirect
= TRUE
;
10310 ent2
->got
.ent
= ent
;
10316 /* Zap sizes of got sections. */
10317 htab
->reliplt
->rawsize
= htab
->reliplt
->size
;
10318 htab
->reliplt
->size
-= htab
->got_reli_size
;
10319 htab
->got_reli_size
= 0;
10321 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10323 asection
*got
, *relgot
;
10325 if (!is_ppc64_elf (ibfd
))
10328 got
= ppc64_elf_tdata (ibfd
)->got
;
10331 got
->rawsize
= got
->size
;
10333 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
10334 relgot
->rawsize
= relgot
->size
;
10339 /* Now reallocate the got, local syms first. We don't need to
10340 allocate section contents again since we never increase size. */
10341 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10343 struct got_entry
**lgot_ents
;
10344 struct got_entry
**end_lgot_ents
;
10345 struct plt_entry
**local_plt
;
10346 struct plt_entry
**end_local_plt
;
10347 unsigned char *lgot_masks
;
10348 bfd_size_type locsymcount
;
10349 Elf_Internal_Shdr
*symtab_hdr
;
10350 asection
*s
, *srel
;
10352 if (!is_ppc64_elf (ibfd
))
10355 lgot_ents
= elf_local_got_ents (ibfd
);
10359 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10360 locsymcount
= symtab_hdr
->sh_info
;
10361 end_lgot_ents
= lgot_ents
+ locsymcount
;
10362 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10363 end_local_plt
= local_plt
+ locsymcount
;
10364 lgot_masks
= (unsigned char *) end_local_plt
;
10365 s
= ppc64_elf_tdata (ibfd
)->got
;
10366 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10367 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10369 struct got_entry
*ent
;
10371 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
10373 unsigned int num
= 1;
10374 ent
->got
.offset
= s
->size
;
10375 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10377 s
->size
+= num
* 8;
10379 srel
->size
+= num
* sizeof (Elf64_External_Rela
);
10380 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
10382 htab
->reliplt
->size
10383 += num
* sizeof (Elf64_External_Rela
);
10384 htab
->got_reli_size
10385 += num
* sizeof (Elf64_External_Rela
);
10391 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
10393 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10395 struct got_entry
*ent
;
10397 if (!is_ppc64_elf (ibfd
))
10400 ent
= ppc64_tlsld_got (ibfd
);
10401 if (!ent
->is_indirect
10402 && ent
->got
.offset
!= (bfd_vma
) -1)
10404 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
10405 ent
->got
.offset
= s
->size
;
10409 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10410 srel
->size
+= sizeof (Elf64_External_Rela
);
10415 done_something
= htab
->reliplt
->rawsize
!= htab
->reliplt
->size
;
10416 if (!done_something
)
10417 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10421 if (!is_ppc64_elf (ibfd
))
10424 got
= ppc64_elf_tdata (ibfd
)->got
;
10427 done_something
= got
->rawsize
!= got
->size
;
10428 if (done_something
)
10433 if (done_something
)
10434 (*htab
->layout_sections_again
) ();
10436 /* Set up for second pass over toc sections to recalculate elf_gp
10437 on input sections. */
10438 htab
->toc_bfd
= NULL
;
10439 htab
->toc_first_sec
= NULL
;
10440 htab
->second_toc_pass
= TRUE
;
10441 return done_something
;
10444 /* Called after second pass of multitoc partitioning. */
10447 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
10449 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10451 /* After the second pass, toc_curr tracks the TOC offset used
10452 for code sections below in ppc64_elf_next_input_section. */
10453 htab
->toc_curr
= TOC_BASE_OFF
;
10456 /* No toc references were found in ISEC. If the code in ISEC makes no
10457 calls, then there's no need to use toc adjusting stubs when branching
10458 into ISEC. Actually, indirect calls from ISEC are OK as they will
10459 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
10460 needed, and 2 if a cyclical call-graph was found but no other reason
10461 for a stub was detected. If called from the top level, a return of
10462 2 means the same as a return of 0. */
10465 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
10469 /* Mark this section as checked. */
10470 isec
->call_check_done
= 1;
10472 /* We know none of our code bearing sections will need toc stubs. */
10473 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
10476 if (isec
->size
== 0)
10479 if (isec
->output_section
== NULL
)
10483 if (isec
->reloc_count
!= 0)
10485 Elf_Internal_Rela
*relstart
, *rel
;
10486 Elf_Internal_Sym
*local_syms
;
10487 struct ppc_link_hash_table
*htab
;
10489 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
10490 info
->keep_memory
);
10491 if (relstart
== NULL
)
10494 /* Look for branches to outside of this section. */
10496 htab
= ppc_hash_table (info
);
10500 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
10502 enum elf_ppc64_reloc_type r_type
;
10503 unsigned long r_symndx
;
10504 struct elf_link_hash_entry
*h
;
10505 struct ppc_link_hash_entry
*eh
;
10506 Elf_Internal_Sym
*sym
;
10508 struct _opd_sec_data
*opd
;
10512 r_type
= ELF64_R_TYPE (rel
->r_info
);
10513 if (r_type
!= R_PPC64_REL24
10514 && r_type
!= R_PPC64_REL14
10515 && r_type
!= R_PPC64_REL14_BRTAKEN
10516 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
10519 r_symndx
= ELF64_R_SYM (rel
->r_info
);
10520 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
10527 /* Calls to dynamic lib functions go through a plt call stub
10529 eh
= (struct ppc_link_hash_entry
*) h
;
10531 && (eh
->elf
.plt
.plist
!= NULL
10533 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
10539 if (sym_sec
== NULL
)
10540 /* Ignore other undefined symbols. */
10543 /* Assume branches to other sections not included in the
10544 link need stubs too, to cover -R and absolute syms. */
10545 if (sym_sec
->output_section
== NULL
)
10552 sym_value
= sym
->st_value
;
10555 if (h
->root
.type
!= bfd_link_hash_defined
10556 && h
->root
.type
!= bfd_link_hash_defweak
)
10558 sym_value
= h
->root
.u
.def
.value
;
10560 sym_value
+= rel
->r_addend
;
10562 /* If this branch reloc uses an opd sym, find the code section. */
10563 opd
= get_opd_info (sym_sec
);
10566 if (h
== NULL
&& opd
->adjust
!= NULL
)
10570 adjust
= opd
->adjust
[sym
->st_value
/ 8];
10572 /* Assume deleted functions won't ever be called. */
10574 sym_value
+= adjust
;
10577 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
10578 if (dest
== (bfd_vma
) -1)
10583 + sym_sec
->output_offset
10584 + sym_sec
->output_section
->vma
);
10586 /* Ignore branch to self. */
10587 if (sym_sec
== isec
)
10590 /* If the called function uses the toc, we need a stub. */
10591 if (sym_sec
->has_toc_reloc
10592 || sym_sec
->makes_toc_func_call
)
10598 /* Assume any branch that needs a long branch stub might in fact
10599 need a plt_branch stub. A plt_branch stub uses r2. */
10600 else if (dest
- (isec
->output_offset
10601 + isec
->output_section
->vma
10602 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
10608 /* If calling back to a section in the process of being
10609 tested, we can't say for sure that no toc adjusting stubs
10610 are needed, so don't return zero. */
10611 else if (sym_sec
->call_check_in_progress
)
10614 /* Branches to another section that itself doesn't have any TOC
10615 references are OK. Recursively call ourselves to check. */
10616 else if (!sym_sec
->call_check_done
)
10620 /* Mark current section as indeterminate, so that other
10621 sections that call back to current won't be marked as
10623 isec
->call_check_in_progress
= 1;
10624 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
10625 isec
->call_check_in_progress
= 0;
10636 if (local_syms
!= NULL
10637 && (elf_symtab_hdr (isec
->owner
).contents
10638 != (unsigned char *) local_syms
))
10640 if (elf_section_data (isec
)->relocs
!= relstart
)
10645 && isec
->map_head
.s
!= NULL
10646 && (strcmp (isec
->output_section
->name
, ".init") == 0
10647 || strcmp (isec
->output_section
->name
, ".fini") == 0))
10649 if (isec
->map_head
.s
->has_toc_reloc
10650 || isec
->map_head
.s
->makes_toc_func_call
)
10652 else if (!isec
->map_head
.s
->call_check_done
)
10655 isec
->call_check_in_progress
= 1;
10656 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
10657 isec
->call_check_in_progress
= 0;
10664 isec
->makes_toc_func_call
= 1;
10669 /* The linker repeatedly calls this function for each input section,
10670 in the order that input sections are linked into output sections.
10671 Build lists of input sections to determine groupings between which
10672 we may insert linker stubs. */
10675 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
10677 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10682 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
10683 && isec
->output_section
->index
<= htab
->top_index
)
10685 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
10686 /* Steal the link_sec pointer for our list. */
10687 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
10688 /* This happens to make the list in reverse order,
10689 which is what we want. */
10690 PREV_SEC (isec
) = *list
;
10694 if (htab
->multi_toc_needed
)
10696 /* If a code section has a function that uses the TOC then we need
10697 to use the right TOC (obviously). Also, make sure that .opd gets
10698 the correct TOC value for R_PPC64_TOC relocs that don't have or
10699 can't find their function symbol (shouldn't ever happen now).
10700 Also specially treat .fixup for the linux kernel. .fixup
10701 contains branches, but only back to the function that hit an
10703 if (isec
->has_toc_reloc
10704 || (isec
->flags
& SEC_CODE
) == 0
10705 || strcmp (isec
->name
, ".fixup") == 0)
10707 if (elf_gp (isec
->owner
) != 0)
10708 htab
->toc_curr
= elf_gp (isec
->owner
);
10712 if (!isec
->call_check_done
10713 && toc_adjusting_stub_needed (info
, isec
) < 0)
10715 /* If we make a local call from this section, ie. a branch
10716 without a following nop, then we have no place to put a
10717 toc restoring insn. We must use the same toc group as
10719 Testing makes_toc_func_call actually tests for *any*
10720 calls to functions that need a good toc pointer. A more
10721 precise test would be better, as this one will set
10722 incorrect values for pasted .init/.fini fragments.
10723 (Fixed later in check_pasted_section.) */
10724 if (isec
->makes_toc_func_call
10725 && elf_gp (isec
->owner
) != 0)
10726 htab
->toc_curr
= elf_gp (isec
->owner
);
10730 /* Functions that don't use the TOC can belong in any TOC group.
10731 Use the last TOC base. */
10732 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
10736 /* Check that all .init and .fini sections use the same toc, if they
10737 have toc relocs. */
10740 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
10742 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
10746 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10747 bfd_vma toc_off
= 0;
10750 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10751 if (i
->has_toc_reloc
)
10754 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10755 else if (toc_off
!= htab
->stub_group
[i
->id
].toc_off
)
10760 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10761 if (i
->makes_toc_func_call
)
10763 toc_off
= htab
->stub_group
[i
->id
].toc_off
;
10767 /* Make sure the whole pasted function uses the same toc offset. */
10769 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
10770 htab
->stub_group
[i
->id
].toc_off
= toc_off
;
10776 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
10778 return (check_pasted_section (info
, ".init")
10779 & check_pasted_section (info
, ".fini"));
10782 /* See whether we can group stub sections together. Grouping stub
10783 sections may result in fewer stubs. More importantly, we need to
10784 put all .init* and .fini* stubs at the beginning of the .init or
10785 .fini output sections respectively, because glibc splits the
10786 _init and _fini functions into multiple parts. Putting a stub in
10787 the middle of a function is not a good idea. */
10790 group_sections (struct ppc_link_hash_table
*htab
,
10791 bfd_size_type stub_group_size
,
10792 bfd_boolean stubs_always_before_branch
)
10795 bfd_size_type stub14_group_size
;
10796 bfd_boolean suppress_size_errors
;
10798 suppress_size_errors
= FALSE
;
10799 stub14_group_size
= stub_group_size
;
10800 if (stub_group_size
== 1)
10802 /* Default values. */
10803 if (stubs_always_before_branch
)
10805 stub_group_size
= 0x1e00000;
10806 stub14_group_size
= 0x7800;
10810 stub_group_size
= 0x1c00000;
10811 stub14_group_size
= 0x7000;
10813 suppress_size_errors
= TRUE
;
10816 list
= htab
->input_list
+ htab
->top_index
;
10819 asection
*tail
= *list
;
10820 while (tail
!= NULL
)
10824 bfd_size_type total
;
10825 bfd_boolean big_sec
;
10829 total
= tail
->size
;
10830 big_sec
= total
> (ppc64_elf_section_data (tail
) != NULL
10831 && ppc64_elf_section_data (tail
)->has_14bit_branch
10832 ? stub14_group_size
: stub_group_size
);
10833 if (big_sec
&& !suppress_size_errors
)
10834 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
10835 tail
->owner
, tail
);
10836 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
10838 while ((prev
= PREV_SEC (curr
)) != NULL
10839 && ((total
+= curr
->output_offset
- prev
->output_offset
)
10840 < (ppc64_elf_section_data (prev
) != NULL
10841 && ppc64_elf_section_data (prev
)->has_14bit_branch
10842 ? stub14_group_size
: stub_group_size
))
10843 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10846 /* OK, the size from the start of CURR to the end is less
10847 than stub_group_size and thus can be handled by one stub
10848 section. (or the tail section is itself larger than
10849 stub_group_size, in which case we may be toast.) We
10850 should really be keeping track of the total size of stubs
10851 added here, as stubs contribute to the final output
10852 section size. That's a little tricky, and this way will
10853 only break if stubs added make the total size more than
10854 2^25, ie. for the default stub_group_size, if stubs total
10855 more than 2097152 bytes, or nearly 75000 plt call stubs. */
10858 prev
= PREV_SEC (tail
);
10859 /* Set up this stub group. */
10860 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10862 while (tail
!= curr
&& (tail
= prev
) != NULL
);
10864 /* But wait, there's more! Input sections up to stub_group_size
10865 bytes before the stub section can be handled by it too.
10866 Don't do this if we have a really large section after the
10867 stubs, as adding more stubs increases the chance that
10868 branches may not reach into the stub section. */
10869 if (!stubs_always_before_branch
&& !big_sec
)
10872 while (prev
!= NULL
10873 && ((total
+= tail
->output_offset
- prev
->output_offset
)
10874 < (ppc64_elf_section_data (prev
) != NULL
10875 && ppc64_elf_section_data (prev
)->has_14bit_branch
10876 ? stub14_group_size
: stub_group_size
))
10877 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
10880 prev
= PREV_SEC (tail
);
10881 htab
->stub_group
[tail
->id
].link_sec
= curr
;
10887 while (list
-- != htab
->input_list
);
10888 free (htab
->input_list
);
10892 /* Determine and set the size of the stub section for a final link.
10894 The basic idea here is to examine all the relocations looking for
10895 PC-relative calls to a target that is unreachable with a "bl"
10899 ppc64_elf_size_stubs (struct bfd_link_info
*info
, bfd_signed_vma group_size
)
10901 bfd_size_type stub_group_size
;
10902 bfd_boolean stubs_always_before_branch
;
10903 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10908 stubs_always_before_branch
= group_size
< 0;
10909 if (group_size
< 0)
10910 stub_group_size
= -group_size
;
10912 stub_group_size
= group_size
;
10914 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
10919 unsigned int bfd_indx
;
10920 asection
*stub_sec
;
10922 htab
->stub_iteration
+= 1;
10924 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
10926 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
10928 Elf_Internal_Shdr
*symtab_hdr
;
10930 Elf_Internal_Sym
*local_syms
= NULL
;
10932 if (!is_ppc64_elf (input_bfd
))
10935 /* We'll need the symbol table in a second. */
10936 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
10937 if (symtab_hdr
->sh_info
== 0)
10940 /* Walk over each section attached to the input bfd. */
10941 for (section
= input_bfd
->sections
;
10943 section
= section
->next
)
10945 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
10947 /* If there aren't any relocs, then there's nothing more
10949 if ((section
->flags
& SEC_RELOC
) == 0
10950 || (section
->flags
& SEC_ALLOC
) == 0
10951 || (section
->flags
& SEC_LOAD
) == 0
10952 || (section
->flags
& SEC_CODE
) == 0
10953 || section
->reloc_count
== 0)
10956 /* If this section is a link-once section that will be
10957 discarded, then don't create any stubs. */
10958 if (section
->output_section
== NULL
10959 || section
->output_section
->owner
!= info
->output_bfd
)
10962 /* Get the relocs. */
10964 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
10965 info
->keep_memory
);
10966 if (internal_relocs
== NULL
)
10967 goto error_ret_free_local
;
10969 /* Now examine each relocation. */
10970 irela
= internal_relocs
;
10971 irelaend
= irela
+ section
->reloc_count
;
10972 for (; irela
< irelaend
; irela
++)
10974 enum elf_ppc64_reloc_type r_type
;
10975 unsigned int r_indx
;
10976 enum ppc_stub_type stub_type
;
10977 struct ppc_stub_hash_entry
*stub_entry
;
10978 asection
*sym_sec
, *code_sec
;
10979 bfd_vma sym_value
, code_value
;
10980 bfd_vma destination
;
10981 bfd_boolean ok_dest
;
10982 struct ppc_link_hash_entry
*hash
;
10983 struct ppc_link_hash_entry
*fdh
;
10984 struct elf_link_hash_entry
*h
;
10985 Elf_Internal_Sym
*sym
;
10987 const asection
*id_sec
;
10988 struct _opd_sec_data
*opd
;
10989 struct plt_entry
*plt_ent
;
10991 r_type
= ELF64_R_TYPE (irela
->r_info
);
10992 r_indx
= ELF64_R_SYM (irela
->r_info
);
10994 if (r_type
>= R_PPC64_max
)
10996 bfd_set_error (bfd_error_bad_value
);
10997 goto error_ret_free_internal
;
11000 /* Only look for stubs on branch instructions. */
11001 if (r_type
!= R_PPC64_REL24
11002 && r_type
!= R_PPC64_REL14
11003 && r_type
!= R_PPC64_REL14_BRTAKEN
11004 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11007 /* Now determine the call target, its name, value,
11009 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
11010 r_indx
, input_bfd
))
11011 goto error_ret_free_internal
;
11012 hash
= (struct ppc_link_hash_entry
*) h
;
11019 sym_value
= sym
->st_value
;
11022 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
11023 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
11025 sym_value
= hash
->elf
.root
.u
.def
.value
;
11026 if (sym_sec
->output_section
!= NULL
)
11029 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
11030 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
11032 /* Recognise an old ABI func code entry sym, and
11033 use the func descriptor sym instead if it is
11035 if (hash
->elf
.root
.root
.string
[0] == '.'
11036 && (fdh
= lookup_fdh (hash
, htab
)) != NULL
)
11038 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
11039 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
11041 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
11042 sym_value
= fdh
->elf
.root
.u
.def
.value
;
11043 if (sym_sec
->output_section
!= NULL
)
11052 bfd_set_error (bfd_error_bad_value
);
11053 goto error_ret_free_internal
;
11059 sym_value
+= irela
->r_addend
;
11060 destination
= (sym_value
11061 + sym_sec
->output_offset
11062 + sym_sec
->output_section
->vma
);
11065 code_sec
= sym_sec
;
11066 code_value
= sym_value
;
11067 opd
= get_opd_info (sym_sec
);
11072 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11074 long adjust
= opd
->adjust
[sym_value
/ 8];
11077 code_value
+= adjust
;
11078 sym_value
+= adjust
;
11080 dest
= opd_entry_value (sym_sec
, sym_value
,
11081 &code_sec
, &code_value
);
11082 if (dest
!= (bfd_vma
) -1)
11084 destination
= dest
;
11087 /* Fixup old ABI sym to point at code
11089 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11090 hash
->elf
.root
.u
.def
.section
= code_sec
;
11091 hash
->elf
.root
.u
.def
.value
= code_value
;
11096 /* Determine what (if any) linker stub is needed. */
11098 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11099 &plt_ent
, destination
);
11101 if (stub_type
!= ppc_stub_plt_call
)
11103 /* Check whether we need a TOC adjusting stub.
11104 Since the linker pastes together pieces from
11105 different object files when creating the
11106 _init and _fini functions, it may be that a
11107 call to what looks like a local sym is in
11108 fact a call needing a TOC adjustment. */
11109 if (code_sec
!= NULL
11110 && code_sec
->output_section
!= NULL
11111 && (htab
->stub_group
[code_sec
->id
].toc_off
11112 != htab
->stub_group
[section
->id
].toc_off
)
11113 && (code_sec
->has_toc_reloc
11114 || code_sec
->makes_toc_func_call
))
11115 stub_type
= ppc_stub_long_branch_r2off
;
11118 if (stub_type
== ppc_stub_none
)
11121 /* __tls_get_addr calls might be eliminated. */
11122 if (stub_type
!= ppc_stub_plt_call
11124 && (hash
== htab
->tls_get_addr
11125 || hash
== htab
->tls_get_addr_fd
)
11126 && section
->has_tls_reloc
11127 && irela
!= internal_relocs
)
11129 /* Get tls info. */
11130 unsigned char *tls_mask
;
11132 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
11133 irela
- 1, input_bfd
))
11134 goto error_ret_free_internal
;
11135 if (*tls_mask
!= 0)
11139 /* Support for grouping stub sections. */
11140 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
11142 /* Get the name of this stub. */
11143 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
11145 goto error_ret_free_internal
;
11147 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
11148 stub_name
, FALSE
, FALSE
);
11149 if (stub_entry
!= NULL
)
11151 /* The proper stub has already been created. */
11156 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
11157 if (stub_entry
== NULL
)
11160 error_ret_free_internal
:
11161 if (elf_section_data (section
)->relocs
== NULL
)
11162 free (internal_relocs
);
11163 error_ret_free_local
:
11164 if (local_syms
!= NULL
11165 && (symtab_hdr
->contents
11166 != (unsigned char *) local_syms
))
11171 stub_entry
->stub_type
= stub_type
;
11172 if (stub_type
!= ppc_stub_plt_call
)
11174 stub_entry
->target_value
= code_value
;
11175 stub_entry
->target_section
= code_sec
;
11179 stub_entry
->target_value
= sym_value
;
11180 stub_entry
->target_section
= sym_sec
;
11182 stub_entry
->h
= hash
;
11183 stub_entry
->plt_ent
= plt_ent
;
11184 stub_entry
->addend
= irela
->r_addend
;
11186 if (stub_entry
->h
!= NULL
)
11187 htab
->stub_globals
+= 1;
11190 /* We're done with the internal relocs, free them. */
11191 if (elf_section_data (section
)->relocs
!= internal_relocs
)
11192 free (internal_relocs
);
11195 if (local_syms
!= NULL
11196 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
11198 if (!info
->keep_memory
)
11201 symtab_hdr
->contents
= (unsigned char *) local_syms
;
11205 /* We may have added some stubs. Find out the new size of the
11207 for (stub_sec
= htab
->stub_bfd
->sections
;
11209 stub_sec
= stub_sec
->next
)
11210 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11212 stub_sec
->rawsize
= stub_sec
->size
;
11213 stub_sec
->size
= 0;
11214 stub_sec
->reloc_count
= 0;
11215 stub_sec
->flags
&= ~SEC_RELOC
;
11218 htab
->brlt
->size
= 0;
11219 htab
->brlt
->reloc_count
= 0;
11220 htab
->brlt
->flags
&= ~SEC_RELOC
;
11221 if (htab
->relbrlt
!= NULL
)
11222 htab
->relbrlt
->size
= 0;
11224 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
11226 if (info
->emitrelocations
11227 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11229 htab
->glink
->reloc_count
= 1;
11230 htab
->glink
->flags
|= SEC_RELOC
;
11233 for (stub_sec
= htab
->stub_bfd
->sections
;
11235 stub_sec
= stub_sec
->next
)
11236 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11237 && stub_sec
->rawsize
!= stub_sec
->size
)
11240 /* Exit from this loop when no stubs have been added, and no stubs
11241 have changed size. */
11242 if (stub_sec
== NULL
)
11245 /* Ask the linker to do its stuff. */
11246 (*htab
->layout_sections_again
) ();
11249 /* It would be nice to strip htab->brlt from the output if the
11250 section is empty, but it's too late. If we strip sections here,
11251 the dynamic symbol table is corrupted since the section symbol
11252 for the stripped section isn't written. */
11257 /* Called after we have determined section placement. If sections
11258 move, we'll be called again. Provide a value for TOCstart. */
11261 ppc64_elf_toc (bfd
*obfd
)
11266 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
11267 order. The TOC starts where the first of these sections starts. */
11268 s
= bfd_get_section_by_name (obfd
, ".got");
11269 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11270 s
= bfd_get_section_by_name (obfd
, ".toc");
11271 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11272 s
= bfd_get_section_by_name (obfd
, ".tocbss");
11273 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11274 s
= bfd_get_section_by_name (obfd
, ".plt");
11275 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
11277 /* This may happen for
11278 o references to TOC base (SYM@toc / TOC[tc0]) without a
11280 o bad linker script
11281 o --gc-sections and empty TOC sections
11283 FIXME: Warn user? */
11285 /* Look for a likely section. We probably won't even be
11287 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11288 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
11290 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11293 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11294 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
11295 == (SEC_ALLOC
| SEC_SMALL_DATA
))
11298 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11299 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
11303 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
11304 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
11310 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
11315 /* Build all the stubs associated with the current output file.
11316 The stubs are kept in a hash table attached to the main linker
11317 hash table. This function is called via gldelf64ppc_finish. */
11320 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
11321 struct bfd_link_info
*info
,
11324 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11325 asection
*stub_sec
;
11327 int stub_sec_count
= 0;
11332 htab
->emit_stub_syms
= emit_stub_syms
;
11334 /* Allocate memory to hold the linker stubs. */
11335 for (stub_sec
= htab
->stub_bfd
->sections
;
11337 stub_sec
= stub_sec
->next
)
11338 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
11339 && stub_sec
->size
!= 0)
11341 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
11342 if (stub_sec
->contents
== NULL
)
11344 /* We want to check that built size is the same as calculated
11345 size. rawsize is a convenient location to use. */
11346 stub_sec
->rawsize
= stub_sec
->size
;
11347 stub_sec
->size
= 0;
11350 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
11355 /* Build the .glink plt call stub. */
11356 if (htab
->emit_stub_syms
)
11358 struct elf_link_hash_entry
*h
;
11359 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
11360 TRUE
, FALSE
, FALSE
);
11363 if (h
->root
.type
== bfd_link_hash_new
)
11365 h
->root
.type
= bfd_link_hash_defined
;
11366 h
->root
.u
.def
.section
= htab
->glink
;
11367 h
->root
.u
.def
.value
= 8;
11368 h
->ref_regular
= 1;
11369 h
->def_regular
= 1;
11370 h
->ref_regular_nonweak
= 1;
11371 h
->forced_local
= 1;
11375 plt0
= htab
->plt
->output_section
->vma
+ htab
->plt
->output_offset
- 16;
11376 if (info
->emitrelocations
)
11378 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
11381 r
->r_offset
= (htab
->glink
->output_offset
11382 + htab
->glink
->output_section
->vma
);
11383 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
11384 r
->r_addend
= plt0
;
11386 p
= htab
->glink
->contents
;
11387 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
11388 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
11390 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
11392 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
11394 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
11396 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
11398 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
11400 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
11402 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
11404 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
11406 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
11408 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
11410 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
11412 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
11414 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
11418 /* Build the .glink lazy link call stubs. */
11420 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
11424 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
11429 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
11431 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
11434 bfd_put_32 (htab
->glink
->owner
,
11435 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
11439 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
11442 if (htab
->brlt
->size
!= 0)
11444 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
11446 if (htab
->brlt
->contents
== NULL
)
11449 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
11451 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
11452 htab
->relbrlt
->size
);
11453 if (htab
->relbrlt
->contents
== NULL
)
11457 /* Build the stubs as directed by the stub hash table. */
11458 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
11460 if (htab
->relbrlt
!= NULL
)
11461 htab
->relbrlt
->reloc_count
= 0;
11463 for (stub_sec
= htab
->stub_bfd
->sections
;
11465 stub_sec
= stub_sec
->next
)
11466 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
11468 stub_sec_count
+= 1;
11469 if (stub_sec
->rawsize
!= stub_sec
->size
)
11473 if (stub_sec
!= NULL
11474 || htab
->glink
->rawsize
!= htab
->glink
->size
)
11476 htab
->stub_error
= TRUE
;
11477 info
->callbacks
->einfo (_("stubs don't match calculated size\n"));
11480 if (htab
->stub_error
)
11485 *stats
= bfd_malloc (500);
11486 if (*stats
== NULL
)
11489 sprintf (*stats
, _("linker stubs in %u group%s\n"
11491 " toc adjust %lu\n"
11492 " long branch %lu\n"
11493 " long toc adj %lu\n"
11496 stub_sec_count
== 1 ? "" : "s",
11497 htab
->stub_count
[ppc_stub_long_branch
- 1],
11498 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
11499 htab
->stub_count
[ppc_stub_plt_branch
- 1],
11500 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
11501 htab
->stub_count
[ppc_stub_plt_call
- 1]);
11506 /* This function undoes the changes made by add_symbol_adjust. */
11509 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11511 struct ppc_link_hash_entry
*eh
;
11513 if (h
->root
.type
== bfd_link_hash_indirect
)
11516 if (h
->root
.type
== bfd_link_hash_warning
)
11517 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11519 eh
= (struct ppc_link_hash_entry
*) h
;
11520 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
11523 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
11528 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
11530 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11533 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
11536 /* What to do when ld finds relocations against symbols defined in
11537 discarded sections. */
11539 static unsigned int
11540 ppc64_elf_action_discarded (asection
*sec
)
11542 if (strcmp (".opd", sec
->name
) == 0)
11545 if (strcmp (".toc", sec
->name
) == 0)
11548 if (strcmp (".toc1", sec
->name
) == 0)
11551 return _bfd_elf_default_action_discarded (sec
);
11554 /* REL points to a low-part reloc on a largetoc instruction sequence.
11555 Find the matching high-part reloc instruction and verify that it
11556 is addis REG,x,imm. If so, set *REG to x and return a pointer to
11557 the high-part reloc. */
11559 static const Elf_Internal_Rela
*
11560 ha_reloc_match (const Elf_Internal_Rela
*relocs
,
11561 const Elf_Internal_Rela
*rel
,
11563 bfd_boolean match_addend
,
11564 const bfd
*input_bfd
,
11565 const bfd_byte
*contents
)
11567 enum elf_ppc64_reloc_type r_type
, r_type_ha
;
11568 bfd_vma r_info_ha
, r_addend
;
11570 r_type
= ELF64_R_TYPE (rel
->r_info
);
11573 case R_PPC64_GOT_TLSLD16_LO
:
11574 case R_PPC64_GOT_TLSGD16_LO
:
11575 case R_PPC64_GOT_TPREL16_LO_DS
:
11576 case R_PPC64_GOT_DTPREL16_LO_DS
:
11577 case R_PPC64_GOT16_LO
:
11578 case R_PPC64_TOC16_LO
:
11579 r_type_ha
= r_type
+ 2;
11581 case R_PPC64_GOT16_LO_DS
:
11582 r_type_ha
= R_PPC64_GOT16_HA
;
11584 case R_PPC64_TOC16_LO_DS
:
11585 r_type_ha
= R_PPC64_TOC16_HA
;
11590 r_info_ha
= ELF64_R_INFO (ELF64_R_SYM (rel
->r_info
), r_type_ha
);
11591 r_addend
= rel
->r_addend
;
11593 while (--rel
>= relocs
)
11594 if (rel
->r_info
== r_info_ha
11596 || rel
->r_addend
== r_addend
))
11598 const bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
11599 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
11600 if ((insn
& (0x3f << 26)) == (15u << 26) /* addis rt,x,imm */
11601 && (insn
& (0x1f << 21)) == (*reg
<< 21))
11603 *reg
= (insn
>> 16) & 0x1f;
11611 /* The RELOCATE_SECTION function is called by the ELF backend linker
11612 to handle the relocations for a section.
11614 The relocs are always passed as Rela structures; if the section
11615 actually uses Rel structures, the r_addend field will always be
11618 This function is responsible for adjust the section contents as
11619 necessary, and (if using Rela relocs and generating a
11620 relocatable output file) adjusting the reloc addend as
11623 This function does not have to worry about setting the reloc
11624 address or the reloc symbol index.
11626 LOCAL_SYMS is a pointer to the swapped in local symbols.
11628 LOCAL_SECTIONS is an array giving the section in the input file
11629 corresponding to the st_shndx field of each local symbol.
11631 The global hash table entry for the global symbols can be found
11632 via elf_sym_hashes (input_bfd).
11634 When generating relocatable output, this function must handle
11635 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
11636 going to be the section symbol corresponding to the output
11637 section, which means that the addend must be adjusted
11641 ppc64_elf_relocate_section (bfd
*output_bfd
,
11642 struct bfd_link_info
*info
,
11644 asection
*input_section
,
11645 bfd_byte
*contents
,
11646 Elf_Internal_Rela
*relocs
,
11647 Elf_Internal_Sym
*local_syms
,
11648 asection
**local_sections
)
11650 struct ppc_link_hash_table
*htab
;
11651 Elf_Internal_Shdr
*symtab_hdr
;
11652 struct elf_link_hash_entry
**sym_hashes
;
11653 Elf_Internal_Rela
*rel
;
11654 Elf_Internal_Rela
*relend
;
11655 Elf_Internal_Rela outrel
;
11657 struct got_entry
**local_got_ents
;
11658 unsigned char *ha_opt
;
11660 bfd_boolean no_ha_opt
;
11661 bfd_boolean ret
= TRUE
;
11662 bfd_boolean is_opd
;
11663 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
11664 bfd_boolean is_power4
= FALSE
;
11665 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
11667 /* Initialize howto table if needed. */
11668 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
11671 htab
= ppc_hash_table (info
);
11675 /* Don't relocate stub sections. */
11676 if (input_section
->owner
== htab
->stub_bfd
)
11679 BFD_ASSERT (is_ppc64_elf (input_bfd
));
11681 local_got_ents
= elf_local_got_ents (input_bfd
);
11682 TOCstart
= elf_gp (output_bfd
);
11683 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11684 sym_hashes
= elf_sym_hashes (input_bfd
);
11685 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
11690 relend
= relocs
+ input_section
->reloc_count
;
11691 for (; rel
< relend
; rel
++)
11693 enum elf_ppc64_reloc_type r_type
;
11694 bfd_vma addend
, orig_addend
;
11695 bfd_reloc_status_type r
;
11696 Elf_Internal_Sym
*sym
;
11698 struct elf_link_hash_entry
*h_elf
;
11699 struct ppc_link_hash_entry
*h
;
11700 struct ppc_link_hash_entry
*fdh
;
11701 const char *sym_name
;
11702 unsigned long r_symndx
, toc_symndx
;
11703 bfd_vma toc_addend
;
11704 unsigned char tls_mask
, tls_gd
, tls_type
;
11705 unsigned char sym_type
;
11706 bfd_vma relocation
;
11707 bfd_boolean unresolved_reloc
;
11708 bfd_boolean warned
;
11711 struct ppc_stub_hash_entry
*stub_entry
;
11712 bfd_vma max_br_offset
;
11715 r_type
= ELF64_R_TYPE (rel
->r_info
);
11716 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11718 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
11719 symbol of the previous ADDR64 reloc. The symbol gives us the
11720 proper TOC base to use. */
11721 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
11723 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
11725 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
11731 unresolved_reloc
= FALSE
;
11733 orig_addend
= rel
->r_addend
;
11735 if (r_symndx
< symtab_hdr
->sh_info
)
11737 /* It's a local symbol. */
11738 struct _opd_sec_data
*opd
;
11740 sym
= local_syms
+ r_symndx
;
11741 sec
= local_sections
[r_symndx
];
11742 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
11743 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
11744 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
11745 opd
= get_opd_info (sec
);
11746 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
11748 long adjust
= opd
->adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
11753 /* If this is a relocation against the opd section sym
11754 and we have edited .opd, adjust the reloc addend so
11755 that ld -r and ld --emit-relocs output is correct.
11756 If it is a reloc against some other .opd symbol,
11757 then the symbol value will be adjusted later. */
11758 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
11759 rel
->r_addend
+= adjust
;
11761 relocation
+= adjust
;
11767 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
11768 r_symndx
, symtab_hdr
, sym_hashes
,
11769 h_elf
, sec
, relocation
,
11770 unresolved_reloc
, warned
);
11771 sym_name
= h_elf
->root
.root
.string
;
11772 sym_type
= h_elf
->type
;
11774 h
= (struct ppc_link_hash_entry
*) h_elf
;
11776 if (sec
!= NULL
&& elf_discarded_section (sec
))
11777 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
11779 ppc64_elf_howto_table
[r_type
],
11782 if (info
->relocatable
)
11785 /* TLS optimizations. Replace instruction sequences and relocs
11786 based on information we collected in tls_optimize. We edit
11787 RELOCS so that --emit-relocs will output something sensible
11788 for the final instruction stream. */
11793 tls_mask
= h
->tls_mask
;
11794 else if (local_got_ents
!= NULL
)
11796 struct plt_entry
**local_plt
= (struct plt_entry
**)
11797 (local_got_ents
+ symtab_hdr
->sh_info
);
11798 unsigned char *lgot_masks
= (unsigned char *)
11799 (local_plt
+ symtab_hdr
->sh_info
);
11800 tls_mask
= lgot_masks
[r_symndx
];
11803 && (r_type
== R_PPC64_TLS
11804 || r_type
== R_PPC64_TLSGD
11805 || r_type
== R_PPC64_TLSLD
))
11807 /* Check for toc tls entries. */
11808 unsigned char *toc_tls
;
11810 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11811 &local_syms
, rel
, input_bfd
))
11815 tls_mask
= *toc_tls
;
11818 /* Check that tls relocs are used with tls syms, and non-tls
11819 relocs are used with non-tls syms. */
11820 if (r_symndx
!= STN_UNDEF
11821 && r_type
!= R_PPC64_NONE
11823 || h
->elf
.root
.type
== bfd_link_hash_defined
11824 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
11825 && (IS_PPC64_TLS_RELOC (r_type
)
11826 != (sym_type
== STT_TLS
11827 || (sym_type
== STT_SECTION
11828 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
11831 && (r_type
== R_PPC64_TLS
11832 || r_type
== R_PPC64_TLSGD
11833 || r_type
== R_PPC64_TLSLD
))
11834 /* R_PPC64_TLS is OK against a symbol in the TOC. */
11837 info
->callbacks
->einfo
11838 (!IS_PPC64_TLS_RELOC (r_type
)
11839 ? _("%H: %s used with TLS symbol %s\n")
11840 : _("%H: %s used with non-TLS symbol %s\n"),
11841 input_bfd
, input_section
, rel
->r_offset
,
11842 ppc64_elf_howto_table
[r_type
]->name
,
11846 /* Ensure reloc mapping code below stays sane. */
11847 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
11848 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
11849 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
11850 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
11851 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
11852 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
11853 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
11854 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
11855 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
11856 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
11864 case R_PPC64_LO_DS_OPT
:
11865 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11866 if ((insn
& (0x3f << 26)) != 58u << 26)
11868 insn
+= (14u << 26) - (58u << 26);
11869 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11870 r_type
= R_PPC64_TOC16_LO
;
11871 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11874 case R_PPC64_TOC16
:
11875 case R_PPC64_TOC16_LO
:
11876 case R_PPC64_TOC16_DS
:
11877 case R_PPC64_TOC16_LO_DS
:
11879 /* Check for toc tls entries. */
11880 unsigned char *toc_tls
;
11883 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
11884 &local_syms
, rel
, input_bfd
);
11890 tls_mask
= *toc_tls
;
11891 if (r_type
== R_PPC64_TOC16_DS
11892 || r_type
== R_PPC64_TOC16_LO_DS
)
11895 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
11900 /* If we found a GD reloc pair, then we might be
11901 doing a GD->IE transition. */
11904 tls_gd
= TLS_TPRELGD
;
11905 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
11908 else if (retval
== 3)
11910 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
11918 case R_PPC64_GOT_TPREL16_HI
:
11919 case R_PPC64_GOT_TPREL16_HA
:
11921 && (tls_mask
& TLS_TPREL
) == 0)
11923 rel
->r_offset
-= d_offset
;
11924 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
11925 r_type
= R_PPC64_NONE
;
11926 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11930 case R_PPC64_GOT_TPREL16_DS
:
11931 case R_PPC64_GOT_TPREL16_LO_DS
:
11933 && (tls_mask
& TLS_TPREL
) == 0)
11936 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
11938 insn
|= 0x3c0d0000; /* addis 0,13,0 */
11939 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
11940 r_type
= R_PPC64_TPREL16_HA
;
11941 if (toc_symndx
!= 0)
11943 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
11944 rel
->r_addend
= toc_addend
;
11945 /* We changed the symbol. Start over in order to
11946 get h, sym, sec etc. right. */
11951 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11957 && (tls_mask
& TLS_TPREL
) == 0)
11959 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
11960 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
11963 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
11964 /* Was PPC64_TLS which sits on insn boundary, now
11965 PPC64_TPREL16_LO which is at low-order half-word. */
11966 rel
->r_offset
+= d_offset
;
11967 r_type
= R_PPC64_TPREL16_LO
;
11968 if (toc_symndx
!= 0)
11970 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
11971 rel
->r_addend
= toc_addend
;
11972 /* We changed the symbol. Start over in order to
11973 get h, sym, sec etc. right. */
11978 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
11982 case R_PPC64_GOT_TLSGD16_HI
:
11983 case R_PPC64_GOT_TLSGD16_HA
:
11984 tls_gd
= TLS_TPRELGD
;
11985 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
11989 case R_PPC64_GOT_TLSLD16_HI
:
11990 case R_PPC64_GOT_TLSLD16_HA
:
11991 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
11994 if ((tls_mask
& tls_gd
) != 0)
11995 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
11996 + R_PPC64_GOT_TPREL16_DS
);
11999 rel
->r_offset
-= d_offset
;
12000 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12001 r_type
= R_PPC64_NONE
;
12003 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12007 case R_PPC64_GOT_TLSGD16
:
12008 case R_PPC64_GOT_TLSGD16_LO
:
12009 tls_gd
= TLS_TPRELGD
;
12010 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12014 case R_PPC64_GOT_TLSLD16
:
12015 case R_PPC64_GOT_TLSLD16_LO
:
12016 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12018 unsigned int insn1
, insn2
, insn3
;
12022 offset
= (bfd_vma
) -1;
12023 /* If not using the newer R_PPC64_TLSGD/LD to mark
12024 __tls_get_addr calls, we must trust that the call
12025 stays with its arg setup insns, ie. that the next
12026 reloc is the __tls_get_addr call associated with
12027 the current reloc. Edit both insns. */
12028 if (input_section
->has_tls_get_addr_call
12029 && rel
+ 1 < relend
12030 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
12031 htab
->tls_get_addr
,
12032 htab
->tls_get_addr_fd
))
12033 offset
= rel
[1].r_offset
;
12034 if ((tls_mask
& tls_gd
) != 0)
12037 insn1
= bfd_get_32 (output_bfd
,
12038 contents
+ rel
->r_offset
- d_offset
);
12039 insn1
&= (1 << 26) - (1 << 2);
12040 insn1
|= 58 << 26; /* ld */
12041 insn2
= 0x7c636a14; /* add 3,3,13 */
12042 if (offset
!= (bfd_vma
) -1)
12043 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12044 if ((tls_mask
& TLS_EXPLICIT
) == 0)
12045 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
12046 + R_PPC64_GOT_TPREL16_DS
);
12048 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
12049 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12054 insn1
= 0x3c6d0000; /* addis 3,13,0 */
12055 insn2
= 0x38630000; /* addi 3,3,0 */
12058 /* Was an LD reloc. */
12060 sec
= local_sections
[toc_symndx
];
12062 r_symndx
< symtab_hdr
->sh_info
;
12064 if (local_sections
[r_symndx
] == sec
)
12066 if (r_symndx
>= symtab_hdr
->sh_info
)
12067 r_symndx
= STN_UNDEF
;
12068 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12069 if (r_symndx
!= STN_UNDEF
)
12070 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12071 + sec
->output_offset
12072 + sec
->output_section
->vma
);
12074 else if (toc_symndx
!= 0)
12076 r_symndx
= toc_symndx
;
12077 rel
->r_addend
= toc_addend
;
12079 r_type
= R_PPC64_TPREL16_HA
;
12080 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12081 if (offset
!= (bfd_vma
) -1)
12083 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
12084 R_PPC64_TPREL16_LO
);
12085 rel
[1].r_offset
= offset
+ d_offset
;
12086 rel
[1].r_addend
= rel
->r_addend
;
12089 bfd_put_32 (output_bfd
, insn1
,
12090 contents
+ rel
->r_offset
- d_offset
);
12091 if (offset
!= (bfd_vma
) -1)
12093 insn3
= bfd_get_32 (output_bfd
,
12094 contents
+ offset
+ 4);
12096 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12098 rel
[1].r_offset
+= 4;
12099 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12102 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12104 if ((tls_mask
& tls_gd
) == 0
12105 && (tls_gd
== 0 || toc_symndx
!= 0))
12107 /* We changed the symbol. Start over in order
12108 to get h, sym, sec etc. right. */
12115 case R_PPC64_TLSGD
:
12116 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
12118 unsigned int insn2
, insn3
;
12119 bfd_vma offset
= rel
->r_offset
;
12121 if ((tls_mask
& TLS_TPRELGD
) != 0)
12124 r_type
= R_PPC64_NONE
;
12125 insn2
= 0x7c636a14; /* add 3,3,13 */
12130 if (toc_symndx
!= 0)
12132 r_symndx
= toc_symndx
;
12133 rel
->r_addend
= toc_addend
;
12135 r_type
= R_PPC64_TPREL16_LO
;
12136 rel
->r_offset
= offset
+ d_offset
;
12137 insn2
= 0x38630000; /* addi 3,3,0 */
12139 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12140 /* Zap the reloc on the _tls_get_addr call too. */
12141 BFD_ASSERT (offset
== rel
[1].r_offset
);
12142 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12143 insn3
= bfd_get_32 (output_bfd
,
12144 contents
+ offset
+ 4);
12146 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12148 rel
->r_offset
+= 4;
12149 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12152 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12153 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
12161 case R_PPC64_TLSLD
:
12162 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
12164 unsigned int insn2
, insn3
;
12165 bfd_vma offset
= rel
->r_offset
;
12168 sec
= local_sections
[toc_symndx
];
12170 r_symndx
< symtab_hdr
->sh_info
;
12172 if (local_sections
[r_symndx
] == sec
)
12174 if (r_symndx
>= symtab_hdr
->sh_info
)
12175 r_symndx
= STN_UNDEF
;
12176 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12177 if (r_symndx
!= STN_UNDEF
)
12178 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
12179 + sec
->output_offset
12180 + sec
->output_section
->vma
);
12182 r_type
= R_PPC64_TPREL16_LO
;
12183 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12184 rel
->r_offset
= offset
+ d_offset
;
12185 /* Zap the reloc on the _tls_get_addr call too. */
12186 BFD_ASSERT (offset
== rel
[1].r_offset
);
12187 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
12188 insn2
= 0x38630000; /* addi 3,3,0 */
12189 insn3
= bfd_get_32 (output_bfd
,
12190 contents
+ offset
+ 4);
12192 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
12194 rel
->r_offset
+= 4;
12195 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
12198 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
12204 case R_PPC64_DTPMOD64
:
12205 if (rel
+ 1 < relend
12206 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
12207 && rel
[1].r_offset
== rel
->r_offset
+ 8)
12209 if ((tls_mask
& TLS_GD
) == 0)
12211 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
12212 if ((tls_mask
& TLS_TPRELGD
) != 0)
12213 r_type
= R_PPC64_TPREL64
;
12216 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12217 r_type
= R_PPC64_NONE
;
12219 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12224 if ((tls_mask
& TLS_LD
) == 0)
12226 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
12227 r_type
= R_PPC64_NONE
;
12228 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12233 case R_PPC64_TPREL64
:
12234 if ((tls_mask
& TLS_TPREL
) == 0)
12236 r_type
= R_PPC64_NONE
;
12237 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
12242 /* Handle other relocations that tweak non-addend part of insn. */
12244 max_br_offset
= 1 << 25;
12245 addend
= rel
->r_addend
;
12251 /* Branch taken prediction relocations. */
12252 case R_PPC64_ADDR14_BRTAKEN
:
12253 case R_PPC64_REL14_BRTAKEN
:
12254 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
12257 /* Branch not taken prediction relocations. */
12258 case R_PPC64_ADDR14_BRNTAKEN
:
12259 case R_PPC64_REL14_BRNTAKEN
:
12260 insn
|= bfd_get_32 (output_bfd
,
12261 contents
+ rel
->r_offset
) & ~(0x01 << 21);
12264 case R_PPC64_REL14
:
12265 max_br_offset
= 1 << 15;
12268 case R_PPC64_REL24
:
12269 /* Calls to functions with a different TOC, such as calls to
12270 shared objects, need to alter the TOC pointer. This is
12271 done using a linkage stub. A REL24 branching to these
12272 linkage stubs needs to be followed by a nop, as the nop
12273 will be replaced with an instruction to restore the TOC
12278 && h
->oh
->is_func_descriptor
)
12279 fdh
= ppc_follow_link (h
->oh
);
12280 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, rel
, htab
);
12281 if (stub_entry
!= NULL
12282 && (stub_entry
->stub_type
== ppc_stub_plt_call
12283 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
12284 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
12286 bfd_boolean can_plt_call
= FALSE
;
12288 if (rel
->r_offset
+ 8 <= input_section
->size
)
12291 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
12293 || nop
== CROR_151515
|| nop
== CROR_313131
)
12296 && (h
== htab
->tls_get_addr_fd
12297 || h
== htab
->tls_get_addr
)
12298 && !htab
->no_tls_get_addr_opt
)
12300 /* Special stub used, leave nop alone. */
12303 bfd_put_32 (input_bfd
, LD_R2_40R1
,
12304 contents
+ rel
->r_offset
+ 4);
12305 can_plt_call
= TRUE
;
12311 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
12313 /* If this is a plain branch rather than a branch
12314 and link, don't require a nop. However, don't
12315 allow tail calls in a shared library as they
12316 will result in r2 being corrupted. */
12318 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
12319 if (info
->executable
&& (br
& 1) == 0)
12320 can_plt_call
= TRUE
;
12325 && strcmp (h
->elf
.root
.root
.string
,
12326 ".__libc_start_main") == 0)
12328 /* Allow crt1 branch to go via a toc adjusting stub. */
12329 can_plt_call
= TRUE
;
12333 if (strcmp (input_section
->output_section
->name
,
12335 || strcmp (input_section
->output_section
->name
,
12337 info
->callbacks
->einfo
12338 (_("%H: automatic multiple TOCs "
12339 "not supported using your crt files; "
12340 "recompile with -mminimal-toc or upgrade gcc\n"),
12341 input_bfd
, input_section
, rel
->r_offset
);
12343 info
->callbacks
->einfo
12344 (_("%H: sibling call optimization to `%s' "
12345 "does not allow automatic multiple TOCs; "
12346 "recompile with -mminimal-toc or "
12347 "-fno-optimize-sibling-calls, "
12348 "or make `%s' extern\n"),
12349 input_bfd
, input_section
, rel
->r_offset
,
12352 bfd_set_error (bfd_error_bad_value
);
12358 && stub_entry
->stub_type
== ppc_stub_plt_call
)
12359 unresolved_reloc
= FALSE
;
12362 if ((stub_entry
== NULL
12363 || stub_entry
->stub_type
== ppc_stub_long_branch
12364 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12365 && get_opd_info (sec
) != NULL
)
12367 /* The branch destination is the value of the opd entry. */
12368 bfd_vma off
= (relocation
+ addend
12369 - sec
->output_section
->vma
12370 - sec
->output_offset
);
12371 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
12372 if (dest
!= (bfd_vma
) -1)
12379 /* If the branch is out of reach we ought to have a long
12381 from
= (rel
->r_offset
12382 + input_section
->output_offset
12383 + input_section
->output_section
->vma
);
12385 if (stub_entry
!= NULL
12386 && (stub_entry
->stub_type
== ppc_stub_long_branch
12387 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
12388 && (r_type
== R_PPC64_ADDR14_BRTAKEN
12389 || r_type
== R_PPC64_ADDR14_BRNTAKEN
12390 || (relocation
+ addend
- from
+ max_br_offset
12391 < 2 * max_br_offset
)))
12392 /* Don't use the stub if this branch is in range. */
12395 if (stub_entry
!= NULL
)
12397 /* Munge up the value and addend so that we call the stub
12398 rather than the procedure directly. */
12399 relocation
= (stub_entry
->stub_offset
12400 + stub_entry
->stub_sec
->output_offset
12401 + stub_entry
->stub_sec
->output_section
->vma
);
12409 /* Set 'a' bit. This is 0b00010 in BO field for branch
12410 on CR(BI) insns (BO == 001at or 011at), and 0b01000
12411 for branch on CTR insns (BO == 1a00t or 1a01t). */
12412 if ((insn
& (0x14 << 21)) == (0x04 << 21))
12413 insn
|= 0x02 << 21;
12414 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
12415 insn
|= 0x08 << 21;
12421 /* Invert 'y' bit if not the default. */
12422 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
12423 insn
^= 0x01 << 21;
12426 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
12429 /* NOP out calls to undefined weak functions.
12430 We can thus call a weak function without first
12431 checking whether the function is defined. */
12433 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12434 && h
->elf
.dynindx
== -1
12435 && r_type
== R_PPC64_REL24
12439 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
12445 /* Set `addend'. */
12450 info
->callbacks
->einfo
12451 (_("%B: unknown relocation type %d for symbol %s\n"),
12452 input_bfd
, (int) r_type
, sym_name
);
12454 bfd_set_error (bfd_error_bad_value
);
12460 case R_PPC64_TLSGD
:
12461 case R_PPC64_TLSLD
:
12462 case R_PPC64_GNU_VTINHERIT
:
12463 case R_PPC64_GNU_VTENTRY
:
12466 /* GOT16 relocations. Like an ADDR16 using the symbol's
12467 address in the GOT as relocation value instead of the
12468 symbol's value itself. Also, create a GOT entry for the
12469 symbol and put the symbol value there. */
12470 case R_PPC64_GOT_TLSGD16
:
12471 case R_PPC64_GOT_TLSGD16_LO
:
12472 case R_PPC64_GOT_TLSGD16_HI
:
12473 case R_PPC64_GOT_TLSGD16_HA
:
12474 tls_type
= TLS_TLS
| TLS_GD
;
12477 case R_PPC64_GOT_TLSLD16
:
12478 case R_PPC64_GOT_TLSLD16_LO
:
12479 case R_PPC64_GOT_TLSLD16_HI
:
12480 case R_PPC64_GOT_TLSLD16_HA
:
12481 tls_type
= TLS_TLS
| TLS_LD
;
12484 case R_PPC64_GOT_TPREL16_DS
:
12485 case R_PPC64_GOT_TPREL16_LO_DS
:
12486 case R_PPC64_GOT_TPREL16_HI
:
12487 case R_PPC64_GOT_TPREL16_HA
:
12488 tls_type
= TLS_TLS
| TLS_TPREL
;
12491 case R_PPC64_GOT_DTPREL16_DS
:
12492 case R_PPC64_GOT_DTPREL16_LO_DS
:
12493 case R_PPC64_GOT_DTPREL16_HI
:
12494 case R_PPC64_GOT_DTPREL16_HA
:
12495 tls_type
= TLS_TLS
| TLS_DTPREL
;
12498 case R_PPC64_GOT16
:
12499 case R_PPC64_GOT16_LO
:
12500 case R_PPC64_GOT16_HI
:
12501 case R_PPC64_GOT16_HA
:
12502 case R_PPC64_GOT16_DS
:
12503 case R_PPC64_GOT16_LO_DS
:
12506 /* Relocation is to the entry for this symbol in the global
12511 unsigned long indx
= 0;
12512 struct got_entry
*ent
;
12514 if (tls_type
== (TLS_TLS
| TLS_LD
)
12516 || !h
->elf
.def_dynamic
))
12517 ent
= ppc64_tlsld_got (input_bfd
);
12523 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
12524 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
12527 && SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12528 /* This is actually a static link, or it is a
12529 -Bsymbolic link and the symbol is defined
12530 locally, or the symbol was forced to be local
12531 because of a version file. */
12535 indx
= h
->elf
.dynindx
;
12536 unresolved_reloc
= FALSE
;
12538 ent
= h
->elf
.got
.glist
;
12542 if (local_got_ents
== NULL
)
12544 ent
= local_got_ents
[r_symndx
];
12547 for (; ent
!= NULL
; ent
= ent
->next
)
12548 if (ent
->addend
== orig_addend
12549 && ent
->owner
== input_bfd
12550 && ent
->tls_type
== tls_type
)
12556 if (ent
->is_indirect
)
12557 ent
= ent
->got
.ent
;
12558 offp
= &ent
->got
.offset
;
12559 got
= ppc64_elf_tdata (ent
->owner
)->got
;
12563 /* The offset must always be a multiple of 8. We use the
12564 least significant bit to record whether we have already
12565 processed this entry. */
12567 if ((off
& 1) != 0)
12571 /* Generate relocs for the dynamic linker, except in
12572 the case of TLSLD where we'll use one entry per
12580 ? h
->elf
.type
== STT_GNU_IFUNC
12581 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
12582 if ((info
->shared
|| indx
!= 0)
12584 || (tls_type
== (TLS_TLS
| TLS_LD
)
12585 && !h
->elf
.def_dynamic
)
12586 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12587 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
12588 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
12590 relgot
= htab
->reliplt
;
12591 if (relgot
!= NULL
)
12593 outrel
.r_offset
= (got
->output_section
->vma
12594 + got
->output_offset
12596 outrel
.r_addend
= addend
;
12597 if (tls_type
& (TLS_LD
| TLS_GD
))
12599 outrel
.r_addend
= 0;
12600 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
12601 if (tls_type
== (TLS_TLS
| TLS_GD
))
12603 loc
= relgot
->contents
;
12604 loc
+= (relgot
->reloc_count
++
12605 * sizeof (Elf64_External_Rela
));
12606 bfd_elf64_swap_reloca_out (output_bfd
,
12608 outrel
.r_offset
+= 8;
12609 outrel
.r_addend
= addend
;
12611 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12614 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
12615 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
12616 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12617 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
12618 else if (indx
!= 0)
12619 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
12623 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12625 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12627 /* Write the .got section contents for the sake
12629 loc
= got
->contents
+ off
;
12630 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
12634 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
12636 outrel
.r_addend
+= relocation
;
12637 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
12638 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
12640 loc
= relgot
->contents
;
12641 loc
+= (relgot
->reloc_count
++
12642 * sizeof (Elf64_External_Rela
));
12643 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
12646 /* Init the .got section contents here if we're not
12647 emitting a reloc. */
12650 relocation
+= addend
;
12651 if (tls_type
== (TLS_TLS
| TLS_LD
))
12653 else if (tls_type
!= 0)
12655 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12656 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
12657 relocation
+= DTP_OFFSET
- TP_OFFSET
;
12659 if (tls_type
== (TLS_TLS
| TLS_GD
))
12661 bfd_put_64 (output_bfd
, relocation
,
12662 got
->contents
+ off
+ 8);
12667 bfd_put_64 (output_bfd
, relocation
,
12668 got
->contents
+ off
);
12672 if (off
>= (bfd_vma
) -2)
12675 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
12676 addend
= -(TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
);
12680 case R_PPC64_PLT16_HA
:
12681 case R_PPC64_PLT16_HI
:
12682 case R_PPC64_PLT16_LO
:
12683 case R_PPC64_PLT32
:
12684 case R_PPC64_PLT64
:
12685 /* Relocation is to the entry for this symbol in the
12686 procedure linkage table. */
12688 /* Resolve a PLT reloc against a local symbol directly,
12689 without using the procedure linkage table. */
12693 /* It's possible that we didn't make a PLT entry for this
12694 symbol. This happens when statically linking PIC code,
12695 or when using -Bsymbolic. Go find a match if there is a
12697 if (htab
->plt
!= NULL
)
12699 struct plt_entry
*ent
;
12700 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12701 if (ent
->addend
== orig_addend
12702 && ent
->plt
.offset
!= (bfd_vma
) -1)
12704 relocation
= (htab
->plt
->output_section
->vma
12705 + htab
->plt
->output_offset
12706 + ent
->plt
.offset
);
12707 unresolved_reloc
= FALSE
;
12713 /* Relocation value is TOC base. */
12714 relocation
= TOCstart
;
12715 if (r_symndx
== STN_UNDEF
)
12716 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
12717 else if (unresolved_reloc
)
12719 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
12720 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
12722 unresolved_reloc
= TRUE
;
12725 /* TOC16 relocs. We want the offset relative to the TOC base,
12726 which is the address of the start of the TOC plus 0x8000.
12727 The TOC consists of sections .got, .toc, .tocbss, and .plt,
12729 case R_PPC64_TOC16
:
12730 case R_PPC64_TOC16_LO
:
12731 case R_PPC64_TOC16_HI
:
12732 case R_PPC64_TOC16_DS
:
12733 case R_PPC64_TOC16_LO_DS
:
12734 case R_PPC64_TOC16_HA
:
12735 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
12738 /* Relocate against the beginning of the section. */
12739 case R_PPC64_SECTOFF
:
12740 case R_PPC64_SECTOFF_LO
:
12741 case R_PPC64_SECTOFF_HI
:
12742 case R_PPC64_SECTOFF_DS
:
12743 case R_PPC64_SECTOFF_LO_DS
:
12744 case R_PPC64_SECTOFF_HA
:
12746 addend
-= sec
->output_section
->vma
;
12749 case R_PPC64_REL16
:
12750 case R_PPC64_REL16_LO
:
12751 case R_PPC64_REL16_HI
:
12752 case R_PPC64_REL16_HA
:
12755 case R_PPC64_REL14
:
12756 case R_PPC64_REL14_BRNTAKEN
:
12757 case R_PPC64_REL14_BRTAKEN
:
12758 case R_PPC64_REL24
:
12761 case R_PPC64_TPREL16
:
12762 case R_PPC64_TPREL16_LO
:
12763 case R_PPC64_TPREL16_HI
:
12764 case R_PPC64_TPREL16_HA
:
12765 case R_PPC64_TPREL16_DS
:
12766 case R_PPC64_TPREL16_LO_DS
:
12767 case R_PPC64_TPREL16_HIGHER
:
12768 case R_PPC64_TPREL16_HIGHERA
:
12769 case R_PPC64_TPREL16_HIGHEST
:
12770 case R_PPC64_TPREL16_HIGHESTA
:
12772 && h
->elf
.root
.type
== bfd_link_hash_undefweak
12773 && h
->elf
.dynindx
== -1)
12775 /* Make this relocation against an undefined weak symbol
12776 resolve to zero. This is really just a tweak, since
12777 code using weak externs ought to check that they are
12778 defined before using them. */
12779 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
12781 insn
= bfd_get_32 (output_bfd
, p
);
12782 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
12784 bfd_put_32 (output_bfd
, insn
, p
);
12787 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12789 /* The TPREL16 relocs shouldn't really be used in shared
12790 libs as they will result in DT_TEXTREL being set, but
12791 support them anyway. */
12795 case R_PPC64_DTPREL16
:
12796 case R_PPC64_DTPREL16_LO
:
12797 case R_PPC64_DTPREL16_HI
:
12798 case R_PPC64_DTPREL16_HA
:
12799 case R_PPC64_DTPREL16_DS
:
12800 case R_PPC64_DTPREL16_LO_DS
:
12801 case R_PPC64_DTPREL16_HIGHER
:
12802 case R_PPC64_DTPREL16_HIGHERA
:
12803 case R_PPC64_DTPREL16_HIGHEST
:
12804 case R_PPC64_DTPREL16_HIGHESTA
:
12805 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12808 case R_PPC64_DTPMOD64
:
12813 case R_PPC64_TPREL64
:
12814 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
12817 case R_PPC64_DTPREL64
:
12818 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
12821 /* Relocations that may need to be propagated if this is a
12823 case R_PPC64_REL30
:
12824 case R_PPC64_REL32
:
12825 case R_PPC64_REL64
:
12826 case R_PPC64_ADDR14
:
12827 case R_PPC64_ADDR14_BRNTAKEN
:
12828 case R_PPC64_ADDR14_BRTAKEN
:
12829 case R_PPC64_ADDR16
:
12830 case R_PPC64_ADDR16_DS
:
12831 case R_PPC64_ADDR16_HA
:
12832 case R_PPC64_ADDR16_HI
:
12833 case R_PPC64_ADDR16_HIGHER
:
12834 case R_PPC64_ADDR16_HIGHERA
:
12835 case R_PPC64_ADDR16_HIGHEST
:
12836 case R_PPC64_ADDR16_HIGHESTA
:
12837 case R_PPC64_ADDR16_LO
:
12838 case R_PPC64_ADDR16_LO_DS
:
12839 case R_PPC64_ADDR24
:
12840 case R_PPC64_ADDR32
:
12841 case R_PPC64_ADDR64
:
12842 case R_PPC64_UADDR16
:
12843 case R_PPC64_UADDR32
:
12844 case R_PPC64_UADDR64
:
12846 if ((input_section
->flags
& SEC_ALLOC
) == 0)
12849 if (NO_OPD_RELOCS
&& is_opd
)
12854 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
12855 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
12856 && (must_be_dyn_reloc (info
, r_type
)
12857 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
12858 || (ELIMINATE_COPY_RELOCS
12861 && h
->elf
.dynindx
!= -1
12862 && !h
->elf
.non_got_ref
12863 && !h
->elf
.def_regular
)
12866 ? h
->elf
.type
== STT_GNU_IFUNC
12867 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
12869 bfd_boolean skip
, relocate
;
12873 /* When generating a dynamic object, these relocations
12874 are copied into the output file to be resolved at run
12880 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
12881 input_section
, rel
->r_offset
);
12882 if (out_off
== (bfd_vma
) -1)
12884 else if (out_off
== (bfd_vma
) -2)
12885 skip
= TRUE
, relocate
= TRUE
;
12886 out_off
+= (input_section
->output_section
->vma
12887 + input_section
->output_offset
);
12888 outrel
.r_offset
= out_off
;
12889 outrel
.r_addend
= rel
->r_addend
;
12891 /* Optimize unaligned reloc use. */
12892 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
12893 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
12894 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
12895 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
12896 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
12897 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
12898 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
12899 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
12900 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
12903 memset (&outrel
, 0, sizeof outrel
);
12904 else if (!SYMBOL_CALLS_LOCAL (info
, &h
->elf
)
12906 && r_type
!= R_PPC64_TOC
)
12907 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
12910 /* This symbol is local, or marked to become local,
12911 or this is an opd section reloc which must point
12912 at a local function. */
12913 outrel
.r_addend
+= relocation
;
12914 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
12916 if (is_opd
&& h
!= NULL
)
12918 /* Lie about opd entries. This case occurs
12919 when building shared libraries and we
12920 reference a function in another shared
12921 lib. The same thing happens for a weak
12922 definition in an application that's
12923 overridden by a strong definition in a
12924 shared lib. (I believe this is a generic
12925 bug in binutils handling of weak syms.)
12926 In these cases we won't use the opd
12927 entry in this lib. */
12928 unresolved_reloc
= FALSE
;
12931 && r_type
== R_PPC64_ADDR64
12933 ? h
->elf
.type
== STT_GNU_IFUNC
12934 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
12935 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12938 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12940 /* We need to relocate .opd contents for ld.so.
12941 Prelink also wants simple and consistent rules
12942 for relocs. This make all RELATIVE relocs have
12943 *r_offset equal to r_addend. */
12952 ? h
->elf
.type
== STT_GNU_IFUNC
12953 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12955 info
->callbacks
->einfo
12956 (_("%H: relocation %s for indirect "
12957 "function %s unsupported\n"),
12958 input_bfd
, input_section
, rel
->r_offset
,
12959 ppc64_elf_howto_table
[r_type
]->name
,
12963 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
12965 else if (sec
== NULL
|| sec
->owner
== NULL
)
12967 bfd_set_error (bfd_error_bad_value
);
12974 osec
= sec
->output_section
;
12975 indx
= elf_section_data (osec
)->dynindx
;
12979 if ((osec
->flags
& SEC_READONLY
) == 0
12980 && htab
->elf
.data_index_section
!= NULL
)
12981 osec
= htab
->elf
.data_index_section
;
12983 osec
= htab
->elf
.text_index_section
;
12984 indx
= elf_section_data (osec
)->dynindx
;
12986 BFD_ASSERT (indx
!= 0);
12988 /* We are turning this relocation into one
12989 against a section symbol, so subtract out
12990 the output section's address but not the
12991 offset of the input section in the output
12993 outrel
.r_addend
-= osec
->vma
;
12996 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
13000 sreloc
= elf_section_data (input_section
)->sreloc
;
13001 if (!htab
->elf
.dynamic_sections_created
)
13002 sreloc
= htab
->reliplt
;
13003 if (sreloc
== NULL
)
13006 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
13009 loc
= sreloc
->contents
;
13010 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13011 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
13013 /* If this reloc is against an external symbol, it will
13014 be computed at runtime, so there's no need to do
13015 anything now. However, for the sake of prelink ensure
13016 that the section contents are a known value. */
13019 unresolved_reloc
= FALSE
;
13020 /* The value chosen here is quite arbitrary as ld.so
13021 ignores section contents except for the special
13022 case of .opd where the contents might be accessed
13023 before relocation. Choose zero, as that won't
13024 cause reloc overflow. */
13027 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
13028 to improve backward compatibility with older
13030 if (r_type
== R_PPC64_ADDR64
)
13031 addend
= outrel
.r_addend
;
13032 /* Adjust pc_relative relocs to have zero in *r_offset. */
13033 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
13034 addend
= (input_section
->output_section
->vma
13035 + input_section
->output_offset
13042 case R_PPC64_GLOB_DAT
:
13043 case R_PPC64_JMP_SLOT
:
13044 case R_PPC64_JMP_IREL
:
13045 case R_PPC64_RELATIVE
:
13046 /* We shouldn't ever see these dynamic relocs in relocatable
13048 /* Fall through. */
13050 case R_PPC64_PLTGOT16
:
13051 case R_PPC64_PLTGOT16_DS
:
13052 case R_PPC64_PLTGOT16_HA
:
13053 case R_PPC64_PLTGOT16_HI
:
13054 case R_PPC64_PLTGOT16_LO
:
13055 case R_PPC64_PLTGOT16_LO_DS
:
13056 case R_PPC64_PLTREL32
:
13057 case R_PPC64_PLTREL64
:
13058 /* These ones haven't been implemented yet. */
13060 info
->callbacks
->einfo
13061 (_("%B: relocation %s is not supported for symbol %s\n"),
13063 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
13065 bfd_set_error (bfd_error_invalid_operation
);
13070 /* Multi-instruction sequences that access the TOC can be
13071 optimized, eg. addis ra,r2,0; addi rb,ra,x;
13072 to nop; addi rb,r2,x; */
13078 case R_PPC64_GOT_TLSLD16_HI
:
13079 case R_PPC64_GOT_TLSGD16_HI
:
13080 case R_PPC64_GOT_TPREL16_HI
:
13081 case R_PPC64_GOT_DTPREL16_HI
:
13082 case R_PPC64_GOT16_HI
:
13083 case R_PPC64_TOC16_HI
:
13084 /* These relocs would only be useful if building up an
13085 offset to later add to r2, perhaps in an indexed
13086 addressing mode instruction. Don't try to optimize.
13087 Unfortunately, the possibility of someone building up an
13088 offset like this or even with the HA relocs, means that
13089 we need to check the high insn when optimizing the low
13093 case R_PPC64_GOT_TLSLD16_HA
:
13094 case R_PPC64_GOT_TLSGD16_HA
:
13095 case R_PPC64_GOT_TPREL16_HA
:
13096 case R_PPC64_GOT_DTPREL16_HA
:
13097 case R_PPC64_GOT16_HA
:
13098 case R_PPC64_TOC16_HA
:
13099 /* nop is done later. */
13102 case R_PPC64_GOT_TLSLD16_LO
:
13103 case R_PPC64_GOT_TLSGD16_LO
:
13104 case R_PPC64_GOT_TPREL16_LO_DS
:
13105 case R_PPC64_GOT_DTPREL16_LO_DS
:
13106 case R_PPC64_GOT16_LO
:
13107 case R_PPC64_GOT16_LO_DS
:
13108 case R_PPC64_TOC16_LO
:
13109 case R_PPC64_TOC16_LO_DS
:
13110 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
13112 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13113 insn
= bfd_get_32 (input_bfd
, p
);
13114 if ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
13115 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
13116 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
13117 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
13118 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
13119 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
13120 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
13121 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
13122 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
13123 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
13124 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
13125 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
13126 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
13127 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
13128 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
13129 && (insn
& 3) != 1)
13130 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
13131 && ((insn
& 3) == 0 || (insn
& 3) == 3)))
13133 unsigned int reg
= (insn
>> 16) & 0x1f;
13134 const Elf_Internal_Rela
*ha
;
13135 bfd_boolean match_addend
;
13137 match_addend
= (sym
!= NULL
13138 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
);
13139 ha
= ha_reloc_match (relocs
, rel
, ®
, match_addend
,
13140 input_bfd
, contents
);
13143 insn
&= ~(0x1f << 16);
13145 bfd_put_32 (input_bfd
, insn
, p
);
13146 if (ha_opt
== NULL
)
13148 ha_opt
= bfd_zmalloc (input_section
->reloc_count
);
13149 if (ha_opt
== NULL
)
13152 ha_opt
[ha
- relocs
] = 1;
13155 /* If we don't find a matching high part insn,
13156 something is fishy. Refuse to nop any high
13157 part insn in this section. */
13164 /* Do any further special processing. */
13170 case R_PPC64_ADDR16_HA
:
13171 case R_PPC64_REL16_HA
:
13172 case R_PPC64_ADDR16_HIGHERA
:
13173 case R_PPC64_ADDR16_HIGHESTA
:
13174 case R_PPC64_TOC16_HA
:
13175 case R_PPC64_SECTOFF_HA
:
13176 case R_PPC64_TPREL16_HA
:
13177 case R_PPC64_DTPREL16_HA
:
13178 case R_PPC64_TPREL16_HIGHER
:
13179 case R_PPC64_TPREL16_HIGHERA
:
13180 case R_PPC64_TPREL16_HIGHEST
:
13181 case R_PPC64_TPREL16_HIGHESTA
:
13182 case R_PPC64_DTPREL16_HIGHER
:
13183 case R_PPC64_DTPREL16_HIGHERA
:
13184 case R_PPC64_DTPREL16_HIGHEST
:
13185 case R_PPC64_DTPREL16_HIGHESTA
:
13186 /* It's just possible that this symbol is a weak symbol
13187 that's not actually defined anywhere. In that case,
13188 'sec' would be NULL, and we should leave the symbol
13189 alone (it will be set to zero elsewhere in the link). */
13194 case R_PPC64_GOT16_HA
:
13195 case R_PPC64_PLTGOT16_HA
:
13196 case R_PPC64_PLT16_HA
:
13197 case R_PPC64_GOT_TLSGD16_HA
:
13198 case R_PPC64_GOT_TLSLD16_HA
:
13199 case R_PPC64_GOT_TPREL16_HA
:
13200 case R_PPC64_GOT_DTPREL16_HA
:
13201 /* Add 0x10000 if sign bit in 0:15 is set.
13202 Bits 0:15 are not used. */
13206 case R_PPC64_ADDR16_DS
:
13207 case R_PPC64_ADDR16_LO_DS
:
13208 case R_PPC64_GOT16_DS
:
13209 case R_PPC64_GOT16_LO_DS
:
13210 case R_PPC64_PLT16_LO_DS
:
13211 case R_PPC64_SECTOFF_DS
:
13212 case R_PPC64_SECTOFF_LO_DS
:
13213 case R_PPC64_TOC16_DS
:
13214 case R_PPC64_TOC16_LO_DS
:
13215 case R_PPC64_PLTGOT16_DS
:
13216 case R_PPC64_PLTGOT16_LO_DS
:
13217 case R_PPC64_GOT_TPREL16_DS
:
13218 case R_PPC64_GOT_TPREL16_LO_DS
:
13219 case R_PPC64_GOT_DTPREL16_DS
:
13220 case R_PPC64_GOT_DTPREL16_LO_DS
:
13221 case R_PPC64_TPREL16_DS
:
13222 case R_PPC64_TPREL16_LO_DS
:
13223 case R_PPC64_DTPREL16_DS
:
13224 case R_PPC64_DTPREL16_LO_DS
:
13225 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
13227 /* If this reloc is against an lq insn, then the value must be
13228 a multiple of 16. This is somewhat of a hack, but the
13229 "correct" way to do this by defining _DQ forms of all the
13230 _DS relocs bloats all reloc switches in this file. It
13231 doesn't seem to make much sense to use any of these relocs
13232 in data, so testing the insn should be safe. */
13233 if ((insn
& (0x3f << 26)) == (56u << 26))
13235 if (((relocation
+ addend
) & mask
) != 0)
13237 info
->callbacks
->einfo
13238 (_("%H: error: %s not a multiple of %u\n"),
13239 input_bfd
, input_section
, rel
->r_offset
,
13240 ppc64_elf_howto_table
[r_type
]->name
,
13242 bfd_set_error (bfd_error_bad_value
);
13249 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
13250 because such sections are not SEC_ALLOC and thus ld.so will
13251 not process them. */
13252 if (unresolved_reloc
13253 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
13254 && h
->elf
.def_dynamic
))
13256 info
->callbacks
->einfo
13257 (_("%H: unresolvable %s relocation against symbol `%s'\n"),
13258 input_bfd
, input_section
, rel
->r_offset
,
13259 ppc64_elf_howto_table
[(int) r_type
]->name
,
13260 h
->elf
.root
.root
.string
);
13264 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
13272 if (r
!= bfd_reloc_ok
)
13274 if (sym_name
== NULL
)
13275 sym_name
= "(null)";
13276 if (r
== bfd_reloc_overflow
)
13281 && h
->elf
.root
.type
== bfd_link_hash_undefweak
13282 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
13284 /* Assume this is a call protected by other code that
13285 detects the symbol is undefined. If this is the case,
13286 we can safely ignore the overflow. If not, the
13287 program is hosed anyway, and a little warning isn't
13293 if (!((*info
->callbacks
->reloc_overflow
)
13294 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
13295 ppc64_elf_howto_table
[r_type
]->name
,
13296 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
13301 info
->callbacks
->einfo
13302 (_("%H: %s reloc against `%s': error %d\n"),
13303 input_bfd
, input_section
, rel
->r_offset
,
13304 ppc64_elf_howto_table
[r_type
]->name
,
13312 if (ha_opt
!= NULL
)
13316 unsigned char *opt
= ha_opt
;
13318 relend
= relocs
+ input_section
->reloc_count
;
13319 for (; rel
< relend
; opt
++, rel
++)
13322 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
13323 bfd_put_32 (input_bfd
, NOP
, p
);
13329 /* If we're emitting relocations, then shortly after this function
13330 returns, reloc offsets and addends for this section will be
13331 adjusted. Worse, reloc symbol indices will be for the output
13332 file rather than the input. Save a copy of the relocs for
13333 opd_entry_value. */
13334 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
13337 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
13338 rel
= bfd_alloc (input_bfd
, amt
);
13339 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
13340 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
13343 memcpy (rel
, relocs
, amt
);
13348 /* Adjust the value of any local symbols in opd sections. */
13351 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
13352 const char *name ATTRIBUTE_UNUSED
,
13353 Elf_Internal_Sym
*elfsym
,
13354 asection
*input_sec
,
13355 struct elf_link_hash_entry
*h
)
13357 struct _opd_sec_data
*opd
;
13364 opd
= get_opd_info (input_sec
);
13365 if (opd
== NULL
|| opd
->adjust
== NULL
)
13368 value
= elfsym
->st_value
- input_sec
->output_offset
;
13369 if (!info
->relocatable
)
13370 value
-= input_sec
->output_section
->vma
;
13372 adjust
= opd
->adjust
[value
/ 8];
13376 elfsym
->st_value
+= adjust
;
13380 /* Finish up dynamic symbol handling. We set the contents of various
13381 dynamic sections here. */
13384 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
13385 struct bfd_link_info
*info
,
13386 struct elf_link_hash_entry
*h
,
13387 Elf_Internal_Sym
*sym
)
13389 struct ppc_link_hash_table
*htab
;
13390 struct plt_entry
*ent
;
13391 Elf_Internal_Rela rela
;
13394 htab
= ppc_hash_table (info
);
13398 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13399 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13401 /* This symbol has an entry in the procedure linkage
13402 table. Set it up. */
13403 if (!htab
->elf
.dynamic_sections_created
13404 || h
->dynindx
== -1)
13406 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
13408 && (h
->root
.type
== bfd_link_hash_defined
13409 || h
->root
.type
== bfd_link_hash_defweak
));
13410 rela
.r_offset
= (htab
->iplt
->output_section
->vma
13411 + htab
->iplt
->output_offset
13412 + ent
->plt
.offset
);
13413 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13414 rela
.r_addend
= (h
->root
.u
.def
.value
13415 + h
->root
.u
.def
.section
->output_offset
13416 + h
->root
.u
.def
.section
->output_section
->vma
13418 loc
= (htab
->reliplt
->contents
13419 + (htab
->reliplt
->reloc_count
++
13420 * sizeof (Elf64_External_Rela
)));
13424 rela
.r_offset
= (htab
->plt
->output_section
->vma
13425 + htab
->plt
->output_offset
13426 + ent
->plt
.offset
);
13427 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13428 rela
.r_addend
= ent
->addend
;
13429 loc
= (htab
->relplt
->contents
13430 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
)
13431 / (PLT_ENTRY_SIZE
/ sizeof (Elf64_External_Rela
))));
13433 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13438 /* This symbol needs a copy reloc. Set it up. */
13440 if (h
->dynindx
== -1
13441 || (h
->root
.type
!= bfd_link_hash_defined
13442 && h
->root
.type
!= bfd_link_hash_defweak
)
13443 || htab
->relbss
== NULL
)
13446 rela
.r_offset
= (h
->root
.u
.def
.value
13447 + h
->root
.u
.def
.section
->output_section
->vma
13448 + h
->root
.u
.def
.section
->output_offset
);
13449 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
13451 loc
= htab
->relbss
->contents
;
13452 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
13453 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
13456 /* Mark some specially defined symbols as absolute. */
13457 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
13458 sym
->st_shndx
= SHN_ABS
;
13463 /* Used to decide how to sort relocs in an optimal manner for the
13464 dynamic linker, before writing them out. */
13466 static enum elf_reloc_type_class
13467 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
13469 enum elf_ppc64_reloc_type r_type
;
13471 r_type
= ELF64_R_TYPE (rela
->r_info
);
13474 case R_PPC64_RELATIVE
:
13475 return reloc_class_relative
;
13476 case R_PPC64_JMP_SLOT
:
13477 return reloc_class_plt
;
13479 return reloc_class_copy
;
13481 return reloc_class_normal
;
13485 /* Finish up the dynamic sections. */
13488 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
13489 struct bfd_link_info
*info
)
13491 struct ppc_link_hash_table
*htab
;
13495 htab
= ppc_hash_table (info
);
13499 dynobj
= htab
->elf
.dynobj
;
13500 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
13502 if (htab
->elf
.dynamic_sections_created
)
13504 Elf64_External_Dyn
*dyncon
, *dynconend
;
13506 if (sdyn
== NULL
|| htab
->got
== NULL
)
13509 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
13510 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
13511 for (; dyncon
< dynconend
; dyncon
++)
13513 Elf_Internal_Dyn dyn
;
13516 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
13523 case DT_PPC64_GLINK
:
13525 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13526 /* We stupidly defined DT_PPC64_GLINK to be the start
13527 of glink rather than the first entry point, which is
13528 what ld.so needs, and now have a bigger stub to
13529 support automatic multiple TOCs. */
13530 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
13534 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13537 dyn
.d_un
.d_ptr
= s
->vma
;
13540 case DT_PPC64_OPDSZ
:
13541 s
= bfd_get_section_by_name (output_bfd
, ".opd");
13544 dyn
.d_un
.d_val
= s
->size
;
13549 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13554 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
13558 dyn
.d_un
.d_val
= htab
->relplt
->size
;
13562 /* Don't count procedure linkage table relocs in the
13563 overall reloc count. */
13567 dyn
.d_un
.d_val
-= s
->size
;
13571 /* We may not be using the standard ELF linker script.
13572 If .rela.plt is the first .rela section, we adjust
13573 DT_RELA to not include it. */
13577 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
13579 dyn
.d_un
.d_ptr
+= s
->size
;
13583 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13587 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
13589 /* Fill in the first entry in the global offset table.
13590 We use it to hold the link-time TOCbase. */
13591 bfd_put_64 (output_bfd
,
13592 elf_gp (output_bfd
) + TOC_BASE_OFF
,
13593 htab
->got
->contents
);
13595 /* Set .got entry size. */
13596 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
13599 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
13601 /* Set .plt entry size. */
13602 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
13606 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
13607 brlt ourselves if emitrelocations. */
13608 if (htab
->brlt
!= NULL
13609 && htab
->brlt
->reloc_count
!= 0
13610 && !_bfd_elf_link_output_relocs (output_bfd
,
13612 elf_section_data (htab
->brlt
)->rela
.hdr
,
13613 elf_section_data (htab
->brlt
)->relocs
,
13617 if (htab
->glink
!= NULL
13618 && htab
->glink
->reloc_count
!= 0
13619 && !_bfd_elf_link_output_relocs (output_bfd
,
13621 elf_section_data (htab
->glink
)->rela
.hdr
,
13622 elf_section_data (htab
->glink
)->relocs
,
13626 /* We need to handle writing out multiple GOT sections ourselves,
13627 since we didn't add them to DYNOBJ. We know dynobj is the first
13629 while ((dynobj
= dynobj
->link_next
) != NULL
)
13633 if (!is_ppc64_elf (dynobj
))
13636 s
= ppc64_elf_tdata (dynobj
)->got
;
13639 && s
->output_section
!= bfd_abs_section_ptr
13640 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13641 s
->contents
, s
->output_offset
,
13644 s
= ppc64_elf_tdata (dynobj
)->relgot
;
13647 && s
->output_section
!= bfd_abs_section_ptr
13648 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
13649 s
->contents
, s
->output_offset
,
13657 #include "elf64-target.h"