1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor, Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the
21 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 /* This file is based on a preliminary PowerPC ELF ABI. The
26 information may not match the final PowerPC ELF ABI. It includes
27 suggestions from the in-progress Embedded PowerPC ABI, and that
28 information may also not match. */
37 #include "elf32-ppc.h"
38 #include "elf-vxworks.h"
41 typedef enum split16_format_type
48 /* RELA relocations are used here. */
50 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
51 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
52 static bfd_reloc_status_type ppc_elf_unhandled_reloc
53 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
54 static void ppc_elf_vle_split16
55 (bfd *, bfd_byte *, bfd_vma, bfd_vma, split16_format_type);
57 /* Branch prediction bit for branch taken relocs. */
58 #define BRANCH_PREDICT_BIT 0x200000
59 /* Mask to set RA in memory instructions. */
60 #define RA_REGISTER_MASK 0x001f0000
61 /* Value to shift register by to insert RA. */
62 #define RA_REGISTER_SHIFT 16
64 /* The name of the dynamic interpreter. This is put in the .interp
66 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
68 /* For old-style PLT. */
69 /* The number of single-slot PLT entries (the rest use two slots). */
70 #define PLT_NUM_SINGLE_ENTRIES 8192
72 /* For new-style .glink and .plt. */
73 #define GLINK_PLTRESOLVE 16*4
74 #define GLINK_ENTRY_SIZE 4*4
75 #define TLS_GET_ADDR_GLINK_SIZE 12*4
77 /* VxWorks uses its own plt layout, filled in by the static linker. */
79 /* The standard VxWorks PLT entry. */
80 #define VXWORKS_PLT_ENTRY_SIZE 32
81 static const bfd_vma ppc_elf_vxworks_plt_entry
82 [VXWORKS_PLT_ENTRY_SIZE / 4] =
84 0x3d800000, /* lis r12,0 */
85 0x818c0000, /* lwz r12,0(r12) */
86 0x7d8903a6, /* mtctr r12 */
87 0x4e800420, /* bctr */
88 0x39600000, /* li r11,0 */
89 0x48000000, /* b 14 <.PLT0resolve+0x4> */
93 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
94 [VXWORKS_PLT_ENTRY_SIZE / 4] =
96 0x3d9e0000, /* addis r12,r30,0 */
97 0x818c0000, /* lwz r12,0(r12) */
98 0x7d8903a6, /* mtctr r12 */
99 0x4e800420, /* bctr */
100 0x39600000, /* li r11,0 */
101 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
102 0x60000000, /* nop */
103 0x60000000, /* nop */
106 /* The initial VxWorks PLT entry. */
107 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
108 static const bfd_vma ppc_elf_vxworks_plt0_entry
109 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
111 0x3d800000, /* lis r12,0 */
112 0x398c0000, /* addi r12,r12,0 */
113 0x800c0008, /* lwz r0,8(r12) */
114 0x7c0903a6, /* mtctr r0 */
115 0x818c0004, /* lwz r12,4(r12) */
116 0x4e800420, /* bctr */
117 0x60000000, /* nop */
118 0x60000000, /* nop */
120 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
121 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
123 0x819e0008, /* lwz r12,8(r30) */
124 0x7d8903a6, /* mtctr r12 */
125 0x819e0004, /* lwz r12,4(r30) */
126 0x4e800420, /* bctr */
127 0x60000000, /* nop */
128 0x60000000, /* nop */
129 0x60000000, /* nop */
130 0x60000000, /* nop */
133 /* For executables, we have some additional relocations in
134 .rela.plt.unloaded, for the kernel loader. */
136 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
137 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
138 /* The number of relocations in the PLTResolve slot. */
139 #define VXWORKS_PLTRESOLVE_RELOCS 2
140 /* The number of relocations in the PLTResolve slot when when creating
142 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
144 /* Some instructions. */
145 #define ADDIS_11_11 0x3d6b0000
146 #define ADDIS_11_30 0x3d7e0000
147 #define ADDIS_12_12 0x3d8c0000
148 #define ADDI_11_11 0x396b0000
149 #define ADD_0_11_11 0x7c0b5a14
150 #define ADD_3_12_2 0x7c6c1214
151 #define ADD_11_0_11 0x7d605a14
153 #define BCL_20_31 0x429f0005
154 #define BCTR 0x4e800420
155 #define BEQLR 0x4d820020
156 #define CMPWI_11_0 0x2c0b0000
157 #define LIS_11 0x3d600000
158 #define LIS_12 0x3d800000
159 #define LWZU_0_12 0x840c0000
160 #define LWZ_0_12 0x800c0000
161 #define LWZ_11_3 0x81630000
162 #define LWZ_11_11 0x816b0000
163 #define LWZ_11_30 0x817e0000
164 #define LWZ_12_3 0x81830000
165 #define LWZ_12_12 0x818c0000
166 #define MR_0_3 0x7c601b78
167 #define MR_3_0 0x7c030378
168 #define MFLR_0 0x7c0802a6
169 #define MFLR_12 0x7d8802a6
170 #define MTCTR_0 0x7c0903a6
171 #define MTCTR_11 0x7d6903a6
172 #define MTLR_0 0x7c0803a6
173 #define NOP 0x60000000
174 #define SUB_11_11_12 0x7d6c5850
176 /* Offset of tp and dtp pointers from start of TLS block. */
177 #define TP_OFFSET 0x7000
178 #define DTP_OFFSET 0x8000
180 /* The value of a defined global symbol. */
181 #define SYM_VAL(SYM) \
182 ((SYM)->root.u.def.section->output_section->vma \
183 + (SYM)->root.u.def.section->output_offset \
184 + (SYM)->root.u.def.value)
186 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
188 static reloc_howto_type ppc_elf_howto_raw[] = {
189 /* This reloc does nothing. */
190 HOWTO (R_PPC_NONE, /* type */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
194 FALSE, /* pc_relative */
196 complain_overflow_bitfield, /* complain_on_overflow */
197 bfd_elf_generic_reloc, /* special_function */
198 "R_PPC_NONE", /* name */
199 FALSE, /* partial_inplace */
202 FALSE), /* pcrel_offset */
204 /* A standard 32 bit relocation. */
205 HOWTO (R_PPC_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_PPC_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_PPC_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_PPC_ADDR24", /* name */
230 FALSE, /* partial_inplace */
232 0x3fffffc, /* dst_mask */
233 FALSE), /* pcrel_offset */
235 /* A standard 16 bit relocation. */
236 HOWTO (R_PPC_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_PPC_ADDR16", /* name */
245 FALSE, /* partial_inplace */
247 0xffff, /* dst_mask */
248 FALSE), /* pcrel_offset */
250 /* A 16 bit relocation without overflow. */
251 HOWTO (R_PPC_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_PPC_ADDR16_LO", /* name */
260 FALSE, /* partial_inplace */
262 0xffff, /* dst_mask */
263 FALSE), /* pcrel_offset */
265 /* The high order 16 bits of an address. */
266 HOWTO (R_PPC_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_PPC_ADDR16_HI", /* name */
275 FALSE, /* partial_inplace */
277 0xffff, /* dst_mask */
278 FALSE), /* pcrel_offset */
280 /* The high order 16 bits of an address, plus 1 if the contents of
281 the low 16 bits, treated as a signed number, is negative. */
282 HOWTO (R_PPC_ADDR16_HA, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE, /* pc_relative */
288 complain_overflow_dont, /* complain_on_overflow */
289 ppc_elf_addr16_ha_reloc, /* special_function */
290 "R_PPC_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_PPC_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_PPC_ADDR14", /* name */
307 FALSE, /* partial_inplace */
309 0xfffc, /* 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_PPC_ADDR14_BRTAKEN, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE, /* pc_relative */
321 complain_overflow_bitfield, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_PPC_ADDR14_BRTAKEN",/* name */
324 FALSE, /* partial_inplace */
326 0xfffc, /* 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_PPC_ADDR14_BRNTAKEN, /* type */
334 2, /* size (0 = byte, 1 = short, 2 = long) */
336 FALSE, /* pc_relative */
338 complain_overflow_bitfield, /* complain_on_overflow */
339 bfd_elf_generic_reloc, /* special_function */
340 "R_PPC_ADDR14_BRNTAKEN",/* name */
341 FALSE, /* partial_inplace */
343 0xfffc, /* dst_mask */
344 FALSE), /* pcrel_offset */
346 /* A relative 26 bit branch; the lower two bits must be zero. */
347 HOWTO (R_PPC_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_PPC_REL24", /* name */
356 FALSE, /* partial_inplace */
358 0x3fffffc, /* dst_mask */
359 TRUE), /* pcrel_offset */
361 /* A relative 16 bit branch; the lower two bits must be zero. */
362 HOWTO (R_PPC_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_PPC_REL14", /* name */
371 FALSE, /* partial_inplace */
373 0xfffc, /* 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_PPC_REL14_BRTAKEN, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 TRUE, /* pc_relative */
385 complain_overflow_signed, /* complain_on_overflow */
386 bfd_elf_generic_reloc, /* special_function */
387 "R_PPC_REL14_BRTAKEN", /* name */
388 FALSE, /* partial_inplace */
390 0xfffc, /* 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_PPC_REL14_BRNTAKEN, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 TRUE, /* pc_relative */
402 complain_overflow_signed, /* complain_on_overflow */
403 bfd_elf_generic_reloc, /* special_function */
404 "R_PPC_REL14_BRNTAKEN",/* name */
405 FALSE, /* partial_inplace */
407 0xfffc, /* dst_mask */
408 TRUE), /* pcrel_offset */
410 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
412 HOWTO (R_PPC_GOT16, /* type */
414 1, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE, /* pc_relative */
418 complain_overflow_signed, /* complain_on_overflow */
419 bfd_elf_generic_reloc, /* special_function */
420 "R_PPC_GOT16", /* name */
421 FALSE, /* partial_inplace */
423 0xffff, /* dst_mask */
424 FALSE), /* pcrel_offset */
426 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
428 HOWTO (R_PPC_GOT16_LO, /* type */
430 1, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE, /* pc_relative */
434 complain_overflow_dont, /* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
436 "R_PPC_GOT16_LO", /* name */
437 FALSE, /* partial_inplace */
439 0xffff, /* dst_mask */
440 FALSE), /* pcrel_offset */
442 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
444 HOWTO (R_PPC_GOT16_HI, /* type */
446 1, /* size (0 = byte, 1 = short, 2 = long) */
448 FALSE, /* pc_relative */
450 complain_overflow_bitfield, /* complain_on_overflow */
451 bfd_elf_generic_reloc, /* special_function */
452 "R_PPC_GOT16_HI", /* name */
453 FALSE, /* partial_inplace */
455 0xffff, /* dst_mask */
456 FALSE), /* pcrel_offset */
458 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
460 HOWTO (R_PPC_GOT16_HA, /* type */
462 1, /* size (0 = byte, 1 = short, 2 = long) */
464 FALSE, /* pc_relative */
466 complain_overflow_bitfield, /* complain_on_overflow */
467 ppc_elf_addr16_ha_reloc, /* special_function */
468 "R_PPC_GOT16_HA", /* name */
469 FALSE, /* partial_inplace */
471 0xffff, /* dst_mask */
472 FALSE), /* pcrel_offset */
474 /* Like R_PPC_REL24, but referring to the procedure linkage table
475 entry for the symbol. */
476 HOWTO (R_PPC_PLTREL24, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 TRUE, /* pc_relative */
482 complain_overflow_signed, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* special_function */
484 "R_PPC_PLTREL24", /* name */
485 FALSE, /* partial_inplace */
487 0x3fffffc, /* dst_mask */
488 TRUE), /* pcrel_offset */
490 /* This is used only by the dynamic linker. The symbol should exist
491 both in the object being run and in some shared library. The
492 dynamic linker copies the data addressed by the symbol from the
493 shared library into the object, because the object being
494 run has to have the data at some particular address. */
495 HOWTO (R_PPC_COPY, /* type */
497 2, /* size (0 = byte, 1 = short, 2 = long) */
499 FALSE, /* pc_relative */
501 complain_overflow_bitfield, /* complain_on_overflow */
502 bfd_elf_generic_reloc, /* special_function */
503 "R_PPC_COPY", /* name */
504 FALSE, /* partial_inplace */
507 FALSE), /* pcrel_offset */
509 /* Like R_PPC_ADDR32, but used when setting global offset table
511 HOWTO (R_PPC_GLOB_DAT, /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE, /* pc_relative */
517 complain_overflow_bitfield, /* complain_on_overflow */
518 bfd_elf_generic_reloc, /* special_function */
519 "R_PPC_GLOB_DAT", /* name */
520 FALSE, /* partial_inplace */
522 0xffffffff, /* dst_mask */
523 FALSE), /* pcrel_offset */
525 /* Marks a procedure linkage table entry for a symbol. */
526 HOWTO (R_PPC_JMP_SLOT, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE, /* pc_relative */
532 complain_overflow_bitfield, /* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_PPC_JMP_SLOT", /* name */
535 FALSE, /* partial_inplace */
538 FALSE), /* pcrel_offset */
540 /* Used only by the dynamic linker. When the object is run, this
541 longword is set to the load address of the object, plus the
543 HOWTO (R_PPC_RELATIVE, /* 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_PPC_RELATIVE", /* name */
552 FALSE, /* partial_inplace */
554 0xffffffff, /* dst_mask */
555 FALSE), /* pcrel_offset */
557 /* Like R_PPC_REL24, but uses the value of the symbol within the
558 object rather than the final value. Normally used for
559 _GLOBAL_OFFSET_TABLE_. */
560 HOWTO (R_PPC_LOCAL24PC, /* type */
562 2, /* size (0 = byte, 1 = short, 2 = long) */
564 TRUE, /* pc_relative */
566 complain_overflow_signed, /* complain_on_overflow */
567 bfd_elf_generic_reloc, /* special_function */
568 "R_PPC_LOCAL24PC", /* name */
569 FALSE, /* partial_inplace */
571 0x3fffffc, /* dst_mask */
572 TRUE), /* pcrel_offset */
574 /* Like R_PPC_ADDR32, but may be unaligned. */
575 HOWTO (R_PPC_UADDR32, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 FALSE, /* pc_relative */
581 complain_overflow_bitfield, /* complain_on_overflow */
582 bfd_elf_generic_reloc, /* special_function */
583 "R_PPC_UADDR32", /* name */
584 FALSE, /* partial_inplace */
586 0xffffffff, /* dst_mask */
587 FALSE), /* pcrel_offset */
589 /* Like R_PPC_ADDR16, but may be unaligned. */
590 HOWTO (R_PPC_UADDR16, /* type */
592 1, /* size (0 = byte, 1 = short, 2 = long) */
594 FALSE, /* pc_relative */
596 complain_overflow_bitfield, /* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 "R_PPC_UADDR16", /* name */
599 FALSE, /* partial_inplace */
601 0xffff, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 /* 32-bit PC relative */
605 HOWTO (R_PPC_REL32, /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 TRUE, /* pc_relative */
611 complain_overflow_bitfield, /* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 "R_PPC_REL32", /* name */
614 FALSE, /* partial_inplace */
616 0xffffffff, /* dst_mask */
617 TRUE), /* pcrel_offset */
619 /* 32-bit relocation to the symbol's procedure linkage table.
620 FIXME: not supported. */
621 HOWTO (R_PPC_PLT32, /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 FALSE, /* pc_relative */
627 complain_overflow_bitfield, /* complain_on_overflow */
628 bfd_elf_generic_reloc, /* special_function */
629 "R_PPC_PLT32", /* name */
630 FALSE, /* partial_inplace */
633 FALSE), /* pcrel_offset */
635 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
636 FIXME: not supported. */
637 HOWTO (R_PPC_PLTREL32, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 TRUE, /* pc_relative */
643 complain_overflow_bitfield, /* complain_on_overflow */
644 bfd_elf_generic_reloc, /* special_function */
645 "R_PPC_PLTREL32", /* name */
646 FALSE, /* partial_inplace */
649 TRUE), /* pcrel_offset */
651 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
653 HOWTO (R_PPC_PLT16_LO, /* type */
655 1, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE, /* pc_relative */
659 complain_overflow_dont, /* complain_on_overflow */
660 bfd_elf_generic_reloc, /* special_function */
661 "R_PPC_PLT16_LO", /* name */
662 FALSE, /* partial_inplace */
664 0xffff, /* dst_mask */
665 FALSE), /* pcrel_offset */
667 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
669 HOWTO (R_PPC_PLT16_HI, /* type */
671 1, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE, /* pc_relative */
675 complain_overflow_bitfield, /* complain_on_overflow */
676 bfd_elf_generic_reloc, /* special_function */
677 "R_PPC_PLT16_HI", /* name */
678 FALSE, /* partial_inplace */
680 0xffff, /* dst_mask */
681 FALSE), /* pcrel_offset */
683 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
685 HOWTO (R_PPC_PLT16_HA, /* type */
687 1, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE, /* pc_relative */
691 complain_overflow_bitfield, /* complain_on_overflow */
692 ppc_elf_addr16_ha_reloc, /* special_function */
693 "R_PPC_PLT16_HA", /* name */
694 FALSE, /* partial_inplace */
696 0xffff, /* dst_mask */
697 FALSE), /* pcrel_offset */
699 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
701 HOWTO (R_PPC_SDAREL16, /* type */
703 1, /* size (0 = byte, 1 = short, 2 = long) */
705 FALSE, /* pc_relative */
707 complain_overflow_signed, /* complain_on_overflow */
708 bfd_elf_generic_reloc, /* special_function */
709 "R_PPC_SDAREL16", /* name */
710 FALSE, /* partial_inplace */
712 0xffff, /* dst_mask */
713 FALSE), /* pcrel_offset */
715 /* 16-bit section relative relocation. */
716 HOWTO (R_PPC_SECTOFF, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 FALSE, /* pc_relative */
722 complain_overflow_bitfield, /* complain_on_overflow */
723 bfd_elf_generic_reloc, /* special_function */
724 "R_PPC_SECTOFF", /* name */
725 FALSE, /* partial_inplace */
727 0xffff, /* dst_mask */
728 FALSE), /* pcrel_offset */
730 /* 16-bit lower half section relative relocation. */
731 HOWTO (R_PPC_SECTOFF_LO, /* type */
733 1, /* size (0 = byte, 1 = short, 2 = long) */
735 FALSE, /* pc_relative */
737 complain_overflow_dont, /* complain_on_overflow */
738 bfd_elf_generic_reloc, /* special_function */
739 "R_PPC_SECTOFF_LO", /* name */
740 FALSE, /* partial_inplace */
742 0xffff, /* dst_mask */
743 FALSE), /* pcrel_offset */
745 /* 16-bit upper half section relative relocation. */
746 HOWTO (R_PPC_SECTOFF_HI, /* type */
748 1, /* size (0 = byte, 1 = short, 2 = long) */
750 FALSE, /* pc_relative */
752 complain_overflow_bitfield, /* complain_on_overflow */
753 bfd_elf_generic_reloc, /* special_function */
754 "R_PPC_SECTOFF_HI", /* name */
755 FALSE, /* partial_inplace */
757 0xffff, /* dst_mask */
758 FALSE), /* pcrel_offset */
760 /* 16-bit upper half adjusted section relative relocation. */
761 HOWTO (R_PPC_SECTOFF_HA, /* type */
763 1, /* size (0 = byte, 1 = short, 2 = long) */
765 FALSE, /* pc_relative */
767 complain_overflow_bitfield, /* complain_on_overflow */
768 ppc_elf_addr16_ha_reloc, /* special_function */
769 "R_PPC_SECTOFF_HA", /* name */
770 FALSE, /* partial_inplace */
772 0xffff, /* dst_mask */
773 FALSE), /* pcrel_offset */
775 /* Marker relocs for TLS. */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 FALSE, /* pc_relative */
782 complain_overflow_dont, /* complain_on_overflow */
783 bfd_elf_generic_reloc, /* special_function */
784 "R_PPC_TLS", /* name */
785 FALSE, /* partial_inplace */
788 FALSE), /* pcrel_offset */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE, /* pc_relative */
796 complain_overflow_dont, /* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 "R_PPC_TLSGD", /* name */
799 FALSE, /* partial_inplace */
802 FALSE), /* pcrel_offset */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 FALSE, /* pc_relative */
810 complain_overflow_dont, /* complain_on_overflow */
811 bfd_elf_generic_reloc, /* special_function */
812 "R_PPC_TLSLD", /* name */
813 FALSE, /* partial_inplace */
816 FALSE), /* pcrel_offset */
818 /* Computes the load module index of the load module that contains the
819 definition of its TLS sym. */
820 HOWTO (R_PPC_DTPMOD32,
822 2, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE, /* pc_relative */
826 complain_overflow_dont, /* complain_on_overflow */
827 ppc_elf_unhandled_reloc, /* special_function */
828 "R_PPC_DTPMOD32", /* name */
829 FALSE, /* partial_inplace */
831 0xffffffff, /* dst_mask */
832 FALSE), /* pcrel_offset */
834 /* Computes a dtv-relative displacement, the difference between the value
835 of sym+add and the base address of the thread-local storage block that
836 contains the definition of sym, minus 0x8000. */
837 HOWTO (R_PPC_DTPREL32,
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE, /* pc_relative */
843 complain_overflow_dont, /* complain_on_overflow */
844 ppc_elf_unhandled_reloc, /* special_function */
845 "R_PPC_DTPREL32", /* name */
846 FALSE, /* partial_inplace */
848 0xffffffff, /* dst_mask */
849 FALSE), /* pcrel_offset */
851 /* A 16 bit dtprel reloc. */
852 HOWTO (R_PPC_DTPREL16,
854 1, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE, /* pc_relative */
858 complain_overflow_signed, /* complain_on_overflow */
859 ppc_elf_unhandled_reloc, /* special_function */
860 "R_PPC_DTPREL16", /* name */
861 FALSE, /* partial_inplace */
863 0xffff, /* dst_mask */
864 FALSE), /* pcrel_offset */
866 /* Like DTPREL16, but no overflow. */
867 HOWTO (R_PPC_DTPREL16_LO,
869 1, /* size (0 = byte, 1 = short, 2 = long) */
871 FALSE, /* pc_relative */
873 complain_overflow_dont, /* complain_on_overflow */
874 ppc_elf_unhandled_reloc, /* special_function */
875 "R_PPC_DTPREL16_LO", /* name */
876 FALSE, /* partial_inplace */
878 0xffff, /* dst_mask */
879 FALSE), /* pcrel_offset */
881 /* Like DTPREL16_LO, but next higher group of 16 bits. */
882 HOWTO (R_PPC_DTPREL16_HI,
884 1, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE, /* pc_relative */
888 complain_overflow_dont, /* complain_on_overflow */
889 ppc_elf_unhandled_reloc, /* special_function */
890 "R_PPC_DTPREL16_HI", /* name */
891 FALSE, /* partial_inplace */
893 0xffff, /* dst_mask */
894 FALSE), /* pcrel_offset */
896 /* Like DTPREL16_HI, but adjust for low 16 bits. */
897 HOWTO (R_PPC_DTPREL16_HA,
899 1, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE, /* pc_relative */
903 complain_overflow_dont, /* complain_on_overflow */
904 ppc_elf_unhandled_reloc, /* special_function */
905 "R_PPC_DTPREL16_HA", /* name */
906 FALSE, /* partial_inplace */
908 0xffff, /* dst_mask */
909 FALSE), /* pcrel_offset */
911 /* Computes a tp-relative displacement, the difference between the value of
912 sym+add and the value of the thread pointer (r13). */
913 HOWTO (R_PPC_TPREL32,
915 2, /* size (0 = byte, 1 = short, 2 = long) */
917 FALSE, /* pc_relative */
919 complain_overflow_dont, /* complain_on_overflow */
920 ppc_elf_unhandled_reloc, /* special_function */
921 "R_PPC_TPREL32", /* name */
922 FALSE, /* partial_inplace */
924 0xffffffff, /* dst_mask */
925 FALSE), /* pcrel_offset */
927 /* A 16 bit tprel reloc. */
928 HOWTO (R_PPC_TPREL16,
930 1, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE, /* pc_relative */
934 complain_overflow_signed, /* complain_on_overflow */
935 ppc_elf_unhandled_reloc, /* special_function */
936 "R_PPC_TPREL16", /* name */
937 FALSE, /* partial_inplace */
939 0xffff, /* dst_mask */
940 FALSE), /* pcrel_offset */
942 /* Like TPREL16, but no overflow. */
943 HOWTO (R_PPC_TPREL16_LO,
945 1, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE, /* pc_relative */
949 complain_overflow_dont, /* complain_on_overflow */
950 ppc_elf_unhandled_reloc, /* special_function */
951 "R_PPC_TPREL16_LO", /* name */
952 FALSE, /* partial_inplace */
954 0xffff, /* dst_mask */
955 FALSE), /* pcrel_offset */
957 /* Like TPREL16_LO, but next higher group of 16 bits. */
958 HOWTO (R_PPC_TPREL16_HI,
960 1, /* size (0 = byte, 1 = short, 2 = long) */
962 FALSE, /* pc_relative */
964 complain_overflow_dont, /* complain_on_overflow */
965 ppc_elf_unhandled_reloc, /* special_function */
966 "R_PPC_TPREL16_HI", /* name */
967 FALSE, /* partial_inplace */
969 0xffff, /* dst_mask */
970 FALSE), /* pcrel_offset */
972 /* Like TPREL16_HI, but adjust for low 16 bits. */
973 HOWTO (R_PPC_TPREL16_HA,
975 1, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE, /* pc_relative */
979 complain_overflow_dont, /* complain_on_overflow */
980 ppc_elf_unhandled_reloc, /* special_function */
981 "R_PPC_TPREL16_HA", /* name */
982 FALSE, /* partial_inplace */
984 0xffff, /* dst_mask */
985 FALSE), /* pcrel_offset */
987 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
988 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
989 to the first entry. */
990 HOWTO (R_PPC_GOT_TLSGD16,
992 1, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE, /* pc_relative */
996 complain_overflow_signed, /* complain_on_overflow */
997 ppc_elf_unhandled_reloc, /* special_function */
998 "R_PPC_GOT_TLSGD16", /* name */
999 FALSE, /* partial_inplace */
1001 0xffff, /* dst_mask */
1002 FALSE), /* pcrel_offset */
1004 /* Like GOT_TLSGD16, but no overflow. */
1005 HOWTO (R_PPC_GOT_TLSGD16_LO,
1007 1, /* size (0 = byte, 1 = short, 2 = long) */
1009 FALSE, /* pc_relative */
1011 complain_overflow_dont, /* complain_on_overflow */
1012 ppc_elf_unhandled_reloc, /* special_function */
1013 "R_PPC_GOT_TLSGD16_LO", /* name */
1014 FALSE, /* partial_inplace */
1016 0xffff, /* dst_mask */
1017 FALSE), /* pcrel_offset */
1019 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1020 HOWTO (R_PPC_GOT_TLSGD16_HI,
1021 16, /* rightshift */
1022 1, /* size (0 = byte, 1 = short, 2 = long) */
1024 FALSE, /* pc_relative */
1026 complain_overflow_dont, /* complain_on_overflow */
1027 ppc_elf_unhandled_reloc, /* special_function */
1028 "R_PPC_GOT_TLSGD16_HI", /* name */
1029 FALSE, /* partial_inplace */
1031 0xffff, /* dst_mask */
1032 FALSE), /* pcrel_offset */
1034 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1035 HOWTO (R_PPC_GOT_TLSGD16_HA,
1036 16, /* rightshift */
1037 1, /* size (0 = byte, 1 = short, 2 = long) */
1039 FALSE, /* pc_relative */
1041 complain_overflow_dont, /* complain_on_overflow */
1042 ppc_elf_unhandled_reloc, /* special_function */
1043 "R_PPC_GOT_TLSGD16_HA", /* name */
1044 FALSE, /* partial_inplace */
1046 0xffff, /* dst_mask */
1047 FALSE), /* pcrel_offset */
1049 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1050 with values (sym+add)@dtpmod and zero, and computes the offset to the
1052 HOWTO (R_PPC_GOT_TLSLD16,
1054 1, /* size (0 = byte, 1 = short, 2 = long) */
1056 FALSE, /* pc_relative */
1058 complain_overflow_signed, /* complain_on_overflow */
1059 ppc_elf_unhandled_reloc, /* special_function */
1060 "R_PPC_GOT_TLSLD16", /* name */
1061 FALSE, /* partial_inplace */
1063 0xffff, /* dst_mask */
1064 FALSE), /* pcrel_offset */
1066 /* Like GOT_TLSLD16, but no overflow. */
1067 HOWTO (R_PPC_GOT_TLSLD16_LO,
1069 1, /* size (0 = byte, 1 = short, 2 = long) */
1071 FALSE, /* pc_relative */
1073 complain_overflow_dont, /* complain_on_overflow */
1074 ppc_elf_unhandled_reloc, /* special_function */
1075 "R_PPC_GOT_TLSLD16_LO", /* name */
1076 FALSE, /* partial_inplace */
1078 0xffff, /* dst_mask */
1079 FALSE), /* pcrel_offset */
1081 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1082 HOWTO (R_PPC_GOT_TLSLD16_HI,
1083 16, /* rightshift */
1084 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 FALSE, /* pc_relative */
1088 complain_overflow_dont, /* complain_on_overflow */
1089 ppc_elf_unhandled_reloc, /* special_function */
1090 "R_PPC_GOT_TLSLD16_HI", /* name */
1091 FALSE, /* partial_inplace */
1093 0xffff, /* dst_mask */
1094 FALSE), /* pcrel_offset */
1096 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1097 HOWTO (R_PPC_GOT_TLSLD16_HA,
1098 16, /* rightshift */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE, /* pc_relative */
1103 complain_overflow_dont, /* complain_on_overflow */
1104 ppc_elf_unhandled_reloc, /* special_function */
1105 "R_PPC_GOT_TLSLD16_HA", /* name */
1106 FALSE, /* partial_inplace */
1108 0xffff, /* dst_mask */
1109 FALSE), /* pcrel_offset */
1111 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1112 the offset to the entry. */
1113 HOWTO (R_PPC_GOT_DTPREL16,
1115 1, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE, /* pc_relative */
1119 complain_overflow_signed, /* complain_on_overflow */
1120 ppc_elf_unhandled_reloc, /* special_function */
1121 "R_PPC_GOT_DTPREL16", /* name */
1122 FALSE, /* partial_inplace */
1124 0xffff, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1127 /* Like GOT_DTPREL16, but no overflow. */
1128 HOWTO (R_PPC_GOT_DTPREL16_LO,
1130 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 FALSE, /* pc_relative */
1134 complain_overflow_dont, /* complain_on_overflow */
1135 ppc_elf_unhandled_reloc, /* special_function */
1136 "R_PPC_GOT_DTPREL16_LO", /* name */
1137 FALSE, /* partial_inplace */
1139 0xffff, /* dst_mask */
1140 FALSE), /* pcrel_offset */
1142 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1143 HOWTO (R_PPC_GOT_DTPREL16_HI,
1144 16, /* rightshift */
1145 1, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_dont, /* complain_on_overflow */
1150 ppc_elf_unhandled_reloc, /* special_function */
1151 "R_PPC_GOT_DTPREL16_HI", /* name */
1152 FALSE, /* partial_inplace */
1154 0xffff, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1158 HOWTO (R_PPC_GOT_DTPREL16_HA,
1159 16, /* rightshift */
1160 1, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 ppc_elf_unhandled_reloc, /* special_function */
1166 "R_PPC_GOT_DTPREL16_HA", /* name */
1167 FALSE, /* partial_inplace */
1169 0xffff, /* dst_mask */
1170 FALSE), /* pcrel_offset */
1172 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1173 offset to the entry. */
1174 HOWTO (R_PPC_GOT_TPREL16,
1176 1, /* size (0 = byte, 1 = short, 2 = long) */
1178 FALSE, /* pc_relative */
1180 complain_overflow_signed, /* complain_on_overflow */
1181 ppc_elf_unhandled_reloc, /* special_function */
1182 "R_PPC_GOT_TPREL16", /* name */
1183 FALSE, /* partial_inplace */
1185 0xffff, /* dst_mask */
1186 FALSE), /* pcrel_offset */
1188 /* Like GOT_TPREL16, but no overflow. */
1189 HOWTO (R_PPC_GOT_TPREL16_LO,
1191 1, /* size (0 = byte, 1 = short, 2 = long) */
1193 FALSE, /* pc_relative */
1195 complain_overflow_dont, /* complain_on_overflow */
1196 ppc_elf_unhandled_reloc, /* special_function */
1197 "R_PPC_GOT_TPREL16_LO", /* name */
1198 FALSE, /* partial_inplace */
1200 0xffff, /* dst_mask */
1201 FALSE), /* pcrel_offset */
1203 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1204 HOWTO (R_PPC_GOT_TPREL16_HI,
1205 16, /* rightshift */
1206 1, /* size (0 = byte, 1 = short, 2 = long) */
1208 FALSE, /* pc_relative */
1210 complain_overflow_dont, /* complain_on_overflow */
1211 ppc_elf_unhandled_reloc, /* special_function */
1212 "R_PPC_GOT_TPREL16_HI", /* name */
1213 FALSE, /* partial_inplace */
1215 0xffff, /* dst_mask */
1216 FALSE), /* pcrel_offset */
1218 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1219 HOWTO (R_PPC_GOT_TPREL16_HA,
1220 16, /* rightshift */
1221 1, /* size (0 = byte, 1 = short, 2 = long) */
1223 FALSE, /* pc_relative */
1225 complain_overflow_dont, /* complain_on_overflow */
1226 ppc_elf_unhandled_reloc, /* special_function */
1227 "R_PPC_GOT_TPREL16_HA", /* name */
1228 FALSE, /* partial_inplace */
1230 0xffff, /* dst_mask */
1231 FALSE), /* pcrel_offset */
1233 /* The remaining relocs are from the Embedded ELF ABI, and are not
1234 in the SVR4 ELF ABI. */
1236 /* 32 bit value resulting from the addend minus the symbol. */
1237 HOWTO (R_PPC_EMB_NADDR32, /* type */
1239 2, /* size (0 = byte, 1 = short, 2 = long) */
1241 FALSE, /* pc_relative */
1243 complain_overflow_bitfield, /* complain_on_overflow */
1244 bfd_elf_generic_reloc, /* special_function */
1245 "R_PPC_EMB_NADDR32", /* name */
1246 FALSE, /* partial_inplace */
1248 0xffffffff, /* dst_mask */
1249 FALSE), /* pcrel_offset */
1251 /* 16 bit value resulting from the addend minus the symbol. */
1252 HOWTO (R_PPC_EMB_NADDR16, /* type */
1254 1, /* size (0 = byte, 1 = short, 2 = long) */
1256 FALSE, /* pc_relative */
1258 complain_overflow_bitfield, /* complain_on_overflow */
1259 bfd_elf_generic_reloc, /* special_function */
1260 "R_PPC_EMB_NADDR16", /* name */
1261 FALSE, /* partial_inplace */
1263 0xffff, /* dst_mask */
1264 FALSE), /* pcrel_offset */
1266 /* 16 bit value resulting from the addend minus the symbol. */
1267 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1269 1, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE, /* pc_relative */
1273 complain_overflow_dont,/* complain_on_overflow */
1274 bfd_elf_generic_reloc, /* special_function */
1275 "R_PPC_EMB_ADDR16_LO", /* name */
1276 FALSE, /* partial_inplace */
1278 0xffff, /* dst_mask */
1279 FALSE), /* pcrel_offset */
1281 /* The high order 16 bits of the addend minus the symbol. */
1282 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1283 16, /* rightshift */
1284 1, /* size (0 = byte, 1 = short, 2 = long) */
1286 FALSE, /* pc_relative */
1288 complain_overflow_dont, /* complain_on_overflow */
1289 bfd_elf_generic_reloc, /* special_function */
1290 "R_PPC_EMB_NADDR16_HI", /* name */
1291 FALSE, /* partial_inplace */
1293 0xffff, /* dst_mask */
1294 FALSE), /* pcrel_offset */
1296 /* The high order 16 bits of the result of the addend minus the address,
1297 plus 1 if the contents of the low 16 bits, treated as a signed number,
1299 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1300 16, /* rightshift */
1301 1, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE, /* pc_relative */
1305 complain_overflow_dont, /* complain_on_overflow */
1306 ppc_elf_addr16_ha_reloc, /* special_function */
1307 "R_PPC_EMB_NADDR16_HA", /* name */
1308 FALSE, /* partial_inplace */
1310 0xffff, /* dst_mask */
1311 FALSE), /* pcrel_offset */
1313 /* 16 bit value resulting from allocating a 4 byte word to hold an
1314 address in the .sdata section, and returning the offset from
1315 _SDA_BASE_ for that relocation. */
1316 HOWTO (R_PPC_EMB_SDAI16, /* type */
1318 1, /* size (0 = byte, 1 = short, 2 = long) */
1320 FALSE, /* pc_relative */
1322 complain_overflow_signed, /* complain_on_overflow */
1323 bfd_elf_generic_reloc, /* special_function */
1324 "R_PPC_EMB_SDAI16", /* name */
1325 FALSE, /* partial_inplace */
1327 0xffff, /* dst_mask */
1328 FALSE), /* pcrel_offset */
1330 /* 16 bit value resulting from allocating a 4 byte word to hold an
1331 address in the .sdata2 section, and returning the offset from
1332 _SDA2_BASE_ for that relocation. */
1333 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1335 1, /* size (0 = byte, 1 = short, 2 = long) */
1337 FALSE, /* pc_relative */
1339 complain_overflow_signed, /* complain_on_overflow */
1340 bfd_elf_generic_reloc, /* special_function */
1341 "R_PPC_EMB_SDA2I16", /* name */
1342 FALSE, /* partial_inplace */
1344 0xffff, /* dst_mask */
1345 FALSE), /* pcrel_offset */
1347 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1348 small data items. */
1349 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1351 1, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE, /* pc_relative */
1355 complain_overflow_signed, /* complain_on_overflow */
1356 bfd_elf_generic_reloc, /* special_function */
1357 "R_PPC_EMB_SDA2REL", /* name */
1358 FALSE, /* partial_inplace */
1360 0xffff, /* dst_mask */
1361 FALSE), /* pcrel_offset */
1363 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1364 signed offset from the appropriate base, and filling in the register
1365 field with the appropriate register (0, 2, or 13). */
1366 HOWTO (R_PPC_EMB_SDA21, /* type */
1368 2, /* size (0 = byte, 1 = short, 2 = long) */
1370 FALSE, /* pc_relative */
1372 complain_overflow_signed, /* complain_on_overflow */
1373 bfd_elf_generic_reloc, /* special_function */
1374 "R_PPC_EMB_SDA21", /* name */
1375 FALSE, /* partial_inplace */
1377 0xffff, /* dst_mask */
1378 FALSE), /* pcrel_offset */
1380 /* Relocation not handled: R_PPC_EMB_MRKREF */
1381 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1382 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1383 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1384 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1385 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1387 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1388 in the 16 bit signed offset from the appropriate base, and filling in the
1389 register field with the appropriate register (0, 2, or 13). */
1390 HOWTO (R_PPC_EMB_RELSDA, /* type */
1392 1, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE, /* pc_relative */
1396 complain_overflow_signed, /* complain_on_overflow */
1397 bfd_elf_generic_reloc, /* special_function */
1398 "R_PPC_EMB_RELSDA", /* name */
1399 FALSE, /* partial_inplace */
1401 0xffff, /* dst_mask */
1402 FALSE), /* pcrel_offset */
1404 /* A relative 8 bit branch. */
1405 HOWTO (R_PPC_VLE_REL8, /* type */
1407 1, /* size (0 = byte, 1 = short, 2 = long) */
1409 TRUE, /* pc_relative */
1411 complain_overflow_signed, /* complain_on_overflow */
1412 bfd_elf_generic_reloc, /* special_function */
1413 "R_PPC_VLE_REL8", /* name */
1414 FALSE, /* partial_inplace */
1416 0xff, /* dst_mask */
1417 TRUE), /* pcrel_offset */
1419 /* A relative 15 bit branch. */
1420 HOWTO (R_PPC_VLE_REL15, /* type */
1422 2, /* size (0 = byte, 1 = short, 2 = long) */
1424 TRUE, /* pc_relative */
1426 complain_overflow_signed, /* complain_on_overflow */
1427 bfd_elf_generic_reloc, /* special_function */
1428 "R_PPC_VLE_REL15", /* name */
1429 FALSE, /* partial_inplace */
1431 0xfe, /* dst_mask */
1432 TRUE), /* pcrel_offset */
1434 /* A relative 24 bit branch. */
1435 HOWTO (R_PPC_VLE_REL24, /* type */
1437 2, /* size (0 = byte, 1 = short, 2 = long) */
1439 TRUE, /* pc_relative */
1441 complain_overflow_signed, /* complain_on_overflow */
1442 bfd_elf_generic_reloc, /* special_function */
1443 "R_PPC_VLE_REL24", /* name */
1444 FALSE, /* partial_inplace */
1446 0x1fffffe, /* dst_mask */
1447 TRUE), /* pcrel_offset */
1449 /* The 16 LSBS in split16a format. */
1450 HOWTO (R_PPC_VLE_LO16A, /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE, /* pc_relative */ /* FIXME: Does this apply to split relocs? */
1456 complain_overflow_bitfield, /* complain_on_overflow */
1457 bfd_elf_generic_reloc, /* special_function */
1458 "R_PPC_VLE_LO16A", /* name */
1459 FALSE, /* partial_inplace */
1461 0x1f00fff, /* dst_mask */
1462 FALSE), /* pcrel_offset */
1464 /* The 16 LSBS in split16d format. */
1465 HOWTO (R_PPC_VLE_LO16D, /* type */
1467 2, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE, /* pc_relative */
1471 complain_overflow_bitfield, /* complain_on_overflow */
1472 bfd_elf_generic_reloc, /* special_function */
1473 "R_PPC_VLE_LO16D", /* name */
1474 FALSE, /* partial_inplace */
1476 0x1f07ff, /* dst_mask */
1477 FALSE), /* pcrel_offset */
1479 /* Bits 16-31 split16a format. */
1480 HOWTO (R_PPC_VLE_HI16A, /* type */
1482 2, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE, /* pc_relative */
1486 complain_overflow_bitfield, /* complain_on_overflow */
1487 bfd_elf_generic_reloc, /* special_function */
1488 "R_PPC_VLE_HI16A", /* name */
1489 FALSE, /* partial_inplace */
1491 0x1f00fff, /* dst_mask */
1492 FALSE), /* pcrel_offset */
1494 /* Bits 16-31 split16d format. */
1495 HOWTO (R_PPC_VLE_HI16D, /* type */
1497 2, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE, /* pc_relative */
1501 complain_overflow_bitfield, /* complain_on_overflow */
1502 bfd_elf_generic_reloc, /* special_function */
1503 "R_PPC_VLE_HI16D", /* name */
1504 FALSE, /* partial_inplace */
1506 0x1f07ff, /* dst_mask */
1507 FALSE), /* pcrel_offset */
1509 /* Bits 16-31 (High Adjusted) in split16a format. */
1510 HOWTO (R_PPC_VLE_HA16A, /* type */
1512 2, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE, /* pc_relative */
1516 complain_overflow_bitfield, /* complain_on_overflow */
1517 bfd_elf_generic_reloc, /* special_function */
1518 "R_PPC_VLE_HA16A", /* name */
1519 FALSE, /* partial_inplace */
1521 0x1f00fff, /* dst_mask */
1522 FALSE), /* pcrel_offset */
1524 /* Bits 16-31 (High Adjusted) in split16d format. */
1525 HOWTO (R_PPC_VLE_HA16D, /* type */
1527 2, /* size (0 = byte, 1 = short, 2 = long) */
1529 FALSE, /* pc_relative */
1531 complain_overflow_bitfield, /* complain_on_overflow */
1532 bfd_elf_generic_reloc, /* special_function */
1533 "R_PPC_VLE_HA16D", /* name */
1534 FALSE, /* partial_inplace */
1536 0x1f07ff, /* dst_mask */
1537 FALSE), /* pcrel_offset */
1539 /* This reloc does nothing. */
1540 HOWTO (R_PPC_VLE_SDA21, /* type */
1542 2, /* size (0 = byte, 1 = short, 2 = long) */
1544 FALSE, /* pc_relative */
1546 complain_overflow_bitfield, /* complain_on_overflow */
1547 bfd_elf_generic_reloc, /* special_function */
1548 "R_PPC_VLE_SDA21", /* name */
1549 FALSE, /* partial_inplace */
1551 0xffff, /* dst_mask */
1552 FALSE), /* pcrel_offset */
1554 /* This reloc does nothing. */
1555 HOWTO (R_PPC_VLE_SDA21_LO, /* type */
1557 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 FALSE, /* pc_relative */
1561 complain_overflow_bitfield, /* complain_on_overflow */
1562 bfd_elf_generic_reloc, /* special_function */
1563 "R_PPC_VLE_SDA21_LO", /* name */
1564 FALSE, /* partial_inplace */
1567 FALSE), /* pcrel_offset */
1569 /* The 16 LSBS relative to _SDA_BASE_ in split16a format. */
1570 HOWTO (R_PPC_VLE_SDAREL_LO16A,/* type */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE, /* pc_relative */
1576 complain_overflow_bitfield, /* complain_on_overflow */
1577 bfd_elf_generic_reloc, /* special_function */
1578 "R_PPC_VLE_SDAREL_LO16A", /* name */
1579 FALSE, /* partial_inplace */
1581 0x1f00fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
1584 /* The 16 LSBS relative to _SDA_BASE_ in split16d format. */
1585 /* This reloc does nothing. */
1586 HOWTO (R_PPC_VLE_SDAREL_LO16D, /* type */
1588 2, /* size (0 = byte, 1 = short, 2 = long) */
1590 FALSE, /* pc_relative */
1592 complain_overflow_bitfield, /* complain_on_overflow */
1593 bfd_elf_generic_reloc, /* special_function */
1594 "R_PPC_VLE_SDAREL_LO16D", /* name */
1595 FALSE, /* partial_inplace */
1597 0x1f07ff, /* dst_mask */
1598 FALSE), /* pcrel_offset */
1600 /* Bits 16-31 relative to _SDA_BASE_ in split16a format. */
1601 HOWTO (R_PPC_VLE_SDAREL_HI16A, /* type */
1603 2, /* size (0 = byte, 1 = short, 2 = long) */
1605 FALSE, /* pc_relative */
1607 complain_overflow_bitfield, /* complain_on_overflow */
1608 bfd_elf_generic_reloc, /* special_function */
1609 "R_PPC_VLE_SDAREL_HI16A", /* name */
1610 FALSE, /* partial_inplace */
1612 0x1f00fff, /* dst_mask */
1613 FALSE), /* pcrel_offset */
1615 /* Bits 16-31 relative to _SDA_BASE_ in split16d format. */
1616 HOWTO (R_PPC_VLE_SDAREL_HI16D, /* type */
1618 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE, /* pc_relative */
1622 complain_overflow_bitfield, /* complain_on_overflow */
1623 bfd_elf_generic_reloc, /* special_function */
1624 "R_PPC_VLE_SDAREL_HI16D", /* name */
1625 FALSE, /* partial_inplace */
1627 0x1f07ff, /* dst_mask */
1628 FALSE), /* pcrel_offset */
1630 /* Bits 16-31 (HA) relative to _SDA_BASE split16a format. */
1631 HOWTO (R_PPC_VLE_SDAREL_HA16A, /* type */
1633 2, /* size (0 = byte, 1 = short, 2 = long) */
1635 FALSE, /* pc_relative */
1637 complain_overflow_bitfield, /* complain_on_overflow */
1638 bfd_elf_generic_reloc, /* special_function */
1639 "R_PPC_VLE_SDAREL_HA16A", /* name */
1640 FALSE, /* partial_inplace */
1642 0x1f00fff, /* dst_mask */
1643 FALSE), /* pcrel_offset */
1645 /* Bits 16-31 (HA) relative to _SDA_BASE split16d format. */
1646 HOWTO (R_PPC_VLE_SDAREL_HA16D, /* type */
1648 2, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE, /* pc_relative */
1652 complain_overflow_bitfield, /* complain_on_overflow */
1653 bfd_elf_generic_reloc, /* special_function */
1654 "R_PPC_VLE_SDAREL_HA16D", /* name */
1655 FALSE, /* partial_inplace */
1657 0x1f07ff, /* dst_mask */
1658 FALSE), /* pcrel_offset */
1660 HOWTO (R_PPC_IRELATIVE, /* type */
1662 2, /* size (0 = byte, 1 = short, 2 = long) */
1664 FALSE, /* pc_relative */
1666 complain_overflow_bitfield, /* complain_on_overflow */
1667 bfd_elf_generic_reloc, /* special_function */
1668 "R_PPC_IRELATIVE", /* name */
1669 FALSE, /* partial_inplace */
1671 0xffffffff, /* dst_mask */
1672 FALSE), /* pcrel_offset */
1674 /* A 16 bit relative relocation. */
1675 HOWTO (R_PPC_REL16, /* type */
1677 1, /* size (0 = byte, 1 = short, 2 = long) */
1679 TRUE, /* pc_relative */
1681 complain_overflow_bitfield, /* complain_on_overflow */
1682 bfd_elf_generic_reloc, /* special_function */
1683 "R_PPC_REL16", /* name */
1684 FALSE, /* partial_inplace */
1686 0xffff, /* dst_mask */
1687 TRUE), /* pcrel_offset */
1689 /* A 16 bit relative relocation without overflow. */
1690 HOWTO (R_PPC_REL16_LO, /* type */
1692 1, /* size (0 = byte, 1 = short, 2 = long) */
1694 TRUE, /* pc_relative */
1696 complain_overflow_dont,/* complain_on_overflow */
1697 bfd_elf_generic_reloc, /* special_function */
1698 "R_PPC_REL16_LO", /* name */
1699 FALSE, /* partial_inplace */
1701 0xffff, /* dst_mask */
1702 TRUE), /* pcrel_offset */
1704 /* The high order 16 bits of a relative address. */
1705 HOWTO (R_PPC_REL16_HI, /* type */
1706 16, /* rightshift */
1707 1, /* size (0 = byte, 1 = short, 2 = long) */
1709 TRUE, /* pc_relative */
1711 complain_overflow_dont, /* complain_on_overflow */
1712 bfd_elf_generic_reloc, /* special_function */
1713 "R_PPC_REL16_HI", /* name */
1714 FALSE, /* partial_inplace */
1716 0xffff, /* dst_mask */
1717 TRUE), /* pcrel_offset */
1719 /* The high order 16 bits of a relative address, plus 1 if the contents of
1720 the low 16 bits, treated as a signed number, is negative. */
1721 HOWTO (R_PPC_REL16_HA, /* type */
1722 16, /* rightshift */
1723 1, /* size (0 = byte, 1 = short, 2 = long) */
1725 TRUE, /* pc_relative */
1727 complain_overflow_dont, /* complain_on_overflow */
1728 ppc_elf_addr16_ha_reloc, /* special_function */
1729 "R_PPC_REL16_HA", /* name */
1730 FALSE, /* partial_inplace */
1732 0xffff, /* dst_mask */
1733 TRUE), /* pcrel_offset */
1735 /* GNU extension to record C++ vtable hierarchy. */
1736 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1738 0, /* size (0 = byte, 1 = short, 2 = long) */
1740 FALSE, /* pc_relative */
1742 complain_overflow_dont, /* complain_on_overflow */
1743 NULL, /* special_function */
1744 "R_PPC_GNU_VTINHERIT", /* name */
1745 FALSE, /* partial_inplace */
1748 FALSE), /* pcrel_offset */
1750 /* GNU extension to record C++ vtable member usage. */
1751 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1753 0, /* size (0 = byte, 1 = short, 2 = long) */
1755 FALSE, /* pc_relative */
1757 complain_overflow_dont, /* complain_on_overflow */
1758 NULL, /* special_function */
1759 "R_PPC_GNU_VTENTRY", /* name */
1760 FALSE, /* partial_inplace */
1763 FALSE), /* pcrel_offset */
1765 /* Phony reloc to handle AIX style TOC entries. */
1766 HOWTO (R_PPC_TOC16, /* type */
1768 1, /* size (0 = byte, 1 = short, 2 = long) */
1770 FALSE, /* pc_relative */
1772 complain_overflow_signed, /* complain_on_overflow */
1773 bfd_elf_generic_reloc, /* special_function */
1774 "R_PPC_TOC16", /* name */
1775 FALSE, /* partial_inplace */
1777 0xffff, /* dst_mask */
1778 FALSE), /* pcrel_offset */
1781 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1784 ppc_elf_howto_init (void)
1786 unsigned int i, type;
1789 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1792 type = ppc_elf_howto_raw[i].type;
1793 if (type >= (sizeof (ppc_elf_howto_table)
1794 / sizeof (ppc_elf_howto_table[0])))
1796 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1800 static reloc_howto_type *
1801 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1802 bfd_reloc_code_real_type code)
1804 enum elf_ppc_reloc_type r;
1806 /* Initialize howto table if not already done. */
1807 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1808 ppc_elf_howto_init ();
1815 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1816 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1817 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1818 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1819 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1820 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1821 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1822 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1823 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1824 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1825 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1826 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1827 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1828 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1829 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1830 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1831 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1832 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1833 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1834 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1835 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1836 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1837 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1838 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1839 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1840 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1841 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1842 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1843 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1844 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1845 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1846 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1847 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1848 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1849 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1850 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1851 case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
1852 case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
1853 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1854 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1855 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1856 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1857 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1858 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1859 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1860 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1861 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1862 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1863 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1864 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1865 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1866 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1867 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1868 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1869 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1870 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1871 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1872 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1873 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1874 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1875 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1876 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1877 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1878 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1879 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1880 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1881 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1882 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1883 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1884 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1885 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1886 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1887 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1888 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1889 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1890 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1891 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1892 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1893 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1894 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1895 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1896 case BFD_RELOC_PPC_VLE_REL8: r = R_PPC_VLE_REL8; break;
1897 case BFD_RELOC_PPC_VLE_REL15: r = R_PPC_VLE_REL15; break;
1898 case BFD_RELOC_PPC_VLE_REL24: r = R_PPC_VLE_REL24; break;
1899 case BFD_RELOC_PPC_VLE_LO16A: r = R_PPC_VLE_LO16A; break;
1900 case BFD_RELOC_PPC_VLE_LO16D: r = R_PPC_VLE_LO16D; break;
1901 case BFD_RELOC_PPC_VLE_HI16A: r = R_PPC_VLE_HI16A; break;
1902 case BFD_RELOC_PPC_VLE_HI16D: r = R_PPC_VLE_HI16D; break;
1903 case BFD_RELOC_PPC_VLE_HA16A: r = R_PPC_VLE_HA16A; break;
1904 case BFD_RELOC_PPC_VLE_HA16D: r = R_PPC_VLE_HA16D; break;
1905 case BFD_RELOC_PPC_VLE_SDA21: r = R_PPC_VLE_SDA21; break;
1906 case BFD_RELOC_PPC_VLE_SDA21_LO: r = R_PPC_VLE_SDA21_LO; break;
1907 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
1908 r = R_PPC_VLE_SDAREL_LO16A;
1910 case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
1911 r = R_PPC_VLE_SDAREL_LO16D;
1913 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
1914 r = R_PPC_VLE_SDAREL_HI16A;
1916 case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
1917 r = R_PPC_VLE_SDAREL_HI16D;
1919 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
1920 r = R_PPC_VLE_SDAREL_HA16A;
1922 case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
1923 r = R_PPC_VLE_SDAREL_HA16D;
1925 case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
1926 case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
1927 case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
1928 case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
1929 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1930 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1933 return ppc_elf_howto_table[r];
1936 static reloc_howto_type *
1937 ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1943 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1945 if (ppc_elf_howto_raw[i].name != NULL
1946 && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
1947 return &ppc_elf_howto_raw[i];
1952 /* Set the howto pointer for a PowerPC ELF reloc. */
1955 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1957 Elf_Internal_Rela *dst)
1959 /* Initialize howto table if not already done. */
1960 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1961 ppc_elf_howto_init ();
1963 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1964 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1966 /* Just because the above assert didn't trigger doesn't mean that
1967 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1968 if (!cache_ptr->howto)
1970 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
1971 abfd, ELF32_R_TYPE (dst->r_info));
1972 bfd_set_error (bfd_error_bad_value);
1974 cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
1978 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1980 static bfd_reloc_status_type
1981 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1982 arelent *reloc_entry,
1984 void *data ATTRIBUTE_UNUSED,
1985 asection *input_section,
1987 char **error_message ATTRIBUTE_UNUSED)
1991 if (output_bfd != NULL)
1993 reloc_entry->address += input_section->output_offset;
1994 return bfd_reloc_ok;
1997 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1998 return bfd_reloc_outofrange;
2000 if (bfd_is_com_section (symbol->section))
2003 relocation = symbol->value;
2005 relocation += symbol->section->output_section->vma;
2006 relocation += symbol->section->output_offset;
2007 relocation += reloc_entry->addend;
2008 if (reloc_entry->howto->pc_relative)
2009 relocation -= reloc_entry->address;
2011 reloc_entry->addend += (relocation & 0x8000) << 1;
2013 return bfd_reloc_continue;
2016 static bfd_reloc_status_type
2017 ppc_elf_unhandled_reloc (bfd *abfd,
2018 arelent *reloc_entry,
2021 asection *input_section,
2023 char **error_message)
2025 /* If this is a relocatable link (output_bfd test tells us), just
2026 call the generic function. Any adjustment will be done at final
2028 if (output_bfd != NULL)
2029 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2030 input_section, output_bfd, error_message);
2032 if (error_message != NULL)
2034 static char buf[60];
2035 sprintf (buf, _("generic linker can't handle %s"),
2036 reloc_entry->howto->name);
2037 *error_message = buf;
2039 return bfd_reloc_dangerous;
2042 /* Sections created by the linker. */
2044 typedef struct elf_linker_section
2046 /* Pointer to the bfd section. */
2050 /* Associated bss section name. */
2051 const char *bss_name;
2052 /* Associated symbol name. */
2053 const char *sym_name;
2054 /* Associated symbol. */
2055 struct elf_link_hash_entry *sym;
2056 } elf_linker_section_t;
2058 /* Linked list of allocated pointer entries. This hangs off of the
2059 symbol lists, and provides allows us to return different pointers,
2060 based on different addend's. */
2062 typedef struct elf_linker_section_pointers
2064 /* next allocated pointer for this symbol */
2065 struct elf_linker_section_pointers *next;
2066 /* offset of pointer from beginning of section */
2070 /* which linker section this is */
2071 elf_linker_section_t *lsect;
2072 } elf_linker_section_pointers_t;
2074 struct ppc_elf_obj_tdata
2076 struct elf_obj_tdata elf;
2078 /* A mapping from local symbols to offsets into the various linker
2079 sections added. This is index by the symbol index. */
2080 elf_linker_section_pointers_t **linker_section_pointers;
2082 /* Flags used to auto-detect plt type. */
2083 unsigned int makes_plt_call : 1;
2084 unsigned int has_rel16 : 1;
2087 #define ppc_elf_tdata(bfd) \
2088 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
2090 #define elf_local_ptr_offsets(bfd) \
2091 (ppc_elf_tdata (bfd)->linker_section_pointers)
2093 #define is_ppc_elf(bfd) \
2094 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2095 && elf_object_id (bfd) == PPC32_ELF_DATA)
2097 /* Override the generic function because we store some extras. */
2100 ppc_elf_mkobject (bfd *abfd)
2102 return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata),
2106 /* Fix bad default arch selected for a 32 bit input bfd when the
2107 default is 64 bit. */
2110 ppc_elf_object_p (bfd *abfd)
2112 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
2114 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2116 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
2118 /* Relies on arch after 64 bit default being 32 bit default. */
2119 abfd->arch_info = abfd->arch_info->next;
2120 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
2126 /* Function to set whether a module needs the -mrelocatable bit set. */
2129 ppc_elf_set_private_flags (bfd *abfd, flagword flags)
2131 BFD_ASSERT (!elf_flags_init (abfd)
2132 || elf_elfheader (abfd)->e_flags == flags);
2134 elf_elfheader (abfd)->e_flags = flags;
2135 elf_flags_init (abfd) = TRUE;
2139 /* Support for core dump NOTE sections. */
2142 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2147 switch (note->descsz)
2152 case 268: /* Linux/PPC. */
2154 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2157 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
2166 /* Make a ".reg/999" section. */
2167 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2168 size, note->descpos + offset);
2172 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2174 switch (note->descsz)
2179 case 128: /* Linux/PPC elf_prpsinfo. */
2180 elf_tdata (abfd)->core_pid
2181 = bfd_get_32 (abfd, note->descdata + 16);
2182 elf_tdata (abfd)->core_program
2183 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2184 elf_tdata (abfd)->core_command
2185 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2188 /* Note that for some reason, a spurious space is tacked
2189 onto the end of the args in some (at least one anyway)
2190 implementations, so strip it off if it exists. */
2193 char *command = elf_tdata (abfd)->core_command;
2194 int n = strlen (command);
2196 if (0 < n && command[n - 1] == ' ')
2197 command[n - 1] = '\0';
2204 ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
2216 va_start (ap, note_type);
2217 memset (data, 0, sizeof (data));
2218 strncpy (data + 32, va_arg (ap, const char *), 16);
2219 strncpy (data + 48, va_arg (ap, const char *), 80);
2221 return elfcore_write_note (abfd, buf, bufsiz,
2222 "CORE", note_type, data, sizeof (data));
2233 va_start (ap, note_type);
2234 memset (data, 0, 72);
2235 pid = va_arg (ap, long);
2236 bfd_put_32 (abfd, pid, data + 24);
2237 cursig = va_arg (ap, int);
2238 bfd_put_16 (abfd, cursig, data + 12);
2239 greg = va_arg (ap, const void *);
2240 memcpy (data + 72, greg, 192);
2241 memset (data + 264, 0, 4);
2243 return elfcore_write_note (abfd, buf, bufsiz,
2244 "CORE", note_type, data, sizeof (data));
2250 ppc_elf_lookup_section_flags (char *flag_name)
2253 if (!strcmp (flag_name, "SHF_PPC_VLE"))
2259 /* Add the VLE flag if required. */
2262 ppc_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *shdr)
2264 if (bfd_get_mach (abfd) == bfd_mach_ppc_vle
2265 && (shdr->sh_flags & SHF_EXECINSTR) != 0)
2266 shdr->sh_flags |= SHF_PPC_VLE;
2271 /* Return address for Ith PLT stub in section PLT, for relocation REL
2272 or (bfd_vma) -1 if it should not be included. */
2275 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
2276 const asection *plt ATTRIBUTE_UNUSED,
2279 return rel->address;
2282 /* Handle a PowerPC specific section when reading an object file. This
2283 is called when bfd_section_from_shdr finds a section with an unknown
2287 ppc_elf_section_from_shdr (bfd *abfd,
2288 Elf_Internal_Shdr *hdr,
2295 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
2298 newsect = hdr->bfd_section;
2299 flags = bfd_get_section_flags (abfd, newsect);
2300 if (hdr->sh_flags & SHF_EXCLUDE)
2301 flags |= SEC_EXCLUDE;
2303 if (hdr->sh_type == SHT_ORDERED)
2304 flags |= SEC_SORT_ENTRIES;
2306 bfd_set_section_flags (abfd, newsect, flags);
2310 /* Set up any other section flags and such that may be necessary. */
2313 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2314 Elf_Internal_Shdr *shdr,
2317 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2318 shdr->sh_type = SHT_ORDERED;
2323 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
2324 need to bump up the number of section headers. */
2327 ppc_elf_additional_program_headers (bfd *abfd,
2328 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2333 s = bfd_get_section_by_name (abfd, ".sbss2");
2334 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
2337 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
2338 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
2344 /* Modify the segment map for VLE executables. */
2347 ppc_elf_modify_segment_map (bfd *abfd,
2348 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2350 struct elf_segment_map *m, *n;
2353 bfd_boolean sect0_vle, sectj_vle;
2355 /* At this point in the link, output sections have already been sorted by
2356 LMA and assigned to segments. All that is left to do is to ensure
2357 there is no mixing of VLE & non-VLE sections in a text segment.
2358 If we find that case, we split the segment.
2359 We maintain the original output section order. */
2361 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2366 sect0_vle = (elf_section_flags (m->sections[0]) & SHF_PPC_VLE) != 0;
2367 for (j = 1; j < m->count; ++j)
2369 sectj_vle = (elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0;
2371 if (sectj_vle != sect0_vle)
2377 /* sections 0..j-1 stay in this (current) segment,
2378 the remainder are put in a new segment.
2379 The scan resumes with the new segment. */
2381 /* Fix the new segment. */
2382 amt = sizeof (struct elf_segment_map);
2383 amt += (m->count - j - 1) * sizeof (asection *);
2384 n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
2388 n->p_type = PT_LOAD;
2389 n->p_flags = PF_X | PF_R;
2391 n->p_flags |= PF_PPC_VLE;
2392 n->count = m->count - j;
2393 for (k = 0; k < n->count; ++k)
2395 n->sections[k] = m->sections[j+k];
2396 m->sections[j+k] = NULL;
2401 /* Fix the current segment */
2408 /* Add extra PPC sections -- Note, for now, make .sbss2 and
2409 .PPC.EMB.sbss0 a normal section, and not a bss section so
2410 that the linker doesn't crater when trying to make more than
2413 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
2415 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
2416 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2417 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
2418 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2419 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
2420 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
2421 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 },
2422 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
2423 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
2424 { NULL, 0, 0, 0, 0 }
2427 /* This is what we want for new plt/got. */
2428 static struct bfd_elf_special_section ppc_alt_plt =
2429 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC };
2431 static const struct bfd_elf_special_section *
2432 ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
2434 const struct bfd_elf_special_section *ssect;
2436 /* See if this is one of the special sections. */
2437 if (sec->name == NULL)
2440 ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
2444 if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
2445 ssect = &ppc_alt_plt;
2449 return _bfd_elf_get_sec_type_attr (abfd, sec);
2452 /* Very simple linked list structure for recording apuinfo values. */
2453 typedef struct apuinfo_list
2455 struct apuinfo_list *next;
2456 unsigned long value;
2460 static apuinfo_list *head;
2461 static bfd_boolean apuinfo_set;
2464 apuinfo_list_init (void)
2467 apuinfo_set = FALSE;
2471 apuinfo_list_add (unsigned long value)
2473 apuinfo_list *entry = head;
2475 while (entry != NULL)
2477 if (entry->value == value)
2479 entry = entry->next;
2482 entry = bfd_malloc (sizeof (* entry));
2486 entry->value = value;
2492 apuinfo_list_length (void)
2494 apuinfo_list *entry;
2495 unsigned long count;
2497 for (entry = head, count = 0;
2499 entry = entry->next)
2505 static inline unsigned long
2506 apuinfo_list_element (unsigned long number)
2508 apuinfo_list * entry;
2512 entry = entry->next)
2515 return entry ? entry->value : 0;
2519 apuinfo_list_finish (void)
2521 apuinfo_list *entry;
2523 for (entry = head; entry;)
2525 apuinfo_list *next = entry->next;
2533 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2534 #define APUINFO_LABEL "APUinfo"
2536 /* Scan the input BFDs and create a linked list of
2537 the APUinfo values that will need to be emitted. */
2540 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
2544 char *buffer = NULL;
2545 bfd_size_type largest_input_size = 0;
2547 unsigned long length;
2548 const char *error_message = NULL;
2550 if (link_info == NULL)
2553 apuinfo_list_init ();
2555 /* Read in the input sections contents. */
2556 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2558 unsigned long datum;
2560 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2564 error_message = _("corrupt %s section in %B");
2565 length = asec->size;
2570 if (largest_input_size < asec->size)
2574 largest_input_size = asec->size;
2575 buffer = bfd_malloc (largest_input_size);
2580 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
2581 || (bfd_bread (buffer, length, ibfd) != length))
2583 error_message = _("unable to read in %s section from %B");
2587 /* Verify the contents of the header. Note - we have to
2588 extract the values this way in order to allow for a
2589 host whose endian-ness is different from the target. */
2590 datum = bfd_get_32 (ibfd, buffer);
2591 if (datum != sizeof APUINFO_LABEL)
2594 datum = bfd_get_32 (ibfd, buffer + 8);
2598 if (strcmp (buffer + 12, APUINFO_LABEL) != 0)
2601 /* Get the number of bytes used for apuinfo entries. */
2602 datum = bfd_get_32 (ibfd, buffer + 4);
2603 if (datum + 20 != length)
2606 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2607 for (i = 0; i < datum; i += 4)
2608 apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i));
2611 error_message = NULL;
2615 /* Compute the size of the output section. */
2616 unsigned num_entries = apuinfo_list_length ();
2618 /* Set the output section size, if it exists. */
2619 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2621 if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
2624 error_message = _("warning: unable to set size of %s section in %B");
2633 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2636 /* Prevent the output section from accumulating the input sections'
2637 contents. We have already stored this in our linked list structure. */
2640 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
2641 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
2643 bfd_byte *contents ATTRIBUTE_UNUSED)
2645 return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
2648 /* Finally we can generate the output section. */
2651 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
2656 unsigned num_entries;
2657 bfd_size_type length;
2659 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2666 length = asec->size;
2670 buffer = bfd_malloc (length);
2673 (*_bfd_error_handler)
2674 (_("failed to allocate space for new APUinfo section."));
2678 /* Create the apuinfo header. */
2679 num_entries = apuinfo_list_length ();
2680 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2681 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2682 bfd_put_32 (abfd, 0x2, buffer + 8);
2683 strcpy ((char *) buffer + 12, APUINFO_LABEL);
2686 for (i = 0; i < num_entries; i++)
2688 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2692 if (length != asec->size)
2693 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
2695 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2696 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
2700 apuinfo_list_finish ();
2704 is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
2706 bfd_byte buf[GLINK_ENTRY_SIZE];
2708 if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE))
2711 return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11
2712 && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11
2713 && bfd_get_32 (abfd, buf + 8) == MTCTR_11
2714 && bfd_get_32 (abfd, buf + 12) == BCTR);
2718 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
2720 bfd_vma vma = *(bfd_vma *) ptr;
2721 return ((section->flags & SEC_ALLOC) != 0
2722 && section->vma <= vma
2723 && vma < section->vma + section->size);
2727 ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
2728 long dynsymcount, asymbol **dynsyms,
2731 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
2732 asection *plt, *relplt, *dynamic, *glink;
2733 bfd_vma glink_vma = 0;
2734 bfd_vma resolv_vma = 0;
2745 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
2748 if (dynsymcount <= 0)
2751 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2755 plt = bfd_get_section_by_name (abfd, ".plt");
2759 /* Call common code to handle old-style executable PLTs. */
2760 if (elf_section_flags (plt) & SHF_EXECINSTR)
2761 return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
2762 dynsymcount, dynsyms, ret);
2764 /* If this object was prelinked, the prelinker stored the address
2765 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
2766 dynamic = bfd_get_section_by_name (abfd, ".dynamic");
2767 if (dynamic != NULL)
2769 bfd_byte *dynbuf, *extdyn, *extdynend;
2771 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
2773 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
2776 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
2777 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
2780 extdynend = extdyn + dynamic->size;
2781 for (; extdyn < extdynend; extdyn += extdynsize)
2783 Elf_Internal_Dyn dyn;
2784 (*swap_dyn_in) (abfd, extdyn, &dyn);
2786 if (dyn.d_tag == DT_NULL)
2789 if (dyn.d_tag == DT_PPC_GOT)
2791 unsigned int g_o_t = dyn.d_un.d_val;
2792 asection *got = bfd_get_section_by_name (abfd, ".got");
2794 && bfd_get_section_contents (abfd, got, buf,
2795 g_o_t - got->vma + 4, 4))
2796 glink_vma = bfd_get_32 (abfd, buf);
2803 /* Otherwise we read the first plt entry. */
2806 if (bfd_get_section_contents (abfd, plt, buf, 0, 4))
2807 glink_vma = bfd_get_32 (abfd, buf);
2813 /* The .glink section usually does not survive the final
2814 link; search for the section (usually .text) where the
2815 glink stubs now reside. */
2816 glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma);
2820 /* Determine glink PLT resolver by reading the relative branch
2821 from the first glink stub. */
2822 if (bfd_get_section_contents (abfd, glink, buf,
2823 glink_vma - glink->vma, 4))
2825 unsigned int insn = bfd_get_32 (abfd, buf);
2827 /* The first glink stub may either branch to the resolver ... */
2829 if ((insn & ~0x3fffffc) == 0)
2830 resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000;
2832 /* ... or fall through a bunch of NOPs. */
2833 else if ((insn ^ B ^ NOP) == 0)
2835 bfd_get_section_contents (abfd, glink, buf,
2836 glink_vma - glink->vma + i, 4);
2838 if (bfd_get_32 (abfd, buf) != NOP)
2840 resolv_vma = glink_vma + i;
2845 count = relplt->size / sizeof (Elf32_External_Rela);
2846 stub_vma = glink_vma - (bfd_vma) count * 16;
2847 /* If the stubs are those for -shared/-pie then we might have
2848 multiple stubs for each plt entry. If that is the case then
2849 there is no way to associate stubs with their plt entries short
2850 of figuring out the GOT pointer value used in the stub. */
2851 if (!is_nonpic_glink_stub (abfd, glink,
2852 glink_vma - GLINK_ENTRY_SIZE - glink->vma))
2855 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
2856 if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
2859 size = count * sizeof (asymbol);
2860 p = relplt->relocation;
2861 for (i = 0; i < count; i++, p++)
2863 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
2865 size += sizeof ("+0x") - 1 + 8;
2868 size += sizeof (asymbol) + sizeof ("__glink");
2871 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
2873 s = *ret = bfd_malloc (size);
2877 names = (char *) (s + count + 1 + (resolv_vma != 0));
2878 p = relplt->relocation;
2879 for (i = 0; i < count; i++, p++)
2883 *s = **p->sym_ptr_ptr;
2884 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2885 we are defining a symbol, ensure one of them is set. */
2886 if ((s->flags & BSF_LOCAL) == 0)
2887 s->flags |= BSF_GLOBAL;
2888 s->flags |= BSF_SYNTHETIC;
2890 s->value = stub_vma - glink->vma;
2893 len = strlen ((*p->sym_ptr_ptr)->name);
2894 memcpy (names, (*p->sym_ptr_ptr)->name, len);
2898 memcpy (names, "+0x", sizeof ("+0x") - 1);
2899 names += sizeof ("+0x") - 1;
2900 bfd_sprintf_vma (abfd, names, p->addend);
2901 names += strlen (names);
2903 memcpy (names, "@plt", sizeof ("@plt"));
2904 names += sizeof ("@plt");
2909 /* Add a symbol at the start of the glink branch table. */
2910 memset (s, 0, sizeof *s);
2912 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
2914 s->value = glink_vma - glink->vma;
2916 memcpy (names, "__glink", sizeof ("__glink"));
2917 names += sizeof ("__glink");
2923 /* Add a symbol for the glink PLT resolver. */
2924 memset (s, 0, sizeof *s);
2926 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
2928 s->value = resolv_vma - glink->vma;
2930 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2931 names += sizeof ("__glink_PLTresolve");
2939 /* The following functions are specific to the ELF linker, while
2940 functions above are used generally. They appear in this file more
2941 or less in the order in which they are called. eg.
2942 ppc_elf_check_relocs is called early in the link process,
2943 ppc_elf_finish_dynamic_sections is one of the last functions
2946 /* Track PLT entries needed for a given symbol. We might need more
2947 than one glink entry per symbol when generating a pic binary. */
2950 struct plt_entry *next;
2952 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2953 This field stores the offset into .got2 used to initialise the
2954 GOT pointer reg. It will always be at least 32768. (Current
2955 gcc always uses an offset of 32768, but ld -r will pack .got2
2956 sections together resulting in larger offsets). */
2959 /* The .got2 section. */
2962 /* PLT refcount or offset. */
2965 bfd_signed_vma refcount;
2969 /* .glink stub offset. */
2970 bfd_vma glink_offset;
2973 /* Of those relocs that might be copied as dynamic relocs, this function
2974 selects those that must be copied when linking a shared library,
2975 even when the symbol is local. */
2978 must_be_dyn_reloc (struct bfd_link_info *info,
2979 enum elf_ppc_reloc_type r_type)
2988 case R_PPC_REL14_BRTAKEN:
2989 case R_PPC_REL14_BRNTAKEN:
2995 case R_PPC_TPREL16_LO:
2996 case R_PPC_TPREL16_HI:
2997 case R_PPC_TPREL16_HA:
2998 return !info->executable;
3002 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3003 copying dynamic variables from a shared lib into an app's dynbss
3004 section, and instead use a dynamic relocation to point into the
3006 #define ELIMINATE_COPY_RELOCS 1
3008 /* PPC ELF linker hash entry. */
3010 struct ppc_elf_link_hash_entry
3012 struct elf_link_hash_entry elf;
3014 /* If this symbol is used in the linker created sections, the processor
3015 specific backend uses this field to map the field into the offset
3016 from the beginning of the section. */
3017 elf_linker_section_pointers_t *linker_section_pointer;
3019 /* Track dynamic relocs copied for this symbol. */
3020 struct elf_dyn_relocs *dyn_relocs;
3022 /* Contexts in which symbol is used in the GOT (or TOC).
3023 TLS_GD .. TLS_TLS bits are or'd into the mask as the
3024 corresponding relocs are encountered during check_relocs.
3025 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3026 indicate the corresponding GOT entry type is not needed. */
3027 #define TLS_GD 1 /* GD reloc. */
3028 #define TLS_LD 2 /* LD reloc. */
3029 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3030 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3031 #define TLS_TLS 16 /* Any TLS reloc. */
3032 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
3033 #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
3036 /* Nonzero if we have seen a small data relocation referring to this
3038 unsigned char has_sda_refs;
3041 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
3043 /* PPC ELF linker hash table. */
3045 struct ppc_elf_link_hash_table
3047 struct elf_link_hash_table elf;
3049 /* Short-cuts to get to dynamic linker sections. */
3061 elf_linker_section_t sdata[2];
3063 asection *glink_eh_frame;
3065 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
3068 /* The .got.plt section (VxWorks only)*/
3071 /* Shortcut to __tls_get_addr. */
3072 struct elf_link_hash_entry *tls_get_addr;
3074 /* The bfd that forced an old-style PLT. */
3077 /* TLS local dynamic got entry handling. */
3079 bfd_signed_vma refcount;
3083 /* Offset of branch table to PltResolve function in glink. */
3084 bfd_vma glink_pltresolve;
3086 /* Size of reserved GOT entries. */
3087 unsigned int got_header_size;
3088 /* Non-zero if allocating the header left a gap. */
3089 unsigned int got_gap;
3091 /* The type of PLT we have chosen to use. */
3092 enum ppc_elf_plt_type plt_type;
3094 /* Set if we should emit symbols for stubs. */
3095 unsigned int emit_stub_syms:1;
3097 /* Set if __tls_get_addr optimization should not be done. */
3098 unsigned int no_tls_get_addr_opt:1;
3100 /* True if the target system is VxWorks. */
3101 unsigned int is_vxworks:1;
3103 /* The size of PLT entries. */
3105 /* The distance between adjacent PLT slots. */
3107 /* The size of the first PLT entry. */
3108 int plt_initial_entry_size;
3110 /* Small local sym cache. */
3111 struct sym_cache sym_cache;
3114 /* Rename some of the generic section flags to better document how they
3115 are used for ppc32. The flags are only valid for ppc32 elf objects. */
3117 /* Nonzero if this section has TLS related relocations. */
3118 #define has_tls_reloc sec_flg0
3120 /* Nonzero if this section has a call to __tls_get_addr. */
3121 #define has_tls_get_addr_call sec_flg1
3123 /* Get the PPC ELF linker hash table from a link_info structure. */
3125 #define ppc_elf_hash_table(p) \
3126 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3127 == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
3129 /* Create an entry in a PPC ELF linker hash table. */
3131 static struct bfd_hash_entry *
3132 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
3133 struct bfd_hash_table *table,
3136 /* Allocate the structure if it has not already been allocated by a
3140 entry = bfd_hash_allocate (table,
3141 sizeof (struct ppc_elf_link_hash_entry));
3146 /* Call the allocation method of the superclass. */
3147 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
3150 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
3151 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
3152 ppc_elf_hash_entry (entry)->tls_mask = 0;
3153 ppc_elf_hash_entry (entry)->has_sda_refs = 0;
3159 /* Create a PPC ELF linker hash table. */
3161 static struct bfd_link_hash_table *
3162 ppc_elf_link_hash_table_create (bfd *abfd)
3164 struct ppc_elf_link_hash_table *ret;
3166 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
3170 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
3171 ppc_elf_link_hash_newfunc,
3172 sizeof (struct ppc_elf_link_hash_entry),
3179 ret->elf.init_plt_refcount.refcount = 0;
3180 ret->elf.init_plt_refcount.glist = NULL;
3181 ret->elf.init_plt_offset.offset = 0;
3182 ret->elf.init_plt_offset.glist = NULL;
3184 ret->sdata[0].name = ".sdata";
3185 ret->sdata[0].sym_name = "_SDA_BASE_";
3186 ret->sdata[0].bss_name = ".sbss";
3188 ret->sdata[1].name = ".sdata2";
3189 ret->sdata[1].sym_name = "_SDA2_BASE_";
3190 ret->sdata[1].bss_name = ".sbss2";
3192 ret->plt_entry_size = 12;
3193 ret->plt_slot_size = 8;
3194 ret->plt_initial_entry_size = 72;
3196 return &ret->elf.root;
3199 /* Create .got and the related sections. */
3202 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
3204 struct ppc_elf_link_hash_table *htab;
3208 if (!_bfd_elf_create_got_section (abfd, info))
3211 htab = ppc_elf_hash_table (info);
3212 htab->got = s = bfd_get_section_by_name (abfd, ".got");
3216 if (htab->is_vxworks)
3218 htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt");
3224 /* The powerpc .got has a blrl instruction in it. Mark it
3226 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
3227 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3228 if (!bfd_set_section_flags (abfd, s, flags))
3232 htab->relgot = bfd_get_section_by_name (abfd, ".rela.got");
3240 ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
3242 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
3246 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS
3247 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3248 s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags);
3251 || !bfd_set_section_alignment (abfd, s, 4))
3254 if (!info->no_ld_generated_unwind_info)
3256 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
3257 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3258 s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags);
3259 htab->glink_eh_frame = s;
3261 || !bfd_set_section_alignment (abfd, s, 2))
3265 flags = SEC_ALLOC | SEC_LINKER_CREATED;
3266 s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
3269 || !bfd_set_section_alignment (abfd, s, 4))
3272 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
3273 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3274 s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags);
3277 || ! bfd_set_section_alignment (abfd, s, 2))
3282 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
3283 to output sections (just like _bfd_elf_create_dynamic_sections has
3284 to create .dynbss and .rela.bss). */
3287 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3289 struct ppc_elf_link_hash_table *htab;
3293 htab = ppc_elf_hash_table (info);
3295 if (htab->got == NULL
3296 && !ppc_elf_create_got (abfd, info))
3299 if (!_bfd_elf_create_dynamic_sections (abfd, info))
3302 if (htab->glink == NULL
3303 && !ppc_elf_create_glink (abfd, info))
3306 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
3307 s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
3308 SEC_ALLOC | SEC_LINKER_CREATED);
3315 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
3316 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
3317 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3318 s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
3321 || ! bfd_set_section_alignment (abfd, s, 2))
3325 if (htab->is_vxworks
3326 && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
3329 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
3330 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
3334 flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
3335 if (htab->plt_type == PLT_VXWORKS)
3336 /* The VxWorks PLT is a loaded section with contents. */
3337 flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
3338 return bfd_set_section_flags (abfd, s, flags);
3341 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3344 ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
3345 struct elf_link_hash_entry *dir,
3346 struct elf_link_hash_entry *ind)
3348 struct ppc_elf_link_hash_entry *edir, *eind;
3350 edir = (struct ppc_elf_link_hash_entry *) dir;
3351 eind = (struct ppc_elf_link_hash_entry *) ind;
3353 edir->tls_mask |= eind->tls_mask;
3354 edir->has_sda_refs |= eind->has_sda_refs;
3356 /* If called to transfer flags for a weakdef during processing
3357 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3358 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3359 if (!(ELIMINATE_COPY_RELOCS
3360 && eind->elf.root.type != bfd_link_hash_indirect
3361 && edir->elf.dynamic_adjusted))
3362 edir->elf.non_got_ref |= eind->elf.non_got_ref;
3364 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
3365 edir->elf.ref_regular |= eind->elf.ref_regular;
3366 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
3367 edir->elf.needs_plt |= eind->elf.needs_plt;
3368 edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
3370 if (eind->dyn_relocs != NULL)
3372 if (edir->dyn_relocs != NULL)
3374 struct elf_dyn_relocs **pp;
3375 struct elf_dyn_relocs *p;
3377 /* Add reloc counts against the indirect sym to the direct sym
3378 list. Merge any entries against the same section. */
3379 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3381 struct elf_dyn_relocs *q;
3383 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3384 if (q->sec == p->sec)
3386 q->pc_count += p->pc_count;
3387 q->count += p->count;
3394 *pp = edir->dyn_relocs;
3397 edir->dyn_relocs = eind->dyn_relocs;
3398 eind->dyn_relocs = NULL;
3401 /* If we were called to copy over info for a weak sym, that's all.
3402 You might think dyn_relocs need not be copied over; After all,
3403 both syms will be dynamic or both non-dynamic so we're just
3404 moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
3405 code in ppc_elf_adjust_dynamic_symbol needs to check for
3406 dyn_relocs in read-only sections, and it does so on what is the
3408 if (eind->elf.root.type != bfd_link_hash_indirect)
3411 /* Copy over the GOT refcount entries that we may have already seen to
3412 the symbol which just became indirect. */
3413 edir->elf.got.refcount += eind->elf.got.refcount;
3414 eind->elf.got.refcount = 0;
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->sec == ent->sec && 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 (eind->elf.dynindx != -1)
3447 if (edir->elf.dynindx != -1)
3448 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
3449 edir->elf.dynstr_index);
3450 edir->elf.dynindx = eind->elf.dynindx;
3451 edir->elf.dynstr_index = eind->elf.dynstr_index;
3452 eind->elf.dynindx = -1;
3453 eind->elf.dynstr_index = 0;
3457 /* Hook called by the linker routine which adds symbols from an object
3458 file. We use it to put .comm items in .sbss, and not .bss. */
3461 ppc_elf_add_symbol_hook (bfd *abfd,
3462 struct bfd_link_info *info,
3463 Elf_Internal_Sym *sym,
3464 const char **namep ATTRIBUTE_UNUSED,
3465 flagword *flagsp ATTRIBUTE_UNUSED,
3469 if (sym->st_shndx == SHN_COMMON
3470 && !info->relocatable
3471 && is_ppc_elf (info->output_bfd)
3472 && sym->st_size <= elf_gp_size (abfd))
3474 /* Common symbols less than or equal to -G nn bytes are automatically
3476 struct ppc_elf_link_hash_table *htab;
3478 htab = ppc_elf_hash_table (info);
3479 if (htab->sbss == NULL)
3481 flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
3483 if (!htab->elf.dynobj)
3484 htab->elf.dynobj = abfd;
3486 htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
3489 if (htab->sbss == NULL)
3494 *valp = sym->st_size;
3497 if ((abfd->flags & DYNAMIC) == 0
3498 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
3499 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
3500 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
3506 create_sdata_sym (struct bfd_link_info *info, elf_linker_section_t *lsect)
3508 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
3510 lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
3512 if (lsect->sym == NULL)
3514 if (lsect->sym->root.type == bfd_link_hash_new)
3515 lsect->sym->non_elf = 0;
3516 lsect->sym->ref_regular = 1;
3517 _bfd_elf_link_hash_hide_symbol (info, lsect->sym, TRUE);
3521 /* Create a special linker section. */
3524 ppc_elf_create_linker_section (bfd *abfd,
3525 struct bfd_link_info *info,
3527 elf_linker_section_t *lsect)
3529 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
3532 flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3533 | SEC_LINKER_CREATED);
3535 /* Record the first bfd that needs the special sections. */
3536 if (!htab->elf.dynobj)
3537 htab->elf.dynobj = abfd;
3539 s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
3543 || !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
3547 return create_sdata_sym (info, lsect);
3550 /* Find a linker generated pointer with a given addend and type. */
3552 static elf_linker_section_pointers_t *
3553 elf_find_pointer_linker_section
3554 (elf_linker_section_pointers_t *linker_pointers,
3556 elf_linker_section_t *lsect)
3558 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
3559 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
3560 return linker_pointers;
3565 /* Allocate a pointer to live in a linker created section. */
3568 elf_create_pointer_linker_section (bfd *abfd,
3569 elf_linker_section_t *lsect,
3570 struct elf_link_hash_entry *h,
3571 const Elf_Internal_Rela *rel)
3573 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
3574 elf_linker_section_pointers_t *linker_section_ptr;
3575 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
3578 BFD_ASSERT (lsect != NULL);
3580 /* Is this a global symbol? */
3583 struct ppc_elf_link_hash_entry *eh;
3585 /* Has this symbol already been allocated? If so, our work is done. */
3586 eh = (struct ppc_elf_link_hash_entry *) h;
3587 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
3592 ptr_linker_section_ptr = &eh->linker_section_pointer;
3596 BFD_ASSERT (is_ppc_elf (abfd));
3598 /* Allocation of a pointer to a local symbol. */
3599 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
3601 /* Allocate a table to hold the local symbols if first time. */
3604 unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info;
3607 amt *= sizeof (elf_linker_section_pointers_t *);
3608 ptr = bfd_zalloc (abfd, amt);
3613 elf_local_ptr_offsets (abfd) = ptr;
3616 /* Has this symbol already been allocated? If so, our work is done. */
3617 if (elf_find_pointer_linker_section (ptr[r_symndx],
3622 ptr_linker_section_ptr = &ptr[r_symndx];
3625 /* Allocate space for a pointer in the linker section, and allocate
3626 a new pointer record from internal memory. */
3627 BFD_ASSERT (ptr_linker_section_ptr != NULL);
3628 amt = sizeof (elf_linker_section_pointers_t);
3629 linker_section_ptr = bfd_alloc (abfd, amt);
3631 if (!linker_section_ptr)
3634 linker_section_ptr->next = *ptr_linker_section_ptr;
3635 linker_section_ptr->addend = rel->r_addend;
3636 linker_section_ptr->lsect = lsect;
3637 *ptr_linker_section_ptr = linker_section_ptr;
3639 linker_section_ptr->offset = lsect->section->size;
3640 lsect->section->size += 4;
3644 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
3645 lsect->name, (long) linker_section_ptr->offset,
3646 (long) lsect->section->size);
3652 static struct plt_entry **
3653 update_local_sym_info (bfd *abfd,
3654 Elf_Internal_Shdr *symtab_hdr,
3655 unsigned long r_symndx,
3658 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
3659 struct plt_entry **local_plt;
3660 char *local_got_tls_masks;
3662 if (local_got_refcounts == NULL)
3664 bfd_size_type size = symtab_hdr->sh_info;
3666 size *= (sizeof (*local_got_refcounts)
3667 + sizeof (*local_plt)
3668 + sizeof (*local_got_tls_masks));
3669 local_got_refcounts = bfd_zalloc (abfd, size);
3670 if (local_got_refcounts == NULL)
3672 elf_local_got_refcounts (abfd) = local_got_refcounts;
3675 local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info);
3676 local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info);
3677 local_got_tls_masks[r_symndx] |= tls_type;
3678 if (tls_type != PLT_IFUNC)
3679 local_got_refcounts[r_symndx] += 1;
3680 return local_plt + r_symndx;
3684 update_plt_info (bfd *abfd, struct plt_entry **plist,
3685 asection *sec, bfd_vma addend)
3687 struct plt_entry *ent;
3691 for (ent = *plist; ent != NULL; ent = ent->next)
3692 if (ent->sec == sec && ent->addend == addend)
3696 bfd_size_type amt = sizeof (*ent);
3697 ent = bfd_alloc (abfd, amt);
3702 ent->addend = addend;
3703 ent->plt.refcount = 0;
3706 ent->plt.refcount += 1;
3710 static struct plt_entry *
3711 find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend)
3713 struct plt_entry *ent;
3717 for (ent = *plist; ent != NULL; ent = ent->next)
3718 if (ent->sec == sec && ent->addend == addend)
3724 is_branch_reloc (enum elf_ppc_reloc_type r_type)
3726 return (r_type == R_PPC_PLTREL24
3727 || r_type == R_PPC_LOCAL24PC
3728 || r_type == R_PPC_REL24
3729 || r_type == R_PPC_REL14
3730 || r_type == R_PPC_REL14_BRTAKEN
3731 || r_type == R_PPC_REL14_BRNTAKEN
3732 || r_type == R_PPC_ADDR24
3733 || r_type == R_PPC_ADDR14
3734 || r_type == R_PPC_ADDR14_BRTAKEN
3735 || r_type == R_PPC_ADDR14_BRNTAKEN);
3739 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
3741 (*_bfd_error_handler)
3742 (_("%B: relocation %s cannot be used when making a shared object"),
3744 ppc_elf_howto_table[r_type]->name);
3745 bfd_set_error (bfd_error_bad_value);
3748 /* Look through the relocs for a section during the first phase, and
3749 allocate space in the global offset table or procedure linkage
3753 ppc_elf_check_relocs (bfd *abfd,
3754 struct bfd_link_info *info,
3756 const Elf_Internal_Rela *relocs)
3758 struct ppc_elf_link_hash_table *htab;
3759 Elf_Internal_Shdr *symtab_hdr;
3760 struct elf_link_hash_entry **sym_hashes;
3761 const Elf_Internal_Rela *rel;
3762 const Elf_Internal_Rela *rel_end;
3763 asection *got2, *sreloc;
3764 struct elf_link_hash_entry *tga;
3766 if (info->relocatable)
3769 /* Don't do anything special with non-loaded, non-alloced sections.
3770 In particular, any relocs in such sections should not affect GOT
3771 and PLT reference counting (ie. we don't allow them to create GOT
3772 or PLT entries), there's no possibility or desire to optimize TLS
3773 relocs, and there's not much point in propagating relocs to shared
3774 libs that the dynamic linker won't relocate. */
3775 if ((sec->flags & SEC_ALLOC) == 0)
3779 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3783 BFD_ASSERT (is_ppc_elf (abfd));
3785 /* Initialize howto table if not already done. */
3786 if (!ppc_elf_howto_table[R_PPC_ADDR32])
3787 ppc_elf_howto_init ();
3789 htab = ppc_elf_hash_table (info);
3790 if (htab->glink == NULL)
3792 if (htab->elf.dynobj == NULL)
3793 htab->elf.dynobj = abfd;
3794 if (!ppc_elf_create_glink (htab->elf.dynobj, info))
3797 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3798 FALSE, FALSE, TRUE);
3799 symtab_hdr = &elf_symtab_hdr (abfd);
3800 sym_hashes = elf_sym_hashes (abfd);
3801 got2 = bfd_get_section_by_name (abfd, ".got2");
3804 rel_end = relocs + sec->reloc_count;
3805 for (rel = relocs; rel < rel_end; rel++)
3807 unsigned long r_symndx;
3808 enum elf_ppc_reloc_type r_type;
3809 struct elf_link_hash_entry *h;
3812 r_symndx = ELF32_R_SYM (rel->r_info);
3813 if (r_symndx < symtab_hdr->sh_info)
3817 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3818 while (h->root.type == bfd_link_hash_indirect
3819 || h->root.type == bfd_link_hash_warning)
3820 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3823 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3824 This shows up in particular in an R_PPC_ADDR32 in the eabi
3827 && htab->got == NULL
3828 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3830 if (htab->elf.dynobj == NULL)
3831 htab->elf.dynobj = abfd;
3832 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3834 BFD_ASSERT (h == htab->elf.hgot);
3838 r_type = ELF32_R_TYPE (rel->r_info);
3839 if (h == NULL && !htab->is_vxworks)
3841 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3846 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
3848 || is_branch_reloc (r_type)))
3850 struct plt_entry **ifunc;
3853 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
3858 /* STT_GNU_IFUNC symbols must have a PLT entry;
3859 In a non-pie executable even when there are
3862 if (r_type == R_PPC_PLTREL24)
3864 ppc_elf_tdata (abfd)->makes_plt_call = 1;
3866 addend = rel->r_addend;
3868 if (!update_plt_info (abfd, ifunc, got2, addend))
3873 if (!htab->is_vxworks
3874 && is_branch_reloc (r_type)
3879 && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
3880 || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
3881 /* We have a new-style __tls_get_addr call with a marker
3885 /* Mark this section as having an old-style call. */
3886 sec->has_tls_get_addr_call = 1;
3893 /* These special tls relocs tie a call to __tls_get_addr with
3894 its parameter symbol. */
3897 case R_PPC_GOT_TLSLD16:
3898 case R_PPC_GOT_TLSLD16_LO:
3899 case R_PPC_GOT_TLSLD16_HI:
3900 case R_PPC_GOT_TLSLD16_HA:
3901 tls_type = TLS_TLS | TLS_LD;
3904 case R_PPC_GOT_TLSGD16:
3905 case R_PPC_GOT_TLSGD16_LO:
3906 case R_PPC_GOT_TLSGD16_HI:
3907 case R_PPC_GOT_TLSGD16_HA:
3908 tls_type = TLS_TLS | TLS_GD;
3911 case R_PPC_GOT_TPREL16:
3912 case R_PPC_GOT_TPREL16_LO:
3913 case R_PPC_GOT_TPREL16_HI:
3914 case R_PPC_GOT_TPREL16_HA:
3915 if (!info->executable)
3916 info->flags |= DF_STATIC_TLS;
3917 tls_type = TLS_TLS | TLS_TPREL;
3920 case R_PPC_GOT_DTPREL16:
3921 case R_PPC_GOT_DTPREL16_LO:
3922 case R_PPC_GOT_DTPREL16_HI:
3923 case R_PPC_GOT_DTPREL16_HA:
3924 tls_type = TLS_TLS | TLS_DTPREL;
3926 sec->has_tls_reloc = 1;
3929 /* GOT16 relocations */
3931 case R_PPC_GOT16_LO:
3932 case R_PPC_GOT16_HI:
3933 case R_PPC_GOT16_HA:
3934 /* This symbol requires a global offset table entry. */
3935 if (htab->got == NULL)
3937 if (htab->elf.dynobj == NULL)
3938 htab->elf.dynobj = abfd;
3939 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3944 h->got.refcount += 1;
3945 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3948 /* This is a global offset table entry for a local symbol. */
3949 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3952 /* We may also need a plt entry if the symbol turns out to be
3954 if (h != NULL && !info->shared)
3956 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
3961 /* Indirect .sdata relocation. */
3962 case R_PPC_EMB_SDAI16:
3965 bad_shared_reloc (abfd, r_type);
3968 if (htab->sdata[0].section == NULL
3969 && !ppc_elf_create_linker_section (abfd, info, 0,
3972 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
3977 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3978 h->non_got_ref = TRUE;
3982 /* Indirect .sdata2 relocation. */
3983 case R_PPC_EMB_SDA2I16:
3986 bad_shared_reloc (abfd, r_type);
3989 if (htab->sdata[1].section == NULL
3990 && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
3993 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
3998 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3999 h->non_got_ref = TRUE;
4003 case R_PPC_VLE_SDAREL_LO16A:
4004 case R_PPC_VLE_SDAREL_LO16D:
4005 case R_PPC_VLE_SDAREL_HI16A:
4006 case R_PPC_VLE_SDAREL_HI16D:
4007 case R_PPC_VLE_SDAREL_HA16A:
4008 case R_PPC_VLE_SDAREL_HA16D:
4009 case R_PPC_SDAREL16:
4010 if (htab->sdata[0].sym == NULL
4011 && !create_sdata_sym (info, &htab->sdata[0]))
4014 if (htab->sdata[1].sym == NULL
4015 && !create_sdata_sym (info, &htab->sdata[1]))
4020 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
4021 h->non_got_ref = TRUE;
4025 case R_PPC_VLE_REL8:
4026 case R_PPC_VLE_REL15:
4027 case R_PPC_VLE_REL24:
4028 case R_PPC_VLE_LO16A:
4029 case R_PPC_VLE_LO16D:
4030 case R_PPC_VLE_HI16A:
4031 case R_PPC_VLE_HI16D:
4032 case R_PPC_VLE_HA16A:
4033 case R_PPC_VLE_HA16D:
4036 case R_PPC_EMB_SDA2REL:
4039 bad_shared_reloc (abfd, r_type);
4042 if (htab->sdata[1].sym == NULL
4043 && !create_sdata_sym (info, &htab->sdata[1]))
4047 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
4048 h->non_got_ref = TRUE;
4052 case R_PPC_VLE_SDA21_LO:
4053 case R_PPC_VLE_SDA21:
4054 case R_PPC_EMB_SDA21:
4055 case R_PPC_EMB_RELSDA:
4058 bad_shared_reloc (abfd, r_type);
4061 if (htab->sdata[0].sym == NULL
4062 && !create_sdata_sym (info, &htab->sdata[0]))
4064 if (htab->sdata[1].sym == NULL
4065 && !create_sdata_sym (info, &htab->sdata[1]))
4069 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
4070 h->non_got_ref = TRUE;
4074 case R_PPC_EMB_NADDR32:
4075 case R_PPC_EMB_NADDR16:
4076 case R_PPC_EMB_NADDR16_LO:
4077 case R_PPC_EMB_NADDR16_HI:
4078 case R_PPC_EMB_NADDR16_HA:
4081 bad_shared_reloc (abfd, r_type);
4085 h->non_got_ref = TRUE;
4088 case R_PPC_PLTREL24:
4093 case R_PPC_PLTREL32:
4094 case R_PPC_PLT16_LO:
4095 case R_PPC_PLT16_HI:
4096 case R_PPC_PLT16_HA:
4098 fprintf (stderr, "Reloc requires a PLT entry\n");
4100 /* This symbol requires a procedure linkage table entry. We
4101 actually build the entry in finish_dynamic_symbol,
4102 because this might be a case of linking PIC code without
4103 linking in any dynamic objects, in which case we don't
4104 need to generate a procedure linkage table after all. */
4108 /* It does not make sense to have a procedure linkage
4109 table entry for a local symbol. */
4110 info->callbacks->einfo (_("%P: %H: %s reloc against local symbol\n"),
4111 abfd, sec, rel->r_offset,
4112 ppc_elf_howto_table[r_type]->name);
4113 bfd_set_error (bfd_error_bad_value);
4120 if (r_type == R_PPC_PLTREL24)
4122 ppc_elf_tdata (abfd)->makes_plt_call = 1;
4124 addend = rel->r_addend;
4127 if (!update_plt_info (abfd, &h->plt.plist, got2, addend))
4132 /* The following relocations don't need to propagate the
4133 relocation if linking a shared object since they are
4134 section relative. */
4136 case R_PPC_SECTOFF_LO:
4137 case R_PPC_SECTOFF_HI:
4138 case R_PPC_SECTOFF_HA:
4139 case R_PPC_DTPREL16:
4140 case R_PPC_DTPREL16_LO:
4141 case R_PPC_DTPREL16_HI:
4142 case R_PPC_DTPREL16_HA:
4147 case R_PPC_REL16_LO:
4148 case R_PPC_REL16_HI:
4149 case R_PPC_REL16_HA:
4150 ppc_elf_tdata (abfd)->has_rel16 = 1;
4153 /* These are just markers. */
4155 case R_PPC_EMB_MRKREF:
4159 case R_PPC_RELAX_PLT:
4160 case R_PPC_RELAX_PLTREL24:
4163 /* These should only appear in dynamic objects. */
4165 case R_PPC_GLOB_DAT:
4166 case R_PPC_JMP_SLOT:
4167 case R_PPC_RELATIVE:
4168 case R_PPC_IRELATIVE:
4171 /* These aren't handled yet. We'll report an error later. */
4173 case R_PPC_EMB_RELSEC16:
4174 case R_PPC_EMB_RELST_LO:
4175 case R_PPC_EMB_RELST_HI:
4176 case R_PPC_EMB_RELST_HA:
4177 case R_PPC_EMB_BIT_FLD:
4180 /* This refers only to functions defined in the shared library. */
4181 case R_PPC_LOCAL24PC:
4182 if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
4184 htab->plt_type = PLT_OLD;
4185 htab->old_bfd = abfd;
4189 /* This relocation describes the C++ object vtable hierarchy.
4190 Reconstruct it for later use during GC. */
4191 case R_PPC_GNU_VTINHERIT:
4192 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4196 /* This relocation describes which C++ vtable entries are actually
4197 used. Record for later use during GC. */
4198 case R_PPC_GNU_VTENTRY:
4199 BFD_ASSERT (h != NULL);
4201 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4205 /* We shouldn't really be seeing these. */
4208 case R_PPC_TPREL16_LO:
4209 case R_PPC_TPREL16_HI:
4210 case R_PPC_TPREL16_HA:
4211 if (!info->executable)
4212 info->flags |= DF_STATIC_TLS;
4216 case R_PPC_DTPMOD32:
4217 case R_PPC_DTPREL32:
4223 && (sec->flags & SEC_CODE) != 0
4225 && htab->plt_type == PLT_UNSET)
4227 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
4228 the start of a function, which assembles to a REL32
4229 reference to .got2. If we detect one of these, then
4230 force the old PLT layout because the linker cannot
4231 reliably deduce the GOT pointer value needed for
4234 Elf_Internal_Sym *isym;
4236 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
4241 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
4244 htab->plt_type = PLT_OLD;
4245 htab->old_bfd = abfd;
4248 if (h == NULL || h == htab->elf.hgot)
4254 case R_PPC_ADDR16_LO:
4255 case R_PPC_ADDR16_HI:
4256 case R_PPC_ADDR16_HA:
4259 if (h != NULL && !info->shared)
4261 /* We may need a plt entry if the symbol turns out to be
4262 a function defined in a dynamic object. */
4263 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
4266 /* We may need a copy reloc too. */
4268 h->pointer_equality_needed = 1;
4274 case R_PPC_REL14_BRTAKEN:
4275 case R_PPC_REL14_BRNTAKEN:
4278 if (h == htab->elf.hgot)
4280 if (htab->plt_type == PLT_UNSET)
4282 htab->plt_type = PLT_OLD;
4283 htab->old_bfd = abfd;
4291 case R_PPC_ADDR14_BRTAKEN:
4292 case R_PPC_ADDR14_BRNTAKEN:
4293 if (h != NULL && !info->shared)
4295 /* We may need a plt entry if the symbol turns out to be
4296 a function defined in a dynamic object. */
4298 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
4304 /* If we are creating a shared library, and this is a reloc
4305 against a global symbol, or a non PC relative reloc
4306 against a local symbol, then we need to copy the reloc
4307 into the shared library. However, if we are linking with
4308 -Bsymbolic, we do not need to copy a reloc against a
4309 global symbol which is defined in an object we are
4310 including in the link (i.e., DEF_REGULAR is set). At
4311 this point we have not seen all the input files, so it is
4312 possible that DEF_REGULAR is not set now but will be set
4313 later (it is never cleared). In case of a weak definition,
4314 DEF_REGULAR may be cleared later by a strong definition in
4315 a shared library. We account for that possibility below by
4316 storing information in the dyn_relocs field of the hash
4317 table entry. A similar situation occurs when creating
4318 shared libraries and symbol visibility changes render the
4321 If on the other hand, we are creating an executable, we
4322 may need to keep relocations for symbols satisfied by a
4323 dynamic library if we manage to avoid copy relocs for the
4326 && (must_be_dyn_reloc (info, r_type)
4328 && (! info->symbolic
4329 || h->root.type == bfd_link_hash_defweak
4330 || !h->def_regular))))
4331 || (ELIMINATE_COPY_RELOCS
4334 && (h->root.type == bfd_link_hash_defweak
4335 || !h->def_regular)))
4337 struct elf_dyn_relocs *p;
4338 struct elf_dyn_relocs **rel_head;
4342 "ppc_elf_check_relocs needs to "
4343 "create relocation for %s\n",
4344 (h && h->root.root.string
4345 ? h->root.root.string : "<unknown>"));
4349 if (htab->elf.dynobj == NULL)
4350 htab->elf.dynobj = abfd;
4352 sreloc = _bfd_elf_make_dynamic_reloc_section
4353 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
4359 /* If this is a global symbol, we count the number of
4360 relocations we need for this symbol. */
4363 rel_head = &ppc_elf_hash_entry (h)->dyn_relocs;
4367 /* Track dynamic relocs needed for local syms too.
4368 We really need local syms available to do this
4372 Elf_Internal_Sym *isym;
4374 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
4379 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
4383 vpp = &elf_section_data (s)->local_dynrel;
4384 rel_head = (struct elf_dyn_relocs **) vpp;
4388 if (p == NULL || p->sec != sec)
4390 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
4393 p->next = *rel_head;
4401 if (!must_be_dyn_reloc (info, r_type))
4413 /* Merge object attributes from IBFD into OBFD. Raise an error if
4414 there are conflicting attributes. */
4416 ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
4418 obj_attribute *in_attr, *in_attrs;
4419 obj_attribute *out_attr, *out_attrs;
4421 if (!elf_known_obj_attributes_proc (obfd)[0].i)
4423 /* This is the first object. Copy the attributes. */
4424 _bfd_elf_copy_obj_attributes (ibfd, obfd);
4426 /* Use the Tag_null value to indicate the attributes have been
4428 elf_known_obj_attributes_proc (obfd)[0].i = 1;
4433 in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
4434 out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
4436 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
4437 non-conflicting ones. */
4438 in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
4439 out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
4440 if (in_attr->i != out_attr->i)
4443 if (out_attr->i == 0)
4444 out_attr->i = in_attr->i;
4445 else if (in_attr->i == 0)
4447 else if (out_attr->i == 1 && in_attr->i == 2)
4449 (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
4450 else if (out_attr->i == 1 && in_attr->i == 3)
4452 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4454 else if (out_attr->i == 3 && in_attr->i == 1)
4456 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4458 else if (out_attr->i == 3 && in_attr->i == 2)
4460 (_("Warning: %B uses soft float, %B uses single-precision hard float"),
4462 else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
4464 (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
4465 else if (in_attr->i > 3)
4467 (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
4471 (_("Warning: %B uses unknown floating point ABI %d"), obfd,
4475 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
4476 merge non-conflicting ones. */
4477 in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector];
4478 out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
4479 if (in_attr->i != out_attr->i)
4481 const char *in_abi = NULL, *out_abi = NULL;
4485 case 1: in_abi = "generic"; break;
4486 case 2: in_abi = "AltiVec"; break;
4487 case 3: in_abi = "SPE"; break;
4490 switch (out_attr->i)
4492 case 1: out_abi = "generic"; break;
4493 case 2: out_abi = "AltiVec"; break;
4494 case 3: out_abi = "SPE"; break;
4498 if (out_attr->i == 0)
4499 out_attr->i = in_attr->i;
4500 else if (in_attr->i == 0)
4502 /* For now, allow generic to transition to AltiVec or SPE
4503 without a warning. If GCC marked files with their stack
4504 alignment and used don't-care markings for files which are
4505 not affected by the vector ABI, we could warn about this
4507 else if (out_attr->i == 1)
4508 out_attr->i = in_attr->i;
4509 else if (in_attr->i == 1)
4511 else if (in_abi == NULL)
4513 (_("Warning: %B uses unknown vector ABI %d"), ibfd,
4515 else if (out_abi == NULL)
4517 (_("Warning: %B uses unknown vector ABI %d"), obfd,
4521 (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
4522 ibfd, obfd, in_abi, out_abi);
4525 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
4526 and merge non-conflicting ones. */
4527 in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return];
4528 out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
4529 if (in_attr->i != out_attr->i)
4532 if (out_attr->i == 0)
4533 out_attr->i = in_attr->i;
4534 else if (in_attr->i == 0)
4536 else if (out_attr->i == 1 && in_attr->i == 2)
4538 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
4539 else if (out_attr->i == 2 && in_attr->i == 1)
4541 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
4542 else if (in_attr->i > 2)
4544 (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
4548 (_("Warning: %B uses unknown small structure return convention %d"), obfd,
4552 /* Merge Tag_compatibility attributes and any common GNU ones. */
4553 _bfd_elf_merge_object_attributes (ibfd, obfd);
4558 /* Merge backend specific data from an object file to the output
4559 object file when linking. */
4562 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4568 if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
4571 /* Check if we have the same endianness. */
4572 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
4575 if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
4578 new_flags = elf_elfheader (ibfd)->e_flags;
4579 old_flags = elf_elfheader (obfd)->e_flags;
4580 if (!elf_flags_init (obfd))
4582 /* First call, no flags set. */
4583 elf_flags_init (obfd) = TRUE;
4584 elf_elfheader (obfd)->e_flags = new_flags;
4587 /* Compatible flags are ok. */
4588 else if (new_flags == old_flags)
4591 /* Incompatible flags. */
4594 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
4595 to be linked with either. */
4597 if ((new_flags & EF_PPC_RELOCATABLE) != 0
4598 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
4601 (*_bfd_error_handler)
4602 (_("%B: compiled with -mrelocatable and linked with "
4603 "modules compiled normally"), ibfd);
4605 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
4606 && (old_flags & EF_PPC_RELOCATABLE) != 0)
4609 (*_bfd_error_handler)
4610 (_("%B: compiled normally and linked with "
4611 "modules compiled with -mrelocatable"), ibfd);
4614 /* The output is -mrelocatable-lib iff both the input files are. */
4615 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
4616 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
4618 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
4619 but each input file is either -mrelocatable or -mrelocatable-lib. */
4620 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
4621 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
4622 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
4623 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
4625 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
4626 any module uses it. */
4627 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
4629 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
4630 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
4632 /* Warn about any other mismatches. */
4633 if (new_flags != old_flags)
4636 (*_bfd_error_handler)
4637 (_("%B: uses different e_flags (0x%lx) fields "
4638 "than previous modules (0x%lx)"),
4639 ibfd, (long) new_flags, (long) old_flags);
4644 bfd_set_error (bfd_error_bad_value);
4653 ppc_elf_vle_split16 (bfd *output_bfd, bfd_byte *contents,
4654 bfd_vma offset, bfd_vma relocation,
4655 split16_format_type split16_format)
4658 bfd_vma insn, top5, bottom11;
4660 insn = bfd_get_32 (output_bfd, contents + offset);
4661 top5 = relocation >> 11;
4662 top5 = top5 << (split16_format == split16a_type ? 20 : 16);
4663 bottom11 = relocation & 0x7ff;
4666 bfd_put_32 (output_bfd, insn, contents + offset);
4670 /* Choose which PLT scheme to use, and set .plt flags appropriately.
4671 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
4673 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
4674 struct bfd_link_info *info,
4675 enum ppc_elf_plt_type plt_style,
4678 struct ppc_elf_link_hash_table *htab;
4681 htab = ppc_elf_hash_table (info);
4683 htab->emit_stub_syms = emit_stub_syms;
4685 if (htab->plt_type == PLT_UNSET)
4687 struct elf_link_hash_entry *h;
4689 if (plt_style == PLT_OLD)
4690 htab->plt_type = PLT_OLD;
4691 else if (info->shared
4692 && htab->elf.dynamic_sections_created
4693 && (h = elf_link_hash_lookup (&htab->elf, "_mcount",
4694 FALSE, FALSE, TRUE)) != NULL
4695 && (h->type == STT_FUNC
4698 && !(SYMBOL_CALLS_LOCAL (info, h)
4699 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4700 && h->root.type == bfd_link_hash_undefweak)))
4702 /* Profiling of shared libs (and pies) is not supported with
4703 secure plt, because ppc32 does profiling before a
4704 function prologue and a secure plt pic call stubs needs
4705 r30 to be set up. */
4706 htab->plt_type = PLT_OLD;
4711 enum ppc_elf_plt_type plt_type = plt_style;
4713 /* Look through the reloc flags left by ppc_elf_check_relocs.
4714 Use the old style bss plt if a file makes plt calls
4715 without using the new relocs, and if ld isn't given
4716 --secure-plt and we never see REL16 relocs. */
4717 if (plt_type == PLT_UNSET)
4719 for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
4720 if (is_ppc_elf (ibfd))
4722 if (ppc_elf_tdata (ibfd)->has_rel16)
4724 else if (ppc_elf_tdata (ibfd)->makes_plt_call)
4727 htab->old_bfd = ibfd;
4731 htab->plt_type = plt_type;
4734 if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
4736 if (htab->old_bfd != NULL)
4737 info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"),
4740 info->callbacks->einfo (_("%P: bss-plt forced by profiling\n"));
4743 BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
4745 if (htab->plt_type == PLT_NEW)
4747 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
4748 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4750 /* The new PLT is a loaded section. */
4751 if (htab->plt != NULL
4752 && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
4755 /* The new GOT is not executable. */
4756 if (htab->got != NULL
4757 && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
4762 /* Stop an unused .glink section from affecting .text alignment. */
4763 if (htab->glink != NULL
4764 && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
4767 return htab->plt_type == PLT_NEW;
4770 /* Return the section that should be marked against GC for a given
4774 ppc_elf_gc_mark_hook (asection *sec,
4775 struct bfd_link_info *info,
4776 Elf_Internal_Rela *rel,
4777 struct elf_link_hash_entry *h,
4778 Elf_Internal_Sym *sym)
4781 switch (ELF32_R_TYPE (rel->r_info))
4783 case R_PPC_GNU_VTINHERIT:
4784 case R_PPC_GNU_VTENTRY:
4788 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
4791 /* Update the got, plt and dynamic reloc reference counts for the
4792 section being removed. */
4795 ppc_elf_gc_sweep_hook (bfd *abfd,
4796 struct bfd_link_info *info,
4798 const Elf_Internal_Rela *relocs)
4800 struct ppc_elf_link_hash_table *htab;
4801 Elf_Internal_Shdr *symtab_hdr;
4802 struct elf_link_hash_entry **sym_hashes;
4803 bfd_signed_vma *local_got_refcounts;
4804 const Elf_Internal_Rela *rel, *relend;
4807 if (info->relocatable)
4810 if ((sec->flags & SEC_ALLOC) == 0)
4813 elf_section_data (sec)->local_dynrel = NULL;
4815 htab = ppc_elf_hash_table (info);
4816 symtab_hdr = &elf_symtab_hdr (abfd);
4817 sym_hashes = elf_sym_hashes (abfd);
4818 local_got_refcounts = elf_local_got_refcounts (abfd);
4819 got2 = bfd_get_section_by_name (abfd, ".got2");
4821 relend = relocs + sec->reloc_count;
4822 for (rel = relocs; rel < relend; rel++)
4824 unsigned long r_symndx;
4825 enum elf_ppc_reloc_type r_type;
4826 struct elf_link_hash_entry *h = NULL;
4828 r_symndx = ELF32_R_SYM (rel->r_info);
4829 if (r_symndx >= symtab_hdr->sh_info)
4831 struct elf_dyn_relocs **pp, *p;
4832 struct ppc_elf_link_hash_entry *eh;
4834 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4835 while (h->root.type == bfd_link_hash_indirect
4836 || h->root.type == bfd_link_hash_warning)
4837 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4838 eh = (struct ppc_elf_link_hash_entry *) h;
4840 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4843 /* Everything must go for SEC. */
4849 r_type = ELF32_R_TYPE (rel->r_info);
4850 if (!htab->is_vxworks
4852 && local_got_refcounts != NULL
4854 || is_branch_reloc (r_type)))
4856 struct plt_entry **local_plt = (struct plt_entry **)
4857 (local_got_refcounts + symtab_hdr->sh_info);
4858 char *local_got_tls_masks = (char *)
4859 (local_plt + symtab_hdr->sh_info);
4860 if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
4862 struct plt_entry **ifunc = local_plt + r_symndx;
4864 struct plt_entry *ent;
4866 if (r_type == R_PPC_PLTREL24 && info->shared)
4867 addend = rel->r_addend;
4868 ent = find_plt_ent (ifunc, got2, addend);
4869 if (ent->plt.refcount > 0)
4870 ent->plt.refcount -= 1;
4877 case R_PPC_GOT_TLSLD16:
4878 case R_PPC_GOT_TLSLD16_LO:
4879 case R_PPC_GOT_TLSLD16_HI:
4880 case R_PPC_GOT_TLSLD16_HA:
4881 case R_PPC_GOT_TLSGD16:
4882 case R_PPC_GOT_TLSGD16_LO:
4883 case R_PPC_GOT_TLSGD16_HI:
4884 case R_PPC_GOT_TLSGD16_HA:
4885 case R_PPC_GOT_TPREL16:
4886 case R_PPC_GOT_TPREL16_LO:
4887 case R_PPC_GOT_TPREL16_HI:
4888 case R_PPC_GOT_TPREL16_HA:
4889 case R_PPC_GOT_DTPREL16:
4890 case R_PPC_GOT_DTPREL16_LO:
4891 case R_PPC_GOT_DTPREL16_HI:
4892 case R_PPC_GOT_DTPREL16_HA:
4894 case R_PPC_GOT16_LO:
4895 case R_PPC_GOT16_HI:
4896 case R_PPC_GOT16_HA:
4899 if (h->got.refcount > 0)
4903 struct plt_entry *ent;
4905 ent = find_plt_ent (&h->plt.plist, NULL, 0);
4906 if (ent != NULL && ent->plt.refcount > 0)
4907 ent->plt.refcount -= 1;
4910 else if (local_got_refcounts != NULL)
4912 if (local_got_refcounts[r_symndx] > 0)
4913 local_got_refcounts[r_symndx]--;
4919 case R_PPC_REL14_BRTAKEN:
4920 case R_PPC_REL14_BRNTAKEN:
4922 if (h == NULL || h == htab->elf.hgot)
4929 case R_PPC_ADDR16_LO:
4930 case R_PPC_ADDR16_HI:
4931 case R_PPC_ADDR16_HA:
4933 case R_PPC_ADDR14_BRTAKEN:
4934 case R_PPC_ADDR14_BRNTAKEN:
4941 case R_PPC_PLTREL24:
4942 case R_PPC_PLTREL32:
4943 case R_PPC_PLT16_LO:
4944 case R_PPC_PLT16_HI:
4945 case R_PPC_PLT16_HA:
4949 struct plt_entry *ent;
4951 if (r_type == R_PPC_PLTREL24 && info->shared)
4952 addend = rel->r_addend;
4953 ent = find_plt_ent (&h->plt.plist, got2, addend);
4954 if (ent != NULL && ent->plt.refcount > 0)
4955 ent->plt.refcount -= 1;
4966 /* Set plt output section type, htab->tls_get_addr, and call the
4967 generic ELF tls_setup function. */
4970 ppc_elf_tls_setup (bfd *obfd,
4971 struct bfd_link_info *info,
4972 int no_tls_get_addr_opt)
4974 struct ppc_elf_link_hash_table *htab;
4976 htab = ppc_elf_hash_table (info);
4977 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
4978 FALSE, FALSE, TRUE);
4979 if (!no_tls_get_addr_opt)
4981 struct elf_link_hash_entry *opt, *tga;
4982 opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
4983 FALSE, FALSE, TRUE);
4985 && (opt->root.type == bfd_link_hash_defined
4986 || opt->root.type == bfd_link_hash_defweak))
4988 /* If glibc supports an optimized __tls_get_addr call stub,
4989 signalled by the presence of __tls_get_addr_opt, and we'll
4990 be calling __tls_get_addr via a plt call stub, then
4991 make __tls_get_addr point to __tls_get_addr_opt. */
4992 tga = htab->tls_get_addr;
4993 if (htab->elf.dynamic_sections_created
4995 && (tga->type == STT_FUNC
4997 && !(SYMBOL_CALLS_LOCAL (info, tga)
4998 || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT
4999 && tga->root.type == bfd_link_hash_undefweak)))
5001 struct plt_entry *ent;
5002 for (ent = tga->plt.plist; ent != NULL; ent = ent->next)
5003 if (ent->plt.refcount > 0)
5007 tga->root.type = bfd_link_hash_indirect;
5008 tga->root.u.i.link = &opt->root;
5009 ppc_elf_copy_indirect_symbol (info, opt, tga);
5010 if (opt->dynindx != -1)
5012 /* Use __tls_get_addr_opt in dynamic relocations. */
5014 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
5016 if (!bfd_elf_link_record_dynamic_symbol (info, opt))
5019 htab->tls_get_addr = opt;
5024 no_tls_get_addr_opt = TRUE;
5026 htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
5027 if (htab->plt_type == PLT_NEW
5028 && htab->plt != NULL
5029 && htab->plt->output_section != NULL)
5031 elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
5032 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
5035 return _bfd_elf_tls_setup (obfd, info);
5038 /* Return TRUE iff REL is a branch reloc with a global symbol matching
5042 branch_reloc_hash_match (const bfd *ibfd,
5043 const Elf_Internal_Rela *rel,
5044 const struct elf_link_hash_entry *hash)
5046 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
5047 enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
5048 unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
5050 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
5052 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
5053 struct elf_link_hash_entry *h;
5055 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5056 while (h->root.type == bfd_link_hash_indirect
5057 || h->root.type == bfd_link_hash_warning)
5058 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5065 /* Run through all the TLS relocs looking for optimization
5069 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
5070 struct bfd_link_info *info)
5074 struct ppc_elf_link_hash_table *htab;
5077 if (info->relocatable || !info->executable)
5080 htab = ppc_elf_hash_table (info);
5084 /* Make two passes through the relocs. First time check that tls
5085 relocs involved in setting up a tls_get_addr call are indeed
5086 followed by such a call. If they are not, don't do any tls
5087 optimization. On the second pass twiddle tls_mask flags to
5088 notify relocate_section that optimization can be done, and
5089 adjust got and plt refcounts. */
5090 for (pass = 0; pass < 2; ++pass)
5091 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5093 Elf_Internal_Sym *locsyms = NULL;
5094 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
5095 asection *got2 = bfd_get_section_by_name (ibfd, ".got2");
5097 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5098 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
5100 Elf_Internal_Rela *relstart, *rel, *relend;
5101 int expecting_tls_get_addr = 0;
5103 /* Read the relocations. */
5104 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
5106 if (relstart == NULL)
5109 relend = relstart + sec->reloc_count;
5110 for (rel = relstart; rel < relend; rel++)
5112 enum elf_ppc_reloc_type r_type;
5113 unsigned long r_symndx;
5114 struct elf_link_hash_entry *h = NULL;
5116 char tls_set, tls_clear;
5117 bfd_boolean is_local;
5118 bfd_signed_vma *got_count;
5120 r_symndx = ELF32_R_SYM (rel->r_info);
5121 if (r_symndx >= symtab_hdr->sh_info)
5123 struct elf_link_hash_entry **sym_hashes;
5125 sym_hashes = elf_sym_hashes (ibfd);
5126 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5127 while (h->root.type == bfd_link_hash_indirect
5128 || h->root.type == bfd_link_hash_warning)
5129 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5137 r_type = ELF32_R_TYPE (rel->r_info);
5138 /* If this section has old-style __tls_get_addr calls
5139 without marker relocs, then check that each
5140 __tls_get_addr call reloc is preceded by a reloc
5141 that conceivably belongs to the __tls_get_addr arg
5142 setup insn. If we don't find matching arg setup
5143 relocs, don't do any tls optimization. */
5145 && sec->has_tls_get_addr_call
5147 && h == htab->tls_get_addr
5148 && !expecting_tls_get_addr
5149 && is_branch_reloc (r_type))
5151 info->callbacks->minfo ("%H __tls_get_addr lost arg, "
5152 "TLS optimization disabled\n",
5153 ibfd, sec, rel->r_offset);
5154 if (elf_section_data (sec)->relocs != relstart)
5159 expecting_tls_get_addr = 0;
5162 case R_PPC_GOT_TLSLD16:
5163 case R_PPC_GOT_TLSLD16_LO:
5164 expecting_tls_get_addr = 1;
5167 case R_PPC_GOT_TLSLD16_HI:
5168 case R_PPC_GOT_TLSLD16_HA:
5169 /* These relocs should never be against a symbol
5170 defined in a shared lib. Leave them alone if
5171 that turns out to be the case. */
5180 case R_PPC_GOT_TLSGD16:
5181 case R_PPC_GOT_TLSGD16_LO:
5182 expecting_tls_get_addr = 1;
5185 case R_PPC_GOT_TLSGD16_HI:
5186 case R_PPC_GOT_TLSGD16_HA:
5192 tls_set = TLS_TLS | TLS_TPRELGD;
5196 case R_PPC_GOT_TPREL16:
5197 case R_PPC_GOT_TPREL16_LO:
5198 case R_PPC_GOT_TPREL16_HI:
5199 case R_PPC_GOT_TPREL16_HA:
5204 tls_clear = TLS_TPREL;
5212 expecting_tls_get_addr = 2;
5223 if (!expecting_tls_get_addr
5224 || (expecting_tls_get_addr == 1
5225 && !sec->has_tls_get_addr_call))
5228 if (rel + 1 < relend
5229 && branch_reloc_hash_match (ibfd, rel + 1,
5230 htab->tls_get_addr))
5233 /* Uh oh, we didn't find the expected call. We
5234 could just mark this symbol to exclude it
5235 from tls optimization but it's safer to skip
5236 the entire optimization. */
5237 info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
5238 "TLS optimization disabled\n"),
5239 ibfd, sec, rel->r_offset);
5240 if (elf_section_data (sec)->relocs != relstart)
5245 if (expecting_tls_get_addr)
5247 struct plt_entry *ent;
5251 && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24)
5252 addend = rel[1].r_addend;
5253 ent = find_plt_ent (&htab->tls_get_addr->plt.plist,
5255 if (ent != NULL && ent->plt.refcount > 0)
5256 ent->plt.refcount -= 1;
5258 if (expecting_tls_get_addr == 2)
5264 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
5265 got_count = &h->got.refcount;
5269 bfd_signed_vma *lgot_refs;
5270 struct plt_entry **local_plt;
5273 if (locsyms == NULL)
5275 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
5276 if (locsyms == NULL)
5277 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
5278 symtab_hdr->sh_info,
5279 0, NULL, NULL, NULL);
5280 if (locsyms == NULL)
5282 if (elf_section_data (sec)->relocs != relstart)
5287 lgot_refs = elf_local_got_refcounts (ibfd);
5288 if (lgot_refs == NULL)
5290 local_plt = (struct plt_entry **)
5291 (lgot_refs + symtab_hdr->sh_info);
5292 lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
5293 tls_mask = &lgot_masks[r_symndx];
5294 got_count = &lgot_refs[r_symndx];
5299 /* We managed to get rid of a got entry. */
5304 *tls_mask |= tls_set;
5305 *tls_mask &= ~tls_clear;
5308 if (elf_section_data (sec)->relocs != relstart)
5313 && (symtab_hdr->contents != (unsigned char *) locsyms))
5315 if (!info->keep_memory)
5318 symtab_hdr->contents = (unsigned char *) locsyms;
5324 /* Return true if we have dynamic relocs that apply to read-only sections. */
5327 readonly_dynrelocs (struct elf_link_hash_entry *h)
5329 struct elf_dyn_relocs *p;
5331 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
5333 asection *s = p->sec->output_section;
5336 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
5337 == (SEC_READONLY | SEC_ALLOC)))
5343 /* Adjust a symbol defined by a dynamic object and referenced by a
5344 regular object. The current definition is in some section of the
5345 dynamic object, but we're not including those sections. We have to
5346 change the definition to something the rest of the link can
5350 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
5351 struct elf_link_hash_entry *h)
5353 struct ppc_elf_link_hash_table *htab;
5357 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
5358 h->root.root.string);
5361 /* Make sure we know what is going on here. */
5362 htab = ppc_elf_hash_table (info);
5363 BFD_ASSERT (htab->elf.dynobj != NULL
5365 || h->type == STT_GNU_IFUNC
5366 || h->u.weakdef != NULL
5369 && !h->def_regular)));
5371 /* Deal with function syms. */
5372 if (h->type == STT_FUNC
5373 || h->type == STT_GNU_IFUNC
5376 /* Clear procedure linkage table information for any symbol that
5377 won't need a .plt entry. */
5378 struct plt_entry *ent;
5379 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
5380 if (ent->plt.refcount > 0)
5383 || (h->type != STT_GNU_IFUNC
5384 && (SYMBOL_CALLS_LOCAL (info, h)
5385 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5386 && h->root.type == bfd_link_hash_undefweak))))
5388 /* A PLT entry is not required/allowed when:
5390 1. We are not using ld.so; because then the PLT entry
5391 can't be set up, so we can't use one. In this case,
5392 ppc_elf_adjust_dynamic_symbol won't even be called.
5394 2. GC has rendered the entry unused.
5396 3. We know for certain that a call to this symbol
5397 will go to this object, or will remain undefined. */
5398 h->plt.plist = NULL;
5403 /* After adjust_dynamic_symbol, non_got_ref set in the
5404 non-shared case means that we have allocated space in
5405 .dynbss for the symbol and thus dyn_relocs for this
5406 symbol should be discarded.
5407 If we get here we know we are making a PLT entry for this
5408 symbol, and in an executable we'd normally resolve
5409 relocations against this symbol to the PLT entry. Allow
5410 dynamic relocs if the reference is weak, and the dynamic
5411 relocs will not cause text relocation. */
5412 if (!h->ref_regular_nonweak
5414 && h->type != STT_GNU_IFUNC
5415 && !htab->is_vxworks
5416 && !ppc_elf_hash_entry (h)->has_sda_refs
5417 && !readonly_dynrelocs (h))
5423 h->plt.plist = NULL;
5425 /* If this is a weak symbol, and there is a real definition, the
5426 processor independent code will have arranged for us to see the
5427 real definition first, and we can just use the same value. */
5428 if (h->u.weakdef != NULL)
5430 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5431 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5432 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5433 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5434 if (ELIMINATE_COPY_RELOCS)
5435 h->non_got_ref = h->u.weakdef->non_got_ref;
5439 /* This is a reference to a symbol defined by a dynamic object which
5440 is not a function. */
5442 /* If we are creating a shared library, we must presume that the
5443 only references to the symbol are via the global offset table.
5444 For such cases we need not do anything here; the relocations will
5445 be handled correctly by relocate_section. */
5449 /* If there are no references to this symbol that do not use the
5450 GOT, we don't need to generate a copy reloc. */
5451 if (!h->non_got_ref)
5454 /* If we didn't find any dynamic relocs in read-only sections, then
5455 we'll be keeping the dynamic relocs and avoiding the copy reloc.
5456 We can't do this if there are any small data relocations. This
5457 doesn't work on VxWorks, where we can not have dynamic
5458 relocations (other than copy and jump slot relocations) in an
5460 if (ELIMINATE_COPY_RELOCS
5461 && !ppc_elf_hash_entry (h)->has_sda_refs
5462 && !htab->is_vxworks
5464 && !readonly_dynrelocs (h))
5470 /* We must allocate the symbol in our .dynbss section, which will
5471 become part of the .bss section of the executable. There will be
5472 an entry for this symbol in the .dynsym section. The dynamic
5473 object will contain position independent code, so all references
5474 from the dynamic object to this symbol will go through the global
5475 offset table. The dynamic linker will use the .dynsym entry to
5476 determine the address it must put in the global offset table, so
5477 both the dynamic object and the regular object will refer to the
5478 same memory location for the variable.
5480 Of course, if the symbol is referenced using SDAREL relocs, we
5481 must instead allocate it in .sbss. */
5483 if (ppc_elf_hash_entry (h)->has_sda_refs)
5487 BFD_ASSERT (s != NULL);
5489 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
5490 copy the initial value out of the dynamic object and into the
5491 runtime process image. We need to remember the offset into the
5492 .rela.bss section we are going to use. */
5493 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
5497 if (ppc_elf_hash_entry (h)->has_sda_refs)
5498 srel = htab->relsbss;
5500 srel = htab->relbss;
5501 BFD_ASSERT (srel != NULL);
5502 srel->size += sizeof (Elf32_External_Rela);
5506 return _bfd_elf_adjust_dynamic_copy (h, s);
5509 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
5510 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
5511 specifying the addend on the plt relocation. For -fpic code, the sym
5512 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
5513 xxxxxxxx.got2.plt_pic32.<callee>. */
5516 add_stub_sym (struct plt_entry *ent,
5517 struct elf_link_hash_entry *h,
5518 struct bfd_link_info *info)
5520 struct elf_link_hash_entry *sh;
5521 size_t len1, len2, len3;
5524 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
5527 stub = ".plt_pic32.";
5529 stub = ".plt_call32.";
5531 len1 = strlen (h->root.root.string);
5532 len2 = strlen (stub);
5535 len3 = strlen (ent->sec->name);
5536 name = bfd_malloc (len1 + len2 + len3 + 9);
5539 sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
5541 memcpy (name + 8, ent->sec->name, len3);
5542 memcpy (name + 8 + len3, stub, len2);
5543 memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
5544 sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
5547 if (sh->root.type == bfd_link_hash_new)
5549 sh->root.type = bfd_link_hash_defined;
5550 sh->root.u.def.section = htab->glink;
5551 sh->root.u.def.value = ent->glink_offset;
5552 sh->ref_regular = 1;
5553 sh->def_regular = 1;
5554 sh->ref_regular_nonweak = 1;
5555 sh->forced_local = 1;
5561 /* Allocate NEED contiguous space in .got, and return the offset.
5562 Handles allocation of the got header when crossing 32k. */
5565 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
5568 unsigned int max_before_header;
5570 if (htab->plt_type == PLT_VXWORKS)
5572 where = htab->got->size;
5573 htab->got->size += need;
5577 max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
5578 if (need <= htab->got_gap)
5580 where = max_before_header - htab->got_gap;
5581 htab->got_gap -= need;
5585 if (htab->got->size + need > max_before_header
5586 && htab->got->size <= max_before_header)
5588 htab->got_gap = max_before_header - htab->got->size;
5589 htab->got->size = max_before_header + htab->got_header_size;
5591 where = htab->got->size;
5592 htab->got->size += need;
5598 /* Allocate space in associated reloc sections for dynamic relocs. */
5601 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
5603 struct bfd_link_info *info = inf;
5604 struct ppc_elf_link_hash_entry *eh;
5605 struct ppc_elf_link_hash_table *htab;
5606 struct elf_dyn_relocs *p;
5608 if (h->root.type == bfd_link_hash_indirect)
5611 htab = ppc_elf_hash_table (info);
5612 if (htab->elf.dynamic_sections_created
5613 || h->type == STT_GNU_IFUNC)
5615 struct plt_entry *ent;
5616 bfd_boolean doneone = FALSE;
5617 bfd_vma plt_offset = 0, glink_offset = 0;
5620 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
5621 if (ent->plt.refcount > 0)
5623 /* Make sure this symbol is output as a dynamic symbol. */
5624 if (h->dynindx == -1
5627 && htab->elf.dynamic_sections_created)
5629 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5633 dyn = htab->elf.dynamic_sections_created;
5635 || h->type == STT_GNU_IFUNC
5636 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
5638 asection *s = htab->plt;
5639 if (!dyn || h->dynindx == -1)
5642 if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
5646 plt_offset = s->size;
5649 ent->plt.offset = plt_offset;
5652 if (!doneone || info->shared)
5654 glink_offset = s->size;
5655 s->size += GLINK_ENTRY_SIZE;
5656 if (h == htab->tls_get_addr
5657 && !htab->no_tls_get_addr_opt)
5658 s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
5665 h->root.u.def.section = s;
5666 h->root.u.def.value = glink_offset;
5668 ent->glink_offset = glink_offset;
5670 if (htab->emit_stub_syms
5671 && !add_stub_sym (ent, h, info))
5678 /* If this is the first .plt entry, make room
5679 for the special first entry. */
5681 s->size += htab->plt_initial_entry_size;
5683 /* The PowerPC PLT is actually composed of two
5684 parts, the first part is 2 words (for a load
5685 and a jump), and then there is a remaining
5686 word available at the end. */
5687 plt_offset = (htab->plt_initial_entry_size
5688 + (htab->plt_slot_size
5690 - htab->plt_initial_entry_size)
5691 / htab->plt_entry_size)));
5693 /* If this symbol is not defined in a regular
5694 file, and we are not generating a shared
5695 library, then set the symbol to this location
5696 in the .plt. This is to avoid text
5697 relocations, and is required to make
5698 function pointers compare as equal between
5699 the normal executable and the shared library. */
5704 h->root.u.def.section = s;
5705 h->root.u.def.value = plt_offset;
5708 /* Make room for this entry. */
5709 s->size += htab->plt_entry_size;
5710 /* After the 8192nd entry, room for two entries
5712 if (htab->plt_type == PLT_OLD
5713 && (s->size - htab->plt_initial_entry_size)
5714 / htab->plt_entry_size
5715 > PLT_NUM_SINGLE_ENTRIES)
5716 s->size += htab->plt_entry_size;
5718 ent->plt.offset = plt_offset;
5721 /* We also need to make an entry in the .rela.plt section. */
5724 if (!htab->elf.dynamic_sections_created
5725 || h->dynindx == -1)
5726 htab->reliplt->size += sizeof (Elf32_External_Rela);
5729 htab->relplt->size += sizeof (Elf32_External_Rela);
5731 if (htab->plt_type == PLT_VXWORKS)
5733 /* Allocate space for the unloaded relocations. */
5735 && htab->elf.dynamic_sections_created)
5738 == (bfd_vma) htab->plt_initial_entry_size)
5740 htab->srelplt2->size
5741 += (sizeof (Elf32_External_Rela)
5742 * VXWORKS_PLTRESOLVE_RELOCS);
5745 htab->srelplt2->size
5746 += (sizeof (Elf32_External_Rela)
5747 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
5750 /* Every PLT entry has an associated GOT entry in
5752 htab->sgotplt->size += 4;
5759 ent->plt.offset = (bfd_vma) -1;
5762 ent->plt.offset = (bfd_vma) -1;
5766 h->plt.plist = NULL;
5772 h->plt.plist = NULL;
5776 eh = (struct ppc_elf_link_hash_entry *) h;
5777 if (eh->elf.got.refcount > 0)
5782 /* Make sure this symbol is output as a dynamic symbol. */
5783 if (eh->elf.dynindx == -1
5784 && !eh->elf.forced_local
5785 && eh->elf.type != STT_GNU_IFUNC
5786 && htab->elf.dynamic_sections_created)
5788 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
5793 if ((eh->tls_mask & TLS_TLS) != 0)
5795 if ((eh->tls_mask & TLS_LD) != 0)
5797 if (!eh->elf.def_dynamic)
5798 /* We'll just use htab->tlsld_got.offset. This should
5799 always be the case. It's a little odd if we have
5800 a local dynamic reloc against a non-local symbol. */
5801 htab->tlsld_got.refcount += 1;
5805 if ((eh->tls_mask & TLS_GD) != 0)
5807 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
5809 if ((eh->tls_mask & TLS_DTPREL) != 0)
5815 eh->elf.got.offset = (bfd_vma) -1;
5818 eh->elf.got.offset = allocate_got (htab, need);
5819 dyn = htab->elf.dynamic_sections_created;
5821 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
5822 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
5823 || eh->elf.root.type != bfd_link_hash_undefweak))
5825 asection *rsec = htab->relgot;
5826 /* All the entries we allocated need relocs.
5827 Except LD only needs one. */
5828 if ((eh->tls_mask & TLS_LD) != 0
5829 && eh->elf.def_dynamic)
5831 rsec->size += need * (sizeof (Elf32_External_Rela) / 4);
5836 eh->elf.got.offset = (bfd_vma) -1;
5838 if (eh->dyn_relocs == NULL
5839 || !htab->elf.dynamic_sections_created)
5842 /* In the shared -Bsymbolic case, discard space allocated for
5843 dynamic pc-relative relocs against symbols which turn out to be
5844 defined in regular objects. For the normal shared case, discard
5845 space for relocs that have become local due to symbol visibility
5850 /* Relocs that use pc_count are those that appear on a call insn,
5851 or certain REL relocs (see must_be_dyn_reloc) that can be
5852 generated via assembly. We want calls to protected symbols to
5853 resolve directly to the function rather than going via the plt.
5854 If people want function pointer comparisons to work as expected
5855 then they should avoid writing weird assembly. */
5856 if (SYMBOL_CALLS_LOCAL (info, h))
5858 struct elf_dyn_relocs **pp;
5860 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
5862 p->count -= p->pc_count;
5871 if (htab->is_vxworks)
5873 struct elf_dyn_relocs **pp;
5875 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
5877 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
5884 /* Discard relocs on undefined symbols that must be local. */
5885 if (eh->dyn_relocs != NULL
5886 && h->root.type == bfd_link_hash_undefined
5887 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
5888 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
5889 eh->dyn_relocs = NULL;
5891 /* Also discard relocs on undefined weak syms with non-default
5893 if (eh->dyn_relocs != NULL
5894 && h->root.type == bfd_link_hash_undefweak)
5896 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5897 eh->dyn_relocs = NULL;
5899 /* Make sure undefined weak symbols are output as a dynamic
5901 else if (h->dynindx == -1
5905 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5910 else if (ELIMINATE_COPY_RELOCS)
5912 /* For the non-shared case, discard space for relocs against
5913 symbols which turn out to need copy relocs or are not
5919 /* Make sure this symbol is output as a dynamic symbol.
5920 Undefined weak syms won't yet be marked as dynamic. */
5921 if (h->dynindx == -1
5922 && !h->forced_local)
5924 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5928 /* If that succeeded, we know we'll be keeping all the
5930 if (h->dynindx != -1)
5934 eh->dyn_relocs = NULL;
5939 /* Finally, allocate space. */
5940 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5942 asection *sreloc = elf_section_data (p->sec)->sreloc;
5943 if (!htab->elf.dynamic_sections_created)
5944 sreloc = htab->reliplt;
5945 sreloc->size += p->count * sizeof (Elf32_External_Rela);
5951 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
5952 read-only sections. */
5955 maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
5957 if (h->root.type == bfd_link_hash_indirect)
5960 if (readonly_dynrelocs (h))
5962 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
5964 /* Not an error, just cut short the traversal. */
5970 static const unsigned char glink_eh_frame_cie[] =
5972 0, 0, 0, 16, /* length. */
5973 0, 0, 0, 0, /* id. */
5974 1, /* CIE version. */
5975 'z', 'R', 0, /* Augmentation string. */
5976 4, /* Code alignment. */
5977 0x7c, /* Data alignment. */
5979 1, /* Augmentation size. */
5980 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
5981 DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
5984 /* Set the sizes of the dynamic sections. */
5987 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5988 struct bfd_link_info *info)
5990 struct ppc_elf_link_hash_table *htab;
5996 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
5999 htab = ppc_elf_hash_table (info);
6000 BFD_ASSERT (htab->elf.dynobj != NULL);
6002 if (elf_hash_table (info)->dynamic_sections_created)
6004 /* Set the contents of the .interp section to the interpreter. */
6005 if (info->executable)
6007 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
6008 BFD_ASSERT (s != NULL);
6009 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
6010 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6014 if (htab->plt_type == PLT_OLD)
6015 htab->got_header_size = 16;
6016 else if (htab->plt_type == PLT_NEW)
6017 htab->got_header_size = 12;
6019 /* Set up .got offsets for local syms, and space for local dynamic
6021 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6023 bfd_signed_vma *local_got;
6024 bfd_signed_vma *end_local_got;
6025 struct plt_entry **local_plt;
6026 struct plt_entry **end_local_plt;
6028 bfd_size_type locsymcount;
6029 Elf_Internal_Shdr *symtab_hdr;
6031 if (!is_ppc_elf (ibfd))
6034 for (s = ibfd->sections; s != NULL; s = s->next)
6036 struct elf_dyn_relocs *p;
6038 for (p = ((struct elf_dyn_relocs *)
6039 elf_section_data (s)->local_dynrel);
6043 if (!bfd_is_abs_section (p->sec)
6044 && bfd_is_abs_section (p->sec->output_section))
6046 /* Input section has been discarded, either because
6047 it is a copy of a linkonce section or due to
6048 linker script /DISCARD/, so we'll be discarding
6051 else if (htab->is_vxworks
6052 && strcmp (p->sec->output_section->name,
6055 /* Relocations in vxworks .tls_vars sections are
6056 handled specially by the loader. */
6058 else if (p->count != 0)
6060 asection *sreloc = elf_section_data (p->sec)->sreloc;
6061 if (!htab->elf.dynamic_sections_created)
6062 sreloc = htab->reliplt;
6063 sreloc->size += p->count * sizeof (Elf32_External_Rela);
6064 if ((p->sec->output_section->flags
6065 & (SEC_READONLY | SEC_ALLOC))
6066 == (SEC_READONLY | SEC_ALLOC))
6067 info->flags |= DF_TEXTREL;
6072 local_got = elf_local_got_refcounts (ibfd);
6076 symtab_hdr = &elf_symtab_hdr (ibfd);
6077 locsymcount = symtab_hdr->sh_info;
6078 end_local_got = local_got + locsymcount;
6079 local_plt = (struct plt_entry **) end_local_got;
6080 end_local_plt = local_plt + locsymcount;
6081 lgot_masks = (char *) end_local_plt;
6083 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
6086 unsigned int need = 0;
6087 if ((*lgot_masks & TLS_TLS) != 0)
6089 if ((*lgot_masks & TLS_GD) != 0)
6091 if ((*lgot_masks & TLS_LD) != 0)
6092 htab->tlsld_got.refcount += 1;
6093 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
6095 if ((*lgot_masks & TLS_DTPREL) != 0)
6101 *local_got = (bfd_vma) -1;
6104 *local_got = allocate_got (htab, need);
6106 htab->relgot->size += (need
6107 * (sizeof (Elf32_External_Rela) / 4));
6111 *local_got = (bfd_vma) -1;
6113 if (htab->is_vxworks)
6116 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
6117 for (; local_plt < end_local_plt; ++local_plt)
6119 struct plt_entry *ent;
6120 bfd_boolean doneone = FALSE;
6121 bfd_vma plt_offset = 0, glink_offset = 0;
6123 for (ent = *local_plt; ent != NULL; ent = ent->next)
6124 if (ent->plt.refcount > 0)
6130 plt_offset = s->size;
6133 ent->plt.offset = plt_offset;
6136 if (!doneone || info->shared)
6138 glink_offset = s->size;
6139 s->size += GLINK_ENTRY_SIZE;
6141 ent->glink_offset = glink_offset;
6145 htab->reliplt->size += sizeof (Elf32_External_Rela);
6150 ent->plt.offset = (bfd_vma) -1;
6154 /* Allocate space for global sym dynamic relocs. */
6155 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
6157 if (htab->tlsld_got.refcount > 0)
6159 htab->tlsld_got.offset = allocate_got (htab, 8);
6161 htab->relgot->size += sizeof (Elf32_External_Rela);
6164 htab->tlsld_got.offset = (bfd_vma) -1;
6166 if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
6168 unsigned int g_o_t = 32768;
6170 /* If we haven't allocated the header, do so now. When we get here,
6171 for old plt/got the got size will be 0 to 32764 (not allocated),
6172 or 32780 to 65536 (header allocated). For new plt/got, the
6173 corresponding ranges are 0 to 32768 and 32780 to 65536. */
6174 if (htab->got->size <= 32768)
6176 g_o_t = htab->got->size;
6177 if (htab->plt_type == PLT_OLD)
6179 htab->got->size += htab->got_header_size;
6182 htab->elf.hgot->root.u.def.value = g_o_t;
6186 struct elf_link_hash_entry *sda = htab->sdata[0].sym;
6188 && !(sda->root.type == bfd_link_hash_defined
6189 || sda->root.type == bfd_link_hash_defweak))
6191 sda->root.type = bfd_link_hash_defined;
6192 sda->root.u.def.section = htab->elf.hgot->root.u.def.section;
6193 sda->root.u.def.value = htab->elf.hgot->root.u.def.value;
6197 if (htab->glink != NULL
6198 && htab->glink->size != 0
6199 && htab->elf.dynamic_sections_created)
6201 htab->glink_pltresolve = htab->glink->size;
6202 /* Space for the branch table. */
6203 htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
6204 /* Pad out to align the start of PLTresolve. */
6205 htab->glink->size += -htab->glink->size & 15;
6206 htab->glink->size += GLINK_PLTRESOLVE;
6208 if (htab->emit_stub_syms)
6210 struct elf_link_hash_entry *sh;
6211 sh = elf_link_hash_lookup (&htab->elf, "__glink",
6212 TRUE, FALSE, FALSE);
6215 if (sh->root.type == bfd_link_hash_new)
6217 sh->root.type = bfd_link_hash_defined;
6218 sh->root.u.def.section = htab->glink;
6219 sh->root.u.def.value = htab->glink_pltresolve;
6220 sh->ref_regular = 1;
6221 sh->def_regular = 1;
6222 sh->ref_regular_nonweak = 1;
6223 sh->forced_local = 1;
6226 sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
6227 TRUE, FALSE, FALSE);
6230 if (sh->root.type == bfd_link_hash_new)
6232 sh->root.type = bfd_link_hash_defined;
6233 sh->root.u.def.section = htab->glink;
6234 sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
6235 sh->ref_regular = 1;
6236 sh->def_regular = 1;
6237 sh->ref_regular_nonweak = 1;
6238 sh->forced_local = 1;
6244 if (htab->glink != NULL
6245 && htab->glink->size != 0
6246 && htab->glink_eh_frame != NULL
6247 && !bfd_is_abs_section (htab->glink_eh_frame->output_section))
6249 s = htab->glink_eh_frame;
6250 s->size = sizeof (glink_eh_frame_cie) + 20;
6254 if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256)
6259 /* We've now determined the sizes of the various dynamic sections.
6260 Allocate memory for them. */
6262 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
6264 bfd_boolean strip_section = TRUE;
6266 if ((s->flags & SEC_LINKER_CREATED) == 0)
6272 /* We'd like to strip these sections if they aren't needed, but if
6273 we've exported dynamic symbols from them we must leave them.
6274 It's too late to tell BFD to get rid of the symbols. */
6275 if (htab->elf.hplt != NULL)
6276 strip_section = FALSE;
6277 /* Strip this section if we don't need it; see the
6280 else if (s == htab->iplt
6282 || s == htab->glink_eh_frame
6283 || s == htab->sgotplt
6285 || s == htab->dynbss
6286 || s == htab->dynsbss
6287 || s == htab->sdata[0].section
6288 || s == htab->sdata[1].section)
6290 /* Strip these too. */
6292 else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s),
6297 /* Remember whether there are any relocation sections. */
6300 /* We use the reloc_count field as a counter if we need
6301 to copy relocs into the output file. */
6307 /* It's not one of our sections, so don't allocate space. */
6311 if (s->size == 0 && strip_section)
6313 /* If we don't need this section, strip it from the
6314 output file. This is mostly to handle .rela.bss and
6315 .rela.plt. We must create both sections in
6316 create_dynamic_sections, because they must be created
6317 before the linker maps input sections to output
6318 sections. The linker does that before
6319 adjust_dynamic_symbol is called, and it is that
6320 function which decides whether anything needs to go
6321 into these sections. */
6322 s->flags |= SEC_EXCLUDE;
6326 if ((s->flags & SEC_HAS_CONTENTS) == 0)
6329 /* Allocate memory for the section contents. */
6330 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
6331 if (s->contents == NULL)
6335 if (htab->elf.dynamic_sections_created)
6337 /* Add some entries to the .dynamic section. We fill in the
6338 values later, in ppc_elf_finish_dynamic_sections, but we
6339 must add the entries now so that we get the correct size for
6340 the .dynamic section. The DT_DEBUG entry is filled in by the
6341 dynamic linker and used by the debugger. */
6342 #define add_dynamic_entry(TAG, VAL) \
6343 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6345 if (info->executable)
6347 if (!add_dynamic_entry (DT_DEBUG, 0))
6351 if (htab->plt != NULL && htab->plt->size != 0)
6353 if (!add_dynamic_entry (DT_PLTGOT, 0)
6354 || !add_dynamic_entry (DT_PLTRELSZ, 0)
6355 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
6356 || !add_dynamic_entry (DT_JMPREL, 0))
6360 if (htab->glink != NULL && htab->glink->size != 0)
6362 if (!add_dynamic_entry (DT_PPC_GOT, 0))
6364 if (!htab->no_tls_get_addr_opt
6365 && htab->tls_get_addr != NULL
6366 && htab->tls_get_addr->plt.plist != NULL
6367 && !add_dynamic_entry (DT_PPC_TLSOPT, 0))
6373 if (!add_dynamic_entry (DT_RELA, 0)
6374 || !add_dynamic_entry (DT_RELASZ, 0)
6375 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
6379 /* If any dynamic relocs apply to a read-only section, then we
6380 need a DT_TEXTREL entry. */
6381 if ((info->flags & DF_TEXTREL) == 0)
6382 elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel,
6385 if ((info->flags & DF_TEXTREL) != 0)
6387 if (!add_dynamic_entry (DT_TEXTREL, 0))
6390 if (htab->is_vxworks
6391 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
6394 #undef add_dynamic_entry
6396 if (htab->glink_eh_frame != NULL
6397 && htab->glink_eh_frame->contents != NULL)
6399 unsigned char *p = htab->glink_eh_frame->contents;
6402 memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
6403 /* CIE length (rewrite in case little-endian). */
6404 bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p);
6405 p += sizeof (glink_eh_frame_cie);
6407 val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie);
6408 bfd_put_32 (htab->elf.dynobj, val, p);
6411 val = p - htab->glink_eh_frame->contents;
6412 bfd_put_32 (htab->elf.dynobj, val, p);
6414 /* Offset to .glink. Set later. */
6417 bfd_put_32 (htab->elf.dynobj, htab->glink->size, p);
6423 && htab->elf.dynamic_sections_created)
6425 bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
6427 *p++ = DW_CFA_advance_loc + adv;
6430 *p++ = DW_CFA_advance_loc1;
6433 else if (adv < 65536)
6435 *p++ = DW_CFA_advance_loc2;
6436 bfd_put_16 (htab->elf.dynobj, adv, p);
6441 *p++ = DW_CFA_advance_loc4;
6442 bfd_put_32 (htab->elf.dynobj, adv, p);
6445 *p++ = DW_CFA_register;
6448 *p++ = DW_CFA_advance_loc + 4;
6449 *p++ = DW_CFA_restore_extended;
6452 BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4)
6453 == htab->glink_eh_frame->size);
6459 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
6462 ppc_elf_hash_symbol (struct elf_link_hash_entry *h)
6464 if (h->plt.plist != NULL
6466 && (!h->pointer_equality_needed
6467 || !h->ref_regular_nonweak))
6470 return _bfd_elf_hash_symbol (h);
6473 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
6475 /* Relaxation trampolines. r12 is available for clobbering (r11, is
6476 used for some functions that are allowed to break the ABI). */
6477 static const int shared_stub_entry[] =
6479 0x7c0802a6, /* mflr 0 */
6480 0x429f0005, /* bcl 20, 31, .Lxxx */
6481 0x7d8802a6, /* mflr 12 */
6482 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
6483 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */
6484 0x7c0803a6, /* mtlr 0 */
6485 0x7d8903a6, /* mtctr 12 */
6486 0x4e800420, /* bctr */
6489 static const int stub_entry[] =
6491 0x3d800000, /* lis 12,xxx@ha */
6492 0x398c0000, /* addi 12,12,xxx@l */
6493 0x7d8903a6, /* mtctr 12 */
6494 0x4e800420, /* bctr */
6498 ppc_elf_relax_section (bfd *abfd,
6500 struct bfd_link_info *link_info,
6505 struct one_fixup *next;
6507 /* Final link, can use the symbol offset. For a
6508 relocatable link we use the symbol's index. */
6513 Elf_Internal_Shdr *symtab_hdr;
6514 bfd_byte *contents = NULL;
6515 Elf_Internal_Sym *isymbuf = NULL;
6516 Elf_Internal_Rela *internal_relocs = NULL;
6517 Elf_Internal_Rela *irel, *irelend;
6518 struct one_fixup *fixups = NULL;
6519 unsigned changes = 0;
6520 struct ppc_elf_link_hash_table *htab;
6521 bfd_size_type trampoff;
6523 bfd_boolean maybe_pasted;
6527 /* Nothing to do if there are no relocations, and no need to do
6528 anything with non-alloc or non-code sections. */
6529 if ((isec->flags & SEC_ALLOC) == 0
6530 || (isec->flags & SEC_CODE) == 0
6531 || (isec->flags & SEC_RELOC) == 0
6532 || isec->reloc_count == 0)
6535 /* We cannot represent the required PIC relocs in the output, so don't
6536 do anything. The linker doesn't support mixing -shared and -r
6538 if (link_info->relocatable && link_info->shared)
6541 trampoff = (isec->size + 3) & (bfd_vma) -4;
6542 maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0
6543 || strcmp (isec->output_section->name, ".fini") == 0);
6544 /* Space for a branch around any trampolines. */
6548 symtab_hdr = &elf_symtab_hdr (abfd);
6550 /* Get a copy of the native relocations. */
6551 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
6552 link_info->keep_memory);
6553 if (internal_relocs == NULL)
6556 htab = ppc_elf_hash_table (link_info);
6557 got2 = bfd_get_section_by_name (abfd, ".got2");
6559 irelend = internal_relocs + isec->reloc_count;
6560 for (irel = internal_relocs; irel < irelend; irel++)
6562 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
6565 struct one_fixup *f;
6566 size_t insn_offset = 0;
6567 bfd_vma max_branch_offset, val;
6570 struct elf_link_hash_entry *h;
6571 struct plt_entry **plist;
6572 unsigned char sym_type;
6577 case R_PPC_LOCAL24PC:
6578 case R_PPC_PLTREL24:
6579 max_branch_offset = 1 << 25;
6583 case R_PPC_REL14_BRTAKEN:
6584 case R_PPC_REL14_BRNTAKEN:
6585 max_branch_offset = 1 << 15;
6592 /* Get the value of the symbol referred to by the reloc. */
6594 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
6596 /* A local symbol. */
6597 Elf_Internal_Sym *isym;
6599 /* Read this BFD's local symbols. */
6600 if (isymbuf == NULL)
6602 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
6603 if (isymbuf == NULL)
6604 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
6605 symtab_hdr->sh_info, 0,
6610 isym = isymbuf + ELF32_R_SYM (irel->r_info);
6611 if (isym->st_shndx == SHN_UNDEF)
6612 tsec = bfd_und_section_ptr;
6613 else if (isym->st_shndx == SHN_ABS)
6614 tsec = bfd_abs_section_ptr;
6615 else if (isym->st_shndx == SHN_COMMON)
6616 tsec = bfd_com_section_ptr;
6618 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
6620 toff = isym->st_value;
6621 sym_type = ELF_ST_TYPE (isym->st_info);
6625 /* Global symbol handling. */
6628 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
6629 h = elf_sym_hashes (abfd)[indx];
6631 while (h->root.type == bfd_link_hash_indirect
6632 || h->root.type == bfd_link_hash_warning)
6633 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6635 if (h->root.type == bfd_link_hash_defined
6636 || h->root.type == bfd_link_hash_defweak)
6638 tsec = h->root.u.def.section;
6639 toff = h->root.u.def.value;
6641 else if (h->root.type == bfd_link_hash_undefined
6642 || h->root.type == bfd_link_hash_undefweak)
6644 tsec = bfd_und_section_ptr;
6645 toff = link_info->relocatable ? indx : 0;
6653 /* The condition here under which we call find_plt_ent must
6654 match that in relocate_section. If we call find_plt_ent here
6655 but not in relocate_section, or vice versa, then the branch
6656 destination used here may be incorrect. */
6660 /* We know is_branch_reloc (r_type) is true. */
6661 if (h->type == STT_GNU_IFUNC
6662 || r_type == R_PPC_PLTREL24)
6663 plist = &h->plt.plist;
6665 else if (sym_type == STT_GNU_IFUNC
6666 && elf_local_got_offsets (abfd) != NULL)
6668 bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
6669 struct plt_entry **local_plt = (struct plt_entry **)
6670 (local_got_offsets + symtab_hdr->sh_info);
6671 plist = local_plt + ELF32_R_SYM (irel->r_info);
6676 struct plt_entry *ent;
6678 if (r_type == R_PPC_PLTREL24 && link_info->shared)
6679 addend = irel->r_addend;
6680 ent = find_plt_ent (plist, got2, addend);
6683 if (htab->plt_type == PLT_NEW
6685 || !htab->elf.dynamic_sections_created
6686 || h->dynindx == -1)
6689 toff = ent->glink_offset;
6694 toff = ent->plt.offset;
6699 /* If the branch and target are in the same section, you have
6700 no hope of adding stubs. We'll error out later should the
6705 /* There probably isn't any reason to handle symbols in
6706 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6707 attribute for a code section, and we are only looking at
6708 branches. However, implement it correctly here as a
6709 reference for other target relax_section functions. */
6710 if (0 && tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
6712 /* At this stage in linking, no SEC_MERGE symbol has been
6713 adjusted, so all references to such symbols need to be
6714 passed through _bfd_merged_section_offset. (Later, in
6715 relocate_section, all SEC_MERGE symbols *except* for
6716 section symbols have been adjusted.)
6718 gas may reduce relocations against symbols in SEC_MERGE
6719 sections to a relocation against the section symbol when
6720 the original addend was zero. When the reloc is against
6721 a section symbol we should include the addend in the
6722 offset passed to _bfd_merged_section_offset, since the
6723 location of interest is the original symbol. On the
6724 other hand, an access to "sym+addend" where "sym" is not
6725 a section symbol should not include the addend; Such an
6726 access is presumed to be an offset from "sym"; The
6727 location of interest is just "sym". */
6728 if (sym_type == STT_SECTION)
6729 toff += irel->r_addend;
6731 toff = _bfd_merged_section_offset (abfd, &tsec,
6732 elf_section_data (tsec)->sec_info,
6735 if (sym_type != STT_SECTION)
6736 toff += irel->r_addend;
6738 /* PLTREL24 addends are special. */
6739 else if (r_type != R_PPC_PLTREL24)
6740 toff += irel->r_addend;
6742 /* Attempted -shared link of non-pic code loses. */
6743 if (tsec->output_section == NULL)
6746 roff = irel->r_offset;
6748 /* If the branch is in range, no need to do anything. */
6749 if (tsec != bfd_und_section_ptr
6750 && (!link_info->relocatable
6751 /* A relocatable link may have sections moved during
6752 final link, so do not presume they remain in range. */
6753 || tsec->output_section == isec->output_section))
6755 bfd_vma symaddr, reladdr;
6757 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
6758 reladdr = isec->output_section->vma + isec->output_offset + roff;
6759 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
6763 /* Look for an existing fixup to this address. */
6764 for (f = fixups; f ; f = f->next)
6765 if (f->tsec == tsec && f->toff == toff)
6771 unsigned long stub_rtype;
6773 val = trampoff - roff;
6774 if (val >= max_branch_offset)
6775 /* Oh dear, we can't reach a trampoline. Don't try to add
6776 one. We'll report an error later. */
6779 if (link_info->shared)
6781 size = 4 * ARRAY_SIZE (shared_stub_entry);
6786 size = 4 * ARRAY_SIZE (stub_entry);
6789 stub_rtype = R_PPC_RELAX;
6790 if (tsec == htab->plt
6791 || tsec == htab->glink)
6793 stub_rtype = R_PPC_RELAX_PLT;
6794 if (r_type == R_PPC_PLTREL24)
6795 stub_rtype = R_PPC_RELAX_PLTREL24;
6798 /* Hijack the old relocation. Since we need two
6799 relocations for this use a "composite" reloc. */
6800 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
6802 irel->r_offset = trampoff + insn_offset;
6803 if (r_type == R_PPC_PLTREL24
6804 && stub_rtype != R_PPC_RELAX_PLTREL24)
6807 /* Record the fixup so we don't do it again this section. */
6808 f = bfd_malloc (sizeof (*f));
6812 f->trampoff = trampoff;
6820 val = f->trampoff - roff;
6821 if (val >= max_branch_offset)
6824 /* Nop out the reloc, since we're finalizing things here. */
6825 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
6828 /* Get the section contents. */
6829 if (contents == NULL)
6831 /* Get cached copy if it exists. */
6832 if (elf_section_data (isec)->this_hdr.contents != NULL)
6833 contents = elf_section_data (isec)->this_hdr.contents;
6836 /* Go get them off disk. */
6837 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
6842 /* Fix up the existing branch to hit the trampoline. */
6843 hit_addr = contents + roff;
6847 case R_PPC_LOCAL24PC:
6848 case R_PPC_PLTREL24:
6849 t0 = bfd_get_32 (abfd, hit_addr);
6851 t0 |= val & 0x3fffffc;
6852 bfd_put_32 (abfd, t0, hit_addr);
6856 case R_PPC_REL14_BRTAKEN:
6857 case R_PPC_REL14_BRNTAKEN:
6858 t0 = bfd_get_32 (abfd, hit_addr);
6861 bfd_put_32 (abfd, t0, hit_addr);
6866 /* Write out the trampolines. */
6875 struct one_fixup *f = fixups;
6876 fixups = fixups->next;
6881 contents = bfd_realloc_or_free (contents, trampoff);
6882 if (contents == NULL)
6885 isec->size = (isec->size + 3) & (bfd_vma) -4;
6886 dest = contents + isec->size;
6887 /* Branch around the trampolines. */
6890 bfd_vma val = B + trampoff - isec->size;
6891 bfd_put_32 (abfd, val, dest);
6894 isec->size = trampoff;
6896 if (link_info->shared)
6898 stub = shared_stub_entry;
6899 size = ARRAY_SIZE (shared_stub_entry);
6904 size = ARRAY_SIZE (stub_entry);
6908 while (dest < contents + trampoff)
6910 bfd_put_32 (abfd, stub[i], dest);
6916 BFD_ASSERT (i == 0);
6920 && symtab_hdr->contents != (unsigned char *) isymbuf)
6922 if (! link_info->keep_memory)
6926 /* Cache the symbols for elf_link_input_bfd. */
6927 symtab_hdr->contents = (unsigned char *) isymbuf;
6931 if (contents != NULL
6932 && elf_section_data (isec)->this_hdr.contents != contents)
6934 if (!changes && !link_info->keep_memory)
6938 /* Cache the section contents for elf_link_input_bfd. */
6939 elf_section_data (isec)->this_hdr.contents = contents;
6945 /* Append sufficient NOP relocs so we can write out relocation
6946 information for the trampolines. */
6947 Elf_Internal_Shdr *rel_hdr;
6948 Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count)
6949 * sizeof (*new_relocs));
6954 memcpy (new_relocs, internal_relocs,
6955 isec->reloc_count * sizeof (*new_relocs));
6956 for (ix = changes; ix--;)
6958 irel = new_relocs + ix + isec->reloc_count;
6960 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
6962 if (internal_relocs != elf_section_data (isec)->relocs)
6963 free (internal_relocs);
6964 elf_section_data (isec)->relocs = new_relocs;
6965 isec->reloc_count += changes;
6966 rel_hdr = _bfd_elf_single_rel_hdr (isec);
6967 rel_hdr->sh_size += changes * rel_hdr->sh_entsize;
6969 else if (elf_section_data (isec)->relocs != internal_relocs)
6970 free (internal_relocs);
6972 *again = changes != 0;
6973 if (!*again && link_info->relocatable)
6975 /* Convert the internal relax relocs to external form. */
6976 for (irel = internal_relocs; irel < irelend; irel++)
6977 if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX)
6979 unsigned long r_symndx = ELF32_R_SYM (irel->r_info);
6981 /* Rewrite the reloc and convert one of the trailing nop
6982 relocs to describe this relocation. */
6983 BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE);
6984 /* The relocs are at the bottom 2 bytes */
6985 irel[0].r_offset += 2;
6986 memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel));
6987 irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
6988 irel[1].r_offset += 4;
6989 irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
6997 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
6999 if (contents != NULL
7000 && elf_section_data (isec)->this_hdr.contents != contents)
7002 if (internal_relocs != NULL
7003 && elf_section_data (isec)->relocs != internal_relocs)
7004 free (internal_relocs);
7008 /* What to do when ld finds relocations against symbols defined in
7009 discarded sections. */
7012 ppc_elf_action_discarded (asection *sec)
7014 if (strcmp (".fixup", sec->name) == 0)
7017 if (strcmp (".got2", sec->name) == 0)
7020 return _bfd_elf_default_action_discarded (sec);
7023 /* Fill in the address for a pointer generated in a linker section. */
7026 elf_finish_pointer_linker_section (bfd *input_bfd,
7027 elf_linker_section_t *lsect,
7028 struct elf_link_hash_entry *h,
7030 const Elf_Internal_Rela *rel)
7032 elf_linker_section_pointers_t *linker_section_ptr;
7034 BFD_ASSERT (lsect != NULL);
7038 /* Handle global symbol. */
7039 struct ppc_elf_link_hash_entry *eh;
7041 eh = (struct ppc_elf_link_hash_entry *) h;
7042 BFD_ASSERT (eh->elf.def_regular);
7043 linker_section_ptr = eh->linker_section_pointer;
7047 /* Handle local symbol. */
7048 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
7050 BFD_ASSERT (is_ppc_elf (input_bfd));
7051 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
7052 linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
7055 linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
7058 BFD_ASSERT (linker_section_ptr != NULL);
7060 /* Offset will always be a multiple of four, so use the bottom bit
7061 as a "written" flag. */
7062 if ((linker_section_ptr->offset & 1) == 0)
7064 bfd_put_32 (lsect->section->owner,
7065 relocation + linker_section_ptr->addend,
7066 lsect->section->contents + linker_section_ptr->offset);
7067 linker_section_ptr->offset += 1;
7070 relocation = (lsect->section->output_section->vma
7071 + lsect->section->output_offset
7072 + linker_section_ptr->offset - 1
7073 - SYM_VAL (lsect->sym));
7077 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
7078 lsect->name, (long) relocation, (long) relocation);
7084 #define PPC_LO(v) ((v) & 0xffff)
7085 #define PPC_HI(v) (((v) >> 16) & 0xffff)
7086 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
7089 write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p,
7090 struct bfd_link_info *info)
7092 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
7093 bfd *output_bfd = info->output_bfd;
7096 plt = ((ent->plt.offset & ~1)
7097 + plt_sec->output_section->vma
7098 + plt_sec->output_offset);
7104 if (ent->addend >= 32768)
7106 + ent->sec->output_section->vma
7107 + ent->sec->output_offset);
7108 else if (htab->elf.hgot != NULL)
7109 got = SYM_VAL (htab->elf.hgot);
7113 if (plt + 0x8000 < 0x10000)
7115 bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
7117 bfd_put_32 (output_bfd, MTCTR_11, p);
7119 bfd_put_32 (output_bfd, BCTR, p);
7121 bfd_put_32 (output_bfd, NOP, p);
7126 bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
7128 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
7130 bfd_put_32 (output_bfd, MTCTR_11, p);
7132 bfd_put_32 (output_bfd, BCTR, p);
7138 bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
7140 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
7142 bfd_put_32 (output_bfd, MTCTR_11, p);
7144 bfd_put_32 (output_bfd, BCTR, p);
7149 /* Return true if symbol is defined statically. */
7152 is_static_defined (struct elf_link_hash_entry *h)
7154 return ((h->root.type == bfd_link_hash_defined
7155 || h->root.type == bfd_link_hash_defweak)
7156 && h->root.u.def.section != NULL
7157 && h->root.u.def.section->output_section != NULL);
7160 /* If INSN is an opcode that may be used with an @tls operand, return
7161 the transformed insn for TLS optimisation, otherwise return 0. If
7162 REG is non-zero only match an insn with RB or RA equal to REG. */
7165 _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg)
7169 if ((insn & (0x3f << 26)) != 31 << 26)
7172 if (reg == 0 || ((insn >> 11) & 0x1f) == reg)
7173 rtra = insn & ((1 << 26) - (1 << 16));
7174 else if (((insn >> 16) & 0x1f) == reg)
7175 rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5);
7179 if ((insn & (0x3ff << 1)) == 266 << 1)
7182 else if ((insn & (0x1f << 1)) == 23 << 1
7183 && ((insn & (0x1f << 6)) < 14 << 6
7184 || ((insn & (0x1f << 6)) >= 16 << 6
7185 && (insn & (0x1f << 6)) < 24 << 6)))
7186 /* load and store indexed -> dform. */
7187 insn = (32 | ((insn >> 6) & 0x1f)) << 26;
7188 else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
7189 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7190 insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1);
7191 else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
7193 insn = (58 << 26) | 2;
7200 /* If INSN is an opcode that may be used with an @tprel operand, return
7201 the transformed insn for an undefined weak symbol, ie. with the
7202 thread pointer REG operand removed. Otherwise return 0. */
7205 _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg)
7207 if ((insn & (0x1f << 16)) == reg << 16
7208 && ((insn & (0x3f << 26)) == 14u << 26 /* addi */
7209 || (insn & (0x3f << 26)) == 15u << 26 /* addis */
7210 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
7211 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
7212 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
7213 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
7214 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
7215 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
7216 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
7217 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
7218 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
7219 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
7220 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
7221 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
7222 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
7223 || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
7225 || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
7226 && ((insn & 3) == 0 || (insn & 3) == 3))))
7228 insn &= ~(0x1f << 16);
7230 else if ((insn & (0x1f << 21)) == reg << 21
7231 && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */
7232 || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */
7233 || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */))
7235 insn &= ~(0x1f << 21);
7236 insn |= (insn & (0x1f << 16)) << 5;
7237 if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */)
7238 insn -= 2 >> 26; /* convert to ori,oris */
7245 /* The RELOCATE_SECTION function is called by the ELF backend linker
7246 to handle the relocations for a section.
7248 The relocs are always passed as Rela structures; if the section
7249 actually uses Rel structures, the r_addend field will always be
7252 This function is responsible for adjust the section contents as
7253 necessary, and (if using Rela relocs and generating a
7254 relocatable output file) adjusting the reloc addend as
7257 This function does not have to worry about setting the reloc
7258 address or the reloc symbol index.
7260 LOCAL_SYMS is a pointer to the swapped in local symbols.
7262 LOCAL_SECTIONS is an array giving the section in the input file
7263 corresponding to the st_shndx field of each local symbol.
7265 The global hash table entry for the global symbols can be found
7266 via elf_sym_hashes (input_bfd).
7268 When generating relocatable output, this function must handle
7269 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
7270 going to be the section symbol corresponding to the output
7271 section, which means that the addend must be adjusted
7275 ppc_elf_relocate_section (bfd *output_bfd,
7276 struct bfd_link_info *info,
7278 asection *input_section,
7280 Elf_Internal_Rela *relocs,
7281 Elf_Internal_Sym *local_syms,
7282 asection **local_sections)
7284 Elf_Internal_Shdr *symtab_hdr;
7285 struct elf_link_hash_entry **sym_hashes;
7286 struct ppc_elf_link_hash_table *htab;
7287 Elf_Internal_Rela *rel;
7288 Elf_Internal_Rela *relend;
7289 Elf_Internal_Rela outrel;
7290 asection *got2, *sreloc = NULL;
7291 bfd_vma *local_got_offsets;
7292 bfd_boolean ret = TRUE;
7293 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
7294 bfd_boolean is_vxworks_tls;
7297 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
7298 "%ld relocations%s",
7299 input_bfd, input_section,
7300 (long) input_section->reloc_count,
7301 (info->relocatable) ? " (relocatable)" : "");
7304 got2 = bfd_get_section_by_name (input_bfd, ".got2");
7306 /* Initialize howto table if not already done. */
7307 if (!ppc_elf_howto_table[R_PPC_ADDR32])
7308 ppc_elf_howto_init ();
7310 htab = ppc_elf_hash_table (info);
7311 local_got_offsets = elf_local_got_offsets (input_bfd);
7312 symtab_hdr = &elf_symtab_hdr (input_bfd);
7313 sym_hashes = elf_sym_hashes (input_bfd);
7314 /* We have to handle relocations in vxworks .tls_vars sections
7315 specially, because the dynamic loader is 'weird'. */
7316 is_vxworks_tls = (htab->is_vxworks && info->shared
7317 && !strcmp (input_section->output_section->name,
7320 relend = relocs + input_section->reloc_count;
7321 for (; rel < relend; rel++)
7323 enum elf_ppc_reloc_type r_type;
7325 bfd_reloc_status_type r;
7326 Elf_Internal_Sym *sym;
7328 struct elf_link_hash_entry *h;
7329 const char *sym_name;
7330 reloc_howto_type *howto;
7331 unsigned long r_symndx;
7333 bfd_vma branch_bit, from;
7334 bfd_boolean unresolved_reloc;
7336 unsigned int tls_type, tls_mask, tls_gd;
7337 struct plt_entry **ifunc;
7339 r_type = ELF32_R_TYPE (rel->r_info);
7343 unresolved_reloc = FALSE;
7345 r_symndx = ELF32_R_SYM (rel->r_info);
7347 if (r_symndx < symtab_hdr->sh_info)
7349 sym = local_syms + r_symndx;
7350 sec = local_sections[r_symndx];
7351 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
7353 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
7357 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
7358 r_symndx, symtab_hdr, sym_hashes,
7360 unresolved_reloc, warned);
7362 sym_name = h->root.root.string;
7365 if (sec != NULL && discarded_section (sec))
7367 /* For relocs against symbols from removed linkonce sections,
7368 or sections discarded by a linker script, we just want the
7369 section contents zeroed. Avoid any special processing. */
7371 if (r_type < R_PPC_max)
7372 howto = ppc_elf_howto_table[r_type];
7373 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
7374 rel, 1, relend, howto, 0, contents);
7377 if (info->relocatable)
7380 && r_type == R_PPC_PLTREL24
7381 && rel->r_addend >= 32768)
7383 /* R_PPC_PLTREL24 is rather special. If non-zero, the
7384 addend specifies the GOT pointer offset within .got2. */
7385 rel->r_addend += got2->output_offset;
7390 /* TLS optimizations. Replace instruction sequences and relocs
7391 based on information we collected in tls_optimize. We edit
7392 RELOCS so that --emit-relocs will output something sensible
7393 for the final instruction stream. */
7397 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
7398 else if (local_got_offsets != NULL)
7400 struct plt_entry **local_plt;
7403 = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info);
7404 lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
7405 tls_mask = lgot_masks[r_symndx];
7408 /* Ensure reloc mapping code below stays sane. */
7409 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
7410 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
7411 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
7412 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
7413 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
7414 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
7415 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
7416 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
7423 case R_PPC_GOT_TPREL16:
7424 case R_PPC_GOT_TPREL16_LO:
7425 if ((tls_mask & TLS_TLS) != 0
7426 && (tls_mask & TLS_TPREL) == 0)
7430 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
7432 insn |= 0x3c020000; /* addis 0,2,0 */
7433 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
7434 r_type = R_PPC_TPREL16_HA;
7435 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7440 if ((tls_mask & TLS_TLS) != 0
7441 && (tls_mask & TLS_TPREL) == 0)
7445 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
7446 insn = _bfd_elf_ppc_at_tls_transform (insn, 2);
7449 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7450 r_type = R_PPC_TPREL16_LO;
7451 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7453 /* Was PPC_TLS which sits on insn boundary, now
7454 PPC_TPREL16_LO which is at low-order half-word. */
7455 rel->r_offset += d_offset;
7459 case R_PPC_GOT_TLSGD16_HI:
7460 case R_PPC_GOT_TLSGD16_HA:
7461 tls_gd = TLS_TPRELGD;
7462 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
7466 case R_PPC_GOT_TLSLD16_HI:
7467 case R_PPC_GOT_TLSLD16_HA:
7468 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
7471 if ((tls_mask & tls_gd) != 0)
7472 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
7473 + R_PPC_GOT_TPREL16);
7476 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
7477 rel->r_offset -= d_offset;
7478 r_type = R_PPC_NONE;
7480 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7484 case R_PPC_GOT_TLSGD16:
7485 case R_PPC_GOT_TLSGD16_LO:
7486 tls_gd = TLS_TPRELGD;
7487 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
7491 case R_PPC_GOT_TLSLD16:
7492 case R_PPC_GOT_TLSLD16_LO:
7493 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
7495 unsigned int insn1, insn2;
7499 offset = (bfd_vma) -1;
7500 /* If not using the newer R_PPC_TLSGD/LD to mark
7501 __tls_get_addr calls, we must trust that the call
7502 stays with its arg setup insns, ie. that the next
7503 reloc is the __tls_get_addr call associated with
7504 the current reloc. Edit both insns. */
7505 if (input_section->has_tls_get_addr_call
7507 && branch_reloc_hash_match (input_bfd, rel + 1,
7508 htab->tls_get_addr))
7509 offset = rel[1].r_offset;
7510 if ((tls_mask & tls_gd) != 0)
7513 insn1 = bfd_get_32 (output_bfd,
7514 contents + rel->r_offset - d_offset);
7515 insn1 &= (1 << 26) - 1;
7516 insn1 |= 32 << 26; /* lwz */
7517 if (offset != (bfd_vma) -1)
7519 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
7520 insn2 = 0x7c631214; /* add 3,3,2 */
7521 bfd_put_32 (output_bfd, insn2, contents + offset);
7523 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
7524 + R_PPC_GOT_TPREL16);
7525 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7530 insn1 = 0x3c620000; /* addis 3,2,0 */
7533 /* Was an LD reloc. */
7535 r_symndx < symtab_hdr->sh_info;
7537 if (local_sections[r_symndx] == sec)
7539 if (r_symndx >= symtab_hdr->sh_info)
7540 r_symndx = STN_UNDEF;
7541 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
7542 if (r_symndx != STN_UNDEF)
7543 rel->r_addend -= (local_syms[r_symndx].st_value
7544 + sec->output_offset
7545 + sec->output_section->vma);
7547 r_type = R_PPC_TPREL16_HA;
7548 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7549 if (offset != (bfd_vma) -1)
7551 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
7552 rel[1].r_offset = offset + d_offset;
7553 rel[1].r_addend = rel->r_addend;
7554 insn2 = 0x38630000; /* addi 3,3,0 */
7555 bfd_put_32 (output_bfd, insn2, contents + offset);
7558 bfd_put_32 (output_bfd, insn1,
7559 contents + rel->r_offset - d_offset);
7562 /* We changed the symbol on an LD reloc. Start over
7563 in order to get h, sym, sec etc. right. */
7571 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
7574 bfd_vma offset = rel->r_offset;
7576 if ((tls_mask & TLS_TPRELGD) != 0)
7579 r_type = R_PPC_NONE;
7580 insn2 = 0x7c631214; /* add 3,3,2 */
7585 r_type = R_PPC_TPREL16_LO;
7586 rel->r_offset += d_offset;
7587 insn2 = 0x38630000; /* addi 3,3,0 */
7589 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7590 bfd_put_32 (output_bfd, insn2, contents + offset);
7591 /* Zap the reloc on the _tls_get_addr call too. */
7592 BFD_ASSERT (offset == rel[1].r_offset);
7593 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
7598 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
7603 r_symndx < symtab_hdr->sh_info;
7605 if (local_sections[r_symndx] == sec)
7607 if (r_symndx >= symtab_hdr->sh_info)
7608 r_symndx = STN_UNDEF;
7609 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
7610 if (r_symndx != STN_UNDEF)
7611 rel->r_addend -= (local_syms[r_symndx].st_value
7612 + sec->output_offset
7613 + sec->output_section->vma);
7615 rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
7616 rel->r_offset += d_offset;
7617 insn2 = 0x38630000; /* addi 3,3,0 */
7618 bfd_put_32 (output_bfd, insn2,
7619 contents + rel->r_offset - d_offset);
7620 /* Zap the reloc on the _tls_get_addr call too. */
7621 BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
7622 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
7629 /* Handle other relocations that tweak non-addend part of insn. */
7636 /* Branch taken prediction relocations. */
7637 case R_PPC_ADDR14_BRTAKEN:
7638 case R_PPC_REL14_BRTAKEN:
7639 branch_bit = BRANCH_PREDICT_BIT;
7642 /* Branch not taken prediction relocations. */
7643 case R_PPC_ADDR14_BRNTAKEN:
7644 case R_PPC_REL14_BRNTAKEN:
7648 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
7649 insn &= ~BRANCH_PREDICT_BIT;
7652 from = (rel->r_offset
7653 + input_section->output_offset
7654 + input_section->output_section->vma);
7656 /* Invert 'y' bit if not the default. */
7657 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
7658 insn ^= BRANCH_PREDICT_BIT;
7660 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7666 if (!htab->is_vxworks)
7668 struct plt_entry *ent;
7672 if (h->type == STT_GNU_IFUNC)
7673 ifunc = &h->plt.plist;
7675 else if (local_got_offsets != NULL
7676 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
7678 struct plt_entry **local_plt;
7680 local_plt = (struct plt_entry **) (local_got_offsets
7681 + symtab_hdr->sh_info);
7682 ifunc = local_plt + r_symndx;
7688 || is_branch_reloc (r_type)))
7691 if (r_type == R_PPC_PLTREL24 && info->shared)
7692 addend = rel->r_addend;
7693 ent = find_plt_ent (ifunc, got2, addend);
7697 if (h == NULL && (ent->plt.offset & 1) == 0)
7699 Elf_Internal_Rela rela;
7702 rela.r_offset = (htab->iplt->output_section->vma
7703 + htab->iplt->output_offset
7705 rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7706 rela.r_addend = relocation;
7707 loc = htab->reliplt->contents;
7708 loc += (htab->reliplt->reloc_count++
7709 * sizeof (Elf32_External_Rela));
7710 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7712 ent->plt.offset |= 1;
7714 if (h == NULL && (ent->glink_offset & 1) == 0)
7716 unsigned char *p = ((unsigned char *) htab->glink->contents
7717 + ent->glink_offset);
7718 write_glink_stub (ent, htab->iplt, p, info);
7719 ent->glink_offset |= 1;
7722 unresolved_reloc = FALSE;
7723 if (htab->plt_type == PLT_NEW
7724 || !htab->elf.dynamic_sections_created
7726 relocation = (htab->glink->output_section->vma
7727 + htab->glink->output_offset
7728 + (ent->glink_offset & ~1));
7730 relocation = (htab->plt->output_section->vma
7731 + htab->plt->output_offset
7736 addend = rel->r_addend;
7739 if (r_type < R_PPC_max)
7740 howto = ppc_elf_howto_table[r_type];
7744 info->callbacks->einfo
7745 (_("%P: %B: unknown relocation type %d for symbol %s\n"),
7746 input_bfd, (int) r_type, sym_name);
7748 bfd_set_error (bfd_error_bad_value);
7756 case R_PPC_EMB_MRKREF:
7757 case R_PPC_GNU_VTINHERIT:
7758 case R_PPC_GNU_VTENTRY:
7761 /* GOT16 relocations. Like an ADDR16 using the symbol's
7762 address in the GOT as relocation value instead of the
7763 symbol's value itself. Also, create a GOT entry for the
7764 symbol and put the symbol value there. */
7765 case R_PPC_GOT_TLSGD16:
7766 case R_PPC_GOT_TLSGD16_LO:
7767 case R_PPC_GOT_TLSGD16_HI:
7768 case R_PPC_GOT_TLSGD16_HA:
7769 tls_type = TLS_TLS | TLS_GD;
7772 case R_PPC_GOT_TLSLD16:
7773 case R_PPC_GOT_TLSLD16_LO:
7774 case R_PPC_GOT_TLSLD16_HI:
7775 case R_PPC_GOT_TLSLD16_HA:
7776 tls_type = TLS_TLS | TLS_LD;
7779 case R_PPC_GOT_TPREL16:
7780 case R_PPC_GOT_TPREL16_LO:
7781 case R_PPC_GOT_TPREL16_HI:
7782 case R_PPC_GOT_TPREL16_HA:
7783 tls_type = TLS_TLS | TLS_TPREL;
7786 case R_PPC_GOT_DTPREL16:
7787 case R_PPC_GOT_DTPREL16_LO:
7788 case R_PPC_GOT_DTPREL16_HI:
7789 case R_PPC_GOT_DTPREL16_HA:
7790 tls_type = TLS_TLS | TLS_DTPREL;
7794 case R_PPC_GOT16_LO:
7795 case R_PPC_GOT16_HI:
7796 case R_PPC_GOT16_HA:
7800 /* Relocation is to the entry for this symbol in the global
7806 if (htab->got == NULL)
7810 if (tls_type == (TLS_TLS | TLS_LD)
7812 || !h->def_dynamic))
7813 offp = &htab->tlsld_got.offset;
7817 dyn = htab->elf.dynamic_sections_created;
7818 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7820 && SYMBOL_REFERENCES_LOCAL (info, h)))
7821 /* This is actually a static link, or it is a
7822 -Bsymbolic link and the symbol is defined
7823 locally, or the symbol was forced to be local
7824 because of a version file. */
7829 unresolved_reloc = FALSE;
7831 offp = &h->got.offset;
7835 if (local_got_offsets == NULL)
7837 offp = &local_got_offsets[r_symndx];
7840 /* The offset must always be a multiple of 4. We use the
7841 least significant bit to record whether we have already
7842 processed this entry. */
7848 unsigned int tls_m = (tls_mask
7849 & (TLS_LD | TLS_GD | TLS_DTPREL
7850 | TLS_TPREL | TLS_TPRELGD));
7852 if (offp == &htab->tlsld_got.offset)
7858 /* We might have multiple got entries for this sym.
7859 Initialize them all. */
7864 if ((tls_m & TLS_LD) != 0)
7866 tls_ty = TLS_TLS | TLS_LD;
7869 else if ((tls_m & TLS_GD) != 0)
7871 tls_ty = TLS_TLS | TLS_GD;
7874 else if ((tls_m & TLS_DTPREL) != 0)
7876 tls_ty = TLS_TLS | TLS_DTPREL;
7877 tls_m &= ~TLS_DTPREL;
7879 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
7881 tls_ty = TLS_TLS | TLS_TPREL;
7885 /* Generate relocs for the dynamic linker. */
7886 if ((info->shared || indx != 0)
7887 && (offp == &htab->tlsld_got.offset
7889 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7890 || h->root.type != bfd_link_hash_undefweak))
7892 asection *rsec = htab->relgot;
7895 outrel.r_offset = (htab->got->output_section->vma
7896 + htab->got->output_offset
7898 outrel.r_addend = 0;
7899 if (tls_ty & (TLS_LD | TLS_GD))
7901 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
7902 if (tls_ty == (TLS_TLS | TLS_GD))
7904 loc = rsec->contents;
7905 loc += (rsec->reloc_count++
7906 * sizeof (Elf32_External_Rela));
7907 bfd_elf32_swap_reloca_out (output_bfd,
7909 outrel.r_offset += 4;
7911 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
7914 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
7915 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
7916 else if (tls_ty == (TLS_TLS | TLS_TPREL))
7917 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
7919 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
7920 else if (ifunc != NULL)
7921 outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7923 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
7924 if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
7926 outrel.r_addend += relocation;
7927 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
7928 outrel.r_addend -= htab->elf.tls_sec->vma;
7930 loc = rsec->contents;
7931 loc += (rsec->reloc_count++
7932 * sizeof (Elf32_External_Rela));
7933 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
7936 /* Init the .got section contents if we're not
7937 emitting a reloc. */
7940 bfd_vma value = relocation;
7942 if (tls_ty == (TLS_TLS | TLS_LD))
7944 else if (tls_ty != 0)
7946 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
7947 if (tls_ty == (TLS_TLS | TLS_TPREL))
7948 value += DTP_OFFSET - TP_OFFSET;
7950 if (tls_ty == (TLS_TLS | TLS_GD))
7952 bfd_put_32 (output_bfd, value,
7953 htab->got->contents + off + 4);
7957 bfd_put_32 (output_bfd, value,
7958 htab->got->contents + off);
7962 if (tls_ty & (TLS_LD | TLS_GD))
7971 if (off >= (bfd_vma) -2)
7974 if ((tls_type & TLS_TLS) != 0)
7976 if (tls_type != (TLS_TLS | TLS_LD))
7978 if ((tls_mask & TLS_LD) != 0
7980 || !h->def_dynamic))
7982 if (tls_type != (TLS_TLS | TLS_GD))
7984 if ((tls_mask & TLS_GD) != 0)
7986 if (tls_type != (TLS_TLS | TLS_DTPREL))
7988 if ((tls_mask & TLS_DTPREL) != 0)
7995 relocation = (htab->got->output_section->vma
7996 + htab->got->output_offset
7998 - SYM_VAL (htab->elf.hgot));
8000 /* Addends on got relocations don't make much sense.
8001 x+off@got is actually x@got+off, and since the got is
8002 generated by a hash table traversal, the value in the
8003 got at entry m+n bears little relation to the entry m. */
8005 info->callbacks->einfo
8006 (_("%P: %H: non-zero addend on %s reloc against `%s'\n"),
8007 input_bfd, input_section, rel->r_offset,
8013 /* Relocations that need no special processing. */
8014 case R_PPC_LOCAL24PC:
8015 /* It makes no sense to point a local relocation
8016 at a symbol not in this object. */
8017 if (unresolved_reloc)
8019 if (! (*info->callbacks->undefined_symbol) (info,
8020 h->root.root.string,
8030 case R_PPC_DTPREL16:
8031 case R_PPC_DTPREL16_LO:
8032 case R_PPC_DTPREL16_HI:
8033 case R_PPC_DTPREL16_HA:
8034 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
8037 /* Relocations that may need to be propagated if this is a shared
8040 case R_PPC_TPREL16_LO:
8041 case R_PPC_TPREL16_HI:
8042 case R_PPC_TPREL16_HA:
8044 && h->root.type == bfd_link_hash_undefweak
8045 && h->dynindx == -1)
8047 /* Make this relocation against an undefined weak symbol
8048 resolve to zero. This is really just a tweak, since
8049 code using weak externs ought to check that they are
8050 defined before using them. */
8051 bfd_byte *p = contents + rel->r_offset - d_offset;
8052 unsigned int insn = bfd_get_32 (output_bfd, p);
8053 insn = _bfd_elf_ppc_at_tprel_transform (insn, 2);
8055 bfd_put_32 (output_bfd, insn, p);
8058 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
8059 /* The TPREL16 relocs shouldn't really be used in shared
8060 libs as they will result in DT_TEXTREL being set, but
8061 support them anyway. */
8065 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
8068 case R_PPC_DTPREL32:
8069 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
8072 case R_PPC_DTPMOD32:
8078 case R_PPC_REL16_LO:
8079 case R_PPC_REL16_HI:
8080 case R_PPC_REL16_HA:
8084 if (h == NULL || h == htab->elf.hgot)
8090 case R_PPC_ADDR16_LO:
8091 case R_PPC_ADDR16_HI:
8092 case R_PPC_ADDR16_HA:
8097 case R_PPC_VLE_REL8:
8098 case R_PPC_VLE_REL15:
8099 case R_PPC_VLE_REL24:
8102 case R_PPC_REL14_BRTAKEN:
8103 case R_PPC_REL14_BRNTAKEN:
8104 /* If these relocations are not to a named symbol, they can be
8105 handled right here, no need to bother the dynamic linker. */
8106 if (SYMBOL_CALLS_LOCAL (info, h)
8107 || h == htab->elf.hgot)
8113 case R_PPC_ADDR14_BRTAKEN:
8114 case R_PPC_ADDR14_BRNTAKEN:
8115 if (h != NULL && !info->shared)
8120 if ((input_section->flags & SEC_ALLOC) == 0
8126 && ((h->root.type == bfd_link_hash_undefined
8127 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
8128 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
8129 || (h->root.type == bfd_link_hash_undefweak
8130 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
8131 && (must_be_dyn_reloc (info, r_type)
8132 || !SYMBOL_CALLS_LOCAL (info, h)))
8133 || (ELIMINATE_COPY_RELOCS
8138 && !h->def_regular))
8143 fprintf (stderr, "ppc_elf_relocate_section needs to "
8144 "create relocation for %s\n",
8145 (h && h->root.root.string
8146 ? h->root.root.string : "<unknown>"));
8149 /* When generating a shared object, these relocations
8150 are copied into the output file to be resolved at run
8154 sreloc = elf_section_data (input_section)->sreloc;
8155 if (!htab->elf.dynamic_sections_created)
8156 sreloc = htab->reliplt;
8162 outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
8165 if (outrel.r_offset == (bfd_vma) -1
8166 || outrel.r_offset == (bfd_vma) -2)
8167 skip = (int) outrel.r_offset;
8168 outrel.r_offset += (input_section->output_section->vma
8169 + input_section->output_offset);
8172 memset (&outrel, 0, sizeof outrel);
8174 && (h->root.type == bfd_link_hash_undefined
8175 || h->root.type == bfd_link_hash_undefweak))
8176 || !SYMBOL_REFERENCES_LOCAL (info, h))
8178 unresolved_reloc = FALSE;
8179 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
8180 outrel.r_addend = rel->r_addend;
8184 outrel.r_addend = relocation + rel->r_addend;
8186 if (r_type != R_PPC_ADDR32)
8192 /* If we get here when building a static
8193 executable, then the libc startup function
8194 responsible for applying indirect function
8195 relocations is going to complain about
8197 If we get here when building a dynamic
8198 executable, it will be because we have
8199 a text relocation. The dynamic loader
8200 will set the text segment writable and
8201 non-executable to apply text relocations.
8202 So we'll segfault when trying to run the
8203 indirection function to resolve the reloc. */
8204 info->callbacks->einfo
8205 (_("%P: %H: relocation %s for indirect "
8206 "function %s unsupported\n"),
8207 input_bfd, input_section, rel->r_offset,
8212 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
8214 else if (sec == NULL || sec->owner == NULL)
8216 bfd_set_error (bfd_error_bad_value);
8223 /* We are turning this relocation into one
8224 against a section symbol. It would be
8225 proper to subtract the symbol's value,
8226 osec->vma, from the emitted reloc addend,
8227 but ld.so expects buggy relocs.
8228 FIXME: Why not always use a zero index? */
8229 osec = sec->output_section;
8230 indx = elf_section_data (osec)->dynindx;
8233 osec = htab->elf.text_index_section;
8234 indx = elf_section_data (osec)->dynindx;
8236 BFD_ASSERT (indx != 0);
8239 printf ("indx=%ld section=%s flags=%08x name=%s\n",
8240 indx, osec->name, osec->flags,
8241 h->root.root.string);
8245 outrel.r_info = ELF32_R_INFO (indx, r_type);
8247 else if (ifunc != NULL)
8248 outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
8250 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
8253 loc = sreloc->contents;
8254 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
8255 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
8260 /* This reloc will be computed at runtime. We clear the memory
8261 so that it contains predictable value. */
8263 && ((input_section->flags & SEC_ALLOC) != 0
8264 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
8266 relocation = howto->pc_relative ? outrel.r_offset : 0;
8273 case R_PPC_RELAX_PLT:
8274 case R_PPC_RELAX_PLTREL24:
8277 struct plt_entry *ent;
8278 bfd_vma got2_addend = 0;
8280 if (r_type == R_PPC_RELAX_PLTREL24)
8283 got2_addend = addend;
8286 ent = find_plt_ent (&h->plt.plist, got2, got2_addend);
8287 if (htab->plt_type == PLT_NEW)
8288 relocation = (htab->glink->output_section->vma
8289 + htab->glink->output_offset
8290 + ent->glink_offset);
8292 relocation = (htab->plt->output_section->vma
8293 + htab->plt->output_offset
8300 relocation -= (input_section->output_section->vma
8301 + input_section->output_offset
8302 + rel->r_offset - 4);
8308 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
8309 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
8311 /* We're clearing the bits for R_PPC_ADDR16_HA
8312 and R_PPC_ADDR16_LO here. */
8316 /* t0 is HA, t1 is LO */
8317 relocation += addend;
8318 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
8319 t1 |= relocation & 0xffff;
8321 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
8322 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
8324 /* Rewrite the reloc and convert one of the trailing nop
8325 relocs to describe this relocation. */
8326 BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE);
8327 /* The relocs are at the bottom 2 bytes */
8328 rel[0].r_offset += 2;
8329 memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
8330 rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
8331 rel[1].r_offset += 4;
8332 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
8337 /* Indirect .sdata relocation. */
8338 case R_PPC_EMB_SDAI16:
8339 BFD_ASSERT (htab->sdata[0].section != NULL);
8340 if (!is_static_defined (htab->sdata[0].sym))
8342 unresolved_reloc = TRUE;
8346 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
8347 h, relocation, rel);
8351 /* Indirect .sdata2 relocation. */
8352 case R_PPC_EMB_SDA2I16:
8353 BFD_ASSERT (htab->sdata[1].section != NULL);
8354 if (!is_static_defined (htab->sdata[1].sym))
8356 unresolved_reloc = TRUE;
8360 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
8361 h, relocation, rel);
8365 /* Handle the TOC16 reloc. We want to use the offset within the .got
8366 section, not the actual VMA. This is appropriate when generating
8367 an embedded ELF object, for which the .got section acts like the
8368 AIX .toc section. */
8369 case R_PPC_TOC16: /* phony GOT16 relocations */
8370 if (sec == NULL || sec->output_section == NULL)
8372 unresolved_reloc = TRUE;
8375 BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec),
8377 || strcmp (bfd_get_section_name (sec->owner, sec),
8380 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
8383 case R_PPC_PLTREL24:
8384 if (h == NULL || ifunc != NULL)
8386 /* Relocation is to the entry for this symbol in the
8387 procedure linkage table. */
8389 struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
8390 info->shared ? addend : 0);
8393 || htab->plt == NULL)
8395 /* We didn't make a PLT entry for this symbol. This
8396 happens when statically linking PIC code, or when
8397 using -Bsymbolic. */
8401 unresolved_reloc = FALSE;
8402 if (htab->plt_type == PLT_NEW)
8403 relocation = (htab->glink->output_section->vma
8404 + htab->glink->output_offset
8405 + ent->glink_offset);
8407 relocation = (htab->plt->output_section->vma
8408 + htab->plt->output_offset
8413 /* Relocate against _SDA_BASE_. */
8414 case R_PPC_SDAREL16:
8417 struct elf_link_hash_entry *sda = htab->sdata[0].sym;
8420 || sec->output_section == NULL
8421 || !is_static_defined (sda))
8423 unresolved_reloc = TRUE;
8426 addend -= SYM_VAL (sda);
8428 name = bfd_get_section_name (output_bfd, sec->output_section);
8429 if (! ((CONST_STRNEQ (name, ".sdata")
8430 && (name[6] == 0 || name[6] == '.'))
8431 || (CONST_STRNEQ (name, ".sbss")
8432 && (name[5] == 0 || name[5] == '.'))))
8434 info->callbacks->einfo
8435 (_("%P: %B: the target (%s) of a %s relocation is "
8436 "in the wrong output section (%s)\n"),
8445 /* Relocate against _SDA2_BASE_. */
8446 case R_PPC_EMB_SDA2REL:
8449 struct elf_link_hash_entry *sda = htab->sdata[1].sym;
8452 || sec->output_section == NULL
8453 || !is_static_defined (sda))
8455 unresolved_reloc = TRUE;
8458 addend -= SYM_VAL (sda);
8460 name = bfd_get_section_name (output_bfd, sec->output_section);
8461 if (! (CONST_STRNEQ (name, ".sdata2")
8462 || CONST_STRNEQ (name, ".sbss2")))
8464 info->callbacks->einfo
8465 (_("%P: %B: the target (%s) of a %s relocation is "
8466 "in the wrong output section (%s)\n"),
8475 case R_PPC_VLE_LO16A:
8476 relocation = (relocation + addend) & 0xffff;
8477 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8478 relocation, split16a_type);
8481 case R_PPC_VLE_LO16D:
8482 relocation = (relocation + addend) & 0xffff;
8483 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8484 relocation, split16d_type);
8487 case R_PPC_VLE_HI16A:
8488 relocation = ((relocation + addend) >> 16) & 0xffff;
8489 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8490 relocation, split16a_type);
8493 case R_PPC_VLE_HI16D:
8494 relocation = ((relocation + addend) >> 16) & 0xffff;
8495 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8496 relocation, split16d_type);
8499 case R_PPC_VLE_HA16A:
8501 bfd_vma value = relocation + addend;
8502 value = (((value >> 16) + ((value & 0x8000) ? 1 : 0)) & 0xffff);
8503 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8504 value, split16a_type);
8508 case R_PPC_VLE_HA16D:
8510 bfd_vma value = relocation + addend;
8511 value = (((value >> 16) + ((value & 0x8000) ? 1 : 0)) & 0xffff);
8512 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8513 value, split16d_type);
8517 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
8518 case R_PPC_EMB_SDA21:
8519 case R_PPC_VLE_SDA21:
8520 case R_PPC_EMB_RELSDA:
8521 case R_PPC_VLE_SDA21_LO:
8525 struct elf_link_hash_entry *sda = NULL;
8527 if (sec == NULL || sec->output_section == NULL)
8529 unresolved_reloc = TRUE;
8533 name = bfd_get_section_name (output_bfd, sec->output_section);
8534 if (((CONST_STRNEQ (name, ".sdata")
8535 && (name[6] == 0 || name[6] == '.'))
8536 || (CONST_STRNEQ (name, ".sbss")
8537 && (name[5] == 0 || name[5] == '.'))))
8540 sda = htab->sdata[0].sym;
8542 else if (CONST_STRNEQ (name, ".sdata2")
8543 || CONST_STRNEQ (name, ".sbss2"))
8546 sda = htab->sdata[1].sym;
8548 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
8549 || strcmp (name, ".PPC.EMB.sbss0") == 0)
8555 info->callbacks->einfo
8556 (_("%P: %B: the target (%s) of a %s relocation is "
8557 "in the wrong output section (%s)\n"),
8563 bfd_set_error (bfd_error_bad_value);
8570 if (!is_static_defined (sda))
8572 unresolved_reloc = TRUE;
8575 addend -= SYM_VAL (sda);
8579 && (r_type == R_PPC_VLE_SDA21
8580 || r_type == R_PPC_VLE_SDA21_LO))
8582 /* Use the split20 format. */
8583 bfd_vma insn, bits12to15, bits21to31;
8584 bfd_vma value = (relocation + rel->r_offset) & 0xffff;
8585 /* Propagate sign bit, if necessary. */
8586 insn = (value & 0x8000) ? 0x70107800 : 0x70000000;
8587 bits12to15 = value & 0x700;
8588 bits21to31 = value & 0x7ff;
8591 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
8594 else if (r_type == R_PPC_EMB_SDA21
8595 || r_type == R_PPC_VLE_SDA21
8596 || r_type == R_PPC_VLE_SDA21_LO)
8598 bfd_vma insn; /* Fill in register field. */
8600 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
8601 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
8602 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
8607 case R_PPC_VLE_SDAREL_LO16A:
8608 case R_PPC_VLE_SDAREL_LO16D:
8609 case R_PPC_VLE_SDAREL_HI16A:
8610 case R_PPC_VLE_SDAREL_HI16D:
8611 case R_PPC_VLE_SDAREL_HA16A:
8612 case R_PPC_VLE_SDAREL_HA16D:
8617 struct elf_link_hash_entry *sda = NULL;
8619 if (sec == NULL || sec->output_section == NULL)
8621 unresolved_reloc = TRUE;
8625 name = bfd_get_section_name (output_bfd, sec->output_section);
8626 if (((CONST_STRNEQ (name, ".sdata")
8627 && (name[6] == 0 || name[6] == '.'))
8628 || (CONST_STRNEQ (name, ".sbss")
8629 && (name[5] == 0 || name[5] == '.'))))
8632 sda = htab->sdata[0].sym;
8634 else if (CONST_STRNEQ (name, ".sdata2")
8635 || CONST_STRNEQ (name, ".sbss2"))
8638 sda = htab->sdata[1].sym;
8642 (*_bfd_error_handler)
8643 (_("%B: the target (%s) of a %s relocation is "
8644 "in the wrong output section (%s)"),
8650 bfd_set_error (bfd_error_bad_value);
8657 if (!is_static_defined (sda))
8659 unresolved_reloc = TRUE;
8664 value = sda->root.u.def.section->output_section->vma
8665 + sda->root.u.def.section->output_offset;
8667 if (r_type == R_PPC_VLE_SDAREL_LO16A)
8669 value = (value + addend) & 0xffff;
8670 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8671 value, split16a_type);
8673 else if (r_type == R_PPC_VLE_SDAREL_LO16D)
8675 value = (value + addend) & 0xffff;
8676 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8677 value, split16d_type);
8679 else if (r_type == R_PPC_VLE_SDAREL_HI16A)
8681 value = ((value + addend) >> 16) & 0xffff;
8682 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8683 value, split16a_type);
8685 else if (r_type == R_PPC_VLE_SDAREL_HI16D)
8687 value = ((value + addend) >> 16) & 0xffff;
8688 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8689 value, split16d_type);
8691 else if (r_type == R_PPC_VLE_SDAREL_HA16A)
8694 value = (((value >> 16) + ((value & 0x8000) ? 1 : 0)) & 0xffff);
8695 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8696 value, split16a_type);
8698 else if (r_type == R_PPC_VLE_SDAREL_HA16D)
8701 value = (((value >> 16) + ((value & 0x8000) ? 1 : 0)) & 0xffff);
8702 ppc_elf_vle_split16 (output_bfd, contents, rel->r_offset,
8703 value, split16d_type);
8708 /* Relocate against the beginning of the section. */
8710 case R_PPC_SECTOFF_LO:
8711 case R_PPC_SECTOFF_HI:
8712 case R_PPC_SECTOFF_HA:
8713 if (sec == NULL || sec->output_section == NULL)
8715 unresolved_reloc = TRUE;
8718 addend -= sec->output_section->vma;
8721 /* Negative relocations. */
8722 case R_PPC_EMB_NADDR32:
8723 case R_PPC_EMB_NADDR16:
8724 case R_PPC_EMB_NADDR16_LO:
8725 case R_PPC_EMB_NADDR16_HI:
8726 case R_PPC_EMB_NADDR16_HA:
8727 addend -= 2 * relocation;
8731 case R_PPC_GLOB_DAT:
8732 case R_PPC_JMP_SLOT:
8733 case R_PPC_RELATIVE:
8734 case R_PPC_IRELATIVE:
8736 case R_PPC_PLTREL32:
8737 case R_PPC_PLT16_LO:
8738 case R_PPC_PLT16_HI:
8739 case R_PPC_PLT16_HA:
8741 case R_PPC_EMB_RELSEC16:
8742 case R_PPC_EMB_RELST_LO:
8743 case R_PPC_EMB_RELST_HI:
8744 case R_PPC_EMB_RELST_HA:
8745 case R_PPC_EMB_BIT_FLD:
8746 info->callbacks->einfo
8747 (_("%P: %B: relocation %s is not yet supported for symbol %s\n"),
8752 bfd_set_error (bfd_error_invalid_operation);
8757 /* Do any further special processing. */
8763 case R_PPC_ADDR16_HA:
8764 case R_PPC_REL16_HA:
8765 case R_PPC_SECTOFF_HA:
8766 case R_PPC_TPREL16_HA:
8767 case R_PPC_DTPREL16_HA:
8768 case R_PPC_EMB_NADDR16_HA:
8769 case R_PPC_EMB_RELST_HA:
8770 /* It's just possible that this symbol is a weak symbol
8771 that's not actually defined anywhere. In that case,
8772 'sec' would be NULL, and we should leave the symbol
8773 alone (it will be set to zero elsewhere in the link). */
8778 case R_PPC_PLT16_HA:
8779 case R_PPC_GOT16_HA:
8780 case R_PPC_GOT_TLSGD16_HA:
8781 case R_PPC_GOT_TLSLD16_HA:
8782 case R_PPC_GOT_TPREL16_HA:
8783 case R_PPC_GOT_DTPREL16_HA:
8784 /* Add 0x10000 if sign bit in 0:15 is set.
8785 Bits 0:15 are not used. */
8791 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
8792 "offset = %ld, addend = %ld\n",
8797 (long) rel->r_offset,
8801 if (unresolved_reloc
8802 && !((input_section->flags & SEC_DEBUGGING) != 0
8804 && _bfd_elf_section_offset (output_bfd, info, input_section,
8805 rel->r_offset) != (bfd_vma) -1)
8807 info->callbacks->einfo
8808 (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
8809 input_bfd, input_section, rel->r_offset,
8815 r = _bfd_final_link_relocate (howto,
8823 if (r != bfd_reloc_ok)
8825 if (r == bfd_reloc_overflow)
8830 && h->root.type == bfd_link_hash_undefweak
8831 && howto->pc_relative)
8833 /* Assume this is a call protected by other code that
8834 detect the symbol is undefined. If this is the case,
8835 we can safely ignore the overflow. If not, the
8836 program is hosed anyway, and a little warning isn't
8842 if (! (*info->callbacks->reloc_overflow) (info,
8843 (h ? &h->root : NULL),
8854 info->callbacks->einfo
8855 (_("%P: %H: %s reloc against `%s': error %d\n"),
8856 input_bfd, input_section, rel->r_offset,
8857 howto->name, sym_name, (int) r);
8864 fprintf (stderr, "\n");
8870 /* Finish up dynamic symbol handling. We set the contents of various
8871 dynamic sections here. */
8874 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
8875 struct bfd_link_info *info,
8876 struct elf_link_hash_entry *h,
8877 Elf_Internal_Sym *sym)
8879 struct ppc_elf_link_hash_table *htab;
8880 struct plt_entry *ent;
8881 bfd_boolean doneone;
8884 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
8885 h->root.root.string);
8888 htab = ppc_elf_hash_table (info);
8889 BFD_ASSERT (htab->elf.dynobj != NULL);
8892 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
8893 if (ent->plt.offset != (bfd_vma) -1)
8897 Elf_Internal_Rela rela;
8899 bfd_vma reloc_index;
8901 if (htab->plt_type == PLT_NEW
8902 || !htab->elf.dynamic_sections_created
8903 || h->dynindx == -1)
8904 reloc_index = ent->plt.offset / 4;
8907 reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
8908 / htab->plt_slot_size);
8909 if (reloc_index > PLT_NUM_SINGLE_ENTRIES
8910 && htab->plt_type == PLT_OLD)
8911 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
8914 /* This symbol has an entry in the procedure linkage table.
8916 if (htab->plt_type == PLT_VXWORKS
8917 && htab->elf.dynamic_sections_created
8918 && h->dynindx != -1)
8921 const bfd_vma *plt_entry;
8923 /* The first three entries in .got.plt are reserved. */
8924 got_offset = (reloc_index + 3) * 4;
8926 /* Use the right PLT. */
8927 plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
8928 : ppc_elf_vxworks_plt_entry;
8930 /* Fill in the .plt on VxWorks. */
8933 bfd_put_32 (output_bfd,
8934 plt_entry[0] | PPC_HA (got_offset),
8935 htab->plt->contents + ent->plt.offset + 0);
8936 bfd_put_32 (output_bfd,
8937 plt_entry[1] | PPC_LO (got_offset),
8938 htab->plt->contents + ent->plt.offset + 4);
8942 bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot);
8944 bfd_put_32 (output_bfd,
8945 plt_entry[0] | PPC_HA (got_loc),
8946 htab->plt->contents + ent->plt.offset + 0);
8947 bfd_put_32 (output_bfd,
8948 plt_entry[1] | PPC_LO (got_loc),
8949 htab->plt->contents + ent->plt.offset + 4);
8952 bfd_put_32 (output_bfd, plt_entry[2],
8953 htab->plt->contents + ent->plt.offset + 8);
8954 bfd_put_32 (output_bfd, plt_entry[3],
8955 htab->plt->contents + ent->plt.offset + 12);
8957 /* This instruction is an immediate load. The value loaded is
8958 the byte offset of the R_PPC_JMP_SLOT relocation from the
8959 start of the .rela.plt section. The value is stored in the
8960 low-order 16 bits of the load instruction. */
8961 /* NOTE: It appears that this is now an index rather than a
8962 prescaled offset. */
8963 bfd_put_32 (output_bfd,
8964 plt_entry[4] | reloc_index,
8965 htab->plt->contents + ent->plt.offset + 16);
8966 /* This instruction is a PC-relative branch whose target is
8967 the start of the PLT section. The address of this branch
8968 instruction is 20 bytes beyond the start of this PLT entry.
8969 The address is encoded in bits 6-29, inclusive. The value
8970 stored is right-shifted by two bits, permitting a 26-bit
8972 bfd_put_32 (output_bfd,
8974 | (-(ent->plt.offset + 20) & 0x03fffffc)),
8975 htab->plt->contents + ent->plt.offset + 20);
8976 bfd_put_32 (output_bfd, plt_entry[6],
8977 htab->plt->contents + ent->plt.offset + 24);
8978 bfd_put_32 (output_bfd, plt_entry[7],
8979 htab->plt->contents + ent->plt.offset + 28);
8981 /* Fill in the GOT entry corresponding to this PLT slot with
8982 the address immediately after the the "bctr" instruction
8983 in this PLT entry. */
8984 bfd_put_32 (output_bfd, (htab->plt->output_section->vma
8985 + htab->plt->output_offset
8986 + ent->plt.offset + 16),
8987 htab->sgotplt->contents + got_offset);
8991 /* Fill in a couple of entries in .rela.plt.unloaded. */
8992 loc = htab->srelplt2->contents
8993 + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
8994 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
8995 * sizeof (Elf32_External_Rela));
8997 /* Provide the @ha relocation for the first instruction. */
8998 rela.r_offset = (htab->plt->output_section->vma
8999 + htab->plt->output_offset
9000 + ent->plt.offset + 2);
9001 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
9003 rela.r_addend = got_offset;
9004 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9005 loc += sizeof (Elf32_External_Rela);
9007 /* Provide the @l relocation for the second instruction. */
9008 rela.r_offset = (htab->plt->output_section->vma
9009 + htab->plt->output_offset
9010 + ent->plt.offset + 6);
9011 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
9013 rela.r_addend = got_offset;
9014 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9015 loc += sizeof (Elf32_External_Rela);
9017 /* Provide a relocation for the GOT entry corresponding to this
9018 PLT slot. Point it at the middle of the .plt entry. */
9019 rela.r_offset = (htab->sgotplt->output_section->vma
9020 + htab->sgotplt->output_offset
9022 rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
9024 rela.r_addend = ent->plt.offset + 16;
9025 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9028 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
9029 In particular, the offset for the relocation is not the
9030 address of the PLT entry for this function, as specified
9031 by the ABI. Instead, the offset is set to the address of
9032 the GOT slot for this function. See EABI 4.4.4.1. */
9033 rela.r_offset = (htab->sgotplt->output_section->vma
9034 + htab->sgotplt->output_offset
9040 asection *splt = htab->plt;
9041 if (!htab->elf.dynamic_sections_created
9042 || h->dynindx == -1)
9045 rela.r_offset = (splt->output_section->vma
9046 + splt->output_offset
9048 if (htab->plt_type == PLT_OLD
9049 || !htab->elf.dynamic_sections_created
9050 || h->dynindx == -1)
9052 /* We don't need to fill in the .plt. The ppc dynamic
9053 linker will fill it in. */
9057 bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
9058 + htab->glink->output_section->vma
9059 + htab->glink->output_offset);
9060 bfd_put_32 (output_bfd, val,
9061 splt->contents + ent->plt.offset);
9065 /* Fill in the entry in the .rela.plt section. */
9067 if (!htab->elf.dynamic_sections_created
9068 || h->dynindx == -1)
9070 BFD_ASSERT (h->type == STT_GNU_IFUNC
9072 && (h->root.type == bfd_link_hash_defined
9073 || h->root.type == bfd_link_hash_defweak));
9074 rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
9075 rela.r_addend = SYM_VAL (h);
9078 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
9080 if (!htab->elf.dynamic_sections_created
9081 || h->dynindx == -1)
9082 loc = (htab->reliplt->contents
9083 + (htab->reliplt->reloc_count++
9084 * sizeof (Elf32_External_Rela)));
9086 loc = (htab->relplt->contents
9087 + reloc_index * sizeof (Elf32_External_Rela));
9088 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9090 if (!h->def_regular)
9092 /* Mark the symbol as undefined, rather than as
9093 defined in the .plt section. Leave the value if
9094 there were any relocations where pointer equality
9095 matters (this is a clue for the dynamic linker, to
9096 make function pointer comparisons work between an
9097 application and shared library), otherwise set it
9099 sym->st_shndx = SHN_UNDEF;
9100 if (!h->pointer_equality_needed)
9102 else if (!h->ref_regular_nonweak)
9104 /* This breaks function pointer comparisons, but
9105 that is better than breaking tests for a NULL
9106 function pointer. */
9110 else if (h->type == STT_GNU_IFUNC
9113 /* Set the value of ifunc symbols in a non-pie
9114 executable to the glink entry. This is to avoid
9115 text relocations. We can't do this for ifunc in
9116 allocate_dynrelocs, as we do for normal dynamic
9117 function symbols with plt entries, because we need
9118 to keep the original value around for the ifunc
9120 sym->st_shndx = (_bfd_elf_section_from_bfd_section
9121 (output_bfd, htab->glink->output_section));
9122 sym->st_value = (ent->glink_offset
9123 + htab->glink->output_offset
9124 + htab->glink->output_section->vma);
9129 if (htab->plt_type == PLT_NEW
9130 || !htab->elf.dynamic_sections_created
9131 || h->dynindx == -1)
9134 asection *splt = htab->plt;
9135 if (!htab->elf.dynamic_sections_created
9136 || h->dynindx == -1)
9139 p = (unsigned char *) htab->glink->contents + ent->glink_offset;
9141 if (h == htab->tls_get_addr && !htab->no_tls_get_addr_opt)
9143 bfd_put_32 (output_bfd, LWZ_11_3, p);
9145 bfd_put_32 (output_bfd, LWZ_12_3 + 4, p);
9147 bfd_put_32 (output_bfd, MR_0_3, p);
9149 bfd_put_32 (output_bfd, CMPWI_11_0, p);
9151 bfd_put_32 (output_bfd, ADD_3_12_2, p);
9153 bfd_put_32 (output_bfd, BEQLR, p);
9155 bfd_put_32 (output_bfd, MR_3_0, p);
9157 bfd_put_32 (output_bfd, NOP, p);
9161 write_glink_stub (ent, splt, p, info);
9164 /* We only need one non-PIC glink stub. */
9174 Elf_Internal_Rela rela;
9177 /* This symbols needs a copy reloc. Set it up. */
9180 fprintf (stderr, ", copy");
9183 BFD_ASSERT (h->dynindx != -1);
9185 if (ppc_elf_hash_entry (h)->has_sda_refs)
9189 BFD_ASSERT (s != NULL);
9191 rela.r_offset = SYM_VAL (h);
9192 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
9194 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
9195 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9199 fprintf (stderr, "\n");
9205 static enum elf_reloc_type_class
9206 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
9208 switch (ELF32_R_TYPE (rela->r_info))
9210 case R_PPC_RELATIVE:
9211 return reloc_class_relative;
9214 case R_PPC_JMP_SLOT:
9215 return reloc_class_plt;
9217 return reloc_class_copy;
9219 return reloc_class_normal;
9223 /* Finish up the dynamic sections. */
9226 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
9227 struct bfd_link_info *info)
9231 struct ppc_elf_link_hash_table *htab;
9234 bfd_boolean ret = TRUE;
9237 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
9240 htab = ppc_elf_hash_table (info);
9241 dynobj = elf_hash_table (info)->dynobj;
9242 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9243 if (htab->is_vxworks)
9244 splt = bfd_get_section_by_name (dynobj, ".plt");
9249 if (htab->elf.hgot != NULL)
9250 got = SYM_VAL (htab->elf.hgot);
9252 if (htab->elf.dynamic_sections_created)
9254 Elf32_External_Dyn *dyncon, *dynconend;
9256 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
9258 dyncon = (Elf32_External_Dyn *) sdyn->contents;
9259 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9260 for (; dyncon < dynconend; dyncon++)
9262 Elf_Internal_Dyn dyn;
9265 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9270 if (htab->is_vxworks)
9274 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9278 dyn.d_un.d_val = htab->relplt->size;
9283 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
9287 dyn.d_un.d_ptr = got;
9291 if (htab->is_vxworks)
9294 dyn.d_un.d_ptr -= htab->relplt->size;
9300 if (htab->is_vxworks
9301 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
9306 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9310 if (htab->got != NULL)
9312 if (htab->elf.hgot->root.u.def.section == htab->got
9313 || htab->elf.hgot->root.u.def.section == htab->sgotplt)
9315 unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
9317 p += htab->elf.hgot->root.u.def.value;
9318 if (htab->plt_type == PLT_OLD)
9320 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
9321 so that a function can easily find the address of
9322 _GLOBAL_OFFSET_TABLE_. */
9323 BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4
9324 < htab->elf.hgot->root.u.def.section->size);
9325 bfd_put_32 (output_bfd, 0x4e800021, p - 4);
9330 bfd_vma val = sdyn->output_section->vma + sdyn->output_offset;
9331 BFD_ASSERT (htab->elf.hgot->root.u.def.value
9332 < htab->elf.hgot->root.u.def.section->size);
9333 bfd_put_32 (output_bfd, val, p);
9338 info->callbacks->einfo (_("%P: %s not defined in linker created %s\n"),
9339 htab->elf.hgot->root.root.string,
9340 (htab->sgotplt != NULL
9341 ? htab->sgotplt->name : htab->got->name));
9342 bfd_set_error (bfd_error_bad_value);
9346 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
9349 /* Fill in the first entry in the VxWorks procedure linkage table. */
9350 if (splt && splt->size > 0)
9352 /* Use the right PLT. */
9353 const bfd_vma *plt_entry = (info->shared
9354 ? ppc_elf_vxworks_pic_plt0_entry
9355 : ppc_elf_vxworks_plt0_entry);
9359 bfd_vma got_value = SYM_VAL (htab->elf.hgot);
9361 bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value),
9362 splt->contents + 0);
9363 bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value),
9364 splt->contents + 4);
9368 bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0);
9369 bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4);
9371 bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8);
9372 bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
9373 bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
9374 bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
9375 bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
9376 bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
9380 Elf_Internal_Rela rela;
9383 loc = htab->srelplt2->contents;
9385 /* Output the @ha relocation for the first instruction. */
9386 rela.r_offset = (htab->plt->output_section->vma
9387 + htab->plt->output_offset
9389 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
9391 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9392 loc += sizeof (Elf32_External_Rela);
9394 /* Output the @l relocation for the second instruction. */
9395 rela.r_offset = (htab->plt->output_section->vma
9396 + htab->plt->output_offset
9398 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
9400 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
9401 loc += sizeof (Elf32_External_Rela);
9403 /* Fix up the remaining relocations. They may have the wrong
9404 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9405 in which symbols were output. */
9406 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
9408 Elf_Internal_Rela rel;
9410 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
9411 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
9412 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
9413 loc += sizeof (Elf32_External_Rela);
9415 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
9416 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
9417 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
9418 loc += sizeof (Elf32_External_Rela);
9420 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
9421 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
9422 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
9423 loc += sizeof (Elf32_External_Rela);
9428 if (htab->glink != NULL
9429 && htab->glink->contents != NULL
9430 && htab->elf.dynamic_sections_created)
9433 unsigned char *endp;
9438 * PIC glink code is the following:
9440 * # ith PLT code stub.
9441 * addis 11,30,(plt+(i-1)*4-got)@ha
9442 * lwz 11,(plt+(i-1)*4-got)@l(11)
9446 * # A table of branches, one for each plt entry.
9447 * # The idea is that the plt call stub loads ctr and r11 with these
9448 * # addresses, so (r11 - res_0) gives the plt index * 4.
9449 * res_0: b PLTresolve
9450 * res_1: b PLTresolve
9452 * # Some number of entries towards the end can be nops
9458 * addis 11,11,(1f-res_0)@ha
9461 * 1: addi 11,11,(1b-res_0)@l
9464 * sub 11,11,12 # r11 = index * 4
9465 * addis 12,12,(got+4-1b)@ha
9466 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
9467 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
9470 * add 11,0,11 # r11 = index * 12 = reloc offset.
9473 static const unsigned int pic_plt_resolve[] =
9494 * Non-PIC glink code is a little simpler.
9496 * # ith PLT code stub.
9497 * lis 11,(plt+(i-1)*4)@ha
9498 * lwz 11,(plt+(i-1)*4)@l(11)
9502 * The branch table is the same, then comes
9506 * addis 11,11,(-res_0)@ha
9507 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
9508 * addi 11,11,(-res_0)@l # r11 = index * 4
9511 * lwz 12,(got+8)@l(12) # got[2] contains the map address
9512 * add 11,0,11 # r11 = index * 12 = reloc offset.
9515 static const unsigned int plt_resolve[] =
9535 if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
9537 if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
9540 /* Build the branch table, one for each plt entry (less one),
9541 and perhaps some padding. */
9542 p = htab->glink->contents;
9543 p += htab->glink_pltresolve;
9544 endp = htab->glink->contents;
9545 endp += htab->glink->size - GLINK_PLTRESOLVE;
9546 while (p < endp - 8 * 4)
9548 bfd_put_32 (output_bfd, B + endp - p, p);
9553 bfd_put_32 (output_bfd, NOP, p);
9557 res0 = (htab->glink_pltresolve
9558 + htab->glink->output_section->vma
9559 + htab->glink->output_offset);
9561 /* Last comes the PLTresolve stub. */
9566 for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
9568 bfd_put_32 (output_bfd, pic_plt_resolve[i], p);
9571 p -= 4 * ARRAY_SIZE (pic_plt_resolve);
9573 bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
9574 + htab->glink->output_section->vma
9575 + htab->glink->output_offset);
9577 bfd_put_32 (output_bfd,
9578 ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
9579 bfd_put_32 (output_bfd,
9580 ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
9581 bfd_put_32 (output_bfd,
9582 ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
9583 if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
9585 bfd_put_32 (output_bfd,
9586 LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
9587 bfd_put_32 (output_bfd,
9588 LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
9592 bfd_put_32 (output_bfd,
9593 LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
9594 bfd_put_32 (output_bfd,
9595 LWZ_12_12 + 4, p + 9*4);
9600 for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
9602 bfd_put_32 (output_bfd, plt_resolve[i], p);
9605 p -= 4 * ARRAY_SIZE (plt_resolve);
9607 bfd_put_32 (output_bfd,
9608 LIS_12 + PPC_HA (got + 4), p + 0*4);
9609 bfd_put_32 (output_bfd,
9610 ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
9611 bfd_put_32 (output_bfd,
9612 ADDI_11_11 + PPC_LO (-res0), p + 3*4);
9613 if (PPC_HA (got + 4) == PPC_HA (got + 8))
9615 bfd_put_32 (output_bfd,
9616 LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
9617 bfd_put_32 (output_bfd,
9618 LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
9622 bfd_put_32 (output_bfd,
9623 LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
9624 bfd_put_32 (output_bfd,
9625 LWZ_12_12 + 4, p + 6*4);
9630 if (htab->glink_eh_frame != NULL
9631 && htab->glink_eh_frame->contents != NULL)
9633 unsigned char *p = htab->glink_eh_frame->contents;
9636 p += sizeof (glink_eh_frame_cie);
9641 /* Offset to .glink. */
9642 val = (htab->glink->output_section->vma
9643 + htab->glink->output_offset);
9644 val -= (htab->glink_eh_frame->output_section->vma
9645 + htab->glink_eh_frame->output_offset);
9646 val -= p - htab->glink_eh_frame->contents;
9647 bfd_put_32 (htab->elf.dynobj, val, p);
9649 if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
9650 && !_bfd_elf_write_section_eh_frame (output_bfd, info,
9651 htab->glink_eh_frame,
9652 htab->glink_eh_frame->contents))
9659 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
9660 #define TARGET_LITTLE_NAME "elf32-powerpcle"
9661 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
9662 #define TARGET_BIG_NAME "elf32-powerpc"
9663 #define ELF_ARCH bfd_arch_powerpc
9664 #define ELF_TARGET_ID PPC32_ELF_DATA
9665 #define ELF_MACHINE_CODE EM_PPC
9666 #ifdef __QNXTARGET__
9667 #define ELF_MAXPAGESIZE 0x1000
9669 #define ELF_MAXPAGESIZE 0x10000
9671 #define ELF_MINPAGESIZE 0x1000
9672 #define ELF_COMMONPAGESIZE 0x1000
9673 #define elf_info_to_howto ppc_elf_info_to_howto
9675 #ifdef EM_CYGNUS_POWERPC
9676 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
9680 #define ELF_MACHINE_ALT2 EM_PPC_OLD
9683 #define elf_backend_plt_not_loaded 1
9684 #define elf_backend_can_gc_sections 1
9685 #define elf_backend_can_refcount 1
9686 #define elf_backend_rela_normal 1
9688 #define bfd_elf32_mkobject ppc_elf_mkobject
9689 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
9690 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
9691 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
9692 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
9693 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
9694 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
9695 #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
9697 #define elf_backend_object_p ppc_elf_object_p
9698 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
9699 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
9700 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
9701 #define elf_backend_relocate_section ppc_elf_relocate_section
9702 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
9703 #define elf_backend_check_relocs ppc_elf_check_relocs
9704 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
9705 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
9706 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
9707 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
9708 #define elf_backend_hash_symbol ppc_elf_hash_symbol
9709 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
9710 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
9711 #define elf_backend_fake_sections ppc_elf_fake_sections
9712 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
9713 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
9714 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
9715 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
9716 #define elf_backend_write_core_note ppc_elf_write_core_note
9717 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
9718 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
9719 #define elf_backend_final_write_processing ppc_elf_final_write_processing
9720 #define elf_backend_write_section ppc_elf_write_section
9721 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
9722 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
9723 #define elf_backend_action_discarded ppc_elf_action_discarded
9724 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
9725 #define elf_backend_post_process_headers _bfd_elf_set_osabi
9726 #define elf_backend_lookup_section_flags_hook ppc_elf_lookup_section_flags
9727 #define elf_backend_section_processing ppc_elf_section_processing
9729 #include "elf32-target.h"
9731 /* FreeBSD Target */
9733 #undef TARGET_LITTLE_SYM
9734 #undef TARGET_LITTLE_NAME
9736 #undef TARGET_BIG_SYM
9737 #define TARGET_BIG_SYM bfd_elf32_powerpc_freebsd_vec
9738 #undef TARGET_BIG_NAME
9739 #define TARGET_BIG_NAME "elf32-powerpc-freebsd"
9742 #define ELF_OSABI ELFOSABI_FREEBSD
9745 #define elf32_bed elf32_powerpc_fbsd_bed
9747 #include "elf32-target.h"
9749 /* VxWorks Target */
9751 #undef TARGET_LITTLE_SYM
9752 #undef TARGET_LITTLE_NAME
9754 #undef TARGET_BIG_SYM
9755 #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
9756 #undef TARGET_BIG_NAME
9757 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
9761 /* VxWorks uses the elf default section flags for .plt. */
9762 static const struct bfd_elf_special_section *
9763 ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
9765 if (sec->name == NULL)
9768 if (strcmp (sec->name, ".plt") == 0)
9769 return _bfd_elf_get_sec_type_attr (abfd, sec);
9771 return ppc_elf_get_sec_type_attr (abfd, sec);
9774 /* Like ppc_elf_link_hash_table_create, but overrides
9775 appropriately for VxWorks. */
9776 static struct bfd_link_hash_table *
9777 ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
9779 struct bfd_link_hash_table *ret;
9781 ret = ppc_elf_link_hash_table_create (abfd);
9784 struct ppc_elf_link_hash_table *htab
9785 = (struct ppc_elf_link_hash_table *)ret;
9786 htab->is_vxworks = 1;
9787 htab->plt_type = PLT_VXWORKS;
9788 htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
9789 htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
9790 htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
9795 /* Tweak magic VxWorks symbols as they are loaded. */
9797 ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
9798 struct bfd_link_info *info,
9799 Elf_Internal_Sym *sym,
9800 const char **namep ATTRIBUTE_UNUSED,
9801 flagword *flagsp ATTRIBUTE_UNUSED,
9805 if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
9809 return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
9813 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
9815 ppc_elf_final_write_processing(abfd, linker);
9816 elf_vxworks_final_write_processing(abfd, linker);
9819 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
9821 #undef elf_backend_want_plt_sym
9822 #define elf_backend_want_plt_sym 1
9823 #undef elf_backend_want_got_plt
9824 #define elf_backend_want_got_plt 1
9825 #undef elf_backend_got_symbol_offset
9826 #define elf_backend_got_symbol_offset 0
9827 #undef elf_backend_plt_not_loaded
9828 #define elf_backend_plt_not_loaded 0
9829 #undef elf_backend_plt_readonly
9830 #define elf_backend_plt_readonly 1
9831 #undef elf_backend_got_header_size
9832 #define elf_backend_got_header_size 12
9834 #undef bfd_elf32_get_synthetic_symtab
9836 #undef bfd_elf32_bfd_link_hash_table_create
9837 #define bfd_elf32_bfd_link_hash_table_create \
9838 ppc_elf_vxworks_link_hash_table_create
9839 #undef elf_backend_add_symbol_hook
9840 #define elf_backend_add_symbol_hook \
9841 ppc_elf_vxworks_add_symbol_hook
9842 #undef elf_backend_link_output_symbol_hook
9843 #define elf_backend_link_output_symbol_hook \
9844 elf_vxworks_link_output_symbol_hook
9845 #undef elf_backend_final_write_processing
9846 #define elf_backend_final_write_processing \
9847 ppc_elf_vxworks_final_write_processing
9848 #undef elf_backend_get_sec_type_attr
9849 #define elf_backend_get_sec_type_attr \
9850 ppc_elf_vxworks_get_sec_type_attr
9851 #undef elf_backend_emit_relocs
9852 #define elf_backend_emit_relocs \
9853 elf_vxworks_emit_relocs
9856 #define elf32_bed ppc_elf_vxworks_bed
9857 #undef elf_backend_post_process_headers
9859 #include "elf32-target.h"