1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 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 <amodra@bigpond.net.au>
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 2 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. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
33 #include "elf/ppc64.h"
34 #include "elf64-ppc.h"
36 static bfd_reloc_status_type ppc64_elf_ha_reloc
37 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
38 static bfd_reloc_status_type ppc64_elf_branch_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_toc_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc64_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_vma opd_entry_value
55 (asection
*, bfd_vma
, asection
**, bfd_vma
*);
57 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
58 #define TARGET_LITTLE_NAME "elf64-powerpcle"
59 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
60 #define TARGET_BIG_NAME "elf64-powerpc"
61 #define ELF_ARCH bfd_arch_powerpc
62 #define ELF_MACHINE_CODE EM_PPC64
63 #define ELF_MAXPAGESIZE 0x10000
64 #define ELF_COMMONPAGESIZE 0x1000
65 #define elf_info_to_howto ppc64_elf_info_to_howto
67 #define elf_backend_want_got_sym 0
68 #define elf_backend_want_plt_sym 0
69 #define elf_backend_plt_alignment 3
70 #define elf_backend_plt_not_loaded 1
71 #define elf_backend_got_header_size 8
72 #define elf_backend_can_gc_sections 1
73 #define elf_backend_can_refcount 1
74 #define elf_backend_rela_normal 1
76 #define bfd_elf64_mkobject ppc64_elf_mkobject
77 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
78 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
79 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
80 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
81 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
82 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
84 #define elf_backend_object_p ppc64_elf_object_p
85 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
86 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
87 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
88 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
89 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
90 #define elf_backend_check_directives ppc64_elf_check_directives
91 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
92 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
93 #define elf_backend_check_relocs ppc64_elf_check_relocs
94 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
95 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
96 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
97 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
98 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
99 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
100 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
101 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
102 #define elf_backend_action_discarded ppc64_elf_action_discarded
103 #define elf_backend_relocate_section ppc64_elf_relocate_section
104 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
105 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
106 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
107 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
108 #define elf_backend_special_sections ppc64_elf_special_sections
110 /* The name of the dynamic interpreter. This is put in the .interp
112 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
114 /* The size in bytes of an entry in the procedure linkage table. */
115 #define PLT_ENTRY_SIZE 24
117 /* The initial size of the plt reserved for the dynamic linker. */
118 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
120 /* TOC base pointers offset from start of TOC. */
121 #define TOC_BASE_OFF 0x8000
123 /* Offset of tp and dtp pointers from start of TLS block. */
124 #define TP_OFFSET 0x7000
125 #define DTP_OFFSET 0x8000
127 /* .plt call stub instructions. The normal stub is like this, but
128 sometimes the .plt entry crosses a 64k boundary and we need to
129 insert an addis to adjust r12. */
130 #define PLT_CALL_STUB_SIZE (7*4)
131 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
132 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
133 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
134 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
135 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
136 /* ld %r11,xxx+16@l(%r12) */
137 #define BCTR 0x4e800420 /* bctr */
140 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
141 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
142 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
144 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
146 /* glink call stub instructions. We enter with the index in R0. */
147 #define GLINK_CALL_STUB_SIZE (16*4)
151 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
152 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
154 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
155 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
156 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
157 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
165 #define NOP 0x60000000
167 /* Some other nops. */
168 #define CROR_151515 0x4def7b82
169 #define CROR_313131 0x4ffffb82
171 /* .glink entries for the first 32k functions are two instructions. */
172 #define LI_R0_0 0x38000000 /* li %r0,0 */
173 #define B_DOT 0x48000000 /* b . */
175 /* After that, we need two instructions to load the index, followed by
177 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
178 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
180 /* Instructions used by the save and restore reg functions. */
181 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
182 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
183 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
184 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
185 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
186 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
187 #define LI_R12_0 0x39800000 /* li %r12,0 */
188 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
189 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
190 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
191 #define BLR 0x4e800020 /* blr */
193 /* Since .opd is an array of descriptors and each entry will end up
194 with identical R_PPC64_RELATIVE relocs, there is really no need to
195 propagate .opd relocs; The dynamic linker should be taught to
196 relocate .opd without reloc entries. */
197 #ifndef NO_OPD_RELOCS
198 #define NO_OPD_RELOCS 0
201 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
203 /* Relocation HOWTO's. */
204 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
206 static reloc_howto_type ppc64_elf_howto_raw
[] = {
207 /* This reloc does nothing. */
208 HOWTO (R_PPC64_NONE
, /* type */
210 2, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE
, /* pc_relative */
214 complain_overflow_dont
, /* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_PPC64_NONE", /* name */
217 FALSE
, /* partial_inplace */
220 FALSE
), /* pcrel_offset */
222 /* A standard 32 bit relocation. */
223 HOWTO (R_PPC64_ADDR32
, /* type */
225 2, /* size (0 = byte, 1 = short, 2 = long) */
227 FALSE
, /* pc_relative */
229 complain_overflow_bitfield
, /* complain_on_overflow */
230 bfd_elf_generic_reloc
, /* special_function */
231 "R_PPC64_ADDR32", /* name */
232 FALSE
, /* partial_inplace */
234 0xffffffff, /* dst_mask */
235 FALSE
), /* pcrel_offset */
237 /* An absolute 26 bit branch; the lower two bits must be zero.
238 FIXME: we don't check that, we just clear them. */
239 HOWTO (R_PPC64_ADDR24
, /* type */
241 2, /* size (0 = byte, 1 = short, 2 = long) */
243 FALSE
, /* pc_relative */
245 complain_overflow_bitfield
, /* complain_on_overflow */
246 bfd_elf_generic_reloc
, /* special_function */
247 "R_PPC64_ADDR24", /* name */
248 FALSE
, /* partial_inplace */
250 0x03fffffc, /* dst_mask */
251 FALSE
), /* pcrel_offset */
253 /* A standard 16 bit relocation. */
254 HOWTO (R_PPC64_ADDR16
, /* type */
256 1, /* size (0 = byte, 1 = short, 2 = long) */
258 FALSE
, /* pc_relative */
260 complain_overflow_bitfield
, /* complain_on_overflow */
261 bfd_elf_generic_reloc
, /* special_function */
262 "R_PPC64_ADDR16", /* name */
263 FALSE
, /* partial_inplace */
265 0xffff, /* dst_mask */
266 FALSE
), /* pcrel_offset */
268 /* A 16 bit relocation without overflow. */
269 HOWTO (R_PPC64_ADDR16_LO
, /* type */
271 1, /* size (0 = byte, 1 = short, 2 = long) */
273 FALSE
, /* pc_relative */
275 complain_overflow_dont
,/* complain_on_overflow */
276 bfd_elf_generic_reloc
, /* special_function */
277 "R_PPC64_ADDR16_LO", /* name */
278 FALSE
, /* partial_inplace */
280 0xffff, /* dst_mask */
281 FALSE
), /* pcrel_offset */
283 /* Bits 16-31 of an address. */
284 HOWTO (R_PPC64_ADDR16_HI
, /* type */
286 1, /* size (0 = byte, 1 = short, 2 = long) */
288 FALSE
, /* pc_relative */
290 complain_overflow_dont
, /* complain_on_overflow */
291 bfd_elf_generic_reloc
, /* special_function */
292 "R_PPC64_ADDR16_HI", /* name */
293 FALSE
, /* partial_inplace */
295 0xffff, /* dst_mask */
296 FALSE
), /* pcrel_offset */
298 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
299 bits, treated as a signed number, is negative. */
300 HOWTO (R_PPC64_ADDR16_HA
, /* type */
302 1, /* size (0 = byte, 1 = short, 2 = long) */
304 FALSE
, /* pc_relative */
306 complain_overflow_dont
, /* complain_on_overflow */
307 ppc64_elf_ha_reloc
, /* special_function */
308 "R_PPC64_ADDR16_HA", /* name */
309 FALSE
, /* partial_inplace */
311 0xffff, /* dst_mask */
312 FALSE
), /* pcrel_offset */
314 /* An absolute 16 bit branch; the lower two bits must be zero.
315 FIXME: we don't check that, we just clear them. */
316 HOWTO (R_PPC64_ADDR14
, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE
, /* pc_relative */
322 complain_overflow_bitfield
, /* complain_on_overflow */
323 ppc64_elf_branch_reloc
, /* special_function */
324 "R_PPC64_ADDR14", /* name */
325 FALSE
, /* partial_inplace */
327 0x0000fffc, /* dst_mask */
328 FALSE
), /* pcrel_offset */
330 /* An absolute 16 bit branch, for which bit 10 should be set to
331 indicate that the branch is expected to be taken. The lower two
332 bits must be zero. */
333 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 FALSE
, /* pc_relative */
339 complain_overflow_bitfield
, /* complain_on_overflow */
340 ppc64_elf_brtaken_reloc
, /* special_function */
341 "R_PPC64_ADDR14_BRTAKEN",/* name */
342 FALSE
, /* partial_inplace */
344 0x0000fffc, /* dst_mask */
345 FALSE
), /* pcrel_offset */
347 /* An absolute 16 bit branch, for which bit 10 should be set to
348 indicate that the branch is not expected to be taken. The lower
349 two bits must be zero. */
350 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 FALSE
, /* pc_relative */
356 complain_overflow_bitfield
, /* complain_on_overflow */
357 ppc64_elf_brtaken_reloc
, /* special_function */
358 "R_PPC64_ADDR14_BRNTAKEN",/* name */
359 FALSE
, /* partial_inplace */
361 0x0000fffc, /* dst_mask */
362 FALSE
), /* pcrel_offset */
364 /* A relative 26 bit branch; the lower two bits must be zero. */
365 HOWTO (R_PPC64_REL24
, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 TRUE
, /* pc_relative */
371 complain_overflow_signed
, /* complain_on_overflow */
372 ppc64_elf_branch_reloc
, /* special_function */
373 "R_PPC64_REL24", /* name */
374 FALSE
, /* partial_inplace */
376 0x03fffffc, /* dst_mask */
377 TRUE
), /* pcrel_offset */
379 /* A relative 16 bit branch; the lower two bits must be zero. */
380 HOWTO (R_PPC64_REL14
, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 TRUE
, /* pc_relative */
386 complain_overflow_signed
, /* complain_on_overflow */
387 ppc64_elf_branch_reloc
, /* special_function */
388 "R_PPC64_REL14", /* name */
389 FALSE
, /* partial_inplace */
391 0x0000fffc, /* dst_mask */
392 TRUE
), /* pcrel_offset */
394 /* A relative 16 bit branch. Bit 10 should be set to indicate that
395 the branch is expected to be taken. The lower two bits must be
397 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 TRUE
, /* pc_relative */
403 complain_overflow_signed
, /* complain_on_overflow */
404 ppc64_elf_brtaken_reloc
, /* special_function */
405 "R_PPC64_REL14_BRTAKEN", /* name */
406 FALSE
, /* partial_inplace */
408 0x0000fffc, /* dst_mask */
409 TRUE
), /* pcrel_offset */
411 /* A relative 16 bit branch. Bit 10 should be set to indicate that
412 the branch is not expected to be taken. The lower two bits must
414 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 TRUE
, /* pc_relative */
420 complain_overflow_signed
, /* complain_on_overflow */
421 ppc64_elf_brtaken_reloc
, /* special_function */
422 "R_PPC64_REL14_BRNTAKEN",/* name */
423 FALSE
, /* partial_inplace */
425 0x0000fffc, /* dst_mask */
426 TRUE
), /* pcrel_offset */
428 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
430 HOWTO (R_PPC64_GOT16
, /* type */
432 1, /* size (0 = byte, 1 = short, 2 = long) */
434 FALSE
, /* pc_relative */
436 complain_overflow_signed
, /* complain_on_overflow */
437 ppc64_elf_unhandled_reloc
, /* special_function */
438 "R_PPC64_GOT16", /* name */
439 FALSE
, /* partial_inplace */
441 0xffff, /* dst_mask */
442 FALSE
), /* pcrel_offset */
444 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
446 HOWTO (R_PPC64_GOT16_LO
, /* type */
448 1, /* size (0 = byte, 1 = short, 2 = long) */
450 FALSE
, /* pc_relative */
452 complain_overflow_dont
, /* complain_on_overflow */
453 ppc64_elf_unhandled_reloc
, /* special_function */
454 "R_PPC64_GOT16_LO", /* name */
455 FALSE
, /* partial_inplace */
457 0xffff, /* dst_mask */
458 FALSE
), /* pcrel_offset */
460 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
462 HOWTO (R_PPC64_GOT16_HI
, /* type */
464 1, /* size (0 = byte, 1 = short, 2 = long) */
466 FALSE
, /* pc_relative */
468 complain_overflow_dont
,/* complain_on_overflow */
469 ppc64_elf_unhandled_reloc
, /* special_function */
470 "R_PPC64_GOT16_HI", /* name */
471 FALSE
, /* partial_inplace */
473 0xffff, /* dst_mask */
474 FALSE
), /* pcrel_offset */
476 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
478 HOWTO (R_PPC64_GOT16_HA
, /* type */
480 1, /* size (0 = byte, 1 = short, 2 = long) */
482 FALSE
, /* pc_relative */
484 complain_overflow_dont
,/* complain_on_overflow */
485 ppc64_elf_unhandled_reloc
, /* special_function */
486 "R_PPC64_GOT16_HA", /* name */
487 FALSE
, /* partial_inplace */
489 0xffff, /* dst_mask */
490 FALSE
), /* pcrel_offset */
492 /* This is used only by the dynamic linker. The symbol should exist
493 both in the object being run and in some shared library. The
494 dynamic linker copies the data addressed by the symbol from the
495 shared library into the object, because the object being
496 run has to have the data at some particular address. */
497 HOWTO (R_PPC64_COPY
, /* type */
499 0, /* this one is variable size */
501 FALSE
, /* pc_relative */
503 complain_overflow_dont
, /* complain_on_overflow */
504 ppc64_elf_unhandled_reloc
, /* special_function */
505 "R_PPC64_COPY", /* name */
506 FALSE
, /* partial_inplace */
509 FALSE
), /* pcrel_offset */
511 /* Like R_PPC64_ADDR64, but used when setting global offset table
513 HOWTO (R_PPC64_GLOB_DAT
, /* type */
515 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
517 FALSE
, /* pc_relative */
519 complain_overflow_dont
, /* complain_on_overflow */
520 ppc64_elf_unhandled_reloc
, /* special_function */
521 "R_PPC64_GLOB_DAT", /* name */
522 FALSE
, /* partial_inplace */
524 ONES (64), /* dst_mask */
525 FALSE
), /* pcrel_offset */
527 /* Created by the link editor. Marks a procedure linkage table
528 entry for a symbol. */
529 HOWTO (R_PPC64_JMP_SLOT
, /* type */
531 0, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE
, /* pc_relative */
535 complain_overflow_dont
, /* complain_on_overflow */
536 ppc64_elf_unhandled_reloc
, /* special_function */
537 "R_PPC64_JMP_SLOT", /* name */
538 FALSE
, /* partial_inplace */
541 FALSE
), /* pcrel_offset */
543 /* Used only by the dynamic linker. When the object is run, this
544 doubleword64 is set to the load address of the object, plus the
546 HOWTO (R_PPC64_RELATIVE
, /* type */
548 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
550 FALSE
, /* pc_relative */
552 complain_overflow_dont
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_PPC64_RELATIVE", /* name */
555 FALSE
, /* partial_inplace */
557 ONES (64), /* dst_mask */
558 FALSE
), /* pcrel_offset */
560 /* Like R_PPC64_ADDR32, but may be unaligned. */
561 HOWTO (R_PPC64_UADDR32
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 FALSE
, /* pc_relative */
567 complain_overflow_bitfield
, /* complain_on_overflow */
568 bfd_elf_generic_reloc
, /* special_function */
569 "R_PPC64_UADDR32", /* name */
570 FALSE
, /* partial_inplace */
572 0xffffffff, /* dst_mask */
573 FALSE
), /* pcrel_offset */
575 /* Like R_PPC64_ADDR16, but may be unaligned. */
576 HOWTO (R_PPC64_UADDR16
, /* type */
578 1, /* size (0 = byte, 1 = short, 2 = long) */
580 FALSE
, /* pc_relative */
582 complain_overflow_bitfield
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_PPC64_UADDR16", /* name */
585 FALSE
, /* partial_inplace */
587 0xffff, /* dst_mask */
588 FALSE
), /* pcrel_offset */
590 /* 32-bit PC relative. */
591 HOWTO (R_PPC64_REL32
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 TRUE
, /* pc_relative */
597 /* FIXME: Verify. Was complain_overflow_bitfield. */
598 complain_overflow_signed
, /* complain_on_overflow */
599 bfd_elf_generic_reloc
, /* special_function */
600 "R_PPC64_REL32", /* name */
601 FALSE
, /* partial_inplace */
603 0xffffffff, /* dst_mask */
604 TRUE
), /* pcrel_offset */
606 /* 32-bit relocation to the symbol's procedure linkage table. */
607 HOWTO (R_PPC64_PLT32
, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 FALSE
, /* pc_relative */
613 complain_overflow_bitfield
, /* complain_on_overflow */
614 ppc64_elf_unhandled_reloc
, /* special_function */
615 "R_PPC64_PLT32", /* name */
616 FALSE
, /* partial_inplace */
618 0xffffffff, /* dst_mask */
619 FALSE
), /* pcrel_offset */
621 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
622 FIXME: R_PPC64_PLTREL32 not supported. */
623 HOWTO (R_PPC64_PLTREL32
, /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 TRUE
, /* pc_relative */
629 complain_overflow_signed
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_PPC64_PLTREL32", /* name */
632 FALSE
, /* partial_inplace */
634 0xffffffff, /* dst_mask */
635 TRUE
), /* pcrel_offset */
637 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
639 HOWTO (R_PPC64_PLT16_LO
, /* type */
641 1, /* size (0 = byte, 1 = short, 2 = long) */
643 FALSE
, /* pc_relative */
645 complain_overflow_dont
, /* complain_on_overflow */
646 ppc64_elf_unhandled_reloc
, /* special_function */
647 "R_PPC64_PLT16_LO", /* name */
648 FALSE
, /* partial_inplace */
650 0xffff, /* dst_mask */
651 FALSE
), /* pcrel_offset */
653 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
655 HOWTO (R_PPC64_PLT16_HI
, /* type */
657 1, /* size (0 = byte, 1 = short, 2 = long) */
659 FALSE
, /* pc_relative */
661 complain_overflow_dont
, /* complain_on_overflow */
662 ppc64_elf_unhandled_reloc
, /* special_function */
663 "R_PPC64_PLT16_HI", /* name */
664 FALSE
, /* partial_inplace */
666 0xffff, /* dst_mask */
667 FALSE
), /* pcrel_offset */
669 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
671 HOWTO (R_PPC64_PLT16_HA
, /* type */
673 1, /* size (0 = byte, 1 = short, 2 = long) */
675 FALSE
, /* pc_relative */
677 complain_overflow_dont
, /* complain_on_overflow */
678 ppc64_elf_unhandled_reloc
, /* special_function */
679 "R_PPC64_PLT16_HA", /* name */
680 FALSE
, /* partial_inplace */
682 0xffff, /* dst_mask */
683 FALSE
), /* pcrel_offset */
685 /* 16-bit section relative relocation. */
686 HOWTO (R_PPC64_SECTOFF
, /* type */
688 1, /* size (0 = byte, 1 = short, 2 = long) */
690 FALSE
, /* pc_relative */
692 complain_overflow_bitfield
, /* complain_on_overflow */
693 ppc64_elf_sectoff_reloc
, /* special_function */
694 "R_PPC64_SECTOFF", /* name */
695 FALSE
, /* partial_inplace */
697 0xffff, /* dst_mask */
698 FALSE
), /* pcrel_offset */
700 /* Like R_PPC64_SECTOFF, but no overflow warning. */
701 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
703 1, /* size (0 = byte, 1 = short, 2 = long) */
705 FALSE
, /* pc_relative */
707 complain_overflow_dont
, /* complain_on_overflow */
708 ppc64_elf_sectoff_reloc
, /* special_function */
709 "R_PPC64_SECTOFF_LO", /* name */
710 FALSE
, /* partial_inplace */
712 0xffff, /* dst_mask */
713 FALSE
), /* pcrel_offset */
715 /* 16-bit upper half section relative relocation. */
716 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 FALSE
, /* pc_relative */
722 complain_overflow_dont
, /* complain_on_overflow */
723 ppc64_elf_sectoff_reloc
, /* special_function */
724 "R_PPC64_SECTOFF_HI", /* name */
725 FALSE
, /* partial_inplace */
727 0xffff, /* dst_mask */
728 FALSE
), /* pcrel_offset */
730 /* 16-bit upper half adjusted section relative relocation. */
731 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
733 1, /* size (0 = byte, 1 = short, 2 = long) */
735 FALSE
, /* pc_relative */
737 complain_overflow_dont
, /* complain_on_overflow */
738 ppc64_elf_sectoff_ha_reloc
, /* special_function */
739 "R_PPC64_SECTOFF_HA", /* name */
740 FALSE
, /* partial_inplace */
742 0xffff, /* dst_mask */
743 FALSE
), /* pcrel_offset */
745 /* Like R_PPC64_REL24 without touching the two least significant bits. */
746 HOWTO (R_PPC64_REL30
, /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 TRUE
, /* pc_relative */
752 complain_overflow_dont
, /* complain_on_overflow */
753 bfd_elf_generic_reloc
, /* special_function */
754 "R_PPC64_REL30", /* name */
755 FALSE
, /* partial_inplace */
757 0xfffffffc, /* dst_mask */
758 TRUE
), /* pcrel_offset */
760 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
762 /* A standard 64-bit relocation. */
763 HOWTO (R_PPC64_ADDR64
, /* type */
765 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
767 FALSE
, /* pc_relative */
769 complain_overflow_dont
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_PPC64_ADDR64", /* name */
772 FALSE
, /* partial_inplace */
774 ONES (64), /* dst_mask */
775 FALSE
), /* pcrel_offset */
777 /* The bits 32-47 of an address. */
778 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
780 1, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_dont
, /* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_PPC64_ADDR16_HIGHER", /* name */
787 FALSE
, /* partial_inplace */
789 0xffff, /* dst_mask */
790 FALSE
), /* pcrel_offset */
792 /* The bits 32-47 of an address, plus 1 if the contents of the low
793 16 bits, treated as a signed number, is negative. */
794 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
796 1, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE
, /* pc_relative */
800 complain_overflow_dont
, /* complain_on_overflow */
801 ppc64_elf_ha_reloc
, /* special_function */
802 "R_PPC64_ADDR16_HIGHERA", /* name */
803 FALSE
, /* partial_inplace */
805 0xffff, /* dst_mask */
806 FALSE
), /* pcrel_offset */
808 /* The bits 48-63 of an address. */
809 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
811 1, /* size (0 = byte, 1 = short, 2 = long) */
813 FALSE
, /* pc_relative */
815 complain_overflow_dont
, /* complain_on_overflow */
816 bfd_elf_generic_reloc
, /* special_function */
817 "R_PPC64_ADDR16_HIGHEST", /* name */
818 FALSE
, /* partial_inplace */
820 0xffff, /* dst_mask */
821 FALSE
), /* pcrel_offset */
823 /* The bits 48-63 of an address, plus 1 if the contents of the low
824 16 bits, treated as a signed number, is negative. */
825 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
827 1, /* size (0 = byte, 1 = short, 2 = long) */
829 FALSE
, /* pc_relative */
831 complain_overflow_dont
, /* complain_on_overflow */
832 ppc64_elf_ha_reloc
, /* special_function */
833 "R_PPC64_ADDR16_HIGHESTA", /* name */
834 FALSE
, /* partial_inplace */
836 0xffff, /* dst_mask */
837 FALSE
), /* pcrel_offset */
839 /* Like ADDR64, but may be unaligned. */
840 HOWTO (R_PPC64_UADDR64
, /* type */
842 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
844 FALSE
, /* pc_relative */
846 complain_overflow_dont
, /* complain_on_overflow */
847 bfd_elf_generic_reloc
, /* special_function */
848 "R_PPC64_UADDR64", /* name */
849 FALSE
, /* partial_inplace */
851 ONES (64), /* dst_mask */
852 FALSE
), /* pcrel_offset */
854 /* 64-bit relative relocation. */
855 HOWTO (R_PPC64_REL64
, /* type */
857 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
859 TRUE
, /* pc_relative */
861 complain_overflow_dont
, /* complain_on_overflow */
862 bfd_elf_generic_reloc
, /* special_function */
863 "R_PPC64_REL64", /* name */
864 FALSE
, /* partial_inplace */
866 ONES (64), /* dst_mask */
867 TRUE
), /* pcrel_offset */
869 /* 64-bit relocation to the symbol's procedure linkage table. */
870 HOWTO (R_PPC64_PLT64
, /* type */
872 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
874 FALSE
, /* pc_relative */
876 complain_overflow_dont
, /* complain_on_overflow */
877 ppc64_elf_unhandled_reloc
, /* special_function */
878 "R_PPC64_PLT64", /* name */
879 FALSE
, /* partial_inplace */
881 ONES (64), /* dst_mask */
882 FALSE
), /* pcrel_offset */
884 /* 64-bit PC relative relocation to the symbol's procedure linkage
886 /* FIXME: R_PPC64_PLTREL64 not supported. */
887 HOWTO (R_PPC64_PLTREL64
, /* type */
889 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
891 TRUE
, /* pc_relative */
893 complain_overflow_dont
, /* complain_on_overflow */
894 ppc64_elf_unhandled_reloc
, /* special_function */
895 "R_PPC64_PLTREL64", /* name */
896 FALSE
, /* partial_inplace */
898 ONES (64), /* dst_mask */
899 TRUE
), /* pcrel_offset */
901 /* 16 bit TOC-relative relocation. */
903 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
904 HOWTO (R_PPC64_TOC16
, /* type */
906 1, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_signed
, /* complain_on_overflow */
911 ppc64_elf_toc_reloc
, /* special_function */
912 "R_PPC64_TOC16", /* name */
913 FALSE
, /* partial_inplace */
915 0xffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* 16 bit TOC-relative relocation without overflow. */
920 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
921 HOWTO (R_PPC64_TOC16_LO
, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_dont
, /* complain_on_overflow */
928 ppc64_elf_toc_reloc
, /* special_function */
929 "R_PPC64_TOC16_LO", /* name */
930 FALSE
, /* partial_inplace */
932 0xffff, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* 16 bit TOC-relative relocation, high 16 bits. */
937 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
938 HOWTO (R_PPC64_TOC16_HI
, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
, /* complain_on_overflow */
945 ppc64_elf_toc_reloc
, /* special_function */
946 "R_PPC64_TOC16_HI", /* name */
947 FALSE
, /* partial_inplace */
949 0xffff, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
953 contents of the low 16 bits, treated as a signed number, is
956 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
957 HOWTO (R_PPC64_TOC16_HA
, /* type */
959 1, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_dont
, /* complain_on_overflow */
964 ppc64_elf_toc_ha_reloc
, /* special_function */
965 "R_PPC64_TOC16_HA", /* name */
966 FALSE
, /* partial_inplace */
968 0xffff, /* dst_mask */
969 FALSE
), /* pcrel_offset */
971 /* 64-bit relocation; insert value of TOC base (.TOC.). */
973 /* R_PPC64_TOC 51 doubleword64 .TOC. */
974 HOWTO (R_PPC64_TOC
, /* type */
976 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
978 FALSE
, /* pc_relative */
980 complain_overflow_bitfield
, /* complain_on_overflow */
981 ppc64_elf_toc64_reloc
, /* special_function */
982 "R_PPC64_TOC", /* name */
983 FALSE
, /* partial_inplace */
985 ONES (64), /* dst_mask */
986 FALSE
), /* pcrel_offset */
988 /* Like R_PPC64_GOT16, but also informs the link editor that the
989 value to relocate may (!) refer to a PLT entry which the link
990 editor (a) may replace with the symbol value. If the link editor
991 is unable to fully resolve the symbol, it may (b) create a PLT
992 entry and store the address to the new PLT entry in the GOT.
993 This permits lazy resolution of function symbols at run time.
994 The link editor may also skip all of this and just (c) emit a
995 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
996 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
997 HOWTO (R_PPC64_PLTGOT16
, /* type */
999 1, /* size (0 = byte, 1 = short, 2 = long) */
1001 FALSE
, /* pc_relative */
1003 complain_overflow_signed
, /* complain_on_overflow */
1004 ppc64_elf_unhandled_reloc
, /* special_function */
1005 "R_PPC64_PLTGOT16", /* name */
1006 FALSE
, /* partial_inplace */
1008 0xffff, /* dst_mask */
1009 FALSE
), /* pcrel_offset */
1011 /* Like R_PPC64_PLTGOT16, but without overflow. */
1012 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1013 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_dont
, /* complain_on_overflow */
1020 ppc64_elf_unhandled_reloc
, /* special_function */
1021 "R_PPC64_PLTGOT16_LO", /* name */
1022 FALSE
, /* partial_inplace */
1024 0xffff, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1028 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1029 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1030 16, /* rightshift */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_dont
, /* complain_on_overflow */
1036 ppc64_elf_unhandled_reloc
, /* special_function */
1037 "R_PPC64_PLTGOT16_HI", /* name */
1038 FALSE
, /* partial_inplace */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1044 1 if the contents of the low 16 bits, treated as a signed number,
1046 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1047 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1048 16, /* rightshift */
1049 1, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE
, /* pc_relative */
1053 complain_overflow_dont
,/* complain_on_overflow */
1054 ppc64_elf_unhandled_reloc
, /* special_function */
1055 "R_PPC64_PLTGOT16_HA", /* name */
1056 FALSE
, /* partial_inplace */
1058 0xffff, /* dst_mask */
1059 FALSE
), /* pcrel_offset */
1061 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1062 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1064 1, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE
, /* pc_relative */
1068 complain_overflow_bitfield
, /* complain_on_overflow */
1069 bfd_elf_generic_reloc
, /* special_function */
1070 "R_PPC64_ADDR16_DS", /* name */
1071 FALSE
, /* partial_inplace */
1073 0xfffc, /* dst_mask */
1074 FALSE
), /* pcrel_offset */
1076 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1077 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1079 1, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE
, /* pc_relative */
1083 complain_overflow_dont
,/* complain_on_overflow */
1084 bfd_elf_generic_reloc
, /* special_function */
1085 "R_PPC64_ADDR16_LO_DS",/* name */
1086 FALSE
, /* partial_inplace */
1088 0xfffc, /* dst_mask */
1089 FALSE
), /* pcrel_offset */
1091 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1092 HOWTO (R_PPC64_GOT16_DS
, /* type */
1094 1, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_signed
, /* complain_on_overflow */
1099 ppc64_elf_unhandled_reloc
, /* special_function */
1100 "R_PPC64_GOT16_DS", /* name */
1101 FALSE
, /* partial_inplace */
1103 0xfffc, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1107 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1109 1, /* size (0 = byte, 1 = short, 2 = long) */
1111 FALSE
, /* pc_relative */
1113 complain_overflow_dont
, /* complain_on_overflow */
1114 ppc64_elf_unhandled_reloc
, /* special_function */
1115 "R_PPC64_GOT16_LO_DS", /* name */
1116 FALSE
, /* partial_inplace */
1118 0xfffc, /* dst_mask */
1119 FALSE
), /* pcrel_offset */
1121 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1122 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1126 FALSE
, /* pc_relative */
1128 complain_overflow_dont
, /* complain_on_overflow */
1129 ppc64_elf_unhandled_reloc
, /* special_function */
1130 "R_PPC64_PLT16_LO_DS", /* name */
1131 FALSE
, /* partial_inplace */
1133 0xfffc, /* dst_mask */
1134 FALSE
), /* pcrel_offset */
1136 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1137 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1139 1, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE
, /* pc_relative */
1143 complain_overflow_bitfield
, /* complain_on_overflow */
1144 ppc64_elf_sectoff_reloc
, /* special_function */
1145 "R_PPC64_SECTOFF_DS", /* name */
1146 FALSE
, /* partial_inplace */
1148 0xfffc, /* dst_mask */
1149 FALSE
), /* pcrel_offset */
1151 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1152 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1154 1, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE
, /* pc_relative */
1158 complain_overflow_dont
, /* complain_on_overflow */
1159 ppc64_elf_sectoff_reloc
, /* special_function */
1160 "R_PPC64_SECTOFF_LO_DS",/* name */
1161 FALSE
, /* partial_inplace */
1163 0xfffc, /* dst_mask */
1164 FALSE
), /* pcrel_offset */
1166 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1167 HOWTO (R_PPC64_TOC16_DS
, /* type */
1169 1, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE
, /* pc_relative */
1173 complain_overflow_signed
, /* complain_on_overflow */
1174 ppc64_elf_toc_reloc
, /* special_function */
1175 "R_PPC64_TOC16_DS", /* name */
1176 FALSE
, /* partial_inplace */
1178 0xfffc, /* dst_mask */
1179 FALSE
), /* pcrel_offset */
1181 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1182 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1184 1, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE
, /* pc_relative */
1188 complain_overflow_dont
, /* complain_on_overflow */
1189 ppc64_elf_toc_reloc
, /* special_function */
1190 "R_PPC64_TOC16_LO_DS", /* name */
1191 FALSE
, /* partial_inplace */
1193 0xfffc, /* dst_mask */
1194 FALSE
), /* pcrel_offset */
1196 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1197 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1198 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1200 1, /* size (0 = byte, 1 = short, 2 = long) */
1202 FALSE
, /* pc_relative */
1204 complain_overflow_signed
, /* complain_on_overflow */
1205 ppc64_elf_unhandled_reloc
, /* special_function */
1206 "R_PPC64_PLTGOT16_DS", /* name */
1207 FALSE
, /* partial_inplace */
1209 0xfffc, /* dst_mask */
1210 FALSE
), /* pcrel_offset */
1212 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1213 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1214 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1216 1, /* size (0 = byte, 1 = short, 2 = long) */
1218 FALSE
, /* pc_relative */
1220 complain_overflow_dont
, /* complain_on_overflow */
1221 ppc64_elf_unhandled_reloc
, /* special_function */
1222 "R_PPC64_PLTGOT16_LO_DS",/* name */
1223 FALSE
, /* partial_inplace */
1225 0xfffc, /* dst_mask */
1226 FALSE
), /* pcrel_offset */
1228 /* Marker reloc for TLS. */
1231 2, /* size (0 = byte, 1 = short, 2 = long) */
1233 FALSE
, /* pc_relative */
1235 complain_overflow_dont
, /* complain_on_overflow */
1236 bfd_elf_generic_reloc
, /* special_function */
1237 "R_PPC64_TLS", /* name */
1238 FALSE
, /* partial_inplace */
1241 FALSE
), /* pcrel_offset */
1243 /* Computes the load module index of the load module that contains the
1244 definition of its TLS sym. */
1245 HOWTO (R_PPC64_DTPMOD64
,
1247 4, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE
, /* pc_relative */
1251 complain_overflow_dont
, /* complain_on_overflow */
1252 ppc64_elf_unhandled_reloc
, /* special_function */
1253 "R_PPC64_DTPMOD64", /* name */
1254 FALSE
, /* partial_inplace */
1256 ONES (64), /* dst_mask */
1257 FALSE
), /* pcrel_offset */
1259 /* Computes a dtv-relative displacement, the difference between the value
1260 of sym+add and the base address of the thread-local storage block that
1261 contains the definition of sym, minus 0x8000. */
1262 HOWTO (R_PPC64_DTPREL64
,
1264 4, /* size (0 = byte, 1 = short, 2 = long) */
1266 FALSE
, /* pc_relative */
1268 complain_overflow_dont
, /* complain_on_overflow */
1269 ppc64_elf_unhandled_reloc
, /* special_function */
1270 "R_PPC64_DTPREL64", /* name */
1271 FALSE
, /* partial_inplace */
1273 ONES (64), /* dst_mask */
1274 FALSE
), /* pcrel_offset */
1276 /* A 16 bit dtprel reloc. */
1277 HOWTO (R_PPC64_DTPREL16
,
1279 1, /* size (0 = byte, 1 = short, 2 = long) */
1281 FALSE
, /* pc_relative */
1283 complain_overflow_signed
, /* complain_on_overflow */
1284 ppc64_elf_unhandled_reloc
, /* special_function */
1285 "R_PPC64_DTPREL16", /* name */
1286 FALSE
, /* partial_inplace */
1288 0xffff, /* dst_mask */
1289 FALSE
), /* pcrel_offset */
1291 /* Like DTPREL16, but no overflow. */
1292 HOWTO (R_PPC64_DTPREL16_LO
,
1294 1, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE
, /* pc_relative */
1298 complain_overflow_dont
, /* complain_on_overflow */
1299 ppc64_elf_unhandled_reloc
, /* special_function */
1300 "R_PPC64_DTPREL16_LO", /* name */
1301 FALSE
, /* partial_inplace */
1303 0xffff, /* dst_mask */
1304 FALSE
), /* pcrel_offset */
1306 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1307 HOWTO (R_PPC64_DTPREL16_HI
,
1308 16, /* rightshift */
1309 1, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE
, /* pc_relative */
1313 complain_overflow_dont
, /* complain_on_overflow */
1314 ppc64_elf_unhandled_reloc
, /* special_function */
1315 "R_PPC64_DTPREL16_HI", /* name */
1316 FALSE
, /* partial_inplace */
1318 0xffff, /* dst_mask */
1319 FALSE
), /* pcrel_offset */
1321 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1322 HOWTO (R_PPC64_DTPREL16_HA
,
1323 16, /* rightshift */
1324 1, /* size (0 = byte, 1 = short, 2 = long) */
1326 FALSE
, /* pc_relative */
1328 complain_overflow_dont
, /* complain_on_overflow */
1329 ppc64_elf_unhandled_reloc
, /* special_function */
1330 "R_PPC64_DTPREL16_HA", /* name */
1331 FALSE
, /* partial_inplace */
1333 0xffff, /* dst_mask */
1334 FALSE
), /* pcrel_offset */
1336 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1337 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1338 32, /* rightshift */
1339 1, /* size (0 = byte, 1 = short, 2 = long) */
1341 FALSE
, /* pc_relative */
1343 complain_overflow_dont
, /* complain_on_overflow */
1344 ppc64_elf_unhandled_reloc
, /* special_function */
1345 "R_PPC64_DTPREL16_HIGHER", /* name */
1346 FALSE
, /* partial_inplace */
1348 0xffff, /* dst_mask */
1349 FALSE
), /* pcrel_offset */
1351 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1352 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1353 32, /* rightshift */
1354 1, /* size (0 = byte, 1 = short, 2 = long) */
1356 FALSE
, /* pc_relative */
1358 complain_overflow_dont
, /* complain_on_overflow */
1359 ppc64_elf_unhandled_reloc
, /* special_function */
1360 "R_PPC64_DTPREL16_HIGHERA", /* name */
1361 FALSE
, /* partial_inplace */
1363 0xffff, /* dst_mask */
1364 FALSE
), /* pcrel_offset */
1366 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1367 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1368 48, /* rightshift */
1369 1, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE
, /* pc_relative */
1373 complain_overflow_dont
, /* complain_on_overflow */
1374 ppc64_elf_unhandled_reloc
, /* special_function */
1375 "R_PPC64_DTPREL16_HIGHEST", /* name */
1376 FALSE
, /* partial_inplace */
1378 0xffff, /* dst_mask */
1379 FALSE
), /* pcrel_offset */
1381 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1382 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1383 48, /* rightshift */
1384 1, /* size (0 = byte, 1 = short, 2 = long) */
1386 FALSE
, /* pc_relative */
1388 complain_overflow_dont
, /* complain_on_overflow */
1389 ppc64_elf_unhandled_reloc
, /* special_function */
1390 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1391 FALSE
, /* partial_inplace */
1393 0xffff, /* dst_mask */
1394 FALSE
), /* pcrel_offset */
1396 /* Like DTPREL16, but for insns with a DS field. */
1397 HOWTO (R_PPC64_DTPREL16_DS
,
1399 1, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE
, /* pc_relative */
1403 complain_overflow_signed
, /* complain_on_overflow */
1404 ppc64_elf_unhandled_reloc
, /* special_function */
1405 "R_PPC64_DTPREL16_DS", /* name */
1406 FALSE
, /* partial_inplace */
1408 0xfffc, /* dst_mask */
1409 FALSE
), /* pcrel_offset */
1411 /* Like DTPREL16_DS, but no overflow. */
1412 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1414 1, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE
, /* pc_relative */
1418 complain_overflow_dont
, /* complain_on_overflow */
1419 ppc64_elf_unhandled_reloc
, /* special_function */
1420 "R_PPC64_DTPREL16_LO_DS", /* name */
1421 FALSE
, /* partial_inplace */
1423 0xfffc, /* dst_mask */
1424 FALSE
), /* pcrel_offset */
1426 /* Computes a tp-relative displacement, the difference between the value of
1427 sym+add and the value of the thread pointer (r13). */
1428 HOWTO (R_PPC64_TPREL64
,
1430 4, /* size (0 = byte, 1 = short, 2 = long) */
1432 FALSE
, /* pc_relative */
1434 complain_overflow_dont
, /* complain_on_overflow */
1435 ppc64_elf_unhandled_reloc
, /* special_function */
1436 "R_PPC64_TPREL64", /* name */
1437 FALSE
, /* partial_inplace */
1439 ONES (64), /* dst_mask */
1440 FALSE
), /* pcrel_offset */
1442 /* A 16 bit tprel reloc. */
1443 HOWTO (R_PPC64_TPREL16
,
1445 1, /* size (0 = byte, 1 = short, 2 = long) */
1447 FALSE
, /* pc_relative */
1449 complain_overflow_signed
, /* complain_on_overflow */
1450 ppc64_elf_unhandled_reloc
, /* special_function */
1451 "R_PPC64_TPREL16", /* name */
1452 FALSE
, /* partial_inplace */
1454 0xffff, /* dst_mask */
1455 FALSE
), /* pcrel_offset */
1457 /* Like TPREL16, but no overflow. */
1458 HOWTO (R_PPC64_TPREL16_LO
,
1460 1, /* size (0 = byte, 1 = short, 2 = long) */
1462 FALSE
, /* pc_relative */
1464 complain_overflow_dont
, /* complain_on_overflow */
1465 ppc64_elf_unhandled_reloc
, /* special_function */
1466 "R_PPC64_TPREL16_LO", /* name */
1467 FALSE
, /* partial_inplace */
1469 0xffff, /* dst_mask */
1470 FALSE
), /* pcrel_offset */
1472 /* Like TPREL16_LO, but next higher group of 16 bits. */
1473 HOWTO (R_PPC64_TPREL16_HI
,
1474 16, /* rightshift */
1475 1, /* size (0 = byte, 1 = short, 2 = long) */
1477 FALSE
, /* pc_relative */
1479 complain_overflow_dont
, /* complain_on_overflow */
1480 ppc64_elf_unhandled_reloc
, /* special_function */
1481 "R_PPC64_TPREL16_HI", /* name */
1482 FALSE
, /* partial_inplace */
1484 0xffff, /* dst_mask */
1485 FALSE
), /* pcrel_offset */
1487 /* Like TPREL16_HI, but adjust for low 16 bits. */
1488 HOWTO (R_PPC64_TPREL16_HA
,
1489 16, /* rightshift */
1490 1, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE
, /* pc_relative */
1494 complain_overflow_dont
, /* complain_on_overflow */
1495 ppc64_elf_unhandled_reloc
, /* special_function */
1496 "R_PPC64_TPREL16_HA", /* name */
1497 FALSE
, /* partial_inplace */
1499 0xffff, /* dst_mask */
1500 FALSE
), /* pcrel_offset */
1502 /* Like TPREL16_HI, but next higher group of 16 bits. */
1503 HOWTO (R_PPC64_TPREL16_HIGHER
,
1504 32, /* rightshift */
1505 1, /* size (0 = byte, 1 = short, 2 = long) */
1507 FALSE
, /* pc_relative */
1509 complain_overflow_dont
, /* complain_on_overflow */
1510 ppc64_elf_unhandled_reloc
, /* special_function */
1511 "R_PPC64_TPREL16_HIGHER", /* name */
1512 FALSE
, /* partial_inplace */
1514 0xffff, /* dst_mask */
1515 FALSE
), /* pcrel_offset */
1517 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1518 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1519 32, /* rightshift */
1520 1, /* size (0 = byte, 1 = short, 2 = long) */
1522 FALSE
, /* pc_relative */
1524 complain_overflow_dont
, /* complain_on_overflow */
1525 ppc64_elf_unhandled_reloc
, /* special_function */
1526 "R_PPC64_TPREL16_HIGHERA", /* name */
1527 FALSE
, /* partial_inplace */
1529 0xffff, /* dst_mask */
1530 FALSE
), /* pcrel_offset */
1532 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1533 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1534 48, /* rightshift */
1535 1, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE
, /* pc_relative */
1539 complain_overflow_dont
, /* complain_on_overflow */
1540 ppc64_elf_unhandled_reloc
, /* special_function */
1541 "R_PPC64_TPREL16_HIGHEST", /* name */
1542 FALSE
, /* partial_inplace */
1544 0xffff, /* dst_mask */
1545 FALSE
), /* pcrel_offset */
1547 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1548 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1549 48, /* rightshift */
1550 1, /* size (0 = byte, 1 = short, 2 = long) */
1552 FALSE
, /* pc_relative */
1554 complain_overflow_dont
, /* complain_on_overflow */
1555 ppc64_elf_unhandled_reloc
, /* special_function */
1556 "R_PPC64_TPREL16_HIGHESTA", /* name */
1557 FALSE
, /* partial_inplace */
1559 0xffff, /* dst_mask */
1560 FALSE
), /* pcrel_offset */
1562 /* Like TPREL16, but for insns with a DS field. */
1563 HOWTO (R_PPC64_TPREL16_DS
,
1565 1, /* size (0 = byte, 1 = short, 2 = long) */
1567 FALSE
, /* pc_relative */
1569 complain_overflow_signed
, /* complain_on_overflow */
1570 ppc64_elf_unhandled_reloc
, /* special_function */
1571 "R_PPC64_TPREL16_DS", /* name */
1572 FALSE
, /* partial_inplace */
1574 0xfffc, /* dst_mask */
1575 FALSE
), /* pcrel_offset */
1577 /* Like TPREL16_DS, but no overflow. */
1578 HOWTO (R_PPC64_TPREL16_LO_DS
,
1580 1, /* size (0 = byte, 1 = short, 2 = long) */
1582 FALSE
, /* pc_relative */
1584 complain_overflow_dont
, /* complain_on_overflow */
1585 ppc64_elf_unhandled_reloc
, /* special_function */
1586 "R_PPC64_TPREL16_LO_DS", /* name */
1587 FALSE
, /* partial_inplace */
1589 0xfffc, /* dst_mask */
1590 FALSE
), /* pcrel_offset */
1592 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1593 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1594 to the first entry relative to the TOC base (r2). */
1595 HOWTO (R_PPC64_GOT_TLSGD16
,
1597 1, /* size (0 = byte, 1 = short, 2 = long) */
1599 FALSE
, /* pc_relative */
1601 complain_overflow_signed
, /* complain_on_overflow */
1602 ppc64_elf_unhandled_reloc
, /* special_function */
1603 "R_PPC64_GOT_TLSGD16", /* name */
1604 FALSE
, /* partial_inplace */
1606 0xffff, /* dst_mask */
1607 FALSE
), /* pcrel_offset */
1609 /* Like GOT_TLSGD16, but no overflow. */
1610 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1612 1, /* size (0 = byte, 1 = short, 2 = long) */
1614 FALSE
, /* pc_relative */
1616 complain_overflow_dont
, /* complain_on_overflow */
1617 ppc64_elf_unhandled_reloc
, /* special_function */
1618 "R_PPC64_GOT_TLSGD16_LO", /* name */
1619 FALSE
, /* partial_inplace */
1621 0xffff, /* dst_mask */
1622 FALSE
), /* pcrel_offset */
1624 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1625 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1626 16, /* rightshift */
1627 1, /* size (0 = byte, 1 = short, 2 = long) */
1629 FALSE
, /* pc_relative */
1631 complain_overflow_dont
, /* complain_on_overflow */
1632 ppc64_elf_unhandled_reloc
, /* special_function */
1633 "R_PPC64_GOT_TLSGD16_HI", /* name */
1634 FALSE
, /* partial_inplace */
1636 0xffff, /* dst_mask */
1637 FALSE
), /* pcrel_offset */
1639 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1640 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1641 16, /* rightshift */
1642 1, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE
, /* pc_relative */
1646 complain_overflow_dont
, /* complain_on_overflow */
1647 ppc64_elf_unhandled_reloc
, /* special_function */
1648 "R_PPC64_GOT_TLSGD16_HA", /* name */
1649 FALSE
, /* partial_inplace */
1651 0xffff, /* dst_mask */
1652 FALSE
), /* pcrel_offset */
1654 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1655 with values (sym+add)@dtpmod and zero, and computes the offset to the
1656 first entry relative to the TOC base (r2). */
1657 HOWTO (R_PPC64_GOT_TLSLD16
,
1659 1, /* size (0 = byte, 1 = short, 2 = long) */
1661 FALSE
, /* pc_relative */
1663 complain_overflow_signed
, /* complain_on_overflow */
1664 ppc64_elf_unhandled_reloc
, /* special_function */
1665 "R_PPC64_GOT_TLSLD16", /* name */
1666 FALSE
, /* partial_inplace */
1668 0xffff, /* dst_mask */
1669 FALSE
), /* pcrel_offset */
1671 /* Like GOT_TLSLD16, but no overflow. */
1672 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1674 1, /* size (0 = byte, 1 = short, 2 = long) */
1676 FALSE
, /* pc_relative */
1678 complain_overflow_dont
, /* complain_on_overflow */
1679 ppc64_elf_unhandled_reloc
, /* special_function */
1680 "R_PPC64_GOT_TLSLD16_LO", /* name */
1681 FALSE
, /* partial_inplace */
1683 0xffff, /* dst_mask */
1684 FALSE
), /* pcrel_offset */
1686 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1687 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1688 16, /* rightshift */
1689 1, /* size (0 = byte, 1 = short, 2 = long) */
1691 FALSE
, /* pc_relative */
1693 complain_overflow_dont
, /* complain_on_overflow */
1694 ppc64_elf_unhandled_reloc
, /* special_function */
1695 "R_PPC64_GOT_TLSLD16_HI", /* name */
1696 FALSE
, /* partial_inplace */
1698 0xffff, /* dst_mask */
1699 FALSE
), /* pcrel_offset */
1701 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1702 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1703 16, /* rightshift */
1704 1, /* size (0 = byte, 1 = short, 2 = long) */
1706 FALSE
, /* pc_relative */
1708 complain_overflow_dont
, /* complain_on_overflow */
1709 ppc64_elf_unhandled_reloc
, /* special_function */
1710 "R_PPC64_GOT_TLSLD16_HA", /* name */
1711 FALSE
, /* partial_inplace */
1713 0xffff, /* dst_mask */
1714 FALSE
), /* pcrel_offset */
1716 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1717 the offset to the entry relative to the TOC base (r2). */
1718 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1720 1, /* size (0 = byte, 1 = short, 2 = long) */
1722 FALSE
, /* pc_relative */
1724 complain_overflow_signed
, /* complain_on_overflow */
1725 ppc64_elf_unhandled_reloc
, /* special_function */
1726 "R_PPC64_GOT_DTPREL16_DS", /* name */
1727 FALSE
, /* partial_inplace */
1729 0xfffc, /* dst_mask */
1730 FALSE
), /* pcrel_offset */
1732 /* Like GOT_DTPREL16_DS, but no overflow. */
1733 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1735 1, /* size (0 = byte, 1 = short, 2 = long) */
1737 FALSE
, /* pc_relative */
1739 complain_overflow_dont
, /* complain_on_overflow */
1740 ppc64_elf_unhandled_reloc
, /* special_function */
1741 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1742 FALSE
, /* partial_inplace */
1744 0xfffc, /* dst_mask */
1745 FALSE
), /* pcrel_offset */
1747 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1748 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1749 16, /* rightshift */
1750 1, /* size (0 = byte, 1 = short, 2 = long) */
1752 FALSE
, /* pc_relative */
1754 complain_overflow_dont
, /* complain_on_overflow */
1755 ppc64_elf_unhandled_reloc
, /* special_function */
1756 "R_PPC64_GOT_DTPREL16_HI", /* name */
1757 FALSE
, /* partial_inplace */
1759 0xffff, /* dst_mask */
1760 FALSE
), /* pcrel_offset */
1762 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1763 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1764 16, /* rightshift */
1765 1, /* size (0 = byte, 1 = short, 2 = long) */
1767 FALSE
, /* pc_relative */
1769 complain_overflow_dont
, /* complain_on_overflow */
1770 ppc64_elf_unhandled_reloc
, /* special_function */
1771 "R_PPC64_GOT_DTPREL16_HA", /* name */
1772 FALSE
, /* partial_inplace */
1774 0xffff, /* dst_mask */
1775 FALSE
), /* pcrel_offset */
1777 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1778 offset to the entry relative to the TOC base (r2). */
1779 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1781 1, /* size (0 = byte, 1 = short, 2 = long) */
1783 FALSE
, /* pc_relative */
1785 complain_overflow_signed
, /* complain_on_overflow */
1786 ppc64_elf_unhandled_reloc
, /* special_function */
1787 "R_PPC64_GOT_TPREL16_DS", /* name */
1788 FALSE
, /* partial_inplace */
1790 0xfffc, /* dst_mask */
1791 FALSE
), /* pcrel_offset */
1793 /* Like GOT_TPREL16_DS, but no overflow. */
1794 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1796 1, /* size (0 = byte, 1 = short, 2 = long) */
1798 FALSE
, /* pc_relative */
1800 complain_overflow_dont
, /* complain_on_overflow */
1801 ppc64_elf_unhandled_reloc
, /* special_function */
1802 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1803 FALSE
, /* partial_inplace */
1805 0xfffc, /* dst_mask */
1806 FALSE
), /* pcrel_offset */
1808 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1809 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1810 16, /* rightshift */
1811 1, /* size (0 = byte, 1 = short, 2 = long) */
1813 FALSE
, /* pc_relative */
1815 complain_overflow_dont
, /* complain_on_overflow */
1816 ppc64_elf_unhandled_reloc
, /* special_function */
1817 "R_PPC64_GOT_TPREL16_HI", /* name */
1818 FALSE
, /* partial_inplace */
1820 0xffff, /* dst_mask */
1821 FALSE
), /* pcrel_offset */
1823 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1824 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1825 16, /* rightshift */
1826 1, /* size (0 = byte, 1 = short, 2 = long) */
1828 FALSE
, /* pc_relative */
1830 complain_overflow_dont
, /* complain_on_overflow */
1831 ppc64_elf_unhandled_reloc
, /* special_function */
1832 "R_PPC64_GOT_TPREL16_HA", /* name */
1833 FALSE
, /* partial_inplace */
1835 0xffff, /* dst_mask */
1836 FALSE
), /* pcrel_offset */
1838 /* GNU extension to record C++ vtable hierarchy. */
1839 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1841 0, /* size (0 = byte, 1 = short, 2 = long) */
1843 FALSE
, /* pc_relative */
1845 complain_overflow_dont
, /* complain_on_overflow */
1846 NULL
, /* special_function */
1847 "R_PPC64_GNU_VTINHERIT", /* name */
1848 FALSE
, /* partial_inplace */
1851 FALSE
), /* pcrel_offset */
1853 /* GNU extension to record C++ vtable member usage. */
1854 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1856 0, /* size (0 = byte, 1 = short, 2 = long) */
1858 FALSE
, /* pc_relative */
1860 complain_overflow_dont
, /* complain_on_overflow */
1861 NULL
, /* special_function */
1862 "R_PPC64_GNU_VTENTRY", /* name */
1863 FALSE
, /* partial_inplace */
1866 FALSE
), /* pcrel_offset */
1870 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1874 ppc_howto_init (void)
1876 unsigned int i
, type
;
1879 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1882 type
= ppc64_elf_howto_raw
[i
].type
;
1883 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1884 / sizeof (ppc64_elf_howto_table
[0])));
1885 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1889 static reloc_howto_type
*
1890 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1891 bfd_reloc_code_real_type code
)
1893 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1895 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1896 /* Initialize howto table if needed. */
1904 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1906 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1908 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1910 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1912 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1914 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1916 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1918 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1920 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1922 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1924 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1926 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1928 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1930 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1932 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1934 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1936 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1938 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1940 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1942 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1944 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1946 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1948 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1950 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1952 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1954 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1956 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1958 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1960 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1962 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1964 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1966 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1968 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1970 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1972 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1974 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1976 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1978 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1980 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1982 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1984 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1986 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1988 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1990 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1992 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1994 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1996 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1998 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2000 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2002 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2004 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2006 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2008 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2010 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2012 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2014 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2016 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2018 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2020 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2022 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2024 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2026 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2028 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2030 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2032 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2034 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2036 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2038 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2040 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2042 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2044 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2046 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2048 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2050 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2052 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2054 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2056 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2058 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2060 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2062 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2064 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2066 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2068 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2070 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2072 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2074 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2076 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2078 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2080 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2082 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2084 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2086 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2088 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2090 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2092 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2094 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2096 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2098 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2100 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2102 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2104 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2108 return ppc64_elf_howto_table
[r
];
2111 /* Set the howto pointer for a PowerPC ELF reloc. */
2114 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2115 Elf_Internal_Rela
*dst
)
2119 /* Initialize howto table if needed. */
2120 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2123 type
= ELF64_R_TYPE (dst
->r_info
);
2124 if (type
>= (sizeof (ppc64_elf_howto_table
)
2125 / sizeof (ppc64_elf_howto_table
[0])))
2127 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2129 type
= R_PPC64_NONE
;
2131 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2134 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2136 static bfd_reloc_status_type
2137 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2138 void *data
, asection
*input_section
,
2139 bfd
*output_bfd
, char **error_message
)
2141 /* If this is a relocatable link (output_bfd test tells us), just
2142 call the generic function. Any adjustment will be done at final
2144 if (output_bfd
!= NULL
)
2145 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2146 input_section
, output_bfd
, error_message
);
2148 /* Adjust the addend for sign extension of the low 16 bits.
2149 We won't actually be using the low 16 bits, so trashing them
2151 reloc_entry
->addend
+= 0x8000;
2152 return bfd_reloc_continue
;
2155 static bfd_reloc_status_type
2156 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2157 void *data
, asection
*input_section
,
2158 bfd
*output_bfd
, char **error_message
)
2160 if (output_bfd
!= NULL
)
2161 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2162 input_section
, output_bfd
, error_message
);
2164 if (strcmp (symbol
->section
->name
, ".opd") == 0
2165 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2167 bfd_vma dest
= opd_entry_value (symbol
->section
,
2168 symbol
->value
+ reloc_entry
->addend
,
2170 if (dest
!= (bfd_vma
) -1)
2171 reloc_entry
->addend
= dest
- (symbol
->value
2172 + symbol
->section
->output_section
->vma
2173 + symbol
->section
->output_offset
);
2175 return bfd_reloc_continue
;
2178 static bfd_reloc_status_type
2179 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2180 void *data
, asection
*input_section
,
2181 bfd
*output_bfd
, char **error_message
)
2184 enum elf_ppc64_reloc_type r_type
;
2185 bfd_size_type octets
;
2186 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2187 bfd_boolean is_power4
= FALSE
;
2189 /* If this is a relocatable link (output_bfd test tells us), just
2190 call the generic function. Any adjustment will be done at final
2192 if (output_bfd
!= NULL
)
2193 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2194 input_section
, output_bfd
, error_message
);
2196 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2197 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2198 insn
&= ~(0x01 << 21);
2199 r_type
= reloc_entry
->howto
->type
;
2200 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2201 || r_type
== R_PPC64_REL14_BRTAKEN
)
2202 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2206 /* Set 'a' bit. This is 0b00010 in BO field for branch
2207 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2208 for branch on CTR insns (BO == 1a00t or 1a01t). */
2209 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2211 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2221 if (!bfd_is_com_section (symbol
->section
))
2222 target
= symbol
->value
;
2223 target
+= symbol
->section
->output_section
->vma
;
2224 target
+= symbol
->section
->output_offset
;
2225 target
+= reloc_entry
->addend
;
2227 from
= (reloc_entry
->address
2228 + input_section
->output_offset
2229 + input_section
->output_section
->vma
);
2231 /* Invert 'y' bit if not the default. */
2232 if ((bfd_signed_vma
) (target
- from
) < 0)
2235 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2237 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2238 input_section
, output_bfd
, error_message
);
2241 static bfd_reloc_status_type
2242 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2243 void *data
, asection
*input_section
,
2244 bfd
*output_bfd
, char **error_message
)
2246 /* If this is a relocatable link (output_bfd test tells us), just
2247 call the generic function. Any adjustment will be done at final
2249 if (output_bfd
!= NULL
)
2250 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2251 input_section
, output_bfd
, error_message
);
2253 /* Subtract the symbol section base address. */
2254 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2255 return bfd_reloc_continue
;
2258 static bfd_reloc_status_type
2259 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2260 void *data
, asection
*input_section
,
2261 bfd
*output_bfd
, char **error_message
)
2263 /* If this is a relocatable link (output_bfd test tells us), just
2264 call the generic function. Any adjustment will be done at final
2266 if (output_bfd
!= NULL
)
2267 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2268 input_section
, output_bfd
, error_message
);
2270 /* Subtract the symbol section base address. */
2271 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2273 /* Adjust the addend for sign extension of the low 16 bits. */
2274 reloc_entry
->addend
+= 0x8000;
2275 return bfd_reloc_continue
;
2278 static bfd_reloc_status_type
2279 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2280 void *data
, asection
*input_section
,
2281 bfd
*output_bfd
, char **error_message
)
2285 /* If this is a relocatable link (output_bfd test tells us), just
2286 call the generic function. Any adjustment will be done at final
2288 if (output_bfd
!= NULL
)
2289 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2290 input_section
, output_bfd
, error_message
);
2292 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2294 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2296 /* Subtract the TOC base address. */
2297 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2298 return bfd_reloc_continue
;
2301 static bfd_reloc_status_type
2302 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2303 void *data
, asection
*input_section
,
2304 bfd
*output_bfd
, char **error_message
)
2308 /* If this is a relocatable link (output_bfd test tells us), just
2309 call the generic function. Any adjustment will be done at final
2311 if (output_bfd
!= NULL
)
2312 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2313 input_section
, output_bfd
, error_message
);
2315 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2317 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2319 /* Subtract the TOC base address. */
2320 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2322 /* Adjust the addend for sign extension of the low 16 bits. */
2323 reloc_entry
->addend
+= 0x8000;
2324 return bfd_reloc_continue
;
2327 static bfd_reloc_status_type
2328 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2329 void *data
, asection
*input_section
,
2330 bfd
*output_bfd
, char **error_message
)
2333 bfd_size_type octets
;
2335 /* If this is a relocatable link (output_bfd test tells us), just
2336 call the generic function. Any adjustment will be done at final
2338 if (output_bfd
!= NULL
)
2339 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2340 input_section
, output_bfd
, error_message
);
2342 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2344 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2346 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2347 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2348 return bfd_reloc_ok
;
2351 static bfd_reloc_status_type
2352 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2353 void *data
, asection
*input_section
,
2354 bfd
*output_bfd
, char **error_message
)
2356 /* If this is a relocatable link (output_bfd test tells us), just
2357 call the generic function. Any adjustment will be done at final
2359 if (output_bfd
!= NULL
)
2360 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2361 input_section
, output_bfd
, error_message
);
2363 if (error_message
!= NULL
)
2365 static char buf
[60];
2366 sprintf (buf
, "generic linker can't handle %s",
2367 reloc_entry
->howto
->name
);
2368 *error_message
= buf
;
2370 return bfd_reloc_dangerous
;
2373 struct ppc64_elf_obj_tdata
2375 struct elf_obj_tdata elf
;
2377 /* Shortcuts to dynamic linker sections. */
2381 /* Used during garbage collection. We attach global symbols defined
2382 on removed .opd entries to this section so that the sym is removed. */
2383 asection
*deleted_section
;
2385 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2386 sections means we potentially need one of these for each input bfd. */
2388 bfd_signed_vma refcount
;
2392 /* A copy of relocs before they are modified for --emit-relocs. */
2393 Elf_Internal_Rela
*opd_relocs
;
2396 #define ppc64_elf_tdata(bfd) \
2397 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2399 #define ppc64_tlsld_got(bfd) \
2400 (&ppc64_elf_tdata (bfd)->tlsld_got)
2402 /* Override the generic function because we store some extras. */
2405 ppc64_elf_mkobject (bfd
*abfd
)
2407 if (abfd
->tdata
.any
== NULL
)
2409 bfd_size_type amt
= sizeof (struct ppc64_elf_obj_tdata
);
2410 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2411 if (abfd
->tdata
.any
== NULL
)
2414 return bfd_elf_mkobject (abfd
);
2417 /* Return 1 if target is one of ours. */
2420 is_ppc64_elf_target (const struct bfd_target
*targ
)
2422 extern const bfd_target bfd_elf64_powerpc_vec
;
2423 extern const bfd_target bfd_elf64_powerpcle_vec
;
2425 return targ
== &bfd_elf64_powerpc_vec
|| targ
== &bfd_elf64_powerpcle_vec
;
2428 /* Fix bad default arch selected for a 64 bit input bfd when the
2429 default is 32 bit. */
2432 ppc64_elf_object_p (bfd
*abfd
)
2434 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2436 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2438 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2440 /* Relies on arch after 32 bit default being 64 bit default. */
2441 abfd
->arch_info
= abfd
->arch_info
->next
;
2442 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2448 /* Support for core dump NOTE sections. */
2451 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2453 size_t offset
, size
;
2455 if (note
->descsz
!= 504)
2459 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2462 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2468 /* Make a ".reg/999" section. */
2469 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2470 size
, note
->descpos
+ offset
);
2474 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2476 if (note
->descsz
!= 136)
2479 elf_tdata (abfd
)->core_program
2480 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2481 elf_tdata (abfd
)->core_command
2482 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2487 /* Merge backend specific data from an object file to the output
2488 object file when linking. */
2491 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2493 /* Check if we have the same endianess. */
2494 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2495 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2496 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2500 if (bfd_big_endian (ibfd
))
2501 msg
= _("%B: compiled for a big endian system "
2502 "and target is little endian");
2504 msg
= _("%B: compiled for a little endian system "
2505 "and target is big endian");
2507 (*_bfd_error_handler
) (msg
, ibfd
);
2509 bfd_set_error (bfd_error_wrong_format
);
2516 /* Add extra PPC sections. */
2518 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2520 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2521 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2522 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2523 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2524 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2525 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2526 { NULL
, 0, 0, 0, 0 }
2529 enum _ppc64_sec_type
{
2535 struct _ppc64_elf_section_data
2537 struct bfd_elf_section_data elf
;
2539 /* An array with one entry for each opd function descriptor. */
2542 /* Points to the function code section for local opd entries. */
2543 asection
**opd_func_sec
;
2544 /* After editing .opd, adjust references to opd local syms. */
2547 /* An array for toc sections, indexed by offset/8.
2548 Specifies the relocation symbol index used at a given toc offset. */
2552 enum _ppc64_sec_type sec_type
:2;
2554 /* Flag set when small branches are detected. Used to
2555 select suitable defaults for the stub group size. */
2556 unsigned int has_14bit_branch
:1;
2559 #define ppc64_elf_section_data(sec) \
2560 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2563 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2565 if (!sec
->used_by_bfd
)
2567 struct _ppc64_elf_section_data
*sdata
;
2568 bfd_size_type amt
= sizeof (*sdata
);
2570 sdata
= bfd_zalloc (abfd
, amt
);
2573 sec
->used_by_bfd
= sdata
;
2576 return _bfd_elf_new_section_hook (abfd
, sec
);
2580 get_opd_info (asection
* sec
)
2583 && ppc64_elf_section_data (sec
) != NULL
2584 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2585 return ppc64_elf_section_data (sec
)->u
.opd_adjust
;
2589 /* Parameters for the qsort hook. */
2590 static asection
*synthetic_opd
;
2591 static bfd_boolean synthetic_relocatable
;
2593 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2596 compare_symbols (const void *ap
, const void *bp
)
2598 const asymbol
*a
= * (const asymbol
**) ap
;
2599 const asymbol
*b
= * (const asymbol
**) bp
;
2601 /* Section symbols first. */
2602 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2604 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2607 /* then .opd symbols. */
2608 if (a
->section
== synthetic_opd
&& b
->section
!= synthetic_opd
)
2610 if (a
->section
!= synthetic_opd
&& b
->section
== synthetic_opd
)
2613 /* then other code symbols. */
2614 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2615 == (SEC_CODE
| SEC_ALLOC
)
2616 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2617 != (SEC_CODE
| SEC_ALLOC
))
2620 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2621 != (SEC_CODE
| SEC_ALLOC
)
2622 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2623 == (SEC_CODE
| SEC_ALLOC
))
2626 if (synthetic_relocatable
)
2628 if (a
->section
->id
< b
->section
->id
)
2631 if (a
->section
->id
> b
->section
->id
)
2635 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2638 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2641 /* For syms with the same value, prefer strong dynamic global function
2642 syms over other syms. */
2643 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2646 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2649 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2652 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2655 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2658 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2661 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2664 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2670 /* Search SYMS for a symbol of the given VALUE. */
2673 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2681 mid
= (lo
+ hi
) >> 1;
2682 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2684 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2694 mid
= (lo
+ hi
) >> 1;
2695 if (syms
[mid
]->section
->id
< id
)
2697 else if (syms
[mid
]->section
->id
> id
)
2699 else if (syms
[mid
]->value
< value
)
2701 else if (syms
[mid
]->value
> value
)
2710 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2714 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2715 long static_count
, asymbol
**static_syms
,
2716 long dyn_count
, asymbol
**dyn_syms
,
2723 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2725 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2730 opd
= bfd_get_section_by_name (abfd
, ".opd");
2734 symcount
= static_count
;
2736 symcount
+= dyn_count
;
2740 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2744 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2746 /* Use both symbol tables. */
2747 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2748 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2750 else if (!relocatable
&& static_count
== 0)
2751 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2753 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2755 synthetic_opd
= opd
;
2756 synthetic_relocatable
= relocatable
;
2757 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2759 if (!relocatable
&& symcount
> 1)
2762 /* Trim duplicate syms, since we may have merged the normal and
2763 dynamic symbols. Actually, we only care about syms that have
2764 different values, so trim any with the same value. */
2765 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2766 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
2767 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
2768 syms
[j
++] = syms
[i
];
2773 if (syms
[i
]->section
== opd
)
2777 for (; i
< symcount
; ++i
)
2778 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2779 != (SEC_CODE
| SEC_ALLOC
))
2780 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2784 for (; i
< symcount
; ++i
)
2785 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2789 for (; i
< symcount
; ++i
)
2790 if (syms
[i
]->section
!= opd
)
2794 for (; i
< symcount
; ++i
)
2795 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2796 != (SEC_CODE
| SEC_ALLOC
))
2801 if (opdsymend
== secsymend
)
2806 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2811 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2812 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2816 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2823 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2827 while (r
< opd
->relocation
+ relcount
2828 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2831 if (r
== opd
->relocation
+ relcount
)
2834 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2837 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2840 sym
= *r
->sym_ptr_ptr
;
2841 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2842 sym
->section
->id
, sym
->value
+ r
->addend
))
2845 size
+= sizeof (asymbol
);
2846 size
+= strlen (syms
[i
]->name
) + 2;
2850 s
= *ret
= bfd_malloc (size
);
2857 names
= (char *) (s
+ count
);
2859 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2863 while (r
< opd
->relocation
+ relcount
2864 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2867 if (r
== opd
->relocation
+ relcount
)
2870 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2873 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2876 sym
= *r
->sym_ptr_ptr
;
2877 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2878 sym
->section
->id
, sym
->value
+ r
->addend
))
2883 s
->section
= sym
->section
;
2884 s
->value
= sym
->value
+ r
->addend
;
2887 len
= strlen (syms
[i
]->name
);
2888 memcpy (names
, syms
[i
]->name
, len
+ 1);
2899 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2903 free_contents_and_exit
:
2911 for (i
= secsymend
; i
< opdsymend
; ++i
)
2915 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2916 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2919 size
+= sizeof (asymbol
);
2920 size
+= strlen (syms
[i
]->name
) + 2;
2924 s
= *ret
= bfd_malloc (size
);
2926 goto free_contents_and_exit
;
2928 names
= (char *) (s
+ count
);
2930 for (i
= secsymend
; i
< opdsymend
; ++i
)
2934 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2935 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2939 asection
*sec
= abfd
->sections
;
2946 long mid
= (lo
+ hi
) >> 1;
2947 if (syms
[mid
]->section
->vma
< ent
)
2949 else if (syms
[mid
]->section
->vma
> ent
)
2953 sec
= syms
[mid
]->section
;
2958 if (lo
>= hi
&& lo
> codesecsym
)
2959 sec
= syms
[lo
- 1]->section
;
2961 for (; sec
!= NULL
; sec
= sec
->next
)
2965 if ((sec
->flags
& SEC_ALLOC
) == 0
2966 || (sec
->flags
& SEC_LOAD
) == 0)
2968 if ((sec
->flags
& SEC_CODE
) != 0)
2971 s
->value
= ent
- s
->section
->vma
;
2974 len
= strlen (syms
[i
]->name
);
2975 memcpy (names
, syms
[i
]->name
, len
+ 1);
2988 /* The following functions are specific to the ELF linker, while
2989 functions above are used generally. Those named ppc64_elf_* are
2990 called by the main ELF linker code. They appear in this file more
2991 or less in the order in which they are called. eg.
2992 ppc64_elf_check_relocs is called early in the link process,
2993 ppc64_elf_finish_dynamic_sections is one of the last functions
2996 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2997 functions have both a function code symbol and a function descriptor
2998 symbol. A call to foo in a relocatable object file looks like:
3005 The function definition in another object file might be:
3009 . .quad .TOC.@tocbase
3015 When the linker resolves the call during a static link, the branch
3016 unsurprisingly just goes to .foo and the .opd information is unused.
3017 If the function definition is in a shared library, things are a little
3018 different: The call goes via a plt call stub, the opd information gets
3019 copied to the plt, and the linker patches the nop.
3027 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3028 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3029 . std 2,40(1) # this is the general idea
3037 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3039 The "reloc ()" notation is supposed to indicate that the linker emits
3040 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3043 What are the difficulties here? Well, firstly, the relocations
3044 examined by the linker in check_relocs are against the function code
3045 sym .foo, while the dynamic relocation in the plt is emitted against
3046 the function descriptor symbol, foo. Somewhere along the line, we need
3047 to carefully copy dynamic link information from one symbol to the other.
3048 Secondly, the generic part of the elf linker will make .foo a dynamic
3049 symbol as is normal for most other backends. We need foo dynamic
3050 instead, at least for an application final link. However, when
3051 creating a shared library containing foo, we need to have both symbols
3052 dynamic so that references to .foo are satisfied during the early
3053 stages of linking. Otherwise the linker might decide to pull in a
3054 definition from some other object, eg. a static library.
3056 Update: As of August 2004, we support a new convention. Function
3057 calls may use the function descriptor symbol, ie. "bl foo". This
3058 behaves exactly as "bl .foo". */
3060 /* The linker needs to keep track of the number of relocs that it
3061 decides to copy as dynamic relocs in check_relocs for each symbol.
3062 This is so that it can later discard them if they are found to be
3063 unnecessary. We store the information in a field extending the
3064 regular ELF linker hash table. */
3066 struct ppc_dyn_relocs
3068 struct ppc_dyn_relocs
*next
;
3070 /* The input section of the reloc. */
3073 /* Total number of relocs copied for the input section. */
3074 bfd_size_type count
;
3076 /* Number of pc-relative relocs copied for the input section. */
3077 bfd_size_type pc_count
;
3080 /* Track GOT entries needed for a given symbol. We might need more
3081 than one got entry per symbol. */
3084 struct got_entry
*next
;
3086 /* The symbol addend that we'll be placing in the GOT. */
3089 /* Unlike other ELF targets, we use separate GOT entries for the same
3090 symbol referenced from different input files. This is to support
3091 automatic multiple TOC/GOT sections, where the TOC base can vary
3092 from one input file to another.
3094 Point to the BFD owning this GOT entry. */
3097 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
3098 TLS_TPREL or TLS_DTPREL for tls entries. */
3101 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
3104 bfd_signed_vma refcount
;
3109 /* The same for PLT. */
3112 struct plt_entry
*next
;
3118 bfd_signed_vma refcount
;
3123 /* Of those relocs that might be copied as dynamic relocs, this macro
3124 selects those that must be copied when linking a shared library,
3125 even when the symbol is local. */
3127 #define MUST_BE_DYN_RELOC(RTYPE) \
3128 ((RTYPE) != R_PPC64_REL32 \
3129 && (RTYPE) != R_PPC64_REL64 \
3130 && (RTYPE) != R_PPC64_REL30)
3132 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3133 copying dynamic variables from a shared lib into an app's dynbss
3134 section, and instead use a dynamic relocation to point into the
3135 shared lib. With code that gcc generates, it's vital that this be
3136 enabled; In the PowerPC64 ABI, the address of a function is actually
3137 the address of a function descriptor, which resides in the .opd
3138 section. gcc uses the descriptor directly rather than going via the
3139 GOT as some other ABI's do, which means that initialized function
3140 pointers must reference the descriptor. Thus, a function pointer
3141 initialized to the address of a function in a shared library will
3142 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3143 redefines the function descriptor symbol to point to the copy. This
3144 presents a problem as a plt entry for that function is also
3145 initialized from the function descriptor symbol and the copy reloc
3146 may not be initialized first. */
3147 #define ELIMINATE_COPY_RELOCS 1
3149 /* Section name for stubs is the associated section name plus this
3151 #define STUB_SUFFIX ".stub"
3154 ppc_stub_long_branch:
3155 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3156 destination, but a 24 bit branch in a stub section will reach.
3159 ppc_stub_plt_branch:
3160 Similar to the above, but a 24 bit branch in the stub section won't
3161 reach its destination.
3162 . addis %r12,%r2,xxx@toc@ha
3163 . ld %r11,xxx@toc@l(%r12)
3168 Used to call a function in a shared library. If it so happens that
3169 the plt entry referenced crosses a 64k boundary, then an extra
3170 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or
3171 xxx+16 as appropriate.
3172 . addis %r12,%r2,xxx@toc@ha
3174 . ld %r11,xxx+0@toc@l(%r12)
3175 . ld %r2,xxx+8@toc@l(%r12)
3177 . ld %r11,xxx+16@toc@l(%r12)
3180 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3181 code to adjust the value and save r2 to support multiple toc sections.
3182 A ppc_stub_long_branch with an r2 offset looks like:
3184 . addis %r2,%r2,off@ha
3185 . addi %r2,%r2,off@l
3188 A ppc_stub_plt_branch with an r2 offset looks like:
3190 . addis %r12,%r2,xxx@toc@ha
3191 . ld %r11,xxx@toc@l(%r12)
3192 . addis %r2,%r2,off@ha
3193 . addi %r2,%r2,off@l
3198 enum ppc_stub_type
{
3200 ppc_stub_long_branch
,
3201 ppc_stub_long_branch_r2off
,
3202 ppc_stub_plt_branch
,
3203 ppc_stub_plt_branch_r2off
,
3207 struct ppc_stub_hash_entry
{
3209 /* Base hash table entry structure. */
3210 struct bfd_hash_entry root
;
3212 enum ppc_stub_type stub_type
;
3214 /* The stub section. */
3217 /* Offset within stub_sec of the beginning of this stub. */
3218 bfd_vma stub_offset
;
3220 /* Given the symbol's value and its section we can determine its final
3221 value when building the stubs (so the stub knows where to jump. */
3222 bfd_vma target_value
;
3223 asection
*target_section
;
3225 /* The symbol table entry, if any, that this was derived from. */
3226 struct ppc_link_hash_entry
*h
;
3228 /* And the reloc addend that this was derived from. */
3231 /* Where this stub is being called from, or, in the case of combined
3232 stub sections, the first input section in the group. */
3236 struct ppc_branch_hash_entry
{
3238 /* Base hash table entry structure. */
3239 struct bfd_hash_entry root
;
3241 /* Offset within branch lookup table. */
3242 unsigned int offset
;
3244 /* Generation marker. */
3248 struct ppc_link_hash_entry
3250 struct elf_link_hash_entry elf
;
3253 /* A pointer to the most recently used stub hash entry against this
3255 struct ppc_stub_hash_entry
*stub_cache
;
3257 /* A pointer to the next symbol starting with a '.' */
3258 struct ppc_link_hash_entry
*next_dot_sym
;
3261 /* Track dynamic relocs copied for this symbol. */
3262 struct ppc_dyn_relocs
*dyn_relocs
;
3264 /* Link between function code and descriptor symbols. */
3265 struct ppc_link_hash_entry
*oh
;
3267 /* Flag function code and descriptor symbols. */
3268 unsigned int is_func
:1;
3269 unsigned int is_func_descriptor
:1;
3270 unsigned int fake
:1;
3272 /* Whether global opd/toc sym has been adjusted or not.
3273 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3274 should be set for all globals defined in any opd/toc section. */
3275 unsigned int adjust_done
:1;
3277 /* Set if we twiddled this symbol to weak at some stage. */
3278 unsigned int was_undefined
:1;
3280 /* Contexts in which symbol is used in the GOT (or TOC).
3281 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3282 corresponding relocs are encountered during check_relocs.
3283 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3284 indicate the corresponding GOT entry type is not needed.
3285 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3286 a TPREL one. We use a separate flag rather than setting TPREL
3287 just for convenience in distinguishing the two cases. */
3288 #define TLS_GD 1 /* GD reloc. */
3289 #define TLS_LD 2 /* LD reloc. */
3290 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3291 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3292 #define TLS_TLS 16 /* Any TLS reloc. */
3293 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3294 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3298 /* ppc64 ELF linker hash table. */
3300 struct ppc_link_hash_table
3302 struct elf_link_hash_table elf
;
3304 /* The stub hash table. */
3305 struct bfd_hash_table stub_hash_table
;
3307 /* Another hash table for plt_branch stubs. */
3308 struct bfd_hash_table branch_hash_table
;
3310 /* Linker stub bfd. */
3313 /* Linker call-backs. */
3314 asection
* (*add_stub_section
) (const char *, asection
*);
3315 void (*layout_sections_again
) (void);
3317 /* Array to keep track of which stub sections have been created, and
3318 information on stub grouping. */
3320 /* This is the section to which stubs in the group will be attached. */
3322 /* The stub section. */
3324 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3328 /* Temp used when calculating TOC pointers. */
3331 /* Highest input section id. */
3334 /* Highest output section index. */
3337 /* Used when adding symbols. */
3338 struct ppc_link_hash_entry
*dot_syms
;
3340 /* List of input sections for each output section. */
3341 asection
**input_list
;
3343 /* Short-cuts to get to dynamic linker sections. */
3354 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3355 struct ppc_link_hash_entry
*tls_get_addr
;
3356 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3359 unsigned long stub_count
[ppc_stub_plt_call
];
3361 /* Number of stubs against global syms. */
3362 unsigned long stub_globals
;
3364 /* Set if we should emit symbols for stubs. */
3365 unsigned int emit_stub_syms
:1;
3367 /* Support for multiple toc sections. */
3368 unsigned int no_multi_toc
:1;
3369 unsigned int multi_toc_needed
:1;
3372 unsigned int stub_error
:1;
3374 /* Temp used by ppc64_elf_check_directives. */
3375 unsigned int twiddled_syms
:1;
3377 /* Incremented every time we size stubs. */
3378 unsigned int stub_iteration
;
3380 /* Small local sym to section mapping cache. */
3381 struct sym_sec_cache sym_sec
;
3384 /* Rename some of the generic section flags to better document how they
3386 #define has_toc_reloc has_gp_reloc
3387 #define makes_toc_func_call need_finalize_relax
3388 #define call_check_in_progress reloc_done
3390 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3392 #define ppc_hash_table(p) \
3393 ((struct ppc_link_hash_table *) ((p)->hash))
3395 #define ppc_stub_hash_lookup(table, string, create, copy) \
3396 ((struct ppc_stub_hash_entry *) \
3397 bfd_hash_lookup ((table), (string), (create), (copy)))
3399 #define ppc_branch_hash_lookup(table, string, create, copy) \
3400 ((struct ppc_branch_hash_entry *) \
3401 bfd_hash_lookup ((table), (string), (create), (copy)))
3403 /* Create an entry in the stub hash table. */
3405 static struct bfd_hash_entry
*
3406 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3407 struct bfd_hash_table
*table
,
3410 /* Allocate the structure if it has not already been allocated by a
3414 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3419 /* Call the allocation method of the superclass. */
3420 entry
= bfd_hash_newfunc (entry
, table
, string
);
3423 struct ppc_stub_hash_entry
*eh
;
3425 /* Initialize the local fields. */
3426 eh
= (struct ppc_stub_hash_entry
*) entry
;
3427 eh
->stub_type
= ppc_stub_none
;
3428 eh
->stub_sec
= NULL
;
3429 eh
->stub_offset
= 0;
3430 eh
->target_value
= 0;
3431 eh
->target_section
= NULL
;
3439 /* Create an entry in the branch hash table. */
3441 static struct bfd_hash_entry
*
3442 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3443 struct bfd_hash_table
*table
,
3446 /* Allocate the structure if it has not already been allocated by a
3450 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3455 /* Call the allocation method of the superclass. */
3456 entry
= bfd_hash_newfunc (entry
, table
, string
);
3459 struct ppc_branch_hash_entry
*eh
;
3461 /* Initialize the local fields. */
3462 eh
= (struct ppc_branch_hash_entry
*) entry
;
3470 /* Create an entry in a ppc64 ELF linker hash table. */
3472 static struct bfd_hash_entry
*
3473 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3474 struct bfd_hash_table
*table
,
3477 /* Allocate the structure if it has not already been allocated by a
3481 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3486 /* Call the allocation method of the superclass. */
3487 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3490 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3492 memset (&eh
->u
.stub_cache
, 0,
3493 (sizeof (struct ppc_link_hash_entry
)
3494 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3496 /* When making function calls, old ABI code references function entry
3497 points (dot symbols), while new ABI code references the function
3498 descriptor symbol. We need to make any combination of reference and
3499 definition work together, without breaking archive linking.
3501 For a defined function "foo" and an undefined call to "bar":
3502 An old object defines "foo" and ".foo", references ".bar" (possibly
3504 A new object defines "foo" and references "bar".
3506 A new object thus has no problem with its undefined symbols being
3507 satisfied by definitions in an old object. On the other hand, the
3508 old object won't have ".bar" satisfied by a new object.
3510 Keep a list of newly added dot-symbols. */
3512 if (string
[0] == '.')
3514 struct ppc_link_hash_table
*htab
;
3516 htab
= (struct ppc_link_hash_table
*) table
;
3517 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3518 htab
->dot_syms
= eh
;
3525 /* Create a ppc64 ELF linker hash table. */
3527 static struct bfd_link_hash_table
*
3528 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3530 struct ppc_link_hash_table
*htab
;
3531 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3533 htab
= bfd_zmalloc (amt
);
3537 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3538 sizeof (struct ppc_link_hash_entry
)))
3544 /* Init the stub hash table too. */
3545 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3546 sizeof (struct ppc_stub_hash_entry
)))
3549 /* And the branch hash table. */
3550 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3551 sizeof (struct ppc_branch_hash_entry
)))
3554 /* Initializing two fields of the union is just cosmetic. We really
3555 only care about glist, but when compiled on a 32-bit host the
3556 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3557 debugger inspection of these fields look nicer. */
3558 htab
->elf
.init_got_refcount
.refcount
= 0;
3559 htab
->elf
.init_got_refcount
.glist
= NULL
;
3560 htab
->elf
.init_plt_refcount
.refcount
= 0;
3561 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3562 htab
->elf
.init_got_offset
.offset
= 0;
3563 htab
->elf
.init_got_offset
.glist
= NULL
;
3564 htab
->elf
.init_plt_offset
.offset
= 0;
3565 htab
->elf
.init_plt_offset
.glist
= NULL
;
3567 return &htab
->elf
.root
;
3570 /* Free the derived linker hash table. */
3573 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3575 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3577 bfd_hash_table_free (&ret
->stub_hash_table
);
3578 bfd_hash_table_free (&ret
->branch_hash_table
);
3579 _bfd_generic_link_hash_table_free (hash
);
3582 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3585 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3587 struct ppc_link_hash_table
*htab
;
3589 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3591 /* Always hook our dynamic sections into the first bfd, which is the
3592 linker created stub bfd. This ensures that the GOT header is at
3593 the start of the output TOC section. */
3594 htab
= ppc_hash_table (info
);
3595 htab
->stub_bfd
= abfd
;
3596 htab
->elf
.dynobj
= abfd
;
3599 /* Build a name for an entry in the stub hash table. */
3602 ppc_stub_name (const asection
*input_section
,
3603 const asection
*sym_sec
,
3604 const struct ppc_link_hash_entry
*h
,
3605 const Elf_Internal_Rela
*rel
)
3610 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3611 offsets from a sym as a branch target? In fact, we could
3612 probably assume the addend is always zero. */
3613 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3617 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3618 stub_name
= bfd_malloc (len
);
3619 if (stub_name
== NULL
)
3622 sprintf (stub_name
, "%08x.%s+%x",
3623 input_section
->id
& 0xffffffff,
3624 h
->elf
.root
.root
.string
,
3625 (int) rel
->r_addend
& 0xffffffff);
3629 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3630 stub_name
= bfd_malloc (len
);
3631 if (stub_name
== NULL
)
3634 sprintf (stub_name
, "%08x.%x:%x+%x",
3635 input_section
->id
& 0xffffffff,
3636 sym_sec
->id
& 0xffffffff,
3637 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3638 (int) rel
->r_addend
& 0xffffffff);
3640 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3641 stub_name
[len
- 2] = 0;
3645 /* Look up an entry in the stub hash. Stub entries are cached because
3646 creating the stub name takes a bit of time. */
3648 static struct ppc_stub_hash_entry
*
3649 ppc_get_stub_entry (const asection
*input_section
,
3650 const asection
*sym_sec
,
3651 struct ppc_link_hash_entry
*h
,
3652 const Elf_Internal_Rela
*rel
,
3653 struct ppc_link_hash_table
*htab
)
3655 struct ppc_stub_hash_entry
*stub_entry
;
3656 const asection
*id_sec
;
3658 /* If this input section is part of a group of sections sharing one
3659 stub section, then use the id of the first section in the group.
3660 Stub names need to include a section id, as there may well be
3661 more than one stub used to reach say, printf, and we need to
3662 distinguish between them. */
3663 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3665 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3666 && h
->u
.stub_cache
->h
== h
3667 && h
->u
.stub_cache
->id_sec
== id_sec
)
3669 stub_entry
= h
->u
.stub_cache
;
3675 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3676 if (stub_name
== NULL
)
3679 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3680 stub_name
, FALSE
, FALSE
);
3682 h
->u
.stub_cache
= stub_entry
;
3690 /* Add a new stub entry to the stub hash. Not all fields of the new
3691 stub entry are initialised. */
3693 static struct ppc_stub_hash_entry
*
3694 ppc_add_stub (const char *stub_name
,
3696 struct ppc_link_hash_table
*htab
)
3700 struct ppc_stub_hash_entry
*stub_entry
;
3702 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3703 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3704 if (stub_sec
== NULL
)
3706 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3707 if (stub_sec
== NULL
)
3713 namelen
= strlen (link_sec
->name
);
3714 len
= namelen
+ sizeof (STUB_SUFFIX
);
3715 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3719 memcpy (s_name
, link_sec
->name
, namelen
);
3720 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3721 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3722 if (stub_sec
== NULL
)
3724 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3726 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3729 /* Enter this entry into the linker stub hash table. */
3730 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3732 if (stub_entry
== NULL
)
3734 (*_bfd_error_handler
) (_("%B: cannot create stub entry %s"),
3735 section
->owner
, stub_name
);
3739 stub_entry
->stub_sec
= stub_sec
;
3740 stub_entry
->stub_offset
= 0;
3741 stub_entry
->id_sec
= link_sec
;
3745 /* Create sections for linker generated code. */
3748 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3750 struct ppc_link_hash_table
*htab
;
3753 htab
= ppc_hash_table (info
);
3755 /* Create .sfpr for code to save and restore fp regs. */
3756 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3757 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3758 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3760 if (htab
->sfpr
== NULL
3761 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3764 /* Create .glink for lazy dynamic linking support. */
3765 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3767 if (htab
->glink
== NULL
3768 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3771 /* Create branch lookup table for plt_branch stubs. */
3774 flags
= (SEC_ALLOC
| SEC_LOAD
3775 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3777 = bfd_make_section_anyway_with_flags (dynobj
, ".data.rel.ro.brlt",
3782 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3783 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3785 = bfd_make_section_anyway_with_flags (dynobj
, ".rodata.brlt", flags
);
3788 if (htab
->brlt
== NULL
3789 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3794 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3795 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3797 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.data.rel.ro.brlt",
3800 else if (info
->emitrelocations
)
3802 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3803 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3805 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.rodata.brlt",
3812 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3818 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3819 not already done. */
3822 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3824 asection
*got
, *relgot
;
3826 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3830 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3833 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
3838 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3839 | SEC_LINKER_CREATED
);
3841 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3843 || !bfd_set_section_alignment (abfd
, got
, 3))
3846 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3847 flags
| SEC_READONLY
);
3849 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
3852 ppc64_elf_tdata (abfd
)->got
= got
;
3853 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3857 /* Create the dynamic sections, and set up shortcuts. */
3860 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3862 struct ppc_link_hash_table
*htab
;
3864 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3867 htab
= ppc_hash_table (info
);
3869 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
3870 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
3871 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3872 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3874 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3876 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
3877 || (!info
->shared
&& !htab
->relbss
))
3883 /* Merge PLT info on FROM with that on TO. */
3886 move_plt_plist (struct ppc_link_hash_entry
*from
,
3887 struct ppc_link_hash_entry
*to
)
3889 if (from
->elf
.plt
.plist
!= NULL
)
3891 if (to
->elf
.plt
.plist
!= NULL
)
3893 struct plt_entry
**entp
;
3894 struct plt_entry
*ent
;
3896 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3898 struct plt_entry
*dent
;
3900 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3901 if (dent
->addend
== ent
->addend
)
3903 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3910 *entp
= to
->elf
.plt
.plist
;
3913 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3914 from
->elf
.plt
.plist
= NULL
;
3918 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3921 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3922 struct elf_link_hash_entry
*dir
,
3923 struct elf_link_hash_entry
*ind
)
3925 struct ppc_link_hash_entry
*edir
, *eind
;
3927 edir
= (struct ppc_link_hash_entry
*) dir
;
3928 eind
= (struct ppc_link_hash_entry
*) ind
;
3930 /* Copy over any dynamic relocs we may have on the indirect sym. */
3931 if (eind
->dyn_relocs
!= NULL
)
3933 if (edir
->dyn_relocs
!= NULL
)
3935 struct ppc_dyn_relocs
**pp
;
3936 struct ppc_dyn_relocs
*p
;
3938 /* Add reloc counts against the indirect sym to the direct sym
3939 list. Merge any entries against the same section. */
3940 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3942 struct ppc_dyn_relocs
*q
;
3944 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3945 if (q
->sec
== p
->sec
)
3947 q
->pc_count
+= p
->pc_count
;
3948 q
->count
+= p
->count
;
3955 *pp
= edir
->dyn_relocs
;
3958 edir
->dyn_relocs
= eind
->dyn_relocs
;
3959 eind
->dyn_relocs
= NULL
;
3962 edir
->is_func
|= eind
->is_func
;
3963 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3964 edir
->tls_mask
|= eind
->tls_mask
;
3966 /* If called to transfer flags for a weakdef during processing
3967 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
3968 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3969 if (!(ELIMINATE_COPY_RELOCS
3970 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3971 && edir
->elf
.dynamic_adjusted
))
3972 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3974 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3975 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3976 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3977 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3979 /* If we were called to copy over info for a weak sym, that's all. */
3980 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3983 /* Copy over got entries that we may have already seen to the
3984 symbol which just became indirect. */
3985 if (eind
->elf
.got
.glist
!= NULL
)
3987 if (edir
->elf
.got
.glist
!= NULL
)
3989 struct got_entry
**entp
;
3990 struct got_entry
*ent
;
3992 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3994 struct got_entry
*dent
;
3996 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3997 if (dent
->addend
== ent
->addend
3998 && dent
->owner
== ent
->owner
3999 && dent
->tls_type
== ent
->tls_type
)
4001 dent
->got
.refcount
+= ent
->got
.refcount
;
4008 *entp
= edir
->elf
.got
.glist
;
4011 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4012 eind
->elf
.got
.glist
= NULL
;
4015 /* And plt entries. */
4016 move_plt_plist (eind
, edir
);
4018 if (eind
->elf
.dynindx
!= -1)
4020 if (edir
->elf
.dynindx
!= -1)
4021 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4022 edir
->elf
.dynstr_index
);
4023 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4024 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4025 eind
->elf
.dynindx
= -1;
4026 eind
->elf
.dynstr_index
= 0;
4030 /* Find the function descriptor hash entry from the given function code
4031 hash entry FH. Link the entries via their OH fields. */
4033 static struct ppc_link_hash_entry
*
4034 get_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4036 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4040 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4042 fdh
= (struct ppc_link_hash_entry
*)
4043 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4046 fdh
->is_func_descriptor
= 1;
4056 /* Make a fake function descriptor sym for the code sym FH. */
4058 static struct ppc_link_hash_entry
*
4059 make_fdh (struct bfd_link_info
*info
,
4060 struct ppc_link_hash_entry
*fh
)
4064 struct bfd_link_hash_entry
*bh
;
4065 struct ppc_link_hash_entry
*fdh
;
4067 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4068 newsym
= bfd_make_empty_symbol (abfd
);
4069 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4070 newsym
->section
= bfd_und_section_ptr
;
4072 newsym
->flags
= BSF_WEAK
;
4075 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4076 newsym
->flags
, newsym
->section
,
4077 newsym
->value
, NULL
, FALSE
, FALSE
,
4081 fdh
= (struct ppc_link_hash_entry
*) bh
;
4082 fdh
->elf
.non_elf
= 0;
4084 fdh
->is_func_descriptor
= 1;
4091 /* Fix function descriptor symbols defined in .opd sections to be
4095 ppc64_elf_add_symbol_hook (bfd
*ibfd ATTRIBUTE_UNUSED
,
4096 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4097 Elf_Internal_Sym
*isym
,
4098 const char **name ATTRIBUTE_UNUSED
,
4099 flagword
*flags ATTRIBUTE_UNUSED
,
4101 bfd_vma
*value ATTRIBUTE_UNUSED
)
4104 && strcmp (bfd_get_section_name (ibfd
, *sec
), ".opd") == 0)
4105 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4110 /* This function makes an old ABI object reference to ".bar" cause the
4111 inclusion of a new ABI object archive that defines "bar".
4112 NAME is a symbol defined in an archive. Return a symbol in the hash
4113 table that might be satisfied by the archive symbols. */
4115 static struct elf_link_hash_entry
*
4116 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4117 struct bfd_link_info
*info
,
4120 struct elf_link_hash_entry
*h
;
4124 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4126 /* Don't return this sym if it is a fake function descriptor
4127 created by add_symbol_adjust. */
4128 && !(h
->root
.type
== bfd_link_hash_undefweak
4129 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4135 len
= strlen (name
);
4136 dot_name
= bfd_alloc (abfd
, len
+ 2);
4137 if (dot_name
== NULL
)
4138 return (struct elf_link_hash_entry
*) 0 - 1;
4140 memcpy (dot_name
+ 1, name
, len
+ 1);
4141 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4142 bfd_release (abfd
, dot_name
);
4146 /* This function satisfies all old ABI object references to ".bar" if a
4147 new ABI object defines "bar". Well, at least, undefined dot symbols
4148 are made weak. This stops later archive searches from including an
4149 object if we already have a function descriptor definition. It also
4150 prevents the linker complaining about undefined symbols.
4151 We also check and correct mismatched symbol visibility here. The
4152 most restrictive visibility of the function descriptor and the
4153 function entry symbol is used. */
4156 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4158 struct ppc_link_hash_table
*htab
;
4159 struct ppc_link_hash_entry
*fdh
;
4161 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4164 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4165 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4167 if (eh
->elf
.root
.root
.string
[0] != '.')
4170 htab
= ppc_hash_table (info
);
4171 fdh
= get_fdh (eh
, htab
);
4173 && !info
->relocatable
4174 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4175 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4176 && eh
->elf
.ref_regular
)
4178 /* Make an undefweak function descriptor sym, which is enough to
4179 pull in an --as-needed shared lib, but won't cause link
4180 errors. Archives are handled elsewhere. */
4181 fdh
= make_fdh (info
, eh
);
4185 fdh
->elf
.ref_regular
= 1;
4187 else if (fdh
!= NULL
)
4189 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4190 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4191 if (entry_vis
< descr_vis
)
4192 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4193 else if (entry_vis
> descr_vis
)
4194 eh
->elf
.other
+= descr_vis
- entry_vis
;
4196 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4197 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4198 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4200 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4201 eh
->was_undefined
= 1;
4202 htab
->twiddled_syms
= 1;
4209 /* Process list of dot-symbols we made in link_hash_newfunc. */
4212 ppc64_elf_check_directives (bfd
*ibfd
, struct bfd_link_info
*info
)
4214 struct ppc_link_hash_table
*htab
;
4215 struct ppc_link_hash_entry
**p
, *eh
;
4217 htab
= ppc_hash_table (info
);
4218 if (!is_ppc64_elf_target (htab
->elf
.root
.creator
))
4221 if (is_ppc64_elf_target (ibfd
->xvec
))
4223 p
= &htab
->dot_syms
;
4224 while ((eh
= *p
) != NULL
)
4227 if (!add_symbol_adjust (eh
, info
))
4229 p
= &eh
->u
.next_dot_sym
;
4233 /* Clear the list for non-ppc64 input files. */
4234 p
= &htab
->dot_syms
;
4235 while ((eh
= *p
) != NULL
)
4238 p
= &eh
->u
.next_dot_sym
;
4241 /* We need to fix the undefs list for any syms we have twiddled to
4243 if (htab
->twiddled_syms
)
4245 bfd_link_repair_undef_list (&htab
->elf
.root
);
4246 htab
->twiddled_syms
= 0;
4251 /* Undo hash table changes when an --as-needed input file is determined
4252 not to be needed. */
4255 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4256 struct bfd_link_info
*info
)
4258 ppc_hash_table (info
)->dot_syms
= NULL
;
4263 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4264 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4266 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4267 char *local_got_tls_masks
;
4269 if (local_got_ents
== NULL
)
4271 bfd_size_type size
= symtab_hdr
->sh_info
;
4273 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
4274 local_got_ents
= bfd_zalloc (abfd
, size
);
4275 if (local_got_ents
== NULL
)
4277 elf_local_got_ents (abfd
) = local_got_ents
;
4280 if ((tls_type
& TLS_EXPLICIT
) == 0)
4282 struct got_entry
*ent
;
4284 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4285 if (ent
->addend
== r_addend
4286 && ent
->owner
== abfd
4287 && ent
->tls_type
== tls_type
)
4291 bfd_size_type amt
= sizeof (*ent
);
4292 ent
= bfd_alloc (abfd
, amt
);
4295 ent
->next
= local_got_ents
[r_symndx
];
4296 ent
->addend
= r_addend
;
4298 ent
->tls_type
= tls_type
;
4299 ent
->got
.refcount
= 0;
4300 local_got_ents
[r_symndx
] = ent
;
4302 ent
->got
.refcount
+= 1;
4305 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
4306 local_got_tls_masks
[r_symndx
] |= tls_type
;
4311 update_plt_info (bfd
*abfd
, struct ppc_link_hash_entry
*eh
, bfd_vma addend
)
4313 struct plt_entry
*ent
;
4315 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4316 if (ent
->addend
== addend
)
4320 bfd_size_type amt
= sizeof (*ent
);
4321 ent
= bfd_alloc (abfd
, amt
);
4324 ent
->next
= eh
->elf
.plt
.plist
;
4325 ent
->addend
= addend
;
4326 ent
->plt
.refcount
= 0;
4327 eh
->elf
.plt
.plist
= ent
;
4329 ent
->plt
.refcount
+= 1;
4330 eh
->elf
.needs_plt
= 1;
4331 if (eh
->elf
.root
.root
.string
[0] == '.'
4332 && eh
->elf
.root
.root
.string
[1] != '\0')
4337 /* Look through the relocs for a section during the first phase, and
4338 calculate needed space in the global offset table, procedure
4339 linkage table, and dynamic reloc sections. */
4342 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4343 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4345 struct ppc_link_hash_table
*htab
;
4346 Elf_Internal_Shdr
*symtab_hdr
;
4347 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
4348 const Elf_Internal_Rela
*rel
;
4349 const Elf_Internal_Rela
*rel_end
;
4351 asection
**opd_sym_map
;
4353 if (info
->relocatable
)
4356 /* Don't do anything special with non-loaded, non-alloced sections.
4357 In particular, any relocs in such sections should not affect GOT
4358 and PLT reference counting (ie. we don't allow them to create GOT
4359 or PLT entries), there's no possibility or desire to optimize TLS
4360 relocs, and there's not much point in propagating relocs to shared
4361 libs that the dynamic linker won't relocate. */
4362 if ((sec
->flags
& SEC_ALLOC
) == 0)
4365 htab
= ppc_hash_table (info
);
4366 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4368 sym_hashes
= elf_sym_hashes (abfd
);
4369 sym_hashes_end
= (sym_hashes
4370 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
4371 - symtab_hdr
->sh_info
);
4375 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
4377 /* Garbage collection needs some extra help with .opd sections.
4378 We don't want to necessarily keep everything referenced by
4379 relocs in .opd, as that would keep all functions. Instead,
4380 if we reference an .opd symbol (a function descriptor), we
4381 want to keep the function code symbol's section. This is
4382 easy for global symbols, but for local syms we need to keep
4383 information about the associated function section. Later, if
4384 edit_opd deletes entries, we'll use this array to adjust
4385 local syms in .opd. */
4387 asection
*func_section
;
4392 amt
= sec
->size
* sizeof (union opd_info
) / 8;
4393 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4394 if (opd_sym_map
== NULL
)
4396 ppc64_elf_section_data (sec
)->u
.opd_func_sec
= opd_sym_map
;
4397 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4398 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4401 if (htab
->sfpr
== NULL
4402 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4405 rel_end
= relocs
+ sec
->reloc_count
;
4406 for (rel
= relocs
; rel
< rel_end
; rel
++)
4408 unsigned long r_symndx
;
4409 struct elf_link_hash_entry
*h
;
4410 enum elf_ppc64_reloc_type r_type
;
4412 struct _ppc64_elf_section_data
*ppc64_sec
;
4414 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4415 if (r_symndx
< symtab_hdr
->sh_info
)
4419 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4420 while (h
->root
.type
== bfd_link_hash_indirect
4421 || h
->root
.type
== bfd_link_hash_warning
)
4422 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4425 r_type
= ELF64_R_TYPE (rel
->r_info
);
4428 case R_PPC64_GOT_TLSLD16
:
4429 case R_PPC64_GOT_TLSLD16_LO
:
4430 case R_PPC64_GOT_TLSLD16_HI
:
4431 case R_PPC64_GOT_TLSLD16_HA
:
4432 ppc64_tlsld_got (abfd
)->refcount
+= 1;
4433 tls_type
= TLS_TLS
| TLS_LD
;
4436 case R_PPC64_GOT_TLSGD16
:
4437 case R_PPC64_GOT_TLSGD16_LO
:
4438 case R_PPC64_GOT_TLSGD16_HI
:
4439 case R_PPC64_GOT_TLSGD16_HA
:
4440 tls_type
= TLS_TLS
| TLS_GD
;
4443 case R_PPC64_GOT_TPREL16_DS
:
4444 case R_PPC64_GOT_TPREL16_LO_DS
:
4445 case R_PPC64_GOT_TPREL16_HI
:
4446 case R_PPC64_GOT_TPREL16_HA
:
4448 info
->flags
|= DF_STATIC_TLS
;
4449 tls_type
= TLS_TLS
| TLS_TPREL
;
4452 case R_PPC64_GOT_DTPREL16_DS
:
4453 case R_PPC64_GOT_DTPREL16_LO_DS
:
4454 case R_PPC64_GOT_DTPREL16_HI
:
4455 case R_PPC64_GOT_DTPREL16_HA
:
4456 tls_type
= TLS_TLS
| TLS_DTPREL
;
4458 sec
->has_tls_reloc
= 1;
4462 case R_PPC64_GOT16_DS
:
4463 case R_PPC64_GOT16_HA
:
4464 case R_PPC64_GOT16_HI
:
4465 case R_PPC64_GOT16_LO
:
4466 case R_PPC64_GOT16_LO_DS
:
4467 /* This symbol requires a global offset table entry. */
4468 sec
->has_toc_reloc
= 1;
4469 if (ppc64_elf_tdata (abfd
)->got
== NULL
4470 && !create_got_section (abfd
, info
))
4475 struct ppc_link_hash_entry
*eh
;
4476 struct got_entry
*ent
;
4478 eh
= (struct ppc_link_hash_entry
*) h
;
4479 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4480 if (ent
->addend
== rel
->r_addend
4481 && ent
->owner
== abfd
4482 && ent
->tls_type
== tls_type
)
4486 bfd_size_type amt
= sizeof (*ent
);
4487 ent
= bfd_alloc (abfd
, amt
);
4490 ent
->next
= eh
->elf
.got
.glist
;
4491 ent
->addend
= rel
->r_addend
;
4493 ent
->tls_type
= tls_type
;
4494 ent
->got
.refcount
= 0;
4495 eh
->elf
.got
.glist
= ent
;
4497 ent
->got
.refcount
+= 1;
4498 eh
->tls_mask
|= tls_type
;
4501 /* This is a global offset table entry for a local symbol. */
4502 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4503 rel
->r_addend
, tls_type
))
4507 case R_PPC64_PLT16_HA
:
4508 case R_PPC64_PLT16_HI
:
4509 case R_PPC64_PLT16_LO
:
4512 /* This symbol requires a procedure linkage table entry. We
4513 actually build the entry in adjust_dynamic_symbol,
4514 because this might be a case of linking PIC code without
4515 linking in any dynamic objects, in which case we don't
4516 need to generate a procedure linkage table after all. */
4519 /* It does not make sense to have a procedure linkage
4520 table entry for a local symbol. */
4521 bfd_set_error (bfd_error_bad_value
);
4525 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4530 /* The following relocations don't need to propagate the
4531 relocation if linking a shared object since they are
4532 section relative. */
4533 case R_PPC64_SECTOFF
:
4534 case R_PPC64_SECTOFF_LO
:
4535 case R_PPC64_SECTOFF_HI
:
4536 case R_PPC64_SECTOFF_HA
:
4537 case R_PPC64_SECTOFF_DS
:
4538 case R_PPC64_SECTOFF_LO_DS
:
4539 case R_PPC64_DTPREL16
:
4540 case R_PPC64_DTPREL16_LO
:
4541 case R_PPC64_DTPREL16_HI
:
4542 case R_PPC64_DTPREL16_HA
:
4543 case R_PPC64_DTPREL16_DS
:
4544 case R_PPC64_DTPREL16_LO_DS
:
4545 case R_PPC64_DTPREL16_HIGHER
:
4546 case R_PPC64_DTPREL16_HIGHERA
:
4547 case R_PPC64_DTPREL16_HIGHEST
:
4548 case R_PPC64_DTPREL16_HIGHESTA
:
4553 case R_PPC64_TOC16_LO
:
4554 case R_PPC64_TOC16_HI
:
4555 case R_PPC64_TOC16_HA
:
4556 case R_PPC64_TOC16_DS
:
4557 case R_PPC64_TOC16_LO_DS
:
4558 sec
->has_toc_reloc
= 1;
4561 /* This relocation describes the C++ object vtable hierarchy.
4562 Reconstruct it for later use during GC. */
4563 case R_PPC64_GNU_VTINHERIT
:
4564 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4568 /* This relocation describes which C++ vtable entries are actually
4569 used. Record for later use during GC. */
4570 case R_PPC64_GNU_VTENTRY
:
4571 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4576 case R_PPC64_REL14_BRTAKEN
:
4577 case R_PPC64_REL14_BRNTAKEN
:
4579 asection
*dest
= NULL
;
4581 /* Heuristic: If jumping outside our section, chances are
4582 we are going to need a stub. */
4585 /* If the sym is weak it may be overridden later, so
4586 don't assume we know where a weak sym lives. */
4587 if (h
->root
.type
== bfd_link_hash_defined
)
4588 dest
= h
->root
.u
.def
.section
;
4591 dest
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4594 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4601 /* We may need a .plt entry if the function this reloc
4602 refers to is in a shared lib. */
4603 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4606 if (h
== &htab
->tls_get_addr
->elf
4607 || h
== &htab
->tls_get_addr_fd
->elf
)
4608 sec
->has_tls_reloc
= 1;
4609 else if (htab
->tls_get_addr
== NULL
4610 && CONST_STRNEQ (h
->root
.root
.string
, ".__tls_get_addr")
4611 && (h
->root
.root
.string
[15] == 0
4612 || h
->root
.root
.string
[15] == '@'))
4614 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) h
;
4615 sec
->has_tls_reloc
= 1;
4617 else if (htab
->tls_get_addr_fd
== NULL
4618 && CONST_STRNEQ (h
->root
.root
.string
, "__tls_get_addr")
4619 && (h
->root
.root
.string
[14] == 0
4620 || h
->root
.root
.string
[14] == '@'))
4622 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) h
;
4623 sec
->has_tls_reloc
= 1;
4628 case R_PPC64_TPREL64
:
4629 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4631 info
->flags
|= DF_STATIC_TLS
;
4634 case R_PPC64_DTPMOD64
:
4635 if (rel
+ 1 < rel_end
4636 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4637 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4638 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4640 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4643 case R_PPC64_DTPREL64
:
4644 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4646 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4647 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4648 /* This is the second reloc of a dtpmod, dtprel pair.
4649 Don't mark with TLS_DTPREL. */
4653 sec
->has_tls_reloc
= 1;
4656 struct ppc_link_hash_entry
*eh
;
4657 eh
= (struct ppc_link_hash_entry
*) h
;
4658 eh
->tls_mask
|= tls_type
;
4661 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4662 rel
->r_addend
, tls_type
))
4665 ppc64_sec
= ppc64_elf_section_data (sec
);
4666 if (ppc64_sec
->sec_type
!= sec_toc
)
4668 /* One extra to simplify get_tls_mask. */
4669 bfd_size_type amt
= sec
->size
* sizeof (unsigned) / 8 + 1;
4670 ppc64_sec
->u
.t_symndx
= bfd_zalloc (abfd
, amt
);
4671 if (ppc64_sec
->u
.t_symndx
== NULL
)
4673 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4674 ppc64_sec
->sec_type
= sec_toc
;
4676 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4677 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
4679 /* Mark the second slot of a GD or LD entry.
4680 -1 to indicate GD and -2 to indicate LD. */
4681 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4682 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
4683 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4684 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
4687 case R_PPC64_TPREL16
:
4688 case R_PPC64_TPREL16_LO
:
4689 case R_PPC64_TPREL16_HI
:
4690 case R_PPC64_TPREL16_HA
:
4691 case R_PPC64_TPREL16_DS
:
4692 case R_PPC64_TPREL16_LO_DS
:
4693 case R_PPC64_TPREL16_HIGHER
:
4694 case R_PPC64_TPREL16_HIGHERA
:
4695 case R_PPC64_TPREL16_HIGHEST
:
4696 case R_PPC64_TPREL16_HIGHESTA
:
4699 info
->flags
|= DF_STATIC_TLS
;
4704 case R_PPC64_ADDR64
:
4705 if (opd_sym_map
!= NULL
4706 && rel
+ 1 < rel_end
4707 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4711 if (h
->root
.root
.string
[0] == '.'
4712 && h
->root
.root
.string
[1] != 0
4713 && get_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
4716 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4722 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
4727 opd_sym_map
[rel
->r_offset
/ 8] = s
;
4735 case R_PPC64_ADDR14
:
4736 case R_PPC64_ADDR14_BRNTAKEN
:
4737 case R_PPC64_ADDR14_BRTAKEN
:
4738 case R_PPC64_ADDR16
:
4739 case R_PPC64_ADDR16_DS
:
4740 case R_PPC64_ADDR16_HA
:
4741 case R_PPC64_ADDR16_HI
:
4742 case R_PPC64_ADDR16_HIGHER
:
4743 case R_PPC64_ADDR16_HIGHERA
:
4744 case R_PPC64_ADDR16_HIGHEST
:
4745 case R_PPC64_ADDR16_HIGHESTA
:
4746 case R_PPC64_ADDR16_LO
:
4747 case R_PPC64_ADDR16_LO_DS
:
4748 case R_PPC64_ADDR24
:
4749 case R_PPC64_ADDR32
:
4750 case R_PPC64_UADDR16
:
4751 case R_PPC64_UADDR32
:
4752 case R_PPC64_UADDR64
:
4754 if (h
!= NULL
&& !info
->shared
)
4755 /* We may need a copy reloc. */
4758 /* Don't propagate .opd relocs. */
4759 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
4762 /* If we are creating a shared library, and this is a reloc
4763 against a global symbol, or a non PC relative reloc
4764 against a local symbol, then we need to copy the reloc
4765 into the shared library. However, if we are linking with
4766 -Bsymbolic, we do not need to copy a reloc against a
4767 global symbol which is defined in an object we are
4768 including in the link (i.e., DEF_REGULAR is set). At
4769 this point we have not seen all the input files, so it is
4770 possible that DEF_REGULAR is not set now but will be set
4771 later (it is never cleared). In case of a weak definition,
4772 DEF_REGULAR may be cleared later by a strong definition in
4773 a shared library. We account for that possibility below by
4774 storing information in the dyn_relocs field of the hash
4775 table entry. A similar situation occurs when creating
4776 shared libraries and symbol visibility changes render the
4779 If on the other hand, we are creating an executable, we
4780 may need to keep relocations for symbols satisfied by a
4781 dynamic library if we manage to avoid copy relocs for the
4785 && (MUST_BE_DYN_RELOC (r_type
)
4787 && (! info
->symbolic
4788 || h
->root
.type
== bfd_link_hash_defweak
4789 || !h
->def_regular
))))
4790 || (ELIMINATE_COPY_RELOCS
4793 && (h
->root
.type
== bfd_link_hash_defweak
4794 || !h
->def_regular
)))
4796 struct ppc_dyn_relocs
*p
;
4797 struct ppc_dyn_relocs
**head
;
4799 /* We must copy these reloc types into the output file.
4800 Create a reloc section in dynobj and make room for
4807 name
= (bfd_elf_string_from_elf_section
4809 elf_elfheader (abfd
)->e_shstrndx
,
4810 elf_section_data (sec
)->rel_hdr
.sh_name
));
4814 if (! CONST_STRNEQ (name
, ".rela")
4815 || strcmp (bfd_get_section_name (abfd
, sec
),
4818 (*_bfd_error_handler
)
4819 (_("%B: bad relocation section name `%s\'"),
4821 bfd_set_error (bfd_error_bad_value
);
4824 dynobj
= htab
->elf
.dynobj
;
4825 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4830 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4831 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
4832 | SEC_ALLOC
| SEC_LOAD
);
4833 sreloc
= bfd_make_section_with_flags (dynobj
,
4837 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
4840 elf_section_data (sec
)->sreloc
= sreloc
;
4843 /* If this is a global symbol, we count the number of
4844 relocations we need for this symbol. */
4847 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4851 /* Track dynamic relocs needed for local syms too.
4852 We really need local syms available to do this
4858 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4863 vpp
= &elf_section_data (s
)->local_dynrel
;
4864 head
= (struct ppc_dyn_relocs
**) vpp
;
4868 if (p
== NULL
|| p
->sec
!= sec
)
4870 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4881 if (!MUST_BE_DYN_RELOC (r_type
))
4894 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4895 of the code entry point, and its section. */
4898 opd_entry_value (asection
*opd_sec
,
4900 asection
**code_sec
,
4903 bfd
*opd_bfd
= opd_sec
->owner
;
4904 Elf_Internal_Rela
*relocs
;
4905 Elf_Internal_Rela
*lo
, *hi
, *look
;
4908 /* No relocs implies we are linking a --just-symbols object. */
4909 if (opd_sec
->reloc_count
== 0)
4913 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, &val
, offset
, 8))
4914 return (bfd_vma
) -1;
4916 if (code_sec
!= NULL
)
4918 asection
*sec
, *likely
= NULL
;
4919 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4921 && (sec
->flags
& SEC_LOAD
) != 0
4922 && (sec
->flags
& SEC_ALLOC
) != 0)
4927 if (code_off
!= NULL
)
4928 *code_off
= val
- likely
->vma
;
4934 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
4936 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
4938 /* Go find the opd reloc at the sym address. */
4940 BFD_ASSERT (lo
!= NULL
);
4941 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
4945 look
= lo
+ (hi
- lo
) / 2;
4946 if (look
->r_offset
< offset
)
4948 else if (look
->r_offset
> offset
)
4952 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (opd_bfd
)->symtab_hdr
;
4953 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
4954 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
4956 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
4959 if (symndx
< symtab_hdr
->sh_info
)
4961 Elf_Internal_Sym
*sym
;
4963 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4966 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
4967 symtab_hdr
->sh_info
,
4968 0, NULL
, NULL
, NULL
);
4971 symtab_hdr
->contents
= (bfd_byte
*) sym
;
4975 val
= sym
->st_value
;
4977 if ((sym
->st_shndx
!= SHN_UNDEF
4978 && sym
->st_shndx
< SHN_LORESERVE
)
4979 || sym
->st_shndx
> SHN_HIRESERVE
)
4980 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
4981 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
4985 struct elf_link_hash_entry
**sym_hashes
;
4986 struct elf_link_hash_entry
*rh
;
4988 sym_hashes
= elf_sym_hashes (opd_bfd
);
4989 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
4990 while (rh
->root
.type
== bfd_link_hash_indirect
4991 || rh
->root
.type
== bfd_link_hash_warning
)
4992 rh
= ((struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
);
4993 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
4994 || rh
->root
.type
== bfd_link_hash_defweak
);
4995 val
= rh
->root
.u
.def
.value
;
4996 sec
= rh
->root
.u
.def
.section
;
4998 val
+= look
->r_addend
;
4999 if (code_off
!= NULL
)
5001 if (code_sec
!= NULL
)
5003 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5004 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5013 /* Mark sections containing dynamically referenced symbols. When
5014 building shared libraries, we must assume that any visible symbol is
5018 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5020 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5021 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5023 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5024 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5026 /* Dynamic linking info is on the func descriptor sym. */
5028 && eh
->oh
->is_func_descriptor
5029 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5030 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5033 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5034 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5035 && (eh
->elf
.ref_dynamic
5036 || (!info
->executable
5037 && eh
->elf
.def_regular
5038 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5039 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5043 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5045 /* Function descriptor syms cause the associated
5046 function code sym section to be marked. */
5047 if (eh
->is_func_descriptor
5048 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5049 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5050 eh
->oh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5051 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5052 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5053 eh
->elf
.root
.u
.def
.value
,
5054 &code_sec
, NULL
) != (bfd_vma
) -1)
5055 code_sec
->flags
|= SEC_KEEP
;
5061 /* Return the section that should be marked against GC for a given
5065 ppc64_elf_gc_mark_hook (asection
*sec
,
5066 struct bfd_link_info
*info
,
5067 Elf_Internal_Rela
*rel
,
5068 struct elf_link_hash_entry
*h
,
5069 Elf_Internal_Sym
*sym
)
5073 /* First mark all our entry sym sections. */
5074 if (info
->gc_sym_list
!= NULL
)
5076 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5077 struct bfd_sym_chain
*sym
= info
->gc_sym_list
;
5079 info
->gc_sym_list
= NULL
;
5080 for (; sym
!= NULL
; sym
= sym
->next
)
5082 struct ppc_link_hash_entry
*eh
;
5084 eh
= (struct ppc_link_hash_entry
*)
5085 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
5088 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5089 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5092 if (eh
->is_func_descriptor
5093 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5094 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5095 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5096 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5097 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5098 eh
->elf
.root
.u
.def
.value
,
5099 &rsec
, NULL
) != (bfd_vma
) -1)
5105 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5107 rsec
= eh
->elf
.root
.u
.def
.section
;
5109 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5113 /* Syms return NULL if we're marking .opd, so we avoid marking all
5114 function sections, as all functions are referenced in .opd. */
5116 if (get_opd_info (sec
) != NULL
)
5121 enum elf_ppc64_reloc_type r_type
;
5122 struct ppc_link_hash_entry
*eh
;
5124 r_type
= ELF64_R_TYPE (rel
->r_info
);
5127 case R_PPC64_GNU_VTINHERIT
:
5128 case R_PPC64_GNU_VTENTRY
:
5132 switch (h
->root
.type
)
5134 case bfd_link_hash_defined
:
5135 case bfd_link_hash_defweak
:
5136 eh
= (struct ppc_link_hash_entry
*) h
;
5138 && eh
->oh
->is_func_descriptor
5139 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5140 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5143 /* Function descriptor syms cause the associated
5144 function code sym section to be marked. */
5145 if (eh
->is_func_descriptor
5146 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5147 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5149 /* They also mark their opd section. */
5150 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5151 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5152 ppc64_elf_gc_mark_hook
);
5154 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5156 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5157 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5158 eh
->elf
.root
.u
.def
.value
,
5159 &rsec
, NULL
) != (bfd_vma
) -1)
5161 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5162 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5163 ppc64_elf_gc_mark_hook
);
5166 rsec
= h
->root
.u
.def
.section
;
5169 case bfd_link_hash_common
:
5170 rsec
= h
->root
.u
.c
.p
->section
;
5180 asection
**opd_sym_section
;
5182 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5183 opd_sym_section
= get_opd_info (rsec
);
5184 if (opd_sym_section
!= NULL
)
5187 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5189 rsec
= opd_sym_section
[(sym
->st_value
+ rel
->r_addend
) / 8];
5196 /* Update the .got, .plt. and dynamic reloc reference counts for the
5197 section being removed. */
5200 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5201 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5203 struct ppc_link_hash_table
*htab
;
5204 Elf_Internal_Shdr
*symtab_hdr
;
5205 struct elf_link_hash_entry
**sym_hashes
;
5206 struct got_entry
**local_got_ents
;
5207 const Elf_Internal_Rela
*rel
, *relend
;
5209 if ((sec
->flags
& SEC_ALLOC
) == 0)
5212 elf_section_data (sec
)->local_dynrel
= NULL
;
5214 htab
= ppc_hash_table (info
);
5215 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5216 sym_hashes
= elf_sym_hashes (abfd
);
5217 local_got_ents
= elf_local_got_ents (abfd
);
5219 relend
= relocs
+ sec
->reloc_count
;
5220 for (rel
= relocs
; rel
< relend
; rel
++)
5222 unsigned long r_symndx
;
5223 enum elf_ppc64_reloc_type r_type
;
5224 struct elf_link_hash_entry
*h
= NULL
;
5227 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5228 r_type
= ELF64_R_TYPE (rel
->r_info
);
5229 if (r_symndx
>= symtab_hdr
->sh_info
)
5231 struct ppc_link_hash_entry
*eh
;
5232 struct ppc_dyn_relocs
**pp
;
5233 struct ppc_dyn_relocs
*p
;
5235 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5236 while (h
->root
.type
== bfd_link_hash_indirect
5237 || h
->root
.type
== bfd_link_hash_warning
)
5238 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5239 eh
= (struct ppc_link_hash_entry
*) h
;
5241 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5244 /* Everything must go for SEC. */
5252 case R_PPC64_GOT_TLSLD16
:
5253 case R_PPC64_GOT_TLSLD16_LO
:
5254 case R_PPC64_GOT_TLSLD16_HI
:
5255 case R_PPC64_GOT_TLSLD16_HA
:
5256 ppc64_tlsld_got (abfd
)->refcount
-= 1;
5257 tls_type
= TLS_TLS
| TLS_LD
;
5260 case R_PPC64_GOT_TLSGD16
:
5261 case R_PPC64_GOT_TLSGD16_LO
:
5262 case R_PPC64_GOT_TLSGD16_HI
:
5263 case R_PPC64_GOT_TLSGD16_HA
:
5264 tls_type
= TLS_TLS
| TLS_GD
;
5267 case R_PPC64_GOT_TPREL16_DS
:
5268 case R_PPC64_GOT_TPREL16_LO_DS
:
5269 case R_PPC64_GOT_TPREL16_HI
:
5270 case R_PPC64_GOT_TPREL16_HA
:
5271 tls_type
= TLS_TLS
| TLS_TPREL
;
5274 case R_PPC64_GOT_DTPREL16_DS
:
5275 case R_PPC64_GOT_DTPREL16_LO_DS
:
5276 case R_PPC64_GOT_DTPREL16_HI
:
5277 case R_PPC64_GOT_DTPREL16_HA
:
5278 tls_type
= TLS_TLS
| TLS_DTPREL
;
5282 case R_PPC64_GOT16_DS
:
5283 case R_PPC64_GOT16_HA
:
5284 case R_PPC64_GOT16_HI
:
5285 case R_PPC64_GOT16_LO
:
5286 case R_PPC64_GOT16_LO_DS
:
5289 struct got_entry
*ent
;
5294 ent
= local_got_ents
[r_symndx
];
5296 for (; ent
!= NULL
; ent
= ent
->next
)
5297 if (ent
->addend
== rel
->r_addend
5298 && ent
->owner
== abfd
5299 && ent
->tls_type
== tls_type
)
5303 if (ent
->got
.refcount
> 0)
5304 ent
->got
.refcount
-= 1;
5308 case R_PPC64_PLT16_HA
:
5309 case R_PPC64_PLT16_HI
:
5310 case R_PPC64_PLT16_LO
:
5314 case R_PPC64_REL14_BRNTAKEN
:
5315 case R_PPC64_REL14_BRTAKEN
:
5319 struct plt_entry
*ent
;
5321 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5322 if (ent
->addend
== rel
->r_addend
)
5326 if (ent
->plt
.refcount
> 0)
5327 ent
->plt
.refcount
-= 1;
5338 /* The maximum size of .sfpr. */
5339 #define SFPR_MAX (218*4)
5341 struct sfpr_def_parms
5343 const char name
[12];
5344 unsigned char lo
, hi
;
5345 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5346 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5349 /* Auto-generate _save*, _rest* functions in .sfpr. */
5352 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5354 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5356 size_t len
= strlen (parm
->name
);
5357 bfd_boolean writing
= FALSE
;
5360 memcpy (sym
, parm
->name
, len
);
5363 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5365 struct elf_link_hash_entry
*h
;
5367 sym
[len
+ 0] = i
/ 10 + '0';
5368 sym
[len
+ 1] = i
% 10 + '0';
5369 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5373 h
->root
.type
= bfd_link_hash_defined
;
5374 h
->root
.u
.def
.section
= htab
->sfpr
;
5375 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
5378 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
5380 if (htab
->sfpr
->contents
== NULL
)
5382 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5383 if (htab
->sfpr
->contents
== NULL
)
5389 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5391 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5393 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5394 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5402 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5404 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5409 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5411 p
= savegpr0 (abfd
, p
, r
);
5412 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5414 bfd_put_32 (abfd
, BLR
, p
);
5419 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5421 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5426 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5428 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5430 p
= restgpr0 (abfd
, p
, r
);
5431 bfd_put_32 (abfd
, MTLR_R0
, p
);
5435 p
= restgpr0 (abfd
, p
, 30);
5436 p
= restgpr0 (abfd
, p
, 31);
5438 bfd_put_32 (abfd
, BLR
, p
);
5443 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5445 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5450 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5452 p
= savegpr1 (abfd
, p
, r
);
5453 bfd_put_32 (abfd
, BLR
, p
);
5458 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5460 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5465 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5467 p
= restgpr1 (abfd
, p
, r
);
5468 bfd_put_32 (abfd
, BLR
, p
);
5473 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5475 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5480 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5482 p
= savefpr (abfd
, p
, r
);
5483 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5485 bfd_put_32 (abfd
, BLR
, p
);
5490 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5492 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5497 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5499 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5501 p
= restfpr (abfd
, p
, r
);
5502 bfd_put_32 (abfd
, MTLR_R0
, p
);
5506 p
= restfpr (abfd
, p
, 30);
5507 p
= restfpr (abfd
, p
, 31);
5509 bfd_put_32 (abfd
, BLR
, p
);
5514 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5516 p
= savefpr (abfd
, p
, r
);
5517 bfd_put_32 (abfd
, BLR
, p
);
5522 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5524 p
= restfpr (abfd
, p
, r
);
5525 bfd_put_32 (abfd
, BLR
, p
);
5530 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5532 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5534 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5539 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5541 p
= savevr (abfd
, p
, r
);
5542 bfd_put_32 (abfd
, BLR
, p
);
5547 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5549 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5551 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5556 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5558 p
= restvr (abfd
, p
, r
);
5559 bfd_put_32 (abfd
, BLR
, p
);
5563 /* Called via elf_link_hash_traverse to transfer dynamic linking
5564 information on function code symbol entries to their corresponding
5565 function descriptor symbol entries. */
5568 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5570 struct bfd_link_info
*info
;
5571 struct ppc_link_hash_table
*htab
;
5572 struct plt_entry
*ent
;
5573 struct ppc_link_hash_entry
*fh
;
5574 struct ppc_link_hash_entry
*fdh
;
5575 bfd_boolean force_local
;
5577 fh
= (struct ppc_link_hash_entry
*) h
;
5578 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5581 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
5582 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
5585 htab
= ppc_hash_table (info
);
5587 /* Resolve undefined references to dot-symbols as the value
5588 in the function descriptor, if we have one in a regular object.
5589 This is to satisfy cases like ".quad .foo". Calls to functions
5590 in dynamic objects are handled elsewhere. */
5591 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
5592 && fh
->was_undefined
5593 && (fh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5594 || fh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
)
5595 && get_opd_info (fh
->oh
->elf
.root
.u
.def
.section
) != NULL
5596 && opd_entry_value (fh
->oh
->elf
.root
.u
.def
.section
,
5597 fh
->oh
->elf
.root
.u
.def
.value
,
5598 &fh
->elf
.root
.u
.def
.section
,
5599 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
5601 fh
->elf
.root
.type
= fh
->oh
->elf
.root
.type
;
5602 fh
->elf
.forced_local
= 1;
5605 /* If this is a function code symbol, transfer dynamic linking
5606 information to the function descriptor symbol. */
5610 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5611 if (ent
->plt
.refcount
> 0)
5614 || fh
->elf
.root
.root
.string
[0] != '.'
5615 || fh
->elf
.root
.root
.string
[1] == '\0')
5618 /* Find the corresponding function descriptor symbol. Create it
5619 as undefined if necessary. */
5621 fdh
= get_fdh (fh
, htab
);
5623 while (fdh
->elf
.root
.type
== bfd_link_hash_indirect
5624 || fdh
->elf
.root
.type
== bfd_link_hash_warning
)
5625 fdh
= (struct ppc_link_hash_entry
*) fdh
->elf
.root
.u
.i
.link
;
5629 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5630 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5632 fdh
= make_fdh (info
, fh
);
5637 /* Fake function descriptors are made undefweak. If the function
5638 code symbol is strong undefined, make the fake sym the same.
5639 If the function code symbol is defined, then force the fake
5640 descriptor local; We can't support overriding of symbols in a
5641 shared library on a fake descriptor. */
5645 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5647 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
5649 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
5650 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
5652 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
5653 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5655 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5660 && !fdh
->elf
.forced_local
5662 || fdh
->elf
.def_dynamic
5663 || fdh
->elf
.ref_dynamic
5664 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
5665 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
5667 if (fdh
->elf
.dynindx
== -1)
5668 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5670 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5671 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5672 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5673 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5674 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
5676 move_plt_plist (fh
, fdh
);
5677 fdh
->elf
.needs_plt
= 1;
5679 fdh
->is_func_descriptor
= 1;
5684 /* Now that the info is on the function descriptor, clear the
5685 function code sym info. Any function code syms for which we
5686 don't have a definition in a regular file, we force local.
5687 This prevents a shared library from exporting syms that have
5688 been imported from another library. Function code syms that
5689 are really in the library we must leave global to prevent the
5690 linker dragging in a definition from a static library. */
5691 force_local
= (!fh
->elf
.def_regular
5693 || !fdh
->elf
.def_regular
5694 || fdh
->elf
.forced_local
);
5695 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5700 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5701 this hook to a) provide some gcc support functions, and b) transfer
5702 dynamic linking information gathered so far on function code symbol
5703 entries, to their corresponding function descriptor symbol entries. */
5706 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5707 struct bfd_link_info
*info
)
5709 struct ppc_link_hash_table
*htab
;
5711 const struct sfpr_def_parms funcs
[] =
5713 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5714 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5715 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5716 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5717 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5718 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5719 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5720 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5721 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5722 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5723 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5724 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5727 htab
= ppc_hash_table (info
);
5728 if (htab
->sfpr
== NULL
)
5729 /* We don't have any relocs. */
5732 /* Provide any missing _save* and _rest* functions. */
5733 htab
->sfpr
->size
= 0;
5734 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
5735 if (!sfpr_define (info
, &funcs
[i
]))
5738 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5740 if (htab
->sfpr
->size
== 0)
5741 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5746 /* Adjust a symbol defined by a dynamic object and referenced by a
5747 regular object. The current definition is in some section of the
5748 dynamic object, but we're not including those sections. We have to
5749 change the definition to something the rest of the link can
5753 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5754 struct elf_link_hash_entry
*h
)
5756 struct ppc_link_hash_table
*htab
;
5758 unsigned int power_of_two
;
5760 htab
= ppc_hash_table (info
);
5762 /* Deal with function syms. */
5763 if (h
->type
== STT_FUNC
5766 /* Clear procedure linkage table information for any symbol that
5767 won't need a .plt entry. */
5768 struct plt_entry
*ent
;
5769 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5770 if (ent
->plt
.refcount
> 0)
5773 || SYMBOL_CALLS_LOCAL (info
, h
)
5774 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5775 && h
->root
.type
== bfd_link_hash_undefweak
))
5777 h
->plt
.plist
= NULL
;
5782 h
->plt
.plist
= NULL
;
5784 /* If this is a weak symbol, and there is a real definition, the
5785 processor independent code will have arranged for us to see the
5786 real definition first, and we can just use the same value. */
5787 if (h
->u
.weakdef
!= NULL
)
5789 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5790 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5791 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5792 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5793 if (ELIMINATE_COPY_RELOCS
)
5794 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
5798 /* If we are creating a shared library, we must presume that the
5799 only references to the symbol are via the global offset table.
5800 For such cases we need not do anything here; the relocations will
5801 be handled correctly by relocate_section. */
5805 /* If there are no references to this symbol that do not use the
5806 GOT, we don't need to generate a copy reloc. */
5807 if (!h
->non_got_ref
)
5810 if (ELIMINATE_COPY_RELOCS
)
5812 struct ppc_link_hash_entry
* eh
;
5813 struct ppc_dyn_relocs
*p
;
5815 eh
= (struct ppc_link_hash_entry
*) h
;
5816 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5818 s
= p
->sec
->output_section
;
5819 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5823 /* If we didn't find any dynamic relocs in read-only sections, then
5824 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
5832 if (h
->plt
.plist
!= NULL
)
5834 /* We should never get here, but unfortunately there are versions
5835 of gcc out there that improperly (for this ABI) put initialized
5836 function pointers, vtable refs and suchlike in read-only
5837 sections. Allow them to proceed, but warn that this might
5838 break at runtime. */
5839 (*_bfd_error_handler
)
5840 (_("copy reloc against `%s' requires lazy plt linking; "
5841 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
5842 h
->root
.root
.string
);
5845 /* This is a reference to a symbol defined by a dynamic object which
5846 is not a function. */
5850 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
5851 h
->root
.root
.string
);
5855 /* We must allocate the symbol in our .dynbss section, which will
5856 become part of the .bss section of the executable. There will be
5857 an entry for this symbol in the .dynsym section. The dynamic
5858 object will contain position independent code, so all references
5859 from the dynamic object to this symbol will go through the global
5860 offset table. The dynamic linker will use the .dynsym entry to
5861 determine the address it must put in the global offset table, so
5862 both the dynamic object and the regular object will refer to the
5863 same memory location for the variable. */
5865 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
5866 to copy the initial value out of the dynamic object and into the
5867 runtime process image. We need to remember the offset into the
5868 .rela.bss section we are going to use. */
5869 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5871 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
5875 /* We need to figure out the alignment required for this symbol. I
5876 have no idea how ELF linkers handle this. */
5877 power_of_two
= bfd_log2 (h
->size
);
5878 if (power_of_two
> 4)
5881 /* Apply the required alignment. */
5883 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
5884 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
5886 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
5890 /* Define the symbol as being at this point in the section. */
5891 h
->root
.u
.def
.section
= s
;
5892 h
->root
.u
.def
.value
= s
->size
;
5894 /* Increment the section size to make room for the symbol. */
5900 /* If given a function descriptor symbol, hide both the function code
5901 sym and the descriptor. */
5903 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
5904 struct elf_link_hash_entry
*h
,
5905 bfd_boolean force_local
)
5907 struct ppc_link_hash_entry
*eh
;
5908 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
5910 eh
= (struct ppc_link_hash_entry
*) h
;
5911 if (eh
->is_func_descriptor
)
5913 struct ppc_link_hash_entry
*fh
= eh
->oh
;
5918 struct ppc_link_hash_table
*htab
;
5921 /* We aren't supposed to use alloca in BFD because on
5922 systems which do not have alloca the version in libiberty
5923 calls xmalloc, which might cause the program to crash
5924 when it runs out of memory. This function doesn't have a
5925 return status, so there's no way to gracefully return an
5926 error. So cheat. We know that string[-1] can be safely
5927 accessed; It's either a string in an ELF string table,
5928 or allocated in an objalloc structure. */
5930 p
= eh
->elf
.root
.root
.string
- 1;
5933 htab
= ppc_hash_table (info
);
5934 fh
= (struct ppc_link_hash_entry
*)
5935 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
5938 /* Unfortunately, if it so happens that the string we were
5939 looking for was allocated immediately before this string,
5940 then we overwrote the string terminator. That's the only
5941 reason the lookup should fail. */
5944 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
5945 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
5947 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
5948 fh
= (struct ppc_link_hash_entry
*)
5949 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
5958 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5963 get_sym_h (struct elf_link_hash_entry
**hp
,
5964 Elf_Internal_Sym
**symp
,
5967 Elf_Internal_Sym
**locsymsp
,
5968 unsigned long r_symndx
,
5971 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
5973 if (r_symndx
>= symtab_hdr
->sh_info
)
5975 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
5976 struct elf_link_hash_entry
*h
;
5978 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5979 while (h
->root
.type
== bfd_link_hash_indirect
5980 || h
->root
.type
== bfd_link_hash_warning
)
5981 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5989 if (symsecp
!= NULL
)
5991 asection
*symsec
= NULL
;
5992 if (h
->root
.type
== bfd_link_hash_defined
5993 || h
->root
.type
== bfd_link_hash_defweak
)
5994 symsec
= h
->root
.u
.def
.section
;
5998 if (tls_maskp
!= NULL
)
6000 struct ppc_link_hash_entry
*eh
;
6002 eh
= (struct ppc_link_hash_entry
*) h
;
6003 *tls_maskp
= &eh
->tls_mask
;
6008 Elf_Internal_Sym
*sym
;
6009 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6011 if (locsyms
== NULL
)
6013 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6014 if (locsyms
== NULL
)
6015 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6016 symtab_hdr
->sh_info
,
6017 0, NULL
, NULL
, NULL
);
6018 if (locsyms
== NULL
)
6020 *locsymsp
= locsyms
;
6022 sym
= locsyms
+ r_symndx
;
6030 if (symsecp
!= NULL
)
6032 asection
*symsec
= NULL
;
6033 if ((sym
->st_shndx
!= SHN_UNDEF
6034 && sym
->st_shndx
< SHN_LORESERVE
)
6035 || sym
->st_shndx
> SHN_HIRESERVE
)
6036 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6040 if (tls_maskp
!= NULL
)
6042 struct got_entry
**lgot_ents
;
6046 lgot_ents
= elf_local_got_ents (ibfd
);
6047 if (lgot_ents
!= NULL
)
6049 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
6050 tls_mask
= &lgot_masks
[r_symndx
];
6052 *tls_maskp
= tls_mask
;
6058 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6059 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6060 type suitable for optimization, and 1 otherwise. */
6063 get_tls_mask (char **tls_maskp
, unsigned long *toc_symndx
,
6064 Elf_Internal_Sym
**locsymsp
,
6065 const Elf_Internal_Rela
*rel
, bfd
*ibfd
)
6067 unsigned long r_symndx
;
6069 struct elf_link_hash_entry
*h
;
6070 Elf_Internal_Sym
*sym
;
6074 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6075 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6078 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6080 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6083 /* Look inside a TOC section too. */
6086 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6087 off
= h
->root
.u
.def
.value
;
6090 off
= sym
->st_value
;
6091 off
+= rel
->r_addend
;
6092 BFD_ASSERT (off
% 8 == 0);
6093 r_symndx
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8];
6094 next_r
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8 + 1];
6095 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6097 if (toc_symndx
!= NULL
)
6098 *toc_symndx
= r_symndx
;
6100 || ((h
->root
.type
== bfd_link_hash_defined
6101 || h
->root
.type
== bfd_link_hash_defweak
)
6102 && !h
->def_dynamic
))
6103 && (next_r
== -1 || next_r
== -2))
6108 /* Adjust all global syms defined in opd sections. In gcc generated
6109 code for the old ABI, these will already have been done. */
6112 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6114 struct ppc_link_hash_entry
*eh
;
6118 if (h
->root
.type
== bfd_link_hash_indirect
)
6121 if (h
->root
.type
== bfd_link_hash_warning
)
6122 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6124 if (h
->root
.type
!= bfd_link_hash_defined
6125 && h
->root
.type
!= bfd_link_hash_defweak
)
6128 eh
= (struct ppc_link_hash_entry
*) h
;
6129 if (eh
->adjust_done
)
6132 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6133 opd_adjust
= get_opd_info (sym_sec
);
6134 if (opd_adjust
!= NULL
)
6136 long adjust
= opd_adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6139 /* This entry has been deleted. */
6140 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6143 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6144 if (elf_discarded_section (dsec
))
6146 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6150 eh
->elf
.root
.u
.def
.value
= 0;
6151 eh
->elf
.root
.u
.def
.section
= dsec
;
6154 eh
->elf
.root
.u
.def
.value
+= adjust
;
6155 eh
->adjust_done
= 1;
6160 /* Handles decrementing dynamic reloc counts for the reloc specified by
6161 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6162 have already been determined. */
6165 dec_dynrel_count (bfd_vma r_info
,
6167 struct bfd_link_info
*info
,
6168 Elf_Internal_Sym
**local_syms
,
6169 struct elf_link_hash_entry
*h
,
6172 enum elf_ppc64_reloc_type r_type
;
6173 struct ppc_dyn_relocs
*p
;
6174 struct ppc_dyn_relocs
**pp
;
6176 /* Can this reloc be dynamic? This switch, and later tests here
6177 should be kept in sync with the code in check_relocs. */
6178 r_type
= ELF64_R_TYPE (r_info
);
6184 case R_PPC64_TPREL16
:
6185 case R_PPC64_TPREL16_LO
:
6186 case R_PPC64_TPREL16_HI
:
6187 case R_PPC64_TPREL16_HA
:
6188 case R_PPC64_TPREL16_DS
:
6189 case R_PPC64_TPREL16_LO_DS
:
6190 case R_PPC64_TPREL16_HIGHER
:
6191 case R_PPC64_TPREL16_HIGHERA
:
6192 case R_PPC64_TPREL16_HIGHEST
:
6193 case R_PPC64_TPREL16_HIGHESTA
:
6197 case R_PPC64_TPREL64
:
6198 case R_PPC64_DTPMOD64
:
6199 case R_PPC64_DTPREL64
:
6200 case R_PPC64_ADDR64
:
6204 case R_PPC64_ADDR14
:
6205 case R_PPC64_ADDR14_BRNTAKEN
:
6206 case R_PPC64_ADDR14_BRTAKEN
:
6207 case R_PPC64_ADDR16
:
6208 case R_PPC64_ADDR16_DS
:
6209 case R_PPC64_ADDR16_HA
:
6210 case R_PPC64_ADDR16_HI
:
6211 case R_PPC64_ADDR16_HIGHER
:
6212 case R_PPC64_ADDR16_HIGHERA
:
6213 case R_PPC64_ADDR16_HIGHEST
:
6214 case R_PPC64_ADDR16_HIGHESTA
:
6215 case R_PPC64_ADDR16_LO
:
6216 case R_PPC64_ADDR16_LO_DS
:
6217 case R_PPC64_ADDR24
:
6218 case R_PPC64_ADDR32
:
6219 case R_PPC64_UADDR16
:
6220 case R_PPC64_UADDR32
:
6221 case R_PPC64_UADDR64
:
6226 if (local_syms
!= NULL
)
6228 unsigned long r_symndx
;
6229 Elf_Internal_Sym
*sym
;
6230 bfd
*ibfd
= sec
->owner
;
6232 r_symndx
= ELF64_R_SYM (r_info
);
6233 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6238 && (MUST_BE_DYN_RELOC (r_type
)
6241 || h
->root
.type
== bfd_link_hash_defweak
6242 || !h
->def_regular
))))
6243 || (ELIMINATE_COPY_RELOCS
6246 && (h
->root
.type
== bfd_link_hash_defweak
6247 || !h
->def_regular
)))
6253 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6256 if (sym_sec
!= NULL
)
6258 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6259 pp
= (struct ppc_dyn_relocs
**) vpp
;
6263 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6264 pp
= (struct ppc_dyn_relocs
**) vpp
;
6267 /* elf_gc_sweep may have already removed all dyn relocs associated
6268 with local syms for a given section. Don't report a dynreloc
6274 while ((p
= *pp
) != NULL
)
6278 if (!MUST_BE_DYN_RELOC (r_type
))
6288 (*_bfd_error_handler
) (_("dynreloc miscount for %B, section %A"),
6290 bfd_set_error (bfd_error_bad_value
);
6294 /* Remove unused Official Procedure Descriptor entries. Currently we
6295 only remove those associated with functions in discarded link-once
6296 sections, or weakly defined functions that have been overridden. It
6297 would be possible to remove many more entries for statically linked
6301 ppc64_elf_edit_opd (bfd
*obfd
, struct bfd_link_info
*info
,
6302 bfd_boolean no_opd_opt
,
6303 bfd_boolean non_overlapping
)
6306 bfd_boolean some_edited
= FALSE
;
6307 asection
*need_pad
= NULL
;
6309 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6312 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6313 Elf_Internal_Shdr
*symtab_hdr
;
6314 Elf_Internal_Sym
*local_syms
;
6315 struct elf_link_hash_entry
**sym_hashes
;
6319 bfd_boolean need_edit
, add_aux_fields
;
6320 bfd_size_type cnt_16b
= 0;
6322 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6323 if (sec
== NULL
|| sec
->size
== 0)
6326 amt
= sec
->size
* sizeof (long) / 8;
6327 opd_adjust
= get_opd_info (sec
);
6328 if (opd_adjust
== NULL
)
6330 /* check_relocs hasn't been called. Must be a ld -r link
6331 or --just-symbols object. */
6332 opd_adjust
= bfd_alloc (obfd
, amt
);
6333 if (opd_adjust
== NULL
)
6335 ppc64_elf_section_data (sec
)->u
.opd_adjust
= opd_adjust
;
6336 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
6337 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
6339 memset (opd_adjust
, 0, amt
);
6344 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6347 if (sec
->output_section
== bfd_abs_section_ptr
)
6350 /* Look through the section relocs. */
6351 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6355 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6356 sym_hashes
= elf_sym_hashes (ibfd
);
6358 /* Read the relocations. */
6359 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6361 if (relstart
== NULL
)
6364 /* First run through the relocs to check they are sane, and to
6365 determine whether we need to edit this opd section. */
6369 relend
= relstart
+ sec
->reloc_count
;
6370 for (rel
= relstart
; rel
< relend
; )
6372 enum elf_ppc64_reloc_type r_type
;
6373 unsigned long r_symndx
;
6375 struct elf_link_hash_entry
*h
;
6376 Elf_Internal_Sym
*sym
;
6378 /* .opd contains a regular array of 16 or 24 byte entries. We're
6379 only interested in the reloc pointing to a function entry
6381 if (rel
->r_offset
!= offset
6382 || rel
+ 1 >= relend
6383 || (rel
+ 1)->r_offset
!= offset
+ 8)
6385 /* If someone messes with .opd alignment then after a
6386 "ld -r" we might have padding in the middle of .opd.
6387 Also, there's nothing to prevent someone putting
6388 something silly in .opd with the assembler. No .opd
6389 optimization for them! */
6391 (*_bfd_error_handler
)
6392 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6397 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6398 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6400 (*_bfd_error_handler
)
6401 (_("%B: unexpected reloc type %u in .opd section"),
6407 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6408 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6412 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6414 const char *sym_name
;
6416 sym_name
= h
->root
.root
.string
;
6418 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6421 (*_bfd_error_handler
)
6422 (_("%B: undefined sym `%s' in .opd section"),
6428 /* opd entries are always for functions defined in the
6429 current input bfd. If the symbol isn't defined in the
6430 input bfd, then we won't be using the function in this
6431 bfd; It must be defined in a linkonce section in another
6432 bfd, or is weak. It's also possible that we are
6433 discarding the function due to a linker script /DISCARD/,
6434 which we test for via the output_section. */
6435 if (sym_sec
->owner
!= ibfd
6436 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6441 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
6443 if (sec
->size
== offset
+ 24)
6448 if (rel
== relend
&& sec
->size
== offset
+ 16)
6456 if (rel
->r_offset
== offset
+ 24)
6458 else if (rel
->r_offset
!= offset
+ 16)
6460 else if (rel
+ 1 < relend
6461 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6462 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6467 else if (rel
+ 2 < relend
6468 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
6469 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
6478 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
6480 if (need_edit
|| add_aux_fields
)
6482 Elf_Internal_Rela
*write_rel
;
6483 bfd_byte
*rptr
, *wptr
;
6484 bfd_byte
*new_contents
= NULL
;
6488 /* This seems a waste of time as input .opd sections are all
6489 zeros as generated by gcc, but I suppose there's no reason
6490 this will always be so. We might start putting something in
6491 the third word of .opd entries. */
6492 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6495 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6500 if (local_syms
!= NULL
6501 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6503 if (elf_section_data (sec
)->relocs
!= relstart
)
6507 sec
->contents
= loc
;
6508 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6511 elf_section_data (sec
)->relocs
= relstart
;
6513 new_contents
= sec
->contents
;
6516 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6517 if (new_contents
== NULL
)
6521 wptr
= new_contents
;
6522 rptr
= sec
->contents
;
6524 write_rel
= relstart
;
6528 for (rel
= relstart
; rel
< relend
; rel
++)
6530 unsigned long r_symndx
;
6532 struct elf_link_hash_entry
*h
;
6533 Elf_Internal_Sym
*sym
;
6535 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6536 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6540 if (rel
->r_offset
== offset
)
6542 struct ppc_link_hash_entry
*fdh
= NULL
;
6544 /* See if the .opd entry is full 24 byte or
6545 16 byte (with fd_aux entry overlapped with next
6548 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
6549 || (rel
+ 3 < relend
6550 && rel
[2].r_offset
== offset
+ 16
6551 && rel
[3].r_offset
== offset
+ 24
6552 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
6553 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
6557 && h
->root
.root
.string
[0] == '.')
6559 fdh
= get_fdh ((struct ppc_link_hash_entry
*) h
,
6560 ppc_hash_table (info
));
6562 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
6563 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6567 skip
= (sym_sec
->owner
!= ibfd
6568 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6571 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6573 /* Arrange for the function descriptor sym
6575 fdh
->elf
.root
.u
.def
.value
= 0;
6576 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6578 opd_adjust
[rel
->r_offset
/ 8] = -1;
6582 /* We'll be keeping this opd entry. */
6586 /* Redefine the function descriptor symbol to
6587 this location in the opd section. It is
6588 necessary to update the value here rather
6589 than using an array of adjustments as we do
6590 for local symbols, because various places
6591 in the generic ELF code use the value
6592 stored in u.def.value. */
6593 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6594 fdh
->adjust_done
= 1;
6597 /* Local syms are a bit tricky. We could
6598 tweak them as they can be cached, but
6599 we'd need to look through the local syms
6600 for the function descriptor sym which we
6601 don't have at the moment. So keep an
6602 array of adjustments. */
6603 opd_adjust
[rel
->r_offset
/ 8]
6604 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
6607 memcpy (wptr
, rptr
, opd_ent_size
);
6608 wptr
+= opd_ent_size
;
6609 if (add_aux_fields
&& opd_ent_size
== 16)
6611 memset (wptr
, '\0', 8);
6615 rptr
+= opd_ent_size
;
6616 offset
+= opd_ent_size
;
6622 && !info
->relocatable
6623 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
6629 /* We need to adjust any reloc offsets to point to the
6630 new opd entries. While we're at it, we may as well
6631 remove redundant relocs. */
6632 rel
->r_offset
+= opd_adjust
[(offset
- opd_ent_size
) / 8];
6633 if (write_rel
!= rel
)
6634 memcpy (write_rel
, rel
, sizeof (*rel
));
6639 sec
->size
= wptr
- new_contents
;
6640 sec
->reloc_count
= write_rel
- relstart
;
6643 free (sec
->contents
);
6644 sec
->contents
= new_contents
;
6647 /* Fudge the header size too, as this is used later in
6648 elf_bfd_final_link if we are emitting relocs. */
6649 elf_section_data (sec
)->rel_hdr
.sh_size
6650 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
6651 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
6654 else if (elf_section_data (sec
)->relocs
!= relstart
)
6657 if (local_syms
!= NULL
6658 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6660 if (!info
->keep_memory
)
6663 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6668 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
6670 /* If we are doing a final link and the last .opd entry is just 16 byte
6671 long, add a 8 byte padding after it. */
6672 if (need_pad
!= NULL
&& !info
->relocatable
)
6676 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
6678 BFD_ASSERT (need_pad
->size
> 0);
6680 p
= bfd_malloc (need_pad
->size
+ 8);
6684 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
6685 p
, 0, need_pad
->size
))
6688 need_pad
->contents
= p
;
6689 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6693 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
6697 need_pad
->contents
= p
;
6700 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
6701 need_pad
->size
+= 8;
6707 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
6710 ppc64_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
6712 struct ppc_link_hash_table
*htab
;
6714 htab
= ppc_hash_table (info
);
6715 if (htab
->tls_get_addr
!= NULL
)
6717 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr
;
6719 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6720 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6721 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6723 htab
->tls_get_addr
= h
;
6725 if (htab
->tls_get_addr_fd
== NULL
6727 && h
->oh
->is_func_descriptor
6728 && (h
->oh
->elf
.root
.type
== bfd_link_hash_defined
6729 || h
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
6730 htab
->tls_get_addr_fd
= h
->oh
;
6733 if (htab
->tls_get_addr_fd
!= NULL
)
6735 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr_fd
;
6737 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6738 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6739 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6741 htab
->tls_get_addr_fd
= h
;
6744 return _bfd_elf_tls_setup (obfd
, info
);
6747 /* Run through all the TLS relocs looking for optimization
6748 opportunities. The linker has been hacked (see ppc64elf.em) to do
6749 a preliminary section layout so that we know the TLS segment
6750 offsets. We can't optimize earlier because some optimizations need
6751 to know the tp offset, and we need to optimize before allocating
6752 dynamic relocations. */
6755 ppc64_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6759 struct ppc_link_hash_table
*htab
;
6761 if (info
->relocatable
|| info
->shared
)
6764 htab
= ppc_hash_table (info
);
6765 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6767 Elf_Internal_Sym
*locsyms
= NULL
;
6768 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
6769 unsigned char *toc_ref
= NULL
;
6771 /* Look at all the sections for this file, with TOC last. */
6772 for (sec
= (ibfd
->sections
== toc
&& toc
&& toc
->next
? toc
->next
6775 sec
= (sec
== toc
? NULL
6776 : sec
->next
== NULL
? toc
6777 : sec
->next
== toc
&& toc
->next
? toc
->next
6779 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
6781 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6782 int expecting_tls_get_addr
;
6783 long toc_ref_index
= 0;
6785 /* Read the relocations. */
6786 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6788 if (relstart
== NULL
)
6791 expecting_tls_get_addr
= 0;
6792 relend
= relstart
+ sec
->reloc_count
;
6793 for (rel
= relstart
; rel
< relend
; rel
++)
6795 enum elf_ppc64_reloc_type r_type
;
6796 unsigned long r_symndx
;
6797 struct elf_link_hash_entry
*h
;
6798 Elf_Internal_Sym
*sym
;
6801 char tls_set
, tls_clear
, tls_type
= 0;
6803 bfd_boolean ok_tprel
, is_local
;
6805 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6806 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
6810 if (elf_section_data (sec
)->relocs
!= relstart
)
6812 if (toc_ref
!= NULL
)
6815 && (elf_tdata (ibfd
)->symtab_hdr
.contents
6816 != (unsigned char *) locsyms
))
6823 if (h
->root
.type
!= bfd_link_hash_defined
6824 && h
->root
.type
!= bfd_link_hash_defweak
)
6826 value
= h
->root
.u
.def
.value
;
6829 /* Symbols referenced by TLS relocs must be of type
6830 STT_TLS. So no need for .opd local sym adjust. */
6831 value
= sym
->st_value
;
6839 value
+= sym_sec
->output_offset
;
6840 value
+= sym_sec
->output_section
->vma
;
6841 value
-= htab
->elf
.tls_sec
->vma
;
6842 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
6843 < (bfd_vma
) 1 << 32);
6846 r_type
= ELF64_R_TYPE (rel
->r_info
);
6849 case R_PPC64_GOT_TLSLD16
:
6850 case R_PPC64_GOT_TLSLD16_LO
:
6851 case R_PPC64_GOT_TLSLD16_HI
:
6852 case R_PPC64_GOT_TLSLD16_HA
:
6853 /* These relocs should never be against a symbol
6854 defined in a shared lib. Leave them alone if
6855 that turns out to be the case. */
6856 ppc64_tlsld_got (ibfd
)->refcount
-= 1;
6863 tls_type
= TLS_TLS
| TLS_LD
;
6864 expecting_tls_get_addr
= 1;
6867 case R_PPC64_GOT_TLSGD16
:
6868 case R_PPC64_GOT_TLSGD16_LO
:
6869 case R_PPC64_GOT_TLSGD16_HI
:
6870 case R_PPC64_GOT_TLSGD16_HA
:
6876 tls_set
= TLS_TLS
| TLS_TPRELGD
;
6878 tls_type
= TLS_TLS
| TLS_GD
;
6879 expecting_tls_get_addr
= 1;
6882 case R_PPC64_GOT_TPREL16_DS
:
6883 case R_PPC64_GOT_TPREL16_LO_DS
:
6884 case R_PPC64_GOT_TPREL16_HI
:
6885 case R_PPC64_GOT_TPREL16_HA
:
6886 expecting_tls_get_addr
= 0;
6891 tls_clear
= TLS_TPREL
;
6892 tls_type
= TLS_TLS
| TLS_TPREL
;
6899 case R_PPC64_REL14_BRTAKEN
:
6900 case R_PPC64_REL14_BRNTAKEN
:
6903 && (h
== &htab
->tls_get_addr
->elf
6904 || h
== &htab
->tls_get_addr_fd
->elf
))
6906 if (!expecting_tls_get_addr
6908 && ((ELF64_R_TYPE (rel
[-1].r_info
)
6910 || (ELF64_R_TYPE (rel
[-1].r_info
)
6911 == R_PPC64_TOC16_LO
)))
6913 /* Check for toc tls entries. */
6917 retval
= get_tls_mask (&toc_tls
, NULL
, &locsyms
,
6921 if (retval
> 1 && toc_tls
!= NULL
)
6923 expecting_tls_get_addr
= 1;
6924 if (toc_ref
!= NULL
)
6925 toc_ref
[toc_ref_index
] = 1;
6929 if (expecting_tls_get_addr
)
6931 struct plt_entry
*ent
;
6932 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
6933 if (ent
->addend
== 0)
6935 if (ent
->plt
.refcount
> 0)
6936 ent
->plt
.refcount
-= 1;
6941 expecting_tls_get_addr
= 0;
6945 case R_PPC64_TOC16_LO
:
6947 expecting_tls_get_addr
= 0;
6948 if (sym_sec
== toc
&& toc
!= NULL
)
6950 /* Mark this toc entry as referenced by a TLS
6951 code sequence. We can do that now in the
6952 case of R_PPC64_TLS, and after checking for
6953 tls_get_addr for the TOC16 relocs. */
6954 if (toc_ref
== NULL
)
6956 toc_ref
= bfd_zmalloc (toc
->size
/ 8);
6957 if (toc_ref
== NULL
)
6961 value
= h
->root
.u
.def
.value
;
6963 value
= sym
->st_value
;
6964 value
+= rel
->r_addend
;
6965 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
6966 toc_ref_index
= value
/ 8;
6967 if (r_type
== R_PPC64_TLS
)
6968 toc_ref
[toc_ref_index
] = 1;
6972 case R_PPC64_TPREL64
:
6973 expecting_tls_get_addr
= 0;
6976 || !toc_ref
[rel
->r_offset
/ 8])
6981 tls_set
= TLS_EXPLICIT
;
6982 tls_clear
= TLS_TPREL
;
6988 case R_PPC64_DTPMOD64
:
6989 expecting_tls_get_addr
= 0;
6992 || !toc_ref
[rel
->r_offset
/ 8])
6994 if (rel
+ 1 < relend
6996 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
6997 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7001 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7004 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7013 tls_set
= TLS_EXPLICIT
;
7019 expecting_tls_get_addr
= 0;
7023 if ((tls_set
& TLS_EXPLICIT
) == 0)
7025 struct got_entry
*ent
;
7027 /* Adjust got entry for this reloc. */
7031 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7033 for (; ent
!= NULL
; ent
= ent
->next
)
7034 if (ent
->addend
== rel
->r_addend
7035 && ent
->owner
== ibfd
7036 && ent
->tls_type
== tls_type
)
7043 /* We managed to get rid of a got entry. */
7044 if (ent
->got
.refcount
> 0)
7045 ent
->got
.refcount
-= 1;
7050 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7051 we'll lose one or two dyn relocs. */
7052 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7056 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7058 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7064 *tls_mask
|= tls_set
;
7065 *tls_mask
&= ~tls_clear
;
7068 if (elf_section_data (sec
)->relocs
!= relstart
)
7072 if (toc_ref
!= NULL
)
7076 && (elf_tdata (ibfd
)->symtab_hdr
.contents
7077 != (unsigned char *) locsyms
))
7079 if (!info
->keep_memory
)
7082 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
7088 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7089 the values of any global symbols in a toc section that has been
7090 edited. Globals in toc sections should be a rarity, so this function
7091 sets a flag if any are found in toc sections other than the one just
7092 edited, so that futher hash table traversals can be avoided. */
7094 struct adjust_toc_info
7097 unsigned long *skip
;
7098 bfd_boolean global_toc_syms
;
7102 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7104 struct ppc_link_hash_entry
*eh
;
7105 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7107 if (h
->root
.type
== bfd_link_hash_indirect
)
7110 if (h
->root
.type
== bfd_link_hash_warning
)
7111 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7113 if (h
->root
.type
!= bfd_link_hash_defined
7114 && h
->root
.type
!= bfd_link_hash_defweak
)
7117 eh
= (struct ppc_link_hash_entry
*) h
;
7118 if (eh
->adjust_done
)
7121 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7123 unsigned long skip
= toc_inf
->skip
[eh
->elf
.root
.u
.def
.value
>> 3];
7124 if (skip
!= (unsigned long) -1)
7125 eh
->elf
.root
.u
.def
.value
-= skip
;
7128 (*_bfd_error_handler
)
7129 (_("%s defined in removed toc entry"), eh
->elf
.root
.root
.string
);
7130 eh
->elf
.root
.u
.def
.section
= &bfd_abs_section
;
7131 eh
->elf
.root
.u
.def
.value
= 0;
7133 eh
->adjust_done
= 1;
7135 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7136 toc_inf
->global_toc_syms
= TRUE
;
7141 /* Examine all relocs referencing .toc sections in order to remove
7142 unused .toc entries. */
7145 ppc64_elf_edit_toc (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
7148 struct adjust_toc_info toc_inf
;
7150 toc_inf
.global_toc_syms
= TRUE
;
7151 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7153 asection
*toc
, *sec
;
7154 Elf_Internal_Shdr
*symtab_hdr
;
7155 Elf_Internal_Sym
*local_syms
;
7156 struct elf_link_hash_entry
**sym_hashes
;
7157 Elf_Internal_Rela
*relstart
, *rel
;
7158 unsigned long *skip
, *drop
;
7159 unsigned char *used
;
7160 unsigned char *keep
, last
, some_unused
;
7162 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7165 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7166 || elf_discarded_section (toc
))
7170 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7171 sym_hashes
= elf_sym_hashes (ibfd
);
7173 /* Look at sections dropped from the final link. */
7176 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7178 if (sec
->reloc_count
== 0
7179 || !elf_discarded_section (sec
)
7180 || get_opd_info (sec
)
7181 || (sec
->flags
& SEC_ALLOC
) == 0
7182 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7185 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7186 if (relstart
== NULL
)
7189 /* Run through the relocs to see which toc entries might be
7191 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7193 enum elf_ppc64_reloc_type r_type
;
7194 unsigned long r_symndx
;
7196 struct elf_link_hash_entry
*h
;
7197 Elf_Internal_Sym
*sym
;
7200 r_type
= ELF64_R_TYPE (rel
->r_info
);
7207 case R_PPC64_TOC16_LO
:
7208 case R_PPC64_TOC16_HI
:
7209 case R_PPC64_TOC16_HA
:
7210 case R_PPC64_TOC16_DS
:
7211 case R_PPC64_TOC16_LO_DS
:
7215 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7216 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7224 val
= h
->root
.u
.def
.value
;
7226 val
= sym
->st_value
;
7227 val
+= rel
->r_addend
;
7229 if (val
>= toc
->size
)
7232 /* Anything in the toc ought to be aligned to 8 bytes.
7233 If not, don't mark as unused. */
7239 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 7) / 8);
7247 if (elf_section_data (sec
)->relocs
!= relstart
)
7254 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
7258 if (local_syms
!= NULL
7259 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7263 && elf_section_data (sec
)->relocs
!= relstart
)
7270 /* Now check all kept sections that might reference the toc.
7271 Check the toc itself last. */
7272 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
7275 sec
= (sec
== toc
? NULL
7276 : sec
->next
== NULL
? toc
7277 : sec
->next
== toc
&& toc
->next
? toc
->next
7282 if (sec
->reloc_count
== 0
7283 || elf_discarded_section (sec
)
7284 || get_opd_info (sec
)
7285 || (sec
->flags
& SEC_ALLOC
) == 0
7286 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7289 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, TRUE
);
7290 if (relstart
== NULL
)
7293 /* Mark toc entries referenced as used. */
7296 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7298 enum elf_ppc64_reloc_type r_type
;
7299 unsigned long r_symndx
;
7301 struct elf_link_hash_entry
*h
;
7302 Elf_Internal_Sym
*sym
;
7305 r_type
= ELF64_R_TYPE (rel
->r_info
);
7309 case R_PPC64_TOC16_LO
:
7310 case R_PPC64_TOC16_HI
:
7311 case R_PPC64_TOC16_HA
:
7312 case R_PPC64_TOC16_DS
:
7313 case R_PPC64_TOC16_LO_DS
:
7314 /* In case we're taking addresses of toc entries. */
7315 case R_PPC64_ADDR64
:
7322 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7323 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7334 val
= h
->root
.u
.def
.value
;
7336 val
= sym
->st_value
;
7337 val
+= rel
->r_addend
;
7339 if (val
>= toc
->size
)
7342 /* For the toc section, we only mark as used if
7343 this entry itself isn't unused. */
7346 && (used
[rel
->r_offset
>> 3]
7347 || !skip
[rel
->r_offset
>> 3]))
7348 /* Do all the relocs again, to catch reference
7357 /* Merge the used and skip arrays. Assume that TOC
7358 doublewords not appearing as either used or unused belong
7359 to to an entry more than one doubleword in size. */
7360 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
7361 drop
< skip
+ (toc
->size
+ 7) / 8;
7382 bfd_byte
*contents
, *src
;
7385 /* Shuffle the toc contents, and at the same time convert the
7386 skip array from booleans into offsets. */
7387 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
7390 elf_section_data (toc
)->this_hdr
.contents
= contents
;
7392 for (src
= contents
, off
= 0, drop
= skip
;
7393 src
< contents
+ toc
->size
;
7398 *drop
= (unsigned long) -1;
7404 memcpy (src
- off
, src
, 8);
7407 toc
->rawsize
= toc
->size
;
7408 toc
->size
= src
- contents
- off
;
7410 if (toc
->reloc_count
!= 0)
7412 Elf_Internal_Rela
*wrel
;
7415 /* Read toc relocs. */
7416 relstart
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
7418 if (relstart
== NULL
)
7421 /* Remove unused toc relocs, and adjust those we keep. */
7423 for (rel
= relstart
; rel
< relstart
+ toc
->reloc_count
; ++rel
)
7424 if (skip
[rel
->r_offset
>> 3] != (unsigned long) -1)
7426 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
7427 wrel
->r_info
= rel
->r_info
;
7428 wrel
->r_addend
= rel
->r_addend
;
7431 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
7432 &local_syms
, NULL
, NULL
))
7435 toc
->reloc_count
= wrel
- relstart
;
7436 sz
= elf_section_data (toc
)->rel_hdr
.sh_entsize
;
7437 elf_section_data (toc
)->rel_hdr
.sh_size
= toc
->reloc_count
* sz
;
7438 BFD_ASSERT (elf_section_data (toc
)->rel_hdr2
== NULL
);
7441 /* Adjust addends for relocs against the toc section sym. */
7442 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7444 if (sec
->reloc_count
== 0
7445 || elf_discarded_section (sec
))
7448 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7450 if (relstart
== NULL
)
7453 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7455 enum elf_ppc64_reloc_type r_type
;
7456 unsigned long r_symndx
;
7458 struct elf_link_hash_entry
*h
;
7459 Elf_Internal_Sym
*sym
;
7461 r_type
= ELF64_R_TYPE (rel
->r_info
);
7468 case R_PPC64_TOC16_LO
:
7469 case R_PPC64_TOC16_HI
:
7470 case R_PPC64_TOC16_HA
:
7471 case R_PPC64_TOC16_DS
:
7472 case R_PPC64_TOC16_LO_DS
:
7473 case R_PPC64_ADDR64
:
7477 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7478 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7482 if (sym_sec
!= toc
|| h
!= NULL
|| sym
->st_value
!= 0)
7485 rel
->r_addend
-= skip
[rel
->r_addend
>> 3];
7489 /* We shouldn't have local or global symbols defined in the TOC,
7490 but handle them anyway. */
7491 if (local_syms
!= NULL
)
7493 Elf_Internal_Sym
*sym
;
7495 for (sym
= local_syms
;
7496 sym
< local_syms
+ symtab_hdr
->sh_info
;
7498 if (sym
->st_shndx
!= SHN_UNDEF
7499 && (sym
->st_shndx
< SHN_LORESERVE
7500 || sym
->st_shndx
> SHN_HIRESERVE
)
7501 && sym
->st_value
!= 0
7502 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
7504 if (skip
[sym
->st_value
>> 3] != (unsigned long) -1)
7505 sym
->st_value
-= skip
[sym
->st_value
>> 3];
7508 (*_bfd_error_handler
)
7509 (_("%s defined in removed toc entry"),
7510 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7513 sym
->st_shndx
= SHN_ABS
;
7515 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7519 /* Finally, adjust any global syms defined in the toc. */
7520 if (toc_inf
.global_toc_syms
)
7523 toc_inf
.skip
= skip
;
7524 toc_inf
.global_toc_syms
= FALSE
;
7525 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
7530 if (local_syms
!= NULL
7531 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7533 if (!info
->keep_memory
)
7536 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7544 /* Allocate space in .plt, .got and associated reloc sections for
7548 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7550 struct bfd_link_info
*info
;
7551 struct ppc_link_hash_table
*htab
;
7553 struct ppc_link_hash_entry
*eh
;
7554 struct ppc_dyn_relocs
*p
;
7555 struct got_entry
*gent
;
7557 if (h
->root
.type
== bfd_link_hash_indirect
)
7560 if (h
->root
.type
== bfd_link_hash_warning
)
7561 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7563 info
= (struct bfd_link_info
*) inf
;
7564 htab
= ppc_hash_table (info
);
7566 if (htab
->elf
.dynamic_sections_created
7568 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
7570 struct plt_entry
*pent
;
7571 bfd_boolean doneone
= FALSE
;
7572 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7573 if (pent
->plt
.refcount
> 0)
7575 /* If this is the first .plt entry, make room for the special
7579 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
7581 pent
->plt
.offset
= s
->size
;
7583 /* Make room for this entry. */
7584 s
->size
+= PLT_ENTRY_SIZE
;
7586 /* Make room for the .glink code. */
7589 s
->size
+= GLINK_CALL_STUB_SIZE
;
7590 /* We need bigger stubs past index 32767. */
7591 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
7595 /* We also need to make an entry in the .rela.plt section. */
7597 s
->size
+= sizeof (Elf64_External_Rela
);
7601 pent
->plt
.offset
= (bfd_vma
) -1;
7604 h
->plt
.plist
= NULL
;
7610 h
->plt
.plist
= NULL
;
7614 eh
= (struct ppc_link_hash_entry
*) h
;
7615 /* Run through the TLS GD got entries first if we're changing them
7617 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
7618 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7619 if (gent
->got
.refcount
> 0
7620 && (gent
->tls_type
& TLS_GD
) != 0)
7622 /* This was a GD entry that has been converted to TPREL. If
7623 there happens to be a TPREL entry we can use that one. */
7624 struct got_entry
*ent
;
7625 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
7626 if (ent
->got
.refcount
> 0
7627 && (ent
->tls_type
& TLS_TPREL
) != 0
7628 && ent
->addend
== gent
->addend
7629 && ent
->owner
== gent
->owner
)
7631 gent
->got
.refcount
= 0;
7635 /* If not, then we'll be using our own TPREL entry. */
7636 if (gent
->got
.refcount
!= 0)
7637 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
7640 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7641 if (gent
->got
.refcount
> 0)
7645 /* Make sure this symbol is output as a dynamic symbol.
7646 Undefined weak syms won't yet be marked as dynamic,
7647 nor will all TLS symbols. */
7648 if (h
->dynindx
== -1
7649 && !h
->forced_local
)
7651 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7655 if ((gent
->tls_type
& TLS_LD
) != 0
7658 gent
->got
.offset
= ppc64_tlsld_got (gent
->owner
)->offset
;
7662 s
= ppc64_elf_tdata (gent
->owner
)->got
;
7663 gent
->got
.offset
= s
->size
;
7665 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
7666 dyn
= htab
->elf
.dynamic_sections_created
;
7668 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
7669 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7670 || h
->root
.type
!= bfd_link_hash_undefweak
))
7671 ppc64_elf_tdata (gent
->owner
)->relgot
->size
7672 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
7673 ? 2 * sizeof (Elf64_External_Rela
)
7674 : sizeof (Elf64_External_Rela
));
7677 gent
->got
.offset
= (bfd_vma
) -1;
7679 if (eh
->dyn_relocs
== NULL
)
7682 /* In the shared -Bsymbolic case, discard space allocated for
7683 dynamic pc-relative relocs against symbols which turn out to be
7684 defined in regular objects. For the normal shared case, discard
7685 space for relocs that have become local due to symbol visibility
7690 /* Relocs that use pc_count are those that appear on a call insn,
7691 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
7692 generated via assembly. We want calls to protected symbols to
7693 resolve directly to the function rather than going via the plt.
7694 If people want function pointer comparisons to work as expected
7695 then they should avoid writing weird assembly. */
7696 if (SYMBOL_CALLS_LOCAL (info
, h
))
7698 struct ppc_dyn_relocs
**pp
;
7700 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
7702 p
->count
-= p
->pc_count
;
7711 /* Also discard relocs on undefined weak syms with non-default
7713 if (eh
->dyn_relocs
!= NULL
7714 && h
->root
.type
== bfd_link_hash_undefweak
)
7716 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7717 eh
->dyn_relocs
= NULL
;
7719 /* Make sure this symbol is output as a dynamic symbol.
7720 Undefined weak syms won't yet be marked as dynamic. */
7721 else if (h
->dynindx
== -1
7722 && !h
->forced_local
)
7724 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7729 else if (ELIMINATE_COPY_RELOCS
)
7731 /* For the non-shared case, discard space for relocs against
7732 symbols which turn out to need copy relocs or are not
7739 /* Make sure this symbol is output as a dynamic symbol.
7740 Undefined weak syms won't yet be marked as dynamic. */
7741 if (h
->dynindx
== -1
7742 && !h
->forced_local
)
7744 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7748 /* If that succeeded, we know we'll be keeping all the
7750 if (h
->dynindx
!= -1)
7754 eh
->dyn_relocs
= NULL
;
7759 /* Finally, allocate space. */
7760 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7762 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
7763 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7769 /* Find any dynamic relocs that apply to read-only sections. */
7772 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7774 struct ppc_link_hash_entry
*eh
;
7775 struct ppc_dyn_relocs
*p
;
7777 if (h
->root
.type
== bfd_link_hash_warning
)
7778 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7780 eh
= (struct ppc_link_hash_entry
*) h
;
7781 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7783 asection
*s
= p
->sec
->output_section
;
7785 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7787 struct bfd_link_info
*info
= inf
;
7789 info
->flags
|= DF_TEXTREL
;
7791 /* Not an error, just cut short the traversal. */
7798 /* Set the sizes of the dynamic sections. */
7801 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7802 struct bfd_link_info
*info
)
7804 struct ppc_link_hash_table
*htab
;
7810 htab
= ppc_hash_table (info
);
7811 dynobj
= htab
->elf
.dynobj
;
7815 if (htab
->elf
.dynamic_sections_created
)
7817 /* Set the contents of the .interp section to the interpreter. */
7818 if (info
->executable
)
7820 s
= bfd_get_section_by_name (dynobj
, ".interp");
7823 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7824 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7828 /* Set up .got offsets for local syms, and space for local dynamic
7830 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7832 struct got_entry
**lgot_ents
;
7833 struct got_entry
**end_lgot_ents
;
7835 bfd_size_type locsymcount
;
7836 Elf_Internal_Shdr
*symtab_hdr
;
7839 if (!is_ppc64_elf_target (ibfd
->xvec
))
7842 if (ppc64_tlsld_got (ibfd
)->refcount
> 0)
7844 s
= ppc64_elf_tdata (ibfd
)->got
;
7845 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7849 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7850 srel
->size
+= sizeof (Elf64_External_Rela
);
7854 ppc64_tlsld_got (ibfd
)->offset
= (bfd_vma
) -1;
7856 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7858 struct ppc_dyn_relocs
*p
;
7860 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
7862 if (!bfd_is_abs_section (p
->sec
)
7863 && bfd_is_abs_section (p
->sec
->output_section
))
7865 /* Input section has been discarded, either because
7866 it is a copy of a linkonce section or due to
7867 linker script /DISCARD/, so we'll be discarding
7870 else if (p
->count
!= 0)
7872 srel
= elf_section_data (p
->sec
)->sreloc
;
7873 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7874 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7875 info
->flags
|= DF_TEXTREL
;
7880 lgot_ents
= elf_local_got_ents (ibfd
);
7884 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7885 locsymcount
= symtab_hdr
->sh_info
;
7886 end_lgot_ents
= lgot_ents
+ locsymcount
;
7887 lgot_masks
= (char *) end_lgot_ents
;
7888 s
= ppc64_elf_tdata (ibfd
)->got
;
7889 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7890 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
7892 struct got_entry
*ent
;
7894 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
7895 if (ent
->got
.refcount
> 0)
7897 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
7899 if (ppc64_tlsld_got (ibfd
)->offset
== (bfd_vma
) -1)
7901 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7904 srel
->size
+= sizeof (Elf64_External_Rela
);
7906 ent
->got
.offset
= ppc64_tlsld_got (ibfd
)->offset
;
7910 ent
->got
.offset
= s
->size
;
7911 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
7915 srel
->size
+= 2 * sizeof (Elf64_External_Rela
);
7921 srel
->size
+= sizeof (Elf64_External_Rela
);
7926 ent
->got
.offset
= (bfd_vma
) -1;
7930 /* Allocate global sym .plt and .got entries, and space for global
7931 sym dynamic relocs. */
7932 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
7934 /* We now have determined the sizes of the various dynamic sections.
7935 Allocate memory for them. */
7937 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7939 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7942 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
7943 /* These haven't been allocated yet; don't strip. */
7945 else if (s
== htab
->got
7948 || s
== htab
->dynbss
)
7950 /* Strip this section if we don't need it; see the
7953 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
7957 if (s
!= htab
->relplt
)
7960 /* We use the reloc_count field as a counter if we need
7961 to copy relocs into the output file. */
7967 /* It's not one of our sections, so don't allocate space. */
7973 /* If we don't need this section, strip it from the
7974 output file. This is mostly to handle .rela.bss and
7975 .rela.plt. We must create both sections in
7976 create_dynamic_sections, because they must be created
7977 before the linker maps input sections to output
7978 sections. The linker does that before
7979 adjust_dynamic_symbol is called, and it is that
7980 function which decides whether anything needs to go
7981 into these sections. */
7982 s
->flags
|= SEC_EXCLUDE
;
7986 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7989 /* Allocate memory for the section contents. We use bfd_zalloc
7990 here in case unused entries are not reclaimed before the
7991 section's contents are written out. This should not happen,
7992 but this way if it does we get a R_PPC64_NONE reloc in .rela
7993 sections instead of garbage.
7994 We also rely on the section contents being zero when writing
7996 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
7997 if (s
->contents
== NULL
)
8001 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8003 if (!is_ppc64_elf_target (ibfd
->xvec
))
8006 s
= ppc64_elf_tdata (ibfd
)->got
;
8007 if (s
!= NULL
&& s
!= htab
->got
)
8010 s
->flags
|= SEC_EXCLUDE
;
8013 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8014 if (s
->contents
== NULL
)
8018 s
= ppc64_elf_tdata (ibfd
)->relgot
;
8022 s
->flags
|= SEC_EXCLUDE
;
8025 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8026 if (s
->contents
== NULL
)
8034 if (htab
->elf
.dynamic_sections_created
)
8036 /* Add some entries to the .dynamic section. We fill in the
8037 values later, in ppc64_elf_finish_dynamic_sections, but we
8038 must add the entries now so that we get the correct size for
8039 the .dynamic section. The DT_DEBUG entry is filled in by the
8040 dynamic linker and used by the debugger. */
8041 #define add_dynamic_entry(TAG, VAL) \
8042 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8044 if (info
->executable
)
8046 if (!add_dynamic_entry (DT_DEBUG
, 0))
8050 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
8052 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8053 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8054 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8055 || !add_dynamic_entry (DT_JMPREL
, 0)
8056 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
8062 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
8063 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
8069 if (!add_dynamic_entry (DT_RELA
, 0)
8070 || !add_dynamic_entry (DT_RELASZ
, 0)
8071 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
8074 /* If any dynamic relocs apply to a read-only section,
8075 then we need a DT_TEXTREL entry. */
8076 if ((info
->flags
& DF_TEXTREL
) == 0)
8077 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
8079 if ((info
->flags
& DF_TEXTREL
) != 0)
8081 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8086 #undef add_dynamic_entry
8091 /* Determine the type of stub needed, if any, for a call. */
8093 static inline enum ppc_stub_type
8094 ppc_type_of_stub (asection
*input_sec
,
8095 const Elf_Internal_Rela
*rel
,
8096 struct ppc_link_hash_entry
**hash
,
8097 bfd_vma destination
)
8099 struct ppc_link_hash_entry
*h
= *hash
;
8101 bfd_vma branch_offset
;
8102 bfd_vma max_branch_offset
;
8103 enum elf_ppc64_reloc_type r_type
;
8107 struct ppc_link_hash_entry
*fdh
= h
;
8109 && fdh
->oh
->is_func_descriptor
)
8112 if (fdh
->elf
.dynindx
!= -1)
8114 struct plt_entry
*ent
;
8116 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8117 if (ent
->addend
== rel
->r_addend
8118 && ent
->plt
.offset
!= (bfd_vma
) -1)
8121 return ppc_stub_plt_call
;
8125 /* Here, we know we don't have a plt entry. If we don't have a
8126 either a defined function descriptor or a defined entry symbol
8127 in a regular object file, then it is pointless trying to make
8128 any other type of stub. */
8129 if (!((fdh
->elf
.root
.type
== bfd_link_hash_defined
8130 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
8131 && fdh
->elf
.root
.u
.def
.section
->output_section
!= NULL
)
8132 && !((h
->elf
.root
.type
== bfd_link_hash_defined
8133 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
8134 && h
->elf
.root
.u
.def
.section
->output_section
!= NULL
))
8135 return ppc_stub_none
;
8138 /* Determine where the call point is. */
8139 location
= (input_sec
->output_offset
8140 + input_sec
->output_section
->vma
8143 branch_offset
= destination
- location
;
8144 r_type
= ELF64_R_TYPE (rel
->r_info
);
8146 /* Determine if a long branch stub is needed. */
8147 max_branch_offset
= 1 << 25;
8148 if (r_type
!= R_PPC64_REL24
)
8149 max_branch_offset
= 1 << 15;
8151 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
8152 /* We need a stub. Figure out whether a long_branch or plt_branch
8154 return ppc_stub_long_branch
;
8156 return ppc_stub_none
;
8159 /* Build a .plt call stub. */
8161 static inline bfd_byte
*
8162 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
)
8164 #define PPC_LO(v) ((v) & 0xffff)
8165 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8166 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8168 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
8169 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
8170 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8171 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8172 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8174 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
8175 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8176 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8178 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
8179 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8180 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
8185 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8187 struct ppc_stub_hash_entry
*stub_entry
;
8188 struct ppc_branch_hash_entry
*br_entry
;
8189 struct bfd_link_info
*info
;
8190 struct ppc_link_hash_table
*htab
;
8194 struct plt_entry
*ent
;
8198 /* Massage our args to the form they really have. */
8199 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8202 htab
= ppc_hash_table (info
);
8204 /* Make a note of the offset within the stubs for this entry. */
8205 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
8206 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
8208 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
8209 switch (stub_entry
->stub_type
)
8211 case ppc_stub_long_branch
:
8212 case ppc_stub_long_branch_r2off
:
8213 /* Branches are relative. This is where we are going to. */
8214 off
= dest
= (stub_entry
->target_value
8215 + stub_entry
->target_section
->output_offset
8216 + stub_entry
->target_section
->output_section
->vma
);
8218 /* And this is where we are coming from. */
8219 off
-= (stub_entry
->stub_offset
8220 + stub_entry
->stub_sec
->output_offset
8221 + stub_entry
->stub_sec
->output_section
->vma
);
8223 if (stub_entry
->stub_type
!= ppc_stub_long_branch_r2off
)
8229 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8230 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8231 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8233 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8235 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8240 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
8242 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8244 (*_bfd_error_handler
) (_("long branch stub `%s' offset overflow"),
8245 stub_entry
->root
.string
);
8246 htab
->stub_error
= TRUE
;
8250 if (info
->emitrelocations
)
8252 Elf_Internal_Rela
*relocs
, *r
;
8253 struct bfd_elf_section_data
*elfsec_data
;
8255 elfsec_data
= elf_section_data (stub_entry
->stub_sec
);
8256 relocs
= elfsec_data
->relocs
;
8259 bfd_size_type relsize
;
8260 relsize
= stub_entry
->stub_sec
->reloc_count
* sizeof (*relocs
);
8261 relocs
= bfd_alloc (htab
->stub_bfd
, relsize
);
8264 elfsec_data
->relocs
= relocs
;
8265 elfsec_data
->rel_hdr
.sh_size
= relsize
;
8266 elfsec_data
->rel_hdr
.sh_entsize
= 24;
8267 stub_entry
->stub_sec
->reloc_count
= 0;
8269 r
= relocs
+ stub_entry
->stub_sec
->reloc_count
;
8270 stub_entry
->stub_sec
->reloc_count
+= 1;
8271 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
8272 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
8274 if (stub_entry
->h
!= NULL
)
8276 struct elf_link_hash_entry
**hashes
;
8277 unsigned long symndx
;
8278 struct ppc_link_hash_entry
*h
;
8280 hashes
= elf_sym_hashes (htab
->stub_bfd
);
8283 bfd_size_type hsize
;
8285 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
8286 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
8289 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
8290 htab
->stub_globals
= 1;
8292 symndx
= htab
->stub_globals
++;
8294 hashes
[symndx
] = &h
->elf
;
8295 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
8296 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
8298 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
8299 /* H is an opd symbol. The addend must be zero. */
8303 off
= (h
->elf
.root
.u
.def
.value
8304 + h
->elf
.root
.u
.def
.section
->output_offset
8305 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
8312 case ppc_stub_plt_branch
:
8313 case ppc_stub_plt_branch_r2off
:
8314 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8315 stub_entry
->root
.string
+ 9,
8317 if (br_entry
== NULL
)
8319 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
8320 stub_entry
->root
.string
);
8321 htab
->stub_error
= TRUE
;
8325 off
= (stub_entry
->target_value
8326 + stub_entry
->target_section
->output_offset
8327 + stub_entry
->target_section
->output_section
->vma
);
8329 bfd_put_64 (htab
->brlt
->owner
, off
,
8330 htab
->brlt
->contents
+ br_entry
->offset
);
8332 if (htab
->relbrlt
!= NULL
)
8334 /* Create a reloc for the branch lookup table entry. */
8335 Elf_Internal_Rela rela
;
8338 rela
.r_offset
= (br_entry
->offset
8339 + htab
->brlt
->output_offset
8340 + htab
->brlt
->output_section
->vma
);
8341 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8342 rela
.r_addend
= off
;
8344 rl
= htab
->relbrlt
->contents
;
8345 rl
+= htab
->relbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8346 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
8349 off
= (br_entry
->offset
8350 + htab
->brlt
->output_offset
8351 + htab
->brlt
->output_section
->vma
8352 - elf_gp (htab
->brlt
->output_section
->owner
)
8353 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8355 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8357 (*_bfd_error_handler
)
8358 (_("linkage table error against `%s'"),
8359 stub_entry
->root
.string
);
8360 bfd_set_error (bfd_error_bad_value
);
8361 htab
->stub_error
= TRUE
;
8366 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
8368 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8370 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8377 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8378 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8379 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8381 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8383 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8385 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8387 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8391 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
8393 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
8396 case ppc_stub_plt_call
:
8397 /* Do the best we can for shared libraries built without
8398 exporting ".foo" for each "foo". This can happen when symbol
8399 versioning scripts strip all bar a subset of symbols. */
8400 if (stub_entry
->h
->oh
!= NULL
8401 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defined
8402 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8404 /* Point the symbol at the stub. There may be multiple stubs,
8405 we don't really care; The main thing is to make this sym
8406 defined somewhere. Maybe defining the symbol in the stub
8407 section is a silly idea. If we didn't do this, htab->top_id
8409 stub_entry
->h
->oh
->elf
.root
.type
= bfd_link_hash_defined
;
8410 stub_entry
->h
->oh
->elf
.root
.u
.def
.section
= stub_entry
->stub_sec
;
8411 stub_entry
->h
->oh
->elf
.root
.u
.def
.value
= stub_entry
->stub_offset
;
8414 /* Now build the stub. */
8416 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8417 if (ent
->addend
== stub_entry
->addend
)
8419 off
= ent
->plt
.offset
;
8422 if (off
>= (bfd_vma
) -2)
8425 off
&= ~ (bfd_vma
) 1;
8426 off
+= (htab
->plt
->output_offset
8427 + htab
->plt
->output_section
->vma
8428 - elf_gp (htab
->plt
->output_section
->owner
)
8429 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8431 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8433 (*_bfd_error_handler
)
8434 (_("linkage table error against `%s'"),
8435 stub_entry
->h
->elf
.root
.root
.string
);
8436 bfd_set_error (bfd_error_bad_value
);
8437 htab
->stub_error
= TRUE
;
8441 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
);
8450 stub_entry
->stub_sec
->size
+= size
;
8452 if (htab
->emit_stub_syms
)
8454 struct elf_link_hash_entry
*h
;
8457 const char *const stub_str
[] = { "long_branch",
8458 "long_branch_r2off",
8463 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
8464 len2
= strlen (stub_entry
->root
.string
);
8465 name
= bfd_malloc (len1
+ len2
+ 2);
8468 memcpy (name
, stub_entry
->root
.string
, 9);
8469 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
8470 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
8471 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
8474 if (h
->root
.type
== bfd_link_hash_new
)
8476 h
->root
.type
= bfd_link_hash_defined
;
8477 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
8478 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
8481 h
->ref_regular_nonweak
= 1;
8482 h
->forced_local
= 1;
8490 /* As above, but don't actually build the stub. Just bump offset so
8491 we know stub section sizes, and select plt_branch stubs where
8492 long_branch stubs won't do. */
8495 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8497 struct ppc_stub_hash_entry
*stub_entry
;
8498 struct bfd_link_info
*info
;
8499 struct ppc_link_hash_table
*htab
;
8503 /* Massage our args to the form they really have. */
8504 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8507 htab
= ppc_hash_table (info
);
8509 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
8511 struct plt_entry
*ent
;
8513 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8514 if (ent
->addend
== stub_entry
->addend
)
8516 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
8519 if (off
>= (bfd_vma
) -2)
8521 off
+= (htab
->plt
->output_offset
8522 + htab
->plt
->output_section
->vma
8523 - elf_gp (htab
->plt
->output_section
->owner
)
8524 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8526 size
= PLT_CALL_STUB_SIZE
;
8527 if (PPC_HA (off
+ 16) != PPC_HA (off
))
8532 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
8534 off
= (stub_entry
->target_value
8535 + stub_entry
->target_section
->output_offset
8536 + stub_entry
->target_section
->output_section
->vma
);
8537 off
-= (stub_entry
->stub_sec
->size
8538 + stub_entry
->stub_sec
->output_offset
8539 + stub_entry
->stub_sec
->output_section
->vma
);
8541 /* Reset the stub type from the plt variant in case we now
8542 can reach with a shorter stub. */
8543 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
8544 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
8547 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
8553 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
8554 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8556 struct ppc_branch_hash_entry
*br_entry
;
8558 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8559 stub_entry
->root
.string
+ 9,
8561 if (br_entry
== NULL
)
8563 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
8564 stub_entry
->root
.string
);
8565 htab
->stub_error
= TRUE
;
8569 if (br_entry
->iter
!= htab
->stub_iteration
)
8571 br_entry
->iter
= htab
->stub_iteration
;
8572 br_entry
->offset
= htab
->brlt
->size
;
8573 htab
->brlt
->size
+= 8;
8575 if (htab
->relbrlt
!= NULL
)
8576 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
8579 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
8581 if (stub_entry
->stub_type
!= ppc_stub_plt_branch
)
8585 if (info
->emitrelocations
8586 && (stub_entry
->stub_type
== ppc_stub_long_branch
8587 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
8588 stub_entry
->stub_sec
->reloc_count
+= 1;
8591 stub_entry
->stub_sec
->size
+= size
;
8595 /* Set up various things so that we can make a list of input sections
8596 for each output section included in the link. Returns -1 on error,
8597 0 when no stubs will be needed, and 1 on success. */
8600 ppc64_elf_setup_section_lists (bfd
*output_bfd
,
8601 struct bfd_link_info
*info
,
8605 int top_id
, top_index
, id
;
8607 asection
**input_list
;
8609 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8611 htab
->no_multi_toc
= no_multi_toc
;
8613 if (htab
->brlt
== NULL
)
8616 /* Find the top input section id. */
8617 for (input_bfd
= info
->input_bfds
, top_id
= 3;
8619 input_bfd
= input_bfd
->link_next
)
8621 for (section
= input_bfd
->sections
;
8623 section
= section
->next
)
8625 if (top_id
< section
->id
)
8626 top_id
= section
->id
;
8630 htab
->top_id
= top_id
;
8631 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
8632 htab
->stub_group
= bfd_zmalloc (amt
);
8633 if (htab
->stub_group
== NULL
)
8636 /* Set toc_off for com, und, abs and ind sections. */
8637 for (id
= 0; id
< 3; id
++)
8638 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
8640 elf_gp (output_bfd
) = htab
->toc_curr
= ppc64_elf_toc (output_bfd
);
8642 /* We can't use output_bfd->section_count here to find the top output
8643 section index as some sections may have been removed, and
8644 strip_excluded_output_sections doesn't renumber the indices. */
8645 for (section
= output_bfd
->sections
, top_index
= 0;
8647 section
= section
->next
)
8649 if (top_index
< section
->index
)
8650 top_index
= section
->index
;
8653 htab
->top_index
= top_index
;
8654 amt
= sizeof (asection
*) * (top_index
+ 1);
8655 input_list
= bfd_zmalloc (amt
);
8656 htab
->input_list
= input_list
;
8657 if (input_list
== NULL
)
8663 /* The linker repeatedly calls this function for each TOC input section
8664 and linker generated GOT section. Group input bfds such that the toc
8665 within a group is less than 64k in size. Will break with cute linker
8666 scripts that play games with dot in the output toc section. */
8669 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
8671 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8673 if (!htab
->no_multi_toc
)
8675 bfd_vma addr
= isec
->output_offset
+ isec
->output_section
->vma
;
8676 bfd_vma off
= addr
- htab
->toc_curr
;
8678 if (off
+ isec
->size
> 0x10000)
8679 htab
->toc_curr
= addr
;
8681 elf_gp (isec
->owner
) = (htab
->toc_curr
8682 - elf_gp (isec
->output_section
->owner
)
8687 /* Called after the last call to the above function. */
8690 ppc64_elf_reinit_toc (bfd
*output_bfd
, struct bfd_link_info
*info
)
8692 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8694 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (output_bfd
);
8696 /* toc_curr tracks the TOC offset used for code sections below in
8697 ppc64_elf_next_input_section. Start off at 0x8000. */
8698 htab
->toc_curr
= TOC_BASE_OFF
;
8701 /* No toc references were found in ISEC. If the code in ISEC makes no
8702 calls, then there's no need to use toc adjusting stubs when branching
8703 into ISEC. Actually, indirect calls from ISEC are OK as they will
8704 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
8705 needed, and 2 if a cyclical call-graph was found but no other reason
8706 for a stub was detected. If called from the top level, a return of
8707 2 means the same as a return of 0. */
8710 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
8712 Elf_Internal_Rela
*relstart
, *rel
;
8713 Elf_Internal_Sym
*local_syms
;
8715 struct ppc_link_hash_table
*htab
;
8717 /* We know none of our code bearing sections will need toc stubs. */
8718 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
8721 if (isec
->size
== 0)
8724 if (isec
->output_section
== NULL
)
8727 /* Hack for linux kernel. .fixup contains branches, but only back to
8728 the function that hit an exception. */
8729 if (strcmp (isec
->name
, ".fixup") == 0)
8732 if (isec
->reloc_count
== 0)
8735 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
8737 if (relstart
== NULL
)
8740 /* Look for branches to outside of this section. */
8743 htab
= ppc_hash_table (info
);
8744 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
8746 enum elf_ppc64_reloc_type r_type
;
8747 unsigned long r_symndx
;
8748 struct elf_link_hash_entry
*h
;
8749 Elf_Internal_Sym
*sym
;
8755 r_type
= ELF64_R_TYPE (rel
->r_info
);
8756 if (r_type
!= R_PPC64_REL24
8757 && r_type
!= R_PPC64_REL14
8758 && r_type
!= R_PPC64_REL14_BRTAKEN
8759 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
8762 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8763 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
8770 /* Calls to dynamic lib functions go through a plt call stub
8771 that uses r2. Branches to undefined symbols might be a call
8772 using old-style dot symbols that can be satisfied by a plt
8773 call into a new-style dynamic library. */
8774 if (sym_sec
== NULL
)
8776 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8779 && eh
->oh
->elf
.plt
.plist
!= NULL
)
8785 /* Ignore other undefined symbols. */
8789 /* Assume branches to other sections not included in the link need
8790 stubs too, to cover -R and absolute syms. */
8791 if (sym_sec
->output_section
== NULL
)
8798 sym_value
= sym
->st_value
;
8801 if (h
->root
.type
!= bfd_link_hash_defined
8802 && h
->root
.type
!= bfd_link_hash_defweak
)
8804 sym_value
= h
->root
.u
.def
.value
;
8806 sym_value
+= rel
->r_addend
;
8808 /* If this branch reloc uses an opd sym, find the code section. */
8809 opd_adjust
= get_opd_info (sym_sec
);
8810 if (opd_adjust
!= NULL
)
8816 adjust
= opd_adjust
[sym
->st_value
/ 8];
8818 /* Assume deleted functions won't ever be called. */
8820 sym_value
+= adjust
;
8823 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
8824 if (dest
== (bfd_vma
) -1)
8829 + sym_sec
->output_offset
8830 + sym_sec
->output_section
->vma
);
8832 /* Ignore branch to self. */
8833 if (sym_sec
== isec
)
8836 /* If the called function uses the toc, we need a stub. */
8837 if (sym_sec
->has_toc_reloc
8838 || sym_sec
->makes_toc_func_call
)
8844 /* Assume any branch that needs a long branch stub might in fact
8845 need a plt_branch stub. A plt_branch stub uses r2. */
8846 else if (dest
- (isec
->output_offset
8847 + isec
->output_section
->vma
8848 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
8854 /* If calling back to a section in the process of being tested, we
8855 can't say for sure that no toc adjusting stubs are needed, so
8856 don't return zero. */
8857 else if (sym_sec
->call_check_in_progress
)
8860 /* Branches to another section that itself doesn't have any TOC
8861 references are OK. Recursively call ourselves to check. */
8862 else if (sym_sec
->id
<= htab
->top_id
8863 && htab
->stub_group
[sym_sec
->id
].toc_off
== 0)
8867 /* Mark current section as indeterminate, so that other
8868 sections that call back to current won't be marked as
8870 isec
->call_check_in_progress
= 1;
8871 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
8872 isec
->call_check_in_progress
= 0;
8876 /* An error. Exit. */
8880 else if (recur
<= 1)
8882 /* Known result. Mark as checked and set section flag. */
8883 htab
->stub_group
[sym_sec
->id
].toc_off
= 1;
8886 sym_sec
->makes_toc_func_call
= 1;
8893 /* Unknown result. Continue checking. */
8899 if (local_syms
!= NULL
8900 && (elf_tdata (isec
->owner
)->symtab_hdr
.contents
8901 != (unsigned char *) local_syms
))
8903 if (elf_section_data (isec
)->relocs
!= relstart
)
8909 /* The linker repeatedly calls this function for each input section,
8910 in the order that input sections are linked into output sections.
8911 Build lists of input sections to determine groupings between which
8912 we may insert linker stubs. */
8915 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
8917 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8919 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
8920 && isec
->output_section
->index
<= htab
->top_index
)
8922 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
8923 /* Steal the link_sec pointer for our list. */
8924 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
8925 /* This happens to make the list in reverse order,
8926 which is what we want. */
8927 PREV_SEC (isec
) = *list
;
8931 if (htab
->multi_toc_needed
)
8933 /* If a code section has a function that uses the TOC then we need
8934 to use the right TOC (obviously). Also, make sure that .opd gets
8935 the correct TOC value for R_PPC64_TOC relocs that don't have or
8936 can't find their function symbol (shouldn't ever happen now). */
8937 if (isec
->has_toc_reloc
|| (isec
->flags
& SEC_CODE
) == 0)
8939 if (elf_gp (isec
->owner
) != 0)
8940 htab
->toc_curr
= elf_gp (isec
->owner
);
8942 else if (htab
->stub_group
[isec
->id
].toc_off
== 0)
8944 int ret
= toc_adjusting_stub_needed (info
, isec
);
8948 isec
->makes_toc_func_call
= ret
& 1;
8952 /* Functions that don't use the TOC can belong in any TOC group.
8953 Use the last TOC base. This happens to make _init and _fini
8955 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
8959 /* See whether we can group stub sections together. Grouping stub
8960 sections may result in fewer stubs. More importantly, we need to
8961 put all .init* and .fini* stubs at the beginning of the .init or
8962 .fini output sections respectively, because glibc splits the
8963 _init and _fini functions into multiple parts. Putting a stub in
8964 the middle of a function is not a good idea. */
8967 group_sections (struct ppc_link_hash_table
*htab
,
8968 bfd_size_type stub_group_size
,
8969 bfd_boolean stubs_always_before_branch
)
8972 bfd_size_type stub14_group_size
;
8973 bfd_boolean suppress_size_errors
;
8975 suppress_size_errors
= FALSE
;
8976 stub14_group_size
= stub_group_size
;
8977 if (stub_group_size
== 1)
8979 /* Default values. */
8980 if (stubs_always_before_branch
)
8982 stub_group_size
= 0x1e00000;
8983 stub14_group_size
= 0x7800;
8987 stub_group_size
= 0x1c00000;
8988 stub14_group_size
= 0x7000;
8990 suppress_size_errors
= TRUE
;
8993 list
= htab
->input_list
+ htab
->top_index
;
8996 asection
*tail
= *list
;
8997 while (tail
!= NULL
)
9001 bfd_size_type total
;
9002 bfd_boolean big_sec
;
9007 big_sec
= total
> (ppc64_elf_section_data (tail
)->has_14bit_branch
9008 ? stub14_group_size
: stub_group_size
);
9009 if (big_sec
&& !suppress_size_errors
)
9010 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
9012 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
9014 while ((prev
= PREV_SEC (curr
)) != NULL
9015 && ((total
+= curr
->output_offset
- prev
->output_offset
)
9016 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9017 ? stub14_group_size
: stub_group_size
))
9018 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9021 /* OK, the size from the start of CURR to the end is less
9022 than stub_group_size and thus can be handled by one stub
9023 section. (or the tail section is itself larger than
9024 stub_group_size, in which case we may be toast.) We
9025 should really be keeping track of the total size of stubs
9026 added here, as stubs contribute to the final output
9027 section size. That's a little tricky, and this way will
9028 only break if stubs added make the total size more than
9029 2^25, ie. for the default stub_group_size, if stubs total
9030 more than 2097152 bytes, or nearly 75000 plt call stubs. */
9033 prev
= PREV_SEC (tail
);
9034 /* Set up this stub group. */
9035 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9037 while (tail
!= curr
&& (tail
= prev
) != NULL
);
9039 /* But wait, there's more! Input sections up to stub_group_size
9040 bytes before the stub section can be handled by it too.
9041 Don't do this if we have a really large section after the
9042 stubs, as adding more stubs increases the chance that
9043 branches may not reach into the stub section. */
9044 if (!stubs_always_before_branch
&& !big_sec
)
9048 && ((total
+= tail
->output_offset
- prev
->output_offset
)
9049 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9050 ? stub14_group_size
: stub_group_size
))
9051 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9054 prev
= PREV_SEC (tail
);
9055 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9061 while (list
-- != htab
->input_list
);
9062 free (htab
->input_list
);
9066 /* Determine and set the size of the stub section for a final link.
9068 The basic idea here is to examine all the relocations looking for
9069 PC-relative calls to a target that is unreachable with a "bl"
9073 ppc64_elf_size_stubs (bfd
*output_bfd
,
9074 struct bfd_link_info
*info
,
9075 bfd_signed_vma group_size
,
9076 asection
*(*add_stub_section
) (const char *, asection
*),
9077 void (*layout_sections_again
) (void))
9079 bfd_size_type stub_group_size
;
9080 bfd_boolean stubs_always_before_branch
;
9081 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9083 /* Stash our params away. */
9084 htab
->add_stub_section
= add_stub_section
;
9085 htab
->layout_sections_again
= layout_sections_again
;
9086 stubs_always_before_branch
= group_size
< 0;
9088 stub_group_size
= -group_size
;
9090 stub_group_size
= group_size
;
9092 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
9097 unsigned int bfd_indx
;
9100 htab
->stub_iteration
+= 1;
9102 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
9104 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
9106 Elf_Internal_Shdr
*symtab_hdr
;
9108 Elf_Internal_Sym
*local_syms
= NULL
;
9110 if (!is_ppc64_elf_target (input_bfd
->xvec
))
9113 /* We'll need the symbol table in a second. */
9114 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9115 if (symtab_hdr
->sh_info
== 0)
9118 /* Walk over each section attached to the input bfd. */
9119 for (section
= input_bfd
->sections
;
9121 section
= section
->next
)
9123 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
9125 /* If there aren't any relocs, then there's nothing more
9127 if ((section
->flags
& SEC_RELOC
) == 0
9128 || (section
->flags
& SEC_ALLOC
) == 0
9129 || (section
->flags
& SEC_LOAD
) == 0
9130 || (section
->flags
& SEC_CODE
) == 0
9131 || section
->reloc_count
== 0)
9134 /* If this section is a link-once section that will be
9135 discarded, then don't create any stubs. */
9136 if (section
->output_section
== NULL
9137 || section
->output_section
->owner
!= output_bfd
)
9140 /* Get the relocs. */
9142 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
9144 if (internal_relocs
== NULL
)
9145 goto error_ret_free_local
;
9147 /* Now examine each relocation. */
9148 irela
= internal_relocs
;
9149 irelaend
= irela
+ section
->reloc_count
;
9150 for (; irela
< irelaend
; irela
++)
9152 enum elf_ppc64_reloc_type r_type
;
9153 unsigned int r_indx
;
9154 enum ppc_stub_type stub_type
;
9155 struct ppc_stub_hash_entry
*stub_entry
;
9156 asection
*sym_sec
, *code_sec
;
9158 bfd_vma destination
;
9159 bfd_boolean ok_dest
;
9160 struct ppc_link_hash_entry
*hash
;
9161 struct ppc_link_hash_entry
*fdh
;
9162 struct elf_link_hash_entry
*h
;
9163 Elf_Internal_Sym
*sym
;
9165 const asection
*id_sec
;
9168 r_type
= ELF64_R_TYPE (irela
->r_info
);
9169 r_indx
= ELF64_R_SYM (irela
->r_info
);
9171 if (r_type
>= R_PPC64_max
)
9173 bfd_set_error (bfd_error_bad_value
);
9174 goto error_ret_free_internal
;
9177 /* Only look for stubs on branch instructions. */
9178 if (r_type
!= R_PPC64_REL24
9179 && r_type
!= R_PPC64_REL14
9180 && r_type
!= R_PPC64_REL14_BRTAKEN
9181 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
9184 /* Now determine the call target, its name, value,
9186 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9188 goto error_ret_free_internal
;
9189 hash
= (struct ppc_link_hash_entry
*) h
;
9196 sym_value
= sym
->st_value
;
9199 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
9200 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
9202 sym_value
= hash
->elf
.root
.u
.def
.value
;
9203 if (sym_sec
->output_section
!= NULL
)
9206 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
9207 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
9209 /* Recognise an old ABI func code entry sym, and
9210 use the func descriptor sym instead if it is
9212 if (hash
->elf
.root
.root
.string
[0] == '.'
9213 && (fdh
= get_fdh (hash
, htab
)) != NULL
)
9215 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
9216 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
9218 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
9219 sym_value
= fdh
->elf
.root
.u
.def
.value
;
9220 if (sym_sec
->output_section
!= NULL
)
9229 bfd_set_error (bfd_error_bad_value
);
9230 goto error_ret_free_internal
;
9236 sym_value
+= irela
->r_addend
;
9237 destination
= (sym_value
9238 + sym_sec
->output_offset
9239 + sym_sec
->output_section
->vma
);
9243 opd_adjust
= get_opd_info (sym_sec
);
9244 if (opd_adjust
!= NULL
)
9250 long adjust
= opd_adjust
[sym_value
/ 8];
9253 sym_value
+= adjust
;
9255 dest
= opd_entry_value (sym_sec
, sym_value
,
9256 &code_sec
, &sym_value
);
9257 if (dest
!= (bfd_vma
) -1)
9262 /* Fixup old ABI sym to point at code
9264 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
9265 hash
->elf
.root
.u
.def
.section
= code_sec
;
9266 hash
->elf
.root
.u
.def
.value
= sym_value
;
9271 /* Determine what (if any) linker stub is needed. */
9272 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
9275 if (stub_type
!= ppc_stub_plt_call
)
9277 /* Check whether we need a TOC adjusting stub.
9278 Since the linker pastes together pieces from
9279 different object files when creating the
9280 _init and _fini functions, it may be that a
9281 call to what looks like a local sym is in
9282 fact a call needing a TOC adjustment. */
9283 if (code_sec
!= NULL
9284 && code_sec
->output_section
!= NULL
9285 && (htab
->stub_group
[code_sec
->id
].toc_off
9286 != htab
->stub_group
[section
->id
].toc_off
)
9287 && (code_sec
->has_toc_reloc
9288 || code_sec
->makes_toc_func_call
))
9289 stub_type
= ppc_stub_long_branch_r2off
;
9292 if (stub_type
== ppc_stub_none
)
9295 /* __tls_get_addr calls might be eliminated. */
9296 if (stub_type
!= ppc_stub_plt_call
9298 && (hash
== htab
->tls_get_addr
9299 || hash
== htab
->tls_get_addr_fd
)
9300 && section
->has_tls_reloc
9301 && irela
!= internal_relocs
)
9306 if (!get_tls_mask (&tls_mask
, NULL
, &local_syms
,
9307 irela
- 1, input_bfd
))
9308 goto error_ret_free_internal
;
9313 /* Support for grouping stub sections. */
9314 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
9316 /* Get the name of this stub. */
9317 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
9319 goto error_ret_free_internal
;
9321 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
9322 stub_name
, FALSE
, FALSE
);
9323 if (stub_entry
!= NULL
)
9325 /* The proper stub has already been created. */
9330 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
9331 if (stub_entry
== NULL
)
9334 error_ret_free_internal
:
9335 if (elf_section_data (section
)->relocs
== NULL
)
9336 free (internal_relocs
);
9337 error_ret_free_local
:
9338 if (local_syms
!= NULL
9339 && (symtab_hdr
->contents
9340 != (unsigned char *) local_syms
))
9345 stub_entry
->stub_type
= stub_type
;
9346 stub_entry
->target_value
= sym_value
;
9347 stub_entry
->target_section
= code_sec
;
9348 stub_entry
->h
= hash
;
9349 stub_entry
->addend
= irela
->r_addend
;
9351 if (stub_entry
->h
!= NULL
)
9352 htab
->stub_globals
+= 1;
9355 /* We're done with the internal relocs, free them. */
9356 if (elf_section_data (section
)->relocs
!= internal_relocs
)
9357 free (internal_relocs
);
9360 if (local_syms
!= NULL
9361 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9363 if (!info
->keep_memory
)
9366 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9370 /* We may have added some stubs. Find out the new size of the
9372 for (stub_sec
= htab
->stub_bfd
->sections
;
9374 stub_sec
= stub_sec
->next
)
9375 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9377 stub_sec
->rawsize
= stub_sec
->size
;
9379 stub_sec
->reloc_count
= 0;
9382 htab
->brlt
->size
= 0;
9383 if (htab
->relbrlt
!= NULL
)
9384 htab
->relbrlt
->size
= 0;
9386 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
9388 for (stub_sec
= htab
->stub_bfd
->sections
;
9390 stub_sec
= stub_sec
->next
)
9391 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9392 && stub_sec
->rawsize
!= stub_sec
->size
)
9395 /* Exit from this loop when no stubs have been added, and no stubs
9396 have changed size. */
9397 if (stub_sec
== NULL
)
9400 /* Ask the linker to do its stuff. */
9401 (*htab
->layout_sections_again
) ();
9404 /* It would be nice to strip htab->brlt from the output if the
9405 section is empty, but it's too late. If we strip sections here,
9406 the dynamic symbol table is corrupted since the section symbol
9407 for the stripped section isn't written. */
9412 /* Called after we have determined section placement. If sections
9413 move, we'll be called again. Provide a value for TOCstart. */
9416 ppc64_elf_toc (bfd
*obfd
)
9421 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
9422 order. The TOC starts where the first of these sections starts. */
9423 s
= bfd_get_section_by_name (obfd
, ".got");
9425 s
= bfd_get_section_by_name (obfd
, ".toc");
9427 s
= bfd_get_section_by_name (obfd
, ".tocbss");
9429 s
= bfd_get_section_by_name (obfd
, ".plt");
9432 /* This may happen for
9433 o references to TOC base (SYM@toc / TOC[tc0]) without a
9436 o --gc-sections and empty TOC sections
9438 FIXME: Warn user? */
9440 /* Look for a likely section. We probably won't even be
9442 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9443 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
9444 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9447 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9448 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
9449 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9452 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9453 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
9456 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9457 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
9463 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
9468 /* Build all the stubs associated with the current output file.
9469 The stubs are kept in a hash table attached to the main linker
9470 hash table. This function is called via gldelf64ppc_finish. */
9473 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
9474 struct bfd_link_info
*info
,
9477 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9480 int stub_sec_count
= 0;
9482 htab
->emit_stub_syms
= emit_stub_syms
;
9484 /* Allocate memory to hold the linker stubs. */
9485 for (stub_sec
= htab
->stub_bfd
->sections
;
9487 stub_sec
= stub_sec
->next
)
9488 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9489 && stub_sec
->size
!= 0)
9491 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
9492 if (stub_sec
->contents
== NULL
)
9494 /* We want to check that built size is the same as calculated
9495 size. rawsize is a convenient location to use. */
9496 stub_sec
->rawsize
= stub_sec
->size
;
9500 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
9505 /* Build the .glink plt call stub. */
9506 if (htab
->emit_stub_syms
)
9508 struct elf_link_hash_entry
*h
;
9509 h
= elf_link_hash_lookup (&htab
->elf
, "__glink", TRUE
, FALSE
, FALSE
);
9512 if (h
->root
.type
== bfd_link_hash_new
)
9514 h
->root
.type
= bfd_link_hash_defined
;
9515 h
->root
.u
.def
.section
= htab
->glink
;
9516 h
->root
.u
.def
.value
= 8;
9519 h
->ref_regular_nonweak
= 1;
9520 h
->forced_local
= 1;
9524 p
= htab
->glink
->contents
;
9525 plt0
= (htab
->plt
->output_section
->vma
9526 + htab
->plt
->output_offset
9527 - (htab
->glink
->output_section
->vma
9528 + htab
->glink
->output_offset
9530 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
9532 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
9534 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
9536 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
9538 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
9540 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
9542 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
9544 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
9546 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
9548 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
9550 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
9552 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
9554 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
9556 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
9560 /* Build the .glink lazy link call stubs. */
9562 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
9566 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
9571 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
9573 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
9576 bfd_put_32 (htab
->glink
->owner
,
9577 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
9581 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
9584 if (htab
->brlt
->size
!= 0)
9586 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
9588 if (htab
->brlt
->contents
== NULL
)
9591 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
9593 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
9594 htab
->relbrlt
->size
);
9595 if (htab
->relbrlt
->contents
== NULL
)
9599 /* Build the stubs as directed by the stub hash table. */
9600 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
9602 if (htab
->relbrlt
!= NULL
)
9603 htab
->relbrlt
->reloc_count
= 0;
9605 for (stub_sec
= htab
->stub_bfd
->sections
;
9607 stub_sec
= stub_sec
->next
)
9608 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9610 stub_sec_count
+= 1;
9611 if (stub_sec
->rawsize
!= stub_sec
->size
)
9615 if (stub_sec
!= NULL
9616 || htab
->glink
->rawsize
!= htab
->glink
->size
)
9618 htab
->stub_error
= TRUE
;
9619 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
9622 if (htab
->stub_error
)
9627 *stats
= bfd_malloc (500);
9631 sprintf (*stats
, _("linker stubs in %u group%s\n"
9634 " long branch %lu\n"
9635 " long toc adj %lu\n"
9638 stub_sec_count
== 1 ? "" : "s",
9639 htab
->stub_count
[ppc_stub_long_branch
- 1],
9640 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
9641 htab
->stub_count
[ppc_stub_plt_branch
- 1],
9642 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
9643 htab
->stub_count
[ppc_stub_plt_call
- 1]);
9648 /* This function undoes the changes made by add_symbol_adjust. */
9651 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
9653 struct ppc_link_hash_entry
*eh
;
9655 if (h
->root
.type
== bfd_link_hash_indirect
)
9658 if (h
->root
.type
== bfd_link_hash_warning
)
9659 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9661 eh
= (struct ppc_link_hash_entry
*) h
;
9662 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
9665 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
9670 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
9672 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9673 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
9676 /* What to do when ld finds relocations against symbols defined in
9677 discarded sections. */
9680 ppc64_elf_action_discarded (asection
*sec
)
9682 if (strcmp (".opd", sec
->name
) == 0)
9685 if (strcmp (".toc", sec
->name
) == 0)
9688 if (strcmp (".toc1", sec
->name
) == 0)
9691 return _bfd_elf_default_action_discarded (sec
);
9694 /* The RELOCATE_SECTION function is called by the ELF backend linker
9695 to handle the relocations for a section.
9697 The relocs are always passed as Rela structures; if the section
9698 actually uses Rel structures, the r_addend field will always be
9701 This function is responsible for adjust the section contents as
9702 necessary, and (if using Rela relocs and generating a
9703 relocatable output file) adjusting the reloc addend as
9706 This function does not have to worry about setting the reloc
9707 address or the reloc symbol index.
9709 LOCAL_SYMS is a pointer to the swapped in local symbols.
9711 LOCAL_SECTIONS is an array giving the section in the input file
9712 corresponding to the st_shndx field of each local symbol.
9714 The global hash table entry for the global symbols can be found
9715 via elf_sym_hashes (input_bfd).
9717 When generating relocatable output, this function must handle
9718 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
9719 going to be the section symbol corresponding to the output
9720 section, which means that the addend must be adjusted
9724 ppc64_elf_relocate_section (bfd
*output_bfd
,
9725 struct bfd_link_info
*info
,
9727 asection
*input_section
,
9729 Elf_Internal_Rela
*relocs
,
9730 Elf_Internal_Sym
*local_syms
,
9731 asection
**local_sections
)
9733 struct ppc_link_hash_table
*htab
;
9734 Elf_Internal_Shdr
*symtab_hdr
;
9735 struct elf_link_hash_entry
**sym_hashes
;
9736 Elf_Internal_Rela
*rel
;
9737 Elf_Internal_Rela
*relend
;
9738 Elf_Internal_Rela outrel
;
9740 struct got_entry
**local_got_ents
;
9742 bfd_boolean ret
= TRUE
;
9744 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
9745 bfd_boolean is_power4
= FALSE
;
9746 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
9748 /* Initialize howto table if needed. */
9749 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9752 htab
= ppc_hash_table (info
);
9754 /* Don't relocate stub sections. */
9755 if (input_section
->owner
== htab
->stub_bfd
)
9758 local_got_ents
= elf_local_got_ents (input_bfd
);
9759 TOCstart
= elf_gp (output_bfd
);
9760 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9761 sym_hashes
= elf_sym_hashes (input_bfd
);
9762 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
9765 relend
= relocs
+ input_section
->reloc_count
;
9766 for (; rel
< relend
; rel
++)
9768 enum elf_ppc64_reloc_type r_type
;
9769 bfd_vma addend
, orig_addend
;
9770 bfd_reloc_status_type r
;
9771 Elf_Internal_Sym
*sym
;
9773 struct elf_link_hash_entry
*h_elf
;
9774 struct ppc_link_hash_entry
*h
;
9775 struct ppc_link_hash_entry
*fdh
;
9776 const char *sym_name
;
9777 unsigned long r_symndx
, toc_symndx
;
9778 char tls_mask
, tls_gd
, tls_type
;
9781 bfd_boolean unresolved_reloc
;
9783 unsigned long insn
, mask
;
9784 struct ppc_stub_hash_entry
*stub_entry
;
9785 bfd_vma max_br_offset
;
9788 r_type
= ELF64_R_TYPE (rel
->r_info
);
9789 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9791 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
9792 symbol of the previous ADDR64 reloc. The symbol gives us the
9793 proper TOC base to use. */
9794 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
9796 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
9798 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
9804 unresolved_reloc
= FALSE
;
9806 orig_addend
= rel
->r_addend
;
9808 if (r_symndx
< symtab_hdr
->sh_info
)
9810 /* It's a local symbol. */
9813 sym
= local_syms
+ r_symndx
;
9814 sec
= local_sections
[r_symndx
];
9815 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
9816 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
9817 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
9818 opd_adjust
= get_opd_info (sec
);
9819 if (opd_adjust
!= NULL
)
9821 long adjust
= opd_adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
9826 /* If this is a relocation against the opd section sym
9827 and we have edited .opd, adjust the reloc addend so
9828 that ld -r and ld --emit-relocs output is correct.
9829 If it is a reloc against some other .opd symbol,
9830 then the symbol value will be adjusted later. */
9831 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
9832 rel
->r_addend
+= adjust
;
9834 relocation
+= adjust
;
9837 if (info
->relocatable
)
9842 if (info
->relocatable
)
9844 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
9845 r_symndx
, symtab_hdr
, sym_hashes
,
9846 h_elf
, sec
, relocation
,
9847 unresolved_reloc
, warned
);
9848 sym_name
= h_elf
->root
.root
.string
;
9849 sym_type
= h_elf
->type
;
9851 h
= (struct ppc_link_hash_entry
*) h_elf
;
9853 /* TLS optimizations. Replace instruction sequences and relocs
9854 based on information we collected in tls_optimize. We edit
9855 RELOCS so that --emit-relocs will output something sensible
9856 for the final instruction stream. */
9860 if (IS_PPC64_TLS_RELOC (r_type
))
9863 tls_mask
= h
->tls_mask
;
9864 else if (local_got_ents
!= NULL
)
9867 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
9868 tls_mask
= lgot_masks
[r_symndx
];
9870 if (tls_mask
== 0 && r_type
== R_PPC64_TLS
)
9872 /* Check for toc tls entries. */
9875 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
9880 tls_mask
= *toc_tls
;
9884 /* Check that tls relocs are used with tls syms, and non-tls
9885 relocs are used with non-tls syms. */
9887 && r_type
!= R_PPC64_NONE
9889 || h
->elf
.root
.type
== bfd_link_hash_defined
9890 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
9891 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
9893 if (r_type
== R_PPC64_TLS
&& tls_mask
!= 0)
9894 /* R_PPC64_TLS is OK against a symbol in the TOC. */
9897 (*_bfd_error_handler
)
9898 (sym_type
== STT_TLS
9899 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
9900 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"),
9903 (long) rel
->r_offset
,
9904 ppc64_elf_howto_table
[r_type
]->name
,
9908 /* Ensure reloc mapping code below stays sane. */
9909 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
9910 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
9911 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
9912 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
9913 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
9914 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
9915 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
9916 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
9917 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
9918 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
9927 case R_PPC64_TOC16_LO
:
9928 case R_PPC64_TOC16_DS
:
9929 case R_PPC64_TOC16_LO_DS
:
9931 /* Check for toc tls entries. */
9935 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
9942 tls_mask
= *toc_tls
;
9943 if (r_type
== R_PPC64_TOC16_DS
9944 || r_type
== R_PPC64_TOC16_LO_DS
)
9947 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
9952 /* If we found a GD reloc pair, then we might be
9953 doing a GD->IE transition. */
9956 tls_gd
= TLS_TPRELGD
;
9957 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
9958 goto tls_get_addr_check
;
9960 else if (retval
== 3)
9962 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
9963 goto tls_get_addr_check
;
9970 case R_PPC64_GOT_TPREL16_DS
:
9971 case R_PPC64_GOT_TPREL16_LO_DS
:
9973 && (tls_mask
& TLS_TPREL
) == 0)
9976 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
9978 insn
|= 0x3c0d0000; /* addis 0,13,0 */
9979 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
9980 r_type
= R_PPC64_TPREL16_HA
;
9981 if (toc_symndx
!= 0)
9983 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
9984 /* We changed the symbol. Start over in order to
9985 get h, sym, sec etc. right. */
9990 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
9996 && (tls_mask
& TLS_TPREL
) == 0)
9999 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
10000 if ((insn
& ((0x3f << 26) | (31 << 11)))
10001 == ((31 << 26) | (13 << 11)))
10002 rtra
= insn
& ((1 << 26) - (1 << 16));
10003 else if ((insn
& ((0x3f << 26) | (31 << 16)))
10004 == ((31 << 26) | (13 << 16)))
10005 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
10008 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
10011 else if ((insn
& (31 << 1)) == 23 << 1
10012 && ((insn
& (31 << 6)) < 14 << 6
10013 || ((insn
& (31 << 6)) >= 16 << 6
10014 && (insn
& (31 << 6)) < 24 << 6)))
10015 /* load and store indexed -> dform. */
10016 insn
= (32 | ((insn
>> 6) & 31)) << 26;
10017 else if ((insn
& (31 << 1)) == 21 << 1
10018 && (insn
& (0x1a << 6)) == 0)
10019 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
10020 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
10021 | ((insn
>> 6) & 1));
10022 else if ((insn
& (31 << 1)) == 21 << 1
10023 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
10025 insn
= (58 << 26) | 2;
10029 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10030 /* Was PPC64_TLS which sits on insn boundary, now
10031 PPC64_TPREL16_LO which is at low-order half-word. */
10032 rel
->r_offset
+= d_offset
;
10033 r_type
= R_PPC64_TPREL16_LO
;
10034 if (toc_symndx
!= 0)
10036 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
10037 /* We changed the symbol. Start over in order to
10038 get h, sym, sec etc. right. */
10043 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10047 case R_PPC64_GOT_TLSGD16_HI
:
10048 case R_PPC64_GOT_TLSGD16_HA
:
10049 tls_gd
= TLS_TPRELGD
;
10050 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10054 case R_PPC64_GOT_TLSLD16_HI
:
10055 case R_PPC64_GOT_TLSLD16_HA
:
10056 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10059 if ((tls_mask
& tls_gd
) != 0)
10060 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10061 + R_PPC64_GOT_TPREL16_DS
);
10064 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10065 rel
->r_offset
-= d_offset
;
10066 r_type
= R_PPC64_NONE
;
10068 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10072 case R_PPC64_GOT_TLSGD16
:
10073 case R_PPC64_GOT_TLSGD16_LO
:
10074 tls_gd
= TLS_TPRELGD
;
10075 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10076 goto tls_get_addr_check
;
10079 case R_PPC64_GOT_TLSLD16
:
10080 case R_PPC64_GOT_TLSLD16_LO
:
10081 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10083 tls_get_addr_check
:
10084 if (rel
+ 1 < relend
)
10086 enum elf_ppc64_reloc_type r_type2
;
10087 unsigned long r_symndx2
;
10088 struct elf_link_hash_entry
*h2
;
10089 bfd_vma insn1
, insn2
, insn3
;
10092 /* The next instruction should be a call to
10093 __tls_get_addr. Peek at the reloc to be sure. */
10094 r_type2
= ELF64_R_TYPE (rel
[1].r_info
);
10095 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
10096 if (r_symndx2
< symtab_hdr
->sh_info
10097 || (r_type2
!= R_PPC64_REL14
10098 && r_type2
!= R_PPC64_REL14_BRTAKEN
10099 && r_type2
!= R_PPC64_REL14_BRNTAKEN
10100 && r_type2
!= R_PPC64_REL24
))
10103 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
10104 while (h2
->root
.type
== bfd_link_hash_indirect
10105 || h2
->root
.type
== bfd_link_hash_warning
)
10106 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
10107 if (h2
== NULL
|| (h2
!= &htab
->tls_get_addr
->elf
10108 && h2
!= &htab
->tls_get_addr_fd
->elf
))
10111 /* OK, it checks out. Replace the call. */
10112 offset
= rel
[1].r_offset
;
10113 insn1
= bfd_get_32 (output_bfd
,
10114 contents
+ rel
->r_offset
- d_offset
);
10115 insn3
= bfd_get_32 (output_bfd
,
10116 contents
+ offset
+ 4);
10117 if ((tls_mask
& tls_gd
) != 0)
10120 insn1
&= (1 << 26) - (1 << 2);
10121 insn1
|= 58 << 26; /* ld */
10122 insn2
= 0x7c636a14; /* add 3,3,13 */
10123 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
10124 if ((tls_mask
& TLS_EXPLICIT
) == 0)
10125 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10126 + R_PPC64_GOT_TPREL16_DS
);
10128 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
10129 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10134 insn1
= 0x3c6d0000; /* addis 3,13,0 */
10135 insn2
= 0x38630000; /* addi 3,3,0 */
10138 /* Was an LD reloc. */
10140 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10141 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10143 else if (toc_symndx
!= 0)
10144 r_symndx
= toc_symndx
;
10145 r_type
= R_PPC64_TPREL16_HA
;
10146 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10147 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
10148 R_PPC64_TPREL16_LO
);
10149 rel
[1].r_offset
+= d_offset
;
10152 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
10156 rel
[1].r_offset
+= 4;
10158 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- d_offset
);
10159 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
10160 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
10161 if (tls_gd
== 0 || toc_symndx
!= 0)
10163 /* We changed the symbol. Start over in order
10164 to get h, sym, sec etc. right. */
10172 case R_PPC64_DTPMOD64
:
10173 if (rel
+ 1 < relend
10174 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
10175 && rel
[1].r_offset
== rel
->r_offset
+ 8)
10177 if ((tls_mask
& TLS_GD
) == 0)
10179 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
10180 if ((tls_mask
& TLS_TPRELGD
) != 0)
10181 r_type
= R_PPC64_TPREL64
;
10184 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10185 r_type
= R_PPC64_NONE
;
10187 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10192 if ((tls_mask
& TLS_LD
) == 0)
10194 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10195 r_type
= R_PPC64_NONE
;
10196 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10201 case R_PPC64_TPREL64
:
10202 if ((tls_mask
& TLS_TPREL
) == 0)
10204 r_type
= R_PPC64_NONE
;
10205 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10210 /* Handle other relocations that tweak non-addend part of insn. */
10212 max_br_offset
= 1 << 25;
10213 addend
= rel
->r_addend
;
10219 /* Branch taken prediction relocations. */
10220 case R_PPC64_ADDR14_BRTAKEN
:
10221 case R_PPC64_REL14_BRTAKEN
:
10222 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
10225 /* Branch not taken prediction relocations. */
10226 case R_PPC64_ADDR14_BRNTAKEN
:
10227 case R_PPC64_REL14_BRNTAKEN
:
10228 insn
|= bfd_get_32 (output_bfd
,
10229 contents
+ rel
->r_offset
) & ~(0x01 << 21);
10232 case R_PPC64_REL14
:
10233 max_br_offset
= 1 << 15;
10236 case R_PPC64_REL24
:
10237 /* Calls to functions with a different TOC, such as calls to
10238 shared objects, need to alter the TOC pointer. This is
10239 done using a linkage stub. A REL24 branching to these
10240 linkage stubs needs to be followed by a nop, as the nop
10241 will be replaced with an instruction to restore the TOC
10246 && (((fdh
= h
->oh
) != NULL
10247 && fdh
->elf
.plt
.plist
!= NULL
)
10248 || (fdh
= h
)->elf
.plt
.plist
!= NULL
))
10250 && sec
->output_section
!= NULL
10251 && sec
->id
<= htab
->top_id
10252 && (htab
->stub_group
[sec
->id
].toc_off
10253 != htab
->stub_group
[input_section
->id
].toc_off
)))
10254 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
10255 rel
, htab
)) != NULL
10256 && (stub_entry
->stub_type
== ppc_stub_plt_call
10257 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
10258 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
10260 bfd_boolean can_plt_call
= FALSE
;
10262 if (rel
->r_offset
+ 8 <= input_section
->size
)
10265 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
10267 || nop
== CROR_151515
|| nop
== CROR_313131
)
10269 bfd_put_32 (input_bfd
, LD_R2_40R1
,
10270 contents
+ rel
->r_offset
+ 4);
10271 can_plt_call
= TRUE
;
10277 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
10279 /* If this is a plain branch rather than a branch
10280 and link, don't require a nop. However, don't
10281 allow tail calls in a shared library as they
10282 will result in r2 being corrupted. */
10284 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10285 if (info
->executable
&& (br
& 1) == 0)
10286 can_plt_call
= TRUE
;
10291 && strcmp (h
->elf
.root
.root
.string
,
10292 ".__libc_start_main") == 0)
10294 /* Allow crt1 branch to go via a toc adjusting stub. */
10295 can_plt_call
= TRUE
;
10299 if (strcmp (input_section
->output_section
->name
,
10301 || strcmp (input_section
->output_section
->name
,
10303 (*_bfd_error_handler
)
10304 (_("%B(%A+0x%lx): automatic multiple TOCs "
10305 "not supported using your crt files; "
10306 "recompile with -mminimal-toc or upgrade gcc"),
10309 (long) rel
->r_offset
);
10311 (*_bfd_error_handler
)
10312 (_("%B(%A+0x%lx): sibling call optimization to `%s' "
10313 "does not allow automatic multiple TOCs; "
10314 "recompile with -mminimal-toc or "
10315 "-fno-optimize-sibling-calls, "
10316 "or make `%s' extern"),
10319 (long) rel
->r_offset
,
10322 bfd_set_error (bfd_error_bad_value
);
10328 && stub_entry
->stub_type
== ppc_stub_plt_call
)
10329 unresolved_reloc
= FALSE
;
10332 if (stub_entry
== NULL
10333 && get_opd_info (sec
) != NULL
)
10335 /* The branch destination is the value of the opd entry. */
10336 bfd_vma off
= (relocation
+ addend
10337 - sec
->output_section
->vma
10338 - sec
->output_offset
);
10339 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
10340 if (dest
!= (bfd_vma
) -1)
10347 /* If the branch is out of reach we ought to have a long
10349 from
= (rel
->r_offset
10350 + input_section
->output_offset
10351 + input_section
->output_section
->vma
);
10353 if (stub_entry
== NULL
10354 && (relocation
+ addend
- from
+ max_br_offset
10355 >= 2 * max_br_offset
)
10356 && r_type
!= R_PPC64_ADDR14_BRTAKEN
10357 && r_type
!= R_PPC64_ADDR14_BRNTAKEN
)
10358 stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
, rel
,
10361 if (stub_entry
!= NULL
)
10363 /* Munge up the value and addend so that we call the stub
10364 rather than the procedure directly. */
10365 relocation
= (stub_entry
->stub_offset
10366 + stub_entry
->stub_sec
->output_offset
10367 + stub_entry
->stub_sec
->output_section
->vma
);
10375 /* Set 'a' bit. This is 0b00010 in BO field for branch
10376 on CR(BI) insns (BO == 001at or 011at), and 0b01000
10377 for branch on CTR insns (BO == 1a00t or 1a01t). */
10378 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10379 insn
|= 0x02 << 21;
10380 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10381 insn
|= 0x08 << 21;
10387 /* Invert 'y' bit if not the default. */
10388 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
10389 insn
^= 0x01 << 21;
10392 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10395 /* NOP out calls to undefined weak functions.
10396 We can thus call a weak function without first
10397 checking whether the function is defined. */
10399 && h
->elf
.root
.type
== bfd_link_hash_undefweak
10400 && r_type
== R_PPC64_REL24
10404 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10410 /* Set `addend'. */
10415 (*_bfd_error_handler
)
10416 (_("%B: unknown relocation type %d for symbol %s"),
10417 input_bfd
, (int) r_type
, sym_name
);
10419 bfd_set_error (bfd_error_bad_value
);
10425 case R_PPC64_GNU_VTINHERIT
:
10426 case R_PPC64_GNU_VTENTRY
:
10429 /* GOT16 relocations. Like an ADDR16 using the symbol's
10430 address in the GOT as relocation value instead of the
10431 symbol's value itself. Also, create a GOT entry for the
10432 symbol and put the symbol value there. */
10433 case R_PPC64_GOT_TLSGD16
:
10434 case R_PPC64_GOT_TLSGD16_LO
:
10435 case R_PPC64_GOT_TLSGD16_HI
:
10436 case R_PPC64_GOT_TLSGD16_HA
:
10437 tls_type
= TLS_TLS
| TLS_GD
;
10440 case R_PPC64_GOT_TLSLD16
:
10441 case R_PPC64_GOT_TLSLD16_LO
:
10442 case R_PPC64_GOT_TLSLD16_HI
:
10443 case R_PPC64_GOT_TLSLD16_HA
:
10444 tls_type
= TLS_TLS
| TLS_LD
;
10447 case R_PPC64_GOT_TPREL16_DS
:
10448 case R_PPC64_GOT_TPREL16_LO_DS
:
10449 case R_PPC64_GOT_TPREL16_HI
:
10450 case R_PPC64_GOT_TPREL16_HA
:
10451 tls_type
= TLS_TLS
| TLS_TPREL
;
10454 case R_PPC64_GOT_DTPREL16_DS
:
10455 case R_PPC64_GOT_DTPREL16_LO_DS
:
10456 case R_PPC64_GOT_DTPREL16_HI
:
10457 case R_PPC64_GOT_DTPREL16_HA
:
10458 tls_type
= TLS_TLS
| TLS_DTPREL
;
10461 case R_PPC64_GOT16
:
10462 case R_PPC64_GOT16_LO
:
10463 case R_PPC64_GOT16_HI
:
10464 case R_PPC64_GOT16_HA
:
10465 case R_PPC64_GOT16_DS
:
10466 case R_PPC64_GOT16_LO_DS
:
10469 /* Relocation is to the entry for this symbol in the global
10474 unsigned long indx
= 0;
10476 if (tls_type
== (TLS_TLS
| TLS_LD
)
10478 || !h
->elf
.def_dynamic
))
10479 offp
= &ppc64_tlsld_got (input_bfd
)->offset
;
10482 struct got_entry
*ent
;
10486 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
10487 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
10490 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
10491 /* This is actually a static link, or it is a
10492 -Bsymbolic link and the symbol is defined
10493 locally, or the symbol was forced to be local
10494 because of a version file. */
10498 indx
= h
->elf
.dynindx
;
10499 unresolved_reloc
= FALSE
;
10501 ent
= h
->elf
.got
.glist
;
10505 if (local_got_ents
== NULL
)
10507 ent
= local_got_ents
[r_symndx
];
10510 for (; ent
!= NULL
; ent
= ent
->next
)
10511 if (ent
->addend
== orig_addend
10512 && ent
->owner
== input_bfd
10513 && ent
->tls_type
== tls_type
)
10517 offp
= &ent
->got
.offset
;
10520 got
= ppc64_elf_tdata (input_bfd
)->got
;
10524 /* The offset must always be a multiple of 8. We use the
10525 least significant bit to record whether we have already
10526 processed this entry. */
10528 if ((off
& 1) != 0)
10532 /* Generate relocs for the dynamic linker, except in
10533 the case of TLSLD where we'll use one entry per
10535 asection
*relgot
= ppc64_elf_tdata (input_bfd
)->relgot
;
10538 if ((info
->shared
|| indx
!= 0)
10540 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10541 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
10543 outrel
.r_offset
= (got
->output_section
->vma
10544 + got
->output_offset
10546 outrel
.r_addend
= addend
;
10547 if (tls_type
& (TLS_LD
| TLS_GD
))
10549 outrel
.r_addend
= 0;
10550 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
10551 if (tls_type
== (TLS_TLS
| TLS_GD
))
10553 loc
= relgot
->contents
;
10554 loc
+= (relgot
->reloc_count
++
10555 * sizeof (Elf64_External_Rela
));
10556 bfd_elf64_swap_reloca_out (output_bfd
,
10558 outrel
.r_offset
+= 8;
10559 outrel
.r_addend
= addend
;
10561 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10564 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
10565 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10566 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10567 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
10568 else if (indx
== 0)
10570 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
10572 /* Write the .got section contents for the sake
10574 loc
= got
->contents
+ off
;
10575 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
10579 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
10581 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
10583 outrel
.r_addend
+= relocation
;
10584 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
10585 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
10587 loc
= relgot
->contents
;
10588 loc
+= (relgot
->reloc_count
++
10589 * sizeof (Elf64_External_Rela
));
10590 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
10593 /* Init the .got section contents here if we're not
10594 emitting a reloc. */
10597 relocation
+= addend
;
10598 if (tls_type
== (TLS_TLS
| TLS_LD
))
10600 else if (tls_type
!= 0)
10602 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10603 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10604 relocation
+= DTP_OFFSET
- TP_OFFSET
;
10606 if (tls_type
== (TLS_TLS
| TLS_GD
))
10608 bfd_put_64 (output_bfd
, relocation
,
10609 got
->contents
+ off
+ 8);
10614 bfd_put_64 (output_bfd
, relocation
,
10615 got
->contents
+ off
);
10619 if (off
>= (bfd_vma
) -2)
10622 relocation
= got
->output_offset
+ off
;
10624 /* TOC base (r2) is TOC start plus 0x8000. */
10625 addend
= -TOC_BASE_OFF
;
10629 case R_PPC64_PLT16_HA
:
10630 case R_PPC64_PLT16_HI
:
10631 case R_PPC64_PLT16_LO
:
10632 case R_PPC64_PLT32
:
10633 case R_PPC64_PLT64
:
10634 /* Relocation is to the entry for this symbol in the
10635 procedure linkage table. */
10637 /* Resolve a PLT reloc against a local symbol directly,
10638 without using the procedure linkage table. */
10642 /* It's possible that we didn't make a PLT entry for this
10643 symbol. This happens when statically linking PIC code,
10644 or when using -Bsymbolic. Go find a match if there is a
10646 if (htab
->plt
!= NULL
)
10648 struct plt_entry
*ent
;
10649 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10650 if (ent
->addend
== orig_addend
10651 && ent
->plt
.offset
!= (bfd_vma
) -1)
10653 relocation
= (htab
->plt
->output_section
->vma
10654 + htab
->plt
->output_offset
10655 + ent
->plt
.offset
);
10656 unresolved_reloc
= FALSE
;
10662 /* Relocation value is TOC base. */
10663 relocation
= TOCstart
;
10665 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
10666 else if (unresolved_reloc
)
10668 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
10669 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
10671 unresolved_reloc
= TRUE
;
10674 /* TOC16 relocs. We want the offset relative to the TOC base,
10675 which is the address of the start of the TOC plus 0x8000.
10676 The TOC consists of sections .got, .toc, .tocbss, and .plt,
10678 case R_PPC64_TOC16
:
10679 case R_PPC64_TOC16_LO
:
10680 case R_PPC64_TOC16_HI
:
10681 case R_PPC64_TOC16_DS
:
10682 case R_PPC64_TOC16_LO_DS
:
10683 case R_PPC64_TOC16_HA
:
10684 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
10687 /* Relocate against the beginning of the section. */
10688 case R_PPC64_SECTOFF
:
10689 case R_PPC64_SECTOFF_LO
:
10690 case R_PPC64_SECTOFF_HI
:
10691 case R_PPC64_SECTOFF_DS
:
10692 case R_PPC64_SECTOFF_LO_DS
:
10693 case R_PPC64_SECTOFF_HA
:
10695 addend
-= sec
->output_section
->vma
;
10698 case R_PPC64_REL14
:
10699 case R_PPC64_REL14_BRNTAKEN
:
10700 case R_PPC64_REL14_BRTAKEN
:
10701 case R_PPC64_REL24
:
10704 case R_PPC64_TPREL16
:
10705 case R_PPC64_TPREL16_LO
:
10706 case R_PPC64_TPREL16_HI
:
10707 case R_PPC64_TPREL16_HA
:
10708 case R_PPC64_TPREL16_DS
:
10709 case R_PPC64_TPREL16_LO_DS
:
10710 case R_PPC64_TPREL16_HIGHER
:
10711 case R_PPC64_TPREL16_HIGHERA
:
10712 case R_PPC64_TPREL16_HIGHEST
:
10713 case R_PPC64_TPREL16_HIGHESTA
:
10714 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10716 /* The TPREL16 relocs shouldn't really be used in shared
10717 libs as they will result in DT_TEXTREL being set, but
10718 support them anyway. */
10722 case R_PPC64_DTPREL16
:
10723 case R_PPC64_DTPREL16_LO
:
10724 case R_PPC64_DTPREL16_HI
:
10725 case R_PPC64_DTPREL16_HA
:
10726 case R_PPC64_DTPREL16_DS
:
10727 case R_PPC64_DTPREL16_LO_DS
:
10728 case R_PPC64_DTPREL16_HIGHER
:
10729 case R_PPC64_DTPREL16_HIGHERA
:
10730 case R_PPC64_DTPREL16_HIGHEST
:
10731 case R_PPC64_DTPREL16_HIGHESTA
:
10732 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10735 case R_PPC64_DTPMOD64
:
10740 case R_PPC64_TPREL64
:
10741 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10744 case R_PPC64_DTPREL64
:
10745 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10748 /* Relocations that may need to be propagated if this is a
10750 case R_PPC64_REL30
:
10751 case R_PPC64_REL32
:
10752 case R_PPC64_REL64
:
10753 case R_PPC64_ADDR14
:
10754 case R_PPC64_ADDR14_BRNTAKEN
:
10755 case R_PPC64_ADDR14_BRTAKEN
:
10756 case R_PPC64_ADDR16
:
10757 case R_PPC64_ADDR16_DS
:
10758 case R_PPC64_ADDR16_HA
:
10759 case R_PPC64_ADDR16_HI
:
10760 case R_PPC64_ADDR16_HIGHER
:
10761 case R_PPC64_ADDR16_HIGHERA
:
10762 case R_PPC64_ADDR16_HIGHEST
:
10763 case R_PPC64_ADDR16_HIGHESTA
:
10764 case R_PPC64_ADDR16_LO
:
10765 case R_PPC64_ADDR16_LO_DS
:
10766 case R_PPC64_ADDR24
:
10767 case R_PPC64_ADDR32
:
10768 case R_PPC64_ADDR64
:
10769 case R_PPC64_UADDR16
:
10770 case R_PPC64_UADDR32
:
10771 case R_PPC64_UADDR64
:
10772 /* r_symndx will be zero only for relocs against symbols
10773 from removed linkonce sections, or sections discarded by
10774 a linker script. */
10778 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
], input_bfd
,
10779 contents
+ rel
->r_offset
);
10785 if ((input_section
->flags
& SEC_ALLOC
) == 0)
10788 if (NO_OPD_RELOCS
&& is_opd
)
10793 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10794 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
10795 && (MUST_BE_DYN_RELOC (r_type
)
10796 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
10797 || (ELIMINATE_COPY_RELOCS
10800 && h
->elf
.dynindx
!= -1
10801 && !h
->elf
.non_got_ref
10802 && h
->elf
.def_dynamic
10803 && !h
->elf
.def_regular
))
10805 Elf_Internal_Rela outrel
;
10806 bfd_boolean skip
, relocate
;
10811 /* When generating a dynamic object, these relocations
10812 are copied into the output file to be resolved at run
10818 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
10819 input_section
, rel
->r_offset
);
10820 if (out_off
== (bfd_vma
) -1)
10822 else if (out_off
== (bfd_vma
) -2)
10823 skip
= TRUE
, relocate
= TRUE
;
10824 out_off
+= (input_section
->output_section
->vma
10825 + input_section
->output_offset
);
10826 outrel
.r_offset
= out_off
;
10827 outrel
.r_addend
= rel
->r_addend
;
10829 /* Optimize unaligned reloc use. */
10830 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
10831 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
10832 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
10833 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
10834 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
10835 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
10836 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
10837 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
10838 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
10841 memset (&outrel
, 0, sizeof outrel
);
10842 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
10844 && r_type
!= R_PPC64_TOC
)
10845 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
10848 /* This symbol is local, or marked to become local,
10849 or this is an opd section reloc which must point
10850 at a local function. */
10851 outrel
.r_addend
+= relocation
;
10852 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
10854 if (is_opd
&& h
!= NULL
)
10856 /* Lie about opd entries. This case occurs
10857 when building shared libraries and we
10858 reference a function in another shared
10859 lib. The same thing happens for a weak
10860 definition in an application that's
10861 overridden by a strong definition in a
10862 shared lib. (I believe this is a generic
10863 bug in binutils handling of weak syms.)
10864 In these cases we won't use the opd
10865 entry in this lib. */
10866 unresolved_reloc
= FALSE
;
10868 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10870 /* We need to relocate .opd contents for ld.so.
10871 Prelink also wants simple and consistent rules
10872 for relocs. This make all RELATIVE relocs have
10873 *r_offset equal to r_addend. */
10880 if (bfd_is_abs_section (sec
))
10882 else if (sec
== NULL
|| sec
->owner
== NULL
)
10884 bfd_set_error (bfd_error_bad_value
);
10891 osec
= sec
->output_section
;
10892 indx
= elf_section_data (osec
)->dynindx
;
10896 if ((osec
->flags
& SEC_READONLY
) == 0
10897 && htab
->elf
.data_index_section
!= NULL
)
10898 osec
= htab
->elf
.data_index_section
;
10900 osec
= htab
->elf
.text_index_section
;
10901 indx
= elf_section_data (osec
)->dynindx
;
10903 BFD_ASSERT (indx
!= 0);
10905 /* We are turning this relocation into one
10906 against a section symbol, so subtract out
10907 the output section's address but not the
10908 offset of the input section in the output
10910 outrel
.r_addend
-= osec
->vma
;
10913 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
10917 sreloc
= elf_section_data (input_section
)->sreloc
;
10918 if (sreloc
== NULL
)
10921 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
10924 loc
= sreloc
->contents
;
10925 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
10926 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
10928 /* If this reloc is against an external symbol, it will
10929 be computed at runtime, so there's no need to do
10930 anything now. However, for the sake of prelink ensure
10931 that the section contents are a known value. */
10934 unresolved_reloc
= FALSE
;
10935 /* The value chosen here is quite arbitrary as ld.so
10936 ignores section contents except for the special
10937 case of .opd where the contents might be accessed
10938 before relocation. Choose zero, as that won't
10939 cause reloc overflow. */
10942 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
10943 to improve backward compatibility with older
10945 if (r_type
== R_PPC64_ADDR64
)
10946 addend
= outrel
.r_addend
;
10947 /* Adjust pc_relative relocs to have zero in *r_offset. */
10948 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
10949 addend
= (input_section
->output_section
->vma
10950 + input_section
->output_offset
10957 case R_PPC64_GLOB_DAT
:
10958 case R_PPC64_JMP_SLOT
:
10959 case R_PPC64_RELATIVE
:
10960 /* We shouldn't ever see these dynamic relocs in relocatable
10962 /* Fall through. */
10964 case R_PPC64_PLTGOT16
:
10965 case R_PPC64_PLTGOT16_DS
:
10966 case R_PPC64_PLTGOT16_HA
:
10967 case R_PPC64_PLTGOT16_HI
:
10968 case R_PPC64_PLTGOT16_LO
:
10969 case R_PPC64_PLTGOT16_LO_DS
:
10970 case R_PPC64_PLTREL32
:
10971 case R_PPC64_PLTREL64
:
10972 /* These ones haven't been implemented yet. */
10974 (*_bfd_error_handler
)
10975 (_("%B: relocation %s is not supported for symbol %s."),
10977 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
10979 bfd_set_error (bfd_error_invalid_operation
);
10984 /* Do any further special processing. */
10990 case R_PPC64_ADDR16_HA
:
10991 case R_PPC64_ADDR16_HIGHERA
:
10992 case R_PPC64_ADDR16_HIGHESTA
:
10993 case R_PPC64_TOC16_HA
:
10994 case R_PPC64_SECTOFF_HA
:
10995 case R_PPC64_TPREL16_HA
:
10996 case R_PPC64_DTPREL16_HA
:
10997 case R_PPC64_TPREL16_HIGHER
:
10998 case R_PPC64_TPREL16_HIGHERA
:
10999 case R_PPC64_TPREL16_HIGHEST
:
11000 case R_PPC64_TPREL16_HIGHESTA
:
11001 case R_PPC64_DTPREL16_HIGHER
:
11002 case R_PPC64_DTPREL16_HIGHERA
:
11003 case R_PPC64_DTPREL16_HIGHEST
:
11004 case R_PPC64_DTPREL16_HIGHESTA
:
11005 /* It's just possible that this symbol is a weak symbol
11006 that's not actually defined anywhere. In that case,
11007 'sec' would be NULL, and we should leave the symbol
11008 alone (it will be set to zero elsewhere in the link). */
11013 case R_PPC64_GOT16_HA
:
11014 case R_PPC64_PLTGOT16_HA
:
11015 case R_PPC64_PLT16_HA
:
11016 case R_PPC64_GOT_TLSGD16_HA
:
11017 case R_PPC64_GOT_TLSLD16_HA
:
11018 case R_PPC64_GOT_TPREL16_HA
:
11019 case R_PPC64_GOT_DTPREL16_HA
:
11020 /* Add 0x10000 if sign bit in 0:15 is set.
11021 Bits 0:15 are not used. */
11025 case R_PPC64_ADDR16_DS
:
11026 case R_PPC64_ADDR16_LO_DS
:
11027 case R_PPC64_GOT16_DS
:
11028 case R_PPC64_GOT16_LO_DS
:
11029 case R_PPC64_PLT16_LO_DS
:
11030 case R_PPC64_SECTOFF_DS
:
11031 case R_PPC64_SECTOFF_LO_DS
:
11032 case R_PPC64_TOC16_DS
:
11033 case R_PPC64_TOC16_LO_DS
:
11034 case R_PPC64_PLTGOT16_DS
:
11035 case R_PPC64_PLTGOT16_LO_DS
:
11036 case R_PPC64_GOT_TPREL16_DS
:
11037 case R_PPC64_GOT_TPREL16_LO_DS
:
11038 case R_PPC64_GOT_DTPREL16_DS
:
11039 case R_PPC64_GOT_DTPREL16_LO_DS
:
11040 case R_PPC64_TPREL16_DS
:
11041 case R_PPC64_TPREL16_LO_DS
:
11042 case R_PPC64_DTPREL16_DS
:
11043 case R_PPC64_DTPREL16_LO_DS
:
11044 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
11046 /* If this reloc is against an lq insn, then the value must be
11047 a multiple of 16. This is somewhat of a hack, but the
11048 "correct" way to do this by defining _DQ forms of all the
11049 _DS relocs bloats all reloc switches in this file. It
11050 doesn't seem to make much sense to use any of these relocs
11051 in data, so testing the insn should be safe. */
11052 if ((insn
& (0x3f << 26)) == (56u << 26))
11054 if (((relocation
+ addend
) & mask
) != 0)
11056 (*_bfd_error_handler
)
11057 (_("%B: error: relocation %s not a multiple of %d"),
11059 ppc64_elf_howto_table
[r_type
]->name
,
11061 bfd_set_error (bfd_error_bad_value
);
11068 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
11069 because such sections are not SEC_ALLOC and thus ld.so will
11070 not process them. */
11071 if (unresolved_reloc
11072 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
11073 && h
->elf
.def_dynamic
))
11075 (*_bfd_error_handler
)
11076 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
11079 (long) rel
->r_offset
,
11080 ppc64_elf_howto_table
[(int) r_type
]->name
,
11081 h
->elf
.root
.root
.string
);
11085 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
11093 if (r
!= bfd_reloc_ok
)
11095 if (sym_name
== NULL
)
11096 sym_name
= "(null)";
11097 if (r
== bfd_reloc_overflow
)
11102 && h
->elf
.root
.type
== bfd_link_hash_undefweak
11103 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
11105 /* Assume this is a call protected by other code that
11106 detects the symbol is undefined. If this is the case,
11107 we can safely ignore the overflow. If not, the
11108 program is hosed anyway, and a little warning isn't
11114 if (!((*info
->callbacks
->reloc_overflow
)
11115 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
11116 ppc64_elf_howto_table
[r_type
]->name
,
11117 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
11122 (*_bfd_error_handler
)
11123 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
11126 (long) rel
->r_offset
,
11127 ppc64_elf_howto_table
[r_type
]->name
,
11135 /* If we're emitting relocations, then shortly after this function
11136 returns, reloc offsets and addends for this section will be
11137 adjusted. Worse, reloc symbol indices will be for the output
11138 file rather than the input. Save a copy of the relocs for
11139 opd_entry_value. */
11140 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
11143 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
11144 rel
= bfd_alloc (input_bfd
, amt
);
11145 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
11146 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
11149 memcpy (rel
, relocs
, amt
);
11154 /* Adjust the value of any local symbols in opd sections. */
11157 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
11158 const char *name ATTRIBUTE_UNUSED
,
11159 Elf_Internal_Sym
*elfsym
,
11160 asection
*input_sec
,
11161 struct elf_link_hash_entry
*h
)
11163 long *opd_adjust
, adjust
;
11169 opd_adjust
= get_opd_info (input_sec
);
11170 if (opd_adjust
== NULL
)
11173 value
= elfsym
->st_value
- input_sec
->output_offset
;
11174 if (!info
->relocatable
)
11175 value
-= input_sec
->output_section
->vma
;
11177 adjust
= opd_adjust
[value
/ 8];
11179 elfsym
->st_value
= 0;
11181 elfsym
->st_value
+= adjust
;
11185 /* Finish up dynamic symbol handling. We set the contents of various
11186 dynamic sections here. */
11189 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
11190 struct bfd_link_info
*info
,
11191 struct elf_link_hash_entry
*h
,
11192 Elf_Internal_Sym
*sym
)
11194 struct ppc_link_hash_table
*htab
;
11195 struct plt_entry
*ent
;
11196 Elf_Internal_Rela rela
;
11199 htab
= ppc_hash_table (info
);
11201 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
11202 if (ent
->plt
.offset
!= (bfd_vma
) -1)
11204 /* This symbol has an entry in the procedure linkage
11205 table. Set it up. */
11207 if (htab
->plt
== NULL
11208 || htab
->relplt
== NULL
11209 || htab
->glink
== NULL
)
11212 /* Create a JMP_SLOT reloc to inform the dynamic linker to
11213 fill in the PLT entry. */
11214 rela
.r_offset
= (htab
->plt
->output_section
->vma
11215 + htab
->plt
->output_offset
11216 + ent
->plt
.offset
);
11217 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
11218 rela
.r_addend
= ent
->addend
;
11220 loc
= htab
->relplt
->contents
;
11221 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
11222 * sizeof (Elf64_External_Rela
));
11223 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11228 Elf_Internal_Rela rela
;
11231 /* This symbol needs a copy reloc. Set it up. */
11233 if (h
->dynindx
== -1
11234 || (h
->root
.type
!= bfd_link_hash_defined
11235 && h
->root
.type
!= bfd_link_hash_defweak
)
11236 || htab
->relbss
== NULL
)
11239 rela
.r_offset
= (h
->root
.u
.def
.value
11240 + h
->root
.u
.def
.section
->output_section
->vma
11241 + h
->root
.u
.def
.section
->output_offset
);
11242 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
11244 loc
= htab
->relbss
->contents
;
11245 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
11246 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11249 /* Mark some specially defined symbols as absolute. */
11250 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
11251 sym
->st_shndx
= SHN_ABS
;
11256 /* Used to decide how to sort relocs in an optimal manner for the
11257 dynamic linker, before writing them out. */
11259 static enum elf_reloc_type_class
11260 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
11262 enum elf_ppc64_reloc_type r_type
;
11264 r_type
= ELF64_R_TYPE (rela
->r_info
);
11267 case R_PPC64_RELATIVE
:
11268 return reloc_class_relative
;
11269 case R_PPC64_JMP_SLOT
:
11270 return reloc_class_plt
;
11272 return reloc_class_copy
;
11274 return reloc_class_normal
;
11278 /* Finish up the dynamic sections. */
11281 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
11282 struct bfd_link_info
*info
)
11284 struct ppc_link_hash_table
*htab
;
11288 htab
= ppc_hash_table (info
);
11289 dynobj
= htab
->elf
.dynobj
;
11290 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
11292 if (htab
->elf
.dynamic_sections_created
)
11294 Elf64_External_Dyn
*dyncon
, *dynconend
;
11296 if (sdyn
== NULL
|| htab
->got
== NULL
)
11299 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
11300 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
11301 for (; dyncon
< dynconend
; dyncon
++)
11303 Elf_Internal_Dyn dyn
;
11306 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
11313 case DT_PPC64_GLINK
:
11315 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11316 /* We stupidly defined DT_PPC64_GLINK to be the start
11317 of glink rather than the first entry point, which is
11318 what ld.so needs, and now have a bigger stub to
11319 support automatic multiple TOCs. */
11320 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
11324 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11327 dyn
.d_un
.d_ptr
= s
->vma
;
11330 case DT_PPC64_OPDSZ
:
11331 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11334 dyn
.d_un
.d_val
= s
->size
;
11339 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11344 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11348 dyn
.d_un
.d_val
= htab
->relplt
->size
;
11352 /* Don't count procedure linkage table relocs in the
11353 overall reloc count. */
11357 dyn
.d_un
.d_val
-= s
->size
;
11361 /* We may not be using the standard ELF linker script.
11362 If .rela.plt is the first .rela section, we adjust
11363 DT_RELA to not include it. */
11367 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
11369 dyn
.d_un
.d_ptr
+= s
->size
;
11373 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11377 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
11379 /* Fill in the first entry in the global offset table.
11380 We use it to hold the link-time TOCbase. */
11381 bfd_put_64 (output_bfd
,
11382 elf_gp (output_bfd
) + TOC_BASE_OFF
,
11383 htab
->got
->contents
);
11385 /* Set .got entry size. */
11386 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
11389 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
11391 /* Set .plt entry size. */
11392 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
11396 /* We need to handle writing out multiple GOT sections ourselves,
11397 since we didn't add them to DYNOBJ. We know dynobj is the first
11399 while ((dynobj
= dynobj
->link_next
) != NULL
)
11403 if (!is_ppc64_elf_target (dynobj
->xvec
))
11406 s
= ppc64_elf_tdata (dynobj
)->got
;
11409 && s
->output_section
!= bfd_abs_section_ptr
11410 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11411 s
->contents
, s
->output_offset
,
11414 s
= ppc64_elf_tdata (dynobj
)->relgot
;
11417 && s
->output_section
!= bfd_abs_section_ptr
11418 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11419 s
->contents
, s
->output_offset
,
11427 #include "elf64-target.h"