1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
37 static bfd_reloc_status_type ppc64_elf_ha_reloc
38 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
39 static bfd_reloc_status_type ppc64_elf_branch_reloc
40 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
55 static bfd_vma opd_entry_value
56 (asection
*, bfd_vma
, asection
**, bfd_vma
*);
58 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
59 #define TARGET_LITTLE_NAME "elf64-powerpcle"
60 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
61 #define TARGET_BIG_NAME "elf64-powerpc"
62 #define ELF_ARCH bfd_arch_powerpc
63 #define ELF_MACHINE_CODE EM_PPC64
64 #define ELF_MAXPAGESIZE 0x10000
65 #define ELF_COMMONPAGESIZE 0x1000
66 #define elf_info_to_howto ppc64_elf_info_to_howto
68 #define elf_backend_want_got_sym 0
69 #define elf_backend_want_plt_sym 0
70 #define elf_backend_plt_alignment 3
71 #define elf_backend_plt_not_loaded 1
72 #define elf_backend_got_header_size 8
73 #define elf_backend_can_gc_sections 1
74 #define elf_backend_can_refcount 1
75 #define elf_backend_rela_normal 1
76 #define elf_backend_default_execstack 0
78 #define bfd_elf64_mkobject ppc64_elf_mkobject
79 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
80 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
81 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
82 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
83 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
84 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
85 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
87 #define elf_backend_object_p ppc64_elf_object_p
88 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
89 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
90 #define elf_backend_write_core_note ppc64_elf_write_core_note
91 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
92 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
93 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
94 #define elf_backend_check_directives ppc64_elf_check_directives
95 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
96 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
97 #define elf_backend_check_relocs ppc64_elf_check_relocs
98 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
99 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
100 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
101 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
102 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
103 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
104 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
105 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
106 #define elf_backend_action_discarded ppc64_elf_action_discarded
107 #define elf_backend_relocate_section ppc64_elf_relocate_section
108 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
109 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
110 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
111 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
112 #define elf_backend_special_sections ppc64_elf_special_sections
114 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
118 /* The size in bytes of an entry in the procedure linkage table. */
119 #define PLT_ENTRY_SIZE 24
121 /* The initial size of the plt reserved for the dynamic linker. */
122 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
124 /* TOC base pointers offset from start of TOC. */
125 #define TOC_BASE_OFF 0x8000
127 /* Offset of tp and dtp pointers from start of TLS block. */
128 #define TP_OFFSET 0x7000
129 #define DTP_OFFSET 0x8000
131 /* .plt call stub instructions. The normal stub is like this, but
132 sometimes the .plt entry crosses a 64k boundary and we need to
133 insert an addis to adjust r12. */
134 #define PLT_CALL_STUB_SIZE (7*4)
135 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
136 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
137 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
138 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
139 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
140 /* ld %r11,xxx+16@l(%r12) */
141 #define BCTR 0x4e800420 /* bctr */
144 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
145 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
146 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
148 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
150 /* glink call stub instructions. We enter with the index in R0. */
151 #define GLINK_CALL_STUB_SIZE (16*4)
155 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
156 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
158 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
159 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
160 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
161 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
169 #define NOP 0x60000000
171 /* Some other nops. */
172 #define CROR_151515 0x4def7b82
173 #define CROR_313131 0x4ffffb82
175 /* .glink entries for the first 32k functions are two instructions. */
176 #define LI_R0_0 0x38000000 /* li %r0,0 */
177 #define B_DOT 0x48000000 /* b . */
179 /* After that, we need two instructions to load the index, followed by
181 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
182 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
184 /* Instructions used by the save and restore reg functions. */
185 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
186 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
187 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
188 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
189 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
190 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
191 #define LI_R12_0 0x39800000 /* li %r12,0 */
192 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
193 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
194 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
195 #define BLR 0x4e800020 /* blr */
197 /* Since .opd is an array of descriptors and each entry will end up
198 with identical R_PPC64_RELATIVE relocs, there is really no need to
199 propagate .opd relocs; The dynamic linker should be taught to
200 relocate .opd without reloc entries. */
201 #ifndef NO_OPD_RELOCS
202 #define NO_OPD_RELOCS 0
205 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
207 /* Relocation HOWTO's. */
208 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
210 static reloc_howto_type ppc64_elf_howto_raw
[] = {
211 /* This reloc does nothing. */
212 HOWTO (R_PPC64_NONE
, /* type */
214 2, /* size (0 = byte, 1 = short, 2 = long) */
216 FALSE
, /* pc_relative */
218 complain_overflow_dont
, /* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_PPC64_NONE", /* name */
221 FALSE
, /* partial_inplace */
224 FALSE
), /* pcrel_offset */
226 /* A standard 32 bit relocation. */
227 HOWTO (R_PPC64_ADDR32
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE
, /* pc_relative */
233 complain_overflow_bitfield
, /* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_PPC64_ADDR32", /* name */
236 FALSE
, /* partial_inplace */
238 0xffffffff, /* dst_mask */
239 FALSE
), /* pcrel_offset */
241 /* An absolute 26 bit branch; the lower two bits must be zero.
242 FIXME: we don't check that, we just clear them. */
243 HOWTO (R_PPC64_ADDR24
, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_bitfield
, /* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_PPC64_ADDR24", /* name */
252 FALSE
, /* partial_inplace */
254 0x03fffffc, /* dst_mask */
255 FALSE
), /* pcrel_offset */
257 /* A standard 16 bit relocation. */
258 HOWTO (R_PPC64_ADDR16
, /* type */
260 1, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE
, /* pc_relative */
264 complain_overflow_bitfield
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_PPC64_ADDR16", /* name */
267 FALSE
, /* partial_inplace */
269 0xffff, /* dst_mask */
270 FALSE
), /* pcrel_offset */
272 /* A 16 bit relocation without overflow. */
273 HOWTO (R_PPC64_ADDR16_LO
, /* type */
275 1, /* size (0 = byte, 1 = short, 2 = long) */
277 FALSE
, /* pc_relative */
279 complain_overflow_dont
,/* complain_on_overflow */
280 bfd_elf_generic_reloc
, /* special_function */
281 "R_PPC64_ADDR16_LO", /* name */
282 FALSE
, /* partial_inplace */
284 0xffff, /* dst_mask */
285 FALSE
), /* pcrel_offset */
287 /* Bits 16-31 of an address. */
288 HOWTO (R_PPC64_ADDR16_HI
, /* type */
290 1, /* size (0 = byte, 1 = short, 2 = long) */
292 FALSE
, /* pc_relative */
294 complain_overflow_dont
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_PPC64_ADDR16_HI", /* name */
297 FALSE
, /* partial_inplace */
299 0xffff, /* dst_mask */
300 FALSE
), /* pcrel_offset */
302 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
303 bits, treated as a signed number, is negative. */
304 HOWTO (R_PPC64_ADDR16_HA
, /* type */
306 1, /* size (0 = byte, 1 = short, 2 = long) */
308 FALSE
, /* pc_relative */
310 complain_overflow_dont
, /* complain_on_overflow */
311 ppc64_elf_ha_reloc
, /* special_function */
312 "R_PPC64_ADDR16_HA", /* name */
313 FALSE
, /* partial_inplace */
315 0xffff, /* dst_mask */
316 FALSE
), /* pcrel_offset */
318 /* An absolute 16 bit branch; the lower two bits must be zero.
319 FIXME: we don't check that, we just clear them. */
320 HOWTO (R_PPC64_ADDR14
, /* type */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE
, /* pc_relative */
326 complain_overflow_bitfield
, /* complain_on_overflow */
327 ppc64_elf_branch_reloc
, /* special_function */
328 "R_PPC64_ADDR14", /* name */
329 FALSE
, /* partial_inplace */
331 0x0000fffc, /* dst_mask */
332 FALSE
), /* pcrel_offset */
334 /* An absolute 16 bit branch, for which bit 10 should be set to
335 indicate that the branch is expected to be taken. The lower two
336 bits must be zero. */
337 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE
, /* pc_relative */
343 complain_overflow_bitfield
, /* complain_on_overflow */
344 ppc64_elf_brtaken_reloc
, /* special_function */
345 "R_PPC64_ADDR14_BRTAKEN",/* name */
346 FALSE
, /* partial_inplace */
348 0x0000fffc, /* dst_mask */
349 FALSE
), /* pcrel_offset */
351 /* An absolute 16 bit branch, for which bit 10 should be set to
352 indicate that the branch is not expected to be taken. The lower
353 two bits must be zero. */
354 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_bitfield
, /* complain_on_overflow */
361 ppc64_elf_brtaken_reloc
, /* special_function */
362 "R_PPC64_ADDR14_BRNTAKEN",/* name */
363 FALSE
, /* partial_inplace */
365 0x0000fffc, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* A relative 26 bit branch; the lower two bits must be zero. */
369 HOWTO (R_PPC64_REL24
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 TRUE
, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 ppc64_elf_branch_reloc
, /* special_function */
377 "R_PPC64_REL24", /* name */
378 FALSE
, /* partial_inplace */
380 0x03fffffc, /* dst_mask */
381 TRUE
), /* pcrel_offset */
383 /* A relative 16 bit branch; the lower two bits must be zero. */
384 HOWTO (R_PPC64_REL14
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 TRUE
, /* pc_relative */
390 complain_overflow_signed
, /* complain_on_overflow */
391 ppc64_elf_branch_reloc
, /* special_function */
392 "R_PPC64_REL14", /* name */
393 FALSE
, /* partial_inplace */
395 0x0000fffc, /* dst_mask */
396 TRUE
), /* pcrel_offset */
398 /* A relative 16 bit branch. Bit 10 should be set to indicate that
399 the branch is expected to be taken. The lower two bits must be
401 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 TRUE
, /* pc_relative */
407 complain_overflow_signed
, /* complain_on_overflow */
408 ppc64_elf_brtaken_reloc
, /* special_function */
409 "R_PPC64_REL14_BRTAKEN", /* name */
410 FALSE
, /* partial_inplace */
412 0x0000fffc, /* dst_mask */
413 TRUE
), /* pcrel_offset */
415 /* A relative 16 bit branch. Bit 10 should be set to indicate that
416 the branch is not expected to be taken. The lower two bits must
418 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 TRUE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 ppc64_elf_brtaken_reloc
, /* special_function */
426 "R_PPC64_REL14_BRNTAKEN",/* name */
427 FALSE
, /* partial_inplace */
429 0x0000fffc, /* dst_mask */
430 TRUE
), /* pcrel_offset */
432 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
434 HOWTO (R_PPC64_GOT16
, /* type */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE
, /* pc_relative */
440 complain_overflow_signed
, /* complain_on_overflow */
441 ppc64_elf_unhandled_reloc
, /* special_function */
442 "R_PPC64_GOT16", /* name */
443 FALSE
, /* partial_inplace */
445 0xffff, /* dst_mask */
446 FALSE
), /* pcrel_offset */
448 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
450 HOWTO (R_PPC64_GOT16_LO
, /* type */
452 1, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 ppc64_elf_unhandled_reloc
, /* special_function */
458 "R_PPC64_GOT16_LO", /* name */
459 FALSE
, /* partial_inplace */
461 0xffff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
464 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
466 HOWTO (R_PPC64_GOT16_HI
, /* type */
468 1, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE
, /* pc_relative */
472 complain_overflow_dont
,/* complain_on_overflow */
473 ppc64_elf_unhandled_reloc
, /* special_function */
474 "R_PPC64_GOT16_HI", /* name */
475 FALSE
, /* partial_inplace */
477 0xffff, /* dst_mask */
478 FALSE
), /* pcrel_offset */
480 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
482 HOWTO (R_PPC64_GOT16_HA
, /* type */
484 1, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_dont
,/* complain_on_overflow */
489 ppc64_elf_unhandled_reloc
, /* special_function */
490 "R_PPC64_GOT16_HA", /* name */
491 FALSE
, /* partial_inplace */
493 0xffff, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* This is used only by the dynamic linker. The symbol should exist
497 both in the object being run and in some shared library. The
498 dynamic linker copies the data addressed by the symbol from the
499 shared library into the object, because the object being
500 run has to have the data at some particular address. */
501 HOWTO (R_PPC64_COPY
, /* type */
503 0, /* this one is variable size */
505 FALSE
, /* pc_relative */
507 complain_overflow_dont
, /* complain_on_overflow */
508 ppc64_elf_unhandled_reloc
, /* special_function */
509 "R_PPC64_COPY", /* name */
510 FALSE
, /* partial_inplace */
513 FALSE
), /* pcrel_offset */
515 /* Like R_PPC64_ADDR64, but used when setting global offset table
517 HOWTO (R_PPC64_GLOB_DAT
, /* type */
519 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
521 FALSE
, /* pc_relative */
523 complain_overflow_dont
, /* complain_on_overflow */
524 ppc64_elf_unhandled_reloc
, /* special_function */
525 "R_PPC64_GLOB_DAT", /* name */
526 FALSE
, /* partial_inplace */
528 ONES (64), /* dst_mask */
529 FALSE
), /* pcrel_offset */
531 /* Created by the link editor. Marks a procedure linkage table
532 entry for a symbol. */
533 HOWTO (R_PPC64_JMP_SLOT
, /* type */
535 0, /* size (0 = byte, 1 = short, 2 = long) */
537 FALSE
, /* pc_relative */
539 complain_overflow_dont
, /* complain_on_overflow */
540 ppc64_elf_unhandled_reloc
, /* special_function */
541 "R_PPC64_JMP_SLOT", /* name */
542 FALSE
, /* partial_inplace */
545 FALSE
), /* pcrel_offset */
547 /* Used only by the dynamic linker. When the object is run, this
548 doubleword64 is set to the load address of the object, plus the
550 HOWTO (R_PPC64_RELATIVE
, /* type */
552 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
554 FALSE
, /* pc_relative */
556 complain_overflow_dont
, /* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_PPC64_RELATIVE", /* name */
559 FALSE
, /* partial_inplace */
561 ONES (64), /* dst_mask */
562 FALSE
), /* pcrel_offset */
564 /* Like R_PPC64_ADDR32, but may be unaligned. */
565 HOWTO (R_PPC64_UADDR32
, /* type */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 FALSE
, /* pc_relative */
571 complain_overflow_bitfield
, /* complain_on_overflow */
572 bfd_elf_generic_reloc
, /* special_function */
573 "R_PPC64_UADDR32", /* name */
574 FALSE
, /* partial_inplace */
576 0xffffffff, /* dst_mask */
577 FALSE
), /* pcrel_offset */
579 /* Like R_PPC64_ADDR16, but may be unaligned. */
580 HOWTO (R_PPC64_UADDR16
, /* type */
582 1, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE
, /* pc_relative */
586 complain_overflow_bitfield
, /* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_PPC64_UADDR16", /* name */
589 FALSE
, /* partial_inplace */
591 0xffff, /* dst_mask */
592 FALSE
), /* pcrel_offset */
594 /* 32-bit PC relative. */
595 HOWTO (R_PPC64_REL32
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 TRUE
, /* pc_relative */
601 /* FIXME: Verify. Was complain_overflow_bitfield. */
602 complain_overflow_signed
, /* complain_on_overflow */
603 bfd_elf_generic_reloc
, /* special_function */
604 "R_PPC64_REL32", /* name */
605 FALSE
, /* partial_inplace */
607 0xffffffff, /* dst_mask */
608 TRUE
), /* pcrel_offset */
610 /* 32-bit relocation to the symbol's procedure linkage table. */
611 HOWTO (R_PPC64_PLT32
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 FALSE
, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 ppc64_elf_unhandled_reloc
, /* special_function */
619 "R_PPC64_PLT32", /* name */
620 FALSE
, /* partial_inplace */
622 0xffffffff, /* dst_mask */
623 FALSE
), /* pcrel_offset */
625 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
626 FIXME: R_PPC64_PLTREL32 not supported. */
627 HOWTO (R_PPC64_PLTREL32
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 TRUE
, /* pc_relative */
633 complain_overflow_signed
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_PPC64_PLTREL32", /* name */
636 FALSE
, /* partial_inplace */
638 0xffffffff, /* dst_mask */
639 TRUE
), /* pcrel_offset */
641 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
643 HOWTO (R_PPC64_PLT16_LO
, /* type */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_dont
, /* complain_on_overflow */
650 ppc64_elf_unhandled_reloc
, /* special_function */
651 "R_PPC64_PLT16_LO", /* name */
652 FALSE
, /* partial_inplace */
654 0xffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
659 HOWTO (R_PPC64_PLT16_HI
, /* type */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
663 FALSE
, /* pc_relative */
665 complain_overflow_dont
, /* complain_on_overflow */
666 ppc64_elf_unhandled_reloc
, /* special_function */
667 "R_PPC64_PLT16_HI", /* name */
668 FALSE
, /* partial_inplace */
670 0xffff, /* dst_mask */
671 FALSE
), /* pcrel_offset */
673 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
675 HOWTO (R_PPC64_PLT16_HA
, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_dont
, /* complain_on_overflow */
682 ppc64_elf_unhandled_reloc
, /* special_function */
683 "R_PPC64_PLT16_HA", /* name */
684 FALSE
, /* partial_inplace */
686 0xffff, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* 16-bit section relative relocation. */
690 HOWTO (R_PPC64_SECTOFF
, /* type */
692 1, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_bitfield
, /* complain_on_overflow */
697 ppc64_elf_sectoff_reloc
, /* special_function */
698 "R_PPC64_SECTOFF", /* name */
699 FALSE
, /* partial_inplace */
701 0xffff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* Like R_PPC64_SECTOFF, but no overflow warning. */
705 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
707 1, /* size (0 = byte, 1 = short, 2 = long) */
709 FALSE
, /* pc_relative */
711 complain_overflow_dont
, /* complain_on_overflow */
712 ppc64_elf_sectoff_reloc
, /* special_function */
713 "R_PPC64_SECTOFF_LO", /* name */
714 FALSE
, /* partial_inplace */
716 0xffff, /* dst_mask */
717 FALSE
), /* pcrel_offset */
719 /* 16-bit upper half section relative relocation. */
720 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
722 1, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE
, /* pc_relative */
726 complain_overflow_dont
, /* complain_on_overflow */
727 ppc64_elf_sectoff_reloc
, /* special_function */
728 "R_PPC64_SECTOFF_HI", /* name */
729 FALSE
, /* partial_inplace */
731 0xffff, /* dst_mask */
732 FALSE
), /* pcrel_offset */
734 /* 16-bit upper half adjusted section relative relocation. */
735 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
737 1, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE
, /* pc_relative */
741 complain_overflow_dont
, /* complain_on_overflow */
742 ppc64_elf_sectoff_ha_reloc
, /* special_function */
743 "R_PPC64_SECTOFF_HA", /* name */
744 FALSE
, /* partial_inplace */
746 0xffff, /* dst_mask */
747 FALSE
), /* pcrel_offset */
749 /* Like R_PPC64_REL24 without touching the two least significant bits. */
750 HOWTO (R_PPC64_REL30
, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 TRUE
, /* pc_relative */
756 complain_overflow_dont
, /* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 "R_PPC64_REL30", /* name */
759 FALSE
, /* partial_inplace */
761 0xfffffffc, /* dst_mask */
762 TRUE
), /* pcrel_offset */
764 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
766 /* A standard 64-bit relocation. */
767 HOWTO (R_PPC64_ADDR64
, /* type */
769 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
771 FALSE
, /* pc_relative */
773 complain_overflow_dont
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_PPC64_ADDR64", /* name */
776 FALSE
, /* partial_inplace */
778 ONES (64), /* dst_mask */
779 FALSE
), /* pcrel_offset */
781 /* The bits 32-47 of an address. */
782 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
784 1, /* size (0 = byte, 1 = short, 2 = long) */
786 FALSE
, /* pc_relative */
788 complain_overflow_dont
, /* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 "R_PPC64_ADDR16_HIGHER", /* name */
791 FALSE
, /* partial_inplace */
793 0xffff, /* dst_mask */
794 FALSE
), /* pcrel_offset */
796 /* The bits 32-47 of an address, plus 1 if the contents of the low
797 16 bits, treated as a signed number, is negative. */
798 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
800 1, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE
, /* pc_relative */
804 complain_overflow_dont
, /* complain_on_overflow */
805 ppc64_elf_ha_reloc
, /* special_function */
806 "R_PPC64_ADDR16_HIGHERA", /* name */
807 FALSE
, /* partial_inplace */
809 0xffff, /* dst_mask */
810 FALSE
), /* pcrel_offset */
812 /* The bits 48-63 of an address. */
813 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
815 1, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 "R_PPC64_ADDR16_HIGHEST", /* name */
822 FALSE
, /* partial_inplace */
824 0xffff, /* dst_mask */
825 FALSE
), /* pcrel_offset */
827 /* The bits 48-63 of an address, plus 1 if the contents of the low
828 16 bits, treated as a signed number, is negative. */
829 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_dont
, /* complain_on_overflow */
836 ppc64_elf_ha_reloc
, /* special_function */
837 "R_PPC64_ADDR16_HIGHESTA", /* name */
838 FALSE
, /* partial_inplace */
840 0xffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
843 /* Like ADDR64, but may be unaligned. */
844 HOWTO (R_PPC64_UADDR64
, /* type */
846 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
848 FALSE
, /* pc_relative */
850 complain_overflow_dont
, /* complain_on_overflow */
851 bfd_elf_generic_reloc
, /* special_function */
852 "R_PPC64_UADDR64", /* name */
853 FALSE
, /* partial_inplace */
855 ONES (64), /* dst_mask */
856 FALSE
), /* pcrel_offset */
858 /* 64-bit relative relocation. */
859 HOWTO (R_PPC64_REL64
, /* type */
861 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
863 TRUE
, /* pc_relative */
865 complain_overflow_dont
, /* complain_on_overflow */
866 bfd_elf_generic_reloc
, /* special_function */
867 "R_PPC64_REL64", /* name */
868 FALSE
, /* partial_inplace */
870 ONES (64), /* dst_mask */
871 TRUE
), /* pcrel_offset */
873 /* 64-bit relocation to the symbol's procedure linkage table. */
874 HOWTO (R_PPC64_PLT64
, /* type */
876 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
878 FALSE
, /* pc_relative */
880 complain_overflow_dont
, /* complain_on_overflow */
881 ppc64_elf_unhandled_reloc
, /* special_function */
882 "R_PPC64_PLT64", /* name */
883 FALSE
, /* partial_inplace */
885 ONES (64), /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* 64-bit PC relative relocation to the symbol's procedure linkage
890 /* FIXME: R_PPC64_PLTREL64 not supported. */
891 HOWTO (R_PPC64_PLTREL64
, /* type */
893 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
895 TRUE
, /* pc_relative */
897 complain_overflow_dont
, /* complain_on_overflow */
898 ppc64_elf_unhandled_reloc
, /* special_function */
899 "R_PPC64_PLTREL64", /* name */
900 FALSE
, /* partial_inplace */
902 ONES (64), /* dst_mask */
903 TRUE
), /* pcrel_offset */
905 /* 16 bit TOC-relative relocation. */
907 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
908 HOWTO (R_PPC64_TOC16
, /* type */
910 1, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_signed
, /* complain_on_overflow */
915 ppc64_elf_toc_reloc
, /* special_function */
916 "R_PPC64_TOC16", /* name */
917 FALSE
, /* partial_inplace */
919 0xffff, /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 /* 16 bit TOC-relative relocation without overflow. */
924 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
925 HOWTO (R_PPC64_TOC16_LO
, /* type */
927 1, /* size (0 = byte, 1 = short, 2 = long) */
929 FALSE
, /* pc_relative */
931 complain_overflow_dont
, /* complain_on_overflow */
932 ppc64_elf_toc_reloc
, /* special_function */
933 "R_PPC64_TOC16_LO", /* name */
934 FALSE
, /* partial_inplace */
936 0xffff, /* dst_mask */
937 FALSE
), /* pcrel_offset */
939 /* 16 bit TOC-relative relocation, high 16 bits. */
941 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
942 HOWTO (R_PPC64_TOC16_HI
, /* type */
944 1, /* size (0 = byte, 1 = short, 2 = long) */
946 FALSE
, /* pc_relative */
948 complain_overflow_dont
, /* complain_on_overflow */
949 ppc64_elf_toc_reloc
, /* special_function */
950 "R_PPC64_TOC16_HI", /* name */
951 FALSE
, /* partial_inplace */
953 0xffff, /* dst_mask */
954 FALSE
), /* pcrel_offset */
956 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
957 contents of the low 16 bits, treated as a signed number, is
960 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
961 HOWTO (R_PPC64_TOC16_HA
, /* type */
963 1, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE
, /* pc_relative */
967 complain_overflow_dont
, /* complain_on_overflow */
968 ppc64_elf_toc_ha_reloc
, /* special_function */
969 "R_PPC64_TOC16_HA", /* name */
970 FALSE
, /* partial_inplace */
972 0xffff, /* dst_mask */
973 FALSE
), /* pcrel_offset */
975 /* 64-bit relocation; insert value of TOC base (.TOC.). */
977 /* R_PPC64_TOC 51 doubleword64 .TOC. */
978 HOWTO (R_PPC64_TOC
, /* type */
980 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
982 FALSE
, /* pc_relative */
984 complain_overflow_bitfield
, /* complain_on_overflow */
985 ppc64_elf_toc64_reloc
, /* special_function */
986 "R_PPC64_TOC", /* name */
987 FALSE
, /* partial_inplace */
989 ONES (64), /* dst_mask */
990 FALSE
), /* pcrel_offset */
992 /* Like R_PPC64_GOT16, but also informs the link editor that the
993 value to relocate may (!) refer to a PLT entry which the link
994 editor (a) may replace with the symbol value. If the link editor
995 is unable to fully resolve the symbol, it may (b) create a PLT
996 entry and store the address to the new PLT entry in the GOT.
997 This permits lazy resolution of function symbols at run time.
998 The link editor may also skip all of this and just (c) emit a
999 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1000 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1001 HOWTO (R_PPC64_PLTGOT16
, /* type */
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_signed
, /* complain_on_overflow */
1008 ppc64_elf_unhandled_reloc
, /* special_function */
1009 "R_PPC64_PLTGOT16", /* name */
1010 FALSE
, /* partial_inplace */
1012 0xffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 /* Like R_PPC64_PLTGOT16, but without overflow. */
1016 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1017 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1019 1, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
, /* complain_on_overflow */
1024 ppc64_elf_unhandled_reloc
, /* special_function */
1025 "R_PPC64_PLTGOT16_LO", /* name */
1026 FALSE
, /* partial_inplace */
1028 0xffff, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1031 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1032 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1033 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1034 16, /* rightshift */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE
, /* pc_relative */
1039 complain_overflow_dont
, /* complain_on_overflow */
1040 ppc64_elf_unhandled_reloc
, /* special_function */
1041 "R_PPC64_PLTGOT16_HI", /* name */
1042 FALSE
, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE
), /* pcrel_offset */
1047 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1048 1 if the contents of the low 16 bits, treated as a signed number,
1050 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1051 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1052 16, /* rightshift */
1053 1, /* size (0 = byte, 1 = short, 2 = long) */
1055 FALSE
, /* pc_relative */
1057 complain_overflow_dont
,/* complain_on_overflow */
1058 ppc64_elf_unhandled_reloc
, /* special_function */
1059 "R_PPC64_PLTGOT16_HA", /* name */
1060 FALSE
, /* partial_inplace */
1062 0xffff, /* dst_mask */
1063 FALSE
), /* pcrel_offset */
1065 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1066 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1068 1, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE
, /* pc_relative */
1072 complain_overflow_bitfield
, /* complain_on_overflow */
1073 bfd_elf_generic_reloc
, /* special_function */
1074 "R_PPC64_ADDR16_DS", /* name */
1075 FALSE
, /* partial_inplace */
1077 0xfffc, /* dst_mask */
1078 FALSE
), /* pcrel_offset */
1080 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1081 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE
, /* pc_relative */
1087 complain_overflow_dont
,/* complain_on_overflow */
1088 bfd_elf_generic_reloc
, /* special_function */
1089 "R_PPC64_ADDR16_LO_DS",/* name */
1090 FALSE
, /* partial_inplace */
1092 0xfffc, /* dst_mask */
1093 FALSE
), /* pcrel_offset */
1095 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1096 HOWTO (R_PPC64_GOT16_DS
, /* type */
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1100 FALSE
, /* pc_relative */
1102 complain_overflow_signed
, /* complain_on_overflow */
1103 ppc64_elf_unhandled_reloc
, /* special_function */
1104 "R_PPC64_GOT16_DS", /* name */
1105 FALSE
, /* partial_inplace */
1107 0xfffc, /* dst_mask */
1108 FALSE
), /* pcrel_offset */
1110 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1111 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1113 1, /* size (0 = byte, 1 = short, 2 = long) */
1115 FALSE
, /* pc_relative */
1117 complain_overflow_dont
, /* complain_on_overflow */
1118 ppc64_elf_unhandled_reloc
, /* special_function */
1119 "R_PPC64_GOT16_LO_DS", /* name */
1120 FALSE
, /* partial_inplace */
1122 0xfffc, /* dst_mask */
1123 FALSE
), /* pcrel_offset */
1125 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1126 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1128 1, /* size (0 = byte, 1 = short, 2 = long) */
1130 FALSE
, /* pc_relative */
1132 complain_overflow_dont
, /* complain_on_overflow */
1133 ppc64_elf_unhandled_reloc
, /* special_function */
1134 "R_PPC64_PLT16_LO_DS", /* name */
1135 FALSE
, /* partial_inplace */
1137 0xfffc, /* dst_mask */
1138 FALSE
), /* pcrel_offset */
1140 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1141 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1143 1, /* size (0 = byte, 1 = short, 2 = long) */
1145 FALSE
, /* pc_relative */
1147 complain_overflow_bitfield
, /* complain_on_overflow */
1148 ppc64_elf_sectoff_reloc
, /* special_function */
1149 "R_PPC64_SECTOFF_DS", /* name */
1150 FALSE
, /* partial_inplace */
1152 0xfffc, /* dst_mask */
1153 FALSE
), /* pcrel_offset */
1155 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1156 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1158 1, /* size (0 = byte, 1 = short, 2 = long) */
1160 FALSE
, /* pc_relative */
1162 complain_overflow_dont
, /* complain_on_overflow */
1163 ppc64_elf_sectoff_reloc
, /* special_function */
1164 "R_PPC64_SECTOFF_LO_DS",/* name */
1165 FALSE
, /* partial_inplace */
1167 0xfffc, /* dst_mask */
1168 FALSE
), /* pcrel_offset */
1170 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1171 HOWTO (R_PPC64_TOC16_DS
, /* type */
1173 1, /* size (0 = byte, 1 = short, 2 = long) */
1175 FALSE
, /* pc_relative */
1177 complain_overflow_signed
, /* complain_on_overflow */
1178 ppc64_elf_toc_reloc
, /* special_function */
1179 "R_PPC64_TOC16_DS", /* name */
1180 FALSE
, /* partial_inplace */
1182 0xfffc, /* dst_mask */
1183 FALSE
), /* pcrel_offset */
1185 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1186 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1188 1, /* size (0 = byte, 1 = short, 2 = long) */
1190 FALSE
, /* pc_relative */
1192 complain_overflow_dont
, /* complain_on_overflow */
1193 ppc64_elf_toc_reloc
, /* special_function */
1194 "R_PPC64_TOC16_LO_DS", /* name */
1195 FALSE
, /* partial_inplace */
1197 0xfffc, /* dst_mask */
1198 FALSE
), /* pcrel_offset */
1200 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1201 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1202 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1204 1, /* size (0 = byte, 1 = short, 2 = long) */
1206 FALSE
, /* pc_relative */
1208 complain_overflow_signed
, /* complain_on_overflow */
1209 ppc64_elf_unhandled_reloc
, /* special_function */
1210 "R_PPC64_PLTGOT16_DS", /* name */
1211 FALSE
, /* partial_inplace */
1213 0xfffc, /* dst_mask */
1214 FALSE
), /* pcrel_offset */
1216 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1217 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1218 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1220 1, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE
, /* pc_relative */
1224 complain_overflow_dont
, /* complain_on_overflow */
1225 ppc64_elf_unhandled_reloc
, /* special_function */
1226 "R_PPC64_PLTGOT16_LO_DS",/* name */
1227 FALSE
, /* partial_inplace */
1229 0xfffc, /* dst_mask */
1230 FALSE
), /* pcrel_offset */
1232 /* Marker reloc for TLS. */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1237 FALSE
, /* pc_relative */
1239 complain_overflow_dont
, /* complain_on_overflow */
1240 bfd_elf_generic_reloc
, /* special_function */
1241 "R_PPC64_TLS", /* name */
1242 FALSE
, /* partial_inplace */
1245 FALSE
), /* pcrel_offset */
1247 /* Computes the load module index of the load module that contains the
1248 definition of its TLS sym. */
1249 HOWTO (R_PPC64_DTPMOD64
,
1251 4, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_dont
, /* complain_on_overflow */
1256 ppc64_elf_unhandled_reloc
, /* special_function */
1257 "R_PPC64_DTPMOD64", /* name */
1258 FALSE
, /* partial_inplace */
1260 ONES (64), /* dst_mask */
1261 FALSE
), /* pcrel_offset */
1263 /* Computes a dtv-relative displacement, the difference between the value
1264 of sym+add and the base address of the thread-local storage block that
1265 contains the definition of sym, minus 0x8000. */
1266 HOWTO (R_PPC64_DTPREL64
,
1268 4, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE
, /* pc_relative */
1272 complain_overflow_dont
, /* complain_on_overflow */
1273 ppc64_elf_unhandled_reloc
, /* special_function */
1274 "R_PPC64_DTPREL64", /* name */
1275 FALSE
, /* partial_inplace */
1277 ONES (64), /* dst_mask */
1278 FALSE
), /* pcrel_offset */
1280 /* A 16 bit dtprel reloc. */
1281 HOWTO (R_PPC64_DTPREL16
,
1283 1, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE
, /* pc_relative */
1287 complain_overflow_signed
, /* complain_on_overflow */
1288 ppc64_elf_unhandled_reloc
, /* special_function */
1289 "R_PPC64_DTPREL16", /* name */
1290 FALSE
, /* partial_inplace */
1292 0xffff, /* dst_mask */
1293 FALSE
), /* pcrel_offset */
1295 /* Like DTPREL16, but no overflow. */
1296 HOWTO (R_PPC64_DTPREL16_LO
,
1298 1, /* size (0 = byte, 1 = short, 2 = long) */
1300 FALSE
, /* pc_relative */
1302 complain_overflow_dont
, /* complain_on_overflow */
1303 ppc64_elf_unhandled_reloc
, /* special_function */
1304 "R_PPC64_DTPREL16_LO", /* name */
1305 FALSE
, /* partial_inplace */
1307 0xffff, /* dst_mask */
1308 FALSE
), /* pcrel_offset */
1310 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1311 HOWTO (R_PPC64_DTPREL16_HI
,
1312 16, /* rightshift */
1313 1, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE
, /* pc_relative */
1317 complain_overflow_dont
, /* complain_on_overflow */
1318 ppc64_elf_unhandled_reloc
, /* special_function */
1319 "R_PPC64_DTPREL16_HI", /* name */
1320 FALSE
, /* partial_inplace */
1322 0xffff, /* dst_mask */
1323 FALSE
), /* pcrel_offset */
1325 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1326 HOWTO (R_PPC64_DTPREL16_HA
,
1327 16, /* rightshift */
1328 1, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE
, /* pc_relative */
1332 complain_overflow_dont
, /* complain_on_overflow */
1333 ppc64_elf_unhandled_reloc
, /* special_function */
1334 "R_PPC64_DTPREL16_HA", /* name */
1335 FALSE
, /* partial_inplace */
1337 0xffff, /* dst_mask */
1338 FALSE
), /* pcrel_offset */
1340 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1341 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1342 32, /* rightshift */
1343 1, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE
, /* pc_relative */
1347 complain_overflow_dont
, /* complain_on_overflow */
1348 ppc64_elf_unhandled_reloc
, /* special_function */
1349 "R_PPC64_DTPREL16_HIGHER", /* name */
1350 FALSE
, /* partial_inplace */
1352 0xffff, /* dst_mask */
1353 FALSE
), /* pcrel_offset */
1355 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1356 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1357 32, /* rightshift */
1358 1, /* size (0 = byte, 1 = short, 2 = long) */
1360 FALSE
, /* pc_relative */
1362 complain_overflow_dont
, /* complain_on_overflow */
1363 ppc64_elf_unhandled_reloc
, /* special_function */
1364 "R_PPC64_DTPREL16_HIGHERA", /* name */
1365 FALSE
, /* partial_inplace */
1367 0xffff, /* dst_mask */
1368 FALSE
), /* pcrel_offset */
1370 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1371 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1372 48, /* rightshift */
1373 1, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE
, /* pc_relative */
1377 complain_overflow_dont
, /* complain_on_overflow */
1378 ppc64_elf_unhandled_reloc
, /* special_function */
1379 "R_PPC64_DTPREL16_HIGHEST", /* name */
1380 FALSE
, /* partial_inplace */
1382 0xffff, /* dst_mask */
1383 FALSE
), /* pcrel_offset */
1385 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1386 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1387 48, /* rightshift */
1388 1, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE
, /* pc_relative */
1392 complain_overflow_dont
, /* complain_on_overflow */
1393 ppc64_elf_unhandled_reloc
, /* special_function */
1394 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1395 FALSE
, /* partial_inplace */
1397 0xffff, /* dst_mask */
1398 FALSE
), /* pcrel_offset */
1400 /* Like DTPREL16, but for insns with a DS field. */
1401 HOWTO (R_PPC64_DTPREL16_DS
,
1403 1, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE
, /* pc_relative */
1407 complain_overflow_signed
, /* complain_on_overflow */
1408 ppc64_elf_unhandled_reloc
, /* special_function */
1409 "R_PPC64_DTPREL16_DS", /* name */
1410 FALSE
, /* partial_inplace */
1412 0xfffc, /* dst_mask */
1413 FALSE
), /* pcrel_offset */
1415 /* Like DTPREL16_DS, but no overflow. */
1416 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1418 1, /* size (0 = byte, 1 = short, 2 = long) */
1420 FALSE
, /* pc_relative */
1422 complain_overflow_dont
, /* complain_on_overflow */
1423 ppc64_elf_unhandled_reloc
, /* special_function */
1424 "R_PPC64_DTPREL16_LO_DS", /* name */
1425 FALSE
, /* partial_inplace */
1427 0xfffc, /* dst_mask */
1428 FALSE
), /* pcrel_offset */
1430 /* Computes a tp-relative displacement, the difference between the value of
1431 sym+add and the value of the thread pointer (r13). */
1432 HOWTO (R_PPC64_TPREL64
,
1434 4, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE
, /* pc_relative */
1438 complain_overflow_dont
, /* complain_on_overflow */
1439 ppc64_elf_unhandled_reloc
, /* special_function */
1440 "R_PPC64_TPREL64", /* name */
1441 FALSE
, /* partial_inplace */
1443 ONES (64), /* dst_mask */
1444 FALSE
), /* pcrel_offset */
1446 /* A 16 bit tprel reloc. */
1447 HOWTO (R_PPC64_TPREL16
,
1449 1, /* size (0 = byte, 1 = short, 2 = long) */
1451 FALSE
, /* pc_relative */
1453 complain_overflow_signed
, /* complain_on_overflow */
1454 ppc64_elf_unhandled_reloc
, /* special_function */
1455 "R_PPC64_TPREL16", /* name */
1456 FALSE
, /* partial_inplace */
1458 0xffff, /* dst_mask */
1459 FALSE
), /* pcrel_offset */
1461 /* Like TPREL16, but no overflow. */
1462 HOWTO (R_PPC64_TPREL16_LO
,
1464 1, /* size (0 = byte, 1 = short, 2 = long) */
1466 FALSE
, /* pc_relative */
1468 complain_overflow_dont
, /* complain_on_overflow */
1469 ppc64_elf_unhandled_reloc
, /* special_function */
1470 "R_PPC64_TPREL16_LO", /* name */
1471 FALSE
, /* partial_inplace */
1473 0xffff, /* dst_mask */
1474 FALSE
), /* pcrel_offset */
1476 /* Like TPREL16_LO, but next higher group of 16 bits. */
1477 HOWTO (R_PPC64_TPREL16_HI
,
1478 16, /* rightshift */
1479 1, /* size (0 = byte, 1 = short, 2 = long) */
1481 FALSE
, /* pc_relative */
1483 complain_overflow_dont
, /* complain_on_overflow */
1484 ppc64_elf_unhandled_reloc
, /* special_function */
1485 "R_PPC64_TPREL16_HI", /* name */
1486 FALSE
, /* partial_inplace */
1488 0xffff, /* dst_mask */
1489 FALSE
), /* pcrel_offset */
1491 /* Like TPREL16_HI, but adjust for low 16 bits. */
1492 HOWTO (R_PPC64_TPREL16_HA
,
1493 16, /* rightshift */
1494 1, /* size (0 = byte, 1 = short, 2 = long) */
1496 FALSE
, /* pc_relative */
1498 complain_overflow_dont
, /* complain_on_overflow */
1499 ppc64_elf_unhandled_reloc
, /* special_function */
1500 "R_PPC64_TPREL16_HA", /* name */
1501 FALSE
, /* partial_inplace */
1503 0xffff, /* dst_mask */
1504 FALSE
), /* pcrel_offset */
1506 /* Like TPREL16_HI, but next higher group of 16 bits. */
1507 HOWTO (R_PPC64_TPREL16_HIGHER
,
1508 32, /* rightshift */
1509 1, /* size (0 = byte, 1 = short, 2 = long) */
1511 FALSE
, /* pc_relative */
1513 complain_overflow_dont
, /* complain_on_overflow */
1514 ppc64_elf_unhandled_reloc
, /* special_function */
1515 "R_PPC64_TPREL16_HIGHER", /* name */
1516 FALSE
, /* partial_inplace */
1518 0xffff, /* dst_mask */
1519 FALSE
), /* pcrel_offset */
1521 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1522 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1523 32, /* rightshift */
1524 1, /* size (0 = byte, 1 = short, 2 = long) */
1526 FALSE
, /* pc_relative */
1528 complain_overflow_dont
, /* complain_on_overflow */
1529 ppc64_elf_unhandled_reloc
, /* special_function */
1530 "R_PPC64_TPREL16_HIGHERA", /* name */
1531 FALSE
, /* partial_inplace */
1533 0xffff, /* dst_mask */
1534 FALSE
), /* pcrel_offset */
1536 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1537 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1538 48, /* rightshift */
1539 1, /* size (0 = byte, 1 = short, 2 = long) */
1541 FALSE
, /* pc_relative */
1543 complain_overflow_dont
, /* complain_on_overflow */
1544 ppc64_elf_unhandled_reloc
, /* special_function */
1545 "R_PPC64_TPREL16_HIGHEST", /* name */
1546 FALSE
, /* partial_inplace */
1548 0xffff, /* dst_mask */
1549 FALSE
), /* pcrel_offset */
1551 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1552 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1553 48, /* rightshift */
1554 1, /* size (0 = byte, 1 = short, 2 = long) */
1556 FALSE
, /* pc_relative */
1558 complain_overflow_dont
, /* complain_on_overflow */
1559 ppc64_elf_unhandled_reloc
, /* special_function */
1560 "R_PPC64_TPREL16_HIGHESTA", /* name */
1561 FALSE
, /* partial_inplace */
1563 0xffff, /* dst_mask */
1564 FALSE
), /* pcrel_offset */
1566 /* Like TPREL16, but for insns with a DS field. */
1567 HOWTO (R_PPC64_TPREL16_DS
,
1569 1, /* size (0 = byte, 1 = short, 2 = long) */
1571 FALSE
, /* pc_relative */
1573 complain_overflow_signed
, /* complain_on_overflow */
1574 ppc64_elf_unhandled_reloc
, /* special_function */
1575 "R_PPC64_TPREL16_DS", /* name */
1576 FALSE
, /* partial_inplace */
1578 0xfffc, /* dst_mask */
1579 FALSE
), /* pcrel_offset */
1581 /* Like TPREL16_DS, but no overflow. */
1582 HOWTO (R_PPC64_TPREL16_LO_DS
,
1584 1, /* size (0 = byte, 1 = short, 2 = long) */
1586 FALSE
, /* pc_relative */
1588 complain_overflow_dont
, /* complain_on_overflow */
1589 ppc64_elf_unhandled_reloc
, /* special_function */
1590 "R_PPC64_TPREL16_LO_DS", /* name */
1591 FALSE
, /* partial_inplace */
1593 0xfffc, /* dst_mask */
1594 FALSE
), /* pcrel_offset */
1596 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1597 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1598 to the first entry relative to the TOC base (r2). */
1599 HOWTO (R_PPC64_GOT_TLSGD16
,
1601 1, /* size (0 = byte, 1 = short, 2 = long) */
1603 FALSE
, /* pc_relative */
1605 complain_overflow_signed
, /* complain_on_overflow */
1606 ppc64_elf_unhandled_reloc
, /* special_function */
1607 "R_PPC64_GOT_TLSGD16", /* name */
1608 FALSE
, /* partial_inplace */
1610 0xffff, /* dst_mask */
1611 FALSE
), /* pcrel_offset */
1613 /* Like GOT_TLSGD16, but no overflow. */
1614 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1616 1, /* size (0 = byte, 1 = short, 2 = long) */
1618 FALSE
, /* pc_relative */
1620 complain_overflow_dont
, /* complain_on_overflow */
1621 ppc64_elf_unhandled_reloc
, /* special_function */
1622 "R_PPC64_GOT_TLSGD16_LO", /* name */
1623 FALSE
, /* partial_inplace */
1625 0xffff, /* dst_mask */
1626 FALSE
), /* pcrel_offset */
1628 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1629 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1630 16, /* rightshift */
1631 1, /* size (0 = byte, 1 = short, 2 = long) */
1633 FALSE
, /* pc_relative */
1635 complain_overflow_dont
, /* complain_on_overflow */
1636 ppc64_elf_unhandled_reloc
, /* special_function */
1637 "R_PPC64_GOT_TLSGD16_HI", /* name */
1638 FALSE
, /* partial_inplace */
1640 0xffff, /* dst_mask */
1641 FALSE
), /* pcrel_offset */
1643 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1644 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1645 16, /* rightshift */
1646 1, /* size (0 = byte, 1 = short, 2 = long) */
1648 FALSE
, /* pc_relative */
1650 complain_overflow_dont
, /* complain_on_overflow */
1651 ppc64_elf_unhandled_reloc
, /* special_function */
1652 "R_PPC64_GOT_TLSGD16_HA", /* name */
1653 FALSE
, /* partial_inplace */
1655 0xffff, /* dst_mask */
1656 FALSE
), /* pcrel_offset */
1658 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1659 with values (sym+add)@dtpmod and zero, and computes the offset to the
1660 first entry relative to the TOC base (r2). */
1661 HOWTO (R_PPC64_GOT_TLSLD16
,
1663 1, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE
, /* pc_relative */
1667 complain_overflow_signed
, /* complain_on_overflow */
1668 ppc64_elf_unhandled_reloc
, /* special_function */
1669 "R_PPC64_GOT_TLSLD16", /* name */
1670 FALSE
, /* partial_inplace */
1672 0xffff, /* dst_mask */
1673 FALSE
), /* pcrel_offset */
1675 /* Like GOT_TLSLD16, but no overflow. */
1676 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1678 1, /* size (0 = byte, 1 = short, 2 = long) */
1680 FALSE
, /* pc_relative */
1682 complain_overflow_dont
, /* complain_on_overflow */
1683 ppc64_elf_unhandled_reloc
, /* special_function */
1684 "R_PPC64_GOT_TLSLD16_LO", /* name */
1685 FALSE
, /* partial_inplace */
1687 0xffff, /* dst_mask */
1688 FALSE
), /* pcrel_offset */
1690 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1691 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1692 16, /* rightshift */
1693 1, /* size (0 = byte, 1 = short, 2 = long) */
1695 FALSE
, /* pc_relative */
1697 complain_overflow_dont
, /* complain_on_overflow */
1698 ppc64_elf_unhandled_reloc
, /* special_function */
1699 "R_PPC64_GOT_TLSLD16_HI", /* name */
1700 FALSE
, /* partial_inplace */
1702 0xffff, /* dst_mask */
1703 FALSE
), /* pcrel_offset */
1705 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1706 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1707 16, /* rightshift */
1708 1, /* size (0 = byte, 1 = short, 2 = long) */
1710 FALSE
, /* pc_relative */
1712 complain_overflow_dont
, /* complain_on_overflow */
1713 ppc64_elf_unhandled_reloc
, /* special_function */
1714 "R_PPC64_GOT_TLSLD16_HA", /* name */
1715 FALSE
, /* partial_inplace */
1717 0xffff, /* dst_mask */
1718 FALSE
), /* pcrel_offset */
1720 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1721 the offset to the entry relative to the TOC base (r2). */
1722 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1724 1, /* size (0 = byte, 1 = short, 2 = long) */
1726 FALSE
, /* pc_relative */
1728 complain_overflow_signed
, /* complain_on_overflow */
1729 ppc64_elf_unhandled_reloc
, /* special_function */
1730 "R_PPC64_GOT_DTPREL16_DS", /* name */
1731 FALSE
, /* partial_inplace */
1733 0xfffc, /* dst_mask */
1734 FALSE
), /* pcrel_offset */
1736 /* Like GOT_DTPREL16_DS, but no overflow. */
1737 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1739 1, /* size (0 = byte, 1 = short, 2 = long) */
1741 FALSE
, /* pc_relative */
1743 complain_overflow_dont
, /* complain_on_overflow */
1744 ppc64_elf_unhandled_reloc
, /* special_function */
1745 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1746 FALSE
, /* partial_inplace */
1748 0xfffc, /* dst_mask */
1749 FALSE
), /* pcrel_offset */
1751 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1752 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1753 16, /* rightshift */
1754 1, /* size (0 = byte, 1 = short, 2 = long) */
1756 FALSE
, /* pc_relative */
1758 complain_overflow_dont
, /* complain_on_overflow */
1759 ppc64_elf_unhandled_reloc
, /* special_function */
1760 "R_PPC64_GOT_DTPREL16_HI", /* name */
1761 FALSE
, /* partial_inplace */
1763 0xffff, /* dst_mask */
1764 FALSE
), /* pcrel_offset */
1766 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1767 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1768 16, /* rightshift */
1769 1, /* size (0 = byte, 1 = short, 2 = long) */
1771 FALSE
, /* pc_relative */
1773 complain_overflow_dont
, /* complain_on_overflow */
1774 ppc64_elf_unhandled_reloc
, /* special_function */
1775 "R_PPC64_GOT_DTPREL16_HA", /* name */
1776 FALSE
, /* partial_inplace */
1778 0xffff, /* dst_mask */
1779 FALSE
), /* pcrel_offset */
1781 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1782 offset to the entry relative to the TOC base (r2). */
1783 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1785 1, /* size (0 = byte, 1 = short, 2 = long) */
1787 FALSE
, /* pc_relative */
1789 complain_overflow_signed
, /* complain_on_overflow */
1790 ppc64_elf_unhandled_reloc
, /* special_function */
1791 "R_PPC64_GOT_TPREL16_DS", /* name */
1792 FALSE
, /* partial_inplace */
1794 0xfffc, /* dst_mask */
1795 FALSE
), /* pcrel_offset */
1797 /* Like GOT_TPREL16_DS, but no overflow. */
1798 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1800 1, /* size (0 = byte, 1 = short, 2 = long) */
1802 FALSE
, /* pc_relative */
1804 complain_overflow_dont
, /* complain_on_overflow */
1805 ppc64_elf_unhandled_reloc
, /* special_function */
1806 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1807 FALSE
, /* partial_inplace */
1809 0xfffc, /* dst_mask */
1810 FALSE
), /* pcrel_offset */
1812 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1813 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1814 16, /* rightshift */
1815 1, /* size (0 = byte, 1 = short, 2 = long) */
1817 FALSE
, /* pc_relative */
1819 complain_overflow_dont
, /* complain_on_overflow */
1820 ppc64_elf_unhandled_reloc
, /* special_function */
1821 "R_PPC64_GOT_TPREL16_HI", /* name */
1822 FALSE
, /* partial_inplace */
1824 0xffff, /* dst_mask */
1825 FALSE
), /* pcrel_offset */
1827 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1828 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1829 16, /* rightshift */
1830 1, /* size (0 = byte, 1 = short, 2 = long) */
1832 FALSE
, /* pc_relative */
1834 complain_overflow_dont
, /* complain_on_overflow */
1835 ppc64_elf_unhandled_reloc
, /* special_function */
1836 "R_PPC64_GOT_TPREL16_HA", /* name */
1837 FALSE
, /* partial_inplace */
1839 0xffff, /* dst_mask */
1840 FALSE
), /* pcrel_offset */
1842 /* GNU extension to record C++ vtable hierarchy. */
1843 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1845 0, /* size (0 = byte, 1 = short, 2 = long) */
1847 FALSE
, /* pc_relative */
1849 complain_overflow_dont
, /* complain_on_overflow */
1850 NULL
, /* special_function */
1851 "R_PPC64_GNU_VTINHERIT", /* name */
1852 FALSE
, /* partial_inplace */
1855 FALSE
), /* pcrel_offset */
1857 /* GNU extension to record C++ vtable member usage. */
1858 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1860 0, /* size (0 = byte, 1 = short, 2 = long) */
1862 FALSE
, /* pc_relative */
1864 complain_overflow_dont
, /* complain_on_overflow */
1865 NULL
, /* special_function */
1866 "R_PPC64_GNU_VTENTRY", /* name */
1867 FALSE
, /* partial_inplace */
1870 FALSE
), /* pcrel_offset */
1874 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1878 ppc_howto_init (void)
1880 unsigned int i
, type
;
1883 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1886 type
= ppc64_elf_howto_raw
[i
].type
;
1887 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1888 / sizeof (ppc64_elf_howto_table
[0])));
1889 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1893 static reloc_howto_type
*
1894 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1895 bfd_reloc_code_real_type code
)
1897 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1899 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1900 /* Initialize howto table if needed. */
1908 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1910 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1912 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1914 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1916 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1918 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1920 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1922 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1924 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1926 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1928 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1930 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1932 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1934 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1936 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1938 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1940 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1942 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1944 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1946 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1948 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1950 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1952 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1954 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1956 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1958 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1960 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1962 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1964 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1966 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1968 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1970 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1972 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1974 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1976 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1978 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1980 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1982 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1984 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1986 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1988 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1990 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1992 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1994 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1996 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1998 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2000 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2002 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2004 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2006 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2008 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2010 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2012 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2014 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2016 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2018 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2020 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2022 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2024 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2026 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2028 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2030 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2032 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2034 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2036 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2038 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2040 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2042 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2044 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2046 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2048 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2050 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2052 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2054 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2056 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2058 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2060 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2062 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2064 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2066 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2068 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2070 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2072 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2074 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2076 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2078 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2080 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2082 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2084 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2086 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2088 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2090 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2092 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2094 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2096 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2098 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2100 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2102 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2104 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2106 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2108 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2112 return ppc64_elf_howto_table
[r
];
2115 static reloc_howto_type
*
2116 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2122 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2124 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2125 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2126 return &ppc64_elf_howto_raw
[i
];
2131 /* Set the howto pointer for a PowerPC ELF reloc. */
2134 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2135 Elf_Internal_Rela
*dst
)
2139 /* Initialize howto table if needed. */
2140 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2143 type
= ELF64_R_TYPE (dst
->r_info
);
2144 if (type
>= (sizeof (ppc64_elf_howto_table
)
2145 / sizeof (ppc64_elf_howto_table
[0])))
2147 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2149 type
= R_PPC64_NONE
;
2151 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2154 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2156 static bfd_reloc_status_type
2157 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2158 void *data
, asection
*input_section
,
2159 bfd
*output_bfd
, char **error_message
)
2161 /* If this is a relocatable link (output_bfd test tells us), just
2162 call the generic function. Any adjustment will be done at final
2164 if (output_bfd
!= NULL
)
2165 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2166 input_section
, output_bfd
, error_message
);
2168 /* Adjust the addend for sign extension of the low 16 bits.
2169 We won't actually be using the low 16 bits, so trashing them
2171 reloc_entry
->addend
+= 0x8000;
2172 return bfd_reloc_continue
;
2175 static bfd_reloc_status_type
2176 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2177 void *data
, asection
*input_section
,
2178 bfd
*output_bfd
, char **error_message
)
2180 if (output_bfd
!= NULL
)
2181 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2182 input_section
, output_bfd
, error_message
);
2184 if (strcmp (symbol
->section
->name
, ".opd") == 0
2185 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2187 bfd_vma dest
= opd_entry_value (symbol
->section
,
2188 symbol
->value
+ reloc_entry
->addend
,
2190 if (dest
!= (bfd_vma
) -1)
2191 reloc_entry
->addend
= dest
- (symbol
->value
2192 + symbol
->section
->output_section
->vma
2193 + symbol
->section
->output_offset
);
2195 return bfd_reloc_continue
;
2198 static bfd_reloc_status_type
2199 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2200 void *data
, asection
*input_section
,
2201 bfd
*output_bfd
, char **error_message
)
2204 enum elf_ppc64_reloc_type r_type
;
2205 bfd_size_type octets
;
2206 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2207 bfd_boolean is_power4
= FALSE
;
2209 /* If this is a relocatable link (output_bfd test tells us), just
2210 call the generic function. Any adjustment will be done at final
2212 if (output_bfd
!= NULL
)
2213 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2214 input_section
, output_bfd
, error_message
);
2216 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2217 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2218 insn
&= ~(0x01 << 21);
2219 r_type
= reloc_entry
->howto
->type
;
2220 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2221 || r_type
== R_PPC64_REL14_BRTAKEN
)
2222 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2226 /* Set 'a' bit. This is 0b00010 in BO field for branch
2227 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2228 for branch on CTR insns (BO == 1a00t or 1a01t). */
2229 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2231 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2241 if (!bfd_is_com_section (symbol
->section
))
2242 target
= symbol
->value
;
2243 target
+= symbol
->section
->output_section
->vma
;
2244 target
+= symbol
->section
->output_offset
;
2245 target
+= reloc_entry
->addend
;
2247 from
= (reloc_entry
->address
2248 + input_section
->output_offset
2249 + input_section
->output_section
->vma
);
2251 /* Invert 'y' bit if not the default. */
2252 if ((bfd_signed_vma
) (target
- from
) < 0)
2255 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2257 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2258 input_section
, output_bfd
, error_message
);
2261 static bfd_reloc_status_type
2262 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2263 void *data
, asection
*input_section
,
2264 bfd
*output_bfd
, char **error_message
)
2266 /* If this is a relocatable link (output_bfd test tells us), just
2267 call the generic function. Any adjustment will be done at final
2269 if (output_bfd
!= NULL
)
2270 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2271 input_section
, output_bfd
, error_message
);
2273 /* Subtract the symbol section base address. */
2274 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2275 return bfd_reloc_continue
;
2278 static bfd_reloc_status_type
2279 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2280 void *data
, asection
*input_section
,
2281 bfd
*output_bfd
, char **error_message
)
2283 /* If this is a relocatable link (output_bfd test tells us), just
2284 call the generic function. Any adjustment will be done at final
2286 if (output_bfd
!= NULL
)
2287 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2288 input_section
, output_bfd
, error_message
);
2290 /* Subtract the symbol section base address. */
2291 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2293 /* Adjust the addend for sign extension of the low 16 bits. */
2294 reloc_entry
->addend
+= 0x8000;
2295 return bfd_reloc_continue
;
2298 static bfd_reloc_status_type
2299 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2300 void *data
, asection
*input_section
,
2301 bfd
*output_bfd
, char **error_message
)
2305 /* If this is a relocatable link (output_bfd test tells us), just
2306 call the generic function. Any adjustment will be done at final
2308 if (output_bfd
!= NULL
)
2309 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2310 input_section
, output_bfd
, error_message
);
2312 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2314 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2316 /* Subtract the TOC base address. */
2317 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2318 return bfd_reloc_continue
;
2321 static bfd_reloc_status_type
2322 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2323 void *data
, asection
*input_section
,
2324 bfd
*output_bfd
, char **error_message
)
2328 /* If this is a relocatable link (output_bfd test tells us), just
2329 call the generic function. Any adjustment will be done at final
2331 if (output_bfd
!= NULL
)
2332 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2333 input_section
, output_bfd
, error_message
);
2335 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2337 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2339 /* Subtract the TOC base address. */
2340 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2342 /* Adjust the addend for sign extension of the low 16 bits. */
2343 reloc_entry
->addend
+= 0x8000;
2344 return bfd_reloc_continue
;
2347 static bfd_reloc_status_type
2348 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2349 void *data
, asection
*input_section
,
2350 bfd
*output_bfd
, char **error_message
)
2353 bfd_size_type octets
;
2355 /* If this is a relocatable link (output_bfd test tells us), just
2356 call the generic function. Any adjustment will be done at final
2358 if (output_bfd
!= NULL
)
2359 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2360 input_section
, output_bfd
, error_message
);
2362 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2364 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2366 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2367 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2368 return bfd_reloc_ok
;
2371 static bfd_reloc_status_type
2372 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2373 void *data
, asection
*input_section
,
2374 bfd
*output_bfd
, char **error_message
)
2376 /* If this is a relocatable link (output_bfd test tells us), just
2377 call the generic function. Any adjustment will be done at final
2379 if (output_bfd
!= NULL
)
2380 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2381 input_section
, output_bfd
, error_message
);
2383 if (error_message
!= NULL
)
2385 static char buf
[60];
2386 sprintf (buf
, "generic linker can't handle %s",
2387 reloc_entry
->howto
->name
);
2388 *error_message
= buf
;
2390 return bfd_reloc_dangerous
;
2393 struct ppc64_elf_obj_tdata
2395 struct elf_obj_tdata elf
;
2397 /* Shortcuts to dynamic linker sections. */
2401 /* Used during garbage collection. We attach global symbols defined
2402 on removed .opd entries to this section so that the sym is removed. */
2403 asection
*deleted_section
;
2405 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2406 sections means we potentially need one of these for each input bfd. */
2408 bfd_signed_vma refcount
;
2412 /* A copy of relocs before they are modified for --emit-relocs. */
2413 Elf_Internal_Rela
*opd_relocs
;
2416 #define ppc64_elf_tdata(bfd) \
2417 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2419 #define ppc64_tlsld_got(bfd) \
2420 (&ppc64_elf_tdata (bfd)->tlsld_got)
2422 /* Override the generic function because we store some extras. */
2425 ppc64_elf_mkobject (bfd
*abfd
)
2427 if (abfd
->tdata
.any
== NULL
)
2429 bfd_size_type amt
= sizeof (struct ppc64_elf_obj_tdata
);
2430 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2431 if (abfd
->tdata
.any
== NULL
)
2434 return bfd_elf_mkobject (abfd
);
2437 /* Return 1 if target is one of ours. */
2440 is_ppc64_elf_target (const struct bfd_target
*targ
)
2442 extern const bfd_target bfd_elf64_powerpc_vec
;
2443 extern const bfd_target bfd_elf64_powerpcle_vec
;
2445 return targ
== &bfd_elf64_powerpc_vec
|| targ
== &bfd_elf64_powerpcle_vec
;
2448 /* Fix bad default arch selected for a 64 bit input bfd when the
2449 default is 32 bit. */
2452 ppc64_elf_object_p (bfd
*abfd
)
2454 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2456 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2458 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2460 /* Relies on arch after 32 bit default being 64 bit default. */
2461 abfd
->arch_info
= abfd
->arch_info
->next
;
2462 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2468 /* Support for core dump NOTE sections. */
2471 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2473 size_t offset
, size
;
2475 if (note
->descsz
!= 504)
2479 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2482 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2488 /* Make a ".reg/999" section. */
2489 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2490 size
, note
->descpos
+ offset
);
2494 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2496 if (note
->descsz
!= 136)
2499 elf_tdata (abfd
)->core_program
2500 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2501 elf_tdata (abfd
)->core_command
2502 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2508 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2521 va_start (ap
, note_type
);
2522 memset (data
, 0, 40);
2523 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2524 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2526 return elfcore_write_note (abfd
, buf
, bufsiz
,
2527 "CORE", note_type
, data
, sizeof (data
));
2538 va_start (ap
, note_type
);
2539 memset (data
, 0, 112);
2540 pid
= va_arg (ap
, long);
2541 bfd_put_32 (abfd
, pid
, data
+ 32);
2542 cursig
= va_arg (ap
, int);
2543 bfd_put_16 (abfd
, cursig
, data
+ 12);
2544 greg
= va_arg (ap
, const void *);
2545 memcpy (data
+ 112, greg
, 384);
2546 memset (data
+ 496, 0, 8);
2548 return elfcore_write_note (abfd
, buf
, bufsiz
,
2549 "CORE", note_type
, data
, sizeof (data
));
2554 /* Merge backend specific data from an object file to the output
2555 object file when linking. */
2558 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2560 /* Check if we have the same endianess. */
2561 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2562 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2563 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2567 if (bfd_big_endian (ibfd
))
2568 msg
= _("%B: compiled for a big endian system "
2569 "and target is little endian");
2571 msg
= _("%B: compiled for a little endian system "
2572 "and target is big endian");
2574 (*_bfd_error_handler
) (msg
, ibfd
);
2576 bfd_set_error (bfd_error_wrong_format
);
2583 /* Add extra PPC sections. */
2585 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2587 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2588 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2589 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2590 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2591 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2592 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2593 { NULL
, 0, 0, 0, 0 }
2596 enum _ppc64_sec_type
{
2602 struct _ppc64_elf_section_data
2604 struct bfd_elf_section_data elf
;
2606 /* An array with one entry for each opd function descriptor. */
2609 /* Points to the function code section for local opd entries. */
2610 asection
**opd_func_sec
;
2611 /* After editing .opd, adjust references to opd local syms. */
2614 /* An array for toc sections, indexed by offset/8.
2615 Specifies the relocation symbol index used at a given toc offset. */
2619 enum _ppc64_sec_type sec_type
:2;
2621 /* Flag set when small branches are detected. Used to
2622 select suitable defaults for the stub group size. */
2623 unsigned int has_14bit_branch
:1;
2626 #define ppc64_elf_section_data(sec) \
2627 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2630 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2632 if (!sec
->used_by_bfd
)
2634 struct _ppc64_elf_section_data
*sdata
;
2635 bfd_size_type amt
= sizeof (*sdata
);
2637 sdata
= bfd_zalloc (abfd
, amt
);
2640 sec
->used_by_bfd
= sdata
;
2643 return _bfd_elf_new_section_hook (abfd
, sec
);
2647 get_opd_info (asection
* sec
)
2650 && ppc64_elf_section_data (sec
) != NULL
2651 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2652 return ppc64_elf_section_data (sec
)->u
.opd_adjust
;
2656 /* Parameters for the qsort hook. */
2657 static asection
*synthetic_opd
;
2658 static bfd_boolean synthetic_relocatable
;
2660 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2663 compare_symbols (const void *ap
, const void *bp
)
2665 const asymbol
*a
= * (const asymbol
**) ap
;
2666 const asymbol
*b
= * (const asymbol
**) bp
;
2668 /* Section symbols first. */
2669 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2671 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2674 /* then .opd symbols. */
2675 if (a
->section
== synthetic_opd
&& b
->section
!= synthetic_opd
)
2677 if (a
->section
!= synthetic_opd
&& b
->section
== synthetic_opd
)
2680 /* then other code symbols. */
2681 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2682 == (SEC_CODE
| SEC_ALLOC
)
2683 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2684 != (SEC_CODE
| SEC_ALLOC
))
2687 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2688 != (SEC_CODE
| SEC_ALLOC
)
2689 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2690 == (SEC_CODE
| SEC_ALLOC
))
2693 if (synthetic_relocatable
)
2695 if (a
->section
->id
< b
->section
->id
)
2698 if (a
->section
->id
> b
->section
->id
)
2702 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2705 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2708 /* For syms with the same value, prefer strong dynamic global function
2709 syms over other syms. */
2710 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2713 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2716 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2719 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2722 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2725 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2728 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2731 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2737 /* Search SYMS for a symbol of the given VALUE. */
2740 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2748 mid
= (lo
+ hi
) >> 1;
2749 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2751 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2761 mid
= (lo
+ hi
) >> 1;
2762 if (syms
[mid
]->section
->id
< id
)
2764 else if (syms
[mid
]->section
->id
> id
)
2766 else if (syms
[mid
]->value
< value
)
2768 else if (syms
[mid
]->value
> value
)
2777 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2781 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2782 long static_count
, asymbol
**static_syms
,
2783 long dyn_count
, asymbol
**dyn_syms
,
2790 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2792 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2797 opd
= bfd_get_section_by_name (abfd
, ".opd");
2801 symcount
= static_count
;
2803 symcount
+= dyn_count
;
2807 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2811 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2813 /* Use both symbol tables. */
2814 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2815 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2817 else if (!relocatable
&& static_count
== 0)
2818 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2820 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2822 synthetic_opd
= opd
;
2823 synthetic_relocatable
= relocatable
;
2824 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2826 if (!relocatable
&& symcount
> 1)
2829 /* Trim duplicate syms, since we may have merged the normal and
2830 dynamic symbols. Actually, we only care about syms that have
2831 different values, so trim any with the same value. */
2832 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2833 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
2834 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
2835 syms
[j
++] = syms
[i
];
2840 if (syms
[i
]->section
== opd
)
2844 for (; i
< symcount
; ++i
)
2845 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2846 != (SEC_CODE
| SEC_ALLOC
))
2847 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2851 for (; i
< symcount
; ++i
)
2852 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2856 for (; i
< symcount
; ++i
)
2857 if (syms
[i
]->section
!= opd
)
2861 for (; i
< symcount
; ++i
)
2862 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2863 != (SEC_CODE
| SEC_ALLOC
))
2868 if (opdsymend
== secsymend
)
2873 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2878 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2879 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2883 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2890 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2894 while (r
< opd
->relocation
+ relcount
2895 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2898 if (r
== opd
->relocation
+ relcount
)
2901 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2904 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2907 sym
= *r
->sym_ptr_ptr
;
2908 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2909 sym
->section
->id
, sym
->value
+ r
->addend
))
2912 size
+= sizeof (asymbol
);
2913 size
+= strlen (syms
[i
]->name
) + 2;
2917 s
= *ret
= bfd_malloc (size
);
2924 names
= (char *) (s
+ count
);
2926 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2930 while (r
< opd
->relocation
+ relcount
2931 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2934 if (r
== opd
->relocation
+ relcount
)
2937 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2940 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2943 sym
= *r
->sym_ptr_ptr
;
2944 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2945 sym
->section
->id
, sym
->value
+ r
->addend
))
2950 s
->section
= sym
->section
;
2951 s
->value
= sym
->value
+ r
->addend
;
2954 len
= strlen (syms
[i
]->name
);
2955 memcpy (names
, syms
[i
]->name
, len
+ 1);
2966 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2970 free_contents_and_exit
:
2978 for (i
= secsymend
; i
< opdsymend
; ++i
)
2982 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2983 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2986 size
+= sizeof (asymbol
);
2987 size
+= strlen (syms
[i
]->name
) + 2;
2991 s
= *ret
= bfd_malloc (size
);
2993 goto free_contents_and_exit
;
2995 names
= (char *) (s
+ count
);
2997 for (i
= secsymend
; i
< opdsymend
; ++i
)
3001 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3002 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3006 asection
*sec
= abfd
->sections
;
3013 long mid
= (lo
+ hi
) >> 1;
3014 if (syms
[mid
]->section
->vma
< ent
)
3016 else if (syms
[mid
]->section
->vma
> ent
)
3020 sec
= syms
[mid
]->section
;
3025 if (lo
>= hi
&& lo
> codesecsym
)
3026 sec
= syms
[lo
- 1]->section
;
3028 for (; sec
!= NULL
; sec
= sec
->next
)
3032 if ((sec
->flags
& SEC_ALLOC
) == 0
3033 || (sec
->flags
& SEC_LOAD
) == 0)
3035 if ((sec
->flags
& SEC_CODE
) != 0)
3038 s
->value
= ent
- s
->section
->vma
;
3041 len
= strlen (syms
[i
]->name
);
3042 memcpy (names
, syms
[i
]->name
, len
+ 1);
3055 /* The following functions are specific to the ELF linker, while
3056 functions above are used generally. Those named ppc64_elf_* are
3057 called by the main ELF linker code. They appear in this file more
3058 or less in the order in which they are called. eg.
3059 ppc64_elf_check_relocs is called early in the link process,
3060 ppc64_elf_finish_dynamic_sections is one of the last functions
3063 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3064 functions have both a function code symbol and a function descriptor
3065 symbol. A call to foo in a relocatable object file looks like:
3072 The function definition in another object file might be:
3076 . .quad .TOC.@tocbase
3082 When the linker resolves the call during a static link, the branch
3083 unsurprisingly just goes to .foo and the .opd information is unused.
3084 If the function definition is in a shared library, things are a little
3085 different: The call goes via a plt call stub, the opd information gets
3086 copied to the plt, and the linker patches the nop.
3094 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3095 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3096 . std 2,40(1) # this is the general idea
3104 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3106 The "reloc ()" notation is supposed to indicate that the linker emits
3107 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3110 What are the difficulties here? Well, firstly, the relocations
3111 examined by the linker in check_relocs are against the function code
3112 sym .foo, while the dynamic relocation in the plt is emitted against
3113 the function descriptor symbol, foo. Somewhere along the line, we need
3114 to carefully copy dynamic link information from one symbol to the other.
3115 Secondly, the generic part of the elf linker will make .foo a dynamic
3116 symbol as is normal for most other backends. We need foo dynamic
3117 instead, at least for an application final link. However, when
3118 creating a shared library containing foo, we need to have both symbols
3119 dynamic so that references to .foo are satisfied during the early
3120 stages of linking. Otherwise the linker might decide to pull in a
3121 definition from some other object, eg. a static library.
3123 Update: As of August 2004, we support a new convention. Function
3124 calls may use the function descriptor symbol, ie. "bl foo". This
3125 behaves exactly as "bl .foo". */
3127 /* The linker needs to keep track of the number of relocs that it
3128 decides to copy as dynamic relocs in check_relocs for each symbol.
3129 This is so that it can later discard them if they are found to be
3130 unnecessary. We store the information in a field extending the
3131 regular ELF linker hash table. */
3133 struct ppc_dyn_relocs
3135 struct ppc_dyn_relocs
*next
;
3137 /* The input section of the reloc. */
3140 /* Total number of relocs copied for the input section. */
3141 bfd_size_type count
;
3143 /* Number of pc-relative relocs copied for the input section. */
3144 bfd_size_type pc_count
;
3147 /* Track GOT entries needed for a given symbol. We might need more
3148 than one got entry per symbol. */
3151 struct got_entry
*next
;
3153 /* The symbol addend that we'll be placing in the GOT. */
3156 /* Unlike other ELF targets, we use separate GOT entries for the same
3157 symbol referenced from different input files. This is to support
3158 automatic multiple TOC/GOT sections, where the TOC base can vary
3159 from one input file to another.
3161 Point to the BFD owning this GOT entry. */
3164 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
3165 TLS_TPREL or TLS_DTPREL for tls entries. */
3168 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
3171 bfd_signed_vma refcount
;
3176 /* The same for PLT. */
3179 struct plt_entry
*next
;
3185 bfd_signed_vma refcount
;
3190 /* Of those relocs that might be copied as dynamic relocs, this macro
3191 selects those that must be copied when linking a shared library,
3192 even when the symbol is local. */
3194 #define MUST_BE_DYN_RELOC(RTYPE) \
3195 ((RTYPE) != R_PPC64_REL32 \
3196 && (RTYPE) != R_PPC64_REL64 \
3197 && (RTYPE) != R_PPC64_REL30)
3199 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3200 copying dynamic variables from a shared lib into an app's dynbss
3201 section, and instead use a dynamic relocation to point into the
3202 shared lib. With code that gcc generates, it's vital that this be
3203 enabled; In the PowerPC64 ABI, the address of a function is actually
3204 the address of a function descriptor, which resides in the .opd
3205 section. gcc uses the descriptor directly rather than going via the
3206 GOT as some other ABI's do, which means that initialized function
3207 pointers must reference the descriptor. Thus, a function pointer
3208 initialized to the address of a function in a shared library will
3209 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3210 redefines the function descriptor symbol to point to the copy. This
3211 presents a problem as a plt entry for that function is also
3212 initialized from the function descriptor symbol and the copy reloc
3213 may not be initialized first. */
3214 #define ELIMINATE_COPY_RELOCS 1
3216 /* Section name for stubs is the associated section name plus this
3218 #define STUB_SUFFIX ".stub"
3221 ppc_stub_long_branch:
3222 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3223 destination, but a 24 bit branch in a stub section will reach.
3226 ppc_stub_plt_branch:
3227 Similar to the above, but a 24 bit branch in the stub section won't
3228 reach its destination.
3229 . addis %r12,%r2,xxx@toc@ha
3230 . ld %r11,xxx@toc@l(%r12)
3235 Used to call a function in a shared library. If it so happens that
3236 the plt entry referenced crosses a 64k boundary, then an extra
3237 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or
3238 xxx+16 as appropriate.
3239 . addis %r12,%r2,xxx@toc@ha
3241 . ld %r11,xxx+0@toc@l(%r12)
3242 . ld %r2,xxx+8@toc@l(%r12)
3244 . ld %r11,xxx+16@toc@l(%r12)
3247 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3248 code to adjust the value and save r2 to support multiple toc sections.
3249 A ppc_stub_long_branch with an r2 offset looks like:
3251 . addis %r2,%r2,off@ha
3252 . addi %r2,%r2,off@l
3255 A ppc_stub_plt_branch with an r2 offset looks like:
3257 . addis %r12,%r2,xxx@toc@ha
3258 . ld %r11,xxx@toc@l(%r12)
3259 . addis %r2,%r2,off@ha
3260 . addi %r2,%r2,off@l
3265 enum ppc_stub_type
{
3267 ppc_stub_long_branch
,
3268 ppc_stub_long_branch_r2off
,
3269 ppc_stub_plt_branch
,
3270 ppc_stub_plt_branch_r2off
,
3274 struct ppc_stub_hash_entry
{
3276 /* Base hash table entry structure. */
3277 struct bfd_hash_entry root
;
3279 enum ppc_stub_type stub_type
;
3281 /* The stub section. */
3284 /* Offset within stub_sec of the beginning of this stub. */
3285 bfd_vma stub_offset
;
3287 /* Given the symbol's value and its section we can determine its final
3288 value when building the stubs (so the stub knows where to jump. */
3289 bfd_vma target_value
;
3290 asection
*target_section
;
3292 /* The symbol table entry, if any, that this was derived from. */
3293 struct ppc_link_hash_entry
*h
;
3295 /* And the reloc addend that this was derived from. */
3298 /* Where this stub is being called from, or, in the case of combined
3299 stub sections, the first input section in the group. */
3303 struct ppc_branch_hash_entry
{
3305 /* Base hash table entry structure. */
3306 struct bfd_hash_entry root
;
3308 /* Offset within branch lookup table. */
3309 unsigned int offset
;
3311 /* Generation marker. */
3315 struct ppc_link_hash_entry
3317 struct elf_link_hash_entry elf
;
3320 /* A pointer to the most recently used stub hash entry against this
3322 struct ppc_stub_hash_entry
*stub_cache
;
3324 /* A pointer to the next symbol starting with a '.' */
3325 struct ppc_link_hash_entry
*next_dot_sym
;
3328 /* Track dynamic relocs copied for this symbol. */
3329 struct ppc_dyn_relocs
*dyn_relocs
;
3331 /* Link between function code and descriptor symbols. */
3332 struct ppc_link_hash_entry
*oh
;
3334 /* Flag function code and descriptor symbols. */
3335 unsigned int is_func
:1;
3336 unsigned int is_func_descriptor
:1;
3337 unsigned int fake
:1;
3339 /* Whether global opd/toc sym has been adjusted or not.
3340 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3341 should be set for all globals defined in any opd/toc section. */
3342 unsigned int adjust_done
:1;
3344 /* Set if we twiddled this symbol to weak at some stage. */
3345 unsigned int was_undefined
:1;
3347 /* Contexts in which symbol is used in the GOT (or TOC).
3348 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3349 corresponding relocs are encountered during check_relocs.
3350 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3351 indicate the corresponding GOT entry type is not needed.
3352 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3353 a TPREL one. We use a separate flag rather than setting TPREL
3354 just for convenience in distinguishing the two cases. */
3355 #define TLS_GD 1 /* GD reloc. */
3356 #define TLS_LD 2 /* LD reloc. */
3357 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3358 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3359 #define TLS_TLS 16 /* Any TLS reloc. */
3360 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3361 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3365 /* ppc64 ELF linker hash table. */
3367 struct ppc_link_hash_table
3369 struct elf_link_hash_table elf
;
3371 /* The stub hash table. */
3372 struct bfd_hash_table stub_hash_table
;
3374 /* Another hash table for plt_branch stubs. */
3375 struct bfd_hash_table branch_hash_table
;
3377 /* Linker stub bfd. */
3380 /* Linker call-backs. */
3381 asection
* (*add_stub_section
) (const char *, asection
*);
3382 void (*layout_sections_again
) (void);
3384 /* Array to keep track of which stub sections have been created, and
3385 information on stub grouping. */
3387 /* This is the section to which stubs in the group will be attached. */
3389 /* The stub section. */
3391 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3395 /* Temp used when calculating TOC pointers. */
3398 /* Highest input section id. */
3401 /* Highest output section index. */
3404 /* Used when adding symbols. */
3405 struct ppc_link_hash_entry
*dot_syms
;
3407 /* List of input sections for each output section. */
3408 asection
**input_list
;
3410 /* Short-cuts to get to dynamic linker sections. */
3421 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3422 struct ppc_link_hash_entry
*tls_get_addr
;
3423 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3426 unsigned long stub_count
[ppc_stub_plt_call
];
3428 /* Number of stubs against global syms. */
3429 unsigned long stub_globals
;
3431 /* Set if we should emit symbols for stubs. */
3432 unsigned int emit_stub_syms
:1;
3434 /* Support for multiple toc sections. */
3435 unsigned int no_multi_toc
:1;
3436 unsigned int multi_toc_needed
:1;
3439 unsigned int stub_error
:1;
3441 /* Temp used by ppc64_elf_check_directives. */
3442 unsigned int twiddled_syms
:1;
3444 /* Incremented every time we size stubs. */
3445 unsigned int stub_iteration
;
3447 /* Small local sym to section mapping cache. */
3448 struct sym_sec_cache sym_sec
;
3451 /* Rename some of the generic section flags to better document how they
3453 #define has_toc_reloc has_gp_reloc
3454 #define makes_toc_func_call need_finalize_relax
3455 #define call_check_in_progress reloc_done
3457 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3459 #define ppc_hash_table(p) \
3460 ((struct ppc_link_hash_table *) ((p)->hash))
3462 #define ppc_stub_hash_lookup(table, string, create, copy) \
3463 ((struct ppc_stub_hash_entry *) \
3464 bfd_hash_lookup ((table), (string), (create), (copy)))
3466 #define ppc_branch_hash_lookup(table, string, create, copy) \
3467 ((struct ppc_branch_hash_entry *) \
3468 bfd_hash_lookup ((table), (string), (create), (copy)))
3470 /* Create an entry in the stub hash table. */
3472 static struct bfd_hash_entry
*
3473 stub_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_stub_hash_entry
));
3486 /* Call the allocation method of the superclass. */
3487 entry
= bfd_hash_newfunc (entry
, table
, string
);
3490 struct ppc_stub_hash_entry
*eh
;
3492 /* Initialize the local fields. */
3493 eh
= (struct ppc_stub_hash_entry
*) entry
;
3494 eh
->stub_type
= ppc_stub_none
;
3495 eh
->stub_sec
= NULL
;
3496 eh
->stub_offset
= 0;
3497 eh
->target_value
= 0;
3498 eh
->target_section
= NULL
;
3506 /* Create an entry in the branch hash table. */
3508 static struct bfd_hash_entry
*
3509 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3510 struct bfd_hash_table
*table
,
3513 /* Allocate the structure if it has not already been allocated by a
3517 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3522 /* Call the allocation method of the superclass. */
3523 entry
= bfd_hash_newfunc (entry
, table
, string
);
3526 struct ppc_branch_hash_entry
*eh
;
3528 /* Initialize the local fields. */
3529 eh
= (struct ppc_branch_hash_entry
*) entry
;
3537 /* Create an entry in a ppc64 ELF linker hash table. */
3539 static struct bfd_hash_entry
*
3540 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3541 struct bfd_hash_table
*table
,
3544 /* Allocate the structure if it has not already been allocated by a
3548 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3553 /* Call the allocation method of the superclass. */
3554 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3557 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3559 memset (&eh
->u
.stub_cache
, 0,
3560 (sizeof (struct ppc_link_hash_entry
)
3561 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3563 /* When making function calls, old ABI code references function entry
3564 points (dot symbols), while new ABI code references the function
3565 descriptor symbol. We need to make any combination of reference and
3566 definition work together, without breaking archive linking.
3568 For a defined function "foo" and an undefined call to "bar":
3569 An old object defines "foo" and ".foo", references ".bar" (possibly
3571 A new object defines "foo" and references "bar".
3573 A new object thus has no problem with its undefined symbols being
3574 satisfied by definitions in an old object. On the other hand, the
3575 old object won't have ".bar" satisfied by a new object.
3577 Keep a list of newly added dot-symbols. */
3579 if (string
[0] == '.')
3581 struct ppc_link_hash_table
*htab
;
3583 htab
= (struct ppc_link_hash_table
*) table
;
3584 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3585 htab
->dot_syms
= eh
;
3592 /* Create a ppc64 ELF linker hash table. */
3594 static struct bfd_link_hash_table
*
3595 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3597 struct ppc_link_hash_table
*htab
;
3598 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3600 htab
= bfd_zmalloc (amt
);
3604 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3605 sizeof (struct ppc_link_hash_entry
)))
3611 /* Init the stub hash table too. */
3612 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3613 sizeof (struct ppc_stub_hash_entry
)))
3616 /* And the branch hash table. */
3617 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3618 sizeof (struct ppc_branch_hash_entry
)))
3621 /* Initializing two fields of the union is just cosmetic. We really
3622 only care about glist, but when compiled on a 32-bit host the
3623 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3624 debugger inspection of these fields look nicer. */
3625 htab
->elf
.init_got_refcount
.refcount
= 0;
3626 htab
->elf
.init_got_refcount
.glist
= NULL
;
3627 htab
->elf
.init_plt_refcount
.refcount
= 0;
3628 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3629 htab
->elf
.init_got_offset
.offset
= 0;
3630 htab
->elf
.init_got_offset
.glist
= NULL
;
3631 htab
->elf
.init_plt_offset
.offset
= 0;
3632 htab
->elf
.init_plt_offset
.glist
= NULL
;
3634 return &htab
->elf
.root
;
3637 /* Free the derived linker hash table. */
3640 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3642 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3644 bfd_hash_table_free (&ret
->stub_hash_table
);
3645 bfd_hash_table_free (&ret
->branch_hash_table
);
3646 _bfd_generic_link_hash_table_free (hash
);
3649 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3652 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3654 struct ppc_link_hash_table
*htab
;
3656 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3658 /* Always hook our dynamic sections into the first bfd, which is the
3659 linker created stub bfd. This ensures that the GOT header is at
3660 the start of the output TOC section. */
3661 htab
= ppc_hash_table (info
);
3662 htab
->stub_bfd
= abfd
;
3663 htab
->elf
.dynobj
= abfd
;
3666 /* Build a name for an entry in the stub hash table. */
3669 ppc_stub_name (const asection
*input_section
,
3670 const asection
*sym_sec
,
3671 const struct ppc_link_hash_entry
*h
,
3672 const Elf_Internal_Rela
*rel
)
3677 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3678 offsets from a sym as a branch target? In fact, we could
3679 probably assume the addend is always zero. */
3680 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3684 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3685 stub_name
= bfd_malloc (len
);
3686 if (stub_name
== NULL
)
3689 sprintf (stub_name
, "%08x.%s+%x",
3690 input_section
->id
& 0xffffffff,
3691 h
->elf
.root
.root
.string
,
3692 (int) rel
->r_addend
& 0xffffffff);
3696 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3697 stub_name
= bfd_malloc (len
);
3698 if (stub_name
== NULL
)
3701 sprintf (stub_name
, "%08x.%x:%x+%x",
3702 input_section
->id
& 0xffffffff,
3703 sym_sec
->id
& 0xffffffff,
3704 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3705 (int) rel
->r_addend
& 0xffffffff);
3707 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3708 stub_name
[len
- 2] = 0;
3712 /* Look up an entry in the stub hash. Stub entries are cached because
3713 creating the stub name takes a bit of time. */
3715 static struct ppc_stub_hash_entry
*
3716 ppc_get_stub_entry (const asection
*input_section
,
3717 const asection
*sym_sec
,
3718 struct ppc_link_hash_entry
*h
,
3719 const Elf_Internal_Rela
*rel
,
3720 struct ppc_link_hash_table
*htab
)
3722 struct ppc_stub_hash_entry
*stub_entry
;
3723 const asection
*id_sec
;
3725 /* If this input section is part of a group of sections sharing one
3726 stub section, then use the id of the first section in the group.
3727 Stub names need to include a section id, as there may well be
3728 more than one stub used to reach say, printf, and we need to
3729 distinguish between them. */
3730 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3732 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3733 && h
->u
.stub_cache
->h
== h
3734 && h
->u
.stub_cache
->id_sec
== id_sec
)
3736 stub_entry
= h
->u
.stub_cache
;
3742 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3743 if (stub_name
== NULL
)
3746 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3747 stub_name
, FALSE
, FALSE
);
3749 h
->u
.stub_cache
= stub_entry
;
3757 /* Add a new stub entry to the stub hash. Not all fields of the new
3758 stub entry are initialised. */
3760 static struct ppc_stub_hash_entry
*
3761 ppc_add_stub (const char *stub_name
,
3763 struct ppc_link_hash_table
*htab
)
3767 struct ppc_stub_hash_entry
*stub_entry
;
3769 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3770 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3771 if (stub_sec
== NULL
)
3773 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3774 if (stub_sec
== NULL
)
3780 namelen
= strlen (link_sec
->name
);
3781 len
= namelen
+ sizeof (STUB_SUFFIX
);
3782 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3786 memcpy (s_name
, link_sec
->name
, namelen
);
3787 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3788 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3789 if (stub_sec
== NULL
)
3791 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3793 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3796 /* Enter this entry into the linker stub hash table. */
3797 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3799 if (stub_entry
== NULL
)
3801 (*_bfd_error_handler
) (_("%B: cannot create stub entry %s"),
3802 section
->owner
, stub_name
);
3806 stub_entry
->stub_sec
= stub_sec
;
3807 stub_entry
->stub_offset
= 0;
3808 stub_entry
->id_sec
= link_sec
;
3812 /* Create sections for linker generated code. */
3815 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3817 struct ppc_link_hash_table
*htab
;
3820 htab
= ppc_hash_table (info
);
3822 /* Create .sfpr for code to save and restore fp regs. */
3823 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3824 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3825 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3827 if (htab
->sfpr
== NULL
3828 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3831 /* Create .glink for lazy dynamic linking support. */
3832 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3834 if (htab
->glink
== NULL
3835 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3838 /* Create branch lookup table for plt_branch stubs. */
3839 flags
= (SEC_ALLOC
| SEC_LOAD
3840 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3841 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3843 if (htab
->brlt
== NULL
3844 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3850 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3851 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3852 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
3856 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3862 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3863 not already done. */
3866 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3868 asection
*got
, *relgot
;
3870 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3874 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3877 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
3882 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3883 | SEC_LINKER_CREATED
);
3885 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3887 || !bfd_set_section_alignment (abfd
, got
, 3))
3890 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3891 flags
| SEC_READONLY
);
3893 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
3896 ppc64_elf_tdata (abfd
)->got
= got
;
3897 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3901 /* Create the dynamic sections, and set up shortcuts. */
3904 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3906 struct ppc_link_hash_table
*htab
;
3908 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3911 htab
= ppc_hash_table (info
);
3913 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
3914 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
3915 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3916 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3918 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3920 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
3921 || (!info
->shared
&& !htab
->relbss
))
3927 /* Merge PLT info on FROM with that on TO. */
3930 move_plt_plist (struct ppc_link_hash_entry
*from
,
3931 struct ppc_link_hash_entry
*to
)
3933 if (from
->elf
.plt
.plist
!= NULL
)
3935 if (to
->elf
.plt
.plist
!= NULL
)
3937 struct plt_entry
**entp
;
3938 struct plt_entry
*ent
;
3940 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3942 struct plt_entry
*dent
;
3944 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3945 if (dent
->addend
== ent
->addend
)
3947 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3954 *entp
= to
->elf
.plt
.plist
;
3957 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3958 from
->elf
.plt
.plist
= NULL
;
3962 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3965 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3966 struct elf_link_hash_entry
*dir
,
3967 struct elf_link_hash_entry
*ind
)
3969 struct ppc_link_hash_entry
*edir
, *eind
;
3971 edir
= (struct ppc_link_hash_entry
*) dir
;
3972 eind
= (struct ppc_link_hash_entry
*) ind
;
3974 /* Copy over any dynamic relocs we may have on the indirect sym. */
3975 if (eind
->dyn_relocs
!= NULL
)
3977 if (edir
->dyn_relocs
!= NULL
)
3979 struct ppc_dyn_relocs
**pp
;
3980 struct ppc_dyn_relocs
*p
;
3982 /* Add reloc counts against the indirect sym to the direct sym
3983 list. Merge any entries against the same section. */
3984 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3986 struct ppc_dyn_relocs
*q
;
3988 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3989 if (q
->sec
== p
->sec
)
3991 q
->pc_count
+= p
->pc_count
;
3992 q
->count
+= p
->count
;
3999 *pp
= edir
->dyn_relocs
;
4002 edir
->dyn_relocs
= eind
->dyn_relocs
;
4003 eind
->dyn_relocs
= NULL
;
4006 edir
->is_func
|= eind
->is_func
;
4007 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4008 edir
->tls_mask
|= eind
->tls_mask
;
4010 /* If called to transfer flags for a weakdef during processing
4011 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4012 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4013 if (!(ELIMINATE_COPY_RELOCS
4014 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4015 && edir
->elf
.dynamic_adjusted
))
4016 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4018 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4019 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4020 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4021 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4023 /* If we were called to copy over info for a weak sym, that's all. */
4024 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4027 /* Copy over got entries that we may have already seen to the
4028 symbol which just became indirect. */
4029 if (eind
->elf
.got
.glist
!= NULL
)
4031 if (edir
->elf
.got
.glist
!= NULL
)
4033 struct got_entry
**entp
;
4034 struct got_entry
*ent
;
4036 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4038 struct got_entry
*dent
;
4040 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4041 if (dent
->addend
== ent
->addend
4042 && dent
->owner
== ent
->owner
4043 && dent
->tls_type
== ent
->tls_type
)
4045 dent
->got
.refcount
+= ent
->got
.refcount
;
4052 *entp
= edir
->elf
.got
.glist
;
4055 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4056 eind
->elf
.got
.glist
= NULL
;
4059 /* And plt entries. */
4060 move_plt_plist (eind
, edir
);
4062 if (eind
->elf
.dynindx
!= -1)
4064 if (edir
->elf
.dynindx
!= -1)
4065 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4066 edir
->elf
.dynstr_index
);
4067 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4068 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4069 eind
->elf
.dynindx
= -1;
4070 eind
->elf
.dynstr_index
= 0;
4074 /* Find the function descriptor hash entry from the given function code
4075 hash entry FH. Link the entries via their OH fields. */
4077 static struct ppc_link_hash_entry
*
4078 get_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4080 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4084 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4086 fdh
= (struct ppc_link_hash_entry
*)
4087 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4090 fdh
->is_func_descriptor
= 1;
4100 /* Make a fake function descriptor sym for the code sym FH. */
4102 static struct ppc_link_hash_entry
*
4103 make_fdh (struct bfd_link_info
*info
,
4104 struct ppc_link_hash_entry
*fh
)
4108 struct bfd_link_hash_entry
*bh
;
4109 struct ppc_link_hash_entry
*fdh
;
4111 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4112 newsym
= bfd_make_empty_symbol (abfd
);
4113 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4114 newsym
->section
= bfd_und_section_ptr
;
4116 newsym
->flags
= BSF_WEAK
;
4119 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4120 newsym
->flags
, newsym
->section
,
4121 newsym
->value
, NULL
, FALSE
, FALSE
,
4125 fdh
= (struct ppc_link_hash_entry
*) bh
;
4126 fdh
->elf
.non_elf
= 0;
4128 fdh
->is_func_descriptor
= 1;
4135 /* Fix function descriptor symbols defined in .opd sections to be
4139 ppc64_elf_add_symbol_hook (bfd
*ibfd ATTRIBUTE_UNUSED
,
4140 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4141 Elf_Internal_Sym
*isym
,
4142 const char **name ATTRIBUTE_UNUSED
,
4143 flagword
*flags ATTRIBUTE_UNUSED
,
4145 bfd_vma
*value ATTRIBUTE_UNUSED
)
4148 && strcmp (bfd_get_section_name (ibfd
, *sec
), ".opd") == 0)
4149 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4154 /* This function makes an old ABI object reference to ".bar" cause the
4155 inclusion of a new ABI object archive that defines "bar".
4156 NAME is a symbol defined in an archive. Return a symbol in the hash
4157 table that might be satisfied by the archive symbols. */
4159 static struct elf_link_hash_entry
*
4160 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4161 struct bfd_link_info
*info
,
4164 struct elf_link_hash_entry
*h
;
4168 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4170 /* Don't return this sym if it is a fake function descriptor
4171 created by add_symbol_adjust. */
4172 && !(h
->root
.type
== bfd_link_hash_undefweak
4173 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4179 len
= strlen (name
);
4180 dot_name
= bfd_alloc (abfd
, len
+ 2);
4181 if (dot_name
== NULL
)
4182 return (struct elf_link_hash_entry
*) 0 - 1;
4184 memcpy (dot_name
+ 1, name
, len
+ 1);
4185 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4186 bfd_release (abfd
, dot_name
);
4190 /* This function satisfies all old ABI object references to ".bar" if a
4191 new ABI object defines "bar". Well, at least, undefined dot symbols
4192 are made weak. This stops later archive searches from including an
4193 object if we already have a function descriptor definition. It also
4194 prevents the linker complaining about undefined symbols.
4195 We also check and correct mismatched symbol visibility here. The
4196 most restrictive visibility of the function descriptor and the
4197 function entry symbol is used. */
4200 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4202 struct ppc_link_hash_table
*htab
;
4203 struct ppc_link_hash_entry
*fdh
;
4205 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4208 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4209 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4211 if (eh
->elf
.root
.root
.string
[0] != '.')
4214 htab
= ppc_hash_table (info
);
4215 fdh
= get_fdh (eh
, htab
);
4217 && !info
->relocatable
4218 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4219 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4220 && eh
->elf
.ref_regular
)
4222 /* Make an undefweak function descriptor sym, which is enough to
4223 pull in an --as-needed shared lib, but won't cause link
4224 errors. Archives are handled elsewhere. */
4225 fdh
= make_fdh (info
, eh
);
4229 fdh
->elf
.ref_regular
= 1;
4231 else if (fdh
!= NULL
)
4233 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4234 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4235 if (entry_vis
< descr_vis
)
4236 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4237 else if (entry_vis
> descr_vis
)
4238 eh
->elf
.other
+= descr_vis
- entry_vis
;
4240 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4241 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4242 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4244 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4245 eh
->was_undefined
= 1;
4246 htab
->twiddled_syms
= 1;
4253 /* Process list of dot-symbols we made in link_hash_newfunc. */
4256 ppc64_elf_check_directives (bfd
*ibfd
, struct bfd_link_info
*info
)
4258 struct ppc_link_hash_table
*htab
;
4259 struct ppc_link_hash_entry
**p
, *eh
;
4261 htab
= ppc_hash_table (info
);
4262 if (!is_ppc64_elf_target (htab
->elf
.root
.creator
))
4265 if (is_ppc64_elf_target (ibfd
->xvec
))
4267 p
= &htab
->dot_syms
;
4268 while ((eh
= *p
) != NULL
)
4271 if (!add_symbol_adjust (eh
, info
))
4273 p
= &eh
->u
.next_dot_sym
;
4277 /* Clear the list for non-ppc64 input files. */
4278 p
= &htab
->dot_syms
;
4279 while ((eh
= *p
) != NULL
)
4282 p
= &eh
->u
.next_dot_sym
;
4285 /* We need to fix the undefs list for any syms we have twiddled to
4287 if (htab
->twiddled_syms
)
4289 bfd_link_repair_undef_list (&htab
->elf
.root
);
4290 htab
->twiddled_syms
= 0;
4295 /* Undo hash table changes when an --as-needed input file is determined
4296 not to be needed. */
4299 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4300 struct bfd_link_info
*info
)
4302 ppc_hash_table (info
)->dot_syms
= NULL
;
4307 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4308 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4310 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4311 char *local_got_tls_masks
;
4313 if (local_got_ents
== NULL
)
4315 bfd_size_type size
= symtab_hdr
->sh_info
;
4317 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
4318 local_got_ents
= bfd_zalloc (abfd
, size
);
4319 if (local_got_ents
== NULL
)
4321 elf_local_got_ents (abfd
) = local_got_ents
;
4324 if ((tls_type
& TLS_EXPLICIT
) == 0)
4326 struct got_entry
*ent
;
4328 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4329 if (ent
->addend
== r_addend
4330 && ent
->owner
== abfd
4331 && ent
->tls_type
== tls_type
)
4335 bfd_size_type amt
= sizeof (*ent
);
4336 ent
= bfd_alloc (abfd
, amt
);
4339 ent
->next
= local_got_ents
[r_symndx
];
4340 ent
->addend
= r_addend
;
4342 ent
->tls_type
= tls_type
;
4343 ent
->got
.refcount
= 0;
4344 local_got_ents
[r_symndx
] = ent
;
4346 ent
->got
.refcount
+= 1;
4349 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
4350 local_got_tls_masks
[r_symndx
] |= tls_type
;
4355 update_plt_info (bfd
*abfd
, struct ppc_link_hash_entry
*eh
, bfd_vma addend
)
4357 struct plt_entry
*ent
;
4359 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4360 if (ent
->addend
== addend
)
4364 bfd_size_type amt
= sizeof (*ent
);
4365 ent
= bfd_alloc (abfd
, amt
);
4368 ent
->next
= eh
->elf
.plt
.plist
;
4369 ent
->addend
= addend
;
4370 ent
->plt
.refcount
= 0;
4371 eh
->elf
.plt
.plist
= ent
;
4373 ent
->plt
.refcount
+= 1;
4374 eh
->elf
.needs_plt
= 1;
4375 if (eh
->elf
.root
.root
.string
[0] == '.'
4376 && eh
->elf
.root
.root
.string
[1] != '\0')
4381 /* Look through the relocs for a section during the first phase, and
4382 calculate needed space in the global offset table, procedure
4383 linkage table, and dynamic reloc sections. */
4386 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4387 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4389 struct ppc_link_hash_table
*htab
;
4390 Elf_Internal_Shdr
*symtab_hdr
;
4391 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
4392 const Elf_Internal_Rela
*rel
;
4393 const Elf_Internal_Rela
*rel_end
;
4395 asection
**opd_sym_map
;
4397 if (info
->relocatable
)
4400 /* Don't do anything special with non-loaded, non-alloced sections.
4401 In particular, any relocs in such sections should not affect GOT
4402 and PLT reference counting (ie. we don't allow them to create GOT
4403 or PLT entries), there's no possibility or desire to optimize TLS
4404 relocs, and there's not much point in propagating relocs to shared
4405 libs that the dynamic linker won't relocate. */
4406 if ((sec
->flags
& SEC_ALLOC
) == 0)
4409 htab
= ppc_hash_table (info
);
4410 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4412 sym_hashes
= elf_sym_hashes (abfd
);
4413 sym_hashes_end
= (sym_hashes
4414 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
4415 - symtab_hdr
->sh_info
);
4419 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
4421 /* Garbage collection needs some extra help with .opd sections.
4422 We don't want to necessarily keep everything referenced by
4423 relocs in .opd, as that would keep all functions. Instead,
4424 if we reference an .opd symbol (a function descriptor), we
4425 want to keep the function code symbol's section. This is
4426 easy for global symbols, but for local syms we need to keep
4427 information about the associated function section. Later, if
4428 edit_opd deletes entries, we'll use this array to adjust
4429 local syms in .opd. */
4431 asection
*func_section
;
4436 amt
= sec
->size
* sizeof (union opd_info
) / 8;
4437 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4438 if (opd_sym_map
== NULL
)
4440 ppc64_elf_section_data (sec
)->u
.opd_func_sec
= opd_sym_map
;
4441 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4442 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4445 if (htab
->sfpr
== NULL
4446 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4449 rel_end
= relocs
+ sec
->reloc_count
;
4450 for (rel
= relocs
; rel
< rel_end
; rel
++)
4452 unsigned long r_symndx
;
4453 struct elf_link_hash_entry
*h
;
4454 enum elf_ppc64_reloc_type r_type
;
4456 struct _ppc64_elf_section_data
*ppc64_sec
;
4458 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4459 if (r_symndx
< symtab_hdr
->sh_info
)
4463 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4464 while (h
->root
.type
== bfd_link_hash_indirect
4465 || h
->root
.type
== bfd_link_hash_warning
)
4466 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4469 r_type
= ELF64_R_TYPE (rel
->r_info
);
4472 case R_PPC64_GOT_TLSLD16
:
4473 case R_PPC64_GOT_TLSLD16_LO
:
4474 case R_PPC64_GOT_TLSLD16_HI
:
4475 case R_PPC64_GOT_TLSLD16_HA
:
4476 ppc64_tlsld_got (abfd
)->refcount
+= 1;
4477 tls_type
= TLS_TLS
| TLS_LD
;
4480 case R_PPC64_GOT_TLSGD16
:
4481 case R_PPC64_GOT_TLSGD16_LO
:
4482 case R_PPC64_GOT_TLSGD16_HI
:
4483 case R_PPC64_GOT_TLSGD16_HA
:
4484 tls_type
= TLS_TLS
| TLS_GD
;
4487 case R_PPC64_GOT_TPREL16_DS
:
4488 case R_PPC64_GOT_TPREL16_LO_DS
:
4489 case R_PPC64_GOT_TPREL16_HI
:
4490 case R_PPC64_GOT_TPREL16_HA
:
4492 info
->flags
|= DF_STATIC_TLS
;
4493 tls_type
= TLS_TLS
| TLS_TPREL
;
4496 case R_PPC64_GOT_DTPREL16_DS
:
4497 case R_PPC64_GOT_DTPREL16_LO_DS
:
4498 case R_PPC64_GOT_DTPREL16_HI
:
4499 case R_PPC64_GOT_DTPREL16_HA
:
4500 tls_type
= TLS_TLS
| TLS_DTPREL
;
4502 sec
->has_tls_reloc
= 1;
4506 case R_PPC64_GOT16_DS
:
4507 case R_PPC64_GOT16_HA
:
4508 case R_PPC64_GOT16_HI
:
4509 case R_PPC64_GOT16_LO
:
4510 case R_PPC64_GOT16_LO_DS
:
4511 /* This symbol requires a global offset table entry. */
4512 sec
->has_toc_reloc
= 1;
4513 if (ppc64_elf_tdata (abfd
)->got
== NULL
4514 && !create_got_section (abfd
, info
))
4519 struct ppc_link_hash_entry
*eh
;
4520 struct got_entry
*ent
;
4522 eh
= (struct ppc_link_hash_entry
*) h
;
4523 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4524 if (ent
->addend
== rel
->r_addend
4525 && ent
->owner
== abfd
4526 && ent
->tls_type
== tls_type
)
4530 bfd_size_type amt
= sizeof (*ent
);
4531 ent
= bfd_alloc (abfd
, amt
);
4534 ent
->next
= eh
->elf
.got
.glist
;
4535 ent
->addend
= rel
->r_addend
;
4537 ent
->tls_type
= tls_type
;
4538 ent
->got
.refcount
= 0;
4539 eh
->elf
.got
.glist
= ent
;
4541 ent
->got
.refcount
+= 1;
4542 eh
->tls_mask
|= tls_type
;
4545 /* This is a global offset table entry for a local symbol. */
4546 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4547 rel
->r_addend
, tls_type
))
4551 case R_PPC64_PLT16_HA
:
4552 case R_PPC64_PLT16_HI
:
4553 case R_PPC64_PLT16_LO
:
4556 /* This symbol requires a procedure linkage table entry. We
4557 actually build the entry in adjust_dynamic_symbol,
4558 because this might be a case of linking PIC code without
4559 linking in any dynamic objects, in which case we don't
4560 need to generate a procedure linkage table after all. */
4563 /* It does not make sense to have a procedure linkage
4564 table entry for a local symbol. */
4565 bfd_set_error (bfd_error_bad_value
);
4569 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4574 /* The following relocations don't need to propagate the
4575 relocation if linking a shared object since they are
4576 section relative. */
4577 case R_PPC64_SECTOFF
:
4578 case R_PPC64_SECTOFF_LO
:
4579 case R_PPC64_SECTOFF_HI
:
4580 case R_PPC64_SECTOFF_HA
:
4581 case R_PPC64_SECTOFF_DS
:
4582 case R_PPC64_SECTOFF_LO_DS
:
4583 case R_PPC64_DTPREL16
:
4584 case R_PPC64_DTPREL16_LO
:
4585 case R_PPC64_DTPREL16_HI
:
4586 case R_PPC64_DTPREL16_HA
:
4587 case R_PPC64_DTPREL16_DS
:
4588 case R_PPC64_DTPREL16_LO_DS
:
4589 case R_PPC64_DTPREL16_HIGHER
:
4590 case R_PPC64_DTPREL16_HIGHERA
:
4591 case R_PPC64_DTPREL16_HIGHEST
:
4592 case R_PPC64_DTPREL16_HIGHESTA
:
4597 case R_PPC64_TOC16_LO
:
4598 case R_PPC64_TOC16_HI
:
4599 case R_PPC64_TOC16_HA
:
4600 case R_PPC64_TOC16_DS
:
4601 case R_PPC64_TOC16_LO_DS
:
4602 sec
->has_toc_reloc
= 1;
4605 /* This relocation describes the C++ object vtable hierarchy.
4606 Reconstruct it for later use during GC. */
4607 case R_PPC64_GNU_VTINHERIT
:
4608 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4612 /* This relocation describes which C++ vtable entries are actually
4613 used. Record for later use during GC. */
4614 case R_PPC64_GNU_VTENTRY
:
4615 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4620 case R_PPC64_REL14_BRTAKEN
:
4621 case R_PPC64_REL14_BRNTAKEN
:
4623 asection
*dest
= NULL
;
4625 /* Heuristic: If jumping outside our section, chances are
4626 we are going to need a stub. */
4629 /* If the sym is weak it may be overridden later, so
4630 don't assume we know where a weak sym lives. */
4631 if (h
->root
.type
== bfd_link_hash_defined
)
4632 dest
= h
->root
.u
.def
.section
;
4635 dest
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4638 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4645 /* We may need a .plt entry if the function this reloc
4646 refers to is in a shared lib. */
4647 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4650 if (h
== &htab
->tls_get_addr
->elf
4651 || h
== &htab
->tls_get_addr_fd
->elf
)
4652 sec
->has_tls_reloc
= 1;
4653 else if (htab
->tls_get_addr
== NULL
4654 && CONST_STRNEQ (h
->root
.root
.string
, ".__tls_get_addr")
4655 && (h
->root
.root
.string
[15] == 0
4656 || h
->root
.root
.string
[15] == '@'))
4658 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) h
;
4659 sec
->has_tls_reloc
= 1;
4661 else if (htab
->tls_get_addr_fd
== NULL
4662 && CONST_STRNEQ (h
->root
.root
.string
, "__tls_get_addr")
4663 && (h
->root
.root
.string
[14] == 0
4664 || h
->root
.root
.string
[14] == '@'))
4666 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) h
;
4667 sec
->has_tls_reloc
= 1;
4672 case R_PPC64_TPREL64
:
4673 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4675 info
->flags
|= DF_STATIC_TLS
;
4678 case R_PPC64_DTPMOD64
:
4679 if (rel
+ 1 < rel_end
4680 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4681 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4682 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4684 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4687 case R_PPC64_DTPREL64
:
4688 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4690 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4691 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4692 /* This is the second reloc of a dtpmod, dtprel pair.
4693 Don't mark with TLS_DTPREL. */
4697 sec
->has_tls_reloc
= 1;
4700 struct ppc_link_hash_entry
*eh
;
4701 eh
= (struct ppc_link_hash_entry
*) h
;
4702 eh
->tls_mask
|= tls_type
;
4705 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4706 rel
->r_addend
, tls_type
))
4709 ppc64_sec
= ppc64_elf_section_data (sec
);
4710 if (ppc64_sec
->sec_type
!= sec_toc
)
4712 /* One extra to simplify get_tls_mask. */
4713 bfd_size_type amt
= sec
->size
* sizeof (unsigned) / 8 + 1;
4714 ppc64_sec
->u
.t_symndx
= bfd_zalloc (abfd
, amt
);
4715 if (ppc64_sec
->u
.t_symndx
== NULL
)
4717 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4718 ppc64_sec
->sec_type
= sec_toc
;
4720 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4721 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
4723 /* Mark the second slot of a GD or LD entry.
4724 -1 to indicate GD and -2 to indicate LD. */
4725 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4726 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
4727 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4728 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
4731 case R_PPC64_TPREL16
:
4732 case R_PPC64_TPREL16_LO
:
4733 case R_PPC64_TPREL16_HI
:
4734 case R_PPC64_TPREL16_HA
:
4735 case R_PPC64_TPREL16_DS
:
4736 case R_PPC64_TPREL16_LO_DS
:
4737 case R_PPC64_TPREL16_HIGHER
:
4738 case R_PPC64_TPREL16_HIGHERA
:
4739 case R_PPC64_TPREL16_HIGHEST
:
4740 case R_PPC64_TPREL16_HIGHESTA
:
4743 info
->flags
|= DF_STATIC_TLS
;
4748 case R_PPC64_ADDR64
:
4749 if (opd_sym_map
!= NULL
4750 && rel
+ 1 < rel_end
4751 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4755 if (h
->root
.root
.string
[0] == '.'
4756 && h
->root
.root
.string
[1] != 0
4757 && get_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
4760 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4766 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
4771 opd_sym_map
[rel
->r_offset
/ 8] = s
;
4779 case R_PPC64_ADDR14
:
4780 case R_PPC64_ADDR14_BRNTAKEN
:
4781 case R_PPC64_ADDR14_BRTAKEN
:
4782 case R_PPC64_ADDR16
:
4783 case R_PPC64_ADDR16_DS
:
4784 case R_PPC64_ADDR16_HA
:
4785 case R_PPC64_ADDR16_HI
:
4786 case R_PPC64_ADDR16_HIGHER
:
4787 case R_PPC64_ADDR16_HIGHERA
:
4788 case R_PPC64_ADDR16_HIGHEST
:
4789 case R_PPC64_ADDR16_HIGHESTA
:
4790 case R_PPC64_ADDR16_LO
:
4791 case R_PPC64_ADDR16_LO_DS
:
4792 case R_PPC64_ADDR24
:
4793 case R_PPC64_ADDR32
:
4794 case R_PPC64_UADDR16
:
4795 case R_PPC64_UADDR32
:
4796 case R_PPC64_UADDR64
:
4798 if (h
!= NULL
&& !info
->shared
)
4799 /* We may need a copy reloc. */
4802 /* Don't propagate .opd relocs. */
4803 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
4806 /* If we are creating a shared library, and this is a reloc
4807 against a global symbol, or a non PC relative reloc
4808 against a local symbol, then we need to copy the reloc
4809 into the shared library. However, if we are linking with
4810 -Bsymbolic, we do not need to copy a reloc against a
4811 global symbol which is defined in an object we are
4812 including in the link (i.e., DEF_REGULAR is set). At
4813 this point we have not seen all the input files, so it is
4814 possible that DEF_REGULAR is not set now but will be set
4815 later (it is never cleared). In case of a weak definition,
4816 DEF_REGULAR may be cleared later by a strong definition in
4817 a shared library. We account for that possibility below by
4818 storing information in the dyn_relocs field of the hash
4819 table entry. A similar situation occurs when creating
4820 shared libraries and symbol visibility changes render the
4823 If on the other hand, we are creating an executable, we
4824 may need to keep relocations for symbols satisfied by a
4825 dynamic library if we manage to avoid copy relocs for the
4829 && (MUST_BE_DYN_RELOC (r_type
)
4831 && (! info
->symbolic
4832 || h
->root
.type
== bfd_link_hash_defweak
4833 || !h
->def_regular
))))
4834 || (ELIMINATE_COPY_RELOCS
4837 && (h
->root
.type
== bfd_link_hash_defweak
4838 || !h
->def_regular
)))
4840 struct ppc_dyn_relocs
*p
;
4841 struct ppc_dyn_relocs
**head
;
4843 /* We must copy these reloc types into the output file.
4844 Create a reloc section in dynobj and make room for
4851 name
= (bfd_elf_string_from_elf_section
4853 elf_elfheader (abfd
)->e_shstrndx
,
4854 elf_section_data (sec
)->rel_hdr
.sh_name
));
4858 if (! CONST_STRNEQ (name
, ".rela")
4859 || strcmp (bfd_get_section_name (abfd
, sec
),
4862 (*_bfd_error_handler
)
4863 (_("%B: bad relocation section name `%s\'"),
4865 bfd_set_error (bfd_error_bad_value
);
4868 dynobj
= htab
->elf
.dynobj
;
4869 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4874 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4875 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
4876 | SEC_ALLOC
| SEC_LOAD
);
4877 sreloc
= bfd_make_section_with_flags (dynobj
,
4881 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
4884 elf_section_data (sec
)->sreloc
= sreloc
;
4887 /* If this is a global symbol, we count the number of
4888 relocations we need for this symbol. */
4891 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4895 /* Track dynamic relocs needed for local syms too.
4896 We really need local syms available to do this
4902 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4907 vpp
= &elf_section_data (s
)->local_dynrel
;
4908 head
= (struct ppc_dyn_relocs
**) vpp
;
4912 if (p
== NULL
|| p
->sec
!= sec
)
4914 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4925 if (!MUST_BE_DYN_RELOC (r_type
))
4938 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4939 of the code entry point, and its section. */
4942 opd_entry_value (asection
*opd_sec
,
4944 asection
**code_sec
,
4947 bfd
*opd_bfd
= opd_sec
->owner
;
4948 Elf_Internal_Rela
*relocs
;
4949 Elf_Internal_Rela
*lo
, *hi
, *look
;
4952 /* No relocs implies we are linking a --just-symbols object. */
4953 if (opd_sec
->reloc_count
== 0)
4957 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, &val
, offset
, 8))
4958 return (bfd_vma
) -1;
4960 if (code_sec
!= NULL
)
4962 asection
*sec
, *likely
= NULL
;
4963 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4965 && (sec
->flags
& SEC_LOAD
) != 0
4966 && (sec
->flags
& SEC_ALLOC
) != 0)
4971 if (code_off
!= NULL
)
4972 *code_off
= val
- likely
->vma
;
4978 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
4980 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
4982 /* Go find the opd reloc at the sym address. */
4984 BFD_ASSERT (lo
!= NULL
);
4985 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
4989 look
= lo
+ (hi
- lo
) / 2;
4990 if (look
->r_offset
< offset
)
4992 else if (look
->r_offset
> offset
)
4996 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (opd_bfd
)->symtab_hdr
;
4997 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
4998 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5000 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5003 if (symndx
< symtab_hdr
->sh_info
)
5005 Elf_Internal_Sym
*sym
;
5007 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5010 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5011 symtab_hdr
->sh_info
,
5012 0, NULL
, NULL
, NULL
);
5015 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5019 val
= sym
->st_value
;
5021 if ((sym
->st_shndx
!= SHN_UNDEF
5022 && sym
->st_shndx
< SHN_LORESERVE
)
5023 || sym
->st_shndx
> SHN_HIRESERVE
)
5024 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5025 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5029 struct elf_link_hash_entry
**sym_hashes
;
5030 struct elf_link_hash_entry
*rh
;
5032 sym_hashes
= elf_sym_hashes (opd_bfd
);
5033 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5034 while (rh
->root
.type
== bfd_link_hash_indirect
5035 || rh
->root
.type
== bfd_link_hash_warning
)
5036 rh
= ((struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
);
5037 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5038 || rh
->root
.type
== bfd_link_hash_defweak
);
5039 val
= rh
->root
.u
.def
.value
;
5040 sec
= rh
->root
.u
.def
.section
;
5042 val
+= look
->r_addend
;
5043 if (code_off
!= NULL
)
5045 if (code_sec
!= NULL
)
5047 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5048 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5057 /* Mark sections containing dynamically referenced symbols. When
5058 building shared libraries, we must assume that any visible symbol is
5062 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5064 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5065 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5067 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5068 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5070 /* Dynamic linking info is on the func descriptor sym. */
5072 && eh
->oh
->is_func_descriptor
5073 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5074 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5077 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5078 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5079 && (eh
->elf
.ref_dynamic
5080 || (!info
->executable
5081 && eh
->elf
.def_regular
5082 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5083 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5087 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5089 /* Function descriptor syms cause the associated
5090 function code sym section to be marked. */
5091 if (eh
->is_func_descriptor
5092 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5093 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5094 eh
->oh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5095 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5096 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5097 eh
->elf
.root
.u
.def
.value
,
5098 &code_sec
, NULL
) != (bfd_vma
) -1)
5099 code_sec
->flags
|= SEC_KEEP
;
5105 /* Return the section that should be marked against GC for a given
5109 ppc64_elf_gc_mark_hook (asection
*sec
,
5110 struct bfd_link_info
*info
,
5111 Elf_Internal_Rela
*rel
,
5112 struct elf_link_hash_entry
*h
,
5113 Elf_Internal_Sym
*sym
)
5117 /* First mark all our entry sym sections. */
5118 if (info
->gc_sym_list
!= NULL
)
5120 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5121 struct bfd_sym_chain
*sym
= info
->gc_sym_list
;
5123 info
->gc_sym_list
= NULL
;
5124 for (; sym
!= NULL
; sym
= sym
->next
)
5126 struct ppc_link_hash_entry
*eh
;
5128 eh
= (struct ppc_link_hash_entry
*)
5129 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
5132 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5133 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5136 if (eh
->is_func_descriptor
5137 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5138 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5139 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5140 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5141 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5142 eh
->elf
.root
.u
.def
.value
,
5143 &rsec
, NULL
) != (bfd_vma
) -1)
5149 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5151 rsec
= eh
->elf
.root
.u
.def
.section
;
5153 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5157 /* Syms return NULL if we're marking .opd, so we avoid marking all
5158 function sections, as all functions are referenced in .opd. */
5160 if (get_opd_info (sec
) != NULL
)
5165 enum elf_ppc64_reloc_type r_type
;
5166 struct ppc_link_hash_entry
*eh
;
5168 r_type
= ELF64_R_TYPE (rel
->r_info
);
5171 case R_PPC64_GNU_VTINHERIT
:
5172 case R_PPC64_GNU_VTENTRY
:
5176 switch (h
->root
.type
)
5178 case bfd_link_hash_defined
:
5179 case bfd_link_hash_defweak
:
5180 eh
= (struct ppc_link_hash_entry
*) h
;
5182 && eh
->oh
->is_func_descriptor
5183 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5184 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5187 /* Function descriptor syms cause the associated
5188 function code sym section to be marked. */
5189 if (eh
->is_func_descriptor
5190 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5191 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5193 /* They also mark their opd section. */
5194 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5195 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5196 ppc64_elf_gc_mark_hook
);
5198 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5200 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5201 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5202 eh
->elf
.root
.u
.def
.value
,
5203 &rsec
, NULL
) != (bfd_vma
) -1)
5205 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5206 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5207 ppc64_elf_gc_mark_hook
);
5210 rsec
= h
->root
.u
.def
.section
;
5213 case bfd_link_hash_common
:
5214 rsec
= h
->root
.u
.c
.p
->section
;
5224 asection
**opd_sym_section
;
5226 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5227 opd_sym_section
= get_opd_info (rsec
);
5228 if (opd_sym_section
!= NULL
)
5231 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5233 rsec
= opd_sym_section
[(sym
->st_value
+ rel
->r_addend
) / 8];
5240 /* Update the .got, .plt. and dynamic reloc reference counts for the
5241 section being removed. */
5244 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5245 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5247 struct ppc_link_hash_table
*htab
;
5248 Elf_Internal_Shdr
*symtab_hdr
;
5249 struct elf_link_hash_entry
**sym_hashes
;
5250 struct got_entry
**local_got_ents
;
5251 const Elf_Internal_Rela
*rel
, *relend
;
5253 if ((sec
->flags
& SEC_ALLOC
) == 0)
5256 elf_section_data (sec
)->local_dynrel
= NULL
;
5258 htab
= ppc_hash_table (info
);
5259 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5260 sym_hashes
= elf_sym_hashes (abfd
);
5261 local_got_ents
= elf_local_got_ents (abfd
);
5263 relend
= relocs
+ sec
->reloc_count
;
5264 for (rel
= relocs
; rel
< relend
; rel
++)
5266 unsigned long r_symndx
;
5267 enum elf_ppc64_reloc_type r_type
;
5268 struct elf_link_hash_entry
*h
= NULL
;
5271 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5272 r_type
= ELF64_R_TYPE (rel
->r_info
);
5273 if (r_symndx
>= symtab_hdr
->sh_info
)
5275 struct ppc_link_hash_entry
*eh
;
5276 struct ppc_dyn_relocs
**pp
;
5277 struct ppc_dyn_relocs
*p
;
5279 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5280 while (h
->root
.type
== bfd_link_hash_indirect
5281 || h
->root
.type
== bfd_link_hash_warning
)
5282 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5283 eh
= (struct ppc_link_hash_entry
*) h
;
5285 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5288 /* Everything must go for SEC. */
5296 case R_PPC64_GOT_TLSLD16
:
5297 case R_PPC64_GOT_TLSLD16_LO
:
5298 case R_PPC64_GOT_TLSLD16_HI
:
5299 case R_PPC64_GOT_TLSLD16_HA
:
5300 ppc64_tlsld_got (abfd
)->refcount
-= 1;
5301 tls_type
= TLS_TLS
| TLS_LD
;
5304 case R_PPC64_GOT_TLSGD16
:
5305 case R_PPC64_GOT_TLSGD16_LO
:
5306 case R_PPC64_GOT_TLSGD16_HI
:
5307 case R_PPC64_GOT_TLSGD16_HA
:
5308 tls_type
= TLS_TLS
| TLS_GD
;
5311 case R_PPC64_GOT_TPREL16_DS
:
5312 case R_PPC64_GOT_TPREL16_LO_DS
:
5313 case R_PPC64_GOT_TPREL16_HI
:
5314 case R_PPC64_GOT_TPREL16_HA
:
5315 tls_type
= TLS_TLS
| TLS_TPREL
;
5318 case R_PPC64_GOT_DTPREL16_DS
:
5319 case R_PPC64_GOT_DTPREL16_LO_DS
:
5320 case R_PPC64_GOT_DTPREL16_HI
:
5321 case R_PPC64_GOT_DTPREL16_HA
:
5322 tls_type
= TLS_TLS
| TLS_DTPREL
;
5326 case R_PPC64_GOT16_DS
:
5327 case R_PPC64_GOT16_HA
:
5328 case R_PPC64_GOT16_HI
:
5329 case R_PPC64_GOT16_LO
:
5330 case R_PPC64_GOT16_LO_DS
:
5333 struct got_entry
*ent
;
5338 ent
= local_got_ents
[r_symndx
];
5340 for (; ent
!= NULL
; ent
= ent
->next
)
5341 if (ent
->addend
== rel
->r_addend
5342 && ent
->owner
== abfd
5343 && ent
->tls_type
== tls_type
)
5347 if (ent
->got
.refcount
> 0)
5348 ent
->got
.refcount
-= 1;
5352 case R_PPC64_PLT16_HA
:
5353 case R_PPC64_PLT16_HI
:
5354 case R_PPC64_PLT16_LO
:
5358 case R_PPC64_REL14_BRNTAKEN
:
5359 case R_PPC64_REL14_BRTAKEN
:
5363 struct plt_entry
*ent
;
5365 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5366 if (ent
->addend
== rel
->r_addend
)
5370 if (ent
->plt
.refcount
> 0)
5371 ent
->plt
.refcount
-= 1;
5382 /* The maximum size of .sfpr. */
5383 #define SFPR_MAX (218*4)
5385 struct sfpr_def_parms
5387 const char name
[12];
5388 unsigned char lo
, hi
;
5389 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5390 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5393 /* Auto-generate _save*, _rest* functions in .sfpr. */
5396 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5398 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5400 size_t len
= strlen (parm
->name
);
5401 bfd_boolean writing
= FALSE
;
5404 memcpy (sym
, parm
->name
, len
);
5407 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5409 struct elf_link_hash_entry
*h
;
5411 sym
[len
+ 0] = i
/ 10 + '0';
5412 sym
[len
+ 1] = i
% 10 + '0';
5413 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5417 h
->root
.type
= bfd_link_hash_defined
;
5418 h
->root
.u
.def
.section
= htab
->sfpr
;
5419 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
5422 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
5424 if (htab
->sfpr
->contents
== NULL
)
5426 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5427 if (htab
->sfpr
->contents
== NULL
)
5433 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5435 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5437 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5438 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5446 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5448 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5453 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5455 p
= savegpr0 (abfd
, p
, r
);
5456 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5458 bfd_put_32 (abfd
, BLR
, p
);
5463 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5465 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5470 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5472 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5474 p
= restgpr0 (abfd
, p
, r
);
5475 bfd_put_32 (abfd
, MTLR_R0
, p
);
5479 p
= restgpr0 (abfd
, p
, 30);
5480 p
= restgpr0 (abfd
, p
, 31);
5482 bfd_put_32 (abfd
, BLR
, p
);
5487 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5489 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5494 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5496 p
= savegpr1 (abfd
, p
, r
);
5497 bfd_put_32 (abfd
, BLR
, p
);
5502 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5504 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5509 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5511 p
= restgpr1 (abfd
, p
, r
);
5512 bfd_put_32 (abfd
, BLR
, p
);
5517 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5519 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5524 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5526 p
= savefpr (abfd
, p
, r
);
5527 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5529 bfd_put_32 (abfd
, BLR
, p
);
5534 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5536 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5541 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5543 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5545 p
= restfpr (abfd
, p
, r
);
5546 bfd_put_32 (abfd
, MTLR_R0
, p
);
5550 p
= restfpr (abfd
, p
, 30);
5551 p
= restfpr (abfd
, p
, 31);
5553 bfd_put_32 (abfd
, BLR
, p
);
5558 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5560 p
= savefpr (abfd
, p
, r
);
5561 bfd_put_32 (abfd
, BLR
, p
);
5566 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5568 p
= restfpr (abfd
, p
, r
);
5569 bfd_put_32 (abfd
, BLR
, p
);
5574 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5576 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5578 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5583 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5585 p
= savevr (abfd
, p
, r
);
5586 bfd_put_32 (abfd
, BLR
, p
);
5591 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5593 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5595 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5600 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5602 p
= restvr (abfd
, p
, r
);
5603 bfd_put_32 (abfd
, BLR
, p
);
5607 /* Called via elf_link_hash_traverse to transfer dynamic linking
5608 information on function code symbol entries to their corresponding
5609 function descriptor symbol entries. */
5612 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5614 struct bfd_link_info
*info
;
5615 struct ppc_link_hash_table
*htab
;
5616 struct plt_entry
*ent
;
5617 struct ppc_link_hash_entry
*fh
;
5618 struct ppc_link_hash_entry
*fdh
;
5619 bfd_boolean force_local
;
5621 fh
= (struct ppc_link_hash_entry
*) h
;
5622 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5625 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
5626 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
5629 htab
= ppc_hash_table (info
);
5631 /* Resolve undefined references to dot-symbols as the value
5632 in the function descriptor, if we have one in a regular object.
5633 This is to satisfy cases like ".quad .foo". Calls to functions
5634 in dynamic objects are handled elsewhere. */
5635 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
5636 && fh
->was_undefined
5637 && (fh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5638 || fh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
)
5639 && get_opd_info (fh
->oh
->elf
.root
.u
.def
.section
) != NULL
5640 && opd_entry_value (fh
->oh
->elf
.root
.u
.def
.section
,
5641 fh
->oh
->elf
.root
.u
.def
.value
,
5642 &fh
->elf
.root
.u
.def
.section
,
5643 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
5645 fh
->elf
.root
.type
= fh
->oh
->elf
.root
.type
;
5646 fh
->elf
.forced_local
= 1;
5649 /* If this is a function code symbol, transfer dynamic linking
5650 information to the function descriptor symbol. */
5654 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5655 if (ent
->plt
.refcount
> 0)
5658 || fh
->elf
.root
.root
.string
[0] != '.'
5659 || fh
->elf
.root
.root
.string
[1] == '\0')
5662 /* Find the corresponding function descriptor symbol. Create it
5663 as undefined if necessary. */
5665 fdh
= get_fdh (fh
, htab
);
5667 while (fdh
->elf
.root
.type
== bfd_link_hash_indirect
5668 || fdh
->elf
.root
.type
== bfd_link_hash_warning
)
5669 fdh
= (struct ppc_link_hash_entry
*) fdh
->elf
.root
.u
.i
.link
;
5673 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5674 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5676 fdh
= make_fdh (info
, fh
);
5681 /* Fake function descriptors are made undefweak. If the function
5682 code symbol is strong undefined, make the fake sym the same.
5683 If the function code symbol is defined, then force the fake
5684 descriptor local; We can't support overriding of symbols in a
5685 shared library on a fake descriptor. */
5689 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5691 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
5693 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
5694 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
5696 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
5697 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5699 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5704 && !fdh
->elf
.forced_local
5706 || fdh
->elf
.def_dynamic
5707 || fdh
->elf
.ref_dynamic
5708 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
5709 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
5711 if (fdh
->elf
.dynindx
== -1)
5712 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5714 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5715 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5716 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5717 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5718 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
5720 move_plt_plist (fh
, fdh
);
5721 fdh
->elf
.needs_plt
= 1;
5723 fdh
->is_func_descriptor
= 1;
5728 /* Now that the info is on the function descriptor, clear the
5729 function code sym info. Any function code syms for which we
5730 don't have a definition in a regular file, we force local.
5731 This prevents a shared library from exporting syms that have
5732 been imported from another library. Function code syms that
5733 are really in the library we must leave global to prevent the
5734 linker dragging in a definition from a static library. */
5735 force_local
= (!fh
->elf
.def_regular
5737 || !fdh
->elf
.def_regular
5738 || fdh
->elf
.forced_local
);
5739 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5744 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5745 this hook to a) provide some gcc support functions, and b) transfer
5746 dynamic linking information gathered so far on function code symbol
5747 entries, to their corresponding function descriptor symbol entries. */
5750 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5751 struct bfd_link_info
*info
)
5753 struct ppc_link_hash_table
*htab
;
5755 const struct sfpr_def_parms funcs
[] =
5757 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5758 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5759 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5760 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5761 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5762 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5763 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5764 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5765 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5766 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5767 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5768 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5771 htab
= ppc_hash_table (info
);
5772 if (htab
->sfpr
== NULL
)
5773 /* We don't have any relocs. */
5776 /* Provide any missing _save* and _rest* functions. */
5777 htab
->sfpr
->size
= 0;
5778 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
5779 if (!sfpr_define (info
, &funcs
[i
]))
5782 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5784 if (htab
->sfpr
->size
== 0)
5785 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5790 /* Adjust a symbol defined by a dynamic object and referenced by a
5791 regular object. The current definition is in some section of the
5792 dynamic object, but we're not including those sections. We have to
5793 change the definition to something the rest of the link can
5797 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5798 struct elf_link_hash_entry
*h
)
5800 struct ppc_link_hash_table
*htab
;
5802 unsigned int power_of_two
;
5804 htab
= ppc_hash_table (info
);
5806 /* Deal with function syms. */
5807 if (h
->type
== STT_FUNC
5810 /* Clear procedure linkage table information for any symbol that
5811 won't need a .plt entry. */
5812 struct plt_entry
*ent
;
5813 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5814 if (ent
->plt
.refcount
> 0)
5817 || SYMBOL_CALLS_LOCAL (info
, h
)
5818 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5819 && h
->root
.type
== bfd_link_hash_undefweak
))
5821 h
->plt
.plist
= NULL
;
5826 h
->plt
.plist
= NULL
;
5828 /* If this is a weak symbol, and there is a real definition, the
5829 processor independent code will have arranged for us to see the
5830 real definition first, and we can just use the same value. */
5831 if (h
->u
.weakdef
!= NULL
)
5833 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5834 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5835 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5836 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5837 if (ELIMINATE_COPY_RELOCS
)
5838 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
5842 /* If we are creating a shared library, we must presume that the
5843 only references to the symbol are via the global offset table.
5844 For such cases we need not do anything here; the relocations will
5845 be handled correctly by relocate_section. */
5849 /* If there are no references to this symbol that do not use the
5850 GOT, we don't need to generate a copy reloc. */
5851 if (!h
->non_got_ref
)
5854 if (ELIMINATE_COPY_RELOCS
)
5856 struct ppc_link_hash_entry
* eh
;
5857 struct ppc_dyn_relocs
*p
;
5859 eh
= (struct ppc_link_hash_entry
*) h
;
5860 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5862 s
= p
->sec
->output_section
;
5863 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5867 /* If we didn't find any dynamic relocs in read-only sections, then
5868 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
5876 if (h
->plt
.plist
!= NULL
)
5878 /* We should never get here, but unfortunately there are versions
5879 of gcc out there that improperly (for this ABI) put initialized
5880 function pointers, vtable refs and suchlike in read-only
5881 sections. Allow them to proceed, but warn that this might
5882 break at runtime. */
5883 (*_bfd_error_handler
)
5884 (_("copy reloc against `%s' requires lazy plt linking; "
5885 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
5886 h
->root
.root
.string
);
5889 /* This is a reference to a symbol defined by a dynamic object which
5890 is not a function. */
5894 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
5895 h
->root
.root
.string
);
5899 /* We must allocate the symbol in our .dynbss section, which will
5900 become part of the .bss section of the executable. There will be
5901 an entry for this symbol in the .dynsym section. The dynamic
5902 object will contain position independent code, so all references
5903 from the dynamic object to this symbol will go through the global
5904 offset table. The dynamic linker will use the .dynsym entry to
5905 determine the address it must put in the global offset table, so
5906 both the dynamic object and the regular object will refer to the
5907 same memory location for the variable. */
5909 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
5910 to copy the initial value out of the dynamic object and into the
5911 runtime process image. We need to remember the offset into the
5912 .rela.bss section we are going to use. */
5913 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5915 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
5919 /* We need to figure out the alignment required for this symbol. I
5920 have no idea how ELF linkers handle this. */
5921 power_of_two
= bfd_log2 (h
->size
);
5922 if (power_of_two
> 4)
5925 /* Apply the required alignment. */
5927 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
5928 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
5930 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
5934 /* Define the symbol as being at this point in the section. */
5935 h
->root
.u
.def
.section
= s
;
5936 h
->root
.u
.def
.value
= s
->size
;
5938 /* Increment the section size to make room for the symbol. */
5944 /* If given a function descriptor symbol, hide both the function code
5945 sym and the descriptor. */
5947 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
5948 struct elf_link_hash_entry
*h
,
5949 bfd_boolean force_local
)
5951 struct ppc_link_hash_entry
*eh
;
5952 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
5954 eh
= (struct ppc_link_hash_entry
*) h
;
5955 if (eh
->is_func_descriptor
)
5957 struct ppc_link_hash_entry
*fh
= eh
->oh
;
5962 struct ppc_link_hash_table
*htab
;
5965 /* We aren't supposed to use alloca in BFD because on
5966 systems which do not have alloca the version in libiberty
5967 calls xmalloc, which might cause the program to crash
5968 when it runs out of memory. This function doesn't have a
5969 return status, so there's no way to gracefully return an
5970 error. So cheat. We know that string[-1] can be safely
5971 accessed; It's either a string in an ELF string table,
5972 or allocated in an objalloc structure. */
5974 p
= eh
->elf
.root
.root
.string
- 1;
5977 htab
= ppc_hash_table (info
);
5978 fh
= (struct ppc_link_hash_entry
*)
5979 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
5982 /* Unfortunately, if it so happens that the string we were
5983 looking for was allocated immediately before this string,
5984 then we overwrote the string terminator. That's the only
5985 reason the lookup should fail. */
5988 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
5989 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
5991 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
5992 fh
= (struct ppc_link_hash_entry
*)
5993 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
6002 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6007 get_sym_h (struct elf_link_hash_entry
**hp
,
6008 Elf_Internal_Sym
**symp
,
6011 Elf_Internal_Sym
**locsymsp
,
6012 unsigned long r_symndx
,
6015 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6017 if (r_symndx
>= symtab_hdr
->sh_info
)
6019 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6020 struct elf_link_hash_entry
*h
;
6022 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6023 while (h
->root
.type
== bfd_link_hash_indirect
6024 || h
->root
.type
== bfd_link_hash_warning
)
6025 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6033 if (symsecp
!= NULL
)
6035 asection
*symsec
= NULL
;
6036 if (h
->root
.type
== bfd_link_hash_defined
6037 || h
->root
.type
== bfd_link_hash_defweak
)
6038 symsec
= h
->root
.u
.def
.section
;
6042 if (tls_maskp
!= NULL
)
6044 struct ppc_link_hash_entry
*eh
;
6046 eh
= (struct ppc_link_hash_entry
*) h
;
6047 *tls_maskp
= &eh
->tls_mask
;
6052 Elf_Internal_Sym
*sym
;
6053 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6055 if (locsyms
== NULL
)
6057 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6058 if (locsyms
== NULL
)
6059 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6060 symtab_hdr
->sh_info
,
6061 0, NULL
, NULL
, NULL
);
6062 if (locsyms
== NULL
)
6064 *locsymsp
= locsyms
;
6066 sym
= locsyms
+ r_symndx
;
6074 if (symsecp
!= NULL
)
6076 asection
*symsec
= NULL
;
6077 if ((sym
->st_shndx
!= SHN_UNDEF
6078 && sym
->st_shndx
< SHN_LORESERVE
)
6079 || sym
->st_shndx
> SHN_HIRESERVE
)
6080 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6084 if (tls_maskp
!= NULL
)
6086 struct got_entry
**lgot_ents
;
6090 lgot_ents
= elf_local_got_ents (ibfd
);
6091 if (lgot_ents
!= NULL
)
6093 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
6094 tls_mask
= &lgot_masks
[r_symndx
];
6096 *tls_maskp
= tls_mask
;
6102 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6103 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6104 type suitable for optimization, and 1 otherwise. */
6107 get_tls_mask (char **tls_maskp
, unsigned long *toc_symndx
,
6108 Elf_Internal_Sym
**locsymsp
,
6109 const Elf_Internal_Rela
*rel
, bfd
*ibfd
)
6111 unsigned long r_symndx
;
6113 struct elf_link_hash_entry
*h
;
6114 Elf_Internal_Sym
*sym
;
6118 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6119 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6122 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6124 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6127 /* Look inside a TOC section too. */
6130 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6131 off
= h
->root
.u
.def
.value
;
6134 off
= sym
->st_value
;
6135 off
+= rel
->r_addend
;
6136 BFD_ASSERT (off
% 8 == 0);
6137 r_symndx
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8];
6138 next_r
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8 + 1];
6139 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6141 if (toc_symndx
!= NULL
)
6142 *toc_symndx
= r_symndx
;
6144 || ((h
->root
.type
== bfd_link_hash_defined
6145 || h
->root
.type
== bfd_link_hash_defweak
)
6146 && !h
->def_dynamic
))
6147 && (next_r
== -1 || next_r
== -2))
6152 /* Adjust all global syms defined in opd sections. In gcc generated
6153 code for the old ABI, these will already have been done. */
6156 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6158 struct ppc_link_hash_entry
*eh
;
6162 if (h
->root
.type
== bfd_link_hash_indirect
)
6165 if (h
->root
.type
== bfd_link_hash_warning
)
6166 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6168 if (h
->root
.type
!= bfd_link_hash_defined
6169 && h
->root
.type
!= bfd_link_hash_defweak
)
6172 eh
= (struct ppc_link_hash_entry
*) h
;
6173 if (eh
->adjust_done
)
6176 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6177 opd_adjust
= get_opd_info (sym_sec
);
6178 if (opd_adjust
!= NULL
)
6180 long adjust
= opd_adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6183 /* This entry has been deleted. */
6184 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6187 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6188 if (elf_discarded_section (dsec
))
6190 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6194 eh
->elf
.root
.u
.def
.value
= 0;
6195 eh
->elf
.root
.u
.def
.section
= dsec
;
6198 eh
->elf
.root
.u
.def
.value
+= adjust
;
6199 eh
->adjust_done
= 1;
6204 /* Handles decrementing dynamic reloc counts for the reloc specified by
6205 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6206 have already been determined. */
6209 dec_dynrel_count (bfd_vma r_info
,
6211 struct bfd_link_info
*info
,
6212 Elf_Internal_Sym
**local_syms
,
6213 struct elf_link_hash_entry
*h
,
6216 enum elf_ppc64_reloc_type r_type
;
6217 struct ppc_dyn_relocs
*p
;
6218 struct ppc_dyn_relocs
**pp
;
6220 /* Can this reloc be dynamic? This switch, and later tests here
6221 should be kept in sync with the code in check_relocs. */
6222 r_type
= ELF64_R_TYPE (r_info
);
6228 case R_PPC64_TPREL16
:
6229 case R_PPC64_TPREL16_LO
:
6230 case R_PPC64_TPREL16_HI
:
6231 case R_PPC64_TPREL16_HA
:
6232 case R_PPC64_TPREL16_DS
:
6233 case R_PPC64_TPREL16_LO_DS
:
6234 case R_PPC64_TPREL16_HIGHER
:
6235 case R_PPC64_TPREL16_HIGHERA
:
6236 case R_PPC64_TPREL16_HIGHEST
:
6237 case R_PPC64_TPREL16_HIGHESTA
:
6241 case R_PPC64_TPREL64
:
6242 case R_PPC64_DTPMOD64
:
6243 case R_PPC64_DTPREL64
:
6244 case R_PPC64_ADDR64
:
6248 case R_PPC64_ADDR14
:
6249 case R_PPC64_ADDR14_BRNTAKEN
:
6250 case R_PPC64_ADDR14_BRTAKEN
:
6251 case R_PPC64_ADDR16
:
6252 case R_PPC64_ADDR16_DS
:
6253 case R_PPC64_ADDR16_HA
:
6254 case R_PPC64_ADDR16_HI
:
6255 case R_PPC64_ADDR16_HIGHER
:
6256 case R_PPC64_ADDR16_HIGHERA
:
6257 case R_PPC64_ADDR16_HIGHEST
:
6258 case R_PPC64_ADDR16_HIGHESTA
:
6259 case R_PPC64_ADDR16_LO
:
6260 case R_PPC64_ADDR16_LO_DS
:
6261 case R_PPC64_ADDR24
:
6262 case R_PPC64_ADDR32
:
6263 case R_PPC64_UADDR16
:
6264 case R_PPC64_UADDR32
:
6265 case R_PPC64_UADDR64
:
6270 if (local_syms
!= NULL
)
6272 unsigned long r_symndx
;
6273 Elf_Internal_Sym
*sym
;
6274 bfd
*ibfd
= sec
->owner
;
6276 r_symndx
= ELF64_R_SYM (r_info
);
6277 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6282 && (MUST_BE_DYN_RELOC (r_type
)
6285 || h
->root
.type
== bfd_link_hash_defweak
6286 || !h
->def_regular
))))
6287 || (ELIMINATE_COPY_RELOCS
6290 && (h
->root
.type
== bfd_link_hash_defweak
6291 || !h
->def_regular
)))
6297 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6300 if (sym_sec
!= NULL
)
6302 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6303 pp
= (struct ppc_dyn_relocs
**) vpp
;
6307 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6308 pp
= (struct ppc_dyn_relocs
**) vpp
;
6311 /* elf_gc_sweep may have already removed all dyn relocs associated
6312 with local syms for a given section. Don't report a dynreloc
6318 while ((p
= *pp
) != NULL
)
6322 if (!MUST_BE_DYN_RELOC (r_type
))
6332 (*_bfd_error_handler
) (_("dynreloc miscount for %B, section %A"),
6334 bfd_set_error (bfd_error_bad_value
);
6338 /* Remove unused Official Procedure Descriptor entries. Currently we
6339 only remove those associated with functions in discarded link-once
6340 sections, or weakly defined functions that have been overridden. It
6341 would be possible to remove many more entries for statically linked
6345 ppc64_elf_edit_opd (bfd
*obfd
, struct bfd_link_info
*info
,
6346 bfd_boolean no_opd_opt
,
6347 bfd_boolean non_overlapping
)
6350 bfd_boolean some_edited
= FALSE
;
6351 asection
*need_pad
= NULL
;
6353 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6356 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6357 Elf_Internal_Shdr
*symtab_hdr
;
6358 Elf_Internal_Sym
*local_syms
;
6359 struct elf_link_hash_entry
**sym_hashes
;
6363 bfd_boolean need_edit
, add_aux_fields
;
6364 bfd_size_type cnt_16b
= 0;
6366 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6367 if (sec
== NULL
|| sec
->size
== 0)
6370 amt
= sec
->size
* sizeof (long) / 8;
6371 opd_adjust
= get_opd_info (sec
);
6372 if (opd_adjust
== NULL
)
6374 /* check_relocs hasn't been called. Must be a ld -r link
6375 or --just-symbols object. */
6376 opd_adjust
= bfd_alloc (obfd
, amt
);
6377 if (opd_adjust
== NULL
)
6379 ppc64_elf_section_data (sec
)->u
.opd_adjust
= opd_adjust
;
6380 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
6381 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
6383 memset (opd_adjust
, 0, amt
);
6388 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6391 if (sec
->output_section
== bfd_abs_section_ptr
)
6394 /* Look through the section relocs. */
6395 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6399 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6400 sym_hashes
= elf_sym_hashes (ibfd
);
6402 /* Read the relocations. */
6403 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6405 if (relstart
== NULL
)
6408 /* First run through the relocs to check they are sane, and to
6409 determine whether we need to edit this opd section. */
6413 relend
= relstart
+ sec
->reloc_count
;
6414 for (rel
= relstart
; rel
< relend
; )
6416 enum elf_ppc64_reloc_type r_type
;
6417 unsigned long r_symndx
;
6419 struct elf_link_hash_entry
*h
;
6420 Elf_Internal_Sym
*sym
;
6422 /* .opd contains a regular array of 16 or 24 byte entries. We're
6423 only interested in the reloc pointing to a function entry
6425 if (rel
->r_offset
!= offset
6426 || rel
+ 1 >= relend
6427 || (rel
+ 1)->r_offset
!= offset
+ 8)
6429 /* If someone messes with .opd alignment then after a
6430 "ld -r" we might have padding in the middle of .opd.
6431 Also, there's nothing to prevent someone putting
6432 something silly in .opd with the assembler. No .opd
6433 optimization for them! */
6435 (*_bfd_error_handler
)
6436 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6441 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6442 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6444 (*_bfd_error_handler
)
6445 (_("%B: unexpected reloc type %u in .opd section"),
6451 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6452 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6456 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6458 const char *sym_name
;
6460 sym_name
= h
->root
.root
.string
;
6462 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6465 (*_bfd_error_handler
)
6466 (_("%B: undefined sym `%s' in .opd section"),
6472 /* opd entries are always for functions defined in the
6473 current input bfd. If the symbol isn't defined in the
6474 input bfd, then we won't be using the function in this
6475 bfd; It must be defined in a linkonce section in another
6476 bfd, or is weak. It's also possible that we are
6477 discarding the function due to a linker script /DISCARD/,
6478 which we test for via the output_section. */
6479 if (sym_sec
->owner
!= ibfd
6480 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6485 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
6487 if (sec
->size
== offset
+ 24)
6492 if (rel
== relend
&& sec
->size
== offset
+ 16)
6500 if (rel
->r_offset
== offset
+ 24)
6502 else if (rel
->r_offset
!= offset
+ 16)
6504 else if (rel
+ 1 < relend
6505 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6506 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6511 else if (rel
+ 2 < relend
6512 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
6513 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
6522 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
6524 if (need_edit
|| add_aux_fields
)
6526 Elf_Internal_Rela
*write_rel
;
6527 bfd_byte
*rptr
, *wptr
;
6528 bfd_byte
*new_contents
= NULL
;
6532 /* This seems a waste of time as input .opd sections are all
6533 zeros as generated by gcc, but I suppose there's no reason
6534 this will always be so. We might start putting something in
6535 the third word of .opd entries. */
6536 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6539 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6544 if (local_syms
!= NULL
6545 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6547 if (elf_section_data (sec
)->relocs
!= relstart
)
6551 sec
->contents
= loc
;
6552 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6555 elf_section_data (sec
)->relocs
= relstart
;
6557 new_contents
= sec
->contents
;
6560 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6561 if (new_contents
== NULL
)
6565 wptr
= new_contents
;
6566 rptr
= sec
->contents
;
6568 write_rel
= relstart
;
6572 for (rel
= relstart
; rel
< relend
; rel
++)
6574 unsigned long r_symndx
;
6576 struct elf_link_hash_entry
*h
;
6577 Elf_Internal_Sym
*sym
;
6579 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6580 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6584 if (rel
->r_offset
== offset
)
6586 struct ppc_link_hash_entry
*fdh
= NULL
;
6588 /* See if the .opd entry is full 24 byte or
6589 16 byte (with fd_aux entry overlapped with next
6592 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
6593 || (rel
+ 3 < relend
6594 && rel
[2].r_offset
== offset
+ 16
6595 && rel
[3].r_offset
== offset
+ 24
6596 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
6597 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
6601 && h
->root
.root
.string
[0] == '.')
6603 fdh
= get_fdh ((struct ppc_link_hash_entry
*) h
,
6604 ppc_hash_table (info
));
6606 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
6607 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6611 skip
= (sym_sec
->owner
!= ibfd
6612 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6615 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6617 /* Arrange for the function descriptor sym
6619 fdh
->elf
.root
.u
.def
.value
= 0;
6620 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6622 opd_adjust
[rel
->r_offset
/ 8] = -1;
6626 /* We'll be keeping this opd entry. */
6630 /* Redefine the function descriptor symbol to
6631 this location in the opd section. It is
6632 necessary to update the value here rather
6633 than using an array of adjustments as we do
6634 for local symbols, because various places
6635 in the generic ELF code use the value
6636 stored in u.def.value. */
6637 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6638 fdh
->adjust_done
= 1;
6641 /* Local syms are a bit tricky. We could
6642 tweak them as they can be cached, but
6643 we'd need to look through the local syms
6644 for the function descriptor sym which we
6645 don't have at the moment. So keep an
6646 array of adjustments. */
6647 opd_adjust
[rel
->r_offset
/ 8]
6648 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
6651 memcpy (wptr
, rptr
, opd_ent_size
);
6652 wptr
+= opd_ent_size
;
6653 if (add_aux_fields
&& opd_ent_size
== 16)
6655 memset (wptr
, '\0', 8);
6659 rptr
+= opd_ent_size
;
6660 offset
+= opd_ent_size
;
6666 && !info
->relocatable
6667 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
6673 /* We need to adjust any reloc offsets to point to the
6674 new opd entries. While we're at it, we may as well
6675 remove redundant relocs. */
6676 rel
->r_offset
+= opd_adjust
[(offset
- opd_ent_size
) / 8];
6677 if (write_rel
!= rel
)
6678 memcpy (write_rel
, rel
, sizeof (*rel
));
6683 sec
->size
= wptr
- new_contents
;
6684 sec
->reloc_count
= write_rel
- relstart
;
6687 free (sec
->contents
);
6688 sec
->contents
= new_contents
;
6691 /* Fudge the header size too, as this is used later in
6692 elf_bfd_final_link if we are emitting relocs. */
6693 elf_section_data (sec
)->rel_hdr
.sh_size
6694 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
6695 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
6698 else if (elf_section_data (sec
)->relocs
!= relstart
)
6701 if (local_syms
!= NULL
6702 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6704 if (!info
->keep_memory
)
6707 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6712 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
6714 /* If we are doing a final link and the last .opd entry is just 16 byte
6715 long, add a 8 byte padding after it. */
6716 if (need_pad
!= NULL
&& !info
->relocatable
)
6720 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
6722 BFD_ASSERT (need_pad
->size
> 0);
6724 p
= bfd_malloc (need_pad
->size
+ 8);
6728 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
6729 p
, 0, need_pad
->size
))
6732 need_pad
->contents
= p
;
6733 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6737 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
6741 need_pad
->contents
= p
;
6744 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
6745 need_pad
->size
+= 8;
6751 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
6754 ppc64_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
6756 struct ppc_link_hash_table
*htab
;
6758 htab
= ppc_hash_table (info
);
6759 if (htab
->tls_get_addr
!= NULL
)
6761 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr
;
6763 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6764 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6765 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6767 htab
->tls_get_addr
= h
;
6769 if (htab
->tls_get_addr_fd
== NULL
6771 && h
->oh
->is_func_descriptor
6772 && (h
->oh
->elf
.root
.type
== bfd_link_hash_defined
6773 || h
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
6774 htab
->tls_get_addr_fd
= h
->oh
;
6777 if (htab
->tls_get_addr_fd
!= NULL
)
6779 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr_fd
;
6781 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6782 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6783 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6785 htab
->tls_get_addr_fd
= h
;
6788 return _bfd_elf_tls_setup (obfd
, info
);
6791 /* Run through all the TLS relocs looking for optimization
6792 opportunities. The linker has been hacked (see ppc64elf.em) to do
6793 a preliminary section layout so that we know the TLS segment
6794 offsets. We can't optimize earlier because some optimizations need
6795 to know the tp offset, and we need to optimize before allocating
6796 dynamic relocations. */
6799 ppc64_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6803 struct ppc_link_hash_table
*htab
;
6805 if (info
->relocatable
|| info
->shared
)
6808 htab
= ppc_hash_table (info
);
6809 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6811 Elf_Internal_Sym
*locsyms
= NULL
;
6812 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
6813 unsigned char *toc_ref
= NULL
;
6815 /* Look at all the sections for this file, with TOC last. */
6816 for (sec
= (ibfd
->sections
== toc
&& toc
&& toc
->next
? toc
->next
6819 sec
= (sec
== toc
? NULL
6820 : sec
->next
== NULL
? toc
6821 : sec
->next
== toc
&& toc
->next
? toc
->next
6823 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
6825 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6826 int expecting_tls_get_addr
;
6827 long toc_ref_index
= 0;
6829 /* Read the relocations. */
6830 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6832 if (relstart
== NULL
)
6835 expecting_tls_get_addr
= 0;
6836 relend
= relstart
+ sec
->reloc_count
;
6837 for (rel
= relstart
; rel
< relend
; rel
++)
6839 enum elf_ppc64_reloc_type r_type
;
6840 unsigned long r_symndx
;
6841 struct elf_link_hash_entry
*h
;
6842 Elf_Internal_Sym
*sym
;
6845 char tls_set
, tls_clear
, tls_type
= 0;
6847 bfd_boolean ok_tprel
, is_local
;
6849 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6850 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
6854 if (elf_section_data (sec
)->relocs
!= relstart
)
6856 if (toc_ref
!= NULL
)
6859 && (elf_tdata (ibfd
)->symtab_hdr
.contents
6860 != (unsigned char *) locsyms
))
6867 if (h
->root
.type
!= bfd_link_hash_defined
6868 && h
->root
.type
!= bfd_link_hash_defweak
)
6870 value
= h
->root
.u
.def
.value
;
6873 /* Symbols referenced by TLS relocs must be of type
6874 STT_TLS. So no need for .opd local sym adjust. */
6875 value
= sym
->st_value
;
6883 value
+= sym_sec
->output_offset
;
6884 value
+= sym_sec
->output_section
->vma
;
6885 value
-= htab
->elf
.tls_sec
->vma
;
6886 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
6887 < (bfd_vma
) 1 << 32);
6890 r_type
= ELF64_R_TYPE (rel
->r_info
);
6893 case R_PPC64_GOT_TLSLD16
:
6894 case R_PPC64_GOT_TLSLD16_LO
:
6895 case R_PPC64_GOT_TLSLD16_HI
:
6896 case R_PPC64_GOT_TLSLD16_HA
:
6897 /* These relocs should never be against a symbol
6898 defined in a shared lib. Leave them alone if
6899 that turns out to be the case. */
6900 ppc64_tlsld_got (ibfd
)->refcount
-= 1;
6907 tls_type
= TLS_TLS
| TLS_LD
;
6908 expecting_tls_get_addr
= 1;
6911 case R_PPC64_GOT_TLSGD16
:
6912 case R_PPC64_GOT_TLSGD16_LO
:
6913 case R_PPC64_GOT_TLSGD16_HI
:
6914 case R_PPC64_GOT_TLSGD16_HA
:
6920 tls_set
= TLS_TLS
| TLS_TPRELGD
;
6922 tls_type
= TLS_TLS
| TLS_GD
;
6923 expecting_tls_get_addr
= 1;
6926 case R_PPC64_GOT_TPREL16_DS
:
6927 case R_PPC64_GOT_TPREL16_LO_DS
:
6928 case R_PPC64_GOT_TPREL16_HI
:
6929 case R_PPC64_GOT_TPREL16_HA
:
6930 expecting_tls_get_addr
= 0;
6935 tls_clear
= TLS_TPREL
;
6936 tls_type
= TLS_TLS
| TLS_TPREL
;
6943 case R_PPC64_REL14_BRTAKEN
:
6944 case R_PPC64_REL14_BRNTAKEN
:
6947 && (h
== &htab
->tls_get_addr
->elf
6948 || h
== &htab
->tls_get_addr_fd
->elf
))
6950 if (!expecting_tls_get_addr
6952 && ((ELF64_R_TYPE (rel
[-1].r_info
)
6954 || (ELF64_R_TYPE (rel
[-1].r_info
)
6955 == R_PPC64_TOC16_LO
)))
6957 /* Check for toc tls entries. */
6961 retval
= get_tls_mask (&toc_tls
, NULL
, &locsyms
,
6965 if (retval
> 1 && toc_tls
!= NULL
)
6967 expecting_tls_get_addr
= 1;
6968 if (toc_ref
!= NULL
)
6969 toc_ref
[toc_ref_index
] = 1;
6973 if (expecting_tls_get_addr
)
6975 struct plt_entry
*ent
;
6976 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
6977 if (ent
->addend
== 0)
6979 if (ent
->plt
.refcount
> 0)
6980 ent
->plt
.refcount
-= 1;
6985 expecting_tls_get_addr
= 0;
6989 case R_PPC64_TOC16_LO
:
6991 expecting_tls_get_addr
= 0;
6992 if (sym_sec
== toc
&& toc
!= NULL
)
6994 /* Mark this toc entry as referenced by a TLS
6995 code sequence. We can do that now in the
6996 case of R_PPC64_TLS, and after checking for
6997 tls_get_addr for the TOC16 relocs. */
6998 if (toc_ref
== NULL
)
7000 toc_ref
= bfd_zmalloc (toc
->size
/ 8);
7001 if (toc_ref
== NULL
)
7005 value
= h
->root
.u
.def
.value
;
7007 value
= sym
->st_value
;
7008 value
+= rel
->r_addend
;
7009 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
7010 toc_ref_index
= value
/ 8;
7011 if (r_type
== R_PPC64_TLS
)
7012 toc_ref
[toc_ref_index
] = 1;
7016 case R_PPC64_TPREL64
:
7017 expecting_tls_get_addr
= 0;
7020 || !toc_ref
[rel
->r_offset
/ 8])
7025 tls_set
= TLS_EXPLICIT
;
7026 tls_clear
= TLS_TPREL
;
7032 case R_PPC64_DTPMOD64
:
7033 expecting_tls_get_addr
= 0;
7036 || !toc_ref
[rel
->r_offset
/ 8])
7038 if (rel
+ 1 < relend
7040 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7041 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7045 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7048 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7057 tls_set
= TLS_EXPLICIT
;
7063 expecting_tls_get_addr
= 0;
7067 if ((tls_set
& TLS_EXPLICIT
) == 0)
7069 struct got_entry
*ent
;
7071 /* Adjust got entry for this reloc. */
7075 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7077 for (; ent
!= NULL
; ent
= ent
->next
)
7078 if (ent
->addend
== rel
->r_addend
7079 && ent
->owner
== ibfd
7080 && ent
->tls_type
== tls_type
)
7087 /* We managed to get rid of a got entry. */
7088 if (ent
->got
.refcount
> 0)
7089 ent
->got
.refcount
-= 1;
7094 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7095 we'll lose one or two dyn relocs. */
7096 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7100 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7102 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7108 *tls_mask
|= tls_set
;
7109 *tls_mask
&= ~tls_clear
;
7112 if (elf_section_data (sec
)->relocs
!= relstart
)
7116 if (toc_ref
!= NULL
)
7120 && (elf_tdata (ibfd
)->symtab_hdr
.contents
7121 != (unsigned char *) locsyms
))
7123 if (!info
->keep_memory
)
7126 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
7132 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7133 the values of any global symbols in a toc section that has been
7134 edited. Globals in toc sections should be a rarity, so this function
7135 sets a flag if any are found in toc sections other than the one just
7136 edited, so that futher hash table traversals can be avoided. */
7138 struct adjust_toc_info
7141 unsigned long *skip
;
7142 bfd_boolean global_toc_syms
;
7146 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7148 struct ppc_link_hash_entry
*eh
;
7149 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7151 if (h
->root
.type
== bfd_link_hash_indirect
)
7154 if (h
->root
.type
== bfd_link_hash_warning
)
7155 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7157 if (h
->root
.type
!= bfd_link_hash_defined
7158 && h
->root
.type
!= bfd_link_hash_defweak
)
7161 eh
= (struct ppc_link_hash_entry
*) h
;
7162 if (eh
->adjust_done
)
7165 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7167 unsigned long skip
= toc_inf
->skip
[eh
->elf
.root
.u
.def
.value
>> 3];
7168 if (skip
!= (unsigned long) -1)
7169 eh
->elf
.root
.u
.def
.value
-= skip
;
7172 (*_bfd_error_handler
)
7173 (_("%s defined in removed toc entry"), eh
->elf
.root
.root
.string
);
7174 eh
->elf
.root
.u
.def
.section
= &bfd_abs_section
;
7175 eh
->elf
.root
.u
.def
.value
= 0;
7177 eh
->adjust_done
= 1;
7179 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7180 toc_inf
->global_toc_syms
= TRUE
;
7185 /* Examine all relocs referencing .toc sections in order to remove
7186 unused .toc entries. */
7189 ppc64_elf_edit_toc (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
7192 struct adjust_toc_info toc_inf
;
7194 toc_inf
.global_toc_syms
= TRUE
;
7195 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7197 asection
*toc
, *sec
;
7198 Elf_Internal_Shdr
*symtab_hdr
;
7199 Elf_Internal_Sym
*local_syms
;
7200 struct elf_link_hash_entry
**sym_hashes
;
7201 Elf_Internal_Rela
*relstart
, *rel
;
7202 unsigned long *skip
, *drop
;
7203 unsigned char *used
;
7204 unsigned char *keep
, last
, some_unused
;
7206 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7209 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7210 || elf_discarded_section (toc
))
7214 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7215 sym_hashes
= elf_sym_hashes (ibfd
);
7217 /* Look at sections dropped from the final link. */
7220 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7222 if (sec
->reloc_count
== 0
7223 || !elf_discarded_section (sec
)
7224 || get_opd_info (sec
)
7225 || (sec
->flags
& SEC_ALLOC
) == 0
7226 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7229 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7230 if (relstart
== NULL
)
7233 /* Run through the relocs to see which toc entries might be
7235 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7237 enum elf_ppc64_reloc_type r_type
;
7238 unsigned long r_symndx
;
7240 struct elf_link_hash_entry
*h
;
7241 Elf_Internal_Sym
*sym
;
7244 r_type
= ELF64_R_TYPE (rel
->r_info
);
7251 case R_PPC64_TOC16_LO
:
7252 case R_PPC64_TOC16_HI
:
7253 case R_PPC64_TOC16_HA
:
7254 case R_PPC64_TOC16_DS
:
7255 case R_PPC64_TOC16_LO_DS
:
7259 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7260 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7268 val
= h
->root
.u
.def
.value
;
7270 val
= sym
->st_value
;
7271 val
+= rel
->r_addend
;
7273 if (val
>= toc
->size
)
7276 /* Anything in the toc ought to be aligned to 8 bytes.
7277 If not, don't mark as unused. */
7283 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 7) / 8);
7291 if (elf_section_data (sec
)->relocs
!= relstart
)
7298 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
7302 if (local_syms
!= NULL
7303 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7307 && elf_section_data (sec
)->relocs
!= relstart
)
7314 /* Now check all kept sections that might reference the toc.
7315 Check the toc itself last. */
7316 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
7319 sec
= (sec
== toc
? NULL
7320 : sec
->next
== NULL
? toc
7321 : sec
->next
== toc
&& toc
->next
? toc
->next
7326 if (sec
->reloc_count
== 0
7327 || elf_discarded_section (sec
)
7328 || get_opd_info (sec
)
7329 || (sec
->flags
& SEC_ALLOC
) == 0
7330 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7333 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, TRUE
);
7334 if (relstart
== NULL
)
7337 /* Mark toc entries referenced as used. */
7340 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7342 enum elf_ppc64_reloc_type r_type
;
7343 unsigned long r_symndx
;
7345 struct elf_link_hash_entry
*h
;
7346 Elf_Internal_Sym
*sym
;
7349 r_type
= ELF64_R_TYPE (rel
->r_info
);
7353 case R_PPC64_TOC16_LO
:
7354 case R_PPC64_TOC16_HI
:
7355 case R_PPC64_TOC16_HA
:
7356 case R_PPC64_TOC16_DS
:
7357 case R_PPC64_TOC16_LO_DS
:
7358 /* In case we're taking addresses of toc entries. */
7359 case R_PPC64_ADDR64
:
7366 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7367 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7378 val
= h
->root
.u
.def
.value
;
7380 val
= sym
->st_value
;
7381 val
+= rel
->r_addend
;
7383 if (val
>= toc
->size
)
7386 /* For the toc section, we only mark as used if
7387 this entry itself isn't unused. */
7390 && (used
[rel
->r_offset
>> 3]
7391 || !skip
[rel
->r_offset
>> 3]))
7392 /* Do all the relocs again, to catch reference
7401 /* Merge the used and skip arrays. Assume that TOC
7402 doublewords not appearing as either used or unused belong
7403 to to an entry more than one doubleword in size. */
7404 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
7405 drop
< skip
+ (toc
->size
+ 7) / 8;
7426 bfd_byte
*contents
, *src
;
7429 /* Shuffle the toc contents, and at the same time convert the
7430 skip array from booleans into offsets. */
7431 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
7434 elf_section_data (toc
)->this_hdr
.contents
= contents
;
7436 for (src
= contents
, off
= 0, drop
= skip
;
7437 src
< contents
+ toc
->size
;
7442 *drop
= (unsigned long) -1;
7448 memcpy (src
- off
, src
, 8);
7451 toc
->rawsize
= toc
->size
;
7452 toc
->size
= src
- contents
- off
;
7454 if (toc
->reloc_count
!= 0)
7456 Elf_Internal_Rela
*wrel
;
7459 /* Read toc relocs. */
7460 relstart
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
7462 if (relstart
== NULL
)
7465 /* Remove unused toc relocs, and adjust those we keep. */
7467 for (rel
= relstart
; rel
< relstart
+ toc
->reloc_count
; ++rel
)
7468 if (skip
[rel
->r_offset
>> 3] != (unsigned long) -1)
7470 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
7471 wrel
->r_info
= rel
->r_info
;
7472 wrel
->r_addend
= rel
->r_addend
;
7475 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
7476 &local_syms
, NULL
, NULL
))
7479 toc
->reloc_count
= wrel
- relstart
;
7480 sz
= elf_section_data (toc
)->rel_hdr
.sh_entsize
;
7481 elf_section_data (toc
)->rel_hdr
.sh_size
= toc
->reloc_count
* sz
;
7482 BFD_ASSERT (elf_section_data (toc
)->rel_hdr2
== NULL
);
7485 /* Adjust addends for relocs against the toc section sym. */
7486 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7488 if (sec
->reloc_count
== 0
7489 || elf_discarded_section (sec
))
7492 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7494 if (relstart
== NULL
)
7497 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7499 enum elf_ppc64_reloc_type r_type
;
7500 unsigned long r_symndx
;
7502 struct elf_link_hash_entry
*h
;
7503 Elf_Internal_Sym
*sym
;
7505 r_type
= ELF64_R_TYPE (rel
->r_info
);
7512 case R_PPC64_TOC16_LO
:
7513 case R_PPC64_TOC16_HI
:
7514 case R_PPC64_TOC16_HA
:
7515 case R_PPC64_TOC16_DS
:
7516 case R_PPC64_TOC16_LO_DS
:
7517 case R_PPC64_ADDR64
:
7521 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7522 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7526 if (sym_sec
!= toc
|| h
!= NULL
|| sym
->st_value
!= 0)
7529 rel
->r_addend
-= skip
[rel
->r_addend
>> 3];
7533 /* We shouldn't have local or global symbols defined in the TOC,
7534 but handle them anyway. */
7535 if (local_syms
!= NULL
)
7537 Elf_Internal_Sym
*sym
;
7539 for (sym
= local_syms
;
7540 sym
< local_syms
+ symtab_hdr
->sh_info
;
7542 if (sym
->st_shndx
!= SHN_UNDEF
7543 && (sym
->st_shndx
< SHN_LORESERVE
7544 || sym
->st_shndx
> SHN_HIRESERVE
)
7545 && sym
->st_value
!= 0
7546 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
7548 if (skip
[sym
->st_value
>> 3] != (unsigned long) -1)
7549 sym
->st_value
-= skip
[sym
->st_value
>> 3];
7552 (*_bfd_error_handler
)
7553 (_("%s defined in removed toc entry"),
7554 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7557 sym
->st_shndx
= SHN_ABS
;
7559 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7563 /* Finally, adjust any global syms defined in the toc. */
7564 if (toc_inf
.global_toc_syms
)
7567 toc_inf
.skip
= skip
;
7568 toc_inf
.global_toc_syms
= FALSE
;
7569 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
7574 if (local_syms
!= NULL
7575 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7577 if (!info
->keep_memory
)
7580 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7588 /* Allocate space in .plt, .got and associated reloc sections for
7592 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7594 struct bfd_link_info
*info
;
7595 struct ppc_link_hash_table
*htab
;
7597 struct ppc_link_hash_entry
*eh
;
7598 struct ppc_dyn_relocs
*p
;
7599 struct got_entry
*gent
;
7601 if (h
->root
.type
== bfd_link_hash_indirect
)
7604 if (h
->root
.type
== bfd_link_hash_warning
)
7605 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7607 info
= (struct bfd_link_info
*) inf
;
7608 htab
= ppc_hash_table (info
);
7610 if (htab
->elf
.dynamic_sections_created
7612 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
7614 struct plt_entry
*pent
;
7615 bfd_boolean doneone
= FALSE
;
7616 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7617 if (pent
->plt
.refcount
> 0)
7619 /* If this is the first .plt entry, make room for the special
7623 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
7625 pent
->plt
.offset
= s
->size
;
7627 /* Make room for this entry. */
7628 s
->size
+= PLT_ENTRY_SIZE
;
7630 /* Make room for the .glink code. */
7633 s
->size
+= GLINK_CALL_STUB_SIZE
;
7634 /* We need bigger stubs past index 32767. */
7635 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
7639 /* We also need to make an entry in the .rela.plt section. */
7641 s
->size
+= sizeof (Elf64_External_Rela
);
7645 pent
->plt
.offset
= (bfd_vma
) -1;
7648 h
->plt
.plist
= NULL
;
7654 h
->plt
.plist
= NULL
;
7658 eh
= (struct ppc_link_hash_entry
*) h
;
7659 /* Run through the TLS GD got entries first if we're changing them
7661 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
7662 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7663 if (gent
->got
.refcount
> 0
7664 && (gent
->tls_type
& TLS_GD
) != 0)
7666 /* This was a GD entry that has been converted to TPREL. If
7667 there happens to be a TPREL entry we can use that one. */
7668 struct got_entry
*ent
;
7669 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
7670 if (ent
->got
.refcount
> 0
7671 && (ent
->tls_type
& TLS_TPREL
) != 0
7672 && ent
->addend
== gent
->addend
7673 && ent
->owner
== gent
->owner
)
7675 gent
->got
.refcount
= 0;
7679 /* If not, then we'll be using our own TPREL entry. */
7680 if (gent
->got
.refcount
!= 0)
7681 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
7684 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7685 if (gent
->got
.refcount
> 0)
7689 /* Make sure this symbol is output as a dynamic symbol.
7690 Undefined weak syms won't yet be marked as dynamic,
7691 nor will all TLS symbols. */
7692 if (h
->dynindx
== -1
7693 && !h
->forced_local
)
7695 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7699 if ((gent
->tls_type
& TLS_LD
) != 0
7702 gent
->got
.offset
= ppc64_tlsld_got (gent
->owner
)->offset
;
7706 s
= ppc64_elf_tdata (gent
->owner
)->got
;
7707 gent
->got
.offset
= s
->size
;
7709 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
7710 dyn
= htab
->elf
.dynamic_sections_created
;
7712 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
7713 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7714 || h
->root
.type
!= bfd_link_hash_undefweak
))
7715 ppc64_elf_tdata (gent
->owner
)->relgot
->size
7716 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
7717 ? 2 * sizeof (Elf64_External_Rela
)
7718 : sizeof (Elf64_External_Rela
));
7721 gent
->got
.offset
= (bfd_vma
) -1;
7723 if (eh
->dyn_relocs
== NULL
)
7726 /* In the shared -Bsymbolic case, discard space allocated for
7727 dynamic pc-relative relocs against symbols which turn out to be
7728 defined in regular objects. For the normal shared case, discard
7729 space for relocs that have become local due to symbol visibility
7734 /* Relocs that use pc_count are those that appear on a call insn,
7735 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
7736 generated via assembly. We want calls to protected symbols to
7737 resolve directly to the function rather than going via the plt.
7738 If people want function pointer comparisons to work as expected
7739 then they should avoid writing weird assembly. */
7740 if (SYMBOL_CALLS_LOCAL (info
, h
))
7742 struct ppc_dyn_relocs
**pp
;
7744 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
7746 p
->count
-= p
->pc_count
;
7755 /* Also discard relocs on undefined weak syms with non-default
7757 if (eh
->dyn_relocs
!= NULL
7758 && h
->root
.type
== bfd_link_hash_undefweak
)
7760 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7761 eh
->dyn_relocs
= NULL
;
7763 /* Make sure this symbol is output as a dynamic symbol.
7764 Undefined weak syms won't yet be marked as dynamic. */
7765 else if (h
->dynindx
== -1
7766 && !h
->forced_local
)
7768 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7773 else if (ELIMINATE_COPY_RELOCS
)
7775 /* For the non-shared case, discard space for relocs against
7776 symbols which turn out to need copy relocs or are not
7783 /* Make sure this symbol is output as a dynamic symbol.
7784 Undefined weak syms won't yet be marked as dynamic. */
7785 if (h
->dynindx
== -1
7786 && !h
->forced_local
)
7788 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7792 /* If that succeeded, we know we'll be keeping all the
7794 if (h
->dynindx
!= -1)
7798 eh
->dyn_relocs
= NULL
;
7803 /* Finally, allocate space. */
7804 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7806 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
7807 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7813 /* Find any dynamic relocs that apply to read-only sections. */
7816 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7818 struct ppc_link_hash_entry
*eh
;
7819 struct ppc_dyn_relocs
*p
;
7821 if (h
->root
.type
== bfd_link_hash_warning
)
7822 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7824 eh
= (struct ppc_link_hash_entry
*) h
;
7825 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7827 asection
*s
= p
->sec
->output_section
;
7829 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7831 struct bfd_link_info
*info
= inf
;
7833 info
->flags
|= DF_TEXTREL
;
7835 /* Not an error, just cut short the traversal. */
7842 /* Set the sizes of the dynamic sections. */
7845 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7846 struct bfd_link_info
*info
)
7848 struct ppc_link_hash_table
*htab
;
7854 htab
= ppc_hash_table (info
);
7855 dynobj
= htab
->elf
.dynobj
;
7859 if (htab
->elf
.dynamic_sections_created
)
7861 /* Set the contents of the .interp section to the interpreter. */
7862 if (info
->executable
)
7864 s
= bfd_get_section_by_name (dynobj
, ".interp");
7867 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7868 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7872 /* Set up .got offsets for local syms, and space for local dynamic
7874 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7876 struct got_entry
**lgot_ents
;
7877 struct got_entry
**end_lgot_ents
;
7879 bfd_size_type locsymcount
;
7880 Elf_Internal_Shdr
*symtab_hdr
;
7883 if (!is_ppc64_elf_target (ibfd
->xvec
))
7886 if (ppc64_tlsld_got (ibfd
)->refcount
> 0)
7888 s
= ppc64_elf_tdata (ibfd
)->got
;
7889 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7893 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7894 srel
->size
+= sizeof (Elf64_External_Rela
);
7898 ppc64_tlsld_got (ibfd
)->offset
= (bfd_vma
) -1;
7900 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7902 struct ppc_dyn_relocs
*p
;
7904 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
7906 if (!bfd_is_abs_section (p
->sec
)
7907 && bfd_is_abs_section (p
->sec
->output_section
))
7909 /* Input section has been discarded, either because
7910 it is a copy of a linkonce section or due to
7911 linker script /DISCARD/, so we'll be discarding
7914 else if (p
->count
!= 0)
7916 srel
= elf_section_data (p
->sec
)->sreloc
;
7917 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7918 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7919 info
->flags
|= DF_TEXTREL
;
7924 lgot_ents
= elf_local_got_ents (ibfd
);
7928 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7929 locsymcount
= symtab_hdr
->sh_info
;
7930 end_lgot_ents
= lgot_ents
+ locsymcount
;
7931 lgot_masks
= (char *) end_lgot_ents
;
7932 s
= ppc64_elf_tdata (ibfd
)->got
;
7933 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7934 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
7936 struct got_entry
*ent
;
7938 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
7939 if (ent
->got
.refcount
> 0)
7941 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
7943 if (ppc64_tlsld_got (ibfd
)->offset
== (bfd_vma
) -1)
7945 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7948 srel
->size
+= sizeof (Elf64_External_Rela
);
7950 ent
->got
.offset
= ppc64_tlsld_got (ibfd
)->offset
;
7954 ent
->got
.offset
= s
->size
;
7955 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
7959 srel
->size
+= 2 * sizeof (Elf64_External_Rela
);
7965 srel
->size
+= sizeof (Elf64_External_Rela
);
7970 ent
->got
.offset
= (bfd_vma
) -1;
7974 /* Allocate global sym .plt and .got entries, and space for global
7975 sym dynamic relocs. */
7976 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
7978 /* We now have determined the sizes of the various dynamic sections.
7979 Allocate memory for them. */
7981 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7983 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7986 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
7987 /* These haven't been allocated yet; don't strip. */
7989 else if (s
== htab
->got
7992 || s
== htab
->dynbss
)
7994 /* Strip this section if we don't need it; see the
7997 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
8001 if (s
!= htab
->relplt
)
8004 /* We use the reloc_count field as a counter if we need
8005 to copy relocs into the output file. */
8011 /* It's not one of our sections, so don't allocate space. */
8017 /* If we don't need this section, strip it from the
8018 output file. This is mostly to handle .rela.bss and
8019 .rela.plt. We must create both sections in
8020 create_dynamic_sections, because they must be created
8021 before the linker maps input sections to output
8022 sections. The linker does that before
8023 adjust_dynamic_symbol is called, and it is that
8024 function which decides whether anything needs to go
8025 into these sections. */
8026 s
->flags
|= SEC_EXCLUDE
;
8030 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8033 /* Allocate memory for the section contents. We use bfd_zalloc
8034 here in case unused entries are not reclaimed before the
8035 section's contents are written out. This should not happen,
8036 but this way if it does we get a R_PPC64_NONE reloc in .rela
8037 sections instead of garbage.
8038 We also rely on the section contents being zero when writing
8040 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8041 if (s
->contents
== NULL
)
8045 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8047 if (!is_ppc64_elf_target (ibfd
->xvec
))
8050 s
= ppc64_elf_tdata (ibfd
)->got
;
8051 if (s
!= NULL
&& s
!= htab
->got
)
8054 s
->flags
|= SEC_EXCLUDE
;
8057 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8058 if (s
->contents
== NULL
)
8062 s
= ppc64_elf_tdata (ibfd
)->relgot
;
8066 s
->flags
|= SEC_EXCLUDE
;
8069 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8070 if (s
->contents
== NULL
)
8078 if (htab
->elf
.dynamic_sections_created
)
8080 /* Add some entries to the .dynamic section. We fill in the
8081 values later, in ppc64_elf_finish_dynamic_sections, but we
8082 must add the entries now so that we get the correct size for
8083 the .dynamic section. The DT_DEBUG entry is filled in by the
8084 dynamic linker and used by the debugger. */
8085 #define add_dynamic_entry(TAG, VAL) \
8086 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8088 if (info
->executable
)
8090 if (!add_dynamic_entry (DT_DEBUG
, 0))
8094 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
8096 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8097 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8098 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8099 || !add_dynamic_entry (DT_JMPREL
, 0)
8100 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
8106 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
8107 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
8113 if (!add_dynamic_entry (DT_RELA
, 0)
8114 || !add_dynamic_entry (DT_RELASZ
, 0)
8115 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
8118 /* If any dynamic relocs apply to a read-only section,
8119 then we need a DT_TEXTREL entry. */
8120 if ((info
->flags
& DF_TEXTREL
) == 0)
8121 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
8123 if ((info
->flags
& DF_TEXTREL
) != 0)
8125 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8130 #undef add_dynamic_entry
8135 /* Determine the type of stub needed, if any, for a call. */
8137 static inline enum ppc_stub_type
8138 ppc_type_of_stub (asection
*input_sec
,
8139 const Elf_Internal_Rela
*rel
,
8140 struct ppc_link_hash_entry
**hash
,
8141 bfd_vma destination
)
8143 struct ppc_link_hash_entry
*h
= *hash
;
8145 bfd_vma branch_offset
;
8146 bfd_vma max_branch_offset
;
8147 enum elf_ppc64_reloc_type r_type
;
8151 struct ppc_link_hash_entry
*fdh
= h
;
8153 && fdh
->oh
->is_func_descriptor
)
8156 if (fdh
->elf
.dynindx
!= -1)
8158 struct plt_entry
*ent
;
8160 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8161 if (ent
->addend
== rel
->r_addend
8162 && ent
->plt
.offset
!= (bfd_vma
) -1)
8165 return ppc_stub_plt_call
;
8169 /* Here, we know we don't have a plt entry. If we don't have a
8170 either a defined function descriptor or a defined entry symbol
8171 in a regular object file, then it is pointless trying to make
8172 any other type of stub. */
8173 if (!((fdh
->elf
.root
.type
== bfd_link_hash_defined
8174 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
8175 && fdh
->elf
.root
.u
.def
.section
->output_section
!= NULL
)
8176 && !((h
->elf
.root
.type
== bfd_link_hash_defined
8177 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
8178 && h
->elf
.root
.u
.def
.section
->output_section
!= NULL
))
8179 return ppc_stub_none
;
8182 /* Determine where the call point is. */
8183 location
= (input_sec
->output_offset
8184 + input_sec
->output_section
->vma
8187 branch_offset
= destination
- location
;
8188 r_type
= ELF64_R_TYPE (rel
->r_info
);
8190 /* Determine if a long branch stub is needed. */
8191 max_branch_offset
= 1 << 25;
8192 if (r_type
!= R_PPC64_REL24
)
8193 max_branch_offset
= 1 << 15;
8195 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
8196 /* We need a stub. Figure out whether a long_branch or plt_branch
8198 return ppc_stub_long_branch
;
8200 return ppc_stub_none
;
8203 /* Build a .plt call stub. */
8205 static inline bfd_byte
*
8206 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
)
8208 #define PPC_LO(v) ((v) & 0xffff)
8209 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8210 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8212 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
8213 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
8214 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8215 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8216 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8218 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
8219 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8220 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8222 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
8223 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8224 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
8229 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8231 struct ppc_stub_hash_entry
*stub_entry
;
8232 struct ppc_branch_hash_entry
*br_entry
;
8233 struct bfd_link_info
*info
;
8234 struct ppc_link_hash_table
*htab
;
8238 struct plt_entry
*ent
;
8242 /* Massage our args to the form they really have. */
8243 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8246 htab
= ppc_hash_table (info
);
8248 /* Make a note of the offset within the stubs for this entry. */
8249 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
8250 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
8252 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
8253 switch (stub_entry
->stub_type
)
8255 case ppc_stub_long_branch
:
8256 case ppc_stub_long_branch_r2off
:
8257 /* Branches are relative. This is where we are going to. */
8258 off
= dest
= (stub_entry
->target_value
8259 + stub_entry
->target_section
->output_offset
8260 + stub_entry
->target_section
->output_section
->vma
);
8262 /* And this is where we are coming from. */
8263 off
-= (stub_entry
->stub_offset
8264 + stub_entry
->stub_sec
->output_offset
8265 + stub_entry
->stub_sec
->output_section
->vma
);
8267 if (stub_entry
->stub_type
!= ppc_stub_long_branch_r2off
)
8273 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8274 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8275 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8277 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8279 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8284 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
8286 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8288 (*_bfd_error_handler
) (_("long branch stub `%s' offset overflow"),
8289 stub_entry
->root
.string
);
8290 htab
->stub_error
= TRUE
;
8294 if (info
->emitrelocations
)
8296 Elf_Internal_Rela
*relocs
, *r
;
8297 struct bfd_elf_section_data
*elfsec_data
;
8299 elfsec_data
= elf_section_data (stub_entry
->stub_sec
);
8300 relocs
= elfsec_data
->relocs
;
8303 bfd_size_type relsize
;
8304 relsize
= stub_entry
->stub_sec
->reloc_count
* sizeof (*relocs
);
8305 relocs
= bfd_alloc (htab
->stub_bfd
, relsize
);
8308 elfsec_data
->relocs
= relocs
;
8309 elfsec_data
->rel_hdr
.sh_size
= relsize
;
8310 elfsec_data
->rel_hdr
.sh_entsize
= 24;
8311 stub_entry
->stub_sec
->reloc_count
= 0;
8313 r
= relocs
+ stub_entry
->stub_sec
->reloc_count
;
8314 stub_entry
->stub_sec
->reloc_count
+= 1;
8315 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
8316 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
8318 if (stub_entry
->h
!= NULL
)
8320 struct elf_link_hash_entry
**hashes
;
8321 unsigned long symndx
;
8322 struct ppc_link_hash_entry
*h
;
8324 hashes
= elf_sym_hashes (htab
->stub_bfd
);
8327 bfd_size_type hsize
;
8329 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
8330 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
8333 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
8334 htab
->stub_globals
= 1;
8336 symndx
= htab
->stub_globals
++;
8338 hashes
[symndx
] = &h
->elf
;
8339 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
8340 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
8342 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
8343 /* H is an opd symbol. The addend must be zero. */
8347 off
= (h
->elf
.root
.u
.def
.value
8348 + h
->elf
.root
.u
.def
.section
->output_offset
8349 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
8356 case ppc_stub_plt_branch
:
8357 case ppc_stub_plt_branch_r2off
:
8358 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8359 stub_entry
->root
.string
+ 9,
8361 if (br_entry
== NULL
)
8363 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
8364 stub_entry
->root
.string
);
8365 htab
->stub_error
= TRUE
;
8369 off
= (stub_entry
->target_value
8370 + stub_entry
->target_section
->output_offset
8371 + stub_entry
->target_section
->output_section
->vma
);
8373 bfd_put_64 (htab
->brlt
->owner
, off
,
8374 htab
->brlt
->contents
+ br_entry
->offset
);
8376 if (htab
->relbrlt
!= NULL
)
8378 /* Create a reloc for the branch lookup table entry. */
8379 Elf_Internal_Rela rela
;
8382 rela
.r_offset
= (br_entry
->offset
8383 + htab
->brlt
->output_offset
8384 + htab
->brlt
->output_section
->vma
);
8385 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8386 rela
.r_addend
= off
;
8388 rl
= htab
->relbrlt
->contents
;
8389 rl
+= htab
->relbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8390 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
8392 else if (info
->emitrelocations
)
8394 Elf_Internal_Rela
*relocs
, *r
;
8395 struct bfd_elf_section_data
*elfsec_data
;
8397 elfsec_data
= elf_section_data (htab
->brlt
);
8398 relocs
= elfsec_data
->relocs
;
8401 bfd_size_type relsize
;
8402 relsize
= htab
->brlt
->reloc_count
* sizeof (*relocs
);
8403 relocs
= bfd_alloc (htab
->brlt
->owner
, relsize
);
8406 elfsec_data
->relocs
= relocs
;
8407 elfsec_data
->rel_hdr
.sh_size
= relsize
;
8408 elfsec_data
->rel_hdr
.sh_entsize
= 24;
8409 htab
->brlt
->reloc_count
= 0;
8411 r
= relocs
+ htab
->brlt
->reloc_count
;
8412 htab
->brlt
->reloc_count
+= 1;
8413 r
->r_offset
= (br_entry
->offset
8414 + htab
->brlt
->output_offset
8415 + htab
->brlt
->output_section
->vma
);
8416 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8420 off
= (br_entry
->offset
8421 + htab
->brlt
->output_offset
8422 + htab
->brlt
->output_section
->vma
8423 - elf_gp (htab
->brlt
->output_section
->owner
)
8424 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8426 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8428 (*_bfd_error_handler
)
8429 (_("linkage table error against `%s'"),
8430 stub_entry
->root
.string
);
8431 bfd_set_error (bfd_error_bad_value
);
8432 htab
->stub_error
= TRUE
;
8437 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
8439 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8441 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8448 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8449 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8450 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8452 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8454 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8456 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8458 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8462 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
8464 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
8467 case ppc_stub_plt_call
:
8468 /* Do the best we can for shared libraries built without
8469 exporting ".foo" for each "foo". This can happen when symbol
8470 versioning scripts strip all bar a subset of symbols. */
8471 if (stub_entry
->h
->oh
!= NULL
8472 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defined
8473 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8475 /* Point the symbol at the stub. There may be multiple stubs,
8476 we don't really care; The main thing is to make this sym
8477 defined somewhere. Maybe defining the symbol in the stub
8478 section is a silly idea. If we didn't do this, htab->top_id
8480 stub_entry
->h
->oh
->elf
.root
.type
= bfd_link_hash_defined
;
8481 stub_entry
->h
->oh
->elf
.root
.u
.def
.section
= stub_entry
->stub_sec
;
8482 stub_entry
->h
->oh
->elf
.root
.u
.def
.value
= stub_entry
->stub_offset
;
8485 /* Now build the stub. */
8487 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8488 if (ent
->addend
== stub_entry
->addend
)
8490 off
= ent
->plt
.offset
;
8493 if (off
>= (bfd_vma
) -2)
8496 off
&= ~ (bfd_vma
) 1;
8497 off
+= (htab
->plt
->output_offset
8498 + htab
->plt
->output_section
->vma
8499 - elf_gp (htab
->plt
->output_section
->owner
)
8500 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8502 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8504 (*_bfd_error_handler
)
8505 (_("linkage table error against `%s'"),
8506 stub_entry
->h
->elf
.root
.root
.string
);
8507 bfd_set_error (bfd_error_bad_value
);
8508 htab
->stub_error
= TRUE
;
8512 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
);
8521 stub_entry
->stub_sec
->size
+= size
;
8523 if (htab
->emit_stub_syms
)
8525 struct elf_link_hash_entry
*h
;
8528 const char *const stub_str
[] = { "long_branch",
8529 "long_branch_r2off",
8534 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
8535 len2
= strlen (stub_entry
->root
.string
);
8536 name
= bfd_malloc (len1
+ len2
+ 2);
8539 memcpy (name
, stub_entry
->root
.string
, 9);
8540 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
8541 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
8542 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
8545 if (h
->root
.type
== bfd_link_hash_new
)
8547 h
->root
.type
= bfd_link_hash_defined
;
8548 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
8549 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
8552 h
->ref_regular_nonweak
= 1;
8553 h
->forced_local
= 1;
8561 /* As above, but don't actually build the stub. Just bump offset so
8562 we know stub section sizes, and select plt_branch stubs where
8563 long_branch stubs won't do. */
8566 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8568 struct ppc_stub_hash_entry
*stub_entry
;
8569 struct bfd_link_info
*info
;
8570 struct ppc_link_hash_table
*htab
;
8574 /* Massage our args to the form they really have. */
8575 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8578 htab
= ppc_hash_table (info
);
8580 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
8582 struct plt_entry
*ent
;
8584 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8585 if (ent
->addend
== stub_entry
->addend
)
8587 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
8590 if (off
>= (bfd_vma
) -2)
8592 off
+= (htab
->plt
->output_offset
8593 + htab
->plt
->output_section
->vma
8594 - elf_gp (htab
->plt
->output_section
->owner
)
8595 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8597 size
= PLT_CALL_STUB_SIZE
;
8598 if (PPC_HA (off
+ 16) != PPC_HA (off
))
8603 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
8605 off
= (stub_entry
->target_value
8606 + stub_entry
->target_section
->output_offset
8607 + stub_entry
->target_section
->output_section
->vma
);
8608 off
-= (stub_entry
->stub_sec
->size
8609 + stub_entry
->stub_sec
->output_offset
8610 + stub_entry
->stub_sec
->output_section
->vma
);
8612 /* Reset the stub type from the plt variant in case we now
8613 can reach with a shorter stub. */
8614 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
8615 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
8618 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
8624 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
8625 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8627 struct ppc_branch_hash_entry
*br_entry
;
8629 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8630 stub_entry
->root
.string
+ 9,
8632 if (br_entry
== NULL
)
8634 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
8635 stub_entry
->root
.string
);
8636 htab
->stub_error
= TRUE
;
8640 if (br_entry
->iter
!= htab
->stub_iteration
)
8642 br_entry
->iter
= htab
->stub_iteration
;
8643 br_entry
->offset
= htab
->brlt
->size
;
8644 htab
->brlt
->size
+= 8;
8646 if (htab
->relbrlt
!= NULL
)
8647 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
8648 else if (info
->emitrelocations
)
8650 htab
->brlt
->reloc_count
+= 1;
8651 htab
->brlt
->flags
|= SEC_RELOC
;
8655 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
8657 if (stub_entry
->stub_type
!= ppc_stub_plt_branch
)
8660 else if (info
->emitrelocations
)
8662 stub_entry
->stub_sec
->reloc_count
+= 1;
8663 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
8667 stub_entry
->stub_sec
->size
+= size
;
8671 /* Set up various things so that we can make a list of input sections
8672 for each output section included in the link. Returns -1 on error,
8673 0 when no stubs will be needed, and 1 on success. */
8676 ppc64_elf_setup_section_lists (bfd
*output_bfd
,
8677 struct bfd_link_info
*info
,
8681 int top_id
, top_index
, id
;
8683 asection
**input_list
;
8685 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8687 htab
->no_multi_toc
= no_multi_toc
;
8689 if (htab
->brlt
== NULL
)
8692 /* Find the top input section id. */
8693 for (input_bfd
= info
->input_bfds
, top_id
= 3;
8695 input_bfd
= input_bfd
->link_next
)
8697 for (section
= input_bfd
->sections
;
8699 section
= section
->next
)
8701 if (top_id
< section
->id
)
8702 top_id
= section
->id
;
8706 htab
->top_id
= top_id
;
8707 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
8708 htab
->stub_group
= bfd_zmalloc (amt
);
8709 if (htab
->stub_group
== NULL
)
8712 /* Set toc_off for com, und, abs and ind sections. */
8713 for (id
= 0; id
< 3; id
++)
8714 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
8716 elf_gp (output_bfd
) = htab
->toc_curr
= ppc64_elf_toc (output_bfd
);
8718 /* We can't use output_bfd->section_count here to find the top output
8719 section index as some sections may have been removed, and
8720 strip_excluded_output_sections doesn't renumber the indices. */
8721 for (section
= output_bfd
->sections
, top_index
= 0;
8723 section
= section
->next
)
8725 if (top_index
< section
->index
)
8726 top_index
= section
->index
;
8729 htab
->top_index
= top_index
;
8730 amt
= sizeof (asection
*) * (top_index
+ 1);
8731 input_list
= bfd_zmalloc (amt
);
8732 htab
->input_list
= input_list
;
8733 if (input_list
== NULL
)
8739 /* The linker repeatedly calls this function for each TOC input section
8740 and linker generated GOT section. Group input bfds such that the toc
8741 within a group is less than 64k in size. Will break with cute linker
8742 scripts that play games with dot in the output toc section. */
8745 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
8747 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8749 if (!htab
->no_multi_toc
)
8751 bfd_vma addr
= isec
->output_offset
+ isec
->output_section
->vma
;
8752 bfd_vma off
= addr
- htab
->toc_curr
;
8754 if (off
+ isec
->size
> 0x10000)
8755 htab
->toc_curr
= addr
;
8757 elf_gp (isec
->owner
) = (htab
->toc_curr
8758 - elf_gp (isec
->output_section
->owner
)
8763 /* Called after the last call to the above function. */
8766 ppc64_elf_reinit_toc (bfd
*output_bfd
, struct bfd_link_info
*info
)
8768 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8770 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (output_bfd
);
8772 /* toc_curr tracks the TOC offset used for code sections below in
8773 ppc64_elf_next_input_section. Start off at 0x8000. */
8774 htab
->toc_curr
= TOC_BASE_OFF
;
8777 /* No toc references were found in ISEC. If the code in ISEC makes no
8778 calls, then there's no need to use toc adjusting stubs when branching
8779 into ISEC. Actually, indirect calls from ISEC are OK as they will
8780 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
8781 needed, and 2 if a cyclical call-graph was found but no other reason
8782 for a stub was detected. If called from the top level, a return of
8783 2 means the same as a return of 0. */
8786 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
8788 Elf_Internal_Rela
*relstart
, *rel
;
8789 Elf_Internal_Sym
*local_syms
;
8791 struct ppc_link_hash_table
*htab
;
8793 /* We know none of our code bearing sections will need toc stubs. */
8794 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
8797 if (isec
->size
== 0)
8800 if (isec
->output_section
== NULL
)
8803 /* Hack for linux kernel. .fixup contains branches, but only back to
8804 the function that hit an exception. */
8805 if (strcmp (isec
->name
, ".fixup") == 0)
8808 if (isec
->reloc_count
== 0)
8811 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
8813 if (relstart
== NULL
)
8816 /* Look for branches to outside of this section. */
8819 htab
= ppc_hash_table (info
);
8820 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
8822 enum elf_ppc64_reloc_type r_type
;
8823 unsigned long r_symndx
;
8824 struct elf_link_hash_entry
*h
;
8825 Elf_Internal_Sym
*sym
;
8831 r_type
= ELF64_R_TYPE (rel
->r_info
);
8832 if (r_type
!= R_PPC64_REL24
8833 && r_type
!= R_PPC64_REL14
8834 && r_type
!= R_PPC64_REL14_BRTAKEN
8835 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
8838 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8839 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
8846 /* Calls to dynamic lib functions go through a plt call stub
8847 that uses r2. Branches to undefined symbols might be a call
8848 using old-style dot symbols that can be satisfied by a plt
8849 call into a new-style dynamic library. */
8850 if (sym_sec
== NULL
)
8852 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8855 && eh
->oh
->elf
.plt
.plist
!= NULL
)
8861 /* Ignore other undefined symbols. */
8865 /* Assume branches to other sections not included in the link need
8866 stubs too, to cover -R and absolute syms. */
8867 if (sym_sec
->output_section
== NULL
)
8874 sym_value
= sym
->st_value
;
8877 if (h
->root
.type
!= bfd_link_hash_defined
8878 && h
->root
.type
!= bfd_link_hash_defweak
)
8880 sym_value
= h
->root
.u
.def
.value
;
8882 sym_value
+= rel
->r_addend
;
8884 /* If this branch reloc uses an opd sym, find the code section. */
8885 opd_adjust
= get_opd_info (sym_sec
);
8886 if (opd_adjust
!= NULL
)
8892 adjust
= opd_adjust
[sym
->st_value
/ 8];
8894 /* Assume deleted functions won't ever be called. */
8896 sym_value
+= adjust
;
8899 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
8900 if (dest
== (bfd_vma
) -1)
8905 + sym_sec
->output_offset
8906 + sym_sec
->output_section
->vma
);
8908 /* Ignore branch to self. */
8909 if (sym_sec
== isec
)
8912 /* If the called function uses the toc, we need a stub. */
8913 if (sym_sec
->has_toc_reloc
8914 || sym_sec
->makes_toc_func_call
)
8920 /* Assume any branch that needs a long branch stub might in fact
8921 need a plt_branch stub. A plt_branch stub uses r2. */
8922 else if (dest
- (isec
->output_offset
8923 + isec
->output_section
->vma
8924 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
8930 /* If calling back to a section in the process of being tested, we
8931 can't say for sure that no toc adjusting stubs are needed, so
8932 don't return zero. */
8933 else if (sym_sec
->call_check_in_progress
)
8936 /* Branches to another section that itself doesn't have any TOC
8937 references are OK. Recursively call ourselves to check. */
8938 else if (sym_sec
->id
<= htab
->top_id
8939 && htab
->stub_group
[sym_sec
->id
].toc_off
== 0)
8943 /* Mark current section as indeterminate, so that other
8944 sections that call back to current won't be marked as
8946 isec
->call_check_in_progress
= 1;
8947 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
8948 isec
->call_check_in_progress
= 0;
8952 /* An error. Exit. */
8956 else if (recur
<= 1)
8958 /* Known result. Mark as checked and set section flag. */
8959 htab
->stub_group
[sym_sec
->id
].toc_off
= 1;
8962 sym_sec
->makes_toc_func_call
= 1;
8969 /* Unknown result. Continue checking. */
8975 if (local_syms
!= NULL
8976 && (elf_tdata (isec
->owner
)->symtab_hdr
.contents
8977 != (unsigned char *) local_syms
))
8979 if (elf_section_data (isec
)->relocs
!= relstart
)
8985 /* The linker repeatedly calls this function for each input section,
8986 in the order that input sections are linked into output sections.
8987 Build lists of input sections to determine groupings between which
8988 we may insert linker stubs. */
8991 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
8993 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8995 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
8996 && isec
->output_section
->index
<= htab
->top_index
)
8998 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
8999 /* Steal the link_sec pointer for our list. */
9000 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
9001 /* This happens to make the list in reverse order,
9002 which is what we want. */
9003 PREV_SEC (isec
) = *list
;
9007 if (htab
->multi_toc_needed
)
9009 /* If a code section has a function that uses the TOC then we need
9010 to use the right TOC (obviously). Also, make sure that .opd gets
9011 the correct TOC value for R_PPC64_TOC relocs that don't have or
9012 can't find their function symbol (shouldn't ever happen now). */
9013 if (isec
->has_toc_reloc
|| (isec
->flags
& SEC_CODE
) == 0)
9015 if (elf_gp (isec
->owner
) != 0)
9016 htab
->toc_curr
= elf_gp (isec
->owner
);
9018 else if (htab
->stub_group
[isec
->id
].toc_off
== 0)
9020 int ret
= toc_adjusting_stub_needed (info
, isec
);
9024 isec
->makes_toc_func_call
= ret
& 1;
9028 /* Functions that don't use the TOC can belong in any TOC group.
9029 Use the last TOC base. This happens to make _init and _fini
9031 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
9035 /* See whether we can group stub sections together. Grouping stub
9036 sections may result in fewer stubs. More importantly, we need to
9037 put all .init* and .fini* stubs at the beginning of the .init or
9038 .fini output sections respectively, because glibc splits the
9039 _init and _fini functions into multiple parts. Putting a stub in
9040 the middle of a function is not a good idea. */
9043 group_sections (struct ppc_link_hash_table
*htab
,
9044 bfd_size_type stub_group_size
,
9045 bfd_boolean stubs_always_before_branch
)
9048 bfd_size_type stub14_group_size
;
9049 bfd_boolean suppress_size_errors
;
9051 suppress_size_errors
= FALSE
;
9052 stub14_group_size
= stub_group_size
;
9053 if (stub_group_size
== 1)
9055 /* Default values. */
9056 if (stubs_always_before_branch
)
9058 stub_group_size
= 0x1e00000;
9059 stub14_group_size
= 0x7800;
9063 stub_group_size
= 0x1c00000;
9064 stub14_group_size
= 0x7000;
9066 suppress_size_errors
= TRUE
;
9069 list
= htab
->input_list
+ htab
->top_index
;
9072 asection
*tail
= *list
;
9073 while (tail
!= NULL
)
9077 bfd_size_type total
;
9078 bfd_boolean big_sec
;
9083 big_sec
= total
> (ppc64_elf_section_data (tail
)->has_14bit_branch
9084 ? stub14_group_size
: stub_group_size
);
9085 if (big_sec
&& !suppress_size_errors
)
9086 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
9088 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
9090 while ((prev
= PREV_SEC (curr
)) != NULL
9091 && ((total
+= curr
->output_offset
- prev
->output_offset
)
9092 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9093 ? stub14_group_size
: stub_group_size
))
9094 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9097 /* OK, the size from the start of CURR to the end is less
9098 than stub_group_size and thus can be handled by one stub
9099 section. (or the tail section is itself larger than
9100 stub_group_size, in which case we may be toast.) We
9101 should really be keeping track of the total size of stubs
9102 added here, as stubs contribute to the final output
9103 section size. That's a little tricky, and this way will
9104 only break if stubs added make the total size more than
9105 2^25, ie. for the default stub_group_size, if stubs total
9106 more than 2097152 bytes, or nearly 75000 plt call stubs. */
9109 prev
= PREV_SEC (tail
);
9110 /* Set up this stub group. */
9111 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9113 while (tail
!= curr
&& (tail
= prev
) != NULL
);
9115 /* But wait, there's more! Input sections up to stub_group_size
9116 bytes before the stub section can be handled by it too.
9117 Don't do this if we have a really large section after the
9118 stubs, as adding more stubs increases the chance that
9119 branches may not reach into the stub section. */
9120 if (!stubs_always_before_branch
&& !big_sec
)
9124 && ((total
+= tail
->output_offset
- prev
->output_offset
)
9125 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9126 ? stub14_group_size
: stub_group_size
))
9127 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9130 prev
= PREV_SEC (tail
);
9131 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9137 while (list
-- != htab
->input_list
);
9138 free (htab
->input_list
);
9142 /* Determine and set the size of the stub section for a final link.
9144 The basic idea here is to examine all the relocations looking for
9145 PC-relative calls to a target that is unreachable with a "bl"
9149 ppc64_elf_size_stubs (bfd
*output_bfd
,
9150 struct bfd_link_info
*info
,
9151 bfd_signed_vma group_size
,
9152 asection
*(*add_stub_section
) (const char *, asection
*),
9153 void (*layout_sections_again
) (void))
9155 bfd_size_type stub_group_size
;
9156 bfd_boolean stubs_always_before_branch
;
9157 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9159 /* Stash our params away. */
9160 htab
->add_stub_section
= add_stub_section
;
9161 htab
->layout_sections_again
= layout_sections_again
;
9162 stubs_always_before_branch
= group_size
< 0;
9164 stub_group_size
= -group_size
;
9166 stub_group_size
= group_size
;
9168 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
9173 unsigned int bfd_indx
;
9176 htab
->stub_iteration
+= 1;
9178 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
9180 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
9182 Elf_Internal_Shdr
*symtab_hdr
;
9184 Elf_Internal_Sym
*local_syms
= NULL
;
9186 if (!is_ppc64_elf_target (input_bfd
->xvec
))
9189 /* We'll need the symbol table in a second. */
9190 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9191 if (symtab_hdr
->sh_info
== 0)
9194 /* Walk over each section attached to the input bfd. */
9195 for (section
= input_bfd
->sections
;
9197 section
= section
->next
)
9199 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
9201 /* If there aren't any relocs, then there's nothing more
9203 if ((section
->flags
& SEC_RELOC
) == 0
9204 || (section
->flags
& SEC_ALLOC
) == 0
9205 || (section
->flags
& SEC_LOAD
) == 0
9206 || (section
->flags
& SEC_CODE
) == 0
9207 || section
->reloc_count
== 0)
9210 /* If this section is a link-once section that will be
9211 discarded, then don't create any stubs. */
9212 if (section
->output_section
== NULL
9213 || section
->output_section
->owner
!= output_bfd
)
9216 /* Get the relocs. */
9218 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
9220 if (internal_relocs
== NULL
)
9221 goto error_ret_free_local
;
9223 /* Now examine each relocation. */
9224 irela
= internal_relocs
;
9225 irelaend
= irela
+ section
->reloc_count
;
9226 for (; irela
< irelaend
; irela
++)
9228 enum elf_ppc64_reloc_type r_type
;
9229 unsigned int r_indx
;
9230 enum ppc_stub_type stub_type
;
9231 struct ppc_stub_hash_entry
*stub_entry
;
9232 asection
*sym_sec
, *code_sec
;
9234 bfd_vma destination
;
9235 bfd_boolean ok_dest
;
9236 struct ppc_link_hash_entry
*hash
;
9237 struct ppc_link_hash_entry
*fdh
;
9238 struct elf_link_hash_entry
*h
;
9239 Elf_Internal_Sym
*sym
;
9241 const asection
*id_sec
;
9244 r_type
= ELF64_R_TYPE (irela
->r_info
);
9245 r_indx
= ELF64_R_SYM (irela
->r_info
);
9247 if (r_type
>= R_PPC64_max
)
9249 bfd_set_error (bfd_error_bad_value
);
9250 goto error_ret_free_internal
;
9253 /* Only look for stubs on branch instructions. */
9254 if (r_type
!= R_PPC64_REL24
9255 && r_type
!= R_PPC64_REL14
9256 && r_type
!= R_PPC64_REL14_BRTAKEN
9257 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
9260 /* Now determine the call target, its name, value,
9262 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9264 goto error_ret_free_internal
;
9265 hash
= (struct ppc_link_hash_entry
*) h
;
9272 sym_value
= sym
->st_value
;
9275 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
9276 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
9278 sym_value
= hash
->elf
.root
.u
.def
.value
;
9279 if (sym_sec
->output_section
!= NULL
)
9282 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
9283 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
9285 /* Recognise an old ABI func code entry sym, and
9286 use the func descriptor sym instead if it is
9288 if (hash
->elf
.root
.root
.string
[0] == '.'
9289 && (fdh
= get_fdh (hash
, htab
)) != NULL
)
9291 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
9292 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
9294 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
9295 sym_value
= fdh
->elf
.root
.u
.def
.value
;
9296 if (sym_sec
->output_section
!= NULL
)
9305 bfd_set_error (bfd_error_bad_value
);
9306 goto error_ret_free_internal
;
9312 sym_value
+= irela
->r_addend
;
9313 destination
= (sym_value
9314 + sym_sec
->output_offset
9315 + sym_sec
->output_section
->vma
);
9319 opd_adjust
= get_opd_info (sym_sec
);
9320 if (opd_adjust
!= NULL
)
9326 long adjust
= opd_adjust
[sym_value
/ 8];
9329 sym_value
+= adjust
;
9331 dest
= opd_entry_value (sym_sec
, sym_value
,
9332 &code_sec
, &sym_value
);
9333 if (dest
!= (bfd_vma
) -1)
9338 /* Fixup old ABI sym to point at code
9340 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
9341 hash
->elf
.root
.u
.def
.section
= code_sec
;
9342 hash
->elf
.root
.u
.def
.value
= sym_value
;
9347 /* Determine what (if any) linker stub is needed. */
9348 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
9351 if (stub_type
!= ppc_stub_plt_call
)
9353 /* Check whether we need a TOC adjusting stub.
9354 Since the linker pastes together pieces from
9355 different object files when creating the
9356 _init and _fini functions, it may be that a
9357 call to what looks like a local sym is in
9358 fact a call needing a TOC adjustment. */
9359 if (code_sec
!= NULL
9360 && code_sec
->output_section
!= NULL
9361 && (htab
->stub_group
[code_sec
->id
].toc_off
9362 != htab
->stub_group
[section
->id
].toc_off
)
9363 && (code_sec
->has_toc_reloc
9364 || code_sec
->makes_toc_func_call
))
9365 stub_type
= ppc_stub_long_branch_r2off
;
9368 if (stub_type
== ppc_stub_none
)
9371 /* __tls_get_addr calls might be eliminated. */
9372 if (stub_type
!= ppc_stub_plt_call
9374 && (hash
== htab
->tls_get_addr
9375 || hash
== htab
->tls_get_addr_fd
)
9376 && section
->has_tls_reloc
9377 && irela
!= internal_relocs
)
9382 if (!get_tls_mask (&tls_mask
, NULL
, &local_syms
,
9383 irela
- 1, input_bfd
))
9384 goto error_ret_free_internal
;
9389 /* Support for grouping stub sections. */
9390 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
9392 /* Get the name of this stub. */
9393 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
9395 goto error_ret_free_internal
;
9397 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
9398 stub_name
, FALSE
, FALSE
);
9399 if (stub_entry
!= NULL
)
9401 /* The proper stub has already been created. */
9406 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
9407 if (stub_entry
== NULL
)
9410 error_ret_free_internal
:
9411 if (elf_section_data (section
)->relocs
== NULL
)
9412 free (internal_relocs
);
9413 error_ret_free_local
:
9414 if (local_syms
!= NULL
9415 && (symtab_hdr
->contents
9416 != (unsigned char *) local_syms
))
9421 stub_entry
->stub_type
= stub_type
;
9422 stub_entry
->target_value
= sym_value
;
9423 stub_entry
->target_section
= code_sec
;
9424 stub_entry
->h
= hash
;
9425 stub_entry
->addend
= irela
->r_addend
;
9427 if (stub_entry
->h
!= NULL
)
9428 htab
->stub_globals
+= 1;
9431 /* We're done with the internal relocs, free them. */
9432 if (elf_section_data (section
)->relocs
!= internal_relocs
)
9433 free (internal_relocs
);
9436 if (local_syms
!= NULL
9437 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9439 if (!info
->keep_memory
)
9442 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9446 /* We may have added some stubs. Find out the new size of the
9448 for (stub_sec
= htab
->stub_bfd
->sections
;
9450 stub_sec
= stub_sec
->next
)
9451 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9453 stub_sec
->rawsize
= stub_sec
->size
;
9455 stub_sec
->reloc_count
= 0;
9456 stub_sec
->flags
&= ~SEC_RELOC
;
9459 htab
->brlt
->size
= 0;
9460 htab
->brlt
->reloc_count
= 0;
9461 htab
->brlt
->flags
&= ~SEC_RELOC
;
9462 if (htab
->relbrlt
!= NULL
)
9463 htab
->relbrlt
->size
= 0;
9465 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
9467 for (stub_sec
= htab
->stub_bfd
->sections
;
9469 stub_sec
= stub_sec
->next
)
9470 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9471 && stub_sec
->rawsize
!= stub_sec
->size
)
9474 /* Exit from this loop when no stubs have been added, and no stubs
9475 have changed size. */
9476 if (stub_sec
== NULL
)
9479 /* Ask the linker to do its stuff. */
9480 (*htab
->layout_sections_again
) ();
9483 /* It would be nice to strip htab->brlt from the output if the
9484 section is empty, but it's too late. If we strip sections here,
9485 the dynamic symbol table is corrupted since the section symbol
9486 for the stripped section isn't written. */
9491 /* Called after we have determined section placement. If sections
9492 move, we'll be called again. Provide a value for TOCstart. */
9495 ppc64_elf_toc (bfd
*obfd
)
9500 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
9501 order. The TOC starts where the first of these sections starts. */
9502 s
= bfd_get_section_by_name (obfd
, ".got");
9504 s
= bfd_get_section_by_name (obfd
, ".toc");
9506 s
= bfd_get_section_by_name (obfd
, ".tocbss");
9508 s
= bfd_get_section_by_name (obfd
, ".plt");
9511 /* This may happen for
9512 o references to TOC base (SYM@toc / TOC[tc0]) without a
9515 o --gc-sections and empty TOC sections
9517 FIXME: Warn user? */
9519 /* Look for a likely section. We probably won't even be
9521 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9522 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
9523 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9526 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9527 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
9528 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9531 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9532 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
9535 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9536 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
9542 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
9547 /* Build all the stubs associated with the current output file.
9548 The stubs are kept in a hash table attached to the main linker
9549 hash table. This function is called via gldelf64ppc_finish. */
9552 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
9553 struct bfd_link_info
*info
,
9556 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9559 int stub_sec_count
= 0;
9561 htab
->emit_stub_syms
= emit_stub_syms
;
9563 /* Allocate memory to hold the linker stubs. */
9564 for (stub_sec
= htab
->stub_bfd
->sections
;
9566 stub_sec
= stub_sec
->next
)
9567 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9568 && stub_sec
->size
!= 0)
9570 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
9571 if (stub_sec
->contents
== NULL
)
9573 /* We want to check that built size is the same as calculated
9574 size. rawsize is a convenient location to use. */
9575 stub_sec
->rawsize
= stub_sec
->size
;
9579 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
9584 /* Build the .glink plt call stub. */
9585 if (htab
->emit_stub_syms
)
9587 struct elf_link_hash_entry
*h
;
9588 h
= elf_link_hash_lookup (&htab
->elf
, "__glink", TRUE
, FALSE
, FALSE
);
9591 if (h
->root
.type
== bfd_link_hash_new
)
9593 h
->root
.type
= bfd_link_hash_defined
;
9594 h
->root
.u
.def
.section
= htab
->glink
;
9595 h
->root
.u
.def
.value
= 8;
9598 h
->ref_regular_nonweak
= 1;
9599 h
->forced_local
= 1;
9603 p
= htab
->glink
->contents
;
9604 plt0
= (htab
->plt
->output_section
->vma
9605 + htab
->plt
->output_offset
9606 - (htab
->glink
->output_section
->vma
9607 + htab
->glink
->output_offset
9609 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
9611 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
9613 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
9615 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
9617 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
9619 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
9621 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
9623 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
9625 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
9627 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
9629 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
9631 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
9633 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
9635 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
9639 /* Build the .glink lazy link call stubs. */
9641 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
9645 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
9650 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
9652 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
9655 bfd_put_32 (htab
->glink
->owner
,
9656 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
9660 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
9663 if (htab
->brlt
->size
!= 0)
9665 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
9667 if (htab
->brlt
->contents
== NULL
)
9670 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
9672 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
9673 htab
->relbrlt
->size
);
9674 if (htab
->relbrlt
->contents
== NULL
)
9678 /* Build the stubs as directed by the stub hash table. */
9679 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
9681 if (htab
->relbrlt
!= NULL
)
9682 htab
->relbrlt
->reloc_count
= 0;
9684 for (stub_sec
= htab
->stub_bfd
->sections
;
9686 stub_sec
= stub_sec
->next
)
9687 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9689 stub_sec_count
+= 1;
9690 if (stub_sec
->rawsize
!= stub_sec
->size
)
9694 if (stub_sec
!= NULL
9695 || htab
->glink
->rawsize
!= htab
->glink
->size
)
9697 htab
->stub_error
= TRUE
;
9698 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
9701 if (htab
->stub_error
)
9706 *stats
= bfd_malloc (500);
9710 sprintf (*stats
, _("linker stubs in %u group%s\n"
9713 " long branch %lu\n"
9714 " long toc adj %lu\n"
9717 stub_sec_count
== 1 ? "" : "s",
9718 htab
->stub_count
[ppc_stub_long_branch
- 1],
9719 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
9720 htab
->stub_count
[ppc_stub_plt_branch
- 1],
9721 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
9722 htab
->stub_count
[ppc_stub_plt_call
- 1]);
9727 /* This function undoes the changes made by add_symbol_adjust. */
9730 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
9732 struct ppc_link_hash_entry
*eh
;
9734 if (h
->root
.type
== bfd_link_hash_indirect
)
9737 if (h
->root
.type
== bfd_link_hash_warning
)
9738 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9740 eh
= (struct ppc_link_hash_entry
*) h
;
9741 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
9744 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
9749 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
9751 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9752 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
9755 /* What to do when ld finds relocations against symbols defined in
9756 discarded sections. */
9759 ppc64_elf_action_discarded (asection
*sec
)
9761 if (strcmp (".opd", sec
->name
) == 0)
9764 if (strcmp (".toc", sec
->name
) == 0)
9767 if (strcmp (".toc1", sec
->name
) == 0)
9770 return _bfd_elf_default_action_discarded (sec
);
9773 /* The RELOCATE_SECTION function is called by the ELF backend linker
9774 to handle the relocations for a section.
9776 The relocs are always passed as Rela structures; if the section
9777 actually uses Rel structures, the r_addend field will always be
9780 This function is responsible for adjust the section contents as
9781 necessary, and (if using Rela relocs and generating a
9782 relocatable output file) adjusting the reloc addend as
9785 This function does not have to worry about setting the reloc
9786 address or the reloc symbol index.
9788 LOCAL_SYMS is a pointer to the swapped in local symbols.
9790 LOCAL_SECTIONS is an array giving the section in the input file
9791 corresponding to the st_shndx field of each local symbol.
9793 The global hash table entry for the global symbols can be found
9794 via elf_sym_hashes (input_bfd).
9796 When generating relocatable output, this function must handle
9797 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
9798 going to be the section symbol corresponding to the output
9799 section, which means that the addend must be adjusted
9803 ppc64_elf_relocate_section (bfd
*output_bfd
,
9804 struct bfd_link_info
*info
,
9806 asection
*input_section
,
9808 Elf_Internal_Rela
*relocs
,
9809 Elf_Internal_Sym
*local_syms
,
9810 asection
**local_sections
)
9812 struct ppc_link_hash_table
*htab
;
9813 Elf_Internal_Shdr
*symtab_hdr
;
9814 struct elf_link_hash_entry
**sym_hashes
;
9815 Elf_Internal_Rela
*rel
;
9816 Elf_Internal_Rela
*relend
;
9817 Elf_Internal_Rela outrel
;
9819 struct got_entry
**local_got_ents
;
9821 bfd_boolean ret
= TRUE
;
9823 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
9824 bfd_boolean is_power4
= FALSE
;
9825 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
9827 /* Initialize howto table if needed. */
9828 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9831 htab
= ppc_hash_table (info
);
9833 /* Don't relocate stub sections. */
9834 if (input_section
->owner
== htab
->stub_bfd
)
9837 local_got_ents
= elf_local_got_ents (input_bfd
);
9838 TOCstart
= elf_gp (output_bfd
);
9839 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9840 sym_hashes
= elf_sym_hashes (input_bfd
);
9841 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
9844 relend
= relocs
+ input_section
->reloc_count
;
9845 for (; rel
< relend
; rel
++)
9847 enum elf_ppc64_reloc_type r_type
;
9848 bfd_vma addend
, orig_addend
;
9849 bfd_reloc_status_type r
;
9850 Elf_Internal_Sym
*sym
;
9852 struct elf_link_hash_entry
*h_elf
;
9853 struct ppc_link_hash_entry
*h
;
9854 struct ppc_link_hash_entry
*fdh
;
9855 const char *sym_name
;
9856 unsigned long r_symndx
, toc_symndx
;
9857 char tls_mask
, tls_gd
, tls_type
;
9860 bfd_boolean unresolved_reloc
;
9862 unsigned long insn
, mask
;
9863 struct ppc_stub_hash_entry
*stub_entry
;
9864 bfd_vma max_br_offset
;
9867 r_type
= ELF64_R_TYPE (rel
->r_info
);
9868 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9870 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
9871 symbol of the previous ADDR64 reloc. The symbol gives us the
9872 proper TOC base to use. */
9873 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
9875 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
9877 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
9883 unresolved_reloc
= FALSE
;
9885 orig_addend
= rel
->r_addend
;
9887 if (r_symndx
< symtab_hdr
->sh_info
)
9889 /* It's a local symbol. */
9892 sym
= local_syms
+ r_symndx
;
9893 sec
= local_sections
[r_symndx
];
9894 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
9895 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
9896 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
9897 opd_adjust
= get_opd_info (sec
);
9898 if (opd_adjust
!= NULL
)
9900 long adjust
= opd_adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
9905 /* If this is a relocation against the opd section sym
9906 and we have edited .opd, adjust the reloc addend so
9907 that ld -r and ld --emit-relocs output is correct.
9908 If it is a reloc against some other .opd symbol,
9909 then the symbol value will be adjusted later. */
9910 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
9911 rel
->r_addend
+= adjust
;
9913 relocation
+= adjust
;
9919 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
9920 r_symndx
, symtab_hdr
, sym_hashes
,
9921 h_elf
, sec
, relocation
,
9922 unresolved_reloc
, warned
);
9923 sym_name
= h_elf
->root
.root
.string
;
9924 sym_type
= h_elf
->type
;
9926 h
= (struct ppc_link_hash_entry
*) h_elf
;
9928 if (sec
!= NULL
&& elf_discarded_section (sec
))
9930 /* For relocs against symbols from removed linkonce sections,
9931 or sections discarded by a linker script, we just want the
9932 section contents zeroed. Avoid any special processing. */
9933 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
], input_bfd
,
9934 contents
+ rel
->r_offset
);
9940 if (info
->relocatable
)
9943 /* TLS optimizations. Replace instruction sequences and relocs
9944 based on information we collected in tls_optimize. We edit
9945 RELOCS so that --emit-relocs will output something sensible
9946 for the final instruction stream. */
9950 if (IS_PPC64_TLS_RELOC (r_type
))
9953 tls_mask
= h
->tls_mask
;
9954 else if (local_got_ents
!= NULL
)
9957 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
9958 tls_mask
= lgot_masks
[r_symndx
];
9960 if (tls_mask
== 0 && r_type
== R_PPC64_TLS
)
9962 /* Check for toc tls entries. */
9965 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
9970 tls_mask
= *toc_tls
;
9974 /* Check that tls relocs are used with tls syms, and non-tls
9975 relocs are used with non-tls syms. */
9977 && r_type
!= R_PPC64_NONE
9979 || h
->elf
.root
.type
== bfd_link_hash_defined
9980 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
9981 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
9983 if (r_type
== R_PPC64_TLS
&& tls_mask
!= 0)
9984 /* R_PPC64_TLS is OK against a symbol in the TOC. */
9987 (*_bfd_error_handler
)
9988 (sym_type
== STT_TLS
9989 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
9990 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"),
9993 (long) rel
->r_offset
,
9994 ppc64_elf_howto_table
[r_type
]->name
,
9998 /* Ensure reloc mapping code below stays sane. */
9999 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
10000 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
10001 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
10002 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
10003 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
10004 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
10005 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
10006 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
10007 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
10008 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
10016 case R_PPC64_TOC16
:
10017 case R_PPC64_TOC16_LO
:
10018 case R_PPC64_TOC16_DS
:
10019 case R_PPC64_TOC16_LO_DS
:
10021 /* Check for toc tls entries. */
10025 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
10032 tls_mask
= *toc_tls
;
10033 if (r_type
== R_PPC64_TOC16_DS
10034 || r_type
== R_PPC64_TOC16_LO_DS
)
10037 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
10042 /* If we found a GD reloc pair, then we might be
10043 doing a GD->IE transition. */
10046 tls_gd
= TLS_TPRELGD
;
10047 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10048 goto tls_get_addr_check
;
10050 else if (retval
== 3)
10052 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10053 goto tls_get_addr_check
;
10060 case R_PPC64_GOT_TPREL16_DS
:
10061 case R_PPC64_GOT_TPREL16_LO_DS
:
10063 && (tls_mask
& TLS_TPREL
) == 0)
10066 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
10068 insn
|= 0x3c0d0000; /* addis 0,13,0 */
10069 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
10070 r_type
= R_PPC64_TPREL16_HA
;
10071 if (toc_symndx
!= 0)
10073 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
10074 /* We changed the symbol. Start over in order to
10075 get h, sym, sec etc. right. */
10080 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10086 && (tls_mask
& TLS_TPREL
) == 0)
10089 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
10090 if ((insn
& ((0x3f << 26) | (31 << 11)))
10091 == ((31 << 26) | (13 << 11)))
10092 rtra
= insn
& ((1 << 26) - (1 << 16));
10093 else if ((insn
& ((0x3f << 26) | (31 << 16)))
10094 == ((31 << 26) | (13 << 16)))
10095 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
10098 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
10101 else if ((insn
& (31 << 1)) == 23 << 1
10102 && ((insn
& (31 << 6)) < 14 << 6
10103 || ((insn
& (31 << 6)) >= 16 << 6
10104 && (insn
& (31 << 6)) < 24 << 6)))
10105 /* load and store indexed -> dform. */
10106 insn
= (32 | ((insn
>> 6) & 31)) << 26;
10107 else if ((insn
& (31 << 1)) == 21 << 1
10108 && (insn
& (0x1a << 6)) == 0)
10109 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
10110 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
10111 | ((insn
>> 6) & 1));
10112 else if ((insn
& (31 << 1)) == 21 << 1
10113 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
10115 insn
= (58 << 26) | 2;
10119 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10120 /* Was PPC64_TLS which sits on insn boundary, now
10121 PPC64_TPREL16_LO which is at low-order half-word. */
10122 rel
->r_offset
+= d_offset
;
10123 r_type
= R_PPC64_TPREL16_LO
;
10124 if (toc_symndx
!= 0)
10126 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
10127 /* We changed the symbol. Start over in order to
10128 get h, sym, sec etc. right. */
10133 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10137 case R_PPC64_GOT_TLSGD16_HI
:
10138 case R_PPC64_GOT_TLSGD16_HA
:
10139 tls_gd
= TLS_TPRELGD
;
10140 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10144 case R_PPC64_GOT_TLSLD16_HI
:
10145 case R_PPC64_GOT_TLSLD16_HA
:
10146 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10149 if ((tls_mask
& tls_gd
) != 0)
10150 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10151 + R_PPC64_GOT_TPREL16_DS
);
10154 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10155 rel
->r_offset
-= d_offset
;
10156 r_type
= R_PPC64_NONE
;
10158 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10162 case R_PPC64_GOT_TLSGD16
:
10163 case R_PPC64_GOT_TLSGD16_LO
:
10164 tls_gd
= TLS_TPRELGD
;
10165 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10166 goto tls_get_addr_check
;
10169 case R_PPC64_GOT_TLSLD16
:
10170 case R_PPC64_GOT_TLSLD16_LO
:
10171 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10173 tls_get_addr_check
:
10174 if (rel
+ 1 < relend
)
10176 enum elf_ppc64_reloc_type r_type2
;
10177 unsigned long r_symndx2
;
10178 struct elf_link_hash_entry
*h2
;
10179 bfd_vma insn1
, insn2
, insn3
;
10182 /* The next instruction should be a call to
10183 __tls_get_addr. Peek at the reloc to be sure. */
10184 r_type2
= ELF64_R_TYPE (rel
[1].r_info
);
10185 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
10186 if (r_symndx2
< symtab_hdr
->sh_info
10187 || (r_type2
!= R_PPC64_REL14
10188 && r_type2
!= R_PPC64_REL14_BRTAKEN
10189 && r_type2
!= R_PPC64_REL14_BRNTAKEN
10190 && r_type2
!= R_PPC64_REL24
))
10193 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
10194 while (h2
->root
.type
== bfd_link_hash_indirect
10195 || h2
->root
.type
== bfd_link_hash_warning
)
10196 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
10197 if (h2
== NULL
|| (h2
!= &htab
->tls_get_addr
->elf
10198 && h2
!= &htab
->tls_get_addr_fd
->elf
))
10201 /* OK, it checks out. Replace the call. */
10202 offset
= rel
[1].r_offset
;
10203 insn1
= bfd_get_32 (output_bfd
,
10204 contents
+ rel
->r_offset
- d_offset
);
10205 insn3
= bfd_get_32 (output_bfd
,
10206 contents
+ offset
+ 4);
10207 if ((tls_mask
& tls_gd
) != 0)
10210 insn1
&= (1 << 26) - (1 << 2);
10211 insn1
|= 58 << 26; /* ld */
10212 insn2
= 0x7c636a14; /* add 3,3,13 */
10213 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
10214 if ((tls_mask
& TLS_EXPLICIT
) == 0)
10215 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10216 + R_PPC64_GOT_TPREL16_DS
);
10218 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
10219 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10224 insn1
= 0x3c6d0000; /* addis 3,13,0 */
10225 insn2
= 0x38630000; /* addi 3,3,0 */
10228 /* Was an LD reloc. */
10230 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10231 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10233 else if (toc_symndx
!= 0)
10234 r_symndx
= toc_symndx
;
10235 r_type
= R_PPC64_TPREL16_HA
;
10236 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10237 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
10238 R_PPC64_TPREL16_LO
);
10239 rel
[1].r_offset
+= d_offset
;
10242 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
10246 rel
[1].r_offset
+= 4;
10248 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- d_offset
);
10249 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
10250 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
10251 if (tls_gd
== 0 || toc_symndx
!= 0)
10253 /* We changed the symbol. Start over in order
10254 to get h, sym, sec etc. right. */
10262 case R_PPC64_DTPMOD64
:
10263 if (rel
+ 1 < relend
10264 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
10265 && rel
[1].r_offset
== rel
->r_offset
+ 8)
10267 if ((tls_mask
& TLS_GD
) == 0)
10269 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
10270 if ((tls_mask
& TLS_TPRELGD
) != 0)
10271 r_type
= R_PPC64_TPREL64
;
10274 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10275 r_type
= R_PPC64_NONE
;
10277 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10282 if ((tls_mask
& TLS_LD
) == 0)
10284 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10285 r_type
= R_PPC64_NONE
;
10286 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10291 case R_PPC64_TPREL64
:
10292 if ((tls_mask
& TLS_TPREL
) == 0)
10294 r_type
= R_PPC64_NONE
;
10295 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10300 /* Handle other relocations that tweak non-addend part of insn. */
10302 max_br_offset
= 1 << 25;
10303 addend
= rel
->r_addend
;
10309 /* Branch taken prediction relocations. */
10310 case R_PPC64_ADDR14_BRTAKEN
:
10311 case R_PPC64_REL14_BRTAKEN
:
10312 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
10315 /* Branch not taken prediction relocations. */
10316 case R_PPC64_ADDR14_BRNTAKEN
:
10317 case R_PPC64_REL14_BRNTAKEN
:
10318 insn
|= bfd_get_32 (output_bfd
,
10319 contents
+ rel
->r_offset
) & ~(0x01 << 21);
10322 case R_PPC64_REL14
:
10323 max_br_offset
= 1 << 15;
10326 case R_PPC64_REL24
:
10327 /* Calls to functions with a different TOC, such as calls to
10328 shared objects, need to alter the TOC pointer. This is
10329 done using a linkage stub. A REL24 branching to these
10330 linkage stubs needs to be followed by a nop, as the nop
10331 will be replaced with an instruction to restore the TOC
10336 && (((fdh
= h
->oh
) != NULL
10337 && fdh
->elf
.plt
.plist
!= NULL
)
10338 || (fdh
= h
)->elf
.plt
.plist
!= NULL
))
10340 && sec
->output_section
!= NULL
10341 && sec
->id
<= htab
->top_id
10342 && (htab
->stub_group
[sec
->id
].toc_off
10343 != htab
->stub_group
[input_section
->id
].toc_off
)))
10344 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
10345 rel
, htab
)) != NULL
10346 && (stub_entry
->stub_type
== ppc_stub_plt_call
10347 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
10348 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
10350 bfd_boolean can_plt_call
= FALSE
;
10352 if (rel
->r_offset
+ 8 <= input_section
->size
)
10355 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
10357 || nop
== CROR_151515
|| nop
== CROR_313131
)
10359 bfd_put_32 (input_bfd
, LD_R2_40R1
,
10360 contents
+ rel
->r_offset
+ 4);
10361 can_plt_call
= TRUE
;
10367 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
10369 /* If this is a plain branch rather than a branch
10370 and link, don't require a nop. However, don't
10371 allow tail calls in a shared library as they
10372 will result in r2 being corrupted. */
10374 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10375 if (info
->executable
&& (br
& 1) == 0)
10376 can_plt_call
= TRUE
;
10381 && strcmp (h
->elf
.root
.root
.string
,
10382 ".__libc_start_main") == 0)
10384 /* Allow crt1 branch to go via a toc adjusting stub. */
10385 can_plt_call
= TRUE
;
10389 if (strcmp (input_section
->output_section
->name
,
10391 || strcmp (input_section
->output_section
->name
,
10393 (*_bfd_error_handler
)
10394 (_("%B(%A+0x%lx): automatic multiple TOCs "
10395 "not supported using your crt files; "
10396 "recompile with -mminimal-toc or upgrade gcc"),
10399 (long) rel
->r_offset
);
10401 (*_bfd_error_handler
)
10402 (_("%B(%A+0x%lx): sibling call optimization to `%s' "
10403 "does not allow automatic multiple TOCs; "
10404 "recompile with -mminimal-toc or "
10405 "-fno-optimize-sibling-calls, "
10406 "or make `%s' extern"),
10409 (long) rel
->r_offset
,
10412 bfd_set_error (bfd_error_bad_value
);
10418 && stub_entry
->stub_type
== ppc_stub_plt_call
)
10419 unresolved_reloc
= FALSE
;
10422 if (stub_entry
== NULL
10423 && get_opd_info (sec
) != NULL
)
10425 /* The branch destination is the value of the opd entry. */
10426 bfd_vma off
= (relocation
+ addend
10427 - sec
->output_section
->vma
10428 - sec
->output_offset
);
10429 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
10430 if (dest
!= (bfd_vma
) -1)
10437 /* If the branch is out of reach we ought to have a long
10439 from
= (rel
->r_offset
10440 + input_section
->output_offset
10441 + input_section
->output_section
->vma
);
10443 if (stub_entry
== NULL
10444 && (relocation
+ addend
- from
+ max_br_offset
10445 >= 2 * max_br_offset
)
10446 && r_type
!= R_PPC64_ADDR14_BRTAKEN
10447 && r_type
!= R_PPC64_ADDR14_BRNTAKEN
)
10448 stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
, rel
,
10451 if (stub_entry
!= NULL
)
10453 /* Munge up the value and addend so that we call the stub
10454 rather than the procedure directly. */
10455 relocation
= (stub_entry
->stub_offset
10456 + stub_entry
->stub_sec
->output_offset
10457 + stub_entry
->stub_sec
->output_section
->vma
);
10465 /* Set 'a' bit. This is 0b00010 in BO field for branch
10466 on CR(BI) insns (BO == 001at or 011at), and 0b01000
10467 for branch on CTR insns (BO == 1a00t or 1a01t). */
10468 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10469 insn
|= 0x02 << 21;
10470 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10471 insn
|= 0x08 << 21;
10477 /* Invert 'y' bit if not the default. */
10478 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
10479 insn
^= 0x01 << 21;
10482 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10485 /* NOP out calls to undefined weak functions.
10486 We can thus call a weak function without first
10487 checking whether the function is defined. */
10489 && h
->elf
.root
.type
== bfd_link_hash_undefweak
10490 && r_type
== R_PPC64_REL24
10494 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10500 /* Set `addend'. */
10505 (*_bfd_error_handler
)
10506 (_("%B: unknown relocation type %d for symbol %s"),
10507 input_bfd
, (int) r_type
, sym_name
);
10509 bfd_set_error (bfd_error_bad_value
);
10515 case R_PPC64_GNU_VTINHERIT
:
10516 case R_PPC64_GNU_VTENTRY
:
10519 /* GOT16 relocations. Like an ADDR16 using the symbol's
10520 address in the GOT as relocation value instead of the
10521 symbol's value itself. Also, create a GOT entry for the
10522 symbol and put the symbol value there. */
10523 case R_PPC64_GOT_TLSGD16
:
10524 case R_PPC64_GOT_TLSGD16_LO
:
10525 case R_PPC64_GOT_TLSGD16_HI
:
10526 case R_PPC64_GOT_TLSGD16_HA
:
10527 tls_type
= TLS_TLS
| TLS_GD
;
10530 case R_PPC64_GOT_TLSLD16
:
10531 case R_PPC64_GOT_TLSLD16_LO
:
10532 case R_PPC64_GOT_TLSLD16_HI
:
10533 case R_PPC64_GOT_TLSLD16_HA
:
10534 tls_type
= TLS_TLS
| TLS_LD
;
10537 case R_PPC64_GOT_TPREL16_DS
:
10538 case R_PPC64_GOT_TPREL16_LO_DS
:
10539 case R_PPC64_GOT_TPREL16_HI
:
10540 case R_PPC64_GOT_TPREL16_HA
:
10541 tls_type
= TLS_TLS
| TLS_TPREL
;
10544 case R_PPC64_GOT_DTPREL16_DS
:
10545 case R_PPC64_GOT_DTPREL16_LO_DS
:
10546 case R_PPC64_GOT_DTPREL16_HI
:
10547 case R_PPC64_GOT_DTPREL16_HA
:
10548 tls_type
= TLS_TLS
| TLS_DTPREL
;
10551 case R_PPC64_GOT16
:
10552 case R_PPC64_GOT16_LO
:
10553 case R_PPC64_GOT16_HI
:
10554 case R_PPC64_GOT16_HA
:
10555 case R_PPC64_GOT16_DS
:
10556 case R_PPC64_GOT16_LO_DS
:
10559 /* Relocation is to the entry for this symbol in the global
10564 unsigned long indx
= 0;
10566 if (tls_type
== (TLS_TLS
| TLS_LD
)
10568 || !h
->elf
.def_dynamic
))
10569 offp
= &ppc64_tlsld_got (input_bfd
)->offset
;
10572 struct got_entry
*ent
;
10576 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
10577 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
10580 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
10581 /* This is actually a static link, or it is a
10582 -Bsymbolic link and the symbol is defined
10583 locally, or the symbol was forced to be local
10584 because of a version file. */
10588 indx
= h
->elf
.dynindx
;
10589 unresolved_reloc
= FALSE
;
10591 ent
= h
->elf
.got
.glist
;
10595 if (local_got_ents
== NULL
)
10597 ent
= local_got_ents
[r_symndx
];
10600 for (; ent
!= NULL
; ent
= ent
->next
)
10601 if (ent
->addend
== orig_addend
10602 && ent
->owner
== input_bfd
10603 && ent
->tls_type
== tls_type
)
10607 offp
= &ent
->got
.offset
;
10610 got
= ppc64_elf_tdata (input_bfd
)->got
;
10614 /* The offset must always be a multiple of 8. We use the
10615 least significant bit to record whether we have already
10616 processed this entry. */
10618 if ((off
& 1) != 0)
10622 /* Generate relocs for the dynamic linker, except in
10623 the case of TLSLD where we'll use one entry per
10625 asection
*relgot
= ppc64_elf_tdata (input_bfd
)->relgot
;
10628 if ((info
->shared
|| indx
!= 0)
10630 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10631 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
10633 outrel
.r_offset
= (got
->output_section
->vma
10634 + got
->output_offset
10636 outrel
.r_addend
= addend
;
10637 if (tls_type
& (TLS_LD
| TLS_GD
))
10639 outrel
.r_addend
= 0;
10640 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
10641 if (tls_type
== (TLS_TLS
| TLS_GD
))
10643 loc
= relgot
->contents
;
10644 loc
+= (relgot
->reloc_count
++
10645 * sizeof (Elf64_External_Rela
));
10646 bfd_elf64_swap_reloca_out (output_bfd
,
10648 outrel
.r_offset
+= 8;
10649 outrel
.r_addend
= addend
;
10651 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10654 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
10655 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10656 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10657 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
10658 else if (indx
== 0)
10660 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
10662 /* Write the .got section contents for the sake
10664 loc
= got
->contents
+ off
;
10665 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
10669 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
10671 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
10673 outrel
.r_addend
+= relocation
;
10674 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
10675 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
10677 loc
= relgot
->contents
;
10678 loc
+= (relgot
->reloc_count
++
10679 * sizeof (Elf64_External_Rela
));
10680 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
10683 /* Init the .got section contents here if we're not
10684 emitting a reloc. */
10687 relocation
+= addend
;
10688 if (tls_type
== (TLS_TLS
| TLS_LD
))
10690 else if (tls_type
!= 0)
10692 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10693 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10694 relocation
+= DTP_OFFSET
- TP_OFFSET
;
10696 if (tls_type
== (TLS_TLS
| TLS_GD
))
10698 bfd_put_64 (output_bfd
, relocation
,
10699 got
->contents
+ off
+ 8);
10704 bfd_put_64 (output_bfd
, relocation
,
10705 got
->contents
+ off
);
10709 if (off
>= (bfd_vma
) -2)
10712 relocation
= got
->output_offset
+ off
;
10714 /* TOC base (r2) is TOC start plus 0x8000. */
10715 addend
= -TOC_BASE_OFF
;
10719 case R_PPC64_PLT16_HA
:
10720 case R_PPC64_PLT16_HI
:
10721 case R_PPC64_PLT16_LO
:
10722 case R_PPC64_PLT32
:
10723 case R_PPC64_PLT64
:
10724 /* Relocation is to the entry for this symbol in the
10725 procedure linkage table. */
10727 /* Resolve a PLT reloc against a local symbol directly,
10728 without using the procedure linkage table. */
10732 /* It's possible that we didn't make a PLT entry for this
10733 symbol. This happens when statically linking PIC code,
10734 or when using -Bsymbolic. Go find a match if there is a
10736 if (htab
->plt
!= NULL
)
10738 struct plt_entry
*ent
;
10739 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10740 if (ent
->addend
== orig_addend
10741 && ent
->plt
.offset
!= (bfd_vma
) -1)
10743 relocation
= (htab
->plt
->output_section
->vma
10744 + htab
->plt
->output_offset
10745 + ent
->plt
.offset
);
10746 unresolved_reloc
= FALSE
;
10752 /* Relocation value is TOC base. */
10753 relocation
= TOCstart
;
10755 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
10756 else if (unresolved_reloc
)
10758 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
10759 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
10761 unresolved_reloc
= TRUE
;
10764 /* TOC16 relocs. We want the offset relative to the TOC base,
10765 which is the address of the start of the TOC plus 0x8000.
10766 The TOC consists of sections .got, .toc, .tocbss, and .plt,
10768 case R_PPC64_TOC16
:
10769 case R_PPC64_TOC16_LO
:
10770 case R_PPC64_TOC16_HI
:
10771 case R_PPC64_TOC16_DS
:
10772 case R_PPC64_TOC16_LO_DS
:
10773 case R_PPC64_TOC16_HA
:
10774 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
10777 /* Relocate against the beginning of the section. */
10778 case R_PPC64_SECTOFF
:
10779 case R_PPC64_SECTOFF_LO
:
10780 case R_PPC64_SECTOFF_HI
:
10781 case R_PPC64_SECTOFF_DS
:
10782 case R_PPC64_SECTOFF_LO_DS
:
10783 case R_PPC64_SECTOFF_HA
:
10785 addend
-= sec
->output_section
->vma
;
10788 case R_PPC64_REL14
:
10789 case R_PPC64_REL14_BRNTAKEN
:
10790 case R_PPC64_REL14_BRTAKEN
:
10791 case R_PPC64_REL24
:
10794 case R_PPC64_TPREL16
:
10795 case R_PPC64_TPREL16_LO
:
10796 case R_PPC64_TPREL16_HI
:
10797 case R_PPC64_TPREL16_HA
:
10798 case R_PPC64_TPREL16_DS
:
10799 case R_PPC64_TPREL16_LO_DS
:
10800 case R_PPC64_TPREL16_HIGHER
:
10801 case R_PPC64_TPREL16_HIGHERA
:
10802 case R_PPC64_TPREL16_HIGHEST
:
10803 case R_PPC64_TPREL16_HIGHESTA
:
10804 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10806 /* The TPREL16 relocs shouldn't really be used in shared
10807 libs as they will result in DT_TEXTREL being set, but
10808 support them anyway. */
10812 case R_PPC64_DTPREL16
:
10813 case R_PPC64_DTPREL16_LO
:
10814 case R_PPC64_DTPREL16_HI
:
10815 case R_PPC64_DTPREL16_HA
:
10816 case R_PPC64_DTPREL16_DS
:
10817 case R_PPC64_DTPREL16_LO_DS
:
10818 case R_PPC64_DTPREL16_HIGHER
:
10819 case R_PPC64_DTPREL16_HIGHERA
:
10820 case R_PPC64_DTPREL16_HIGHEST
:
10821 case R_PPC64_DTPREL16_HIGHESTA
:
10822 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10825 case R_PPC64_DTPMOD64
:
10830 case R_PPC64_TPREL64
:
10831 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10834 case R_PPC64_DTPREL64
:
10835 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10838 /* Relocations that may need to be propagated if this is a
10840 case R_PPC64_REL30
:
10841 case R_PPC64_REL32
:
10842 case R_PPC64_REL64
:
10843 case R_PPC64_ADDR14
:
10844 case R_PPC64_ADDR14_BRNTAKEN
:
10845 case R_PPC64_ADDR14_BRTAKEN
:
10846 case R_PPC64_ADDR16
:
10847 case R_PPC64_ADDR16_DS
:
10848 case R_PPC64_ADDR16_HA
:
10849 case R_PPC64_ADDR16_HI
:
10850 case R_PPC64_ADDR16_HIGHER
:
10851 case R_PPC64_ADDR16_HIGHERA
:
10852 case R_PPC64_ADDR16_HIGHEST
:
10853 case R_PPC64_ADDR16_HIGHESTA
:
10854 case R_PPC64_ADDR16_LO
:
10855 case R_PPC64_ADDR16_LO_DS
:
10856 case R_PPC64_ADDR24
:
10857 case R_PPC64_ADDR32
:
10858 case R_PPC64_ADDR64
:
10859 case R_PPC64_UADDR16
:
10860 case R_PPC64_UADDR32
:
10861 case R_PPC64_UADDR64
:
10863 if ((input_section
->flags
& SEC_ALLOC
) == 0)
10866 if (NO_OPD_RELOCS
&& is_opd
)
10871 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10872 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
10873 && (MUST_BE_DYN_RELOC (r_type
)
10874 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
10875 || (ELIMINATE_COPY_RELOCS
10878 && h
->elf
.dynindx
!= -1
10879 && !h
->elf
.non_got_ref
10880 && h
->elf
.def_dynamic
10881 && !h
->elf
.def_regular
))
10883 Elf_Internal_Rela outrel
;
10884 bfd_boolean skip
, relocate
;
10889 /* When generating a dynamic object, these relocations
10890 are copied into the output file to be resolved at run
10896 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
10897 input_section
, rel
->r_offset
);
10898 if (out_off
== (bfd_vma
) -1)
10900 else if (out_off
== (bfd_vma
) -2)
10901 skip
= TRUE
, relocate
= TRUE
;
10902 out_off
+= (input_section
->output_section
->vma
10903 + input_section
->output_offset
);
10904 outrel
.r_offset
= out_off
;
10905 outrel
.r_addend
= rel
->r_addend
;
10907 /* Optimize unaligned reloc use. */
10908 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
10909 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
10910 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
10911 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
10912 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
10913 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
10914 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
10915 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
10916 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
10919 memset (&outrel
, 0, sizeof outrel
);
10920 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
10922 && r_type
!= R_PPC64_TOC
)
10923 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
10926 /* This symbol is local, or marked to become local,
10927 or this is an opd section reloc which must point
10928 at a local function. */
10929 outrel
.r_addend
+= relocation
;
10930 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
10932 if (is_opd
&& h
!= NULL
)
10934 /* Lie about opd entries. This case occurs
10935 when building shared libraries and we
10936 reference a function in another shared
10937 lib. The same thing happens for a weak
10938 definition in an application that's
10939 overridden by a strong definition in a
10940 shared lib. (I believe this is a generic
10941 bug in binutils handling of weak syms.)
10942 In these cases we won't use the opd
10943 entry in this lib. */
10944 unresolved_reloc
= FALSE
;
10946 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10948 /* We need to relocate .opd contents for ld.so.
10949 Prelink also wants simple and consistent rules
10950 for relocs. This make all RELATIVE relocs have
10951 *r_offset equal to r_addend. */
10958 if (bfd_is_abs_section (sec
))
10960 else if (sec
== NULL
|| sec
->owner
== NULL
)
10962 bfd_set_error (bfd_error_bad_value
);
10969 osec
= sec
->output_section
;
10970 indx
= elf_section_data (osec
)->dynindx
;
10974 if ((osec
->flags
& SEC_READONLY
) == 0
10975 && htab
->elf
.data_index_section
!= NULL
)
10976 osec
= htab
->elf
.data_index_section
;
10978 osec
= htab
->elf
.text_index_section
;
10979 indx
= elf_section_data (osec
)->dynindx
;
10981 BFD_ASSERT (indx
!= 0);
10983 /* We are turning this relocation into one
10984 against a section symbol, so subtract out
10985 the output section's address but not the
10986 offset of the input section in the output
10988 outrel
.r_addend
-= osec
->vma
;
10991 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
10995 sreloc
= elf_section_data (input_section
)->sreloc
;
10996 if (sreloc
== NULL
)
10999 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
11002 loc
= sreloc
->contents
;
11003 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
11004 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
11006 /* If this reloc is against an external symbol, it will
11007 be computed at runtime, so there's no need to do
11008 anything now. However, for the sake of prelink ensure
11009 that the section contents are a known value. */
11012 unresolved_reloc
= FALSE
;
11013 /* The value chosen here is quite arbitrary as ld.so
11014 ignores section contents except for the special
11015 case of .opd where the contents might be accessed
11016 before relocation. Choose zero, as that won't
11017 cause reloc overflow. */
11020 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
11021 to improve backward compatibility with older
11023 if (r_type
== R_PPC64_ADDR64
)
11024 addend
= outrel
.r_addend
;
11025 /* Adjust pc_relative relocs to have zero in *r_offset. */
11026 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
11027 addend
= (input_section
->output_section
->vma
11028 + input_section
->output_offset
11035 case R_PPC64_GLOB_DAT
:
11036 case R_PPC64_JMP_SLOT
:
11037 case R_PPC64_RELATIVE
:
11038 /* We shouldn't ever see these dynamic relocs in relocatable
11040 /* Fall through. */
11042 case R_PPC64_PLTGOT16
:
11043 case R_PPC64_PLTGOT16_DS
:
11044 case R_PPC64_PLTGOT16_HA
:
11045 case R_PPC64_PLTGOT16_HI
:
11046 case R_PPC64_PLTGOT16_LO
:
11047 case R_PPC64_PLTGOT16_LO_DS
:
11048 case R_PPC64_PLTREL32
:
11049 case R_PPC64_PLTREL64
:
11050 /* These ones haven't been implemented yet. */
11052 (*_bfd_error_handler
)
11053 (_("%B: relocation %s is not supported for symbol %s."),
11055 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
11057 bfd_set_error (bfd_error_invalid_operation
);
11062 /* Do any further special processing. */
11068 case R_PPC64_ADDR16_HA
:
11069 case R_PPC64_ADDR16_HIGHERA
:
11070 case R_PPC64_ADDR16_HIGHESTA
:
11071 case R_PPC64_TOC16_HA
:
11072 case R_PPC64_SECTOFF_HA
:
11073 case R_PPC64_TPREL16_HA
:
11074 case R_PPC64_DTPREL16_HA
:
11075 case R_PPC64_TPREL16_HIGHER
:
11076 case R_PPC64_TPREL16_HIGHERA
:
11077 case R_PPC64_TPREL16_HIGHEST
:
11078 case R_PPC64_TPREL16_HIGHESTA
:
11079 case R_PPC64_DTPREL16_HIGHER
:
11080 case R_PPC64_DTPREL16_HIGHERA
:
11081 case R_PPC64_DTPREL16_HIGHEST
:
11082 case R_PPC64_DTPREL16_HIGHESTA
:
11083 /* It's just possible that this symbol is a weak symbol
11084 that's not actually defined anywhere. In that case,
11085 'sec' would be NULL, and we should leave the symbol
11086 alone (it will be set to zero elsewhere in the link). */
11091 case R_PPC64_GOT16_HA
:
11092 case R_PPC64_PLTGOT16_HA
:
11093 case R_PPC64_PLT16_HA
:
11094 case R_PPC64_GOT_TLSGD16_HA
:
11095 case R_PPC64_GOT_TLSLD16_HA
:
11096 case R_PPC64_GOT_TPREL16_HA
:
11097 case R_PPC64_GOT_DTPREL16_HA
:
11098 /* Add 0x10000 if sign bit in 0:15 is set.
11099 Bits 0:15 are not used. */
11103 case R_PPC64_ADDR16_DS
:
11104 case R_PPC64_ADDR16_LO_DS
:
11105 case R_PPC64_GOT16_DS
:
11106 case R_PPC64_GOT16_LO_DS
:
11107 case R_PPC64_PLT16_LO_DS
:
11108 case R_PPC64_SECTOFF_DS
:
11109 case R_PPC64_SECTOFF_LO_DS
:
11110 case R_PPC64_TOC16_DS
:
11111 case R_PPC64_TOC16_LO_DS
:
11112 case R_PPC64_PLTGOT16_DS
:
11113 case R_PPC64_PLTGOT16_LO_DS
:
11114 case R_PPC64_GOT_TPREL16_DS
:
11115 case R_PPC64_GOT_TPREL16_LO_DS
:
11116 case R_PPC64_GOT_DTPREL16_DS
:
11117 case R_PPC64_GOT_DTPREL16_LO_DS
:
11118 case R_PPC64_TPREL16_DS
:
11119 case R_PPC64_TPREL16_LO_DS
:
11120 case R_PPC64_DTPREL16_DS
:
11121 case R_PPC64_DTPREL16_LO_DS
:
11122 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
11124 /* If this reloc is against an lq insn, then the value must be
11125 a multiple of 16. This is somewhat of a hack, but the
11126 "correct" way to do this by defining _DQ forms of all the
11127 _DS relocs bloats all reloc switches in this file. It
11128 doesn't seem to make much sense to use any of these relocs
11129 in data, so testing the insn should be safe. */
11130 if ((insn
& (0x3f << 26)) == (56u << 26))
11132 if (((relocation
+ addend
) & mask
) != 0)
11134 (*_bfd_error_handler
)
11135 (_("%B: error: relocation %s not a multiple of %d"),
11137 ppc64_elf_howto_table
[r_type
]->name
,
11139 bfd_set_error (bfd_error_bad_value
);
11146 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
11147 because such sections are not SEC_ALLOC and thus ld.so will
11148 not process them. */
11149 if (unresolved_reloc
11150 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
11151 && h
->elf
.def_dynamic
))
11153 (*_bfd_error_handler
)
11154 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
11157 (long) rel
->r_offset
,
11158 ppc64_elf_howto_table
[(int) r_type
]->name
,
11159 h
->elf
.root
.root
.string
);
11163 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
11171 if (r
!= bfd_reloc_ok
)
11173 if (sym_name
== NULL
)
11174 sym_name
= "(null)";
11175 if (r
== bfd_reloc_overflow
)
11180 && h
->elf
.root
.type
== bfd_link_hash_undefweak
11181 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
11183 /* Assume this is a call protected by other code that
11184 detects the symbol is undefined. If this is the case,
11185 we can safely ignore the overflow. If not, the
11186 program is hosed anyway, and a little warning isn't
11192 if (!((*info
->callbacks
->reloc_overflow
)
11193 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
11194 ppc64_elf_howto_table
[r_type
]->name
,
11195 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
11200 (*_bfd_error_handler
)
11201 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
11204 (long) rel
->r_offset
,
11205 ppc64_elf_howto_table
[r_type
]->name
,
11213 /* If we're emitting relocations, then shortly after this function
11214 returns, reloc offsets and addends for this section will be
11215 adjusted. Worse, reloc symbol indices will be for the output
11216 file rather than the input. Save a copy of the relocs for
11217 opd_entry_value. */
11218 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
11221 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
11222 rel
= bfd_alloc (input_bfd
, amt
);
11223 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
11224 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
11227 memcpy (rel
, relocs
, amt
);
11232 /* Adjust the value of any local symbols in opd sections. */
11235 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
11236 const char *name ATTRIBUTE_UNUSED
,
11237 Elf_Internal_Sym
*elfsym
,
11238 asection
*input_sec
,
11239 struct elf_link_hash_entry
*h
)
11241 long *opd_adjust
, adjust
;
11247 opd_adjust
= get_opd_info (input_sec
);
11248 if (opd_adjust
== NULL
)
11251 value
= elfsym
->st_value
- input_sec
->output_offset
;
11252 if (!info
->relocatable
)
11253 value
-= input_sec
->output_section
->vma
;
11255 adjust
= opd_adjust
[value
/ 8];
11257 elfsym
->st_value
= 0;
11259 elfsym
->st_value
+= adjust
;
11263 /* Finish up dynamic symbol handling. We set the contents of various
11264 dynamic sections here. */
11267 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
11268 struct bfd_link_info
*info
,
11269 struct elf_link_hash_entry
*h
,
11270 Elf_Internal_Sym
*sym
)
11272 struct ppc_link_hash_table
*htab
;
11273 struct plt_entry
*ent
;
11274 Elf_Internal_Rela rela
;
11277 htab
= ppc_hash_table (info
);
11279 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
11280 if (ent
->plt
.offset
!= (bfd_vma
) -1)
11282 /* This symbol has an entry in the procedure linkage
11283 table. Set it up. */
11285 if (htab
->plt
== NULL
11286 || htab
->relplt
== NULL
11287 || htab
->glink
== NULL
)
11290 /* Create a JMP_SLOT reloc to inform the dynamic linker to
11291 fill in the PLT entry. */
11292 rela
.r_offset
= (htab
->plt
->output_section
->vma
11293 + htab
->plt
->output_offset
11294 + ent
->plt
.offset
);
11295 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
11296 rela
.r_addend
= ent
->addend
;
11298 loc
= htab
->relplt
->contents
;
11299 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
11300 * sizeof (Elf64_External_Rela
));
11301 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11306 Elf_Internal_Rela rela
;
11309 /* This symbol needs a copy reloc. Set it up. */
11311 if (h
->dynindx
== -1
11312 || (h
->root
.type
!= bfd_link_hash_defined
11313 && h
->root
.type
!= bfd_link_hash_defweak
)
11314 || htab
->relbss
== NULL
)
11317 rela
.r_offset
= (h
->root
.u
.def
.value
11318 + h
->root
.u
.def
.section
->output_section
->vma
11319 + h
->root
.u
.def
.section
->output_offset
);
11320 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
11322 loc
= htab
->relbss
->contents
;
11323 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
11324 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11327 /* Mark some specially defined symbols as absolute. */
11328 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
11329 sym
->st_shndx
= SHN_ABS
;
11334 /* Used to decide how to sort relocs in an optimal manner for the
11335 dynamic linker, before writing them out. */
11337 static enum elf_reloc_type_class
11338 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
11340 enum elf_ppc64_reloc_type r_type
;
11342 r_type
= ELF64_R_TYPE (rela
->r_info
);
11345 case R_PPC64_RELATIVE
:
11346 return reloc_class_relative
;
11347 case R_PPC64_JMP_SLOT
:
11348 return reloc_class_plt
;
11350 return reloc_class_copy
;
11352 return reloc_class_normal
;
11356 /* Finish up the dynamic sections. */
11359 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
11360 struct bfd_link_info
*info
)
11362 struct ppc_link_hash_table
*htab
;
11366 htab
= ppc_hash_table (info
);
11367 dynobj
= htab
->elf
.dynobj
;
11368 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
11370 if (htab
->elf
.dynamic_sections_created
)
11372 Elf64_External_Dyn
*dyncon
, *dynconend
;
11374 if (sdyn
== NULL
|| htab
->got
== NULL
)
11377 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
11378 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
11379 for (; dyncon
< dynconend
; dyncon
++)
11381 Elf_Internal_Dyn dyn
;
11384 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
11391 case DT_PPC64_GLINK
:
11393 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11394 /* We stupidly defined DT_PPC64_GLINK to be the start
11395 of glink rather than the first entry point, which is
11396 what ld.so needs, and now have a bigger stub to
11397 support automatic multiple TOCs. */
11398 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
11402 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11405 dyn
.d_un
.d_ptr
= s
->vma
;
11408 case DT_PPC64_OPDSZ
:
11409 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11412 dyn
.d_un
.d_val
= s
->size
;
11417 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11422 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11426 dyn
.d_un
.d_val
= htab
->relplt
->size
;
11430 /* Don't count procedure linkage table relocs in the
11431 overall reloc count. */
11435 dyn
.d_un
.d_val
-= s
->size
;
11439 /* We may not be using the standard ELF linker script.
11440 If .rela.plt is the first .rela section, we adjust
11441 DT_RELA to not include it. */
11445 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
11447 dyn
.d_un
.d_ptr
+= s
->size
;
11451 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11455 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
11457 /* Fill in the first entry in the global offset table.
11458 We use it to hold the link-time TOCbase. */
11459 bfd_put_64 (output_bfd
,
11460 elf_gp (output_bfd
) + TOC_BASE_OFF
,
11461 htab
->got
->contents
);
11463 /* Set .got entry size. */
11464 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
11467 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
11469 /* Set .plt entry size. */
11470 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
11474 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
11475 brlt ourselves if emitrelocations. */
11476 if (htab
->brlt
!= NULL
11477 && htab
->brlt
->reloc_count
!= 0
11478 && !_bfd_elf_link_output_relocs (output_bfd
,
11480 &elf_section_data (htab
->brlt
)->rel_hdr
,
11481 elf_section_data (htab
->brlt
)->relocs
,
11485 /* We need to handle writing out multiple GOT sections ourselves,
11486 since we didn't add them to DYNOBJ. We know dynobj is the first
11488 while ((dynobj
= dynobj
->link_next
) != NULL
)
11492 if (!is_ppc64_elf_target (dynobj
->xvec
))
11495 s
= ppc64_elf_tdata (dynobj
)->got
;
11498 && s
->output_section
!= bfd_abs_section_ptr
11499 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11500 s
->contents
, s
->output_offset
,
11503 s
= ppc64_elf_tdata (dynobj
)->relgot
;
11506 && s
->output_section
!= bfd_abs_section_ptr
11507 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11508 s
->contents
, s
->output_offset
,
11516 #include "elf64-target.h"