1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004
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 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
33 #include "elf/ppc64.h"
34 #include "elf64-ppc.h"
36 static bfd_reloc_status_type ppc64_elf_ha_reloc
37 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
38 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_toc_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc64_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
55 #define TARGET_LITTLE_NAME "elf64-powerpcle"
56 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
57 #define TARGET_BIG_NAME "elf64-powerpc"
58 #define ELF_ARCH bfd_arch_powerpc
59 #define ELF_MACHINE_CODE EM_PPC64
60 #define ELF_MAXPAGESIZE 0x10000
61 #define elf_info_to_howto ppc64_elf_info_to_howto
63 #define elf_backend_want_got_sym 0
64 #define elf_backend_want_plt_sym 0
65 #define elf_backend_plt_alignment 3
66 #define elf_backend_plt_not_loaded 1
67 #define elf_backend_got_symbol_offset 0
68 #define elf_backend_got_header_size 8
69 #define elf_backend_can_gc_sections 1
70 #define elf_backend_can_refcount 1
71 #define elf_backend_rela_normal 1
73 #define bfd_elf64_mkobject ppc64_elf_mkobject
74 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
75 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
76 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
77 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
78 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
80 #define elf_backend_object_p ppc64_elf_object_p
81 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
82 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
83 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
84 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
85 #define elf_backend_check_relocs ppc64_elf_check_relocs
86 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
87 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
88 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
89 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
90 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
91 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
92 #define elf_backend_relocate_section ppc64_elf_relocate_section
93 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
94 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
95 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
96 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
97 #define elf_backend_special_sections ppc64_elf_special_sections
99 /* The name of the dynamic interpreter. This is put in the .interp
101 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
103 /* The size in bytes of an entry in the procedure linkage table. */
104 #define PLT_ENTRY_SIZE 24
106 /* The initial size of the plt reserved for the dynamic linker. */
107 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
109 /* TOC base pointers offset from start of TOC. */
110 #define TOC_BASE_OFF 0x8000
112 /* Offset of tp and dtp pointers from start of TLS block. */
113 #define TP_OFFSET 0x7000
114 #define DTP_OFFSET 0x8000
116 /* .plt call stub instructions. The normal stub is like this, but
117 sometimes the .plt entry crosses a 64k boundary and we need to
118 insert an addis to adjust r12. */
119 #define PLT_CALL_STUB_SIZE (7*4)
120 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
121 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
122 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
123 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
124 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
125 /* ld %r11,xxx+16@l(%r12) */
126 #define BCTR 0x4e800420 /* bctr */
129 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
130 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
132 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
134 /* glink call stub instructions. We enter with the index in R0, and the
135 address of glink entry in CTR. From that, we can calculate PLT0. */
136 #define GLINK_CALL_STUB_SIZE (16*4)
137 #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */
138 #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */
139 #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */
140 #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */
141 #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */
142 #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */
143 #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */
144 /* sub %r12,%r12,%r11 */
145 #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */
146 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
147 /* ld %r11,xxx@l(%r12) */
148 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */
151 /* ld %r11,16(%r12) */
155 #define NOP 0x60000000
157 /* Some other nops. */
158 #define CROR_151515 0x4def7b82
159 #define CROR_313131 0x4ffffb82
161 /* .glink entries for the first 32k functions are two instructions. */
162 #define LI_R0_0 0x38000000 /* li %r0,0 */
163 #define B_DOT 0x48000000 /* b . */
165 /* After that, we need two instructions to load the index, followed by
167 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
168 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
170 /* Instructions to save and restore floating point regs. */
171 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
172 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
173 #define BLR 0x4e800020 /* blr */
175 /* Since .opd is an array of descriptors and each entry will end up
176 with identical R_PPC64_RELATIVE relocs, there is really no need to
177 propagate .opd relocs; The dynamic linker should be taught to
178 relocate .opd without reloc entries. */
179 #ifndef NO_OPD_RELOCS
180 #define NO_OPD_RELOCS 0
183 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
185 /* Relocation HOWTO's. */
186 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
188 static reloc_howto_type ppc64_elf_howto_raw
[] = {
189 /* This reloc does nothing. */
190 HOWTO (R_PPC64_NONE
, /* type */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
194 FALSE
, /* pc_relative */
196 complain_overflow_dont
, /* complain_on_overflow */
197 bfd_elf_generic_reloc
, /* special_function */
198 "R_PPC64_NONE", /* name */
199 FALSE
, /* partial_inplace */
202 FALSE
), /* pcrel_offset */
204 /* A standard 32 bit relocation. */
205 HOWTO (R_PPC64_ADDR32
, /* type */
207 2, /* size (0 = byte, 1 = short, 2 = long) */
209 FALSE
, /* pc_relative */
211 complain_overflow_bitfield
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_PPC64_ADDR32", /* name */
214 FALSE
, /* partial_inplace */
216 0xffffffff, /* dst_mask */
217 FALSE
), /* pcrel_offset */
219 /* An absolute 26 bit branch; the lower two bits must be zero.
220 FIXME: we don't check that, we just clear them. */
221 HOWTO (R_PPC64_ADDR24
, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 FALSE
, /* pc_relative */
227 complain_overflow_bitfield
, /* complain_on_overflow */
228 bfd_elf_generic_reloc
, /* special_function */
229 "R_PPC64_ADDR24", /* name */
230 FALSE
, /* partial_inplace */
232 0x03fffffc, /* dst_mask */
233 FALSE
), /* pcrel_offset */
235 /* A standard 16 bit relocation. */
236 HOWTO (R_PPC64_ADDR16
, /* type */
238 1, /* size (0 = byte, 1 = short, 2 = long) */
240 FALSE
, /* pc_relative */
242 complain_overflow_bitfield
, /* complain_on_overflow */
243 bfd_elf_generic_reloc
, /* special_function */
244 "R_PPC64_ADDR16", /* name */
245 FALSE
, /* partial_inplace */
247 0xffff, /* dst_mask */
248 FALSE
), /* pcrel_offset */
250 /* A 16 bit relocation without overflow. */
251 HOWTO (R_PPC64_ADDR16_LO
, /* type */
253 1, /* size (0 = byte, 1 = short, 2 = long) */
255 FALSE
, /* pc_relative */
257 complain_overflow_dont
,/* complain_on_overflow */
258 bfd_elf_generic_reloc
, /* special_function */
259 "R_PPC64_ADDR16_LO", /* name */
260 FALSE
, /* partial_inplace */
262 0xffff, /* dst_mask */
263 FALSE
), /* pcrel_offset */
265 /* Bits 16-31 of an address. */
266 HOWTO (R_PPC64_ADDR16_HI
, /* type */
268 1, /* size (0 = byte, 1 = short, 2 = long) */
270 FALSE
, /* pc_relative */
272 complain_overflow_dont
, /* complain_on_overflow */
273 bfd_elf_generic_reloc
, /* special_function */
274 "R_PPC64_ADDR16_HI", /* name */
275 FALSE
, /* partial_inplace */
277 0xffff, /* dst_mask */
278 FALSE
), /* pcrel_offset */
280 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
281 bits, treated as a signed number, is negative. */
282 HOWTO (R_PPC64_ADDR16_HA
, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_dont
, /* complain_on_overflow */
289 ppc64_elf_ha_reloc
, /* special_function */
290 "R_PPC64_ADDR16_HA", /* name */
291 FALSE
, /* partial_inplace */
293 0xffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 /* An absolute 16 bit branch; the lower two bits must be zero.
297 FIXME: we don't check that, we just clear them. */
298 HOWTO (R_PPC64_ADDR14
, /* type */
300 2, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE
, /* pc_relative */
304 complain_overflow_bitfield
, /* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_PPC64_ADDR14", /* name */
307 FALSE
, /* partial_inplace */
309 0x0000fffc, /* dst_mask */
310 FALSE
), /* pcrel_offset */
312 /* An absolute 16 bit branch, for which bit 10 should be set to
313 indicate that the branch is expected to be taken. The lower two
314 bits must be zero. */
315 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE
, /* pc_relative */
321 complain_overflow_bitfield
, /* complain_on_overflow */
322 ppc64_elf_brtaken_reloc
, /* special_function */
323 "R_PPC64_ADDR14_BRTAKEN",/* name */
324 FALSE
, /* partial_inplace */
326 0x0000fffc, /* dst_mask */
327 FALSE
), /* pcrel_offset */
329 /* An absolute 16 bit branch, for which bit 10 should be set to
330 indicate that the branch is not expected to be taken. The lower
331 two bits must be zero. */
332 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
334 2, /* size (0 = byte, 1 = short, 2 = long) */
336 FALSE
, /* pc_relative */
338 complain_overflow_bitfield
, /* complain_on_overflow */
339 ppc64_elf_brtaken_reloc
, /* special_function */
340 "R_PPC64_ADDR14_BRNTAKEN",/* name */
341 FALSE
, /* partial_inplace */
343 0x0000fffc, /* dst_mask */
344 FALSE
), /* pcrel_offset */
346 /* A relative 26 bit branch; the lower two bits must be zero. */
347 HOWTO (R_PPC64_REL24
, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 TRUE
, /* pc_relative */
353 complain_overflow_signed
, /* complain_on_overflow */
354 bfd_elf_generic_reloc
, /* special_function */
355 "R_PPC64_REL24", /* name */
356 FALSE
, /* partial_inplace */
358 0x03fffffc, /* dst_mask */
359 TRUE
), /* pcrel_offset */
361 /* A relative 16 bit branch; the lower two bits must be zero. */
362 HOWTO (R_PPC64_REL14
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 TRUE
, /* pc_relative */
368 complain_overflow_signed
, /* complain_on_overflow */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_PPC64_REL14", /* name */
371 FALSE
, /* partial_inplace */
373 0x0000fffc, /* dst_mask */
374 TRUE
), /* pcrel_offset */
376 /* A relative 16 bit branch. Bit 10 should be set to indicate that
377 the branch is expected to be taken. The lower two bits must be
379 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 TRUE
, /* pc_relative */
385 complain_overflow_signed
, /* complain_on_overflow */
386 ppc64_elf_brtaken_reloc
, /* special_function */
387 "R_PPC64_REL14_BRTAKEN", /* name */
388 FALSE
, /* partial_inplace */
390 0x0000fffc, /* dst_mask */
391 TRUE
), /* pcrel_offset */
393 /* A relative 16 bit branch. Bit 10 should be set to indicate that
394 the branch is not expected to be taken. The lower two bits must
396 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 TRUE
, /* pc_relative */
402 complain_overflow_signed
, /* complain_on_overflow */
403 ppc64_elf_brtaken_reloc
, /* special_function */
404 "R_PPC64_REL14_BRNTAKEN",/* name */
405 FALSE
, /* partial_inplace */
407 0x0000fffc, /* dst_mask */
408 TRUE
), /* pcrel_offset */
410 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
412 HOWTO (R_PPC64_GOT16
, /* type */
414 1, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE
, /* pc_relative */
418 complain_overflow_signed
, /* complain_on_overflow */
419 ppc64_elf_unhandled_reloc
, /* special_function */
420 "R_PPC64_GOT16", /* name */
421 FALSE
, /* partial_inplace */
423 0xffff, /* dst_mask */
424 FALSE
), /* pcrel_offset */
426 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
428 HOWTO (R_PPC64_GOT16_LO
, /* type */
430 1, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE
, /* pc_relative */
434 complain_overflow_dont
, /* complain_on_overflow */
435 ppc64_elf_unhandled_reloc
, /* special_function */
436 "R_PPC64_GOT16_LO", /* name */
437 FALSE
, /* partial_inplace */
439 0xffff, /* dst_mask */
440 FALSE
), /* pcrel_offset */
442 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
444 HOWTO (R_PPC64_GOT16_HI
, /* type */
446 1, /* size (0 = byte, 1 = short, 2 = long) */
448 FALSE
, /* pc_relative */
450 complain_overflow_dont
,/* complain_on_overflow */
451 ppc64_elf_unhandled_reloc
, /* special_function */
452 "R_PPC64_GOT16_HI", /* name */
453 FALSE
, /* partial_inplace */
455 0xffff, /* dst_mask */
456 FALSE
), /* pcrel_offset */
458 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
460 HOWTO (R_PPC64_GOT16_HA
, /* type */
462 1, /* size (0 = byte, 1 = short, 2 = long) */
464 FALSE
, /* pc_relative */
466 complain_overflow_dont
,/* complain_on_overflow */
467 ppc64_elf_unhandled_reloc
, /* special_function */
468 "R_PPC64_GOT16_HA", /* name */
469 FALSE
, /* partial_inplace */
471 0xffff, /* dst_mask */
472 FALSE
), /* pcrel_offset */
474 /* This is used only by the dynamic linker. The symbol should exist
475 both in the object being run and in some shared library. The
476 dynamic linker copies the data addressed by the symbol from the
477 shared library into the object, because the object being
478 run has to have the data at some particular address. */
479 HOWTO (R_PPC64_COPY
, /* type */
481 0, /* this one is variable size */
483 FALSE
, /* pc_relative */
485 complain_overflow_dont
, /* complain_on_overflow */
486 ppc64_elf_unhandled_reloc
, /* special_function */
487 "R_PPC64_COPY", /* name */
488 FALSE
, /* partial_inplace */
491 FALSE
), /* pcrel_offset */
493 /* Like R_PPC64_ADDR64, but used when setting global offset table
495 HOWTO (R_PPC64_GLOB_DAT
, /* type */
497 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
499 FALSE
, /* pc_relative */
501 complain_overflow_dont
, /* complain_on_overflow */
502 ppc64_elf_unhandled_reloc
, /* special_function */
503 "R_PPC64_GLOB_DAT", /* name */
504 FALSE
, /* partial_inplace */
506 ONES (64), /* dst_mask */
507 FALSE
), /* pcrel_offset */
509 /* Created by the link editor. Marks a procedure linkage table
510 entry for a symbol. */
511 HOWTO (R_PPC64_JMP_SLOT
, /* type */
513 0, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE
, /* pc_relative */
517 complain_overflow_dont
, /* complain_on_overflow */
518 ppc64_elf_unhandled_reloc
, /* special_function */
519 "R_PPC64_JMP_SLOT", /* name */
520 FALSE
, /* partial_inplace */
523 FALSE
), /* pcrel_offset */
525 /* Used only by the dynamic linker. When the object is run, this
526 doubleword64 is set to the load address of the object, plus the
528 HOWTO (R_PPC64_RELATIVE
, /* type */
530 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
532 FALSE
, /* pc_relative */
534 complain_overflow_dont
, /* complain_on_overflow */
535 bfd_elf_generic_reloc
, /* special_function */
536 "R_PPC64_RELATIVE", /* name */
537 FALSE
, /* partial_inplace */
539 ONES (64), /* dst_mask */
540 FALSE
), /* pcrel_offset */
542 /* Like R_PPC64_ADDR32, but may be unaligned. */
543 HOWTO (R_PPC64_UADDR32
, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 FALSE
, /* pc_relative */
549 complain_overflow_bitfield
, /* complain_on_overflow */
550 bfd_elf_generic_reloc
, /* special_function */
551 "R_PPC64_UADDR32", /* name */
552 FALSE
, /* partial_inplace */
554 0xffffffff, /* dst_mask */
555 FALSE
), /* pcrel_offset */
557 /* Like R_PPC64_ADDR16, but may be unaligned. */
558 HOWTO (R_PPC64_UADDR16
, /* type */
560 1, /* size (0 = byte, 1 = short, 2 = long) */
562 FALSE
, /* pc_relative */
564 complain_overflow_bitfield
, /* complain_on_overflow */
565 bfd_elf_generic_reloc
, /* special_function */
566 "R_PPC64_UADDR16", /* name */
567 FALSE
, /* partial_inplace */
569 0xffff, /* dst_mask */
570 FALSE
), /* pcrel_offset */
572 /* 32-bit PC relative. */
573 HOWTO (R_PPC64_REL32
, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 TRUE
, /* pc_relative */
579 /* FIXME: Verify. Was complain_overflow_bitfield. */
580 complain_overflow_signed
, /* complain_on_overflow */
581 bfd_elf_generic_reloc
, /* special_function */
582 "R_PPC64_REL32", /* name */
583 FALSE
, /* partial_inplace */
585 0xffffffff, /* dst_mask */
586 TRUE
), /* pcrel_offset */
588 /* 32-bit relocation to the symbol's procedure linkage table. */
589 HOWTO (R_PPC64_PLT32
, /* type */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
593 FALSE
, /* pc_relative */
595 complain_overflow_bitfield
, /* complain_on_overflow */
596 ppc64_elf_unhandled_reloc
, /* special_function */
597 "R_PPC64_PLT32", /* name */
598 FALSE
, /* partial_inplace */
600 0xffffffff, /* dst_mask */
601 FALSE
), /* pcrel_offset */
603 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
604 FIXME: R_PPC64_PLTREL32 not supported. */
605 HOWTO (R_PPC64_PLTREL32
, /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 TRUE
, /* pc_relative */
611 complain_overflow_signed
, /* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 "R_PPC64_PLTREL32", /* name */
614 FALSE
, /* partial_inplace */
616 0xffffffff, /* dst_mask */
617 TRUE
), /* pcrel_offset */
619 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
621 HOWTO (R_PPC64_PLT16_LO
, /* type */
623 1, /* size (0 = byte, 1 = short, 2 = long) */
625 FALSE
, /* pc_relative */
627 complain_overflow_dont
, /* complain_on_overflow */
628 ppc64_elf_unhandled_reloc
, /* special_function */
629 "R_PPC64_PLT16_LO", /* name */
630 FALSE
, /* partial_inplace */
632 0xffff, /* dst_mask */
633 FALSE
), /* pcrel_offset */
635 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
637 HOWTO (R_PPC64_PLT16_HI
, /* type */
639 1, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE
, /* pc_relative */
643 complain_overflow_dont
, /* complain_on_overflow */
644 ppc64_elf_unhandled_reloc
, /* special_function */
645 "R_PPC64_PLT16_HI", /* name */
646 FALSE
, /* partial_inplace */
648 0xffff, /* dst_mask */
649 FALSE
), /* pcrel_offset */
651 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
653 HOWTO (R_PPC64_PLT16_HA
, /* type */
655 1, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_dont
, /* complain_on_overflow */
660 ppc64_elf_unhandled_reloc
, /* special_function */
661 "R_PPC64_PLT16_HA", /* name */
662 FALSE
, /* partial_inplace */
664 0xffff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
667 /* 16-bit section relative relocation. */
668 HOWTO (R_PPC64_SECTOFF
, /* type */
670 1, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_bitfield
, /* complain_on_overflow */
675 ppc64_elf_sectoff_reloc
, /* special_function */
676 "R_PPC64_SECTOFF", /* name */
677 FALSE
, /* partial_inplace */
679 0xffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
682 /* Like R_PPC64_SECTOFF, but no overflow warning. */
683 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
685 1, /* size (0 = byte, 1 = short, 2 = long) */
687 FALSE
, /* pc_relative */
689 complain_overflow_dont
, /* complain_on_overflow */
690 ppc64_elf_sectoff_reloc
, /* special_function */
691 "R_PPC64_SECTOFF_LO", /* name */
692 FALSE
, /* partial_inplace */
694 0xffff, /* dst_mask */
695 FALSE
), /* pcrel_offset */
697 /* 16-bit upper half section relative relocation. */
698 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
700 1, /* size (0 = byte, 1 = short, 2 = long) */
702 FALSE
, /* pc_relative */
704 complain_overflow_dont
, /* complain_on_overflow */
705 ppc64_elf_sectoff_reloc
, /* special_function */
706 "R_PPC64_SECTOFF_HI", /* name */
707 FALSE
, /* partial_inplace */
709 0xffff, /* dst_mask */
710 FALSE
), /* pcrel_offset */
712 /* 16-bit upper half adjusted section relative relocation. */
713 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
715 1, /* size (0 = byte, 1 = short, 2 = long) */
717 FALSE
, /* pc_relative */
719 complain_overflow_dont
, /* complain_on_overflow */
720 ppc64_elf_sectoff_ha_reloc
, /* special_function */
721 "R_PPC64_SECTOFF_HA", /* name */
722 FALSE
, /* partial_inplace */
724 0xffff, /* dst_mask */
725 FALSE
), /* pcrel_offset */
727 /* Like R_PPC64_REL24 without touching the two least significant bits. */
728 HOWTO (R_PPC64_REL30
, /* type */
730 2, /* size (0 = byte, 1 = short, 2 = long) */
732 TRUE
, /* pc_relative */
734 complain_overflow_dont
, /* complain_on_overflow */
735 bfd_elf_generic_reloc
, /* special_function */
736 "R_PPC64_REL30", /* name */
737 FALSE
, /* partial_inplace */
739 0xfffffffc, /* dst_mask */
740 TRUE
), /* pcrel_offset */
742 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
744 /* A standard 64-bit relocation. */
745 HOWTO (R_PPC64_ADDR64
, /* type */
747 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
749 FALSE
, /* pc_relative */
751 complain_overflow_dont
, /* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* special_function */
753 "R_PPC64_ADDR64", /* name */
754 FALSE
, /* partial_inplace */
756 ONES (64), /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 /* The bits 32-47 of an address. */
760 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
762 1, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_dont
, /* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_PPC64_ADDR16_HIGHER", /* name */
769 FALSE
, /* partial_inplace */
771 0xffff, /* dst_mask */
772 FALSE
), /* pcrel_offset */
774 /* The bits 32-47 of an address, plus 1 if the contents of the low
775 16 bits, treated as a signed number, is negative. */
776 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
778 1, /* size (0 = byte, 1 = short, 2 = long) */
780 FALSE
, /* pc_relative */
782 complain_overflow_dont
, /* complain_on_overflow */
783 ppc64_elf_ha_reloc
, /* special_function */
784 "R_PPC64_ADDR16_HIGHERA", /* name */
785 FALSE
, /* partial_inplace */
787 0xffff, /* dst_mask */
788 FALSE
), /* pcrel_offset */
790 /* The bits 48-63 of an address. */
791 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
793 1, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_dont
, /* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_PPC64_ADDR16_HIGHEST", /* name */
800 FALSE
, /* partial_inplace */
802 0xffff, /* dst_mask */
803 FALSE
), /* pcrel_offset */
805 /* The bits 48-63 of an address, plus 1 if the contents of the low
806 16 bits, treated as a signed number, is negative. */
807 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
809 1, /* size (0 = byte, 1 = short, 2 = long) */
811 FALSE
, /* pc_relative */
813 complain_overflow_dont
, /* complain_on_overflow */
814 ppc64_elf_ha_reloc
, /* special_function */
815 "R_PPC64_ADDR16_HIGHESTA", /* name */
816 FALSE
, /* partial_inplace */
818 0xffff, /* dst_mask */
819 FALSE
), /* pcrel_offset */
821 /* Like ADDR64, but may be unaligned. */
822 HOWTO (R_PPC64_UADDR64
, /* type */
824 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
826 FALSE
, /* pc_relative */
828 complain_overflow_dont
, /* complain_on_overflow */
829 bfd_elf_generic_reloc
, /* special_function */
830 "R_PPC64_UADDR64", /* name */
831 FALSE
, /* partial_inplace */
833 ONES (64), /* dst_mask */
834 FALSE
), /* pcrel_offset */
836 /* 64-bit relative relocation. */
837 HOWTO (R_PPC64_REL64
, /* type */
839 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
841 TRUE
, /* pc_relative */
843 complain_overflow_dont
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 "R_PPC64_REL64", /* name */
846 FALSE
, /* partial_inplace */
848 ONES (64), /* dst_mask */
849 TRUE
), /* pcrel_offset */
851 /* 64-bit relocation to the symbol's procedure linkage table. */
852 HOWTO (R_PPC64_PLT64
, /* type */
854 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
856 FALSE
, /* pc_relative */
858 complain_overflow_dont
, /* complain_on_overflow */
859 ppc64_elf_unhandled_reloc
, /* special_function */
860 "R_PPC64_PLT64", /* name */
861 FALSE
, /* partial_inplace */
863 ONES (64), /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 /* 64-bit PC relative relocation to the symbol's procedure linkage
868 /* FIXME: R_PPC64_PLTREL64 not supported. */
869 HOWTO (R_PPC64_PLTREL64
, /* type */
871 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
873 TRUE
, /* pc_relative */
875 complain_overflow_dont
, /* complain_on_overflow */
876 ppc64_elf_unhandled_reloc
, /* special_function */
877 "R_PPC64_PLTREL64", /* name */
878 FALSE
, /* partial_inplace */
880 ONES (64), /* dst_mask */
881 TRUE
), /* pcrel_offset */
883 /* 16 bit TOC-relative relocation. */
885 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
886 HOWTO (R_PPC64_TOC16
, /* type */
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE
, /* pc_relative */
892 complain_overflow_signed
, /* complain_on_overflow */
893 ppc64_elf_toc_reloc
, /* special_function */
894 "R_PPC64_TOC16", /* name */
895 FALSE
, /* partial_inplace */
897 0xffff, /* dst_mask */
898 FALSE
), /* pcrel_offset */
900 /* 16 bit TOC-relative relocation without overflow. */
902 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
903 HOWTO (R_PPC64_TOC16_LO
, /* type */
905 1, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE
, /* pc_relative */
909 complain_overflow_dont
, /* complain_on_overflow */
910 ppc64_elf_toc_reloc
, /* special_function */
911 "R_PPC64_TOC16_LO", /* name */
912 FALSE
, /* partial_inplace */
914 0xffff, /* dst_mask */
915 FALSE
), /* pcrel_offset */
917 /* 16 bit TOC-relative relocation, high 16 bits. */
919 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
920 HOWTO (R_PPC64_TOC16_HI
, /* type */
922 1, /* size (0 = byte, 1 = short, 2 = long) */
924 FALSE
, /* pc_relative */
926 complain_overflow_dont
, /* complain_on_overflow */
927 ppc64_elf_toc_reloc
, /* special_function */
928 "R_PPC64_TOC16_HI", /* name */
929 FALSE
, /* partial_inplace */
931 0xffff, /* dst_mask */
932 FALSE
), /* pcrel_offset */
934 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
935 contents of the low 16 bits, treated as a signed number, is
938 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
939 HOWTO (R_PPC64_TOC16_HA
, /* type */
941 1, /* size (0 = byte, 1 = short, 2 = long) */
943 FALSE
, /* pc_relative */
945 complain_overflow_dont
, /* complain_on_overflow */
946 ppc64_elf_toc_ha_reloc
, /* special_function */
947 "R_PPC64_TOC16_HA", /* name */
948 FALSE
, /* partial_inplace */
950 0xffff, /* dst_mask */
951 FALSE
), /* pcrel_offset */
953 /* 64-bit relocation; insert value of TOC base (.TOC.). */
955 /* R_PPC64_TOC 51 doubleword64 .TOC. */
956 HOWTO (R_PPC64_TOC
, /* type */
958 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
960 FALSE
, /* pc_relative */
962 complain_overflow_bitfield
, /* complain_on_overflow */
963 ppc64_elf_toc64_reloc
, /* special_function */
964 "R_PPC64_TOC", /* name */
965 FALSE
, /* partial_inplace */
967 ONES (64), /* dst_mask */
968 FALSE
), /* pcrel_offset */
970 /* Like R_PPC64_GOT16, but also informs the link editor that the
971 value to relocate may (!) refer to a PLT entry which the link
972 editor (a) may replace with the symbol value. If the link editor
973 is unable to fully resolve the symbol, it may (b) create a PLT
974 entry and store the address to the new PLT entry in the GOT.
975 This permits lazy resolution of function symbols at run time.
976 The link editor may also skip all of this and just (c) emit a
977 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
978 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
979 HOWTO (R_PPC64_PLTGOT16
, /* type */
981 1, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE
, /* pc_relative */
985 complain_overflow_signed
, /* complain_on_overflow */
986 ppc64_elf_unhandled_reloc
, /* special_function */
987 "R_PPC64_PLTGOT16", /* name */
988 FALSE
, /* partial_inplace */
990 0xffff, /* dst_mask */
991 FALSE
), /* pcrel_offset */
993 /* Like R_PPC64_PLTGOT16, but without overflow. */
994 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
995 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
997 1, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE
, /* pc_relative */
1001 complain_overflow_dont
, /* complain_on_overflow */
1002 ppc64_elf_unhandled_reloc
, /* special_function */
1003 "R_PPC64_PLTGOT16_LO", /* name */
1004 FALSE
, /* partial_inplace */
1006 0xffff, /* dst_mask */
1007 FALSE
), /* pcrel_offset */
1009 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1010 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1011 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1012 16, /* rightshift */
1013 1, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE
, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 ppc64_elf_unhandled_reloc
, /* special_function */
1019 "R_PPC64_PLTGOT16_HI", /* name */
1020 FALSE
, /* partial_inplace */
1022 0xffff, /* dst_mask */
1023 FALSE
), /* pcrel_offset */
1025 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1026 1 if the contents of the low 16 bits, treated as a signed number,
1028 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1029 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1030 16, /* rightshift */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_dont
,/* complain_on_overflow */
1036 ppc64_elf_unhandled_reloc
, /* special_function */
1037 "R_PPC64_PLTGOT16_HA", /* name */
1038 FALSE
, /* partial_inplace */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1044 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1046 1, /* size (0 = byte, 1 = short, 2 = long) */
1048 FALSE
, /* pc_relative */
1050 complain_overflow_bitfield
, /* complain_on_overflow */
1051 bfd_elf_generic_reloc
, /* special_function */
1052 "R_PPC64_ADDR16_DS", /* name */
1053 FALSE
, /* partial_inplace */
1055 0xfffc, /* dst_mask */
1056 FALSE
), /* pcrel_offset */
1058 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1059 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1061 1, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_dont
,/* complain_on_overflow */
1066 bfd_elf_generic_reloc
, /* special_function */
1067 "R_PPC64_ADDR16_LO_DS",/* name */
1068 FALSE
, /* partial_inplace */
1070 0xfffc, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1073 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1074 HOWTO (R_PPC64_GOT16_DS
, /* type */
1076 1, /* size (0 = byte, 1 = short, 2 = long) */
1078 FALSE
, /* pc_relative */
1080 complain_overflow_signed
, /* complain_on_overflow */
1081 ppc64_elf_unhandled_reloc
, /* special_function */
1082 "R_PPC64_GOT16_DS", /* name */
1083 FALSE
, /* partial_inplace */
1085 0xfffc, /* dst_mask */
1086 FALSE
), /* pcrel_offset */
1088 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1089 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1091 1, /* size (0 = byte, 1 = short, 2 = long) */
1093 FALSE
, /* pc_relative */
1095 complain_overflow_dont
, /* complain_on_overflow */
1096 ppc64_elf_unhandled_reloc
, /* special_function */
1097 "R_PPC64_GOT16_LO_DS", /* name */
1098 FALSE
, /* partial_inplace */
1100 0xfffc, /* dst_mask */
1101 FALSE
), /* pcrel_offset */
1103 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1104 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1106 1, /* size (0 = byte, 1 = short, 2 = long) */
1108 FALSE
, /* pc_relative */
1110 complain_overflow_dont
, /* complain_on_overflow */
1111 ppc64_elf_unhandled_reloc
, /* special_function */
1112 "R_PPC64_PLT16_LO_DS", /* name */
1113 FALSE
, /* partial_inplace */
1115 0xfffc, /* dst_mask */
1116 FALSE
), /* pcrel_offset */
1118 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1119 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1121 1, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE
, /* pc_relative */
1125 complain_overflow_bitfield
, /* complain_on_overflow */
1126 ppc64_elf_sectoff_reloc
, /* special_function */
1127 "R_PPC64_SECTOFF_DS", /* name */
1128 FALSE
, /* partial_inplace */
1130 0xfffc, /* dst_mask */
1131 FALSE
), /* pcrel_offset */
1133 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1134 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1136 1, /* size (0 = byte, 1 = short, 2 = long) */
1138 FALSE
, /* pc_relative */
1140 complain_overflow_dont
, /* complain_on_overflow */
1141 ppc64_elf_sectoff_reloc
, /* special_function */
1142 "R_PPC64_SECTOFF_LO_DS",/* name */
1143 FALSE
, /* partial_inplace */
1145 0xfffc, /* dst_mask */
1146 FALSE
), /* pcrel_offset */
1148 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1149 HOWTO (R_PPC64_TOC16_DS
, /* type */
1151 1, /* size (0 = byte, 1 = short, 2 = long) */
1153 FALSE
, /* pc_relative */
1155 complain_overflow_signed
, /* complain_on_overflow */
1156 ppc64_elf_toc_reloc
, /* special_function */
1157 "R_PPC64_TOC16_DS", /* name */
1158 FALSE
, /* partial_inplace */
1160 0xfffc, /* dst_mask */
1161 FALSE
), /* pcrel_offset */
1163 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1164 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1166 1, /* size (0 = byte, 1 = short, 2 = long) */
1168 FALSE
, /* pc_relative */
1170 complain_overflow_dont
, /* complain_on_overflow */
1171 ppc64_elf_toc_reloc
, /* special_function */
1172 "R_PPC64_TOC16_LO_DS", /* name */
1173 FALSE
, /* partial_inplace */
1175 0xfffc, /* dst_mask */
1176 FALSE
), /* pcrel_offset */
1178 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1179 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1180 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1182 1, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE
, /* pc_relative */
1186 complain_overflow_signed
, /* complain_on_overflow */
1187 ppc64_elf_unhandled_reloc
, /* special_function */
1188 "R_PPC64_PLTGOT16_DS", /* name */
1189 FALSE
, /* partial_inplace */
1191 0xfffc, /* dst_mask */
1192 FALSE
), /* pcrel_offset */
1194 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1195 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1196 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1198 1, /* size (0 = byte, 1 = short, 2 = long) */
1200 FALSE
, /* pc_relative */
1202 complain_overflow_dont
, /* complain_on_overflow */
1203 ppc64_elf_unhandled_reloc
, /* special_function */
1204 "R_PPC64_PLTGOT16_LO_DS",/* name */
1205 FALSE
, /* partial_inplace */
1207 0xfffc, /* dst_mask */
1208 FALSE
), /* pcrel_offset */
1210 /* Marker reloc for TLS. */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE
, /* pc_relative */
1217 complain_overflow_dont
, /* complain_on_overflow */
1218 bfd_elf_generic_reloc
, /* special_function */
1219 "R_PPC64_TLS", /* name */
1220 FALSE
, /* partial_inplace */
1223 FALSE
), /* pcrel_offset */
1225 /* Computes the load module index of the load module that contains the
1226 definition of its TLS sym. */
1227 HOWTO (R_PPC64_DTPMOD64
,
1229 4, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE
, /* pc_relative */
1233 complain_overflow_dont
, /* complain_on_overflow */
1234 ppc64_elf_unhandled_reloc
, /* special_function */
1235 "R_PPC64_DTPMOD64", /* name */
1236 FALSE
, /* partial_inplace */
1238 ONES (64), /* dst_mask */
1239 FALSE
), /* pcrel_offset */
1241 /* Computes a dtv-relative displacement, the difference between the value
1242 of sym+add and the base address of the thread-local storage block that
1243 contains the definition of sym, minus 0x8000. */
1244 HOWTO (R_PPC64_DTPREL64
,
1246 4, /* size (0 = byte, 1 = short, 2 = long) */
1248 FALSE
, /* pc_relative */
1250 complain_overflow_dont
, /* complain_on_overflow */
1251 ppc64_elf_unhandled_reloc
, /* special_function */
1252 "R_PPC64_DTPREL64", /* name */
1253 FALSE
, /* partial_inplace */
1255 ONES (64), /* dst_mask */
1256 FALSE
), /* pcrel_offset */
1258 /* A 16 bit dtprel reloc. */
1259 HOWTO (R_PPC64_DTPREL16
,
1261 1, /* size (0 = byte, 1 = short, 2 = long) */
1263 FALSE
, /* pc_relative */
1265 complain_overflow_signed
, /* complain_on_overflow */
1266 ppc64_elf_unhandled_reloc
, /* special_function */
1267 "R_PPC64_DTPREL16", /* name */
1268 FALSE
, /* partial_inplace */
1270 0xffff, /* dst_mask */
1271 FALSE
), /* pcrel_offset */
1273 /* Like DTPREL16, but no overflow. */
1274 HOWTO (R_PPC64_DTPREL16_LO
,
1276 1, /* size (0 = byte, 1 = short, 2 = long) */
1278 FALSE
, /* pc_relative */
1280 complain_overflow_dont
, /* complain_on_overflow */
1281 ppc64_elf_unhandled_reloc
, /* special_function */
1282 "R_PPC64_DTPREL16_LO", /* name */
1283 FALSE
, /* partial_inplace */
1285 0xffff, /* dst_mask */
1286 FALSE
), /* pcrel_offset */
1288 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1289 HOWTO (R_PPC64_DTPREL16_HI
,
1290 16, /* rightshift */
1291 1, /* size (0 = byte, 1 = short, 2 = long) */
1293 FALSE
, /* pc_relative */
1295 complain_overflow_dont
, /* complain_on_overflow */
1296 ppc64_elf_unhandled_reloc
, /* special_function */
1297 "R_PPC64_DTPREL16_HI", /* name */
1298 FALSE
, /* partial_inplace */
1300 0xffff, /* dst_mask */
1301 FALSE
), /* pcrel_offset */
1303 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1304 HOWTO (R_PPC64_DTPREL16_HA
,
1305 16, /* rightshift */
1306 1, /* size (0 = byte, 1 = short, 2 = long) */
1308 FALSE
, /* pc_relative */
1310 complain_overflow_dont
, /* complain_on_overflow */
1311 ppc64_elf_unhandled_reloc
, /* special_function */
1312 "R_PPC64_DTPREL16_HA", /* name */
1313 FALSE
, /* partial_inplace */
1315 0xffff, /* dst_mask */
1316 FALSE
), /* pcrel_offset */
1318 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1319 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1320 32, /* rightshift */
1321 1, /* size (0 = byte, 1 = short, 2 = long) */
1323 FALSE
, /* pc_relative */
1325 complain_overflow_dont
, /* complain_on_overflow */
1326 ppc64_elf_unhandled_reloc
, /* special_function */
1327 "R_PPC64_DTPREL16_HIGHER", /* name */
1328 FALSE
, /* partial_inplace */
1330 0xffff, /* dst_mask */
1331 FALSE
), /* pcrel_offset */
1333 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1334 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1335 32, /* rightshift */
1336 1, /* size (0 = byte, 1 = short, 2 = long) */
1338 FALSE
, /* pc_relative */
1340 complain_overflow_dont
, /* complain_on_overflow */
1341 ppc64_elf_unhandled_reloc
, /* special_function */
1342 "R_PPC64_DTPREL16_HIGHERA", /* name */
1343 FALSE
, /* partial_inplace */
1345 0xffff, /* dst_mask */
1346 FALSE
), /* pcrel_offset */
1348 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1349 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1350 48, /* rightshift */
1351 1, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE
, /* pc_relative */
1355 complain_overflow_dont
, /* complain_on_overflow */
1356 ppc64_elf_unhandled_reloc
, /* special_function */
1357 "R_PPC64_DTPREL16_HIGHEST", /* name */
1358 FALSE
, /* partial_inplace */
1360 0xffff, /* dst_mask */
1361 FALSE
), /* pcrel_offset */
1363 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1364 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1365 48, /* rightshift */
1366 1, /* size (0 = byte, 1 = short, 2 = long) */
1368 FALSE
, /* pc_relative */
1370 complain_overflow_dont
, /* complain_on_overflow */
1371 ppc64_elf_unhandled_reloc
, /* special_function */
1372 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1373 FALSE
, /* partial_inplace */
1375 0xffff, /* dst_mask */
1376 FALSE
), /* pcrel_offset */
1378 /* Like DTPREL16, but for insns with a DS field. */
1379 HOWTO (R_PPC64_DTPREL16_DS
,
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 FALSE
, /* pc_relative */
1385 complain_overflow_signed
, /* complain_on_overflow */
1386 ppc64_elf_unhandled_reloc
, /* special_function */
1387 "R_PPC64_DTPREL16_DS", /* name */
1388 FALSE
, /* partial_inplace */
1390 0xfffc, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1393 /* Like DTPREL16_DS, but no overflow. */
1394 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1396 1, /* size (0 = byte, 1 = short, 2 = long) */
1398 FALSE
, /* pc_relative */
1400 complain_overflow_dont
, /* complain_on_overflow */
1401 ppc64_elf_unhandled_reloc
, /* special_function */
1402 "R_PPC64_DTPREL16_LO_DS", /* name */
1403 FALSE
, /* partial_inplace */
1405 0xfffc, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1408 /* Computes a tp-relative displacement, the difference between the value of
1409 sym+add and the value of the thread pointer (r13). */
1410 HOWTO (R_PPC64_TPREL64
,
1412 4, /* size (0 = byte, 1 = short, 2 = long) */
1414 FALSE
, /* pc_relative */
1416 complain_overflow_dont
, /* complain_on_overflow */
1417 ppc64_elf_unhandled_reloc
, /* special_function */
1418 "R_PPC64_TPREL64", /* name */
1419 FALSE
, /* partial_inplace */
1421 ONES (64), /* dst_mask */
1422 FALSE
), /* pcrel_offset */
1424 /* A 16 bit tprel reloc. */
1425 HOWTO (R_PPC64_TPREL16
,
1427 1, /* size (0 = byte, 1 = short, 2 = long) */
1429 FALSE
, /* pc_relative */
1431 complain_overflow_signed
, /* complain_on_overflow */
1432 ppc64_elf_unhandled_reloc
, /* special_function */
1433 "R_PPC64_TPREL16", /* name */
1434 FALSE
, /* partial_inplace */
1436 0xffff, /* dst_mask */
1437 FALSE
), /* pcrel_offset */
1439 /* Like TPREL16, but no overflow. */
1440 HOWTO (R_PPC64_TPREL16_LO
,
1442 1, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE
, /* pc_relative */
1446 complain_overflow_dont
, /* complain_on_overflow */
1447 ppc64_elf_unhandled_reloc
, /* special_function */
1448 "R_PPC64_TPREL16_LO", /* name */
1449 FALSE
, /* partial_inplace */
1451 0xffff, /* dst_mask */
1452 FALSE
), /* pcrel_offset */
1454 /* Like TPREL16_LO, but next higher group of 16 bits. */
1455 HOWTO (R_PPC64_TPREL16_HI
,
1456 16, /* rightshift */
1457 1, /* size (0 = byte, 1 = short, 2 = long) */
1459 FALSE
, /* pc_relative */
1461 complain_overflow_dont
, /* complain_on_overflow */
1462 ppc64_elf_unhandled_reloc
, /* special_function */
1463 "R_PPC64_TPREL16_HI", /* name */
1464 FALSE
, /* partial_inplace */
1466 0xffff, /* dst_mask */
1467 FALSE
), /* pcrel_offset */
1469 /* Like TPREL16_HI, but adjust for low 16 bits. */
1470 HOWTO (R_PPC64_TPREL16_HA
,
1471 16, /* rightshift */
1472 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE
, /* pc_relative */
1476 complain_overflow_dont
, /* complain_on_overflow */
1477 ppc64_elf_unhandled_reloc
, /* special_function */
1478 "R_PPC64_TPREL16_HA", /* name */
1479 FALSE
, /* partial_inplace */
1481 0xffff, /* dst_mask */
1482 FALSE
), /* pcrel_offset */
1484 /* Like TPREL16_HI, but next higher group of 16 bits. */
1485 HOWTO (R_PPC64_TPREL16_HIGHER
,
1486 32, /* rightshift */
1487 1, /* size (0 = byte, 1 = short, 2 = long) */
1489 FALSE
, /* pc_relative */
1491 complain_overflow_dont
, /* complain_on_overflow */
1492 ppc64_elf_unhandled_reloc
, /* special_function */
1493 "R_PPC64_TPREL16_HIGHER", /* name */
1494 FALSE
, /* partial_inplace */
1496 0xffff, /* dst_mask */
1497 FALSE
), /* pcrel_offset */
1499 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1500 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1501 32, /* rightshift */
1502 1, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE
, /* pc_relative */
1506 complain_overflow_dont
, /* complain_on_overflow */
1507 ppc64_elf_unhandled_reloc
, /* special_function */
1508 "R_PPC64_TPREL16_HIGHERA", /* name */
1509 FALSE
, /* partial_inplace */
1511 0xffff, /* dst_mask */
1512 FALSE
), /* pcrel_offset */
1514 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1515 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1516 48, /* rightshift */
1517 1, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE
, /* pc_relative */
1521 complain_overflow_dont
, /* complain_on_overflow */
1522 ppc64_elf_unhandled_reloc
, /* special_function */
1523 "R_PPC64_TPREL16_HIGHEST", /* name */
1524 FALSE
, /* partial_inplace */
1526 0xffff, /* dst_mask */
1527 FALSE
), /* pcrel_offset */
1529 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1530 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1531 48, /* rightshift */
1532 1, /* size (0 = byte, 1 = short, 2 = long) */
1534 FALSE
, /* pc_relative */
1536 complain_overflow_dont
, /* complain_on_overflow */
1537 ppc64_elf_unhandled_reloc
, /* special_function */
1538 "R_PPC64_TPREL16_HIGHESTA", /* name */
1539 FALSE
, /* partial_inplace */
1541 0xffff, /* dst_mask */
1542 FALSE
), /* pcrel_offset */
1544 /* Like TPREL16, but for insns with a DS field. */
1545 HOWTO (R_PPC64_TPREL16_DS
,
1547 1, /* size (0 = byte, 1 = short, 2 = long) */
1549 FALSE
, /* pc_relative */
1551 complain_overflow_signed
, /* complain_on_overflow */
1552 ppc64_elf_unhandled_reloc
, /* special_function */
1553 "R_PPC64_TPREL16_DS", /* name */
1554 FALSE
, /* partial_inplace */
1556 0xfffc, /* dst_mask */
1557 FALSE
), /* pcrel_offset */
1559 /* Like TPREL16_DS, but no overflow. */
1560 HOWTO (R_PPC64_TPREL16_LO_DS
,
1562 1, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE
, /* pc_relative */
1566 complain_overflow_dont
, /* complain_on_overflow */
1567 ppc64_elf_unhandled_reloc
, /* special_function */
1568 "R_PPC64_TPREL16_LO_DS", /* name */
1569 FALSE
, /* partial_inplace */
1571 0xfffc, /* dst_mask */
1572 FALSE
), /* pcrel_offset */
1574 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1575 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1576 to the first entry relative to the TOC base (r2). */
1577 HOWTO (R_PPC64_GOT_TLSGD16
,
1579 1, /* size (0 = byte, 1 = short, 2 = long) */
1581 FALSE
, /* pc_relative */
1583 complain_overflow_signed
, /* complain_on_overflow */
1584 ppc64_elf_unhandled_reloc
, /* special_function */
1585 "R_PPC64_GOT_TLSGD16", /* name */
1586 FALSE
, /* partial_inplace */
1588 0xffff, /* dst_mask */
1589 FALSE
), /* pcrel_offset */
1591 /* Like GOT_TLSGD16, but no overflow. */
1592 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1594 1, /* size (0 = byte, 1 = short, 2 = long) */
1596 FALSE
, /* pc_relative */
1598 complain_overflow_dont
, /* complain_on_overflow */
1599 ppc64_elf_unhandled_reloc
, /* special_function */
1600 "R_PPC64_GOT_TLSGD16_LO", /* name */
1601 FALSE
, /* partial_inplace */
1603 0xffff, /* dst_mask */
1604 FALSE
), /* pcrel_offset */
1606 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1607 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1608 16, /* rightshift */
1609 1, /* size (0 = byte, 1 = short, 2 = long) */
1611 FALSE
, /* pc_relative */
1613 complain_overflow_dont
, /* complain_on_overflow */
1614 ppc64_elf_unhandled_reloc
, /* special_function */
1615 "R_PPC64_GOT_TLSGD16_HI", /* name */
1616 FALSE
, /* partial_inplace */
1618 0xffff, /* dst_mask */
1619 FALSE
), /* pcrel_offset */
1621 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1622 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1623 16, /* rightshift */
1624 1, /* size (0 = byte, 1 = short, 2 = long) */
1626 FALSE
, /* pc_relative */
1628 complain_overflow_dont
, /* complain_on_overflow */
1629 ppc64_elf_unhandled_reloc
, /* special_function */
1630 "R_PPC64_GOT_TLSGD16_HA", /* name */
1631 FALSE
, /* partial_inplace */
1633 0xffff, /* dst_mask */
1634 FALSE
), /* pcrel_offset */
1636 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1637 with values (sym+add)@dtpmod and zero, and computes the offset to the
1638 first entry relative to the TOC base (r2). */
1639 HOWTO (R_PPC64_GOT_TLSLD16
,
1641 1, /* size (0 = byte, 1 = short, 2 = long) */
1643 FALSE
, /* pc_relative */
1645 complain_overflow_signed
, /* complain_on_overflow */
1646 ppc64_elf_unhandled_reloc
, /* special_function */
1647 "R_PPC64_GOT_TLSLD16", /* name */
1648 FALSE
, /* partial_inplace */
1650 0xffff, /* dst_mask */
1651 FALSE
), /* pcrel_offset */
1653 /* Like GOT_TLSLD16, but no overflow. */
1654 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1656 1, /* size (0 = byte, 1 = short, 2 = long) */
1658 FALSE
, /* pc_relative */
1660 complain_overflow_dont
, /* complain_on_overflow */
1661 ppc64_elf_unhandled_reloc
, /* special_function */
1662 "R_PPC64_GOT_TLSLD16_LO", /* name */
1663 FALSE
, /* partial_inplace */
1665 0xffff, /* dst_mask */
1666 FALSE
), /* pcrel_offset */
1668 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1669 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1670 16, /* rightshift */
1671 1, /* size (0 = byte, 1 = short, 2 = long) */
1673 FALSE
, /* pc_relative */
1675 complain_overflow_dont
, /* complain_on_overflow */
1676 ppc64_elf_unhandled_reloc
, /* special_function */
1677 "R_PPC64_GOT_TLSLD16_HI", /* name */
1678 FALSE
, /* partial_inplace */
1680 0xffff, /* dst_mask */
1681 FALSE
), /* pcrel_offset */
1683 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1684 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1685 16, /* rightshift */
1686 1, /* size (0 = byte, 1 = short, 2 = long) */
1688 FALSE
, /* pc_relative */
1690 complain_overflow_dont
, /* complain_on_overflow */
1691 ppc64_elf_unhandled_reloc
, /* special_function */
1692 "R_PPC64_GOT_TLSLD16_HA", /* name */
1693 FALSE
, /* partial_inplace */
1695 0xffff, /* dst_mask */
1696 FALSE
), /* pcrel_offset */
1698 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1699 the offset to the entry relative to the TOC base (r2). */
1700 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1702 1, /* size (0 = byte, 1 = short, 2 = long) */
1704 FALSE
, /* pc_relative */
1706 complain_overflow_signed
, /* complain_on_overflow */
1707 ppc64_elf_unhandled_reloc
, /* special_function */
1708 "R_PPC64_GOT_DTPREL16_DS", /* name */
1709 FALSE
, /* partial_inplace */
1711 0xfffc, /* dst_mask */
1712 FALSE
), /* pcrel_offset */
1714 /* Like GOT_DTPREL16_DS, but no overflow. */
1715 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1717 1, /* size (0 = byte, 1 = short, 2 = long) */
1719 FALSE
, /* pc_relative */
1721 complain_overflow_dont
, /* complain_on_overflow */
1722 ppc64_elf_unhandled_reloc
, /* special_function */
1723 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1724 FALSE
, /* partial_inplace */
1726 0xfffc, /* dst_mask */
1727 FALSE
), /* pcrel_offset */
1729 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1730 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1731 16, /* rightshift */
1732 1, /* size (0 = byte, 1 = short, 2 = long) */
1734 FALSE
, /* pc_relative */
1736 complain_overflow_dont
, /* complain_on_overflow */
1737 ppc64_elf_unhandled_reloc
, /* special_function */
1738 "R_PPC64_GOT_DTPREL16_HI", /* name */
1739 FALSE
, /* partial_inplace */
1741 0xffff, /* dst_mask */
1742 FALSE
), /* pcrel_offset */
1744 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1745 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1746 16, /* rightshift */
1747 1, /* size (0 = byte, 1 = short, 2 = long) */
1749 FALSE
, /* pc_relative */
1751 complain_overflow_dont
, /* complain_on_overflow */
1752 ppc64_elf_unhandled_reloc
, /* special_function */
1753 "R_PPC64_GOT_DTPREL16_HA", /* name */
1754 FALSE
, /* partial_inplace */
1756 0xffff, /* dst_mask */
1757 FALSE
), /* pcrel_offset */
1759 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1760 offset to the entry relative to the TOC base (r2). */
1761 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1763 1, /* size (0 = byte, 1 = short, 2 = long) */
1765 FALSE
, /* pc_relative */
1767 complain_overflow_signed
, /* complain_on_overflow */
1768 ppc64_elf_unhandled_reloc
, /* special_function */
1769 "R_PPC64_GOT_TPREL16_DS", /* name */
1770 FALSE
, /* partial_inplace */
1772 0xfffc, /* dst_mask */
1773 FALSE
), /* pcrel_offset */
1775 /* Like GOT_TPREL16_DS, but no overflow. */
1776 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1778 1, /* size (0 = byte, 1 = short, 2 = long) */
1780 FALSE
, /* pc_relative */
1782 complain_overflow_dont
, /* complain_on_overflow */
1783 ppc64_elf_unhandled_reloc
, /* special_function */
1784 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1785 FALSE
, /* partial_inplace */
1787 0xfffc, /* dst_mask */
1788 FALSE
), /* pcrel_offset */
1790 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1791 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1792 16, /* rightshift */
1793 1, /* size (0 = byte, 1 = short, 2 = long) */
1795 FALSE
, /* pc_relative */
1797 complain_overflow_dont
, /* complain_on_overflow */
1798 ppc64_elf_unhandled_reloc
, /* special_function */
1799 "R_PPC64_GOT_TPREL16_HI", /* name */
1800 FALSE
, /* partial_inplace */
1802 0xffff, /* dst_mask */
1803 FALSE
), /* pcrel_offset */
1805 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1806 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1807 16, /* rightshift */
1808 1, /* size (0 = byte, 1 = short, 2 = long) */
1810 FALSE
, /* pc_relative */
1812 complain_overflow_dont
, /* complain_on_overflow */
1813 ppc64_elf_unhandled_reloc
, /* special_function */
1814 "R_PPC64_GOT_TPREL16_HA", /* name */
1815 FALSE
, /* partial_inplace */
1817 0xffff, /* dst_mask */
1818 FALSE
), /* pcrel_offset */
1820 /* GNU extension to record C++ vtable hierarchy. */
1821 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1823 0, /* size (0 = byte, 1 = short, 2 = long) */
1825 FALSE
, /* pc_relative */
1827 complain_overflow_dont
, /* complain_on_overflow */
1828 NULL
, /* special_function */
1829 "R_PPC64_GNU_VTINHERIT", /* name */
1830 FALSE
, /* partial_inplace */
1833 FALSE
), /* pcrel_offset */
1835 /* GNU extension to record C++ vtable member usage. */
1836 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1838 0, /* size (0 = byte, 1 = short, 2 = long) */
1840 FALSE
, /* pc_relative */
1842 complain_overflow_dont
, /* complain_on_overflow */
1843 NULL
, /* special_function */
1844 "R_PPC64_GNU_VTENTRY", /* name */
1845 FALSE
, /* partial_inplace */
1848 FALSE
), /* pcrel_offset */
1852 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1856 ppc_howto_init (void)
1858 unsigned int i
, type
;
1861 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1864 type
= ppc64_elf_howto_raw
[i
].type
;
1865 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1866 / sizeof (ppc64_elf_howto_table
[0])));
1867 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1871 static reloc_howto_type
*
1872 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1873 bfd_reloc_code_real_type code
)
1875 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1877 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1878 /* Initialize howto table if needed. */
1886 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1888 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1890 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1892 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1894 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1896 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1898 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1900 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1902 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1904 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1906 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1908 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1910 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1912 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1914 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1916 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1918 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1920 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1922 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1924 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1926 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1928 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1930 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1932 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1934 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1936 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1938 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1940 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1942 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1944 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1946 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1948 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1950 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1952 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1954 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1956 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1958 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1960 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1962 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1964 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1966 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1968 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1970 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1972 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1974 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1976 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1978 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1980 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1982 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1984 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1986 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1988 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1990 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1992 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1994 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1996 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1998 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2000 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2002 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2004 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2006 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2008 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2010 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2012 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2014 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2016 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2018 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2020 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2022 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2024 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2026 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2028 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2030 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2032 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2034 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2036 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2038 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2040 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2042 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2044 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2046 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2048 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2050 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2052 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2054 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2056 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2058 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2060 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2062 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2064 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2066 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2068 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2070 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2072 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2074 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2076 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2078 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2080 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2082 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2084 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2086 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2090 return ppc64_elf_howto_table
[r
];
2093 /* Set the howto pointer for a PowerPC ELF reloc. */
2096 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2097 Elf_Internal_Rela
*dst
)
2101 /* Initialize howto table if needed. */
2102 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2105 type
= ELF64_R_TYPE (dst
->r_info
);
2106 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
2107 / sizeof (ppc64_elf_howto_table
[0])));
2108 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2111 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2113 static bfd_reloc_status_type
2114 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2115 void *data
, asection
*input_section
,
2116 bfd
*output_bfd
, char **error_message
)
2118 /* If this is a relocatable link (output_bfd test tells us), just
2119 call the generic function. Any adjustment will be done at final
2121 if (output_bfd
!= NULL
)
2122 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2123 input_section
, output_bfd
, error_message
);
2125 /* Adjust the addend for sign extension of the low 16 bits.
2126 We won't actually be using the low 16 bits, so trashing them
2128 reloc_entry
->addend
+= 0x8000;
2129 return bfd_reloc_continue
;
2132 static bfd_reloc_status_type
2133 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2134 void *data
, asection
*input_section
,
2135 bfd
*output_bfd
, char **error_message
)
2138 enum elf_ppc64_reloc_type r_type
;
2139 bfd_size_type octets
;
2140 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2141 bfd_boolean is_power4
= FALSE
;
2143 /* If this is a relocatable link (output_bfd test tells us), just
2144 call the generic function. Any adjustment will be done at final
2146 if (output_bfd
!= NULL
)
2147 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2148 input_section
, output_bfd
, error_message
);
2150 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2151 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2152 insn
&= ~(0x01 << 21);
2153 r_type
= reloc_entry
->howto
->type
;
2154 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2155 || r_type
== R_PPC64_REL14_BRTAKEN
)
2156 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2160 /* Set 'a' bit. This is 0b00010 in BO field for branch
2161 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2162 for branch on CTR insns (BO == 1a00t or 1a01t). */
2163 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2165 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2168 return bfd_reloc_continue
;
2175 if (!bfd_is_com_section (symbol
->section
))
2176 target
= symbol
->value
;
2177 target
+= symbol
->section
->output_section
->vma
;
2178 target
+= symbol
->section
->output_offset
;
2179 target
+= reloc_entry
->addend
;
2181 from
= (reloc_entry
->address
2182 + input_section
->output_offset
2183 + input_section
->output_section
->vma
);
2185 /* Invert 'y' bit if not the default. */
2186 if ((bfd_signed_vma
) (target
- from
) < 0)
2189 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2190 return bfd_reloc_continue
;
2193 static bfd_reloc_status_type
2194 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2195 void *data
, asection
*input_section
,
2196 bfd
*output_bfd
, char **error_message
)
2198 /* If this is a relocatable link (output_bfd test tells us), just
2199 call the generic function. Any adjustment will be done at final
2201 if (output_bfd
!= NULL
)
2202 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2203 input_section
, output_bfd
, error_message
);
2205 /* Subtract the symbol section base address. */
2206 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2207 return bfd_reloc_continue
;
2210 static bfd_reloc_status_type
2211 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2212 void *data
, asection
*input_section
,
2213 bfd
*output_bfd
, char **error_message
)
2215 /* If this is a relocatable link (output_bfd test tells us), just
2216 call the generic function. Any adjustment will be done at final
2218 if (output_bfd
!= NULL
)
2219 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2220 input_section
, output_bfd
, error_message
);
2222 /* Subtract the symbol section base address. */
2223 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2225 /* Adjust the addend for sign extension of the low 16 bits. */
2226 reloc_entry
->addend
+= 0x8000;
2227 return bfd_reloc_continue
;
2230 static bfd_reloc_status_type
2231 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2232 void *data
, asection
*input_section
,
2233 bfd
*output_bfd
, char **error_message
)
2237 /* If this is a relocatable link (output_bfd test tells us), just
2238 call the generic function. Any adjustment will be done at final
2240 if (output_bfd
!= NULL
)
2241 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2242 input_section
, output_bfd
, error_message
);
2244 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2246 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2248 /* Subtract the TOC base address. */
2249 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2250 return bfd_reloc_continue
;
2253 static bfd_reloc_status_type
2254 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2255 void *data
, asection
*input_section
,
2256 bfd
*output_bfd
, char **error_message
)
2260 /* If this is a relocatable link (output_bfd test tells us), just
2261 call the generic function. Any adjustment will be done at final
2263 if (output_bfd
!= NULL
)
2264 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2265 input_section
, output_bfd
, error_message
);
2267 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2269 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2271 /* Subtract the TOC base address. */
2272 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2274 /* Adjust the addend for sign extension of the low 16 bits. */
2275 reloc_entry
->addend
+= 0x8000;
2276 return bfd_reloc_continue
;
2279 static bfd_reloc_status_type
2280 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2281 void *data
, asection
*input_section
,
2282 bfd
*output_bfd
, char **error_message
)
2285 bfd_size_type octets
;
2287 /* If this is a relocatable link (output_bfd test tells us), just
2288 call the generic function. Any adjustment will be done at final
2290 if (output_bfd
!= NULL
)
2291 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2292 input_section
, output_bfd
, error_message
);
2294 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2296 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2298 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2299 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2300 return bfd_reloc_ok
;
2303 static bfd_reloc_status_type
2304 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2305 void *data
, asection
*input_section
,
2306 bfd
*output_bfd
, char **error_message
)
2308 /* If this is a relocatable link (output_bfd test tells us), just
2309 call the generic function. Any adjustment will be done at final
2311 if (output_bfd
!= NULL
)
2312 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2313 input_section
, output_bfd
, error_message
);
2315 if (error_message
!= NULL
)
2317 static char buf
[60];
2318 sprintf (buf
, "generic linker can't handle %s",
2319 reloc_entry
->howto
->name
);
2320 *error_message
= buf
;
2322 return bfd_reloc_dangerous
;
2325 struct ppc64_elf_obj_tdata
2327 struct elf_obj_tdata elf
;
2329 /* Shortcuts to dynamic linker sections. */
2333 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2334 sections means we potentially need one of these for each input bfd. */
2336 bfd_signed_vma refcount
;
2341 #define ppc64_elf_tdata(bfd) \
2342 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2344 #define ppc64_tlsld_got(bfd) \
2345 (&ppc64_elf_tdata (bfd)->tlsld_got)
2347 /* Override the generic function because we store some extras. */
2350 ppc64_elf_mkobject (bfd
*abfd
)
2352 bfd_size_type amt
= sizeof (struct ppc64_elf_obj_tdata
);
2353 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2354 if (abfd
->tdata
.any
== NULL
)
2359 /* Fix bad default arch selected for a 64 bit input bfd when the
2360 default is 32 bit. */
2363 ppc64_elf_object_p (bfd
*abfd
)
2365 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2367 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2369 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2371 /* Relies on arch after 32 bit default being 64 bit default. */
2372 abfd
->arch_info
= abfd
->arch_info
->next
;
2373 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2379 /* Support for core dump NOTE sections. */
2382 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2384 size_t offset
, raw_size
;
2386 if (note
->descsz
!= 504)
2390 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2393 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2399 /* Make a ".reg/999" section. */
2400 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2401 raw_size
, note
->descpos
+ offset
);
2405 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2407 if (note
->descsz
!= 136)
2410 elf_tdata (abfd
)->core_program
2411 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2412 elf_tdata (abfd
)->core_command
2413 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2418 /* Merge backend specific data from an object file to the output
2419 object file when linking. */
2422 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2424 /* Check if we have the same endianess. */
2425 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2426 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2427 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2431 if (bfd_big_endian (ibfd
))
2432 msg
= _("%s: compiled for a big endian system "
2433 "and target is little endian");
2435 msg
= _("%s: compiled for a little endian system "
2436 "and target is big endian");
2438 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
2440 bfd_set_error (bfd_error_wrong_format
);
2447 /* Add extra PPC sections. */
2449 static struct bfd_elf_special_section
const ppc64_elf_special_sections
[]=
2451 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2452 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2453 { ".plt", 4, 0, SHT_NOBITS
, 0 },
2454 { ".toc", 4, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2455 { ".toc1", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2456 { ".tocbss", 7, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2457 { NULL
, 0, 0, 0, 0 }
2460 struct _ppc64_elf_section_data
2462 struct bfd_elf_section_data elf
;
2464 /* An array with one entry for each opd function descriptor. */
2467 /* Points to the function code section for local opd entries. */
2468 asection
**func_sec
;
2469 /* After editing .opd, adjust references to opd local syms. */
2473 /* An array for toc sections, indexed by offset/8.
2474 Specifies the relocation symbol index used at a given toc offset. */
2478 #define ppc64_elf_section_data(sec) \
2479 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2482 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2484 struct _ppc64_elf_section_data
*sdata
;
2485 bfd_size_type amt
= sizeof (*sdata
);
2487 sdata
= bfd_zalloc (abfd
, amt
);
2490 sec
->used_by_bfd
= sdata
;
2492 return _bfd_elf_new_section_hook (abfd
, sec
);
2495 /* The following functions are specific to the ELF linker, while
2496 functions above are used generally. Those named ppc64_elf_* are
2497 called by the main ELF linker code. They appear in this file more
2498 or less in the order in which they are called. eg.
2499 ppc64_elf_check_relocs is called early in the link process,
2500 ppc64_elf_finish_dynamic_sections is one of the last functions
2503 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2504 functions have both a function code symbol and a function descriptor
2505 symbol. A call to foo in a relocatable object file looks like:
2512 The function definition in another object file might be:
2516 . .quad .TOC.@tocbase
2522 When the linker resolves the call during a static link, the branch
2523 unsurprisingly just goes to .foo and the .opd information is unused.
2524 If the function definition is in a shared library, things are a little
2525 different: The call goes via a plt call stub, the opd information gets
2526 copied to the plt, and the linker patches the nop.
2534 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
2535 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
2536 . std 2,40(1) # this is the general idea
2544 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2546 The "reloc ()" notation is supposed to indicate that the linker emits
2547 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2550 What are the difficulties here? Well, firstly, the relocations
2551 examined by the linker in check_relocs are against the function code
2552 sym .foo, while the dynamic relocation in the plt is emitted against
2553 the function descriptor symbol, foo. Somewhere along the line, we need
2554 to carefully copy dynamic link information from one symbol to the other.
2555 Secondly, the generic part of the elf linker will make .foo a dynamic
2556 symbol as is normal for most other backends. We need foo dynamic
2557 instead, at least for an application final link. However, when
2558 creating a shared library containing foo, we need to have both symbols
2559 dynamic so that references to .foo are satisfied during the early
2560 stages of linking. Otherwise the linker might decide to pull in a
2561 definition from some other object, eg. a static library. */
2563 /* The linker needs to keep track of the number of relocs that it
2564 decides to copy as dynamic relocs in check_relocs for each symbol.
2565 This is so that it can later discard them if they are found to be
2566 unnecessary. We store the information in a field extending the
2567 regular ELF linker hash table. */
2569 struct ppc_dyn_relocs
2571 struct ppc_dyn_relocs
*next
;
2573 /* The input section of the reloc. */
2576 /* Total number of relocs copied for the input section. */
2577 bfd_size_type count
;
2579 /* Number of pc-relative relocs copied for the input section. */
2580 bfd_size_type pc_count
;
2583 /* Track GOT entries needed for a given symbol. We might need more
2584 than one got entry per symbol. */
2587 struct got_entry
*next
;
2589 /* The symbol addend that we'll be placing in the GOT. */
2592 /* Unlike other ELF targets, we use separate GOT entries for the same
2593 symbol referenced from different input files. This is to support
2594 automatic multiple TOC/GOT sections, where the TOC base can vary
2595 from one input file to another.
2597 Point to the BFD owning this GOT entry. */
2600 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2601 TLS_TPREL or TLS_DTPREL for tls entries. */
2604 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2607 bfd_signed_vma refcount
;
2612 /* The same for PLT. */
2615 struct plt_entry
*next
;
2621 bfd_signed_vma refcount
;
2626 /* Of those relocs that might be copied as dynamic relocs, this macro
2627 selects those that must be copied when linking a shared library,
2628 even when the symbol is local. */
2630 #define MUST_BE_DYN_RELOC(RTYPE) \
2631 ((RTYPE) != R_PPC64_REL32 \
2632 && (RTYPE) != R_PPC64_REL64 \
2633 && (RTYPE) != R_PPC64_REL30)
2635 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2636 copying dynamic variables from a shared lib into an app's dynbss
2637 section, and instead use a dynamic relocation to point into the
2638 shared lib. With code that gcc generates, it's vital that this be
2639 enabled; In the PowerPC64 ABI, the address of a function is actually
2640 the address of a function descriptor, which resides in the .opd
2641 section. gcc uses the descriptor directly rather than going via the
2642 GOT as some other ABI's do, which means that initialized function
2643 pointers must reference the descriptor. Thus, a function pointer
2644 initialized to the address of a function in a shared library will
2645 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2646 redefines the function descriptor symbol to point to the copy. This
2647 presents a problem as a plt entry for that function is also
2648 initialized from the function descriptor symbol and the copy reloc
2649 may not be initialized first. */
2650 #define ELIMINATE_COPY_RELOCS 1
2652 /* Section name for stubs is the associated section name plus this
2654 #define STUB_SUFFIX ".stub"
2657 ppc_stub_long_branch:
2658 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2659 destination, but a 24 bit branch in a stub section will reach.
2662 ppc_stub_plt_branch:
2663 Similar to the above, but a 24 bit branch in the stub section won't
2664 reach its destination.
2665 . addis %r12,%r2,xxx@toc@ha
2666 . ld %r11,xxx@toc@l(%r12)
2671 Used to call a function in a shared library.
2672 . addis %r12,%r2,xxx@toc@ha
2674 . ld %r11,xxx+0@toc@l(%r12)
2675 . ld %r2,xxx+8@toc@l(%r12)
2677 . ld %r11,xxx+16@toc@l(%r12)
2680 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2681 code to adjust the value and save r2 to support multiple toc sections.
2682 A ppc_stub_long_branch with an r2 offset looks like:
2684 . addis %r2,%r2,off@ha
2685 . addi %r2,%r2,off@l
2688 A ppc_stub_plt_branch with an r2 offset looks like:
2690 . addis %r12,%r2,xxx@toc@ha
2691 . ld %r11,xxx@toc@l(%r12)
2692 . addis %r2,%r2,off@ha
2693 . addi %r2,%r2,off@l
2698 enum ppc_stub_type
{
2700 ppc_stub_long_branch
,
2701 ppc_stub_long_branch_r2off
,
2702 ppc_stub_plt_branch
,
2703 ppc_stub_plt_branch_r2off
,
2707 struct ppc_stub_hash_entry
{
2709 /* Base hash table entry structure. */
2710 struct bfd_hash_entry root
;
2712 enum ppc_stub_type stub_type
;
2714 /* The stub section. */
2717 /* Offset within stub_sec of the beginning of this stub. */
2718 bfd_vma stub_offset
;
2720 /* Given the symbol's value and its section we can determine its final
2721 value when building the stubs (so the stub knows where to jump. */
2722 bfd_vma target_value
;
2723 asection
*target_section
;
2725 /* The symbol table entry, if any, that this was derived from. */
2726 struct ppc_link_hash_entry
*h
;
2728 /* And the reloc addend that this was derived from. */
2731 /* Where this stub is being called from, or, in the case of combined
2732 stub sections, the first input section in the group. */
2736 struct ppc_branch_hash_entry
{
2738 /* Base hash table entry structure. */
2739 struct bfd_hash_entry root
;
2741 /* Offset within .branch_lt. */
2742 unsigned int offset
;
2744 /* Generation marker. */
2748 struct ppc_link_hash_entry
2750 struct elf_link_hash_entry elf
;
2752 /* A pointer to the most recently used stub hash entry against this
2754 struct ppc_stub_hash_entry
*stub_cache
;
2756 /* Track dynamic relocs copied for this symbol. */
2757 struct ppc_dyn_relocs
*dyn_relocs
;
2759 /* Link between function code and descriptor symbols. */
2760 struct elf_link_hash_entry
*oh
;
2762 /* Flag function code and descriptor symbols. */
2763 unsigned int is_func
:1;
2764 unsigned int is_func_descriptor
:1;
2765 unsigned int is_entry
:1;
2767 /* Whether global opd sym has been adjusted or not. */
2768 unsigned int adjust_done
:1;
2770 /* Contexts in which symbol is used in the GOT (or TOC).
2771 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
2772 corresponding relocs are encountered during check_relocs.
2773 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2774 indicate the corresponding GOT entry type is not needed.
2775 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
2776 a TPREL one. We use a separate flag rather than setting TPREL
2777 just for convenience in distinguishing the two cases. */
2778 #define TLS_GD 1 /* GD reloc. */
2779 #define TLS_LD 2 /* LD reloc. */
2780 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2781 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2782 #define TLS_TLS 16 /* Any TLS reloc. */
2783 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
2784 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2788 /* ppc64 ELF linker hash table. */
2790 struct ppc_link_hash_table
2792 struct elf_link_hash_table elf
;
2794 /* The stub hash table. */
2795 struct bfd_hash_table stub_hash_table
;
2797 /* Another hash table for plt_branch stubs. */
2798 struct bfd_hash_table branch_hash_table
;
2800 /* Linker stub bfd. */
2803 /* Linker call-backs. */
2804 asection
* (*add_stub_section
) (const char *, asection
*);
2805 void (*layout_sections_again
) (void);
2807 /* Array to keep track of which stub sections have been created, and
2808 information on stub grouping. */
2810 /* This is the section to which stubs in the group will be attached. */
2812 /* The stub section. */
2814 /* Along with elf_gp, specifies the TOC pointer used in this group. */
2818 /* Support for multiple toc sections. */
2819 unsigned int no_multi_toc
;
2820 unsigned int multi_toc_needed
;
2822 /* Temp used when calculating TOC pointers. */
2825 /* Highest input section id. */
2828 /* Highest output section index. */
2831 /* List of input sections for each output section. */
2832 asection
**input_list
;
2834 /* Short-cuts to get to dynamic linker sections. */
2845 /* Shortcut to .__tls_get_addr. */
2846 struct elf_link_hash_entry
*tls_get_addr
;
2849 unsigned long stub_count
[ppc_stub_plt_call
];
2851 /* Set if we should emit symbols for stubs. */
2852 unsigned int emit_stub_syms
;
2855 unsigned int stub_error
;
2857 /* Flag set when small branches are detected. Used to
2858 select suitable defaults for the stub group size. */
2859 unsigned int has_14bit_branch
;
2861 /* Set if we detect a reference undefined weak symbol. */
2862 unsigned int have_undefweak
;
2864 /* Incremented every time we size stubs. */
2865 unsigned int stub_iteration
;
2867 /* Small local sym to section mapping cache. */
2868 struct sym_sec_cache sym_sec
;
2871 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2873 #define ppc_hash_table(p) \
2874 ((struct ppc_link_hash_table *) ((p)->hash))
2876 #define ppc_stub_hash_lookup(table, string, create, copy) \
2877 ((struct ppc_stub_hash_entry *) \
2878 bfd_hash_lookup ((table), (string), (create), (copy)))
2880 #define ppc_branch_hash_lookup(table, string, create, copy) \
2881 ((struct ppc_branch_hash_entry *) \
2882 bfd_hash_lookup ((table), (string), (create), (copy)))
2884 /* Create an entry in the stub hash table. */
2886 static struct bfd_hash_entry
*
2887 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2888 struct bfd_hash_table
*table
,
2891 /* Allocate the structure if it has not already been allocated by a
2895 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2900 /* Call the allocation method of the superclass. */
2901 entry
= bfd_hash_newfunc (entry
, table
, string
);
2904 struct ppc_stub_hash_entry
*eh
;
2906 /* Initialize the local fields. */
2907 eh
= (struct ppc_stub_hash_entry
*) entry
;
2908 eh
->stub_type
= ppc_stub_none
;
2909 eh
->stub_sec
= NULL
;
2910 eh
->stub_offset
= 0;
2911 eh
->target_value
= 0;
2912 eh
->target_section
= NULL
;
2920 /* Create an entry in the branch hash table. */
2922 static struct bfd_hash_entry
*
2923 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
2924 struct bfd_hash_table
*table
,
2927 /* Allocate the structure if it has not already been allocated by a
2931 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2936 /* Call the allocation method of the superclass. */
2937 entry
= bfd_hash_newfunc (entry
, table
, string
);
2940 struct ppc_branch_hash_entry
*eh
;
2942 /* Initialize the local fields. */
2943 eh
= (struct ppc_branch_hash_entry
*) entry
;
2951 /* Create an entry in a ppc64 ELF linker hash table. */
2953 static struct bfd_hash_entry
*
2954 link_hash_newfunc (struct bfd_hash_entry
*entry
,
2955 struct bfd_hash_table
*table
,
2958 /* Allocate the structure if it has not already been allocated by a
2962 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2967 /* Call the allocation method of the superclass. */
2968 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2971 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2973 eh
->stub_cache
= NULL
;
2974 eh
->dyn_relocs
= NULL
;
2977 eh
->is_func_descriptor
= 0;
2979 eh
->adjust_done
= 0;
2986 /* Create a ppc64 ELF linker hash table. */
2988 static struct bfd_link_hash_table
*
2989 ppc64_elf_link_hash_table_create (bfd
*abfd
)
2991 struct ppc_link_hash_table
*htab
;
2992 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2994 htab
= bfd_zmalloc (amt
);
2998 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
3004 /* Init the stub hash table too. */
3005 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
3008 /* And the branch hash table. */
3009 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
3012 /* Initializing two fields of the union is just cosmetic. We really
3013 only care about glist, but when compiled on a 32-bit host the
3014 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3015 debugger inspection of these fields look nicer. */
3016 htab
->elf
.init_refcount
.refcount
= 0;
3017 htab
->elf
.init_refcount
.glist
= NULL
;
3018 htab
->elf
.init_offset
.offset
= 0;
3019 htab
->elf
.init_offset
.glist
= NULL
;
3021 return &htab
->elf
.root
;
3024 /* Free the derived linker hash table. */
3027 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3029 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3031 bfd_hash_table_free (&ret
->stub_hash_table
);
3032 bfd_hash_table_free (&ret
->branch_hash_table
);
3033 _bfd_generic_link_hash_table_free (hash
);
3036 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3039 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3041 struct ppc_link_hash_table
*htab
;
3043 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3045 /* Always hook our dynamic sections into the first bfd, which is the
3046 linker created stub bfd. This ensures that the GOT header is at
3047 the start of the output TOC section. */
3048 htab
= ppc_hash_table (info
);
3049 htab
->stub_bfd
= abfd
;
3050 htab
->elf
.dynobj
= abfd
;
3053 /* Build a name for an entry in the stub hash table. */
3056 ppc_stub_name (const asection
*input_section
,
3057 const asection
*sym_sec
,
3058 const struct ppc_link_hash_entry
*h
,
3059 const Elf_Internal_Rela
*rel
)
3064 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3065 offsets from a sym as a branch target? In fact, we could
3066 probably assume the addend is always zero. */
3067 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3071 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3072 stub_name
= bfd_malloc (len
);
3073 if (stub_name
!= NULL
)
3075 sprintf (stub_name
, "%08x.%s+%x",
3076 input_section
->id
& 0xffffffff,
3077 h
->elf
.root
.root
.string
,
3078 (int) rel
->r_addend
& 0xffffffff);
3083 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3084 stub_name
= bfd_malloc (len
);
3085 if (stub_name
!= NULL
)
3087 sprintf (stub_name
, "%08x.%x:%x+%x",
3088 input_section
->id
& 0xffffffff,
3089 sym_sec
->id
& 0xffffffff,
3090 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3091 (int) rel
->r_addend
& 0xffffffff);
3097 /* Look up an entry in the stub hash. Stub entries are cached because
3098 creating the stub name takes a bit of time. */
3100 static struct ppc_stub_hash_entry
*
3101 ppc_get_stub_entry (const asection
*input_section
,
3102 const asection
*sym_sec
,
3103 struct elf_link_hash_entry
*hash
,
3104 const Elf_Internal_Rela
*rel
,
3105 struct ppc_link_hash_table
*htab
)
3107 struct ppc_stub_hash_entry
*stub_entry
;
3108 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
3109 const asection
*id_sec
;
3111 /* If this input section is part of a group of sections sharing one
3112 stub section, then use the id of the first section in the group.
3113 Stub names need to include a section id, as there may well be
3114 more than one stub used to reach say, printf, and we need to
3115 distinguish between them. */
3116 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3118 if (h
!= NULL
&& h
->stub_cache
!= NULL
3119 && h
->stub_cache
->h
== h
3120 && h
->stub_cache
->id_sec
== id_sec
)
3122 stub_entry
= h
->stub_cache
;
3128 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3129 if (stub_name
== NULL
)
3132 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3133 stub_name
, FALSE
, FALSE
);
3135 h
->stub_cache
= stub_entry
;
3143 /* Add a new stub entry to the stub hash. Not all fields of the new
3144 stub entry are initialised. */
3146 static struct ppc_stub_hash_entry
*
3147 ppc_add_stub (const char *stub_name
,
3149 struct ppc_link_hash_table
*htab
)
3153 struct ppc_stub_hash_entry
*stub_entry
;
3155 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3156 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3157 if (stub_sec
== NULL
)
3159 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3160 if (stub_sec
== NULL
)
3166 namelen
= strlen (link_sec
->name
);
3167 len
= namelen
+ sizeof (STUB_SUFFIX
);
3168 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3172 memcpy (s_name
, link_sec
->name
, namelen
);
3173 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3174 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3175 if (stub_sec
== NULL
)
3177 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3179 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3182 /* Enter this entry into the linker stub hash table. */
3183 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3185 if (stub_entry
== NULL
)
3187 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3188 bfd_archive_filename (section
->owner
),
3193 stub_entry
->stub_sec
= stub_sec
;
3194 stub_entry
->stub_offset
= 0;
3195 stub_entry
->id_sec
= link_sec
;
3199 /* Create sections for linker generated code. */
3202 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3204 struct ppc_link_hash_table
*htab
;
3207 htab
= ppc_hash_table (info
);
3209 /* Create .sfpr for code to save and restore fp regs. */
3210 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3211 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3212 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
3213 if (htab
->sfpr
== NULL
3214 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
3215 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3218 /* Create .glink for lazy dynamic linking support. */
3219 htab
->glink
= bfd_make_section_anyway (dynobj
, ".glink");
3220 if (htab
->glink
== NULL
3221 || ! bfd_set_section_flags (dynobj
, htab
->glink
, flags
)
3222 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 2))
3225 /* Create .branch_lt for plt_branch stubs. */
3226 flags
= (SEC_ALLOC
| SEC_LOAD
3227 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3228 htab
->brlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
3229 if (htab
->brlt
== NULL
3230 || ! bfd_set_section_flags (dynobj
, htab
->brlt
, flags
)
3231 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3236 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3237 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3238 htab
->relbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
3240 || ! bfd_set_section_flags (dynobj
, htab
->relbrlt
, flags
)
3241 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3247 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3248 not already done. */
3251 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3253 asection
*got
, *relgot
;
3255 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3259 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3262 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
3267 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3268 | SEC_LINKER_CREATED
);
3270 got
= bfd_make_section (abfd
, ".got");
3272 || !bfd_set_section_flags (abfd
, got
, flags
)
3273 || !bfd_set_section_alignment (abfd
, got
, 3))
3276 relgot
= bfd_make_section (abfd
, ".rela.got");
3278 || ! bfd_set_section_flags (abfd
, relgot
, flags
| SEC_READONLY
)
3279 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
3282 ppc64_elf_tdata (abfd
)->got
= got
;
3283 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3287 /* Create the dynamic sections, and set up shortcuts. */
3290 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3292 struct ppc_link_hash_table
*htab
;
3294 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3297 htab
= ppc_hash_table (info
);
3299 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
3300 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
3301 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3302 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3304 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3306 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
3307 || (!info
->shared
&& !htab
->relbss
))
3313 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3316 ppc64_elf_copy_indirect_symbol
3317 (const struct elf_backend_data
*bed ATTRIBUTE_UNUSED
,
3318 struct elf_link_hash_entry
*dir
,
3319 struct elf_link_hash_entry
*ind
)
3321 struct ppc_link_hash_entry
*edir
, *eind
;
3324 edir
= (struct ppc_link_hash_entry
*) dir
;
3325 eind
= (struct ppc_link_hash_entry
*) ind
;
3327 /* Copy over any dynamic relocs we may have on the indirect sym. */
3328 if (eind
->dyn_relocs
!= NULL
)
3330 if (edir
->dyn_relocs
!= NULL
)
3332 struct ppc_dyn_relocs
**pp
;
3333 struct ppc_dyn_relocs
*p
;
3335 if (eind
->elf
.root
.type
== bfd_link_hash_indirect
)
3338 /* Add reloc counts against the weak sym to the strong sym
3339 list. Merge any entries against the same section. */
3340 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3342 struct ppc_dyn_relocs
*q
;
3344 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3345 if (q
->sec
== p
->sec
)
3347 q
->pc_count
+= p
->pc_count
;
3348 q
->count
+= p
->count
;
3355 *pp
= edir
->dyn_relocs
;
3358 edir
->dyn_relocs
= eind
->dyn_relocs
;
3359 eind
->dyn_relocs
= NULL
;
3362 edir
->is_func
|= eind
->is_func
;
3363 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3364 edir
->is_entry
|= eind
->is_entry
;
3365 edir
->tls_mask
|= eind
->tls_mask
;
3367 mask
= (ELF_LINK_HASH_REF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
3368 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
| ELF_LINK_NON_GOT_REF
3369 | ELF_LINK_HASH_NEEDS_PLT
);
3370 /* If called to transfer flags for a weakdef during processing
3371 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
3372 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3373 if (ELIMINATE_COPY_RELOCS
3374 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3375 && (edir
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
3376 mask
&= ~ELF_LINK_NON_GOT_REF
;
3378 edir
->elf
.elf_link_hash_flags
|= eind
->elf
.elf_link_hash_flags
& mask
;
3380 /* If we were called to copy over info for a weak sym, that's all. */
3381 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3384 /* Copy over got entries that we may have already seen to the
3385 symbol which just became indirect. */
3386 if (eind
->elf
.got
.glist
!= NULL
)
3388 if (edir
->elf
.got
.glist
!= NULL
)
3390 struct got_entry
**entp
;
3391 struct got_entry
*ent
;
3393 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3395 struct got_entry
*dent
;
3397 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3398 if (dent
->addend
== ent
->addend
3399 && dent
->owner
== ent
->owner
3400 && dent
->tls_type
== ent
->tls_type
)
3402 dent
->got
.refcount
+= ent
->got
.refcount
;
3409 *entp
= edir
->elf
.got
.glist
;
3412 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3413 eind
->elf
.got
.glist
= NULL
;
3416 /* And plt entries. */
3417 if (eind
->elf
.plt
.plist
!= NULL
)
3419 if (edir
->elf
.plt
.plist
!= NULL
)
3421 struct plt_entry
**entp
;
3422 struct plt_entry
*ent
;
3424 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3426 struct plt_entry
*dent
;
3428 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3429 if (dent
->addend
== ent
->addend
)
3431 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3438 *entp
= edir
->elf
.plt
.plist
;
3441 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3442 eind
->elf
.plt
.plist
= NULL
;
3445 if (edir
->elf
.dynindx
== -1)
3447 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3448 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3449 eind
->elf
.dynindx
= -1;
3450 eind
->elf
.dynstr_index
= 0;
3453 BFD_ASSERT (eind
->elf
.dynindx
== -1);
3456 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
3457 symbols undefined on the command-line. */
3460 ppc64_elf_mark_entry_syms (struct bfd_link_info
*info
)
3462 struct ppc_link_hash_table
*htab
;
3463 struct bfd_sym_chain
*sym
;
3465 htab
= ppc_hash_table (info
);
3466 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
3468 struct elf_link_hash_entry
*h
;
3470 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
3472 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
3478 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
3479 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
3481 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
3482 char *local_got_tls_masks
;
3484 if (local_got_ents
== NULL
)
3486 bfd_size_type size
= symtab_hdr
->sh_info
;
3488 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
3489 local_got_ents
= bfd_zalloc (abfd
, size
);
3490 if (local_got_ents
== NULL
)
3492 elf_local_got_ents (abfd
) = local_got_ents
;
3495 if ((tls_type
& TLS_EXPLICIT
) == 0)
3497 struct got_entry
*ent
;
3499 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
3500 if (ent
->addend
== r_addend
3501 && ent
->owner
== abfd
3502 && ent
->tls_type
== tls_type
)
3506 bfd_size_type amt
= sizeof (*ent
);
3507 ent
= bfd_alloc (abfd
, amt
);
3510 ent
->next
= local_got_ents
[r_symndx
];
3511 ent
->addend
= r_addend
;
3513 ent
->tls_type
= tls_type
;
3514 ent
->got
.refcount
= 0;
3515 local_got_ents
[r_symndx
] = ent
;
3517 ent
->got
.refcount
+= 1;
3520 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
3521 local_got_tls_masks
[r_symndx
] |= tls_type
;
3526 update_plt_info (bfd
*abfd
, struct ppc_link_hash_entry
*eh
, bfd_vma addend
)
3528 struct plt_entry
*ent
;
3530 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
3531 if (ent
->addend
== addend
)
3535 bfd_size_type amt
= sizeof (*ent
);
3536 ent
= bfd_alloc (abfd
, amt
);
3539 ent
->next
= eh
->elf
.plt
.plist
;
3540 ent
->addend
= addend
;
3541 ent
->plt
.refcount
= 0;
3542 eh
->elf
.plt
.plist
= ent
;
3544 ent
->plt
.refcount
+= 1;
3545 eh
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3550 /* Find the function descriptor hash entry from the given function code
3551 hash entry FH. Link the entries via their OH fields. */
3552 static struct ppc_link_hash_entry
*
3553 get_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3555 struct ppc_link_hash_entry
*fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
3559 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3561 fdh
= (struct ppc_link_hash_entry
*)
3562 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3565 fdh
->is_func_descriptor
= 1;
3575 /* Look through the relocs for a section during the first phase, and
3576 calculate needed space in the global offset table, procedure
3577 linkage table, and dynamic reloc sections. */
3580 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
3581 asection
*sec
, const Elf_Internal_Rela
*relocs
)
3583 struct ppc_link_hash_table
*htab
;
3584 Elf_Internal_Shdr
*symtab_hdr
;
3585 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3586 const Elf_Internal_Rela
*rel
;
3587 const Elf_Internal_Rela
*rel_end
;
3589 asection
**opd_sym_map
;
3591 if (info
->relocatable
)
3594 /* Don't do anything special with non-loaded, non-alloced sections.
3595 In particular, any relocs in such sections should not affect GOT
3596 and PLT reference counting (ie. we don't allow them to create GOT
3597 or PLT entries), there's no possibility or desire to optimize TLS
3598 relocs, and there's not much point in propagating relocs to shared
3599 libs that the dynamic linker won't relocate. */
3600 if ((sec
->flags
& SEC_ALLOC
) == 0)
3603 htab
= ppc_hash_table (info
);
3604 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3606 sym_hashes
= elf_sym_hashes (abfd
);
3607 sym_hashes_end
= (sym_hashes
3608 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
3609 - symtab_hdr
->sh_info
);
3613 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
3615 /* Garbage collection needs some extra help with .opd sections.
3616 We don't want to necessarily keep everything referenced by
3617 relocs in .opd, as that would keep all functions. Instead,
3618 if we reference an .opd symbol (a function descriptor), we
3619 want to keep the function code symbol's section. This is
3620 easy for global symbols, but for local syms we need to keep
3621 information about the associated function section. Later, if
3622 edit_opd deletes entries, we'll use this array to adjust
3623 local syms in .opd. */
3625 asection
*func_section
;
3630 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
3631 opd_sym_map
= bfd_zalloc (abfd
, amt
);
3632 if (opd_sym_map
== NULL
)
3634 ppc64_elf_section_data (sec
)->opd
.func_sec
= opd_sym_map
;
3637 if (htab
->sfpr
== NULL
3638 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
3641 rel_end
= relocs
+ sec
->reloc_count
;
3642 for (rel
= relocs
; rel
< rel_end
; rel
++)
3644 unsigned long r_symndx
;
3645 struct elf_link_hash_entry
*h
;
3646 enum elf_ppc64_reloc_type r_type
;
3649 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3650 if (r_symndx
< symtab_hdr
->sh_info
)
3653 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3655 r_type
= ELF64_R_TYPE (rel
->r_info
);
3658 case R_PPC64_GOT_TLSLD16
:
3659 case R_PPC64_GOT_TLSLD16_LO
:
3660 case R_PPC64_GOT_TLSLD16_HI
:
3661 case R_PPC64_GOT_TLSLD16_HA
:
3662 ppc64_tlsld_got (abfd
)->refcount
+= 1;
3663 tls_type
= TLS_TLS
| TLS_LD
;
3666 case R_PPC64_GOT_TLSGD16
:
3667 case R_PPC64_GOT_TLSGD16_LO
:
3668 case R_PPC64_GOT_TLSGD16_HI
:
3669 case R_PPC64_GOT_TLSGD16_HA
:
3670 tls_type
= TLS_TLS
| TLS_GD
;
3673 case R_PPC64_GOT_TPREL16_DS
:
3674 case R_PPC64_GOT_TPREL16_LO_DS
:
3675 case R_PPC64_GOT_TPREL16_HI
:
3676 case R_PPC64_GOT_TPREL16_HA
:
3678 info
->flags
|= DF_STATIC_TLS
;
3679 tls_type
= TLS_TLS
| TLS_TPREL
;
3682 case R_PPC64_GOT_DTPREL16_DS
:
3683 case R_PPC64_GOT_DTPREL16_LO_DS
:
3684 case R_PPC64_GOT_DTPREL16_HI
:
3685 case R_PPC64_GOT_DTPREL16_HA
:
3686 tls_type
= TLS_TLS
| TLS_DTPREL
;
3688 sec
->has_tls_reloc
= 1;
3692 case R_PPC64_GOT16_DS
:
3693 case R_PPC64_GOT16_HA
:
3694 case R_PPC64_GOT16_HI
:
3695 case R_PPC64_GOT16_LO
:
3696 case R_PPC64_GOT16_LO_DS
:
3697 /* This symbol requires a global offset table entry. */
3698 sec
->has_gp_reloc
= 1;
3699 if (ppc64_elf_tdata (abfd
)->got
== NULL
3700 && !create_got_section (abfd
, info
))
3705 struct ppc_link_hash_entry
*eh
;
3706 struct got_entry
*ent
;
3708 eh
= (struct ppc_link_hash_entry
*) h
;
3709 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
3710 if (ent
->addend
== rel
->r_addend
3711 && ent
->owner
== abfd
3712 && ent
->tls_type
== tls_type
)
3716 bfd_size_type amt
= sizeof (*ent
);
3717 ent
= bfd_alloc (abfd
, amt
);
3720 ent
->next
= eh
->elf
.got
.glist
;
3721 ent
->addend
= rel
->r_addend
;
3723 ent
->tls_type
= tls_type
;
3724 ent
->got
.refcount
= 0;
3725 eh
->elf
.got
.glist
= ent
;
3727 ent
->got
.refcount
+= 1;
3728 eh
->tls_mask
|= tls_type
;
3731 /* This is a global offset table entry for a local symbol. */
3732 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3733 rel
->r_addend
, tls_type
))
3737 case R_PPC64_PLT16_HA
:
3738 case R_PPC64_PLT16_HI
:
3739 case R_PPC64_PLT16_LO
:
3742 /* This symbol requires a procedure linkage table entry. We
3743 actually build the entry in adjust_dynamic_symbol,
3744 because this might be a case of linking PIC code without
3745 linking in any dynamic objects, in which case we don't
3746 need to generate a procedure linkage table after all. */
3749 /* It does not make sense to have a procedure linkage
3750 table entry for a local symbol. */
3751 bfd_set_error (bfd_error_bad_value
);
3755 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3760 /* The following relocations don't need to propagate the
3761 relocation if linking a shared object since they are
3762 section relative. */
3763 case R_PPC64_SECTOFF
:
3764 case R_PPC64_SECTOFF_LO
:
3765 case R_PPC64_SECTOFF_HI
:
3766 case R_PPC64_SECTOFF_HA
:
3767 case R_PPC64_SECTOFF_DS
:
3768 case R_PPC64_SECTOFF_LO_DS
:
3769 case R_PPC64_DTPREL16
:
3770 case R_PPC64_DTPREL16_LO
:
3771 case R_PPC64_DTPREL16_HI
:
3772 case R_PPC64_DTPREL16_HA
:
3773 case R_PPC64_DTPREL16_DS
:
3774 case R_PPC64_DTPREL16_LO_DS
:
3775 case R_PPC64_DTPREL16_HIGHER
:
3776 case R_PPC64_DTPREL16_HIGHERA
:
3777 case R_PPC64_DTPREL16_HIGHEST
:
3778 case R_PPC64_DTPREL16_HIGHESTA
:
3783 case R_PPC64_TOC16_LO
:
3784 case R_PPC64_TOC16_HI
:
3785 case R_PPC64_TOC16_HA
:
3786 case R_PPC64_TOC16_DS
:
3787 case R_PPC64_TOC16_LO_DS
:
3788 sec
->has_gp_reloc
= 1;
3791 /* This relocation describes the C++ object vtable hierarchy.
3792 Reconstruct it for later use during GC. */
3793 case R_PPC64_GNU_VTINHERIT
:
3794 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3798 /* This relocation describes which C++ vtable entries are actually
3799 used. Record for later use during GC. */
3800 case R_PPC64_GNU_VTENTRY
:
3801 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3806 case R_PPC64_REL14_BRTAKEN
:
3807 case R_PPC64_REL14_BRNTAKEN
:
3808 htab
->has_14bit_branch
= 1;
3813 && h
->root
.root
.string
[0] == '.'
3814 && h
->root
.root
.string
[1] != 0)
3816 /* We may need a .plt entry if the function this reloc
3817 refers to is in a shared lib. */
3818 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3821 if (h
== htab
->tls_get_addr
)
3822 sec
->has_tls_reloc
= 1;
3823 else if ((strncmp (h
->root
.root
.string
, ".__tls_get_addr", 15)
3825 && (h
->root
.root
.string
[15] == 0
3826 || h
->root
.root
.string
[15] == '@'))
3828 htab
->tls_get_addr
= h
;
3829 sec
->has_tls_reloc
= 1;
3834 case R_PPC64_TPREL64
:
3835 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
3837 info
->flags
|= DF_STATIC_TLS
;
3840 case R_PPC64_DTPMOD64
:
3841 if (rel
+ 1 < rel_end
3842 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
3843 && rel
[1].r_offset
== rel
->r_offset
+ 8)
3844 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
3846 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
3849 case R_PPC64_DTPREL64
:
3850 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
3852 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
3853 && rel
[-1].r_offset
== rel
->r_offset
- 8)
3854 /* This is the second reloc of a dtpmod, dtprel pair.
3855 Don't mark with TLS_DTPREL. */
3859 sec
->has_tls_reloc
= 1;
3862 struct ppc_link_hash_entry
*eh
;
3863 eh
= (struct ppc_link_hash_entry
*) h
;
3864 eh
->tls_mask
|= tls_type
;
3867 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3868 rel
->r_addend
, tls_type
))
3871 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3873 /* One extra to simplify get_tls_mask. */
3874 bfd_size_type amt
= sec
->_raw_size
* sizeof (unsigned) / 8 + 1;
3875 ppc64_elf_section_data (sec
)->t_symndx
= bfd_zalloc (abfd
, amt
);
3876 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3879 BFD_ASSERT (rel
->r_offset
% 8 == 0);
3880 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
3882 /* Mark the second slot of a GD or LD entry.
3883 -1 to indicate GD and -2 to indicate LD. */
3884 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
3885 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
3886 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
3887 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
3890 case R_PPC64_TPREL16
:
3891 case R_PPC64_TPREL16_LO
:
3892 case R_PPC64_TPREL16_HI
:
3893 case R_PPC64_TPREL16_HA
:
3894 case R_PPC64_TPREL16_DS
:
3895 case R_PPC64_TPREL16_LO_DS
:
3896 case R_PPC64_TPREL16_HIGHER
:
3897 case R_PPC64_TPREL16_HIGHERA
:
3898 case R_PPC64_TPREL16_HIGHEST
:
3899 case R_PPC64_TPREL16_HIGHESTA
:
3902 info
->flags
|= DF_STATIC_TLS
;
3907 case R_PPC64_ADDR64
:
3908 if (opd_sym_map
!= NULL
3910 && h
->root
.root
.string
[0] == '.'
3911 && h
->root
.root
.string
[1] != 0)
3912 get_fdh ((struct ppc_link_hash_entry
*) h
, htab
);
3914 if (opd_sym_map
!= NULL
3916 && rel
+ 1 < rel_end
3917 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
3921 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
3926 opd_sym_map
[rel
->r_offset
/ 24] = s
;
3933 case R_PPC64_ADDR14
:
3934 case R_PPC64_ADDR14_BRNTAKEN
:
3935 case R_PPC64_ADDR14_BRTAKEN
:
3936 case R_PPC64_ADDR16
:
3937 case R_PPC64_ADDR16_DS
:
3938 case R_PPC64_ADDR16_HA
:
3939 case R_PPC64_ADDR16_HI
:
3940 case R_PPC64_ADDR16_HIGHER
:
3941 case R_PPC64_ADDR16_HIGHERA
:
3942 case R_PPC64_ADDR16_HIGHEST
:
3943 case R_PPC64_ADDR16_HIGHESTA
:
3944 case R_PPC64_ADDR16_LO
:
3945 case R_PPC64_ADDR16_LO_DS
:
3946 case R_PPC64_ADDR24
:
3947 case R_PPC64_ADDR32
:
3948 case R_PPC64_UADDR16
:
3949 case R_PPC64_UADDR32
:
3950 case R_PPC64_UADDR64
:
3952 if (h
!= NULL
&& !info
->shared
)
3953 /* We may need a copy reloc. */
3954 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3956 /* Don't propagate .opd relocs. */
3957 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
3960 /* If we are creating a shared library, and this is a reloc
3961 against a global symbol, or a non PC relative reloc
3962 against a local symbol, then we need to copy the reloc
3963 into the shared library. However, if we are linking with
3964 -Bsymbolic, we do not need to copy a reloc against a
3965 global symbol which is defined in an object we are
3966 including in the link (i.e., DEF_REGULAR is set). At
3967 this point we have not seen all the input files, so it is
3968 possible that DEF_REGULAR is not set now but will be set
3969 later (it is never cleared). In case of a weak definition,
3970 DEF_REGULAR may be cleared later by a strong definition in
3971 a shared library. We account for that possibility below by
3972 storing information in the dyn_relocs field of the hash
3973 table entry. A similar situation occurs when creating
3974 shared libraries and symbol visibility changes render the
3977 If on the other hand, we are creating an executable, we
3978 may need to keep relocations for symbols satisfied by a
3979 dynamic library if we manage to avoid copy relocs for the
3983 && (MUST_BE_DYN_RELOC (r_type
)
3985 && (! info
->symbolic
3986 || h
->root
.type
== bfd_link_hash_defweak
3987 || (h
->elf_link_hash_flags
3988 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3989 || (ELIMINATE_COPY_RELOCS
3992 && (h
->root
.type
== bfd_link_hash_defweak
3993 || (h
->elf_link_hash_flags
3994 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3996 struct ppc_dyn_relocs
*p
;
3997 struct ppc_dyn_relocs
**head
;
3999 /* We must copy these reloc types into the output file.
4000 Create a reloc section in dynobj and make room for
4007 name
= (bfd_elf_string_from_elf_section
4009 elf_elfheader (abfd
)->e_shstrndx
,
4010 elf_section_data (sec
)->rel_hdr
.sh_name
));
4014 if (strncmp (name
, ".rela", 5) != 0
4015 || strcmp (bfd_get_section_name (abfd
, sec
),
4018 (*_bfd_error_handler
)
4019 (_("%s: bad relocation section name `%s\'"),
4020 bfd_archive_filename (abfd
), name
);
4021 bfd_set_error (bfd_error_bad_value
);
4024 dynobj
= htab
->elf
.dynobj
;
4025 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4030 sreloc
= bfd_make_section (dynobj
, name
);
4031 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4032 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4033 if ((sec
->flags
& SEC_ALLOC
) != 0)
4034 flags
|= SEC_ALLOC
| SEC_LOAD
;
4036 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
4037 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
4040 elf_section_data (sec
)->sreloc
= sreloc
;
4043 /* If this is a global symbol, we count the number of
4044 relocations we need for this symbol. */
4047 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4051 /* Track dynamic relocs needed for local syms too.
4052 We really need local syms available to do this
4056 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4061 head
= ((struct ppc_dyn_relocs
**)
4062 &elf_section_data (s
)->local_dynrel
);
4066 if (p
== NULL
|| p
->sec
!= sec
)
4068 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4079 if (!MUST_BE_DYN_RELOC (r_type
))
4092 /* Return the section that should be marked against GC for a given
4096 ppc64_elf_gc_mark_hook (asection
*sec
,
4097 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4098 Elf_Internal_Rela
*rel
,
4099 struct elf_link_hash_entry
*h
,
4100 Elf_Internal_Sym
*sym
)
4102 asection
*rsec
= NULL
;
4106 enum elf_ppc64_reloc_type r_type
;
4107 struct ppc_link_hash_entry
*fdh
;
4109 r_type
= ELF64_R_TYPE (rel
->r_info
);
4112 case R_PPC64_GNU_VTINHERIT
:
4113 case R_PPC64_GNU_VTENTRY
:
4117 switch (h
->root
.type
)
4119 case bfd_link_hash_defined
:
4120 case bfd_link_hash_defweak
:
4121 fdh
= (struct ppc_link_hash_entry
*) h
;
4123 /* Function descriptor syms cause the associated
4124 function code sym section to be marked. */
4125 if (fdh
->is_func_descriptor
)
4126 rsec
= fdh
->oh
->root
.u
.def
.section
;
4128 /* Function entry syms return NULL if they are in .opd
4129 and are not ._start (or others undefined on the ld
4130 command line). Thus we avoid marking all function
4131 sections, as all functions are referenced in .opd. */
4132 else if ((fdh
->oh
!= NULL
4133 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
4134 || ppc64_elf_section_data (sec
)->opd
.func_sec
== NULL
)
4135 rsec
= h
->root
.u
.def
.section
;
4138 case bfd_link_hash_common
:
4139 rsec
= h
->root
.u
.c
.p
->section
;
4149 asection
**opd_sym_section
;
4151 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4152 opd_sym_section
= ppc64_elf_section_data (rsec
)->opd
.func_sec
;
4153 if (opd_sym_section
!= NULL
)
4154 rsec
= opd_sym_section
[sym
->st_value
/ 24];
4155 else if (ppc64_elf_section_data (sec
)->opd
.func_sec
!= NULL
)
4162 /* Update the .got, .plt. and dynamic reloc reference counts for the
4163 section being removed. */
4166 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
4167 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4169 struct ppc_link_hash_table
*htab
;
4170 Elf_Internal_Shdr
*symtab_hdr
;
4171 struct elf_link_hash_entry
**sym_hashes
;
4172 struct got_entry
**local_got_ents
;
4173 const Elf_Internal_Rela
*rel
, *relend
;
4175 if ((sec
->flags
& SEC_ALLOC
) == 0)
4178 elf_section_data (sec
)->local_dynrel
= NULL
;
4180 htab
= ppc_hash_table (info
);
4181 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4182 sym_hashes
= elf_sym_hashes (abfd
);
4183 local_got_ents
= elf_local_got_ents (abfd
);
4185 relend
= relocs
+ sec
->reloc_count
;
4186 for (rel
= relocs
; rel
< relend
; rel
++)
4188 unsigned long r_symndx
;
4189 enum elf_ppc64_reloc_type r_type
;
4190 struct elf_link_hash_entry
*h
= NULL
;
4193 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4194 r_type
= ELF64_R_TYPE (rel
->r_info
);
4195 if (r_symndx
>= symtab_hdr
->sh_info
)
4197 struct ppc_link_hash_entry
*eh
;
4198 struct ppc_dyn_relocs
**pp
;
4199 struct ppc_dyn_relocs
*p
;
4201 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4202 eh
= (struct ppc_link_hash_entry
*) h
;
4204 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4207 /* Everything must go for SEC. */
4215 case R_PPC64_GOT_TLSLD16
:
4216 case R_PPC64_GOT_TLSLD16_LO
:
4217 case R_PPC64_GOT_TLSLD16_HI
:
4218 case R_PPC64_GOT_TLSLD16_HA
:
4219 ppc64_tlsld_got (abfd
)->refcount
-= 1;
4220 tls_type
= TLS_TLS
| TLS_LD
;
4223 case R_PPC64_GOT_TLSGD16
:
4224 case R_PPC64_GOT_TLSGD16_LO
:
4225 case R_PPC64_GOT_TLSGD16_HI
:
4226 case R_PPC64_GOT_TLSGD16_HA
:
4227 tls_type
= TLS_TLS
| TLS_GD
;
4230 case R_PPC64_GOT_TPREL16_DS
:
4231 case R_PPC64_GOT_TPREL16_LO_DS
:
4232 case R_PPC64_GOT_TPREL16_HI
:
4233 case R_PPC64_GOT_TPREL16_HA
:
4234 tls_type
= TLS_TLS
| TLS_TPREL
;
4237 case R_PPC64_GOT_DTPREL16_DS
:
4238 case R_PPC64_GOT_DTPREL16_LO_DS
:
4239 case R_PPC64_GOT_DTPREL16_HI
:
4240 case R_PPC64_GOT_DTPREL16_HA
:
4241 tls_type
= TLS_TLS
| TLS_DTPREL
;
4245 case R_PPC64_GOT16_DS
:
4246 case R_PPC64_GOT16_HA
:
4247 case R_PPC64_GOT16_HI
:
4248 case R_PPC64_GOT16_LO
:
4249 case R_PPC64_GOT16_LO_DS
:
4252 struct got_entry
*ent
;
4257 ent
= local_got_ents
[r_symndx
];
4259 for (; ent
!= NULL
; ent
= ent
->next
)
4260 if (ent
->addend
== rel
->r_addend
4261 && ent
->owner
== abfd
4262 && ent
->tls_type
== tls_type
)
4266 if (ent
->got
.refcount
> 0)
4267 ent
->got
.refcount
-= 1;
4271 case R_PPC64_PLT16_HA
:
4272 case R_PPC64_PLT16_HI
:
4273 case R_PPC64_PLT16_LO
:
4277 case R_PPC64_REL14_BRNTAKEN
:
4278 case R_PPC64_REL14_BRTAKEN
:
4282 struct plt_entry
*ent
;
4284 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4285 if (ent
->addend
== rel
->r_addend
)
4289 if (ent
->plt
.refcount
> 0)
4290 ent
->plt
.refcount
-= 1;
4301 /* Called via elf_link_hash_traverse to transfer dynamic linking
4302 information on function code symbol entries to their corresponding
4303 function descriptor symbol entries. */
4305 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
4307 struct bfd_link_info
*info
;
4308 struct ppc_link_hash_table
*htab
;
4309 struct plt_entry
*ent
;
4310 struct ppc_link_hash_entry
*fh
;
4311 struct ppc_link_hash_entry
*fdh
;
4312 bfd_boolean force_local
;
4314 fh
= (struct ppc_link_hash_entry
*) h
;
4315 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
4318 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
4319 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
4322 htab
= ppc_hash_table (info
);
4324 /* If this is a function code symbol, transfer dynamic linking
4325 information to the function descriptor symbol. */
4329 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4330 && (fh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
4331 htab
->have_undefweak
= TRUE
;
4333 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4334 if (ent
->plt
.refcount
> 0)
4337 || fh
->elf
.root
.root
.string
[0] != '.'
4338 || fh
->elf
.root
.root
.string
[1] == '\0')
4341 /* Find the corresponding function descriptor symbol. Create it
4342 as undefined if necessary. */
4344 fdh
= get_fdh (fh
, htab
);
4346 while (fdh
->elf
.root
.type
== bfd_link_hash_indirect
4347 || fdh
->elf
.root
.type
== bfd_link_hash_warning
)
4348 fdh
= (struct ppc_link_hash_entry
*) fdh
->elf
.root
.u
.i
.link
;
4352 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
4353 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
4357 struct bfd_link_hash_entry
*bh
;
4359 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4360 newsym
= bfd_make_empty_symbol (abfd
);
4361 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4362 newsym
->section
= bfd_und_section_ptr
;
4364 newsym
->flags
= BSF_OBJECT
;
4365 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4366 newsym
->flags
|= BSF_WEAK
;
4368 bh
= &fdh
->elf
.root
;
4369 if ( !(_bfd_generic_link_add_one_symbol
4370 (info
, abfd
, newsym
->name
, newsym
->flags
,
4371 newsym
->section
, newsym
->value
, NULL
, FALSE
, FALSE
, &bh
)))
4375 fdh
= (struct ppc_link_hash_entry
*) bh
;
4376 fdh
->elf
.elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4378 fdh
->elf
.type
= STT_OBJECT
;
4382 && (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
4384 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4385 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0
4386 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
4387 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
4389 if (fdh
->elf
.dynindx
== -1)
4390 if (! bfd_elf64_link_record_dynamic_symbol (info
, &fdh
->elf
))
4392 fdh
->elf
.elf_link_hash_flags
4393 |= (fh
->elf
.elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
4394 | ELF_LINK_HASH_REF_DYNAMIC
4395 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
4396 | ELF_LINK_NON_GOT_REF
));
4397 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
4399 fdh
->elf
.plt
.plist
= fh
->elf
.plt
.plist
;
4400 fdh
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4402 fdh
->is_func_descriptor
= 1;
4407 /* Now that the info is on the function descriptor, clear the
4408 function code sym info. Any function code syms for which we
4409 don't have a definition in a regular file, we force local.
4410 This prevents a shared library from exporting syms that have
4411 been imported from another library. Function code syms that
4412 are really in the library we must leave global to prevent the
4413 linker dragging in a definition from a static library. */
4416 && ((fh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4418 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4419 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0));
4420 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
4425 #define MIN_SAVE_FPR 14
4426 #define MAX_SAVE_FPR 31
4428 /* Called near the start of bfd_elf_size_dynamic_sections. We use
4429 this hook to a) provide some gcc support functions, and b) transfer
4430 dynamic linking information gathered so far on function code symbol
4431 entries, to their corresponding function descriptor symbol entries. */
4433 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
4434 struct bfd_link_info
*info
)
4436 struct ppc_link_hash_table
*htab
;
4437 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
4438 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
4440 struct elf_link_hash_entry
*h
;
4444 htab
= ppc_hash_table (info
);
4446 if (htab
->sfpr
== NULL
)
4447 /* We don't have any relocs. */
4450 /* First provide any missing ._savef* and ._restf* functions. */
4451 memcpy (sym
, "._savef14", 10);
4452 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4454 sym
[7] = i
/ 10 + '0';
4455 sym
[8] = i
% 10 + '0';
4456 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4458 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4460 if (lowest_savef
> i
)
4462 h
->root
.type
= bfd_link_hash_defined
;
4463 h
->root
.u
.def
.section
= htab
->sfpr
;
4464 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
4466 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4467 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
4471 memcpy (sym
, "._restf14", 10);
4472 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4474 sym
[7] = i
/ 10 + '0';
4475 sym
[8] = i
% 10 + '0';
4476 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4478 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4480 if (lowest_restf
> i
)
4482 h
->root
.type
= bfd_link_hash_defined
;
4483 h
->root
.u
.def
.section
= htab
->sfpr
;
4484 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4485 + (i
- lowest_restf
) * 4);
4487 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4488 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
4492 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
4494 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4495 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
4497 if (htab
->sfpr
->_raw_size
== 0)
4499 if (!htab
->have_undefweak
)
4501 _bfd_strip_section_from_output (info
, htab
->sfpr
);
4505 htab
->sfpr
->_raw_size
= 4;
4508 p
= bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
4511 htab
->sfpr
->contents
= p
;
4513 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
4515 unsigned int fpr
= i
<< 21;
4516 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4517 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4520 if (lowest_savef
<= MAX_SAVE_FPR
)
4522 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4526 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
4528 unsigned int fpr
= i
<< 21;
4529 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4530 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4533 if (lowest_restf
<= MAX_SAVE_FPR
4534 || htab
->sfpr
->_raw_size
== 4)
4536 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4542 /* Adjust a symbol defined by a dynamic object and referenced by a
4543 regular object. The current definition is in some section of the
4544 dynamic object, but we're not including those sections. We have to
4545 change the definition to something the rest of the link can
4549 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4550 struct elf_link_hash_entry
*h
)
4552 struct ppc_link_hash_table
*htab
;
4554 unsigned int power_of_two
;
4556 htab
= ppc_hash_table (info
);
4558 /* Deal with function syms. */
4559 if (h
->type
== STT_FUNC
4560 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4562 /* Clear procedure linkage table information for any symbol that
4563 won't need a .plt entry. */
4564 struct plt_entry
*ent
;
4565 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4566 if (ent
->plt
.refcount
> 0)
4568 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
4570 || SYMBOL_CALLS_LOCAL (info
, h
)
4571 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4572 && h
->root
.type
== bfd_link_hash_undefweak
))
4574 h
->plt
.plist
= NULL
;
4575 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4579 h
->plt
.plist
= NULL
;
4581 /* If this is a weak symbol, and there is a real definition, the
4582 processor independent code will have arranged for us to see the
4583 real definition first, and we can just use the same value. */
4584 if (h
->weakdef
!= NULL
)
4586 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4587 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4588 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4589 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4590 if (ELIMINATE_COPY_RELOCS
)
4591 h
->elf_link_hash_flags
4592 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
4593 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
4597 /* If we are creating a shared library, we must presume that the
4598 only references to the symbol are via the global offset table.
4599 For such cases we need not do anything here; the relocations will
4600 be handled correctly by relocate_section. */
4604 /* If there are no references to this symbol that do not use the
4605 GOT, we don't need to generate a copy reloc. */
4606 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
4609 if (ELIMINATE_COPY_RELOCS
)
4611 struct ppc_link_hash_entry
* eh
;
4612 struct ppc_dyn_relocs
*p
;
4614 eh
= (struct ppc_link_hash_entry
*) h
;
4615 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4617 s
= p
->sec
->output_section
;
4618 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4622 /* If we didn't find any dynamic relocs in read-only sections, then
4623 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4626 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4631 if (h
->plt
.plist
!= NULL
)
4633 /* We should never get here, but unfortunately there are versions
4634 of gcc out there that improperly (for this ABI) put initialized
4635 function pointers, vtable refs and suchlike in read-only
4636 sections. Allow them to proceed, but warn that this might
4637 break at runtime. */
4638 (*_bfd_error_handler
)
4639 (_("copy reloc against `%s' requires lazy plt linking; "
4640 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
4641 h
->root
.root
.string
);
4644 /* This is a reference to a symbol defined by a dynamic object which
4645 is not a function. */
4647 /* We must allocate the symbol in our .dynbss section, which will
4648 become part of the .bss section of the executable. There will be
4649 an entry for this symbol in the .dynsym section. The dynamic
4650 object will contain position independent code, so all references
4651 from the dynamic object to this symbol will go through the global
4652 offset table. The dynamic linker will use the .dynsym entry to
4653 determine the address it must put in the global offset table, so
4654 both the dynamic object and the regular object will refer to the
4655 same memory location for the variable. */
4657 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
4658 to copy the initial value out of the dynamic object and into the
4659 runtime process image. We need to remember the offset into the
4660 .rela.bss section we are going to use. */
4661 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4663 htab
->relbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
4664 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4667 /* We need to figure out the alignment required for this symbol. I
4668 have no idea how ELF linkers handle this. */
4669 power_of_two
= bfd_log2 (h
->size
);
4670 if (power_of_two
> 4)
4673 /* Apply the required alignment. */
4675 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4676 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
4678 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
4682 /* Define the symbol as being at this point in the section. */
4683 h
->root
.u
.def
.section
= s
;
4684 h
->root
.u
.def
.value
= s
->_raw_size
;
4686 /* Increment the section size to make room for the symbol. */
4687 s
->_raw_size
+= h
->size
;
4692 /* If given a function descriptor symbol, hide both the function code
4693 sym and the descriptor. */
4695 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
4696 struct elf_link_hash_entry
*h
,
4697 bfd_boolean force_local
)
4699 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
4701 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
4703 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
4708 struct ppc_link_hash_table
*htab
;
4711 /* We aren't supposed to use alloca in BFD because on
4712 systems which do not have alloca the version in libiberty
4713 calls xmalloc, which might cause the program to crash
4714 when it runs out of memory. This function doesn't have a
4715 return status, so there's no way to gracefully return an
4716 error. So cheat. We know that string[-1] can be safely
4717 dereferenced; It's either a string in an ELF string
4718 table, or allocated in an objalloc structure. */
4720 p
= h
->root
.root
.string
- 1;
4723 htab
= ppc_hash_table (info
);
4724 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4727 /* Unfortunately, if it so happens that the string we were
4728 looking for was allocated immediately before this string,
4729 then we overwrote the string terminator. That's the only
4730 reason the lookup should fail. */
4733 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
4734 while (q
>= h
->root
.root
.string
&& *q
== *p
)
4736 if (q
< h
->root
.root
.string
&& *p
== '.')
4737 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4741 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
4742 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
4746 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
4751 get_sym_h (struct elf_link_hash_entry
**hp
, Elf_Internal_Sym
**symp
,
4752 asection
**symsecp
, char **tls_maskp
, Elf_Internal_Sym
**locsymsp
,
4753 unsigned long r_symndx
, bfd
*ibfd
)
4755 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4757 if (r_symndx
>= symtab_hdr
->sh_info
)
4759 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4760 struct elf_link_hash_entry
*h
;
4762 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4763 while (h
->root
.type
== bfd_link_hash_indirect
4764 || h
->root
.type
== bfd_link_hash_warning
)
4765 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4773 if (symsecp
!= NULL
)
4775 asection
*symsec
= NULL
;
4776 if (h
->root
.type
== bfd_link_hash_defined
4777 || h
->root
.type
== bfd_link_hash_defweak
)
4778 symsec
= h
->root
.u
.def
.section
;
4782 if (tls_maskp
!= NULL
)
4784 struct ppc_link_hash_entry
*eh
;
4786 eh
= (struct ppc_link_hash_entry
*) h
;
4787 *tls_maskp
= &eh
->tls_mask
;
4792 Elf_Internal_Sym
*sym
;
4793 Elf_Internal_Sym
*locsyms
= *locsymsp
;
4795 if (locsyms
== NULL
)
4797 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4798 if (locsyms
== NULL
)
4799 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4800 symtab_hdr
->sh_info
,
4801 0, NULL
, NULL
, NULL
);
4802 if (locsyms
== NULL
)
4804 *locsymsp
= locsyms
;
4806 sym
= locsyms
+ r_symndx
;
4814 if (symsecp
!= NULL
)
4816 asection
*symsec
= NULL
;
4817 if ((sym
->st_shndx
!= SHN_UNDEF
4818 && sym
->st_shndx
< SHN_LORESERVE
)
4819 || sym
->st_shndx
> SHN_HIRESERVE
)
4820 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
4824 if (tls_maskp
!= NULL
)
4826 struct got_entry
**lgot_ents
;
4830 lgot_ents
= elf_local_got_ents (ibfd
);
4831 if (lgot_ents
!= NULL
)
4833 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
4834 tls_mask
= &lgot_masks
[r_symndx
];
4836 *tls_maskp
= tls_mask
;
4842 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
4843 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
4844 type suitable for optimization, and 1 otherwise. */
4847 get_tls_mask (char **tls_maskp
, unsigned long *toc_symndx
,
4848 Elf_Internal_Sym
**locsymsp
,
4849 const Elf_Internal_Rela
*rel
, bfd
*ibfd
)
4851 unsigned long r_symndx
;
4853 struct elf_link_hash_entry
*h
;
4854 Elf_Internal_Sym
*sym
;
4858 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4859 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4862 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
4864 || ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
4867 /* Look inside a TOC section too. */
4870 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
4871 off
= h
->root
.u
.def
.value
;
4874 off
= sym
->st_value
;
4875 off
+= rel
->r_addend
;
4876 BFD_ASSERT (off
% 8 == 0);
4877 r_symndx
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8];
4878 next_r
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8 + 1];
4879 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4881 if (toc_symndx
!= NULL
)
4882 *toc_symndx
= r_symndx
;
4884 || ((h
->root
.type
== bfd_link_hash_defined
4885 || h
->root
.type
== bfd_link_hash_defweak
)
4886 && !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4887 && (next_r
== -1 || next_r
== -2))
4892 /* Adjust all global syms defined in opd sections. In gcc generated
4893 code these will already have been done, but I suppose we have to
4894 cater for all sorts of hand written assembly. */
4897 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
4899 struct ppc_link_hash_entry
*eh
;
4903 if (h
->root
.type
== bfd_link_hash_indirect
)
4906 if (h
->root
.type
== bfd_link_hash_warning
)
4907 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4909 if (h
->root
.type
!= bfd_link_hash_defined
4910 && h
->root
.type
!= bfd_link_hash_defweak
)
4913 eh
= (struct ppc_link_hash_entry
*) h
;
4914 if (eh
->adjust_done
)
4917 sym_sec
= eh
->elf
.root
.u
.def
.section
;
4919 && elf_section_data (sym_sec
) != NULL
4920 && (opd_adjust
= ppc64_elf_section_data (sym_sec
)->opd
.adjust
) != NULL
)
4922 eh
->elf
.root
.u
.def
.value
+= opd_adjust
[eh
->elf
.root
.u
.def
.value
/ 24];
4923 eh
->adjust_done
= 1;
4928 /* Remove unused Official Procedure Descriptor entries. Currently we
4929 only remove those associated with functions in discarded link-once
4930 sections, or weakly defined functions that have been overridden. It
4931 would be possible to remove many more entries for statically linked
4935 ppc64_elf_edit_opd (bfd
*obfd
, struct bfd_link_info
*info
)
4938 bfd_boolean some_edited
= FALSE
;
4940 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4943 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4944 Elf_Internal_Shdr
*symtab_hdr
;
4945 Elf_Internal_Sym
*local_syms
;
4946 struct elf_link_hash_entry
**sym_hashes
;
4950 bfd_boolean need_edit
;
4952 sec
= bfd_get_section_by_name (ibfd
, ".opd");
4956 amt
= sec
->_raw_size
* sizeof (long) / 24;
4957 adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
4960 /* Must be a ld -r link. ie. check_relocs hasn't been
4962 adjust
= bfd_zalloc (obfd
, amt
);
4963 ppc64_elf_section_data (sec
)->opd
.adjust
= adjust
;
4965 memset (adjust
, 0, amt
);
4967 if (sec
->output_section
== bfd_abs_section_ptr
)
4970 /* Look through the section relocs. */
4971 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
4975 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4976 sym_hashes
= elf_sym_hashes (ibfd
);
4978 /* Read the relocations. */
4979 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4981 if (relstart
== NULL
)
4984 /* First run through the relocs to check they are sane, and to
4985 determine whether we need to edit this opd section. */
4988 relend
= relstart
+ sec
->reloc_count
;
4989 for (rel
= relstart
; rel
< relend
; )
4991 enum elf_ppc64_reloc_type r_type
;
4992 unsigned long r_symndx
;
4994 struct elf_link_hash_entry
*h
;
4995 Elf_Internal_Sym
*sym
;
4997 /* .opd contains a regular array of 24 byte entries. We're
4998 only interested in the reloc pointing to a function entry
5000 if (rel
->r_offset
!= offset
5001 || rel
+ 1 >= relend
5002 || (rel
+ 1)->r_offset
!= offset
+ 8)
5004 /* If someone messes with .opd alignment then after a
5005 "ld -r" we might have padding in the middle of .opd.
5006 Also, there's nothing to prevent someone putting
5007 something silly in .opd with the assembler. No .opd
5008 optimization for them! */
5009 (*_bfd_error_handler
)
5010 (_("%s: .opd is not a regular array of opd entries"),
5011 bfd_archive_filename (ibfd
));
5016 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
5017 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
5019 (*_bfd_error_handler
)
5020 (_("%s: unexpected reloc type %u in .opd section"),
5021 bfd_archive_filename (ibfd
), r_type
);
5026 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5027 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
5031 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
5033 const char *sym_name
;
5035 sym_name
= h
->root
.root
.string
;
5037 sym_name
= bfd_elf_local_sym_name (ibfd
, sym
);
5039 (*_bfd_error_handler
)
5040 (_("%s: undefined sym `%s' in .opd section"),
5041 bfd_archive_filename (ibfd
),
5047 /* opd entries are always for functions defined in the
5048 current input bfd. If the symbol isn't defined in the
5049 input bfd, then we won't be using the function in this
5050 bfd; It must be defined in a linkonce section in another
5051 bfd, or is weak. It's also possible that we are
5052 discarding the function due to a linker script /DISCARD/,
5053 which we test for via the output_section. */
5054 if (sym_sec
->owner
!= ibfd
5055 || sym_sec
->output_section
== bfd_abs_section_ptr
)
5060 /* Allow for the possibility of a reloc on the third word. */
5062 && rel
->r_offset
== offset
- 8)
5068 Elf_Internal_Rela
*write_rel
;
5069 bfd_byte
*rptr
, *wptr
;
5072 /* This seems a waste of time as input .opd sections are all
5073 zeros as generated by gcc, but I suppose there's no reason
5074 this will always be so. We might start putting something in
5075 the third word of .opd entries. */
5076 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
5078 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
5080 || !bfd_get_section_contents (ibfd
, sec
, loc
, 0,
5084 if (local_syms
!= NULL
5085 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5087 if (elf_section_data (sec
)->relocs
!= relstart
)
5091 sec
->contents
= loc
;
5092 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
5095 elf_section_data (sec
)->relocs
= relstart
;
5097 wptr
= sec
->contents
;
5098 rptr
= sec
->contents
;
5099 write_rel
= relstart
;
5102 for (rel
= relstart
; rel
< relend
; rel
++)
5104 unsigned long r_symndx
;
5106 struct elf_link_hash_entry
*h
;
5107 Elf_Internal_Sym
*sym
;
5109 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5110 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
5114 if (rel
->r_offset
== offset
)
5116 struct ppc_link_hash_entry
*fdh
= NULL
;
5118 fdh
= get_fdh ((struct ppc_link_hash_entry
*) h
,
5119 ppc_hash_table (info
));
5121 skip
= (sym_sec
->owner
!= ibfd
5122 || sym_sec
->output_section
== bfd_abs_section_ptr
);
5125 if (h
!= NULL
&& sym_sec
->owner
== ibfd
)
5127 /* Arrange for the function descriptor sym
5129 fdh
->elf
.root
.u
.def
.value
= 0;
5130 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
5135 /* We'll be keeping this opd entry. */
5139 /* Redefine the function descriptor symbol to
5140 this location in the opd section. It is
5141 necessary to update the value here rather
5142 than using an array of adjustments as we do
5143 for local symbols, because various places
5144 in the generic ELF code use the value
5145 stored in u.def.value. */
5146 fdh
->elf
.root
.u
.def
.value
= wptr
- sec
->contents
;
5147 fdh
->adjust_done
= 1;
5150 /* Local syms are a bit tricky. We could
5151 tweak them as they can be cached, but
5152 we'd need to look through the local syms
5153 for the function descriptor sym which we
5154 don't have at the moment. So keep an
5155 array of adjustments. */
5156 adjust
[rel
->r_offset
/ 24] = wptr
- rptr
;
5159 memcpy (wptr
, rptr
, 24);
5168 BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel
->r_info
)));
5171 /* We won't be needing dynamic relocs here. */
5172 struct ppc_dyn_relocs
**pp
;
5173 struct ppc_dyn_relocs
*p
;
5176 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5177 else if (sym_sec
!= NULL
)
5178 pp
= ((struct ppc_dyn_relocs
**)
5179 &elf_section_data (sym_sec
)->local_dynrel
);
5181 pp
= ((struct ppc_dyn_relocs
**)
5182 &elf_section_data (sec
)->local_dynrel
);
5183 while ((p
= *pp
) != NULL
)
5198 /* We need to adjust any reloc offsets to point to the
5199 new opd entries. While we're at it, we may as well
5200 remove redundant relocs. */
5201 rel
->r_offset
+= wptr
- rptr
;
5202 if (write_rel
!= rel
)
5203 memcpy (write_rel
, rel
, sizeof (*rel
));
5208 sec
->_cooked_size
= wptr
- sec
->contents
;
5209 sec
->reloc_count
= write_rel
- relstart
;
5210 /* Fudge the size too, as this is used later in
5211 elf_bfd_final_link if we are emitting relocs. */
5212 elf_section_data (sec
)->rel_hdr
.sh_size
5213 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
5214 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
5217 else if (elf_section_data (sec
)->relocs
!= relstart
)
5220 if (local_syms
!= NULL
5221 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5223 if (!info
->keep_memory
)
5226 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5231 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
5236 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
5239 ppc64_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
5241 struct ppc_link_hash_table
*htab
;
5243 htab
= ppc_hash_table (info
);
5244 if (htab
->tls_get_addr
!= NULL
)
5246 struct elf_link_hash_entry
*h
= htab
->tls_get_addr
;
5248 while (h
->root
.type
== bfd_link_hash_indirect
5249 || h
->root
.type
== bfd_link_hash_warning
)
5250 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5252 htab
->tls_get_addr
= h
;
5255 return _bfd_elf_tls_setup (obfd
, info
);
5258 /* Run through all the TLS relocs looking for optimization
5259 opportunities. The linker has been hacked (see ppc64elf.em) to do
5260 a preliminary section layout so that we know the TLS segment
5261 offsets. We can't optimize earlier because some optimizations need
5262 to know the tp offset, and we need to optimize before allocating
5263 dynamic relocations. */
5266 ppc64_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
5270 struct ppc_link_hash_table
*htab
;
5272 if (info
->relocatable
|| info
->shared
)
5275 htab
= ppc_hash_table (info
);
5276 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5278 Elf_Internal_Sym
*locsyms
= NULL
;
5280 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5281 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
5283 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
5284 int expecting_tls_get_addr
;
5286 /* Read the relocations. */
5287 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
5289 if (relstart
== NULL
)
5292 expecting_tls_get_addr
= 0;
5293 relend
= relstart
+ sec
->reloc_count
;
5294 for (rel
= relstart
; rel
< relend
; rel
++)
5296 enum elf_ppc64_reloc_type r_type
;
5297 unsigned long r_symndx
;
5298 struct elf_link_hash_entry
*h
;
5299 Elf_Internal_Sym
*sym
;
5302 char tls_set
, tls_clear
, tls_type
= 0;
5304 bfd_boolean ok_tprel
, is_local
;
5306 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5307 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
5311 if (elf_section_data (sec
)->relocs
!= relstart
)
5314 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5315 != (unsigned char *) locsyms
))
5322 if (h
->root
.type
!= bfd_link_hash_defined
5323 && h
->root
.type
!= bfd_link_hash_defweak
)
5325 value
= h
->root
.u
.def
.value
;
5329 value
= sym
->st_value
;
5331 if (elf_section_data (sym_sec
) != NULL
)
5334 adjust
= ppc64_elf_section_data (sym_sec
)->opd
.adjust
;
5336 value
+= adjust
[value
/ 24];
5343 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5346 value
+= sym_sec
->output_offset
;
5347 value
+= sym_sec
->output_section
->vma
;
5348 value
-= htab
->elf
.tls_sec
->vma
;
5349 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
5350 < (bfd_vma
) 1 << 32);
5353 r_type
= ELF64_R_TYPE (rel
->r_info
);
5356 case R_PPC64_GOT_TLSLD16
:
5357 case R_PPC64_GOT_TLSLD16_LO
:
5358 case R_PPC64_GOT_TLSLD16_HI
:
5359 case R_PPC64_GOT_TLSLD16_HA
:
5360 /* These relocs should never be against a symbol
5361 defined in a shared lib. Leave them alone if
5362 that turns out to be the case. */
5363 ppc64_tlsld_got (ibfd
)->refcount
-= 1;
5370 tls_type
= TLS_TLS
| TLS_LD
;
5371 expecting_tls_get_addr
= 1;
5374 case R_PPC64_GOT_TLSGD16
:
5375 case R_PPC64_GOT_TLSGD16_LO
:
5376 case R_PPC64_GOT_TLSGD16_HI
:
5377 case R_PPC64_GOT_TLSGD16_HA
:
5383 tls_set
= TLS_TLS
| TLS_TPRELGD
;
5385 tls_type
= TLS_TLS
| TLS_GD
;
5386 expecting_tls_get_addr
= 1;
5389 case R_PPC64_GOT_TPREL16_DS
:
5390 case R_PPC64_GOT_TPREL16_LO_DS
:
5391 case R_PPC64_GOT_TPREL16_HI
:
5392 case R_PPC64_GOT_TPREL16_HA
:
5393 expecting_tls_get_addr
= 0;
5398 tls_clear
= TLS_TPREL
;
5399 tls_type
= TLS_TLS
| TLS_TPREL
;
5406 case R_PPC64_REL14_BRTAKEN
:
5407 case R_PPC64_REL14_BRNTAKEN
:
5410 && h
== htab
->tls_get_addr
)
5412 if (!expecting_tls_get_addr
5414 && ((ELF64_R_TYPE (rel
[-1].r_info
)
5416 || (ELF64_R_TYPE (rel
[-1].r_info
)
5417 == R_PPC64_TOC16_LO
)))
5419 /* Check for toc tls entries. */
5423 retval
= get_tls_mask (&toc_tls
, NULL
, &locsyms
,
5427 if (toc_tls
!= NULL
)
5428 expecting_tls_get_addr
= retval
> 1;
5431 if (expecting_tls_get_addr
)
5433 struct plt_entry
*ent
;
5434 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
5435 if (ent
->addend
== 0)
5437 if (ent
->plt
.refcount
> 0)
5438 ent
->plt
.refcount
-= 1;
5443 expecting_tls_get_addr
= 0;
5446 case R_PPC64_TPREL64
:
5447 expecting_tls_get_addr
= 0;
5451 tls_set
= TLS_EXPLICIT
;
5452 tls_clear
= TLS_TPREL
;
5458 case R_PPC64_DTPMOD64
:
5459 expecting_tls_get_addr
= 0;
5460 if (rel
+ 1 < relend
5462 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
5463 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5467 tls_set
= TLS_EXPLICIT
| TLS_GD
;
5470 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
5479 tls_set
= TLS_EXPLICIT
;
5485 expecting_tls_get_addr
= 0;
5489 if ((tls_set
& TLS_EXPLICIT
) == 0)
5491 struct got_entry
*ent
;
5493 /* Adjust got entry for this reloc. */
5497 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
5499 for (; ent
!= NULL
; ent
= ent
->next
)
5500 if (ent
->addend
== rel
->r_addend
5501 && ent
->owner
== ibfd
5502 && ent
->tls_type
== tls_type
)
5509 /* We managed to get rid of a got entry. */
5510 if (ent
->got
.refcount
> 0)
5511 ent
->got
.refcount
-= 1;
5516 struct ppc_link_hash_entry
* eh
;
5517 struct ppc_dyn_relocs
**pp
;
5518 struct ppc_dyn_relocs
*p
;
5520 /* Adjust dynamic relocs. */
5521 eh
= (struct ppc_link_hash_entry
*) h
;
5522 for (pp
= &eh
->dyn_relocs
;
5527 /* If we got rid of a DTPMOD/DTPREL reloc
5528 pair then we'll lose one or two dyn
5530 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
5539 *tls_mask
|= tls_set
;
5540 *tls_mask
&= ~tls_clear
;
5543 if (elf_section_data (sec
)->relocs
!= relstart
)
5548 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5549 != (unsigned char *) locsyms
))
5551 if (!info
->keep_memory
)
5554 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
5560 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
5561 will be called from elflink.h. If elflink.h doesn't call our
5562 finish_dynamic_symbol routine, we'll need to do something about
5563 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
5564 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
5567 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
5568 && ((H)->dynindx != -1 \
5569 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
5571 /* Allocate space in .plt, .got and associated reloc sections for
5575 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5577 struct bfd_link_info
*info
;
5578 struct ppc_link_hash_table
*htab
;
5580 struct ppc_link_hash_entry
*eh
;
5581 struct ppc_dyn_relocs
*p
;
5582 struct got_entry
*gent
;
5584 if (h
->root
.type
== bfd_link_hash_indirect
)
5587 if (h
->root
.type
== bfd_link_hash_warning
)
5588 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5590 info
= (struct bfd_link_info
*) inf
;
5591 htab
= ppc_hash_table (info
);
5593 if (htab
->elf
.dynamic_sections_created
5595 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
5597 struct plt_entry
*pent
;
5598 bfd_boolean doneone
= FALSE
;
5599 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5600 if (pent
->plt
.refcount
> 0)
5602 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
5604 /* If this is the first .plt entry, make room for the special
5607 if (s
->_raw_size
== 0)
5608 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
5610 pent
->plt
.offset
= s
->_raw_size
;
5612 /* Make room for this entry. */
5613 s
->_raw_size
+= PLT_ENTRY_SIZE
;
5615 /* Make room for the .glink code. */
5617 if (s
->_raw_size
== 0)
5618 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
5619 /* We need bigger stubs past index 32767. */
5620 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
5622 s
->_raw_size
+= 2*4;
5624 /* We also need to make an entry in the .rela.plt section. */
5626 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
5630 pent
->plt
.offset
= (bfd_vma
) -1;
5633 h
->plt
.plist
= NULL
;
5634 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5639 h
->plt
.plist
= NULL
;
5640 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5643 eh
= (struct ppc_link_hash_entry
*) h
;
5644 /* Run through the TLS GD got entries first if we're changing them
5646 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
5647 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5648 if (gent
->got
.refcount
> 0
5649 && (gent
->tls_type
& TLS_GD
) != 0)
5651 /* This was a GD entry that has been converted to TPREL. If
5652 there happens to be a TPREL entry we can use that one. */
5653 struct got_entry
*ent
;
5654 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5655 if (ent
->got
.refcount
> 0
5656 && (ent
->tls_type
& TLS_TPREL
) != 0
5657 && ent
->addend
== gent
->addend
5658 && ent
->owner
== gent
->owner
)
5660 gent
->got
.refcount
= 0;
5664 /* If not, then we'll be using our own TPREL entry. */
5665 if (gent
->got
.refcount
!= 0)
5666 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
5669 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5670 if (gent
->got
.refcount
> 0)
5674 /* Make sure this symbol is output as a dynamic symbol.
5675 Undefined weak syms won't yet be marked as dynamic,
5676 nor will all TLS symbols. */
5677 if (h
->dynindx
== -1
5678 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5680 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5684 if ((gent
->tls_type
& TLS_LD
) != 0
5685 && !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5687 gent
->got
.offset
= ppc64_tlsld_got (gent
->owner
)->offset
;
5691 s
= ppc64_elf_tdata (gent
->owner
)->got
;
5692 gent
->got
.offset
= s
->_raw_size
;
5694 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
5695 dyn
= htab
->elf
.dynamic_sections_created
;
5697 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5698 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5699 || h
->root
.type
!= bfd_link_hash_undefweak
))
5700 ppc64_elf_tdata (gent
->owner
)->relgot
->_raw_size
5701 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
5702 ? 2 * sizeof (Elf64_External_Rela
)
5703 : sizeof (Elf64_External_Rela
));
5706 gent
->got
.offset
= (bfd_vma
) -1;
5708 if (eh
->dyn_relocs
== NULL
)
5711 /* In the shared -Bsymbolic case, discard space allocated for
5712 dynamic pc-relative relocs against symbols which turn out to be
5713 defined in regular objects. For the normal shared case, discard
5714 space for relocs that have become local due to symbol visibility
5719 /* Relocs that use pc_count are those that appear on a call insn,
5720 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
5721 generated via assembly. We want calls to protected symbols to
5722 resolve directly to the function rather than going via the plt.
5723 If people want function pointer comparisons to work as expected
5724 then they should avoid writing weird assembly. */
5725 if (SYMBOL_CALLS_LOCAL (info
, h
))
5727 struct ppc_dyn_relocs
**pp
;
5729 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5731 p
->count
-= p
->pc_count
;
5740 /* Also discard relocs on undefined weak syms with non-default
5742 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5743 && h
->root
.type
== bfd_link_hash_undefweak
)
5744 eh
->dyn_relocs
= NULL
;
5746 else if (ELIMINATE_COPY_RELOCS
)
5748 /* For the non-shared case, discard space for relocs against
5749 symbols which turn out to need copy relocs or are not
5752 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5753 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5754 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5756 /* Make sure this symbol is output as a dynamic symbol.
5757 Undefined weak syms won't yet be marked as dynamic. */
5758 if (h
->dynindx
== -1
5759 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5761 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5765 /* If that succeeded, we know we'll be keeping all the
5767 if (h
->dynindx
!= -1)
5771 eh
->dyn_relocs
= NULL
;
5776 /* Finally, allocate space. */
5777 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5779 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5780 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5786 /* Find any dynamic relocs that apply to read-only sections. */
5789 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5791 struct ppc_link_hash_entry
*eh
;
5792 struct ppc_dyn_relocs
*p
;
5794 if (h
->root
.type
== bfd_link_hash_warning
)
5795 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5797 eh
= (struct ppc_link_hash_entry
*) h
;
5798 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5800 asection
*s
= p
->sec
->output_section
;
5802 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5804 struct bfd_link_info
*info
= inf
;
5806 info
->flags
|= DF_TEXTREL
;
5808 /* Not an error, just cut short the traversal. */
5815 /* Set the sizes of the dynamic sections. */
5818 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5819 struct bfd_link_info
*info
)
5821 struct ppc_link_hash_table
*htab
;
5827 htab
= ppc_hash_table (info
);
5828 dynobj
= htab
->elf
.dynobj
;
5832 if (htab
->elf
.dynamic_sections_created
)
5834 /* Set the contents of the .interp section to the interpreter. */
5835 if (info
->executable
)
5837 s
= bfd_get_section_by_name (dynobj
, ".interp");
5840 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5841 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5845 /* Set up .got offsets for local syms, and space for local dynamic
5847 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5849 struct got_entry
**lgot_ents
;
5850 struct got_entry
**end_lgot_ents
;
5852 bfd_size_type locsymcount
;
5853 Elf_Internal_Shdr
*symtab_hdr
;
5856 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
5859 if (ppc64_tlsld_got (ibfd
)->refcount
> 0)
5861 s
= ppc64_elf_tdata (ibfd
)->got
;
5862 ppc64_tlsld_got (ibfd
)->offset
= s
->_raw_size
;
5866 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
5867 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5871 ppc64_tlsld_got (ibfd
)->offset
= (bfd_vma
) -1;
5873 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5875 struct ppc_dyn_relocs
*p
;
5877 for (p
= *((struct ppc_dyn_relocs
**)
5878 &elf_section_data (s
)->local_dynrel
);
5882 if (!bfd_is_abs_section (p
->sec
)
5883 && bfd_is_abs_section (p
->sec
->output_section
))
5885 /* Input section has been discarded, either because
5886 it is a copy of a linkonce section or due to
5887 linker script /DISCARD/, so we'll be discarding
5890 else if (p
->count
!= 0)
5892 srel
= elf_section_data (p
->sec
)->sreloc
;
5893 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5894 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
5895 info
->flags
|= DF_TEXTREL
;
5900 lgot_ents
= elf_local_got_ents (ibfd
);
5904 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
5905 locsymcount
= symtab_hdr
->sh_info
;
5906 end_lgot_ents
= lgot_ents
+ locsymcount
;
5907 lgot_masks
= (char *) end_lgot_ents
;
5908 s
= ppc64_elf_tdata (ibfd
)->got
;
5909 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
5910 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
5912 struct got_entry
*ent
;
5914 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
5915 if (ent
->got
.refcount
> 0)
5917 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
5919 if (ppc64_tlsld_got (ibfd
)->offset
== (bfd_vma
) -1)
5921 ppc64_tlsld_got (ibfd
)->offset
= s
->_raw_size
;
5924 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5926 ent
->got
.offset
= ppc64_tlsld_got (ibfd
)->offset
;
5930 ent
->got
.offset
= s
->_raw_size
;
5931 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
5935 srel
->_raw_size
+= 2 * sizeof (Elf64_External_Rela
);
5941 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5946 ent
->got
.offset
= (bfd_vma
) -1;
5950 /* Allocate global sym .plt and .got entries, and space for global
5951 sym dynamic relocs. */
5952 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
5954 /* We now have determined the sizes of the various dynamic sections.
5955 Allocate memory for them. */
5957 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5959 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5962 /* Reset _cooked_size since prelim layout will set it wrongly,
5963 and a non-zero _cooked_size sticks. */
5964 s
->_cooked_size
= 0;
5966 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
5967 /* These haven't been allocated yet; don't strip. */
5969 else if (s
== htab
->got
5971 || s
== htab
->glink
)
5973 /* Strip this section if we don't need it; see the
5976 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
5978 if (s
->_raw_size
== 0)
5980 /* If we don't need this section, strip it from the
5981 output file. This is mostly to handle .rela.bss and
5982 .rela.plt. We must create both sections in
5983 create_dynamic_sections, because they must be created
5984 before the linker maps input sections to output
5985 sections. The linker does that before
5986 adjust_dynamic_symbol is called, and it is that
5987 function which decides whether anything needs to go
5988 into these sections. */
5992 if (s
!= htab
->relplt
)
5995 /* We use the reloc_count field as a counter if we need
5996 to copy relocs into the output file. */
6002 /* It's not one of our sections, so don't allocate space. */
6006 if (s
->_raw_size
== 0)
6008 _bfd_strip_section_from_output (info
, s
);
6012 /* .plt is in the bss section. We don't initialise it. */
6016 /* Allocate memory for the section contents. We use bfd_zalloc
6017 here in case unused entries are not reclaimed before the
6018 section's contents are written out. This should not happen,
6019 but this way if it does we get a R_PPC64_NONE reloc in .rela
6020 sections instead of garbage.
6021 We also rely on the section contents being zero when writing
6023 s
->contents
= bfd_zalloc (dynobj
, s
->_raw_size
);
6024 if (s
->contents
== NULL
)
6028 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6030 s
= ppc64_elf_tdata (ibfd
)->got
;
6031 if (s
!= NULL
&& s
!= htab
->got
)
6033 s
->_cooked_size
= 0;
6034 if (s
->_raw_size
== 0)
6035 _bfd_strip_section_from_output (info
, s
);
6038 s
->contents
= bfd_zalloc (ibfd
, s
->_raw_size
);
6039 if (s
->contents
== NULL
)
6043 s
= ppc64_elf_tdata (ibfd
)->relgot
;
6046 s
->_cooked_size
= 0;
6047 if (s
->_raw_size
== 0)
6048 _bfd_strip_section_from_output (info
, s
);
6051 s
->contents
= bfd_zalloc (ibfd
, s
->_raw_size
);
6052 if (s
->contents
== NULL
)
6060 if (htab
->elf
.dynamic_sections_created
)
6062 /* Add some entries to the .dynamic section. We fill in the
6063 values later, in ppc64_elf_finish_dynamic_sections, but we
6064 must add the entries now so that we get the correct size for
6065 the .dynamic section. The DT_DEBUG entry is filled in by the
6066 dynamic linker and used by the debugger. */
6067 #define add_dynamic_entry(TAG, VAL) \
6068 bfd_elf64_add_dynamic_entry (info, (TAG), (VAL))
6070 if (info
->executable
)
6072 if (!add_dynamic_entry (DT_DEBUG
, 0))
6076 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
6078 if (!add_dynamic_entry (DT_PLTGOT
, 0)
6079 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
6080 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
6081 || !add_dynamic_entry (DT_JMPREL
, 0)
6082 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
6088 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
6089 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
6095 if (!add_dynamic_entry (DT_RELA
, 0)
6096 || !add_dynamic_entry (DT_RELASZ
, 0)
6097 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
6100 /* If any dynamic relocs apply to a read-only section,
6101 then we need a DT_TEXTREL entry. */
6102 if ((info
->flags
& DF_TEXTREL
) == 0)
6103 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
6105 if ((info
->flags
& DF_TEXTREL
) != 0)
6107 if (!add_dynamic_entry (DT_TEXTREL
, 0))
6112 #undef add_dynamic_entry
6117 /* Determine the type of stub needed, if any, for a call. */
6119 static inline enum ppc_stub_type
6120 ppc_type_of_stub (asection
*input_sec
,
6121 const Elf_Internal_Rela
*rel
,
6122 struct ppc_link_hash_entry
**hash
,
6123 bfd_vma destination
)
6125 struct ppc_link_hash_entry
*h
= *hash
;
6127 bfd_vma branch_offset
;
6128 bfd_vma max_branch_offset
;
6129 enum elf_ppc64_reloc_type r_type
;
6134 && h
->oh
->dynindx
!= -1)
6136 struct plt_entry
*ent
;
6137 for (ent
= h
->oh
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6138 if (ent
->addend
== rel
->r_addend
6139 && ent
->plt
.offset
!= (bfd_vma
) -1)
6141 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
6142 return ppc_stub_plt_call
;
6146 if (!(h
->elf
.root
.type
== bfd_link_hash_defined
6147 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
6148 || h
->elf
.root
.u
.def
.section
->output_section
== NULL
)
6149 return ppc_stub_none
;
6152 /* Determine where the call point is. */
6153 location
= (input_sec
->output_offset
6154 + input_sec
->output_section
->vma
6157 branch_offset
= destination
- location
;
6158 r_type
= ELF64_R_TYPE (rel
->r_info
);
6160 /* Determine if a long branch stub is needed. */
6161 max_branch_offset
= 1 << 25;
6162 if (r_type
!= R_PPC64_REL24
)
6163 max_branch_offset
= 1 << 15;
6165 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
6166 /* We need a stub. Figure out whether a long_branch or plt_branch
6168 return ppc_stub_long_branch
;
6170 return ppc_stub_none
;
6173 /* Build a .plt call stub. */
6175 static inline bfd_byte
*
6176 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
)
6178 #define PPC_LO(v) ((v) & 0xffff)
6179 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6180 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6182 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
6183 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
6184 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6185 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6186 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
6188 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
6189 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6190 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
6192 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
6193 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6194 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
6199 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6201 struct ppc_stub_hash_entry
*stub_entry
;
6202 struct ppc_branch_hash_entry
*br_entry
;
6203 struct bfd_link_info
*info
;
6204 struct ppc_link_hash_table
*htab
;
6208 struct plt_entry
*ent
;
6212 /* Massage our args to the form they really have. */
6213 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6216 htab
= ppc_hash_table (info
);
6218 /* Make a note of the offset within the stubs for this entry. */
6219 stub_entry
->stub_offset
= stub_entry
->stub_sec
->_cooked_size
;
6220 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
6222 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
6223 switch (stub_entry
->stub_type
)
6225 case ppc_stub_long_branch
:
6226 case ppc_stub_long_branch_r2off
:
6227 /* Branches are relative. This is where we are going to. */
6228 off
= (stub_entry
->target_value
6229 + stub_entry
->target_section
->output_offset
6230 + stub_entry
->target_section
->output_section
->vma
);
6232 /* And this is where we are coming from. */
6233 off
-= (stub_entry
->stub_offset
6234 + stub_entry
->stub_sec
->output_offset
6235 + stub_entry
->stub_sec
->output_section
->vma
);
6237 if (stub_entry
->stub_type
!= ppc_stub_long_branch_r2off
)
6243 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
6244 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6245 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
6247 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
6249 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
6254 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
6256 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
6259 case ppc_stub_plt_branch
:
6260 case ppc_stub_plt_branch_r2off
:
6261 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6262 stub_entry
->root
.string
+ 9,
6264 if (br_entry
== NULL
)
6266 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
6267 stub_entry
->root
.string
+ 9);
6268 htab
->stub_error
= TRUE
;
6272 off
= (stub_entry
->target_value
6273 + stub_entry
->target_section
->output_offset
6274 + stub_entry
->target_section
->output_section
->vma
);
6276 bfd_put_64 (htab
->brlt
->owner
, off
,
6277 htab
->brlt
->contents
+ br_entry
->offset
);
6281 /* Create a reloc for the branch lookup table entry. */
6282 Elf_Internal_Rela rela
;
6285 rela
.r_offset
= (br_entry
->offset
6286 + htab
->brlt
->output_offset
6287 + htab
->brlt
->output_section
->vma
);
6288 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6289 rela
.r_addend
= off
;
6291 rl
= htab
->relbrlt
->contents
;
6292 rl
+= htab
->relbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
6293 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
6296 off
= (br_entry
->offset
6297 + htab
->brlt
->output_offset
6298 + htab
->brlt
->output_section
->vma
6299 - elf_gp (htab
->brlt
->output_section
->owner
)
6300 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6302 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6304 (*_bfd_error_handler
)
6305 (_("linkage table error against `%s'"),
6306 stub_entry
->root
.string
);
6307 bfd_set_error (bfd_error_bad_value
);
6308 htab
->stub_error
= TRUE
;
6313 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
6315 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
6317 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
6324 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
6325 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6326 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
6328 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
6330 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
6332 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
6334 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
6338 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
6340 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
6343 case ppc_stub_plt_call
:
6344 /* Do the best we can for shared libraries built without
6345 exporting ".foo" for each "foo". This can happen when symbol
6346 versioning scripts strip all bar a subset of symbols. */
6347 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
6348 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
6350 /* Point the symbol at the stub. There may be multiple stubs,
6351 we don't really care; The main thing is to make this sym
6352 defined somewhere. Maybe defining the symbol in the stub
6353 section is a silly idea. If we didn't do this, htab->top_id
6355 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
6356 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
6357 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
6360 /* Now build the stub. */
6362 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6363 if (ent
->addend
== stub_entry
->addend
)
6365 off
= ent
->plt
.offset
;
6368 if (off
>= (bfd_vma
) -2)
6371 off
&= ~ (bfd_vma
) 1;
6372 off
+= (htab
->plt
->output_offset
6373 + htab
->plt
->output_section
->vma
6374 - elf_gp (htab
->plt
->output_section
->owner
)
6375 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6377 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6379 (*_bfd_error_handler
)
6380 (_("linkage table error against `%s'"),
6381 stub_entry
->h
->elf
.root
.root
.string
);
6382 bfd_set_error (bfd_error_bad_value
);
6383 htab
->stub_error
= TRUE
;
6387 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
);
6396 stub_entry
->stub_sec
->_cooked_size
+= size
;
6398 if (htab
->emit_stub_syms
6399 && !(stub_entry
->stub_type
== ppc_stub_plt_call
6400 && stub_entry
->h
->oh
->root
.type
== bfd_link_hash_defined
6401 && stub_entry
->h
->oh
->root
.u
.def
.section
== stub_entry
->stub_sec
6402 && stub_entry
->h
->oh
->root
.u
.def
.value
== stub_entry
->stub_offset
))
6404 struct elf_link_hash_entry
*h
;
6405 h
= elf_link_hash_lookup (&htab
->elf
, stub_entry
->root
.string
,
6406 TRUE
, FALSE
, FALSE
);
6409 if (h
->root
.type
== bfd_link_hash_new
)
6411 h
->root
.type
= bfd_link_hash_defined
;
6412 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
6413 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
6414 h
->elf_link_hash_flags
= (ELF_LINK_HASH_REF_REGULAR
6415 | ELF_LINK_HASH_DEF_REGULAR
6416 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6417 | ELF_LINK_FORCED_LOCAL
);
6424 /* As above, but don't actually build the stub. Just bump offset so
6425 we know stub section sizes, and select plt_branch stubs where
6426 long_branch stubs won't do. */
6429 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6431 struct ppc_stub_hash_entry
*stub_entry
;
6432 struct bfd_link_info
*info
;
6433 struct ppc_link_hash_table
*htab
;
6437 /* Massage our args to the form they really have. */
6438 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6441 htab
= ppc_hash_table (info
);
6443 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
6445 struct plt_entry
*ent
;
6447 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6448 if (ent
->addend
== stub_entry
->addend
)
6450 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
6453 if (off
>= (bfd_vma
) -2)
6455 off
+= (htab
->plt
->output_offset
6456 + htab
->plt
->output_section
->vma
6457 - elf_gp (htab
->plt
->output_section
->owner
)
6458 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6460 size
= PLT_CALL_STUB_SIZE
;
6461 if (PPC_HA (off
+ 16) != PPC_HA (off
))
6466 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
6468 off
= (stub_entry
->target_value
6469 + stub_entry
->target_section
->output_offset
6470 + stub_entry
->target_section
->output_section
->vma
);
6471 off
-= (stub_entry
->stub_sec
->_raw_size
6472 + stub_entry
->stub_sec
->output_offset
6473 + stub_entry
->stub_sec
->output_section
->vma
);
6475 /* Reset the stub type from the plt variant in case we now
6476 can reach with a shorter stub. */
6477 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
6478 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
6481 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
6487 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
6488 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
6490 struct ppc_branch_hash_entry
*br_entry
;
6492 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6493 stub_entry
->root
.string
+ 9,
6495 if (br_entry
== NULL
)
6497 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
6498 stub_entry
->root
.string
+ 9);
6499 htab
->stub_error
= TRUE
;
6503 if (br_entry
->iter
!= htab
->stub_iteration
)
6505 br_entry
->iter
= htab
->stub_iteration
;
6506 br_entry
->offset
= htab
->brlt
->_raw_size
;
6507 htab
->brlt
->_raw_size
+= 8;
6510 htab
->relbrlt
->_raw_size
+= sizeof (Elf64_External_Rela
);
6513 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
6515 if (stub_entry
->stub_type
!= ppc_stub_plt_branch
)
6520 stub_entry
->stub_sec
->_raw_size
+= size
;
6524 /* Set up various things so that we can make a list of input sections
6525 for each output section included in the link. Returns -1 on error,
6526 0 when no stubs will be needed, and 1 on success. */
6529 ppc64_elf_setup_section_lists (bfd
*output_bfd
, struct bfd_link_info
*info
)
6532 int top_id
, top_index
, id
;
6534 asection
**input_list
;
6536 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6538 if (htab
->brlt
== NULL
)
6541 /* Find the top input section id. */
6542 for (input_bfd
= info
->input_bfds
, top_id
= 3;
6544 input_bfd
= input_bfd
->link_next
)
6546 for (section
= input_bfd
->sections
;
6548 section
= section
->next
)
6550 if (top_id
< section
->id
)
6551 top_id
= section
->id
;
6555 htab
->top_id
= top_id
;
6556 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
6557 htab
->stub_group
= bfd_zmalloc (amt
);
6558 if (htab
->stub_group
== NULL
)
6561 /* Set toc_off for com, und, abs and ind sections. */
6562 for (id
= 0; id
< 3; id
++)
6563 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
6565 elf_gp (output_bfd
) = htab
->toc_curr
= ppc64_elf_toc (output_bfd
);
6567 /* We can't use output_bfd->section_count here to find the top output
6568 section index as some sections may have been removed, and
6569 _bfd_strip_section_from_output doesn't renumber the indices. */
6570 for (section
= output_bfd
->sections
, top_index
= 0;
6572 section
= section
->next
)
6574 if (top_index
< section
->index
)
6575 top_index
= section
->index
;
6578 htab
->top_index
= top_index
;
6579 amt
= sizeof (asection
*) * (top_index
+ 1);
6580 input_list
= bfd_zmalloc (amt
);
6581 htab
->input_list
= input_list
;
6582 if (input_list
== NULL
)
6588 /* The linker repeatedly calls this function for each TOC input section
6589 and linker generated GOT section. Group input bfds such that the toc
6590 within a group is less than 64k in size. Will break with cute linker
6591 scripts that play games with dot in the output toc section. */
6594 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
6596 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6598 if (!htab
->no_multi_toc
)
6600 bfd_vma addr
= isec
->output_offset
+ isec
->output_section
->vma
;
6601 bfd_vma off
= addr
- htab
->toc_curr
;
6602 if (off
+ isec
->_raw_size
> 0x10000)
6604 htab
->toc_curr
= addr
;
6605 htab
->multi_toc_needed
= 1;
6607 elf_gp (isec
->owner
) = (htab
->toc_curr
6608 - elf_gp (isec
->output_section
->owner
)
6613 /* Called after the last call to the above function. */
6616 ppc64_elf_reinit_toc (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6617 struct bfd_link_info
*info
)
6619 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6621 /* toc_curr tracks the TOC offset used for code sections below in
6622 ppc64_elf_next_input_section. Start off at 0x8000. */
6623 htab
->toc_curr
= TOC_BASE_OFF
;
6626 /* No toc references were found in ISEC. If the code in ISEC makes no
6627 calls, then there's no need to use toc adjusting stubs when branching
6628 into ISEC. Actually, indirect calls from ISEC are OK as they will
6632 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
6639 /* We know none of our code bearing sections will need toc stubs. */
6640 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
6643 if (isec
->_raw_size
== 0)
6646 /* Hack for linux kernel. .fixup contains branches, but only back to
6647 the function that hit an exception. */
6648 branch_ok
= strcmp (isec
->name
, ".fixup") == 0;
6650 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6651 if (contents
== NULL
)
6653 contents
= bfd_malloc (isec
->_raw_size
);
6654 if (contents
== NULL
)
6656 if (! bfd_get_section_contents (isec
->owner
, isec
, contents
,
6657 0, isec
->_raw_size
))
6662 if (info
->keep_memory
)
6663 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6666 /* Code scan, because we don't necessarily have relocs on calls to
6667 static functions. */
6669 for (i
= 0; i
< isec
->_raw_size
; i
+= 4)
6671 unsigned long insn
= bfd_get_32 (isec
->owner
, contents
+ i
);
6672 /* Is this a branch? */
6673 if ((insn
& (0x3f << 26)) == (18 << 26)
6674 /* If branch and link, it's a function call. */
6676 /* Sibling calls use a plain branch. I don't know a way
6677 of deciding whether a branch is really a sibling call. */
6685 if (elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6690 /* The linker repeatedly calls this function for each input section,
6691 in the order that input sections are linked into output sections.
6692 Build lists of input sections to determine groupings between which
6693 we may insert linker stubs. */
6696 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
6698 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6701 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
6702 && isec
->output_section
->index
<= htab
->top_index
)
6704 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
6705 /* Steal the link_sec pointer for our list. */
6706 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
6707 /* This happens to make the list in reverse order,
6708 which is what we want. */
6709 PREV_SEC (isec
) = *list
;
6713 /* If a code section has a function that uses the TOC then we need
6714 to use the right TOC (obviously). Also, make sure that .opd gets
6715 the correct TOC value for R_PPC64_TOC relocs that don't have or
6716 can't find their function symbol (shouldn't ever happen now). */
6717 if (isec
->has_gp_reloc
|| (isec
->flags
& SEC_CODE
) == 0)
6719 if (elf_gp (isec
->owner
) != 0)
6720 htab
->toc_curr
= elf_gp (isec
->owner
);
6722 else if ((ret
= toc_adjusting_stub_needed (info
, isec
)) < 0)
6725 isec
->has_gp_reloc
= ret
;
6727 /* Functions that don't use the TOC can belong in any TOC group.
6728 Use the last TOC base. This happens to make _init and _fini
6730 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
6734 /* See whether we can group stub sections together. Grouping stub
6735 sections may result in fewer stubs. More importantly, we need to
6736 put all .init* and .fini* stubs at the beginning of the .init or
6737 .fini output sections respectively, because glibc splits the
6738 _init and _fini functions into multiple parts. Putting a stub in
6739 the middle of a function is not a good idea. */
6742 group_sections (struct ppc_link_hash_table
*htab
,
6743 bfd_size_type stub_group_size
,
6744 bfd_boolean stubs_always_before_branch
)
6746 asection
**list
= htab
->input_list
+ htab
->top_index
;
6749 asection
*tail
= *list
;
6750 while (tail
!= NULL
)
6754 bfd_size_type total
;
6755 bfd_boolean big_sec
;
6759 if (tail
->_cooked_size
)
6760 total
= tail
->_cooked_size
;
6762 total
= tail
->_raw_size
;
6763 big_sec
= total
>= stub_group_size
;
6764 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
6766 while ((prev
= PREV_SEC (curr
)) != NULL
6767 && ((total
+= curr
->output_offset
- prev
->output_offset
)
6769 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
6772 /* OK, the size from the start of CURR to the end is less
6773 than stub_group_size and thus can be handled by one stub
6774 section. (or the tail section is itself larger than
6775 stub_group_size, in which case we may be toast.) We
6776 should really be keeping track of the total size of stubs
6777 added here, as stubs contribute to the final output
6778 section size. That's a little tricky, and this way will
6779 only break if stubs added make the total size more than
6780 2^25, ie. for the default stub_group_size, if stubs total
6781 more than 2097152 bytes, or nearly 75000 plt call stubs. */
6784 prev
= PREV_SEC (tail
);
6785 /* Set up this stub group. */
6786 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6788 while (tail
!= curr
&& (tail
= prev
) != NULL
);
6790 /* But wait, there's more! Input sections up to stub_group_size
6791 bytes before the stub section can be handled by it too.
6792 Don't do this if we have a really large section after the
6793 stubs, as adding more stubs increases the chance that
6794 branches may not reach into the stub section. */
6795 if (!stubs_always_before_branch
&& !big_sec
)
6799 && ((total
+= tail
->output_offset
- prev
->output_offset
)
6801 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
6804 prev
= PREV_SEC (tail
);
6805 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6811 while (list
-- != htab
->input_list
);
6812 free (htab
->input_list
);
6816 /* Determine and set the size of the stub section for a final link.
6818 The basic idea here is to examine all the relocations looking for
6819 PC-relative calls to a target that is unreachable with a "bl"
6823 ppc64_elf_size_stubs (bfd
*output_bfd
,
6824 struct bfd_link_info
*info
,
6825 bfd_signed_vma group_size
,
6826 asection
*(*add_stub_section
) (const char *, asection
*),
6827 void (*layout_sections_again
) (void))
6829 bfd_size_type stub_group_size
;
6830 bfd_boolean stubs_always_before_branch
;
6831 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6833 /* Stash our params away. */
6834 htab
->add_stub_section
= add_stub_section
;
6835 htab
->layout_sections_again
= layout_sections_again
;
6836 stubs_always_before_branch
= group_size
< 0;
6838 stub_group_size
= -group_size
;
6840 stub_group_size
= group_size
;
6841 if (stub_group_size
== 1)
6843 /* Default values. */
6844 if (stubs_always_before_branch
)
6846 stub_group_size
= 0x1e00000;
6847 if (htab
->has_14bit_branch
)
6848 stub_group_size
= 0x7800;
6852 stub_group_size
= 0x1c00000;
6853 if (htab
->has_14bit_branch
)
6854 stub_group_size
= 0x7000;
6858 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
6863 unsigned int bfd_indx
;
6865 bfd_boolean stub_changed
;
6867 htab
->stub_iteration
+= 1;
6868 stub_changed
= FALSE
;
6870 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
6872 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
6874 Elf_Internal_Shdr
*symtab_hdr
;
6876 Elf_Internal_Sym
*local_syms
= NULL
;
6878 /* We'll need the symbol table in a second. */
6879 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6880 if (symtab_hdr
->sh_info
== 0)
6883 /* Walk over each section attached to the input bfd. */
6884 for (section
= input_bfd
->sections
;
6886 section
= section
->next
)
6888 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
6890 /* If there aren't any relocs, then there's nothing more
6892 if ((section
->flags
& SEC_RELOC
) == 0
6893 || section
->reloc_count
== 0)
6896 /* If this section is a link-once section that will be
6897 discarded, then don't create any stubs. */
6898 if (section
->output_section
== NULL
6899 || section
->output_section
->owner
!= output_bfd
)
6902 /* Get the relocs. */
6904 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
6906 if (internal_relocs
== NULL
)
6907 goto error_ret_free_local
;
6909 /* Now examine each relocation. */
6910 irela
= internal_relocs
;
6911 irelaend
= irela
+ section
->reloc_count
;
6912 for (; irela
< irelaend
; irela
++)
6914 enum elf_ppc64_reloc_type r_type
;
6915 unsigned int r_indx
;
6916 enum ppc_stub_type stub_type
;
6917 struct ppc_stub_hash_entry
*stub_entry
;
6920 bfd_vma destination
;
6921 struct ppc_link_hash_entry
*hash
;
6922 struct elf_link_hash_entry
*h
;
6923 Elf_Internal_Sym
*sym
;
6925 const asection
*id_sec
;
6927 r_type
= ELF64_R_TYPE (irela
->r_info
);
6928 r_indx
= ELF64_R_SYM (irela
->r_info
);
6930 if (r_type
>= R_PPC64_max
)
6932 bfd_set_error (bfd_error_bad_value
);
6933 goto error_ret_free_internal
;
6936 /* Only look for stubs on branch instructions. */
6937 if (r_type
!= R_PPC64_REL24
6938 && r_type
!= R_PPC64_REL14
6939 && r_type
!= R_PPC64_REL14_BRTAKEN
6940 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
6943 /* Now determine the call target, its name, value,
6946 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6948 goto error_ret_free_internal
;
6949 hash
= (struct ppc_link_hash_entry
*) h
;
6953 /* It's a local symbol. */
6954 sym_value
= sym
->st_value
;
6955 destination
= (sym_value
+ irela
->r_addend
6956 + sym_sec
->output_offset
6957 + sym_sec
->output_section
->vma
);
6961 /* It's an external symbol. */
6963 if (hash
->elf
.root
.type
== bfd_link_hash_defined
6964 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
6966 sym_value
= hash
->elf
.root
.u
.def
.value
;
6967 if (sym_sec
->output_section
!= NULL
)
6968 destination
= (sym_value
+ irela
->r_addend
6969 + sym_sec
->output_offset
6970 + sym_sec
->output_section
->vma
);
6972 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
6974 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
6978 bfd_set_error (bfd_error_bad_value
);
6979 goto error_ret_free_internal
;
6983 /* Determine what (if any) linker stub is needed. */
6984 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
6987 if (stub_type
!= ppc_stub_plt_call
)
6989 /* Check whether we need a TOC adjusting stub.
6990 Since the linker pastes together pieces from
6991 different object files when creating the
6992 _init and _fini functions, it may be that a
6993 call to what looks like a local sym is in
6994 fact a call needing a TOC adjustment. */
6996 && sym_sec
->output_section
!= NULL
6997 && (htab
->stub_group
[sym_sec
->id
].toc_off
6998 != htab
->stub_group
[section
->id
].toc_off
)
6999 && sym_sec
->has_gp_reloc
7000 && section
->has_gp_reloc
)
7001 stub_type
= ppc_stub_long_branch_r2off
;
7004 if (stub_type
== ppc_stub_none
)
7007 /* __tls_get_addr calls might be eliminated. */
7008 if (stub_type
!= ppc_stub_plt_call
7010 && &hash
->elf
== htab
->tls_get_addr
7011 && section
->has_tls_reloc
7012 && irela
!= internal_relocs
)
7017 if (!get_tls_mask (&tls_mask
, NULL
, &local_syms
,
7018 irela
- 1, input_bfd
))
7019 goto error_ret_free_internal
;
7024 /* Support for grouping stub sections. */
7025 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
7027 /* Get the name of this stub. */
7028 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
7030 goto error_ret_free_internal
;
7032 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
7033 stub_name
, FALSE
, FALSE
);
7034 if (stub_entry
!= NULL
)
7036 /* The proper stub has already been created. */
7041 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
7042 if (stub_entry
== NULL
)
7045 error_ret_free_internal
:
7046 if (elf_section_data (section
)->relocs
== NULL
)
7047 free (internal_relocs
);
7048 error_ret_free_local
:
7049 if (local_syms
!= NULL
7050 && (symtab_hdr
->contents
7051 != (unsigned char *) local_syms
))
7056 stub_entry
->stub_type
= stub_type
;
7057 stub_entry
->target_value
= sym_value
;
7058 stub_entry
->target_section
= sym_sec
;
7059 stub_entry
->h
= hash
;
7060 stub_entry
->addend
= irela
->r_addend
;
7061 stub_changed
= TRUE
;
7064 /* We're done with the internal relocs, free them. */
7065 if (elf_section_data (section
)->relocs
!= internal_relocs
)
7066 free (internal_relocs
);
7069 if (local_syms
!= NULL
7070 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7072 if (!info
->keep_memory
)
7075 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7082 /* OK, we've added some stubs. Find out the new size of the
7084 for (stub_sec
= htab
->stub_bfd
->sections
;
7086 stub_sec
= stub_sec
->next
)
7087 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7089 stub_sec
->_raw_size
= 0;
7090 stub_sec
->_cooked_size
= 0;
7092 htab
->brlt
->_raw_size
= 0;
7093 htab
->brlt
->_cooked_size
= 0;
7096 htab
->relbrlt
->_raw_size
= 0;
7097 htab
->relbrlt
->_cooked_size
= 0;
7100 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
7102 /* Ask the linker to do its stuff. */
7103 (*htab
->layout_sections_again
) ();
7106 /* It would be nice to strip .branch_lt from the output if the
7107 section is empty, but it's too late. If we strip sections here,
7108 the dynamic symbol table is corrupted since the section symbol
7109 for the stripped section isn't written. */
7114 /* Called after we have determined section placement. If sections
7115 move, we'll be called again. Provide a value for TOCstart. */
7118 ppc64_elf_toc (bfd
*obfd
)
7123 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
7124 order. The TOC starts where the first of these sections starts. */
7125 s
= bfd_get_section_by_name (obfd
, ".got");
7127 s
= bfd_get_section_by_name (obfd
, ".toc");
7129 s
= bfd_get_section_by_name (obfd
, ".tocbss");
7131 s
= bfd_get_section_by_name (obfd
, ".plt");
7134 /* This may happen for
7135 o references to TOC base (SYM@toc / TOC[tc0]) without a
7138 o --gc-sections and empty TOC sections
7140 FIXME: Warn user? */
7142 /* Look for a likely section. We probably won't even be
7144 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7145 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
7146 == (SEC_ALLOC
| SEC_SMALL_DATA
))
7149 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7150 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
7151 == (SEC_ALLOC
| SEC_SMALL_DATA
))
7154 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7155 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
7158 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7159 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
7165 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
7170 /* Build all the stubs associated with the current output file.
7171 The stubs are kept in a hash table attached to the main linker
7172 hash table. This function is called via gldelf64ppc_finish. */
7175 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
7176 struct bfd_link_info
*info
,
7179 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7182 int stub_sec_count
= 0;
7184 htab
->emit_stub_syms
= emit_stub_syms
;
7185 for (stub_sec
= htab
->stub_bfd
->sections
;
7187 stub_sec
= stub_sec
->next
)
7188 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7192 /* Allocate memory to hold the linker stubs. */
7193 size
= stub_sec
->_raw_size
;
7196 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
7197 if (stub_sec
->contents
== NULL
)
7200 stub_sec
->_cooked_size
= 0;
7203 if (htab
->plt
!= NULL
)
7208 /* Build the .glink plt call stub. */
7209 plt0
= (htab
->plt
->output_section
->vma
7210 + htab
->plt
->output_offset
7211 - (htab
->glink
->output_section
->vma
7212 + htab
->glink
->output_offset
7213 + GLINK_CALL_STUB_SIZE
));
7214 if (plt0
+ 0x80008000 > 0xffffffff)
7216 (*_bfd_error_handler
) (_(".glink and .plt too far apart"));
7217 bfd_set_error (bfd_error_bad_value
);
7221 if (htab
->emit_stub_syms
)
7223 struct elf_link_hash_entry
*h
;
7224 h
= elf_link_hash_lookup (&htab
->elf
, "__glink", TRUE
, FALSE
, FALSE
);
7227 if (h
->root
.type
== bfd_link_hash_new
)
7229 h
->root
.type
= bfd_link_hash_defined
;
7230 h
->root
.u
.def
.section
= htab
->glink
;
7231 h
->root
.u
.def
.value
= 0;
7232 h
->elf_link_hash_flags
= (ELF_LINK_HASH_REF_REGULAR
7233 | ELF_LINK_HASH_DEF_REGULAR
7234 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
7235 | ELF_LINK_FORCED_LOCAL
);
7238 p
= htab
->glink
->contents
;
7239 bfd_put_32 (htab
->glink
->owner
, MFCTR_R12
, p
);
7241 bfd_put_32 (htab
->glink
->owner
, SLDI_R11_R0_3
, p
);
7243 bfd_put_32 (htab
->glink
->owner
, ADDIC_R2_R0_32K
, p
);
7245 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
7247 bfd_put_32 (htab
->glink
->owner
, SRADI_R2_R2_63
, p
);
7249 bfd_put_32 (htab
->glink
->owner
, SLDI_R11_R0_2
, p
);
7251 bfd_put_32 (htab
->glink
->owner
, AND_R2_R2_R11
, p
);
7253 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
7255 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R12_R2
, p
);
7257 bfd_put_32 (htab
->glink
->owner
, ADDIS_R12_R12
| PPC_HA (plt0
), p
);
7259 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| PPC_LO (plt0
), p
);
7261 bfd_put_32 (htab
->glink
->owner
, ADDI_R12_R12
| PPC_LO (plt0
), p
);
7263 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
7265 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
7267 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
7269 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
7272 /* Build the .glink lazy link call stubs. */
7274 while (p
< htab
->glink
->contents
+ htab
->glink
->_raw_size
)
7278 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
7283 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
7285 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
7288 bfd_put_32 (htab
->glink
->owner
,
7289 B_DOT
| ((htab
->glink
->contents
- p
) & 0x3fffffc), p
);
7293 htab
->glink
->_cooked_size
= p
- htab
->glink
->contents
;
7296 if (htab
->brlt
->_raw_size
!= 0)
7298 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
7299 htab
->brlt
->_raw_size
);
7300 if (htab
->brlt
->contents
== NULL
)
7303 if (info
->shared
&& htab
->relbrlt
->_raw_size
!= 0)
7305 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
7306 htab
->relbrlt
->_raw_size
);
7307 if (htab
->relbrlt
->contents
== NULL
)
7311 /* Build the stubs as directed by the stub hash table. */
7312 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
7314 for (stub_sec
= htab
->stub_bfd
->sections
;
7316 stub_sec
= stub_sec
->next
)
7317 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7319 stub_sec_count
+= 1;
7320 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
7324 if (stub_sec
!= NULL
7325 || htab
->glink
->_raw_size
!= htab
->glink
->_cooked_size
)
7327 htab
->stub_error
= TRUE
;
7328 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
7331 if (htab
->stub_error
)
7336 *stats
= bfd_malloc (500);
7340 sprintf (*stats
, _("linker stubs in %u groups\n"
7343 " long branch %lu\n"
7344 " long toc adj %lu\n"
7347 htab
->stub_count
[ppc_stub_long_branch
- 1],
7348 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
7349 htab
->stub_count
[ppc_stub_plt_branch
- 1],
7350 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
7351 htab
->stub_count
[ppc_stub_plt_call
- 1]);
7356 /* The RELOCATE_SECTION function is called by the ELF backend linker
7357 to handle the relocations for a section.
7359 The relocs are always passed as Rela structures; if the section
7360 actually uses Rel structures, the r_addend field will always be
7363 This function is responsible for adjust the section contents as
7364 necessary, and (if using Rela relocs and generating a
7365 relocatable output file) adjusting the reloc addend as
7368 This function does not have to worry about setting the reloc
7369 address or the reloc symbol index.
7371 LOCAL_SYMS is a pointer to the swapped in local symbols.
7373 LOCAL_SECTIONS is an array giving the section in the input file
7374 corresponding to the st_shndx field of each local symbol.
7376 The global hash table entry for the global symbols can be found
7377 via elf_sym_hashes (input_bfd).
7379 When generating relocatable output, this function must handle
7380 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
7381 going to be the section symbol corresponding to the output
7382 section, which means that the addend must be adjusted
7386 ppc64_elf_relocate_section (bfd
*output_bfd
,
7387 struct bfd_link_info
*info
,
7389 asection
*input_section
,
7391 Elf_Internal_Rela
*relocs
,
7392 Elf_Internal_Sym
*local_syms
,
7393 asection
**local_sections
)
7395 struct ppc_link_hash_table
*htab
;
7396 Elf_Internal_Shdr
*symtab_hdr
;
7397 struct elf_link_hash_entry
**sym_hashes
;
7398 Elf_Internal_Rela
*rel
;
7399 Elf_Internal_Rela
*relend
;
7400 Elf_Internal_Rela outrel
;
7402 struct got_entry
**local_got_ents
;
7404 bfd_boolean ret
= TRUE
;
7406 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
7407 bfd_boolean is_power4
= FALSE
;
7409 if (info
->relocatable
)
7412 /* Initialize howto table if needed. */
7413 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
7416 htab
= ppc_hash_table (info
);
7417 local_got_ents
= elf_local_got_ents (input_bfd
);
7418 TOCstart
= elf_gp (output_bfd
);
7419 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
7420 sym_hashes
= elf_sym_hashes (input_bfd
);
7421 is_opd
= ppc64_elf_section_data (input_section
)->opd
.adjust
!= NULL
;
7424 relend
= relocs
+ input_section
->reloc_count
;
7425 for (; rel
< relend
; rel
++)
7427 enum elf_ppc64_reloc_type r_type
;
7429 bfd_reloc_status_type r
;
7430 Elf_Internal_Sym
*sym
;
7432 struct elf_link_hash_entry
*h
;
7433 struct elf_link_hash_entry
*fdh
;
7434 const char *sym_name
;
7435 unsigned long r_symndx
, toc_symndx
;
7436 char tls_mask
, tls_gd
, tls_type
;
7439 bfd_boolean unresolved_reloc
;
7441 unsigned long insn
, mask
;
7442 struct ppc_stub_hash_entry
*stub_entry
;
7443 bfd_vma max_br_offset
;
7446 r_type
= ELF64_R_TYPE (rel
->r_info
);
7447 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7449 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
7450 symbol of the previous ADDR64 reloc. The symbol gives us the
7451 proper TOC base to use. */
7452 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
7454 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
7456 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
7462 unresolved_reloc
= FALSE
;
7465 if (r_symndx
< symtab_hdr
->sh_info
)
7467 /* It's a local symbol. */
7468 sym
= local_syms
+ r_symndx
;
7469 sec
= local_sections
[r_symndx
];
7470 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
7471 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
7472 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
7473 if (elf_section_data (sec
) != NULL
)
7475 long *opd_sym_adjust
;
7477 opd_sym_adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
7478 if (opd_sym_adjust
!= NULL
)
7479 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
7484 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
7485 r_symndx
, symtab_hdr
, sym_hashes
,
7487 unresolved_reloc
, warned
);
7488 sym_name
= h
->root
.root
.string
;
7492 /* TLS optimizations. Replace instruction sequences and relocs
7493 based on information we collected in tls_optimize. We edit
7494 RELOCS so that --emit-relocs will output something sensible
7495 for the final instruction stream. */
7499 if (IS_PPC64_TLS_RELOC (r_type
))
7502 tls_mask
= ((struct ppc_link_hash_entry
*) h
)->tls_mask
;
7503 else if (local_got_ents
!= NULL
)
7506 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
7507 tls_mask
= lgot_masks
[r_symndx
];
7509 if (tls_mask
== 0 && r_type
== R_PPC64_TLS
)
7511 /* Check for toc tls entries. */
7514 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
7519 tls_mask
= *toc_tls
;
7523 /* Check that tls relocs are used with tls syms, and non-tls
7524 relocs are used with non-tls syms. */
7526 && r_type
!= R_PPC64_NONE
7528 || h
->root
.type
== bfd_link_hash_defined
7529 || h
->root
.type
== bfd_link_hash_defweak
)
7530 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
7532 if (r_type
== R_PPC64_TLS
&& tls_mask
!= 0)
7533 /* R_PPC64_TLS is OK against a symbol in the TOC. */
7536 (*_bfd_error_handler
)
7537 (sym_type
== STT_TLS
7538 ? _("%s(%s+0x%lx): %s used with TLS symbol %s")
7539 : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"),
7540 bfd_archive_filename (input_bfd
),
7541 input_section
->name
,
7542 (long) rel
->r_offset
,
7543 ppc64_elf_howto_table
[r_type
]->name
,
7547 /* Ensure reloc mapping code below stays sane. */
7548 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
7549 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
7550 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
7551 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
7552 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
7553 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
7554 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
7555 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
7556 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
7557 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
7566 case R_PPC64_TOC16_LO
:
7567 case R_PPC64_TOC16_DS
:
7568 case R_PPC64_TOC16_LO_DS
:
7570 /* Check for toc tls entries. */
7574 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
7581 tls_mask
= *toc_tls
;
7582 if (r_type
== R_PPC64_TOC16_DS
7583 || r_type
== R_PPC64_TOC16_LO_DS
)
7586 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
7591 /* If we found a GD reloc pair, then we might be
7592 doing a GD->IE transition. */
7595 tls_gd
= TLS_TPRELGD
;
7596 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7597 goto tls_get_addr_check
;
7599 else if (retval
== 3)
7601 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7602 goto tls_get_addr_check
;
7609 case R_PPC64_GOT_TPREL16_DS
:
7610 case R_PPC64_GOT_TPREL16_LO_DS
:
7612 && (tls_mask
& TLS_TPREL
) == 0)
7615 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
7617 insn
|= 0x3c0d0000; /* addis 0,13,0 */
7618 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
7619 r_type
= R_PPC64_TPREL16_HA
;
7620 if (toc_symndx
!= 0)
7622 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
7623 /* We changed the symbol. Start over in order to
7624 get h, sym, sec etc. right. */
7629 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7635 && (tls_mask
& TLS_TPREL
) == 0)
7638 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7639 if ((insn
& ((0x3f << 26) | (31 << 11)))
7640 == ((31 << 26) | (13 << 11)))
7641 rtra
= insn
& ((1 << 26) - (1 << 16));
7642 else if ((insn
& ((0x3f << 26) | (31 << 16)))
7643 == ((31 << 26) | (13 << 16)))
7644 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
7647 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
7650 else if ((insn
& (31 << 1)) == 23 << 1
7651 && ((insn
& (31 << 6)) < 14 << 6
7652 || ((insn
& (31 << 6)) >= 16 << 6
7653 && (insn
& (31 << 6)) < 24 << 6)))
7654 /* load and store indexed -> dform. */
7655 insn
= (32 | ((insn
>> 6) & 31)) << 26;
7656 else if ((insn
& (31 << 1)) == 21 << 1
7657 && (insn
& (0x1a << 6)) == 0)
7658 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7659 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
7660 | ((insn
>> 6) & 1));
7661 else if ((insn
& (31 << 1)) == 21 << 1
7662 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
7664 insn
= (58 << 26) | 2;
7668 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7669 /* Was PPC64_TLS which sits on insn boundary, now
7670 PPC64_TPREL16_LO which is at insn+2. */
7672 r_type
= R_PPC64_TPREL16_LO
;
7673 if (toc_symndx
!= 0)
7675 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
7676 /* We changed the symbol. Start over in order to
7677 get h, sym, sec etc. right. */
7682 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7686 case R_PPC64_GOT_TLSGD16_HI
:
7687 case R_PPC64_GOT_TLSGD16_HA
:
7688 tls_gd
= TLS_TPRELGD
;
7689 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7693 case R_PPC64_GOT_TLSLD16_HI
:
7694 case R_PPC64_GOT_TLSLD16_HA
:
7695 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7698 if ((tls_mask
& tls_gd
) != 0)
7699 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7700 + R_PPC64_GOT_TPREL16_DS
);
7703 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
7705 r_type
= R_PPC64_NONE
;
7707 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7711 case R_PPC64_GOT_TLSGD16
:
7712 case R_PPC64_GOT_TLSGD16_LO
:
7713 tls_gd
= TLS_TPRELGD
;
7714 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7715 goto tls_get_addr_check
;
7718 case R_PPC64_GOT_TLSLD16
:
7719 case R_PPC64_GOT_TLSLD16_LO
:
7720 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7723 if (rel
+ 1 < relend
)
7725 enum elf_ppc64_reloc_type r_type2
;
7726 unsigned long r_symndx2
;
7727 struct elf_link_hash_entry
*h2
;
7728 bfd_vma insn1
, insn2
, insn3
;
7731 /* The next instruction should be a call to
7732 __tls_get_addr. Peek at the reloc to be sure. */
7733 r_type2
= ELF64_R_TYPE (rel
[1].r_info
);
7734 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
7735 if (r_symndx2
< symtab_hdr
->sh_info
7736 || (r_type2
!= R_PPC64_REL14
7737 && r_type2
!= R_PPC64_REL14_BRTAKEN
7738 && r_type2
!= R_PPC64_REL14_BRNTAKEN
7739 && r_type2
!= R_PPC64_REL24
))
7742 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
7743 while (h2
->root
.type
== bfd_link_hash_indirect
7744 || h2
->root
.type
== bfd_link_hash_warning
)
7745 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
7746 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
7749 /* OK, it checks out. Replace the call. */
7750 offset
= rel
[1].r_offset
;
7751 insn1
= bfd_get_32 (output_bfd
,
7752 contents
+ rel
->r_offset
- 2);
7753 insn3
= bfd_get_32 (output_bfd
,
7754 contents
+ offset
+ 4);
7755 if ((tls_mask
& tls_gd
) != 0)
7758 insn1
&= (1 << 26) - (1 << 2);
7759 insn1
|= 58 << 26; /* ld */
7760 insn2
= 0x7c636a14; /* add 3,3,13 */
7761 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
7762 if ((tls_mask
& TLS_EXPLICIT
) == 0)
7763 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7764 + R_PPC64_GOT_TPREL16_DS
);
7766 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
7767 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7772 insn1
= 0x3c6d0000; /* addis 3,13,0 */
7773 insn2
= 0x38630000; /* addi 3,3,0 */
7776 /* Was an LD reloc. */
7778 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7779 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7781 else if (toc_symndx
!= 0)
7782 r_symndx
= toc_symndx
;
7783 r_type
= R_PPC64_TPREL16_HA
;
7784 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7785 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
7786 R_PPC64_TPREL16_LO
);
7787 rel
[1].r_offset
+= 2;
7790 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
7794 rel
[1].r_offset
+= 4;
7796 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
7797 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7798 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
7799 if (tls_gd
== 0 || toc_symndx
!= 0)
7801 /* We changed the symbol. Start over in order
7802 to get h, sym, sec etc. right. */
7810 case R_PPC64_DTPMOD64
:
7811 if (rel
+ 1 < relend
7812 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
7813 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7815 if ((tls_mask
& TLS_GD
) == 0)
7817 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
7818 if ((tls_mask
& TLS_TPRELGD
) != 0)
7819 r_type
= R_PPC64_TPREL64
;
7822 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
7823 r_type
= R_PPC64_NONE
;
7825 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7830 if ((tls_mask
& TLS_LD
) == 0)
7832 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
7833 r_type
= R_PPC64_NONE
;
7834 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7839 case R_PPC64_TPREL64
:
7840 if ((tls_mask
& TLS_TPREL
) == 0)
7842 r_type
= R_PPC64_NONE
;
7843 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7848 /* Handle other relocations that tweak non-addend part of insn. */
7855 /* Branch taken prediction relocations. */
7856 case R_PPC64_ADDR14_BRTAKEN
:
7857 case R_PPC64_REL14_BRTAKEN
:
7858 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
7861 /* Branch not taken prediction relocations. */
7862 case R_PPC64_ADDR14_BRNTAKEN
:
7863 case R_PPC64_REL14_BRNTAKEN
:
7864 insn
|= bfd_get_32 (output_bfd
,
7865 contents
+ rel
->r_offset
) & ~(0x01 << 21);
7868 /* Set 'a' bit. This is 0b00010 in BO field for branch
7869 on CR(BI) insns (BO == 001at or 011at), and 0b01000
7870 for branch on CTR insns (BO == 1a00t or 1a01t). */
7871 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7873 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7880 from
= (rel
->r_offset
7881 + input_section
->output_offset
7882 + input_section
->output_section
->vma
);
7884 /* Invert 'y' bit if not the default. */
7885 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7889 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7893 /* Calls to functions with a different TOC, such as calls to
7894 shared objects, need to alter the TOC pointer. This is
7895 done using a linkage stub. A REL24 branching to these
7896 linkage stubs needs to be followed by a nop, as the nop
7897 will be replaced with an instruction to restore the TOC
7900 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
7901 && fdh
->plt
.plist
!= NULL
)
7902 || ((fdh
= h
, sec
) != NULL
7903 && sec
->output_section
!= NULL
7904 && (htab
->stub_group
[sec
->id
].toc_off
7905 != htab
->stub_group
[input_section
->id
].toc_off
)))
7906 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
7908 && (stub_entry
->stub_type
== ppc_stub_plt_call
7909 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
7910 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
7912 bfd_boolean can_plt_call
= 0;
7914 if (rel
->r_offset
+ 8 <= input_section
->_cooked_size
)
7916 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
7918 || insn
== CROR_151515
|| insn
== CROR_313131
)
7920 bfd_put_32 (input_bfd
, LD_R2_40R1
,
7921 contents
+ rel
->r_offset
+ 4);
7928 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
7930 /* If this is a plain branch rather than a branch
7931 and link, don't require a nop. */
7932 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7933 if ((insn
& 1) == 0)
7937 && strcmp (h
->root
.root
.string
,
7938 ".__libc_start_main") == 0)
7940 /* Allow crt1 branch to go via a toc adjusting stub. */
7945 if (strcmp (input_section
->output_section
->name
,
7947 || strcmp (input_section
->output_section
->name
,
7949 (*_bfd_error_handler
)
7950 (_("%s(%s+0x%lx): automatic multiple TOCs "
7951 "not supported using your crt files; "
7952 "recompile with -mminimal-toc or upgrade gcc"),
7953 bfd_archive_filename (input_bfd
),
7954 input_section
->name
,
7955 (long) rel
->r_offset
);
7957 (*_bfd_error_handler
)
7958 (_("%s(%s+0x%lx): sibling call optimization to `%s' "
7959 "does not allow automatic multiple TOCs; "
7960 "recompile with -mminimal-toc or "
7961 "-fno-optimize-sibling-calls, "
7962 "or make `%s' extern"),
7963 bfd_archive_filename (input_bfd
),
7964 input_section
->name
,
7965 (long) rel
->r_offset
,
7968 bfd_set_error (bfd_error_bad_value
);
7975 relocation
= (stub_entry
->stub_offset
7976 + stub_entry
->stub_sec
->output_offset
7977 + stub_entry
->stub_sec
->output_section
->vma
);
7978 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
7979 unresolved_reloc
= FALSE
;
7984 && h
->root
.type
== bfd_link_hash_undefweak
7986 && rel
->r_addend
== 0)
7988 /* Tweak calls to undefined weak functions to point at a
7989 blr. We can thus call a weak function without first
7990 checking whether the function is defined. We have a
7991 blr at the end of .sfpr. */
7992 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
7993 relocation
= (htab
->sfpr
->_raw_size
- 4
7994 + htab
->sfpr
->output_offset
7995 + htab
->sfpr
->output_section
->vma
);
7996 from
= (rel
->r_offset
7997 + input_section
->output_offset
7998 + input_section
->output_section
->vma
);
8000 /* But let's not be silly about it. If the blr isn't in
8001 reach, just go to the next instruction. */
8002 if (relocation
- from
+ (1 << 25) >= (1 << 26)
8003 || htab
->sfpr
->_raw_size
== 0)
8004 relocation
= from
+ 4;
8011 addend
= rel
->r_addend
;
8015 (*_bfd_error_handler
)
8016 (_("%s: unknown relocation type %d for symbol %s"),
8017 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
8019 bfd_set_error (bfd_error_bad_value
);
8025 case R_PPC64_GNU_VTINHERIT
:
8026 case R_PPC64_GNU_VTENTRY
:
8029 /* GOT16 relocations. Like an ADDR16 using the symbol's
8030 address in the GOT as relocation value instead of the
8031 symbol's value itself. Also, create a GOT entry for the
8032 symbol and put the symbol value there. */
8033 case R_PPC64_GOT_TLSGD16
:
8034 case R_PPC64_GOT_TLSGD16_LO
:
8035 case R_PPC64_GOT_TLSGD16_HI
:
8036 case R_PPC64_GOT_TLSGD16_HA
:
8037 tls_type
= TLS_TLS
| TLS_GD
;
8040 case R_PPC64_GOT_TLSLD16
:
8041 case R_PPC64_GOT_TLSLD16_LO
:
8042 case R_PPC64_GOT_TLSLD16_HI
:
8043 case R_PPC64_GOT_TLSLD16_HA
:
8044 tls_type
= TLS_TLS
| TLS_LD
;
8047 case R_PPC64_GOT_TPREL16_DS
:
8048 case R_PPC64_GOT_TPREL16_LO_DS
:
8049 case R_PPC64_GOT_TPREL16_HI
:
8050 case R_PPC64_GOT_TPREL16_HA
:
8051 tls_type
= TLS_TLS
| TLS_TPREL
;
8054 case R_PPC64_GOT_DTPREL16_DS
:
8055 case R_PPC64_GOT_DTPREL16_LO_DS
:
8056 case R_PPC64_GOT_DTPREL16_HI
:
8057 case R_PPC64_GOT_DTPREL16_HA
:
8058 tls_type
= TLS_TLS
| TLS_DTPREL
;
8062 case R_PPC64_GOT16_LO
:
8063 case R_PPC64_GOT16_HI
:
8064 case R_PPC64_GOT16_HA
:
8065 case R_PPC64_GOT16_DS
:
8066 case R_PPC64_GOT16_LO_DS
:
8069 /* Relocation is to the entry for this symbol in the global
8074 unsigned long indx
= 0;
8076 if (tls_type
== (TLS_TLS
| TLS_LD
)
8078 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
8079 offp
= &ppc64_tlsld_got (input_bfd
)->offset
;
8082 struct got_entry
*ent
;
8086 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
8087 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
8089 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
8090 /* This is actually a static link, or it is a
8091 -Bsymbolic link and the symbol is defined
8092 locally, or the symbol was forced to be local
8093 because of a version file. */
8098 unresolved_reloc
= FALSE
;
8104 if (local_got_ents
== NULL
)
8106 ent
= local_got_ents
[r_symndx
];
8109 for (; ent
!= NULL
; ent
= ent
->next
)
8110 if (ent
->addend
== rel
->r_addend
8111 && ent
->owner
== input_bfd
8112 && ent
->tls_type
== tls_type
)
8116 offp
= &ent
->got
.offset
;
8119 got
= ppc64_elf_tdata (input_bfd
)->got
;
8123 /* The offset must always be a multiple of 8. We use the
8124 least significant bit to record whether we have already
8125 processed this entry. */
8131 /* Generate relocs for the dynamic linker, except in
8132 the case of TLSLD where we'll use one entry per
8134 asection
*relgot
= ppc64_elf_tdata (input_bfd
)->relgot
;
8137 if ((info
->shared
|| indx
!= 0)
8139 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8140 || h
->root
.type
!= bfd_link_hash_undefweak
))
8142 outrel
.r_offset
= (got
->output_section
->vma
8143 + got
->output_offset
8145 outrel
.r_addend
= rel
->r_addend
;
8146 if (tls_type
& (TLS_LD
| TLS_GD
))
8148 outrel
.r_addend
= 0;
8149 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
8150 if (tls_type
== (TLS_TLS
| TLS_GD
))
8152 loc
= relgot
->contents
;
8153 loc
+= (relgot
->reloc_count
++
8154 * sizeof (Elf64_External_Rela
));
8155 bfd_elf64_swap_reloca_out (output_bfd
,
8157 outrel
.r_offset
+= 8;
8158 outrel
.r_addend
= rel
->r_addend
;
8160 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
8163 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
8164 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
8165 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
8166 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
8169 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
8171 /* Write the .got section contents for the sake
8173 loc
= got
->contents
+ off
;
8174 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
8178 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
8180 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
8182 outrel
.r_addend
+= relocation
;
8183 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
8184 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
8186 loc
= relgot
->contents
;
8187 loc
+= (relgot
->reloc_count
++
8188 * sizeof (Elf64_External_Rela
));
8189 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
8192 /* Init the .got section contents here if we're not
8193 emitting a reloc. */
8196 relocation
+= rel
->r_addend
;
8197 if (tls_type
== (TLS_TLS
| TLS_LD
))
8199 else if (tls_type
!= 0)
8201 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8202 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
8203 relocation
+= DTP_OFFSET
- TP_OFFSET
;
8205 if (tls_type
== (TLS_TLS
| TLS_GD
))
8207 bfd_put_64 (output_bfd
, relocation
,
8208 got
->contents
+ off
+ 8);
8213 bfd_put_64 (output_bfd
, relocation
,
8214 got
->contents
+ off
);
8218 if (off
>= (bfd_vma
) -2)
8221 relocation
= got
->output_offset
+ off
;
8223 /* TOC base (r2) is TOC start plus 0x8000. */
8224 addend
= -TOC_BASE_OFF
;
8228 case R_PPC64_PLT16_HA
:
8229 case R_PPC64_PLT16_HI
:
8230 case R_PPC64_PLT16_LO
:
8233 /* Relocation is to the entry for this symbol in the
8234 procedure linkage table. */
8236 /* Resolve a PLT reloc against a local symbol directly,
8237 without using the procedure linkage table. */
8241 /* It's possible that we didn't make a PLT entry for this
8242 symbol. This happens when statically linking PIC code,
8243 or when using -Bsymbolic. Go find a match if there is a
8245 if (htab
->plt
!= NULL
)
8247 struct plt_entry
*ent
;
8248 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8249 if (ent
->addend
== rel
->r_addend
8250 && ent
->plt
.offset
!= (bfd_vma
) -1)
8252 relocation
= (htab
->plt
->output_section
->vma
8253 + htab
->plt
->output_offset
8255 unresolved_reloc
= FALSE
;
8261 /* Relocation value is TOC base. */
8262 relocation
= TOCstart
;
8264 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
8265 else if (unresolved_reloc
)
8267 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
8268 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
8270 unresolved_reloc
= TRUE
;
8273 /* TOC16 relocs. We want the offset relative to the TOC base,
8274 which is the address of the start of the TOC plus 0x8000.
8275 The TOC consists of sections .got, .toc, .tocbss, and .plt,
8278 case R_PPC64_TOC16_LO
:
8279 case R_PPC64_TOC16_HI
:
8280 case R_PPC64_TOC16_DS
:
8281 case R_PPC64_TOC16_LO_DS
:
8282 case R_PPC64_TOC16_HA
:
8283 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
8286 /* Relocate against the beginning of the section. */
8287 case R_PPC64_SECTOFF
:
8288 case R_PPC64_SECTOFF_LO
:
8289 case R_PPC64_SECTOFF_HI
:
8290 case R_PPC64_SECTOFF_DS
:
8291 case R_PPC64_SECTOFF_LO_DS
:
8292 case R_PPC64_SECTOFF_HA
:
8294 addend
-= sec
->output_section
->vma
;
8298 case R_PPC64_REL14_BRNTAKEN
:
8299 case R_PPC64_REL14_BRTAKEN
:
8303 case R_PPC64_TPREL16
:
8304 case R_PPC64_TPREL16_LO
:
8305 case R_PPC64_TPREL16_HI
:
8306 case R_PPC64_TPREL16_HA
:
8307 case R_PPC64_TPREL16_DS
:
8308 case R_PPC64_TPREL16_LO_DS
:
8309 case R_PPC64_TPREL16_HIGHER
:
8310 case R_PPC64_TPREL16_HIGHERA
:
8311 case R_PPC64_TPREL16_HIGHEST
:
8312 case R_PPC64_TPREL16_HIGHESTA
:
8313 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8315 /* The TPREL16 relocs shouldn't really be used in shared
8316 libs as they will result in DT_TEXTREL being set, but
8317 support them anyway. */
8321 case R_PPC64_DTPREL16
:
8322 case R_PPC64_DTPREL16_LO
:
8323 case R_PPC64_DTPREL16_HI
:
8324 case R_PPC64_DTPREL16_HA
:
8325 case R_PPC64_DTPREL16_DS
:
8326 case R_PPC64_DTPREL16_LO_DS
:
8327 case R_PPC64_DTPREL16_HIGHER
:
8328 case R_PPC64_DTPREL16_HIGHERA
:
8329 case R_PPC64_DTPREL16_HIGHEST
:
8330 case R_PPC64_DTPREL16_HIGHESTA
:
8331 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8334 case R_PPC64_DTPMOD64
:
8339 case R_PPC64_TPREL64
:
8340 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8343 case R_PPC64_DTPREL64
:
8344 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8347 /* Relocations that may need to be propagated if this is a
8352 case R_PPC64_ADDR14
:
8353 case R_PPC64_ADDR14_BRNTAKEN
:
8354 case R_PPC64_ADDR14_BRTAKEN
:
8355 case R_PPC64_ADDR16
:
8356 case R_PPC64_ADDR16_DS
:
8357 case R_PPC64_ADDR16_HA
:
8358 case R_PPC64_ADDR16_HI
:
8359 case R_PPC64_ADDR16_HIGHER
:
8360 case R_PPC64_ADDR16_HIGHERA
:
8361 case R_PPC64_ADDR16_HIGHEST
:
8362 case R_PPC64_ADDR16_HIGHESTA
:
8363 case R_PPC64_ADDR16_LO
:
8364 case R_PPC64_ADDR16_LO_DS
:
8365 case R_PPC64_ADDR24
:
8366 case R_PPC64_ADDR32
:
8367 case R_PPC64_ADDR64
:
8368 case R_PPC64_UADDR16
:
8369 case R_PPC64_UADDR32
:
8370 case R_PPC64_UADDR64
:
8371 /* r_symndx will be zero only for relocs against symbols
8372 from removed linkonce sections, or sections discarded by
8380 if ((input_section
->flags
& SEC_ALLOC
) == 0)
8383 if (NO_OPD_RELOCS
&& is_opd
)
8388 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8389 || h
->root
.type
!= bfd_link_hash_undefweak
)
8390 && (MUST_BE_DYN_RELOC (r_type
)
8391 || !SYMBOL_CALLS_LOCAL (info
, h
)))
8392 || (ELIMINATE_COPY_RELOCS
8396 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
8397 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
8398 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
8400 Elf_Internal_Rela outrel
;
8401 bfd_boolean skip
, relocate
;
8406 /* When generating a dynamic object, these relocations
8407 are copied into the output file to be resolved at run
8413 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
8414 input_section
, rel
->r_offset
);
8415 if (out_off
== (bfd_vma
) -1)
8417 else if (out_off
== (bfd_vma
) -2)
8418 skip
= TRUE
, relocate
= TRUE
;
8419 out_off
+= (input_section
->output_section
->vma
8420 + input_section
->output_offset
);
8421 outrel
.r_offset
= out_off
;
8422 outrel
.r_addend
= rel
->r_addend
;
8424 /* Optimize unaligned reloc use. */
8425 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
8426 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
8427 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
8428 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
8429 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
8430 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
8431 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
8432 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
8433 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
8436 memset (&outrel
, 0, sizeof outrel
);
8437 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
8439 && r_type
!= R_PPC64_TOC
)
8440 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
8443 /* This symbol is local, or marked to become local,
8444 or this is an opd section reloc which must point
8445 at a local function. */
8446 outrel
.r_addend
+= relocation
;
8447 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
8449 if (is_opd
&& h
!= NULL
)
8451 /* Lie about opd entries. This case occurs
8452 when building shared libraries and we
8453 reference a function in another shared
8454 lib. The same thing happens for a weak
8455 definition in an application that's
8456 overridden by a strong definition in a
8457 shared lib. (I believe this is a generic
8458 bug in binutils handling of weak syms.)
8459 In these cases we won't use the opd
8460 entry in this lib. */
8461 unresolved_reloc
= FALSE
;
8463 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8465 /* We need to relocate .opd contents for ld.so.
8466 Prelink also wants simple and consistent rules
8467 for relocs. This make all RELATIVE relocs have
8468 *r_offset equal to r_addend. */
8475 if (bfd_is_abs_section (sec
))
8477 else if (sec
== NULL
|| sec
->owner
== NULL
)
8479 bfd_set_error (bfd_error_bad_value
);
8486 osec
= sec
->output_section
;
8487 indx
= elf_section_data (osec
)->dynindx
;
8489 /* We are turning this relocation into one
8490 against a section symbol, so subtract out
8491 the output section's address but not the
8492 offset of the input section in the output
8494 outrel
.r_addend
-= osec
->vma
;
8497 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
8501 sreloc
= elf_section_data (input_section
)->sreloc
;
8505 loc
= sreloc
->contents
;
8506 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8507 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
8509 /* If this reloc is against an external symbol, it will
8510 be computed at runtime, so there's no need to do
8511 anything now. However, for the sake of prelink ensure
8512 that the section contents are a known value. */
8515 unresolved_reloc
= FALSE
;
8516 /* The value chosen here is quite arbitrary as ld.so
8517 ignores section contents except for the special
8518 case of .opd where the contents might be accessed
8519 before relocation. Choose zero, as that won't
8520 cause reloc overflow. */
8523 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
8524 to improve backward compatibility with older
8526 if (r_type
== R_PPC64_ADDR64
)
8527 addend
= outrel
.r_addend
;
8528 /* Adjust pc_relative relocs to have zero in *r_offset. */
8529 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
8530 addend
= (input_section
->output_section
->vma
8531 + input_section
->output_offset
8538 case R_PPC64_GLOB_DAT
:
8539 case R_PPC64_JMP_SLOT
:
8540 case R_PPC64_RELATIVE
:
8541 /* We shouldn't ever see these dynamic relocs in relocatable
8545 case R_PPC64_PLTGOT16
:
8546 case R_PPC64_PLTGOT16_DS
:
8547 case R_PPC64_PLTGOT16_HA
:
8548 case R_PPC64_PLTGOT16_HI
:
8549 case R_PPC64_PLTGOT16_LO
:
8550 case R_PPC64_PLTGOT16_LO_DS
:
8551 case R_PPC64_PLTREL32
:
8552 case R_PPC64_PLTREL64
:
8553 /* These ones haven't been implemented yet. */
8555 (*_bfd_error_handler
)
8556 (_("%s: relocation %s is not supported for symbol %s."),
8557 bfd_archive_filename (input_bfd
),
8558 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
8560 bfd_set_error (bfd_error_invalid_operation
);
8565 /* Do any further special processing. */
8571 case R_PPC64_ADDR16_HA
:
8572 case R_PPC64_ADDR16_HIGHERA
:
8573 case R_PPC64_ADDR16_HIGHESTA
:
8574 case R_PPC64_GOT16_HA
:
8575 case R_PPC64_PLTGOT16_HA
:
8576 case R_PPC64_PLT16_HA
:
8577 case R_PPC64_TOC16_HA
:
8578 case R_PPC64_SECTOFF_HA
:
8579 case R_PPC64_TPREL16_HA
:
8580 case R_PPC64_DTPREL16_HA
:
8581 case R_PPC64_GOT_TLSGD16_HA
:
8582 case R_PPC64_GOT_TLSLD16_HA
:
8583 case R_PPC64_GOT_TPREL16_HA
:
8584 case R_PPC64_GOT_DTPREL16_HA
:
8585 case R_PPC64_TPREL16_HIGHER
:
8586 case R_PPC64_TPREL16_HIGHERA
:
8587 case R_PPC64_TPREL16_HIGHEST
:
8588 case R_PPC64_TPREL16_HIGHESTA
:
8589 case R_PPC64_DTPREL16_HIGHER
:
8590 case R_PPC64_DTPREL16_HIGHERA
:
8591 case R_PPC64_DTPREL16_HIGHEST
:
8592 case R_PPC64_DTPREL16_HIGHESTA
:
8593 /* It's just possible that this symbol is a weak symbol
8594 that's not actually defined anywhere. In that case,
8595 'sec' would be NULL, and we should leave the symbol
8596 alone (it will be set to zero elsewhere in the link). */
8598 /* Add 0x10000 if sign bit in 0:15 is set.
8599 Bits 0:15 are not used. */
8603 case R_PPC64_ADDR16_DS
:
8604 case R_PPC64_ADDR16_LO_DS
:
8605 case R_PPC64_GOT16_DS
:
8606 case R_PPC64_GOT16_LO_DS
:
8607 case R_PPC64_PLT16_LO_DS
:
8608 case R_PPC64_SECTOFF_DS
:
8609 case R_PPC64_SECTOFF_LO_DS
:
8610 case R_PPC64_TOC16_DS
:
8611 case R_PPC64_TOC16_LO_DS
:
8612 case R_PPC64_PLTGOT16_DS
:
8613 case R_PPC64_PLTGOT16_LO_DS
:
8614 case R_PPC64_GOT_TPREL16_DS
:
8615 case R_PPC64_GOT_TPREL16_LO_DS
:
8616 case R_PPC64_GOT_DTPREL16_DS
:
8617 case R_PPC64_GOT_DTPREL16_LO_DS
:
8618 case R_PPC64_TPREL16_DS
:
8619 case R_PPC64_TPREL16_LO_DS
:
8620 case R_PPC64_DTPREL16_DS
:
8621 case R_PPC64_DTPREL16_LO_DS
:
8622 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
8624 /* If this reloc is against an lq insn, then the value must be
8625 a multiple of 16. This is somewhat of a hack, but the
8626 "correct" way to do this by defining _DQ forms of all the
8627 _DS relocs bloats all reloc switches in this file. It
8628 doesn't seem to make much sense to use any of these relocs
8629 in data, so testing the insn should be safe. */
8630 if ((insn
& (0x3f << 26)) == (56u << 26))
8632 if (((relocation
+ addend
) & mask
) != 0)
8634 (*_bfd_error_handler
)
8635 (_("%s: error: relocation %s not a multiple of %d"),
8636 bfd_archive_filename (input_bfd
),
8637 ppc64_elf_howto_table
[r_type
]->name
,
8639 bfd_set_error (bfd_error_bad_value
);
8646 case R_PPC64_REL14_BRNTAKEN
:
8647 case R_PPC64_REL14_BRTAKEN
:
8648 max_br_offset
= 1 << 15;
8652 max_br_offset
= 1 << 25;
8655 /* If the branch is out of reach or the TOC register needs
8656 adjusting, then redirect the call to the local stub for
8658 from
= (rel
->r_offset
8659 + input_section
->output_offset
8660 + input_section
->output_section
->vma
);
8661 if ((relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
8663 && sec
->output_section
!= NULL
8664 && sec
->id
<= htab
->top_id
8665 && (htab
->stub_group
[sec
->id
].toc_off
8666 != htab
->stub_group
[input_section
->id
].toc_off
)))
8667 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
8668 rel
, htab
)) != NULL
)
8670 /* Munge up the value and addend so that we call the stub
8671 rather than the procedure directly. */
8672 relocation
= (stub_entry
->stub_offset
8673 + stub_entry
->stub_sec
->output_offset
8674 + stub_entry
->stub_sec
->output_section
->vma
);
8680 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8681 because such sections are not SEC_ALLOC and thus ld.so will
8682 not process them. */
8683 if (unresolved_reloc
8684 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8685 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
8687 (*_bfd_error_handler
)
8688 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
8689 bfd_archive_filename (input_bfd
),
8690 bfd_get_section_name (input_bfd
, input_section
),
8691 (long) rel
->r_offset
,
8692 ppc64_elf_howto_table
[(int) r_type
]->name
,
8693 h
->root
.root
.string
);
8697 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
8705 if (r
!= bfd_reloc_ok
)
8707 if (sym_name
== NULL
)
8708 sym_name
= "(null)";
8709 if (r
== bfd_reloc_overflow
)
8714 && h
->root
.type
== bfd_link_hash_undefweak
8715 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
8717 /* Assume this is a call protected by other code that
8718 detects the symbol is undefined. If this is the case,
8719 we can safely ignore the overflow. If not, the
8720 program is hosed anyway, and a little warning isn't
8726 if (!((*info
->callbacks
->reloc_overflow
)
8727 (info
, sym_name
, ppc64_elf_howto_table
[r_type
]->name
,
8728 rel
->r_addend
, input_bfd
, input_section
, rel
->r_offset
)))
8733 (*_bfd_error_handler
)
8734 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
8735 bfd_archive_filename (input_bfd
),
8736 bfd_get_section_name (input_bfd
, input_section
),
8737 (long) rel
->r_offset
,
8738 ppc64_elf_howto_table
[r_type
]->name
,
8749 /* Adjust the value of any local symbols in opd sections. */
8752 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
8753 const char *name ATTRIBUTE_UNUSED
,
8754 Elf_Internal_Sym
*elfsym
,
8755 asection
*input_sec
,
8756 struct elf_link_hash_entry
*h
)
8762 || input_sec
== NULL
8763 || ppc64_elf_section_data (input_sec
) == NULL
8764 || (adjust
= ppc64_elf_section_data (input_sec
)->opd
.adjust
) == NULL
)
8767 value
= elfsym
->st_value
- input_sec
->output_offset
;
8768 if (!info
->relocatable
)
8769 value
-= input_sec
->output_section
->vma
;
8771 elfsym
->st_value
+= adjust
[value
/ 24];
8775 /* Finish up dynamic symbol handling. We set the contents of various
8776 dynamic sections here. */
8779 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8780 struct bfd_link_info
*info
,
8781 struct elf_link_hash_entry
*h
,
8782 Elf_Internal_Sym
*sym
)
8784 struct ppc_link_hash_table
*htab
;
8787 htab
= ppc_hash_table (info
);
8788 dynobj
= htab
->elf
.dynobj
;
8790 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
8792 struct plt_entry
*ent
;
8793 Elf_Internal_Rela rela
;
8796 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8797 if (ent
->plt
.offset
!= (bfd_vma
) -1)
8799 /* This symbol has an entry in the procedure linkage
8800 table. Set it up. */
8802 if (htab
->plt
== NULL
8803 || htab
->relplt
== NULL
8804 || htab
->glink
== NULL
)
8807 /* Create a JMP_SLOT reloc to inform the dynamic linker to
8808 fill in the PLT entry. */
8809 rela
.r_offset
= (htab
->plt
->output_section
->vma
8810 + htab
->plt
->output_offset
8812 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
8813 rela
.r_addend
= ent
->addend
;
8815 loc
= htab
->relplt
->contents
;
8816 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
8817 * sizeof (Elf64_External_Rela
));
8818 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8822 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
8824 Elf_Internal_Rela rela
;
8827 /* This symbol needs a copy reloc. Set it up. */
8829 if (h
->dynindx
== -1
8830 || (h
->root
.type
!= bfd_link_hash_defined
8831 && h
->root
.type
!= bfd_link_hash_defweak
)
8832 || htab
->relbss
== NULL
)
8835 rela
.r_offset
= (h
->root
.u
.def
.value
8836 + h
->root
.u
.def
.section
->output_section
->vma
8837 + h
->root
.u
.def
.section
->output_offset
);
8838 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
8840 loc
= htab
->relbss
->contents
;
8841 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8842 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8845 /* Mark some specially defined symbols as absolute. */
8846 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
8847 sym
->st_shndx
= SHN_ABS
;
8852 /* Used to decide how to sort relocs in an optimal manner for the
8853 dynamic linker, before writing them out. */
8855 static enum elf_reloc_type_class
8856 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
8858 enum elf_ppc64_reloc_type r_type
;
8860 r_type
= ELF64_R_TYPE (rela
->r_info
);
8863 case R_PPC64_RELATIVE
:
8864 return reloc_class_relative
;
8865 case R_PPC64_JMP_SLOT
:
8866 return reloc_class_plt
;
8868 return reloc_class_copy
;
8870 return reloc_class_normal
;
8874 /* Finish up the dynamic sections. */
8877 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
8878 struct bfd_link_info
*info
)
8880 struct ppc_link_hash_table
*htab
;
8884 htab
= ppc_hash_table (info
);
8885 dynobj
= htab
->elf
.dynobj
;
8886 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8888 if (htab
->elf
.dynamic_sections_created
)
8890 Elf64_External_Dyn
*dyncon
, *dynconend
;
8892 if (sdyn
== NULL
|| htab
->got
== NULL
)
8895 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
8896 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
8897 for (; dyncon
< dynconend
; dyncon
++)
8899 Elf_Internal_Dyn dyn
;
8902 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8909 case DT_PPC64_GLINK
:
8911 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8912 /* We stupidly defined DT_PPC64_GLINK to be the start
8913 of glink rather than the first entry point, which is
8914 what ld.so needs, and now have a bigger stub to
8915 support automatic multiple TOCs. */
8916 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
8920 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8923 dyn
.d_un
.d_ptr
= s
->vma
;
8926 case DT_PPC64_OPDSZ
:
8927 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8930 dyn
.d_un
.d_val
= s
->_raw_size
;
8935 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8940 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8944 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
8948 /* Don't count procedure linkage table relocs in the
8949 overall reloc count. */
8953 dyn
.d_un
.d_val
-= s
->_raw_size
;
8957 /* We may not be using the standard ELF linker script.
8958 If .rela.plt is the first .rela section, we adjust
8959 DT_RELA to not include it. */
8963 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
8965 dyn
.d_un
.d_ptr
+= s
->_raw_size
;
8969 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8973 if (htab
->got
!= NULL
&& htab
->got
->_raw_size
!= 0)
8975 /* Fill in the first entry in the global offset table.
8976 We use it to hold the link-time TOCbase. */
8977 bfd_put_64 (output_bfd
,
8978 elf_gp (output_bfd
) + TOC_BASE_OFF
,
8979 htab
->got
->contents
);
8981 /* Set .got entry size. */
8982 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
8985 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
8987 /* Set .plt entry size. */
8988 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
8992 /* We need to handle writing out multiple GOT sections ourselves,
8993 since we didn't add them to DYNOBJ. */
8994 while ((dynobj
= dynobj
->link_next
) != NULL
)
8997 s
= ppc64_elf_tdata (dynobj
)->got
;
8999 && s
->_raw_size
!= 0
9000 && s
->output_section
!= bfd_abs_section_ptr
9001 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
9002 s
->contents
, s
->output_offset
,
9005 s
= ppc64_elf_tdata (dynobj
)->relgot
;
9007 && s
->_raw_size
!= 0
9008 && s
->output_section
!= bfd_abs_section_ptr
9009 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
9010 s
->contents
, s
->output_offset
,
9018 #include "elf64-target.h"