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 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* This file is based on a preliminary PowerPC ELF ABI. The
24 information may not match the final PowerPC ELF ABI. It includes
25 suggestions from the in-progress Embedded PowerPC ABI, and that
26 information may also not match. */
35 #include "elf32-ppc.h"
36 #include "elf-vxworks.h"
38 /* RELA relocations are used here. */
40 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
42 static bfd_reloc_status_type ppc_elf_unhandled_reloc
43 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
45 /* Branch prediction bit for branch taken relocs. */
46 #define BRANCH_PREDICT_BIT 0x200000
47 /* Mask to set RA in memory instructions. */
48 #define RA_REGISTER_MASK 0x001f0000
49 /* Value to shift register by to insert RA. */
50 #define RA_REGISTER_SHIFT 16
52 /* The name of the dynamic interpreter. This is put in the .interp
54 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
56 /* For old-style PLT. */
57 /* The number of single-slot PLT entries (the rest use two slots). */
58 #define PLT_NUM_SINGLE_ENTRIES 8192
60 /* For new-style .glink and .plt. */
61 #define GLINK_PLTRESOLVE 16*4
62 #define GLINK_ENTRY_SIZE 4*4
64 /* VxWorks uses its own plt layout, filled in by the static linker. */
66 /* The standard VxWorks PLT entry. */
67 #define VXWORKS_PLT_ENTRY_SIZE 32
68 static const bfd_vma ppc_elf_vxworks_plt_entry
69 [VXWORKS_PLT_ENTRY_SIZE / 4] =
71 0x3d800000, /* lis r12,0 */
72 0x818c0000, /* lwz r12,0(r12) */
73 0x7d8903a6, /* mtctr r12 */
74 0x4e800420, /* bctr */
75 0x39600000, /* li r11,0 */
76 0x48000000, /* b 14 <.PLT0resolve+0x4> */
80 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
81 [VXWORKS_PLT_ENTRY_SIZE / 4] =
83 0x3d9e0000, /* addis r12,r30,0 */
84 0x818c0000, /* lwz r12,0(r12) */
85 0x7d8903a6, /* mtctr r12 */
86 0x4e800420, /* bctr */
87 0x39600000, /* li r11,0 */
88 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
93 /* The initial VxWorks PLT entry. */
94 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
95 static const bfd_vma ppc_elf_vxworks_plt0_entry
96 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
98 0x3d800000, /* lis r12,0 */
99 0x398c0000, /* addi r12,r12,0 */
100 0x800c0008, /* lwz r0,8(r12) */
101 0x7c0903a6, /* mtctr r0 */
102 0x818c0004, /* lwz r12,4(r12) */
103 0x4e800420, /* bctr */
104 0x60000000, /* nop */
105 0x60000000, /* nop */
107 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
108 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
110 0x819e0008, /* lwz r12,8(r30) */
111 0x7d8903a6, /* mtctr r12 */
112 0x819e0004, /* lwz r12,4(r30) */
113 0x4e800420, /* bctr */
114 0x60000000, /* nop */
115 0x60000000, /* nop */
116 0x60000000, /* nop */
117 0x60000000, /* nop */
120 /* For executables, we have some additional relocations in
121 .rela.plt.unloaded, for the kernel loader. */
123 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
124 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
125 /* The number of relocations in the PLTResolve slot. */
126 #define VXWORKS_PLTRESOLVE_RELOCS 2
127 /* The number of relocations in the PLTResolve slot when when creating
129 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
131 /* Some instructions. */
132 #define ADDIS_11_11 0x3d6b0000
133 #define ADDIS_11_30 0x3d7e0000
134 #define ADDIS_12_12 0x3d8c0000
135 #define ADDI_11_11 0x396b0000
136 #define ADD_0_11_11 0x7c0b5a14
137 #define ADD_11_0_11 0x7d605a14
139 #define BCL_20_31 0x429f0005
140 #define BCTR 0x4e800420
141 #define LIS_11 0x3d600000
142 #define LIS_12 0x3d800000
143 #define LWZU_0_12 0x840c0000
144 #define LWZ_0_12 0x800c0000
145 #define LWZ_11_11 0x816b0000
146 #define LWZ_11_30 0x817e0000
147 #define LWZ_12_12 0x818c0000
148 #define MFLR_0 0x7c0802a6
149 #define MFLR_12 0x7d8802a6
150 #define MTCTR_0 0x7c0903a6
151 #define MTCTR_11 0x7d6903a6
152 #define MTLR_0 0x7c0803a6
153 #define NOP 0x60000000
154 #define SUB_11_11_12 0x7d6c5850
156 /* Offset of tp and dtp pointers from start of TLS block. */
157 #define TP_OFFSET 0x7000
158 #define DTP_OFFSET 0x8000
160 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
162 static reloc_howto_type ppc_elf_howto_raw[] = {
163 /* This reloc does nothing. */
164 HOWTO (R_PPC_NONE, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 FALSE, /* pc_relative */
170 complain_overflow_bitfield, /* complain_on_overflow */
171 bfd_elf_generic_reloc, /* special_function */
172 "R_PPC_NONE", /* name */
173 FALSE, /* partial_inplace */
176 FALSE), /* pcrel_offset */
178 /* A standard 32 bit relocation. */
179 HOWTO (R_PPC_ADDR32, /* type */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE, /* pc_relative */
185 complain_overflow_bitfield, /* complain_on_overflow */
186 bfd_elf_generic_reloc, /* special_function */
187 "R_PPC_ADDR32", /* name */
188 FALSE, /* partial_inplace */
190 0xffffffff, /* dst_mask */
191 FALSE), /* pcrel_offset */
193 /* An absolute 26 bit branch; the lower two bits must be zero.
194 FIXME: we don't check that, we just clear them. */
195 HOWTO (R_PPC_ADDR24, /* type */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
199 FALSE, /* pc_relative */
201 complain_overflow_bitfield, /* complain_on_overflow */
202 bfd_elf_generic_reloc, /* special_function */
203 "R_PPC_ADDR24", /* name */
204 FALSE, /* partial_inplace */
206 0x3fffffc, /* dst_mask */
207 FALSE), /* pcrel_offset */
209 /* A standard 16 bit relocation. */
210 HOWTO (R_PPC_ADDR16, /* type */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE, /* pc_relative */
216 complain_overflow_bitfield, /* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_PPC_ADDR16", /* name */
219 FALSE, /* partial_inplace */
221 0xffff, /* dst_mask */
222 FALSE), /* pcrel_offset */
224 /* A 16 bit relocation without overflow. */
225 HOWTO (R_PPC_ADDR16_LO, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 FALSE, /* pc_relative */
231 complain_overflow_dont,/* complain_on_overflow */
232 bfd_elf_generic_reloc, /* special_function */
233 "R_PPC_ADDR16_LO", /* name */
234 FALSE, /* partial_inplace */
236 0xffff, /* dst_mask */
237 FALSE), /* pcrel_offset */
239 /* The high order 16 bits of an address. */
240 HOWTO (R_PPC_ADDR16_HI, /* type */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
244 FALSE, /* pc_relative */
246 complain_overflow_dont, /* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_PPC_ADDR16_HI", /* name */
249 FALSE, /* partial_inplace */
251 0xffff, /* dst_mask */
252 FALSE), /* pcrel_offset */
254 /* The high order 16 bits of an address, plus 1 if the contents of
255 the low 16 bits, treated as a signed number, is negative. */
256 HOWTO (R_PPC_ADDR16_HA, /* type */
258 1, /* size (0 = byte, 1 = short, 2 = long) */
260 FALSE, /* pc_relative */
262 complain_overflow_dont, /* complain_on_overflow */
263 ppc_elf_addr16_ha_reloc, /* special_function */
264 "R_PPC_ADDR16_HA", /* name */
265 FALSE, /* partial_inplace */
267 0xffff, /* dst_mask */
268 FALSE), /* pcrel_offset */
270 /* An absolute 16 bit branch; the lower two bits must be zero.
271 FIXME: we don't check that, we just clear them. */
272 HOWTO (R_PPC_ADDR14, /* type */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
276 FALSE, /* pc_relative */
278 complain_overflow_bitfield, /* complain_on_overflow */
279 bfd_elf_generic_reloc, /* special_function */
280 "R_PPC_ADDR14", /* name */
281 FALSE, /* partial_inplace */
283 0xfffc, /* dst_mask */
284 FALSE), /* pcrel_offset */
286 /* An absolute 16 bit branch, for which bit 10 should be set to
287 indicate that the branch is expected to be taken. The lower two
288 bits must be zero. */
289 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE, /* pc_relative */
295 complain_overflow_bitfield, /* complain_on_overflow */
296 bfd_elf_generic_reloc, /* special_function */
297 "R_PPC_ADDR14_BRTAKEN",/* name */
298 FALSE, /* partial_inplace */
300 0xfffc, /* dst_mask */
301 FALSE), /* pcrel_offset */
303 /* An absolute 16 bit branch, for which bit 10 should be set to
304 indicate that the branch is not expected to be taken. The lower
305 two bits must be zero. */
306 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE, /* pc_relative */
312 complain_overflow_bitfield, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_PPC_ADDR14_BRNTAKEN",/* name */
315 FALSE, /* partial_inplace */
317 0xfffc, /* dst_mask */
318 FALSE), /* pcrel_offset */
320 /* A relative 26 bit branch; the lower two bits must be zero. */
321 HOWTO (R_PPC_REL24, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 TRUE, /* pc_relative */
327 complain_overflow_signed, /* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_PPC_REL24", /* name */
330 FALSE, /* partial_inplace */
332 0x3fffffc, /* dst_mask */
333 TRUE), /* pcrel_offset */
335 /* A relative 16 bit branch; the lower two bits must be zero. */
336 HOWTO (R_PPC_REL14, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 TRUE, /* pc_relative */
342 complain_overflow_signed, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_PPC_REL14", /* name */
345 FALSE, /* partial_inplace */
347 0xfffc, /* dst_mask */
348 TRUE), /* pcrel_offset */
350 /* A relative 16 bit branch. Bit 10 should be set to indicate that
351 the branch is expected to be taken. The lower two bits must be
353 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 TRUE, /* pc_relative */
359 complain_overflow_signed, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_PPC_REL14_BRTAKEN", /* name */
362 FALSE, /* partial_inplace */
364 0xfffc, /* dst_mask */
365 TRUE), /* pcrel_offset */
367 /* A relative 16 bit branch. Bit 10 should be set to indicate that
368 the branch is not expected to be taken. The lower two bits must
370 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 TRUE, /* pc_relative */
376 complain_overflow_signed, /* complain_on_overflow */
377 bfd_elf_generic_reloc, /* special_function */
378 "R_PPC_REL14_BRNTAKEN",/* name */
379 FALSE, /* partial_inplace */
381 0xfffc, /* dst_mask */
382 TRUE), /* pcrel_offset */
384 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
386 HOWTO (R_PPC_GOT16, /* type */
388 1, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_signed, /* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_PPC_GOT16", /* name */
395 FALSE, /* partial_inplace */
397 0xffff, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
402 HOWTO (R_PPC_GOT16_LO, /* type */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE, /* pc_relative */
408 complain_overflow_dont, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_PPC_GOT16_LO", /* name */
411 FALSE, /* partial_inplace */
413 0xffff, /* dst_mask */
414 FALSE), /* pcrel_offset */
416 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
418 HOWTO (R_PPC_GOT16_HI, /* type */
420 1, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE, /* pc_relative */
424 complain_overflow_bitfield, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* special_function */
426 "R_PPC_GOT16_HI", /* name */
427 FALSE, /* partial_inplace */
429 0xffff, /* dst_mask */
430 FALSE), /* pcrel_offset */
432 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
434 HOWTO (R_PPC_GOT16_HA, /* type */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE, /* pc_relative */
440 complain_overflow_bitfield, /* complain_on_overflow */
441 ppc_elf_addr16_ha_reloc, /* special_function */
442 "R_PPC_GOT16_HA", /* name */
443 FALSE, /* partial_inplace */
445 0xffff, /* dst_mask */
446 FALSE), /* pcrel_offset */
448 /* Like R_PPC_REL24, but referring to the procedure linkage table
449 entry for the symbol. */
450 HOWTO (R_PPC_PLTREL24, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE, /* pc_relative */
456 complain_overflow_signed, /* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 "R_PPC_PLTREL24", /* name */
459 FALSE, /* partial_inplace */
461 0x3fffffc, /* dst_mask */
462 TRUE), /* pcrel_offset */
464 /* This is used only by the dynamic linker. The symbol should exist
465 both in the object being run and in some shared library. The
466 dynamic linker copies the data addressed by the symbol from the
467 shared library into the object, because the object being
468 run has to have the data at some particular address. */
469 HOWTO (R_PPC_COPY, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 FALSE, /* pc_relative */
475 complain_overflow_bitfield, /* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 "R_PPC_COPY", /* name */
478 FALSE, /* partial_inplace */
481 FALSE), /* pcrel_offset */
483 /* Like R_PPC_ADDR32, but used when setting global offset table
485 HOWTO (R_PPC_GLOB_DAT, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE, /* pc_relative */
491 complain_overflow_bitfield, /* complain_on_overflow */
492 bfd_elf_generic_reloc, /* special_function */
493 "R_PPC_GLOB_DAT", /* name */
494 FALSE, /* partial_inplace */
496 0xffffffff, /* dst_mask */
497 FALSE), /* pcrel_offset */
499 /* Marks a procedure linkage table entry for a symbol. */
500 HOWTO (R_PPC_JMP_SLOT, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE, /* pc_relative */
506 complain_overflow_bitfield, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_PPC_JMP_SLOT", /* name */
509 FALSE, /* partial_inplace */
512 FALSE), /* pcrel_offset */
514 /* Used only by the dynamic linker. When the object is run, this
515 longword is set to the load address of the object, plus the
517 HOWTO (R_PPC_RELATIVE, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 FALSE, /* pc_relative */
523 complain_overflow_bitfield, /* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_PPC_RELATIVE", /* name */
526 FALSE, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 FALSE), /* pcrel_offset */
531 /* Like R_PPC_REL24, but uses the value of the symbol within the
532 object rather than the final value. Normally used for
533 _GLOBAL_OFFSET_TABLE_. */
534 HOWTO (R_PPC_LOCAL24PC, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 TRUE, /* pc_relative */
540 complain_overflow_signed, /* complain_on_overflow */
541 bfd_elf_generic_reloc, /* special_function */
542 "R_PPC_LOCAL24PC", /* name */
543 FALSE, /* partial_inplace */
545 0x3fffffc, /* dst_mask */
546 TRUE), /* pcrel_offset */
548 /* Like R_PPC_ADDR32, but may be unaligned. */
549 HOWTO (R_PPC_UADDR32, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 FALSE, /* pc_relative */
555 complain_overflow_bitfield, /* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 "R_PPC_UADDR32", /* name */
558 FALSE, /* partial_inplace */
560 0xffffffff, /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* Like R_PPC_ADDR16, but may be unaligned. */
564 HOWTO (R_PPC_UADDR16, /* type */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE, /* pc_relative */
570 complain_overflow_bitfield, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 "R_PPC_UADDR16", /* name */
573 FALSE, /* partial_inplace */
575 0xffff, /* dst_mask */
576 FALSE), /* pcrel_offset */
578 /* 32-bit PC relative */
579 HOWTO (R_PPC_REL32, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 TRUE, /* pc_relative */
585 complain_overflow_bitfield, /* complain_on_overflow */
586 bfd_elf_generic_reloc, /* special_function */
587 "R_PPC_REL32", /* name */
588 FALSE, /* partial_inplace */
590 0xffffffff, /* dst_mask */
591 TRUE), /* pcrel_offset */
593 /* 32-bit relocation to the symbol's procedure linkage table.
594 FIXME: not supported. */
595 HOWTO (R_PPC_PLT32, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 FALSE, /* pc_relative */
601 complain_overflow_bitfield, /* complain_on_overflow */
602 bfd_elf_generic_reloc, /* special_function */
603 "R_PPC_PLT32", /* name */
604 FALSE, /* partial_inplace */
607 FALSE), /* pcrel_offset */
609 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
610 FIXME: not supported. */
611 HOWTO (R_PPC_PLTREL32, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 TRUE, /* pc_relative */
617 complain_overflow_bitfield, /* complain_on_overflow */
618 bfd_elf_generic_reloc, /* special_function */
619 "R_PPC_PLTREL32", /* name */
620 FALSE, /* partial_inplace */
623 TRUE), /* pcrel_offset */
625 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
627 HOWTO (R_PPC_PLT16_LO, /* type */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
631 FALSE, /* pc_relative */
633 complain_overflow_dont, /* complain_on_overflow */
634 bfd_elf_generic_reloc, /* special_function */
635 "R_PPC_PLT16_LO", /* name */
636 FALSE, /* partial_inplace */
638 0xffff, /* dst_mask */
639 FALSE), /* pcrel_offset */
641 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
643 HOWTO (R_PPC_PLT16_HI, /* type */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE, /* pc_relative */
649 complain_overflow_bitfield, /* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_PPC_PLT16_HI", /* name */
652 FALSE, /* partial_inplace */
654 0xffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
659 HOWTO (R_PPC_PLT16_HA, /* type */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
663 FALSE, /* pc_relative */
665 complain_overflow_bitfield, /* complain_on_overflow */
666 ppc_elf_addr16_ha_reloc, /* special_function */
667 "R_PPC_PLT16_HA", /* name */
668 FALSE, /* partial_inplace */
670 0xffff, /* dst_mask */
671 FALSE), /* pcrel_offset */
673 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
675 HOWTO (R_PPC_SDAREL16, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE, /* pc_relative */
681 complain_overflow_signed, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_PPC_SDAREL16", /* name */
684 FALSE, /* partial_inplace */
686 0xffff, /* dst_mask */
687 FALSE), /* pcrel_offset */
689 /* 16-bit section relative relocation. */
690 HOWTO (R_PPC_SECTOFF, /* type */
692 1, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE, /* pc_relative */
696 complain_overflow_bitfield, /* complain_on_overflow */
697 bfd_elf_generic_reloc, /* special_function */
698 "R_PPC_SECTOFF", /* name */
699 FALSE, /* partial_inplace */
701 0xffff, /* dst_mask */
702 FALSE), /* pcrel_offset */
704 /* 16-bit lower half section relative relocation. */
705 HOWTO (R_PPC_SECTOFF_LO, /* type */
707 1, /* size (0 = byte, 1 = short, 2 = long) */
709 FALSE, /* pc_relative */
711 complain_overflow_dont, /* complain_on_overflow */
712 bfd_elf_generic_reloc, /* special_function */
713 "R_PPC_SECTOFF_LO", /* name */
714 FALSE, /* partial_inplace */
716 0xffff, /* dst_mask */
717 FALSE), /* pcrel_offset */
719 /* 16-bit upper half section relative relocation. */
720 HOWTO (R_PPC_SECTOFF_HI, /* type */
722 1, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE, /* pc_relative */
726 complain_overflow_bitfield, /* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_PPC_SECTOFF_HI", /* name */
729 FALSE, /* partial_inplace */
731 0xffff, /* dst_mask */
732 FALSE), /* pcrel_offset */
734 /* 16-bit upper half adjusted section relative relocation. */
735 HOWTO (R_PPC_SECTOFF_HA, /* type */
737 1, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE, /* pc_relative */
741 complain_overflow_bitfield, /* complain_on_overflow */
742 ppc_elf_addr16_ha_reloc, /* special_function */
743 "R_PPC_SECTOFF_HA", /* name */
744 FALSE, /* partial_inplace */
746 0xffff, /* dst_mask */
747 FALSE), /* pcrel_offset */
749 /* Marker relocs for TLS. */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE, /* pc_relative */
756 complain_overflow_dont, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_PPC_TLS", /* name */
759 FALSE, /* partial_inplace */
762 FALSE), /* pcrel_offset */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE, /* pc_relative */
770 complain_overflow_dont, /* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 "R_PPC_TLSGD", /* name */
773 FALSE, /* partial_inplace */
776 FALSE), /* pcrel_offset */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE, /* pc_relative */
784 complain_overflow_dont, /* complain_on_overflow */
785 bfd_elf_generic_reloc, /* special_function */
786 "R_PPC_TLSLD", /* name */
787 FALSE, /* partial_inplace */
790 FALSE), /* pcrel_offset */
792 /* Computes the load module index of the load module that contains the
793 definition of its TLS sym. */
794 HOWTO (R_PPC_DTPMOD32,
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE, /* pc_relative */
800 complain_overflow_dont, /* complain_on_overflow */
801 ppc_elf_unhandled_reloc, /* special_function */
802 "R_PPC_DTPMOD32", /* name */
803 FALSE, /* partial_inplace */
805 0xffffffff, /* dst_mask */
806 FALSE), /* pcrel_offset */
808 /* Computes a dtv-relative displacement, the difference between the value
809 of sym+add and the base address of the thread-local storage block that
810 contains the definition of sym, minus 0x8000. */
811 HOWTO (R_PPC_DTPREL32,
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE, /* pc_relative */
817 complain_overflow_dont, /* complain_on_overflow */
818 ppc_elf_unhandled_reloc, /* special_function */
819 "R_PPC_DTPREL32", /* name */
820 FALSE, /* partial_inplace */
822 0xffffffff, /* dst_mask */
823 FALSE), /* pcrel_offset */
825 /* A 16 bit dtprel reloc. */
826 HOWTO (R_PPC_DTPREL16,
828 1, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE, /* pc_relative */
832 complain_overflow_signed, /* complain_on_overflow */
833 ppc_elf_unhandled_reloc, /* special_function */
834 "R_PPC_DTPREL16", /* name */
835 FALSE, /* partial_inplace */
837 0xffff, /* dst_mask */
838 FALSE), /* pcrel_offset */
840 /* Like DTPREL16, but no overflow. */
841 HOWTO (R_PPC_DTPREL16_LO,
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE, /* pc_relative */
847 complain_overflow_dont, /* complain_on_overflow */
848 ppc_elf_unhandled_reloc, /* special_function */
849 "R_PPC_DTPREL16_LO", /* name */
850 FALSE, /* partial_inplace */
852 0xffff, /* dst_mask */
853 FALSE), /* pcrel_offset */
855 /* Like DTPREL16_LO, but next higher group of 16 bits. */
856 HOWTO (R_PPC_DTPREL16_HI,
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE, /* pc_relative */
862 complain_overflow_dont, /* complain_on_overflow */
863 ppc_elf_unhandled_reloc, /* special_function */
864 "R_PPC_DTPREL16_HI", /* name */
865 FALSE, /* partial_inplace */
867 0xffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 /* Like DTPREL16_HI, but adjust for low 16 bits. */
871 HOWTO (R_PPC_DTPREL16_HA,
873 1, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_dont, /* complain_on_overflow */
878 ppc_elf_unhandled_reloc, /* special_function */
879 "R_PPC_DTPREL16_HA", /* name */
880 FALSE, /* partial_inplace */
882 0xffff, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* Computes a tp-relative displacement, the difference between the value of
886 sym+add and the value of the thread pointer (r13). */
887 HOWTO (R_PPC_TPREL32,
889 2, /* size (0 = byte, 1 = short, 2 = long) */
891 FALSE, /* pc_relative */
893 complain_overflow_dont, /* complain_on_overflow */
894 ppc_elf_unhandled_reloc, /* special_function */
895 "R_PPC_TPREL32", /* name */
896 FALSE, /* partial_inplace */
898 0xffffffff, /* dst_mask */
899 FALSE), /* pcrel_offset */
901 /* A 16 bit tprel reloc. */
902 HOWTO (R_PPC_TPREL16,
904 1, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE, /* pc_relative */
908 complain_overflow_signed, /* complain_on_overflow */
909 ppc_elf_unhandled_reloc, /* special_function */
910 "R_PPC_TPREL16", /* name */
911 FALSE, /* partial_inplace */
913 0xffff, /* dst_mask */
914 FALSE), /* pcrel_offset */
916 /* Like TPREL16, but no overflow. */
917 HOWTO (R_PPC_TPREL16_LO,
919 1, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE, /* pc_relative */
923 complain_overflow_dont, /* complain_on_overflow */
924 ppc_elf_unhandled_reloc, /* special_function */
925 "R_PPC_TPREL16_LO", /* name */
926 FALSE, /* partial_inplace */
928 0xffff, /* dst_mask */
929 FALSE), /* pcrel_offset */
931 /* Like TPREL16_LO, but next higher group of 16 bits. */
932 HOWTO (R_PPC_TPREL16_HI,
934 1, /* size (0 = byte, 1 = short, 2 = long) */
936 FALSE, /* pc_relative */
938 complain_overflow_dont, /* complain_on_overflow */
939 ppc_elf_unhandled_reloc, /* special_function */
940 "R_PPC_TPREL16_HI", /* name */
941 FALSE, /* partial_inplace */
943 0xffff, /* dst_mask */
944 FALSE), /* pcrel_offset */
946 /* Like TPREL16_HI, but adjust for low 16 bits. */
947 HOWTO (R_PPC_TPREL16_HA,
949 1, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE, /* pc_relative */
953 complain_overflow_dont, /* complain_on_overflow */
954 ppc_elf_unhandled_reloc, /* special_function */
955 "R_PPC_TPREL16_HA", /* name */
956 FALSE, /* partial_inplace */
958 0xffff, /* dst_mask */
959 FALSE), /* pcrel_offset */
961 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
962 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
963 to the first entry. */
964 HOWTO (R_PPC_GOT_TLSGD16,
966 1, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE, /* pc_relative */
970 complain_overflow_signed, /* complain_on_overflow */
971 ppc_elf_unhandled_reloc, /* special_function */
972 "R_PPC_GOT_TLSGD16", /* name */
973 FALSE, /* partial_inplace */
975 0xffff, /* dst_mask */
976 FALSE), /* pcrel_offset */
978 /* Like GOT_TLSGD16, but no overflow. */
979 HOWTO (R_PPC_GOT_TLSGD16_LO,
981 1, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE, /* pc_relative */
985 complain_overflow_dont, /* complain_on_overflow */
986 ppc_elf_unhandled_reloc, /* special_function */
987 "R_PPC_GOT_TLSGD16_LO", /* name */
988 FALSE, /* partial_inplace */
990 0xffff, /* dst_mask */
991 FALSE), /* pcrel_offset */
993 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
994 HOWTO (R_PPC_GOT_TLSGD16_HI,
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE, /* pc_relative */
1000 complain_overflow_dont, /* complain_on_overflow */
1001 ppc_elf_unhandled_reloc, /* special_function */
1002 "R_PPC_GOT_TLSGD16_HI", /* name */
1003 FALSE, /* partial_inplace */
1005 0xffff, /* dst_mask */
1006 FALSE), /* pcrel_offset */
1008 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1009 HOWTO (R_PPC_GOT_TLSGD16_HA,
1010 16, /* rightshift */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE, /* pc_relative */
1015 complain_overflow_dont, /* complain_on_overflow */
1016 ppc_elf_unhandled_reloc, /* special_function */
1017 "R_PPC_GOT_TLSGD16_HA", /* name */
1018 FALSE, /* partial_inplace */
1020 0xffff, /* dst_mask */
1021 FALSE), /* pcrel_offset */
1023 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1024 with values (sym+add)@dtpmod and zero, and computes the offset to the
1026 HOWTO (R_PPC_GOT_TLSLD16,
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE, /* pc_relative */
1032 complain_overflow_signed, /* complain_on_overflow */
1033 ppc_elf_unhandled_reloc, /* special_function */
1034 "R_PPC_GOT_TLSLD16", /* name */
1035 FALSE, /* partial_inplace */
1037 0xffff, /* dst_mask */
1038 FALSE), /* pcrel_offset */
1040 /* Like GOT_TLSLD16, but no overflow. */
1041 HOWTO (R_PPC_GOT_TLSLD16_LO,
1043 1, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE, /* pc_relative */
1047 complain_overflow_dont, /* complain_on_overflow */
1048 ppc_elf_unhandled_reloc, /* special_function */
1049 "R_PPC_GOT_TLSLD16_LO", /* name */
1050 FALSE, /* partial_inplace */
1052 0xffff, /* dst_mask */
1053 FALSE), /* pcrel_offset */
1055 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1056 HOWTO (R_PPC_GOT_TLSLD16_HI,
1057 16, /* rightshift */
1058 1, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE, /* pc_relative */
1062 complain_overflow_dont, /* complain_on_overflow */
1063 ppc_elf_unhandled_reloc, /* special_function */
1064 "R_PPC_GOT_TLSLD16_HI", /* name */
1065 FALSE, /* partial_inplace */
1067 0xffff, /* dst_mask */
1068 FALSE), /* pcrel_offset */
1070 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1071 HOWTO (R_PPC_GOT_TLSLD16_HA,
1072 16, /* rightshift */
1073 1, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE, /* pc_relative */
1077 complain_overflow_dont, /* complain_on_overflow */
1078 ppc_elf_unhandled_reloc, /* special_function */
1079 "R_PPC_GOT_TLSLD16_HA", /* name */
1080 FALSE, /* partial_inplace */
1082 0xffff, /* dst_mask */
1083 FALSE), /* pcrel_offset */
1085 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1086 the offset to the entry. */
1087 HOWTO (R_PPC_GOT_DTPREL16,
1089 1, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE, /* pc_relative */
1093 complain_overflow_signed, /* complain_on_overflow */
1094 ppc_elf_unhandled_reloc, /* special_function */
1095 "R_PPC_GOT_DTPREL16", /* name */
1096 FALSE, /* partial_inplace */
1098 0xffff, /* dst_mask */
1099 FALSE), /* pcrel_offset */
1101 /* Like GOT_DTPREL16, but no overflow. */
1102 HOWTO (R_PPC_GOT_DTPREL16_LO,
1104 1, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE, /* pc_relative */
1108 complain_overflow_dont, /* complain_on_overflow */
1109 ppc_elf_unhandled_reloc, /* special_function */
1110 "R_PPC_GOT_DTPREL16_LO", /* name */
1111 FALSE, /* partial_inplace */
1113 0xffff, /* dst_mask */
1114 FALSE), /* pcrel_offset */
1116 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1117 HOWTO (R_PPC_GOT_DTPREL16_HI,
1118 16, /* rightshift */
1119 1, /* size (0 = byte, 1 = short, 2 = long) */
1121 FALSE, /* pc_relative */
1123 complain_overflow_dont, /* complain_on_overflow */
1124 ppc_elf_unhandled_reloc, /* special_function */
1125 "R_PPC_GOT_DTPREL16_HI", /* name */
1126 FALSE, /* partial_inplace */
1128 0xffff, /* dst_mask */
1129 FALSE), /* pcrel_offset */
1131 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1132 HOWTO (R_PPC_GOT_DTPREL16_HA,
1133 16, /* rightshift */
1134 1, /* size (0 = byte, 1 = short, 2 = long) */
1136 FALSE, /* pc_relative */
1138 complain_overflow_dont, /* complain_on_overflow */
1139 ppc_elf_unhandled_reloc, /* special_function */
1140 "R_PPC_GOT_DTPREL16_HA", /* name */
1141 FALSE, /* partial_inplace */
1143 0xffff, /* dst_mask */
1144 FALSE), /* pcrel_offset */
1146 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1147 offset to the entry. */
1148 HOWTO (R_PPC_GOT_TPREL16,
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE, /* pc_relative */
1154 complain_overflow_signed, /* complain_on_overflow */
1155 ppc_elf_unhandled_reloc, /* special_function */
1156 "R_PPC_GOT_TPREL16", /* name */
1157 FALSE, /* partial_inplace */
1159 0xffff, /* dst_mask */
1160 FALSE), /* pcrel_offset */
1162 /* Like GOT_TPREL16, but no overflow. */
1163 HOWTO (R_PPC_GOT_TPREL16_LO,
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE, /* pc_relative */
1169 complain_overflow_dont, /* complain_on_overflow */
1170 ppc_elf_unhandled_reloc, /* special_function */
1171 "R_PPC_GOT_TPREL16_LO", /* name */
1172 FALSE, /* partial_inplace */
1174 0xffff, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1177 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1178 HOWTO (R_PPC_GOT_TPREL16_HI,
1179 16, /* rightshift */
1180 1, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE, /* pc_relative */
1184 complain_overflow_dont, /* complain_on_overflow */
1185 ppc_elf_unhandled_reloc, /* special_function */
1186 "R_PPC_GOT_TPREL16_HI", /* name */
1187 FALSE, /* partial_inplace */
1189 0xffff, /* dst_mask */
1190 FALSE), /* pcrel_offset */
1192 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1193 HOWTO (R_PPC_GOT_TPREL16_HA,
1194 16, /* rightshift */
1195 1, /* size (0 = byte, 1 = short, 2 = long) */
1197 FALSE, /* pc_relative */
1199 complain_overflow_dont, /* complain_on_overflow */
1200 ppc_elf_unhandled_reloc, /* special_function */
1201 "R_PPC_GOT_TPREL16_HA", /* name */
1202 FALSE, /* partial_inplace */
1204 0xffff, /* dst_mask */
1205 FALSE), /* pcrel_offset */
1207 /* The remaining relocs are from the Embedded ELF ABI, and are not
1208 in the SVR4 ELF ABI. */
1210 /* 32 bit value resulting from the addend minus the symbol. */
1211 HOWTO (R_PPC_EMB_NADDR32, /* type */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE, /* pc_relative */
1217 complain_overflow_bitfield, /* complain_on_overflow */
1218 bfd_elf_generic_reloc, /* special_function */
1219 "R_PPC_EMB_NADDR32", /* name */
1220 FALSE, /* partial_inplace */
1222 0xffffffff, /* dst_mask */
1223 FALSE), /* pcrel_offset */
1225 /* 16 bit value resulting from the addend minus the symbol. */
1226 HOWTO (R_PPC_EMB_NADDR16, /* type */
1228 1, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE, /* pc_relative */
1232 complain_overflow_bitfield, /* complain_on_overflow */
1233 bfd_elf_generic_reloc, /* special_function */
1234 "R_PPC_EMB_NADDR16", /* name */
1235 FALSE, /* partial_inplace */
1237 0xffff, /* dst_mask */
1238 FALSE), /* pcrel_offset */
1240 /* 16 bit value resulting from the addend minus the symbol. */
1241 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1243 1, /* size (0 = byte, 1 = short, 2 = long) */
1245 FALSE, /* pc_relative */
1247 complain_overflow_dont,/* complain_on_overflow */
1248 bfd_elf_generic_reloc, /* special_function */
1249 "R_PPC_EMB_ADDR16_LO", /* name */
1250 FALSE, /* partial_inplace */
1252 0xffff, /* dst_mask */
1253 FALSE), /* pcrel_offset */
1255 /* The high order 16 bits of the addend minus the symbol. */
1256 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1257 16, /* rightshift */
1258 1, /* size (0 = byte, 1 = short, 2 = long) */
1260 FALSE, /* pc_relative */
1262 complain_overflow_dont, /* complain_on_overflow */
1263 bfd_elf_generic_reloc, /* special_function */
1264 "R_PPC_EMB_NADDR16_HI", /* name */
1265 FALSE, /* partial_inplace */
1267 0xffff, /* dst_mask */
1268 FALSE), /* pcrel_offset */
1270 /* The high order 16 bits of the result of the addend minus the address,
1271 plus 1 if the contents of the low 16 bits, treated as a signed number,
1273 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1274 16, /* rightshift */
1275 1, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE, /* pc_relative */
1279 complain_overflow_dont, /* complain_on_overflow */
1280 ppc_elf_addr16_ha_reloc, /* special_function */
1281 "R_PPC_EMB_NADDR16_HA", /* name */
1282 FALSE, /* partial_inplace */
1284 0xffff, /* dst_mask */
1285 FALSE), /* pcrel_offset */
1287 /* 16 bit value resulting from allocating a 4 byte word to hold an
1288 address in the .sdata section, and returning the offset from
1289 _SDA_BASE_ for that relocation. */
1290 HOWTO (R_PPC_EMB_SDAI16, /* type */
1292 1, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE, /* pc_relative */
1296 complain_overflow_bitfield, /* complain_on_overflow */
1297 bfd_elf_generic_reloc, /* special_function */
1298 "R_PPC_EMB_SDAI16", /* name */
1299 FALSE, /* partial_inplace */
1301 0xffff, /* dst_mask */
1302 FALSE), /* pcrel_offset */
1304 /* 16 bit value resulting from allocating a 4 byte word to hold an
1305 address in the .sdata2 section, and returning the offset from
1306 _SDA2_BASE_ for that relocation. */
1307 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1309 1, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE, /* pc_relative */
1313 complain_overflow_bitfield, /* complain_on_overflow */
1314 bfd_elf_generic_reloc, /* special_function */
1315 "R_PPC_EMB_SDA2I16", /* name */
1316 FALSE, /* partial_inplace */
1318 0xffff, /* dst_mask */
1319 FALSE), /* pcrel_offset */
1321 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1322 small data items. */
1323 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1325 1, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE, /* pc_relative */
1329 complain_overflow_signed, /* complain_on_overflow */
1330 bfd_elf_generic_reloc, /* special_function */
1331 "R_PPC_EMB_SDA2REL", /* name */
1332 FALSE, /* partial_inplace */
1334 0xffff, /* dst_mask */
1335 FALSE), /* pcrel_offset */
1337 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1338 signed offset from the appropriate base, and filling in the register
1339 field with the appropriate register (0, 2, or 13). */
1340 HOWTO (R_PPC_EMB_SDA21, /* type */
1342 2, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE, /* pc_relative */
1346 complain_overflow_signed, /* complain_on_overflow */
1347 bfd_elf_generic_reloc, /* special_function */
1348 "R_PPC_EMB_SDA21", /* name */
1349 FALSE, /* partial_inplace */
1351 0xffff, /* dst_mask */
1352 FALSE), /* pcrel_offset */
1354 /* Relocation not handled: R_PPC_EMB_MRKREF */
1355 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1356 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1357 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1358 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1359 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1361 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1362 in the 16 bit signed offset from the appropriate base, and filling in the
1363 register field with the appropriate register (0, 2, or 13). */
1364 HOWTO (R_PPC_EMB_RELSDA, /* type */
1366 1, /* size (0 = byte, 1 = short, 2 = long) */
1368 TRUE, /* pc_relative */
1370 complain_overflow_signed, /* complain_on_overflow */
1371 bfd_elf_generic_reloc, /* special_function */
1372 "R_PPC_EMB_RELSDA", /* name */
1373 FALSE, /* partial_inplace */
1375 0xffff, /* dst_mask */
1376 FALSE), /* pcrel_offset */
1378 /* A 16 bit relative relocation. */
1379 HOWTO (R_PPC_REL16, /* type */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 TRUE, /* pc_relative */
1385 complain_overflow_bitfield, /* complain_on_overflow */
1386 bfd_elf_generic_reloc, /* special_function */
1387 "R_PPC_REL16", /* name */
1388 FALSE, /* partial_inplace */
1390 0xffff, /* dst_mask */
1391 TRUE), /* pcrel_offset */
1393 /* A 16 bit relative relocation without overflow. */
1394 HOWTO (R_PPC_REL16_LO, /* type */
1396 1, /* size (0 = byte, 1 = short, 2 = long) */
1398 TRUE, /* pc_relative */
1400 complain_overflow_dont,/* complain_on_overflow */
1401 bfd_elf_generic_reloc, /* special_function */
1402 "R_PPC_REL16_LO", /* name */
1403 FALSE, /* partial_inplace */
1405 0xffff, /* dst_mask */
1406 TRUE), /* pcrel_offset */
1408 /* The high order 16 bits of a relative address. */
1409 HOWTO (R_PPC_REL16_HI, /* type */
1410 16, /* rightshift */
1411 1, /* size (0 = byte, 1 = short, 2 = long) */
1413 TRUE, /* pc_relative */
1415 complain_overflow_dont, /* complain_on_overflow */
1416 bfd_elf_generic_reloc, /* special_function */
1417 "R_PPC_REL16_HI", /* name */
1418 FALSE, /* partial_inplace */
1420 0xffff, /* dst_mask */
1421 TRUE), /* pcrel_offset */
1423 /* The high order 16 bits of a relative address, plus 1 if the contents of
1424 the low 16 bits, treated as a signed number, is negative. */
1425 HOWTO (R_PPC_REL16_HA, /* type */
1426 16, /* rightshift */
1427 1, /* size (0 = byte, 1 = short, 2 = long) */
1429 TRUE, /* pc_relative */
1431 complain_overflow_dont, /* complain_on_overflow */
1432 ppc_elf_addr16_ha_reloc, /* special_function */
1433 "R_PPC_REL16_HA", /* name */
1434 FALSE, /* partial_inplace */
1436 0xffff, /* dst_mask */
1437 TRUE), /* pcrel_offset */
1439 /* GNU extension to record C++ vtable hierarchy. */
1440 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1442 0, /* size (0 = byte, 1 = short, 2 = long) */
1444 FALSE, /* pc_relative */
1446 complain_overflow_dont, /* complain_on_overflow */
1447 NULL, /* special_function */
1448 "R_PPC_GNU_VTINHERIT", /* name */
1449 FALSE, /* partial_inplace */
1452 FALSE), /* pcrel_offset */
1454 /* GNU extension to record C++ vtable member usage. */
1455 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1457 0, /* size (0 = byte, 1 = short, 2 = long) */
1459 FALSE, /* pc_relative */
1461 complain_overflow_dont, /* complain_on_overflow */
1462 NULL, /* special_function */
1463 "R_PPC_GNU_VTENTRY", /* name */
1464 FALSE, /* partial_inplace */
1467 FALSE), /* pcrel_offset */
1469 /* Phony reloc to handle AIX style TOC entries. */
1470 HOWTO (R_PPC_TOC16, /* type */
1472 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 FALSE, /* pc_relative */
1476 complain_overflow_signed, /* complain_on_overflow */
1477 bfd_elf_generic_reloc, /* special_function */
1478 "R_PPC_TOC16", /* name */
1479 FALSE, /* partial_inplace */
1481 0xffff, /* dst_mask */
1482 FALSE), /* pcrel_offset */
1485 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1488 ppc_elf_howto_init (void)
1490 unsigned int i, type;
1493 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1496 type = ppc_elf_howto_raw[i].type;
1497 if (type >= (sizeof (ppc_elf_howto_table)
1498 / sizeof (ppc_elf_howto_table[0])))
1500 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1504 static reloc_howto_type *
1505 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1506 bfd_reloc_code_real_type code)
1508 enum elf_ppc_reloc_type r;
1510 /* Initialize howto table if not already done. */
1511 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1512 ppc_elf_howto_init ();
1519 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1520 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1521 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1522 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1523 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1524 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1525 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1526 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1527 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1528 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1529 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1530 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1531 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1532 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1533 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1534 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1535 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1536 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1537 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1538 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1539 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1540 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1541 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1542 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1543 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1544 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1545 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1546 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1547 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1548 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1549 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1550 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1551 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1552 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1553 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1554 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1555 case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
1556 case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
1557 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1558 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1559 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1560 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1561 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1562 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1563 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1564 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1565 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1566 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1567 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1568 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1569 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1570 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1571 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1572 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1573 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1574 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1575 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1576 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1577 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1578 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1579 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1580 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1581 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1582 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1583 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1584 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1585 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1586 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1587 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1588 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1589 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1590 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1591 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1592 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1593 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1594 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1595 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1596 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1597 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1598 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1599 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1600 case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
1601 case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
1602 case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
1603 case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
1604 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1605 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1608 return ppc_elf_howto_table[r];
1611 static reloc_howto_type *
1612 ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1618 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1620 if (ppc_elf_howto_raw[i].name != NULL
1621 && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
1622 return &ppc_elf_howto_raw[i];
1627 /* Set the howto pointer for a PowerPC ELF reloc. */
1630 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1632 Elf_Internal_Rela *dst)
1634 /* Initialize howto table if not already done. */
1635 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1636 ppc_elf_howto_init ();
1638 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1639 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1641 /* Just because the above assert didn't trigger doesn't mean that
1642 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1643 if (!cache_ptr->howto)
1645 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
1646 abfd, ELF32_R_TYPE (dst->r_info));
1647 bfd_set_error (bfd_error_bad_value);
1649 cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
1653 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1655 static bfd_reloc_status_type
1656 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1657 arelent *reloc_entry,
1659 void *data ATTRIBUTE_UNUSED,
1660 asection *input_section,
1662 char **error_message ATTRIBUTE_UNUSED)
1666 if (output_bfd != NULL)
1668 reloc_entry->address += input_section->output_offset;
1669 return bfd_reloc_ok;
1672 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1673 return bfd_reloc_outofrange;
1675 if (bfd_is_com_section (symbol->section))
1678 relocation = symbol->value;
1680 relocation += symbol->section->output_section->vma;
1681 relocation += symbol->section->output_offset;
1682 relocation += reloc_entry->addend;
1683 if (reloc_entry->howto->pc_relative)
1684 relocation -= reloc_entry->address;
1686 reloc_entry->addend += (relocation & 0x8000) << 1;
1688 return bfd_reloc_continue;
1691 static bfd_reloc_status_type
1692 ppc_elf_unhandled_reloc (bfd *abfd,
1693 arelent *reloc_entry,
1696 asection *input_section,
1698 char **error_message)
1700 /* If this is a relocatable link (output_bfd test tells us), just
1701 call the generic function. Any adjustment will be done at final
1703 if (output_bfd != NULL)
1704 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1705 input_section, output_bfd, error_message);
1707 if (error_message != NULL)
1709 static char buf[60];
1710 sprintf (buf, _("generic linker can't handle %s"),
1711 reloc_entry->howto->name);
1712 *error_message = buf;
1714 return bfd_reloc_dangerous;
1717 /* Sections created by the linker. */
1719 typedef struct elf_linker_section
1721 /* Pointer to the bfd section. */
1725 /* Associated bss section name. */
1726 const char *bss_name;
1727 /* Associated symbol name. */
1728 const char *sym_name;
1729 /* Associated symbol. */
1730 struct elf_link_hash_entry *sym;
1731 } elf_linker_section_t;
1733 /* Linked list of allocated pointer entries. This hangs off of the
1734 symbol lists, and provides allows us to return different pointers,
1735 based on different addend's. */
1737 typedef struct elf_linker_section_pointers
1739 /* next allocated pointer for this symbol */
1740 struct elf_linker_section_pointers *next;
1741 /* offset of pointer from beginning of section */
1745 /* which linker section this is */
1746 elf_linker_section_t *lsect;
1747 } elf_linker_section_pointers_t;
1749 struct ppc_elf_obj_tdata
1751 struct elf_obj_tdata elf;
1753 /* A mapping from local symbols to offsets into the various linker
1754 sections added. This is index by the symbol index. */
1755 elf_linker_section_pointers_t **linker_section_pointers;
1757 /* Flags used to auto-detect plt type. */
1758 unsigned int makes_plt_call : 1;
1759 unsigned int has_rel16 : 1;
1762 #define ppc_elf_tdata(bfd) \
1763 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1765 #define elf_local_ptr_offsets(bfd) \
1766 (ppc_elf_tdata (bfd)->linker_section_pointers)
1768 /* Override the generic function because we store some extras. */
1771 ppc_elf_mkobject (bfd *abfd)
1773 if (abfd->tdata.any == NULL)
1775 bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
1776 abfd->tdata.any = bfd_zalloc (abfd, amt);
1777 if (abfd->tdata.any == NULL)
1780 return bfd_elf_mkobject (abfd);
1783 /* Fix bad default arch selected for a 32 bit input bfd when the
1784 default is 64 bit. */
1787 ppc_elf_object_p (bfd *abfd)
1789 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
1791 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
1793 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
1795 /* Relies on arch after 64 bit default being 32 bit default. */
1796 abfd->arch_info = abfd->arch_info->next;
1797 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
1803 /* Function to set whether a module needs the -mrelocatable bit set. */
1806 ppc_elf_set_private_flags (bfd *abfd, flagword flags)
1808 BFD_ASSERT (!elf_flags_init (abfd)
1809 || elf_elfheader (abfd)->e_flags == flags);
1811 elf_elfheader (abfd)->e_flags = flags;
1812 elf_flags_init (abfd) = TRUE;
1816 /* Support for core dump NOTE sections. */
1819 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1824 switch (note->descsz)
1829 case 268: /* Linux/PPC. */
1831 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1834 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1843 /* Make a ".reg/999" section. */
1844 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1845 size, note->descpos + offset);
1849 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1851 switch (note->descsz)
1856 case 128: /* Linux/PPC elf_prpsinfo. */
1857 elf_tdata (abfd)->core_program
1858 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1859 elf_tdata (abfd)->core_command
1860 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1863 /* Note that for some reason, a spurious space is tacked
1864 onto the end of the args in some (at least one anyway)
1865 implementations, so strip it off if it exists. */
1868 char *command = elf_tdata (abfd)->core_command;
1869 int n = strlen (command);
1871 if (0 < n && command[n - 1] == ' ')
1872 command[n - 1] = '\0';
1879 ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
1891 va_start (ap, note_type);
1892 memset (data, 0, 32);
1893 strncpy (data + 32, va_arg (ap, const char *), 16);
1894 strncpy (data + 48, va_arg (ap, const char *), 80);
1896 return elfcore_write_note (abfd, buf, bufsiz,
1897 "CORE", note_type, data, sizeof (data));
1908 va_start (ap, note_type);
1909 memset (data, 0, 72);
1910 pid = va_arg (ap, long);
1911 bfd_put_32 (abfd, pid, data + 24);
1912 cursig = va_arg (ap, int);
1913 bfd_put_16 (abfd, cursig, data + 12);
1914 greg = va_arg (ap, const void *);
1915 memcpy (data + 72, greg, 192);
1916 memset (data + 264, 0, 4);
1918 return elfcore_write_note (abfd, buf, bufsiz,
1919 "CORE", note_type, data, sizeof (data));
1924 /* Return address for Ith PLT stub in section PLT, for relocation REL
1925 or (bfd_vma) -1 if it should not be included. */
1928 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
1929 const asection *plt ATTRIBUTE_UNUSED,
1932 return rel->address;
1935 /* Handle a PowerPC specific section when reading an object file. This
1936 is called when bfd_section_from_shdr finds a section with an unknown
1940 ppc_elf_section_from_shdr (bfd *abfd,
1941 Elf_Internal_Shdr *hdr,
1948 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1951 newsect = hdr->bfd_section;
1952 flags = bfd_get_section_flags (abfd, newsect);
1953 if (hdr->sh_flags & SHF_EXCLUDE)
1954 flags |= SEC_EXCLUDE;
1956 if (hdr->sh_type == SHT_ORDERED)
1957 flags |= SEC_SORT_ENTRIES;
1959 bfd_set_section_flags (abfd, newsect, flags);
1963 /* Set up any other section flags and such that may be necessary. */
1966 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1967 Elf_Internal_Shdr *shdr,
1970 if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE)
1971 shdr->sh_flags |= SHF_EXCLUDE;
1973 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1974 shdr->sh_type = SHT_ORDERED;
1979 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1980 need to bump up the number of section headers. */
1983 ppc_elf_additional_program_headers (bfd *abfd,
1984 struct bfd_link_info *info ATTRIBUTE_UNUSED)
1989 s = bfd_get_section_by_name (abfd, ".sbss2");
1990 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1993 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1994 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
2000 /* Add extra PPC sections -- Note, for now, make .sbss2 and
2001 .PPC.EMB.sbss0 a normal section, and not a bss section so
2002 that the linker doesn't crater when trying to make more than
2005 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
2007 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
2008 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2009 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
2010 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2011 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
2012 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
2013 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 },
2014 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
2015 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
2016 { NULL, 0, 0, 0, 0 }
2019 /* This is what we want for new plt/got. */
2020 static struct bfd_elf_special_section ppc_alt_plt =
2021 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC };
2023 static const struct bfd_elf_special_section *
2024 ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
2026 const struct bfd_elf_special_section *ssect;
2028 /* See if this is one of the special sections. */
2029 if (sec->name == NULL)
2032 ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
2036 if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
2037 ssect = &ppc_alt_plt;
2041 return _bfd_elf_get_sec_type_attr (abfd, sec);
2044 /* Very simple linked list structure for recording apuinfo values. */
2045 typedef struct apuinfo_list
2047 struct apuinfo_list *next;
2048 unsigned long value;
2052 static apuinfo_list *head;
2056 apuinfo_list_init (void)
2062 apuinfo_list_add (unsigned long value)
2064 apuinfo_list *entry = head;
2066 while (entry != NULL)
2068 if (entry->value == value)
2070 entry = entry->next;
2073 entry = bfd_malloc (sizeof (* entry));
2077 entry->value = value;
2083 apuinfo_list_length (void)
2085 apuinfo_list *entry;
2086 unsigned long count;
2088 for (entry = head, count = 0;
2090 entry = entry->next)
2096 static inline unsigned long
2097 apuinfo_list_element (unsigned long number)
2099 apuinfo_list * entry;
2103 entry = entry->next)
2106 return entry ? entry->value : 0;
2110 apuinfo_list_finish (void)
2112 apuinfo_list *entry;
2114 for (entry = head; entry;)
2116 apuinfo_list *next = entry->next;
2124 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2125 #define APUINFO_LABEL "APUinfo"
2127 /* Scan the input BFDs and create a linked list of
2128 the APUinfo values that will need to be emitted. */
2131 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
2136 unsigned num_input_sections;
2137 bfd_size_type output_section_size;
2139 unsigned num_entries;
2140 unsigned long offset;
2141 unsigned long length;
2142 const char *error_message = NULL;
2144 if (link_info == NULL)
2147 /* Scan the input bfds, looking for apuinfo sections. */
2148 num_input_sections = 0;
2149 output_section_size = 0;
2151 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2153 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2156 ++ num_input_sections;
2157 output_section_size += asec->size;
2161 /* We need at least one input sections
2162 in order to make merging worthwhile. */
2163 if (num_input_sections < 1)
2166 /* Just make sure that the output section exists as well. */
2167 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2171 /* Allocate a buffer for the contents of the input sections. */
2172 buffer = bfd_malloc (output_section_size);
2177 apuinfo_list_init ();
2179 /* Read in the input sections contents. */
2180 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2182 unsigned long datum;
2185 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2189 length = asec->size;
2192 error_message = _("corrupt or empty %s section in %B");
2196 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
2197 || (bfd_bread (buffer + offset, length, ibfd) != length))
2199 error_message = _("unable to read in %s section from %B");
2203 /* Process the contents of the section. */
2204 ptr = buffer + offset;
2205 error_message = _("corrupt %s section in %B");
2207 /* Verify the contents of the header. Note - we have to
2208 extract the values this way in order to allow for a
2209 host whose endian-ness is different from the target. */
2210 datum = bfd_get_32 (ibfd, ptr);
2211 if (datum != sizeof APUINFO_LABEL)
2214 datum = bfd_get_32 (ibfd, ptr + 8);
2218 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
2221 /* Get the number of bytes used for apuinfo entries. */
2222 datum = bfd_get_32 (ibfd, ptr + 4);
2223 if (datum + 20 != length)
2226 /* Make sure that we do not run off the end of the section. */
2227 if (offset + length > output_section_size)
2230 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2231 for (i = 0; i < datum; i += 4)
2232 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
2234 /* Update the offset. */
2238 error_message = NULL;
2240 /* Compute the size of the output section. */
2241 num_entries = apuinfo_list_length ();
2242 output_section_size = 20 + num_entries * 4;
2244 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2246 if (! bfd_set_section_size (abfd, asec, output_section_size))
2248 error_message = _("warning: unable to set size of %s section in %B");
2254 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2257 /* Prevent the output section from accumulating the input sections'
2258 contents. We have already stored this in our linked list structure. */
2261 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
2262 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
2264 bfd_byte *contents ATTRIBUTE_UNUSED)
2266 return (apuinfo_list_length ()
2267 && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
2270 /* Finally we can generate the output section. */
2273 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
2278 unsigned num_entries;
2279 bfd_size_type length;
2281 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2285 if (apuinfo_list_length () == 0)
2288 length = asec->size;
2292 buffer = bfd_malloc (length);
2295 (*_bfd_error_handler)
2296 (_("failed to allocate space for new APUinfo section."));
2300 /* Create the apuinfo header. */
2301 num_entries = apuinfo_list_length ();
2302 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2303 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2304 bfd_put_32 (abfd, 0x2, buffer + 8);
2305 strcpy ((char *) buffer + 12, APUINFO_LABEL);
2308 for (i = 0; i < num_entries; i++)
2310 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2314 if (length != asec->size)
2315 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
2317 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2318 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
2322 apuinfo_list_finish ();
2325 /* The following functions are specific to the ELF linker, while
2326 functions above are used generally. They appear in this file more
2327 or less in the order in which they are called. eg.
2328 ppc_elf_check_relocs is called early in the link process,
2329 ppc_elf_finish_dynamic_sections is one of the last functions
2332 /* The PPC linker needs to keep track of the number of relocs that it
2333 decides to copy as dynamic relocs in check_relocs for each symbol.
2334 This is so that it can later discard them if they are found to be
2335 unnecessary. We store the information in a field extending the
2336 regular ELF linker hash table. */
2338 struct ppc_elf_dyn_relocs
2340 struct ppc_elf_dyn_relocs *next;
2342 /* The input section of the reloc. */
2345 /* Total number of relocs copied for the input section. */
2346 bfd_size_type count;
2348 /* Number of pc-relative relocs copied for the input section. */
2349 bfd_size_type pc_count;
2352 /* Track PLT entries needed for a given symbol. We might need more
2353 than one glink entry per symbol. */
2356 struct plt_entry *next;
2358 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2359 This field stores the offset into .got2 used to initialise the
2360 GOT pointer reg. It will always be at least 32768 (and for
2361 current gcc this is the only offset used). */
2364 /* The .got2 section. */
2367 /* PLT refcount or offset. */
2370 bfd_signed_vma refcount;
2374 /* .glink stub offset. */
2375 bfd_vma glink_offset;
2378 /* Of those relocs that might be copied as dynamic relocs, this function
2379 selects those that must be copied when linking a shared library,
2380 even when the symbol is local. */
2383 must_be_dyn_reloc (struct bfd_link_info *info,
2384 enum elf_ppc_reloc_type r_type)
2393 case R_PPC_REL14_BRTAKEN:
2394 case R_PPC_REL14_BRNTAKEN:
2400 case R_PPC_TPREL16_LO:
2401 case R_PPC_TPREL16_HI:
2402 case R_PPC_TPREL16_HA:
2403 return !info->executable;
2407 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2408 copying dynamic variables from a shared lib into an app's dynbss
2409 section, and instead use a dynamic relocation to point into the
2411 #define ELIMINATE_COPY_RELOCS 1
2413 /* PPC ELF linker hash entry. */
2415 struct ppc_elf_link_hash_entry
2417 struct elf_link_hash_entry elf;
2419 /* If this symbol is used in the linker created sections, the processor
2420 specific backend uses this field to map the field into the offset
2421 from the beginning of the section. */
2422 elf_linker_section_pointers_t *linker_section_pointer;
2424 /* Track dynamic relocs copied for this symbol. */
2425 struct ppc_elf_dyn_relocs *dyn_relocs;
2427 /* Contexts in which symbol is used in the GOT (or TOC).
2428 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2429 corresponding relocs are encountered during check_relocs.
2430 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2431 indicate the corresponding GOT entry type is not needed. */
2432 #define TLS_GD 1 /* GD reloc. */
2433 #define TLS_LD 2 /* LD reloc. */
2434 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2435 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2436 #define TLS_TLS 16 /* Any TLS reloc. */
2437 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2440 /* Nonzero if we have seen a small data relocation referring to this
2442 unsigned char has_sda_refs;
2445 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2447 /* PPC ELF linker hash table. */
2449 struct ppc_elf_link_hash_table
2451 struct elf_link_hash_table elf;
2453 /* Short-cuts to get to dynamic linker sections. */
2463 elf_linker_section_t sdata[2];
2466 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2469 /* The .got.plt section (VxWorks only)*/
2472 /* Shortcut to __tls_get_addr. */
2473 struct elf_link_hash_entry *tls_get_addr;
2475 /* The bfd that forced an old-style PLT. */
2478 /* TLS local dynamic got entry handling. */
2480 bfd_signed_vma refcount;
2484 /* Offset of PltResolve function in glink. */
2485 bfd_vma glink_pltresolve;
2487 /* Size of reserved GOT entries. */
2488 unsigned int got_header_size;
2489 /* Non-zero if allocating the header left a gap. */
2490 unsigned int got_gap;
2492 /* The type of PLT we have chosen to use. */
2493 enum ppc_elf_plt_type plt_type;
2495 /* Set if we should emit symbols for stubs. */
2496 unsigned int emit_stub_syms:1;
2498 /* True if the target system is VxWorks. */
2499 unsigned int is_vxworks:1;
2501 /* The size of PLT entries. */
2503 /* The distance between adjacent PLT slots. */
2505 /* The size of the first PLT entry. */
2506 int plt_initial_entry_size;
2508 /* Small local sym to section mapping cache. */
2509 struct sym_sec_cache sym_sec;
2512 /* Get the PPC ELF linker hash table from a link_info structure. */
2514 #define ppc_elf_hash_table(p) \
2515 ((struct ppc_elf_link_hash_table *) (p)->hash)
2517 /* Create an entry in a PPC ELF linker hash table. */
2519 static struct bfd_hash_entry *
2520 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2521 struct bfd_hash_table *table,
2524 /* Allocate the structure if it has not already been allocated by a
2528 entry = bfd_hash_allocate (table,
2529 sizeof (struct ppc_elf_link_hash_entry));
2534 /* Call the allocation method of the superclass. */
2535 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2538 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
2539 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
2540 ppc_elf_hash_entry (entry)->tls_mask = 0;
2546 /* Create a PPC ELF linker hash table. */
2548 static struct bfd_link_hash_table *
2549 ppc_elf_link_hash_table_create (bfd *abfd)
2551 struct ppc_elf_link_hash_table *ret;
2553 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
2557 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
2558 ppc_elf_link_hash_newfunc,
2559 sizeof (struct ppc_elf_link_hash_entry)))
2565 ret->elf.init_plt_refcount.refcount = 0;
2566 ret->elf.init_plt_refcount.glist = NULL;
2567 ret->elf.init_plt_offset.offset = 0;
2568 ret->elf.init_plt_offset.glist = NULL;
2570 ret->sdata[0].name = ".sdata";
2571 ret->sdata[0].sym_name = "_SDA_BASE_";
2572 ret->sdata[0].bss_name = ".sbss";
2574 ret->sdata[1].name = ".sdata2";
2575 ret->sdata[1].sym_name = "_SDA2_BASE_";
2576 ret->sdata[1].bss_name = ".sbss2";
2578 ret->plt_entry_size = 12;
2579 ret->plt_slot_size = 8;
2580 ret->plt_initial_entry_size = 72;
2582 return &ret->elf.root;
2585 /* Create .got and the related sections. */
2588 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2590 struct ppc_elf_link_hash_table *htab;
2594 if (!_bfd_elf_create_got_section (abfd, info))
2597 htab = ppc_elf_hash_table (info);
2598 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2602 if (htab->is_vxworks)
2604 htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt");
2610 /* The powerpc .got has a blrl instruction in it. Mark it
2612 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
2613 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2614 if (!bfd_set_section_flags (abfd, s, flags))
2618 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2619 | SEC_LINKER_CREATED | SEC_READONLY);
2620 htab->relgot = bfd_make_section_with_flags (abfd, ".rela.got", flags);
2622 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2628 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2629 to output sections (just like _bfd_elf_create_dynamic_sections has
2630 to create .dynbss and .rela.bss). */
2633 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2635 struct ppc_elf_link_hash_table *htab;
2639 htab = ppc_elf_hash_table (info);
2641 if (htab->got == NULL
2642 && !ppc_elf_create_got (abfd, info))
2645 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2648 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
2649 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2651 s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags | SEC_CODE);
2654 || !bfd_set_section_alignment (abfd, s, 4))
2657 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2658 s = bfd_make_section_with_flags (abfd, ".dynsbss",
2659 SEC_ALLOC | SEC_LINKER_CREATED);
2666 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2667 s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags);
2670 || ! bfd_set_section_alignment (abfd, s, 2))
2674 if (htab->is_vxworks
2675 && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2678 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2679 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2683 flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
2684 if (htab->plt_type == PLT_VXWORKS)
2685 /* The VxWorks PLT is a loaded section with contents. */
2686 flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
2687 return bfd_set_section_flags (abfd, s, flags);
2690 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2693 ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
2694 struct elf_link_hash_entry *dir,
2695 struct elf_link_hash_entry *ind)
2697 struct ppc_elf_link_hash_entry *edir, *eind;
2699 edir = (struct ppc_elf_link_hash_entry *) dir;
2700 eind = (struct ppc_elf_link_hash_entry *) ind;
2702 if (eind->dyn_relocs != NULL)
2704 if (edir->dyn_relocs != NULL)
2706 struct ppc_elf_dyn_relocs **pp;
2707 struct ppc_elf_dyn_relocs *p;
2709 /* Add reloc counts against the indirect sym to the direct sym
2710 list. Merge any entries against the same section. */
2711 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2713 struct ppc_elf_dyn_relocs *q;
2715 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2716 if (q->sec == p->sec)
2718 q->pc_count += p->pc_count;
2719 q->count += p->count;
2726 *pp = edir->dyn_relocs;
2729 edir->dyn_relocs = eind->dyn_relocs;
2730 eind->dyn_relocs = NULL;
2733 edir->tls_mask |= eind->tls_mask;
2734 edir->has_sda_refs |= eind->has_sda_refs;
2736 /* If called to transfer flags for a weakdef during processing
2737 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2738 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2739 if (!(ELIMINATE_COPY_RELOCS
2740 && eind->elf.root.type != bfd_link_hash_indirect
2741 && edir->elf.dynamic_adjusted))
2742 edir->elf.non_got_ref |= eind->elf.non_got_ref;
2744 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
2745 edir->elf.ref_regular |= eind->elf.ref_regular;
2746 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
2747 edir->elf.needs_plt |= eind->elf.needs_plt;
2749 /* If we were called to copy over info for a weak sym, that's all. */
2750 if (eind->elf.root.type != bfd_link_hash_indirect)
2753 /* Copy over the GOT refcount entries that we may have already seen to
2754 the symbol which just became indirect. */
2755 edir->elf.got.refcount += eind->elf.got.refcount;
2756 eind->elf.got.refcount = 0;
2758 /* And plt entries. */
2759 if (eind->elf.plt.plist != NULL)
2761 if (edir->elf.plt.plist != NULL)
2763 struct plt_entry **entp;
2764 struct plt_entry *ent;
2766 for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
2768 struct plt_entry *dent;
2770 for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
2771 if (dent->sec == ent->sec && dent->addend == ent->addend)
2773 dent->plt.refcount += ent->plt.refcount;
2780 *entp = edir->elf.plt.plist;
2783 edir->elf.plt.plist = eind->elf.plt.plist;
2784 eind->elf.plt.plist = NULL;
2787 if (eind->elf.dynindx != -1)
2789 if (edir->elf.dynindx != -1)
2790 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
2791 edir->elf.dynstr_index);
2792 edir->elf.dynindx = eind->elf.dynindx;
2793 edir->elf.dynstr_index = eind->elf.dynstr_index;
2794 eind->elf.dynindx = -1;
2795 eind->elf.dynstr_index = 0;
2799 /* Return 1 if target is one of ours. */
2802 is_ppc_elf_target (const struct bfd_target *targ)
2804 extern const bfd_target bfd_elf32_powerpc_vec;
2805 extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
2806 extern const bfd_target bfd_elf32_powerpcle_vec;
2808 return (targ == &bfd_elf32_powerpc_vec
2809 || targ == &bfd_elf32_powerpc_vxworks_vec
2810 || targ == &bfd_elf32_powerpcle_vec);
2813 /* Hook called by the linker routine which adds symbols from an object
2814 file. We use it to put .comm items in .sbss, and not .bss. */
2817 ppc_elf_add_symbol_hook (bfd *abfd,
2818 struct bfd_link_info *info,
2819 Elf_Internal_Sym *sym,
2820 const char **namep ATTRIBUTE_UNUSED,
2821 flagword *flagsp ATTRIBUTE_UNUSED,
2825 if (sym->st_shndx == SHN_COMMON
2826 && !info->relocatable
2827 && sym->st_size <= elf_gp_size (abfd)
2828 && is_ppc_elf_target (info->hash->creator))
2830 /* Common symbols less than or equal to -G nn bytes are automatically
2832 struct ppc_elf_link_hash_table *htab;
2834 htab = ppc_elf_hash_table (info);
2835 if (htab->sbss == NULL)
2837 flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
2839 if (!htab->elf.dynobj)
2840 htab->elf.dynobj = abfd;
2842 htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2845 if (htab->sbss == NULL)
2850 *valp = sym->st_size;
2857 create_sdata_sym (struct ppc_elf_link_hash_table *htab,
2858 elf_linker_section_t *lsect)
2860 lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
2862 if (lsect->sym == NULL)
2864 if (lsect->sym->root.type == bfd_link_hash_new)
2865 lsect->sym->non_elf = 0;
2866 lsect->sym->ref_regular = 1;
2870 /* Create a special linker section. */
2873 ppc_elf_create_linker_section (bfd *abfd,
2874 struct bfd_link_info *info,
2876 elf_linker_section_t *lsect)
2878 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2881 flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2882 | SEC_LINKER_CREATED);
2884 /* Record the first bfd that needs the special sections. */
2885 if (!htab->elf.dynobj)
2886 htab->elf.dynobj = abfd;
2888 s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2892 || !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2896 return create_sdata_sym (htab, lsect);
2899 /* Find a linker generated pointer with a given addend and type. */
2901 static elf_linker_section_pointers_t *
2902 elf_find_pointer_linker_section
2903 (elf_linker_section_pointers_t *linker_pointers,
2905 elf_linker_section_t *lsect)
2907 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
2908 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
2909 return linker_pointers;
2914 /* Allocate a pointer to live in a linker created section. */
2917 elf_create_pointer_linker_section (bfd *abfd,
2918 elf_linker_section_t *lsect,
2919 struct elf_link_hash_entry *h,
2920 const Elf_Internal_Rela *rel)
2922 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
2923 elf_linker_section_pointers_t *linker_section_ptr;
2924 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2927 BFD_ASSERT (lsect != NULL);
2929 /* Is this a global symbol? */
2932 struct ppc_elf_link_hash_entry *eh;
2934 /* Has this symbol already been allocated? If so, our work is done. */
2935 eh = (struct ppc_elf_link_hash_entry *) h;
2936 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
2941 ptr_linker_section_ptr = &eh->linker_section_pointer;
2945 /* Allocation of a pointer to a local symbol. */
2946 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
2948 /* Allocate a table to hold the local symbols if first time. */
2951 unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info;
2954 amt *= sizeof (elf_linker_section_pointers_t *);
2955 ptr = bfd_zalloc (abfd, amt);
2960 elf_local_ptr_offsets (abfd) = ptr;
2963 /* Has this symbol already been allocated? If so, our work is done. */
2964 if (elf_find_pointer_linker_section (ptr[r_symndx],
2969 ptr_linker_section_ptr = &ptr[r_symndx];
2972 /* Allocate space for a pointer in the linker section, and allocate
2973 a new pointer record from internal memory. */
2974 BFD_ASSERT (ptr_linker_section_ptr != NULL);
2975 amt = sizeof (elf_linker_section_pointers_t);
2976 linker_section_ptr = bfd_alloc (abfd, amt);
2978 if (!linker_section_ptr)
2981 linker_section_ptr->next = *ptr_linker_section_ptr;
2982 linker_section_ptr->addend = rel->r_addend;
2983 linker_section_ptr->lsect = lsect;
2984 *ptr_linker_section_ptr = linker_section_ptr;
2986 linker_section_ptr->offset = lsect->section->size;
2987 lsect->section->size += 4;
2991 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2992 lsect->name, (long) linker_section_ptr->offset,
2993 (long) lsect->section->size);
3000 update_local_sym_info (bfd *abfd,
3001 Elf_Internal_Shdr *symtab_hdr,
3002 unsigned long r_symndx,
3005 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
3006 char *local_got_tls_masks;
3008 if (local_got_refcounts == NULL)
3010 bfd_size_type size = symtab_hdr->sh_info;
3012 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
3013 local_got_refcounts = bfd_zalloc (abfd, size);
3014 if (local_got_refcounts == NULL)
3016 elf_local_got_refcounts (abfd) = local_got_refcounts;
3019 local_got_refcounts[r_symndx] += 1;
3020 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
3021 local_got_tls_masks[r_symndx] |= tls_type;
3026 update_plt_info (bfd *abfd, struct elf_link_hash_entry *h,
3027 asection *sec, bfd_vma addend)
3029 struct plt_entry *ent;
3033 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
3034 if (ent->sec == sec && ent->addend == addend)
3038 bfd_size_type amt = sizeof (*ent);
3039 ent = bfd_alloc (abfd, amt);
3042 ent->next = h->plt.plist;
3044 ent->addend = addend;
3045 ent->plt.refcount = 0;
3048 ent->plt.refcount += 1;
3052 static struct plt_entry *
3053 find_plt_ent (struct elf_link_hash_entry *h, asection *sec, bfd_vma addend)
3055 struct plt_entry *ent;
3059 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
3060 if (ent->sec == sec && ent->addend == addend)
3066 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
3068 (*_bfd_error_handler)
3069 (_("%B: relocation %s cannot be used when making a shared object"),
3071 ppc_elf_howto_table[r_type]->name);
3072 bfd_set_error (bfd_error_bad_value);
3075 /* Look through the relocs for a section during the first phase, and
3076 allocate space in the global offset table or procedure linkage
3080 ppc_elf_check_relocs (bfd *abfd,
3081 struct bfd_link_info *info,
3083 const Elf_Internal_Rela *relocs)
3085 struct ppc_elf_link_hash_table *htab;
3086 Elf_Internal_Shdr *symtab_hdr;
3087 struct elf_link_hash_entry **sym_hashes;
3088 const Elf_Internal_Rela *rel;
3089 const Elf_Internal_Rela *rel_end;
3090 asection *got2, *sreloc;
3091 struct elf_link_hash_entry *tga;
3093 if (info->relocatable)
3096 /* Don't do anything special with non-loaded, non-alloced sections.
3097 In particular, any relocs in such sections should not affect GOT
3098 and PLT reference counting (ie. we don't allow them to create GOT
3099 or PLT entries), there's no possibility or desire to optimize TLS
3100 relocs, and there's not much point in propagating relocs to shared
3101 libs that the dynamic linker won't relocate. */
3102 if ((sec->flags & SEC_ALLOC) == 0)
3106 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3110 /* Initialize howto table if not already done. */
3111 if (!ppc_elf_howto_table[R_PPC_ADDR32])
3112 ppc_elf_howto_init ();
3114 htab = ppc_elf_hash_table (info);
3115 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3116 FALSE, FALSE, TRUE);
3117 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3118 sym_hashes = elf_sym_hashes (abfd);
3119 got2 = bfd_get_section_by_name (abfd, ".got2");
3122 rel_end = relocs + sec->reloc_count;
3123 for (rel = relocs; rel < rel_end; rel++)
3125 unsigned long r_symndx;
3126 enum elf_ppc_reloc_type r_type;
3127 struct elf_link_hash_entry *h;
3130 r_symndx = ELF32_R_SYM (rel->r_info);
3131 if (r_symndx < symtab_hdr->sh_info)
3135 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3136 while (h->root.type == bfd_link_hash_indirect
3137 || h->root.type == bfd_link_hash_warning)
3138 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3141 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3142 This shows up in particular in an R_PPC_ADDR32 in the eabi
3145 && htab->got == NULL
3146 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3148 if (htab->elf.dynobj == NULL)
3149 htab->elf.dynobj = abfd;
3150 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3152 BFD_ASSERT (h == htab->elf.hgot);
3156 r_type = ELF32_R_TYPE (rel->r_info);
3157 if (h != NULL && h == tga)
3163 case R_PPC_PLTREL24:
3164 case R_PPC_LOCAL24PC:
3167 case R_PPC_REL14_BRTAKEN:
3168 case R_PPC_REL14_BRNTAKEN:
3171 case R_PPC_ADDR14_BRTAKEN:
3172 case R_PPC_ADDR14_BRNTAKEN:
3174 && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
3175 || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
3176 /* We have a new-style __tls_get_addr call with a marker
3180 /* Mark this section as having an old-style call. */
3181 sec->has_tls_get_addr_call = 1;
3189 /* These special tls relocs tie a call to __tls_get_addr with
3190 its parameter symbol. */
3193 case R_PPC_GOT_TLSLD16:
3194 case R_PPC_GOT_TLSLD16_LO:
3195 case R_PPC_GOT_TLSLD16_HI:
3196 case R_PPC_GOT_TLSLD16_HA:
3197 tls_type = TLS_TLS | TLS_LD;
3200 case R_PPC_GOT_TLSGD16:
3201 case R_PPC_GOT_TLSGD16_LO:
3202 case R_PPC_GOT_TLSGD16_HI:
3203 case R_PPC_GOT_TLSGD16_HA:
3204 tls_type = TLS_TLS | TLS_GD;
3207 case R_PPC_GOT_TPREL16:
3208 case R_PPC_GOT_TPREL16_LO:
3209 case R_PPC_GOT_TPREL16_HI:
3210 case R_PPC_GOT_TPREL16_HA:
3211 if (!info->executable)
3212 info->flags |= DF_STATIC_TLS;
3213 tls_type = TLS_TLS | TLS_TPREL;
3216 case R_PPC_GOT_DTPREL16:
3217 case R_PPC_GOT_DTPREL16_LO:
3218 case R_PPC_GOT_DTPREL16_HI:
3219 case R_PPC_GOT_DTPREL16_HA:
3220 tls_type = TLS_TLS | TLS_DTPREL;
3222 sec->has_tls_reloc = 1;
3225 /* GOT16 relocations */
3227 case R_PPC_GOT16_LO:
3228 case R_PPC_GOT16_HI:
3229 case R_PPC_GOT16_HA:
3230 /* This symbol requires a global offset table entry. */
3231 if (htab->got == NULL)
3233 if (htab->elf.dynobj == NULL)
3234 htab->elf.dynobj = abfd;
3235 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3240 h->got.refcount += 1;
3241 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3244 /* This is a global offset table entry for a local symbol. */
3245 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3249 /* Indirect .sdata relocation. */
3250 case R_PPC_EMB_SDAI16:
3253 bad_shared_reloc (abfd, r_type);
3256 if (htab->sdata[0].section == NULL
3257 && !ppc_elf_create_linker_section (abfd, info, 0,
3260 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
3265 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3266 h->non_got_ref = TRUE;
3270 /* Indirect .sdata2 relocation. */
3271 case R_PPC_EMB_SDA2I16:
3274 bad_shared_reloc (abfd, r_type);
3277 if (htab->sdata[1].section == NULL
3278 && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
3281 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
3286 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3287 h->non_got_ref = TRUE;
3291 case R_PPC_SDAREL16:
3294 bad_shared_reloc (abfd, r_type);
3297 if (htab->sdata[0].sym == NULL
3298 && !create_sdata_sym (htab, &htab->sdata[0]))
3302 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3303 h->non_got_ref = TRUE;
3307 case R_PPC_EMB_SDA2REL:
3310 bad_shared_reloc (abfd, r_type);
3313 if (htab->sdata[1].sym == NULL
3314 && !create_sdata_sym (htab, &htab->sdata[1]))
3318 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3319 h->non_got_ref = TRUE;
3323 case R_PPC_EMB_SDA21:
3324 case R_PPC_EMB_RELSDA:
3327 bad_shared_reloc (abfd, r_type);
3330 if (htab->sdata[0].sym == NULL
3331 && !create_sdata_sym (htab, &htab->sdata[0]))
3333 if (htab->sdata[1].sym == NULL
3334 && !create_sdata_sym (htab, &htab->sdata[1]))
3338 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3339 h->non_got_ref = TRUE;
3343 case R_PPC_EMB_NADDR32:
3344 case R_PPC_EMB_NADDR16:
3345 case R_PPC_EMB_NADDR16_LO:
3346 case R_PPC_EMB_NADDR16_HI:
3347 case R_PPC_EMB_NADDR16_HA:
3350 bad_shared_reloc (abfd, r_type);
3354 h->non_got_ref = TRUE;
3358 case R_PPC_PLTREL24:
3359 case R_PPC_PLTREL32:
3360 case R_PPC_PLT16_LO:
3361 case R_PPC_PLT16_HI:
3362 case R_PPC_PLT16_HA:
3364 fprintf (stderr, "Reloc requires a PLT entry\n");
3366 /* This symbol requires a procedure linkage table entry. We
3367 actually build the entry in finish_dynamic_symbol,
3368 because this might be a case of linking PIC code without
3369 linking in any dynamic objects, in which case we don't
3370 need to generate a procedure linkage table after all. */
3374 /* It does not make sense to have a procedure linkage
3375 table entry for a local symbol. */
3376 (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
3380 (long) rel->r_offset,
3381 ppc_elf_howto_table[r_type]->name);
3382 bfd_set_error (bfd_error_bad_value);
3389 if (r_type == R_PPC_PLTREL24)
3391 ppc_elf_tdata (abfd)->makes_plt_call = 1;
3392 addend = rel->r_addend;
3395 if (!update_plt_info (abfd, h, got2, addend))
3400 /* The following relocations don't need to propagate the
3401 relocation if linking a shared object since they are
3402 section relative. */
3404 case R_PPC_SECTOFF_LO:
3405 case R_PPC_SECTOFF_HI:
3406 case R_PPC_SECTOFF_HA:
3407 case R_PPC_DTPREL16:
3408 case R_PPC_DTPREL16_LO:
3409 case R_PPC_DTPREL16_HI:
3410 case R_PPC_DTPREL16_HA:
3415 case R_PPC_REL16_LO:
3416 case R_PPC_REL16_HI:
3417 case R_PPC_REL16_HA:
3418 ppc_elf_tdata (abfd)->has_rel16 = 1;
3421 /* These are just markers. */
3423 case R_PPC_EMB_MRKREF:
3428 /* These should only appear in dynamic objects. */
3430 case R_PPC_GLOB_DAT:
3431 case R_PPC_JMP_SLOT:
3432 case R_PPC_RELATIVE:
3435 /* These aren't handled yet. We'll report an error later. */
3437 case R_PPC_EMB_RELSEC16:
3438 case R_PPC_EMB_RELST_LO:
3439 case R_PPC_EMB_RELST_HI:
3440 case R_PPC_EMB_RELST_HA:
3441 case R_PPC_EMB_BIT_FLD:
3444 /* This refers only to functions defined in the shared library. */
3445 case R_PPC_LOCAL24PC:
3446 if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
3448 htab->plt_type = PLT_OLD;
3449 htab->old_bfd = abfd;
3453 /* This relocation describes the C++ object vtable hierarchy.
3454 Reconstruct it for later use during GC. */
3455 case R_PPC_GNU_VTINHERIT:
3456 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3460 /* This relocation describes which C++ vtable entries are actually
3461 used. Record for later use during GC. */
3462 case R_PPC_GNU_VTENTRY:
3463 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3467 /* We shouldn't really be seeing these. */
3470 case R_PPC_TPREL16_LO:
3471 case R_PPC_TPREL16_HI:
3472 case R_PPC_TPREL16_HA:
3473 if (!info->executable)
3474 info->flags |= DF_STATIC_TLS;
3478 case R_PPC_DTPMOD32:
3479 case R_PPC_DTPREL32:
3485 && (sec->flags & SEC_CODE) != 0
3486 && (info->shared || info->pie)
3487 && htab->plt_type == PLT_UNSET)
3489 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3490 the start of a function, which assembles to a REL32
3491 reference to .got2. If we detect one of these, then
3492 force the old PLT layout because the linker cannot
3493 reliably deduce the GOT pointer value needed for
3497 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
3501 htab->plt_type = PLT_OLD;
3502 htab->old_bfd = abfd;
3505 if (h == NULL || h == htab->elf.hgot)
3511 case R_PPC_REL14_BRTAKEN:
3512 case R_PPC_REL14_BRNTAKEN:
3515 if (h == htab->elf.hgot)
3517 if (htab->plt_type == PLT_UNSET)
3519 htab->plt_type = PLT_OLD;
3520 htab->old_bfd = abfd;
3529 case R_PPC_ADDR16_LO:
3530 case R_PPC_ADDR16_HI:
3531 case R_PPC_ADDR16_HA:
3533 case R_PPC_ADDR14_BRTAKEN:
3534 case R_PPC_ADDR14_BRNTAKEN:
3538 if (h != NULL && !info->shared)
3540 /* We may need a plt entry if the symbol turns out to be
3541 a function defined in a dynamic object. */
3542 if (!update_plt_info (abfd, h, NULL, 0))
3545 /* We may need a copy reloc too. */
3550 /* If we are creating a shared library, and this is a reloc
3551 against a global symbol, or a non PC relative reloc
3552 against a local symbol, then we need to copy the reloc
3553 into the shared library. However, if we are linking with
3554 -Bsymbolic, we do not need to copy a reloc against a
3555 global symbol which is defined in an object we are
3556 including in the link (i.e., DEF_REGULAR is set). At
3557 this point we have not seen all the input files, so it is
3558 possible that DEF_REGULAR is not set now but will be set
3559 later (it is never cleared). In case of a weak definition,
3560 DEF_REGULAR may be cleared later by a strong definition in
3561 a shared library. We account for that possibility below by
3562 storing information in the dyn_relocs field of the hash
3563 table entry. A similar situation occurs when creating
3564 shared libraries and symbol visibility changes render the
3567 If on the other hand, we are creating an executable, we
3568 may need to keep relocations for symbols satisfied by a
3569 dynamic library if we manage to avoid copy relocs for the
3572 && (must_be_dyn_reloc (info, r_type)
3574 && (! info->symbolic
3575 || h->root.type == bfd_link_hash_defweak
3576 || !h->def_regular))))
3577 || (ELIMINATE_COPY_RELOCS
3580 && (h->root.type == bfd_link_hash_defweak
3581 || !h->def_regular)))
3583 struct ppc_elf_dyn_relocs *p;
3584 struct ppc_elf_dyn_relocs **head;
3588 "ppc_elf_check_relocs needs to "
3589 "create relocation for %s\n",
3590 (h && h->root.root.string
3591 ? h->root.root.string : "<unknown>"));
3597 name = (bfd_elf_string_from_elf_section
3599 elf_elfheader (abfd)->e_shstrndx,
3600 elf_section_data (sec)->rel_hdr.sh_name));
3604 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
3605 && strcmp (bfd_get_section_name (abfd, sec),
3608 if (htab->elf.dynobj == NULL)
3609 htab->elf.dynobj = abfd;
3610 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3615 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3616 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3617 | SEC_ALLOC | SEC_LOAD);
3618 sreloc = bfd_make_section_with_flags (htab->elf.dynobj,
3622 || ! bfd_set_section_alignment (htab->elf.dynobj,
3626 elf_section_data (sec)->sreloc = sreloc;
3629 /* If this is a global symbol, we count the number of
3630 relocations we need for this symbol. */
3633 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3637 /* Track dynamic relocs needed for local syms too.
3638 We really need local syms available to do this
3644 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3649 vpp = &elf_section_data (s)->local_dynrel;
3650 head = (struct ppc_elf_dyn_relocs **) vpp;
3654 if (p == NULL || p->sec != sec)
3656 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3667 if (!must_be_dyn_reloc (info, r_type))
3679 /* Merge object attributes from IBFD into OBFD. Raise an error if
3680 there are conflicting attributes. */
3682 ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
3684 obj_attribute *in_attr;
3685 obj_attribute *out_attr;
3687 if (!elf_known_obj_attributes_proc (obfd)[0].i)
3689 /* This is the first object. Copy the attributes. */
3690 _bfd_elf_copy_obj_attributes (ibfd, obfd);
3692 /* Use the Tag_null value to indicate the attributes have been
3694 elf_known_obj_attributes_proc (obfd)[0].i = 1;
3699 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
3700 non-conflicting ones. */
3701 in_attr = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
3702 out_attr = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
3703 if (in_attr[Tag_GNU_Power_ABI_FP].i != out_attr[Tag_GNU_Power_ABI_FP].i)
3705 out_attr[Tag_GNU_Power_ABI_FP].type = 1;
3706 if (out_attr[Tag_GNU_Power_ABI_FP].i == 0)
3707 out_attr[Tag_GNU_Power_ABI_FP].i = in_attr[Tag_GNU_Power_ABI_FP].i;
3708 else if (in_attr[Tag_GNU_Power_ABI_FP].i == 0)
3710 else if (out_attr[Tag_GNU_Power_ABI_FP].i == 1
3711 && in_attr[Tag_GNU_Power_ABI_FP].i == 2)
3713 (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
3714 else if (out_attr[Tag_GNU_Power_ABI_FP].i == 2
3715 && in_attr[Tag_GNU_Power_ABI_FP].i == 1)
3717 (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
3718 else if (in_attr[Tag_GNU_Power_ABI_FP].i > 2)
3720 (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
3721 in_attr[Tag_GNU_Power_ABI_FP].i);
3724 (_("Warning: %B uses unknown floating point ABI %d"), obfd,
3725 out_attr[Tag_GNU_Power_ABI_FP].i);
3728 /* Merge Tag_compatibility attributes and any common GNU ones. */
3729 _bfd_elf_merge_object_attributes (ibfd, obfd);
3734 /* Merge backend specific data from an object file to the output
3735 object file when linking. */
3738 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
3744 if (!is_ppc_elf_target (ibfd->xvec)
3745 || !is_ppc_elf_target (obfd->xvec))
3748 /* Check if we have the same endianess. */
3749 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
3752 if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
3755 new_flags = elf_elfheader (ibfd)->e_flags;
3756 old_flags = elf_elfheader (obfd)->e_flags;
3757 if (!elf_flags_init (obfd))
3759 /* First call, no flags set. */
3760 elf_flags_init (obfd) = TRUE;
3761 elf_elfheader (obfd)->e_flags = new_flags;
3764 /* Compatible flags are ok. */
3765 else if (new_flags == old_flags)
3768 /* Incompatible flags. */
3771 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
3772 to be linked with either. */
3774 if ((new_flags & EF_PPC_RELOCATABLE) != 0
3775 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
3778 (*_bfd_error_handler)
3779 (_("%B: compiled with -mrelocatable and linked with "
3780 "modules compiled normally"), ibfd);
3782 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
3783 && (old_flags & EF_PPC_RELOCATABLE) != 0)
3786 (*_bfd_error_handler)
3787 (_("%B: compiled normally and linked with "
3788 "modules compiled with -mrelocatable"), ibfd);
3791 /* The output is -mrelocatable-lib iff both the input files are. */
3792 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
3793 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
3795 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
3796 but each input file is either -mrelocatable or -mrelocatable-lib. */
3797 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
3798 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
3799 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
3800 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
3802 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
3803 any module uses it. */
3804 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
3806 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3807 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3809 /* Warn about any other mismatches. */
3810 if (new_flags != old_flags)
3813 (*_bfd_error_handler)
3814 (_("%B: uses different e_flags (0x%lx) fields "
3815 "than previous modules (0x%lx)"),
3816 ibfd, (long) new_flags, (long) old_flags);
3821 bfd_set_error (bfd_error_bad_value);
3829 /* Choose which PLT scheme to use, and set .plt flags appropriately.
3830 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
3832 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
3833 struct bfd_link_info *info,
3834 enum ppc_elf_plt_type plt_style,
3837 struct ppc_elf_link_hash_table *htab;
3840 htab = ppc_elf_hash_table (info);
3842 if (htab->plt_type == PLT_UNSET)
3844 if (plt_style == PLT_OLD)
3845 htab->plt_type = PLT_OLD;
3849 enum ppc_elf_plt_type plt_type = plt_style;
3851 /* Look through the reloc flags left by ppc_elf_check_relocs.
3852 Use the old style bss plt if a file makes plt calls
3853 without using the new relocs, and if ld isn't given
3854 --secure-plt and we never see REL16 relocs. */
3855 if (plt_type == PLT_UNSET)
3857 for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
3858 if (is_ppc_elf_target (ibfd->xvec))
3860 if (ppc_elf_tdata (ibfd)->has_rel16)
3862 else if (ppc_elf_tdata (ibfd)->makes_plt_call)
3865 htab->old_bfd = ibfd;
3869 htab->plt_type = plt_type;
3872 if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
3873 info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd);
3875 htab->emit_stub_syms = emit_stub_syms;
3877 BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
3879 if (htab->plt_type == PLT_NEW)
3881 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3882 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3884 /* The new PLT is a loaded section. */
3885 if (htab->plt != NULL
3886 && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
3889 /* The new GOT is not executable. */
3890 if (htab->got != NULL
3891 && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
3896 /* Stop an unused .glink section from affecting .text alignment. */
3897 if (htab->glink != NULL
3898 && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
3901 return htab->plt_type == PLT_NEW;
3904 /* Return the section that should be marked against GC for a given
3908 ppc_elf_gc_mark_hook (asection *sec,
3909 struct bfd_link_info *info,
3910 Elf_Internal_Rela *rel,
3911 struct elf_link_hash_entry *h,
3912 Elf_Internal_Sym *sym)
3915 switch (ELF32_R_TYPE (rel->r_info))
3917 case R_PPC_GNU_VTINHERIT:
3918 case R_PPC_GNU_VTENTRY:
3922 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3925 /* Update the got, plt and dynamic reloc reference counts for the
3926 section being removed. */
3929 ppc_elf_gc_sweep_hook (bfd *abfd,
3930 struct bfd_link_info *info,
3932 const Elf_Internal_Rela *relocs)
3934 struct ppc_elf_link_hash_table *htab;
3935 Elf_Internal_Shdr *symtab_hdr;
3936 struct elf_link_hash_entry **sym_hashes;
3937 bfd_signed_vma *local_got_refcounts;
3938 const Elf_Internal_Rela *rel, *relend;
3941 if ((sec->flags & SEC_ALLOC) == 0)
3944 elf_section_data (sec)->local_dynrel = NULL;
3946 htab = ppc_elf_hash_table (info);
3947 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3948 sym_hashes = elf_sym_hashes (abfd);
3949 local_got_refcounts = elf_local_got_refcounts (abfd);
3950 got2 = bfd_get_section_by_name (abfd, ".got2");
3952 relend = relocs + sec->reloc_count;
3953 for (rel = relocs; rel < relend; rel++)
3955 unsigned long r_symndx;
3956 enum elf_ppc_reloc_type r_type;
3957 struct elf_link_hash_entry *h = NULL;
3959 r_symndx = ELF32_R_SYM (rel->r_info);
3960 if (r_symndx >= symtab_hdr->sh_info)
3962 struct ppc_elf_dyn_relocs **pp, *p;
3963 struct ppc_elf_link_hash_entry *eh;
3965 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3966 while (h->root.type == bfd_link_hash_indirect
3967 || h->root.type == bfd_link_hash_warning)
3968 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3969 eh = (struct ppc_elf_link_hash_entry *) h;
3971 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3974 /* Everything must go for SEC. */
3980 r_type = ELF32_R_TYPE (rel->r_info);
3983 case R_PPC_GOT_TLSLD16:
3984 case R_PPC_GOT_TLSLD16_LO:
3985 case R_PPC_GOT_TLSLD16_HI:
3986 case R_PPC_GOT_TLSLD16_HA:
3987 case R_PPC_GOT_TLSGD16:
3988 case R_PPC_GOT_TLSGD16_LO:
3989 case R_PPC_GOT_TLSGD16_HI:
3990 case R_PPC_GOT_TLSGD16_HA:
3991 case R_PPC_GOT_TPREL16:
3992 case R_PPC_GOT_TPREL16_LO:
3993 case R_PPC_GOT_TPREL16_HI:
3994 case R_PPC_GOT_TPREL16_HA:
3995 case R_PPC_GOT_DTPREL16:
3996 case R_PPC_GOT_DTPREL16_LO:
3997 case R_PPC_GOT_DTPREL16_HI:
3998 case R_PPC_GOT_DTPREL16_HA:
4000 case R_PPC_GOT16_LO:
4001 case R_PPC_GOT16_HI:
4002 case R_PPC_GOT16_HA:
4005 if (h->got.refcount > 0)
4008 else if (local_got_refcounts != NULL)
4010 if (local_got_refcounts[r_symndx] > 0)
4011 local_got_refcounts[r_symndx]--;
4017 case R_PPC_REL14_BRTAKEN:
4018 case R_PPC_REL14_BRNTAKEN:
4020 if (h == NULL || h == htab->elf.hgot)
4027 case R_PPC_ADDR16_LO:
4028 case R_PPC_ADDR16_HI:
4029 case R_PPC_ADDR16_HA:
4031 case R_PPC_ADDR14_BRTAKEN:
4032 case R_PPC_ADDR14_BRNTAKEN:
4039 case R_PPC_PLTREL24:
4040 case R_PPC_PLTREL32:
4041 case R_PPC_PLT16_LO:
4042 case R_PPC_PLT16_HI:
4043 case R_PPC_PLT16_HA:
4046 bfd_vma addend = r_type == R_PPC_PLTREL24 ? rel->r_addend : 0;
4047 struct plt_entry *ent = find_plt_ent (h, got2, addend);
4048 if (ent->plt.refcount > 0)
4049 ent->plt.refcount -= 1;
4060 /* Set plt output section type, htab->tls_get_addr, and call the
4061 generic ELF tls_setup function. */
4064 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
4066 struct ppc_elf_link_hash_table *htab;
4068 htab = ppc_elf_hash_table (info);
4069 if (htab->plt_type == PLT_NEW
4070 && htab->plt != NULL
4071 && htab->plt->output_section != NULL)
4073 elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
4074 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
4077 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
4078 FALSE, FALSE, TRUE);
4079 return _bfd_elf_tls_setup (obfd, info);
4082 /* Return TRUE iff REL is a branch reloc with a global symbol matching
4086 branch_reloc_hash_match (const bfd *ibfd,
4087 const Elf_Internal_Rela *rel,
4088 const struct elf_link_hash_entry *hash)
4090 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4091 enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
4092 unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
4094 if (r_symndx >= symtab_hdr->sh_info
4095 && (r_type == R_PPC_PLTREL24
4096 || r_type == R_PPC_LOCAL24PC
4097 || r_type == R_PPC_REL14
4098 || r_type == R_PPC_REL14_BRTAKEN
4099 || r_type == R_PPC_REL14_BRNTAKEN
4100 || r_type == R_PPC_REL24
4101 || r_type == R_PPC_ADDR24
4102 || r_type == R_PPC_ADDR14
4103 || r_type == R_PPC_ADDR14_BRTAKEN
4104 || r_type == R_PPC_ADDR14_BRNTAKEN))
4106 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
4107 struct elf_link_hash_entry *h;
4109 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4110 while (h->root.type == bfd_link_hash_indirect
4111 || h->root.type == bfd_link_hash_warning)
4112 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4119 /* Run through all the TLS relocs looking for optimization
4123 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
4124 struct bfd_link_info *info)
4128 struct ppc_elf_link_hash_table *htab;
4131 if (info->relocatable || !info->executable)
4134 htab = ppc_elf_hash_table (info);
4135 /* Make two passes through the relocs. First time check that tls
4136 relocs involved in setting up a tls_get_addr call are indeed
4137 followed by such a call. If they are not, exclude them from
4138 the optimizations done on the second pass. */
4139 for (pass = 0; pass < 2; ++pass)
4140 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4142 Elf_Internal_Sym *locsyms = NULL;
4143 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4145 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4146 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
4148 Elf_Internal_Rela *relstart, *rel, *relend;
4150 /* Read the relocations. */
4151 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
4153 if (relstart == NULL)
4156 relend = relstart + sec->reloc_count;
4157 for (rel = relstart; rel < relend; rel++)
4159 enum elf_ppc_reloc_type r_type;
4160 unsigned long r_symndx;
4161 struct elf_link_hash_entry *h = NULL;
4163 char tls_set, tls_clear;
4164 bfd_boolean is_local;
4165 int expecting_tls_get_addr;
4166 bfd_signed_vma *got_count;
4168 r_symndx = ELF32_R_SYM (rel->r_info);
4169 if (r_symndx >= symtab_hdr->sh_info)
4171 struct elf_link_hash_entry **sym_hashes;
4173 sym_hashes = elf_sym_hashes (ibfd);
4174 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4175 while (h->root.type == bfd_link_hash_indirect
4176 || h->root.type == bfd_link_hash_warning)
4177 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4180 expecting_tls_get_addr = 0;
4186 r_type = ELF32_R_TYPE (rel->r_info);
4189 case R_PPC_GOT_TLSLD16:
4190 case R_PPC_GOT_TLSLD16_LO:
4191 expecting_tls_get_addr = 1;
4194 case R_PPC_GOT_TLSLD16_HI:
4195 case R_PPC_GOT_TLSLD16_HA:
4196 /* These relocs should never be against a symbol
4197 defined in a shared lib. Leave them alone if
4198 that turns out to be the case. */
4207 case R_PPC_GOT_TLSGD16:
4208 case R_PPC_GOT_TLSGD16_LO:
4209 expecting_tls_get_addr = 1;
4212 case R_PPC_GOT_TLSGD16_HI:
4213 case R_PPC_GOT_TLSGD16_HA:
4219 tls_set = TLS_TLS | TLS_TPRELGD;
4223 case R_PPC_GOT_TPREL16:
4224 case R_PPC_GOT_TPREL16_LO:
4225 case R_PPC_GOT_TPREL16_HI:
4226 case R_PPC_GOT_TPREL16_HA:
4231 tls_clear = TLS_TPREL;
4243 if (!expecting_tls_get_addr
4244 || !sec->has_tls_get_addr_call)
4247 if (rel + 1 < relend
4248 && branch_reloc_hash_match (ibfd, rel + 1,
4249 htab->tls_get_addr))
4252 /* Uh oh, we didn't find the expected call. We
4253 could just mark this symbol to exclude it
4254 from tls optimization but it's safer to skip
4255 the entire section. */
4256 sec->has_tls_reloc = 0;
4262 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
4263 got_count = &h->got.refcount;
4267 Elf_Internal_Sym *sym;
4268 bfd_signed_vma *lgot_refs;
4271 if (locsyms == NULL)
4273 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4274 if (locsyms == NULL)
4275 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4276 symtab_hdr->sh_info,
4277 0, NULL, NULL, NULL);
4278 if (locsyms == NULL)
4280 if (elf_section_data (sec)->relocs != relstart)
4285 sym = locsyms + r_symndx;
4286 lgot_refs = elf_local_got_refcounts (ibfd);
4287 if (lgot_refs == NULL)
4289 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
4290 tls_mask = &lgot_masks[r_symndx];
4291 got_count = &lgot_refs[r_symndx];
4296 /* We managed to get rid of a got entry. */
4301 if (expecting_tls_get_addr)
4303 struct plt_entry *ent;
4305 ent = find_plt_ent (htab->tls_get_addr, NULL, 0);
4306 if (ent != NULL && ent->plt.refcount > 0)
4307 ent->plt.refcount -= 1;
4310 *tls_mask |= tls_set;
4311 *tls_mask &= ~tls_clear;
4314 if (elf_section_data (sec)->relocs != relstart)
4319 && (symtab_hdr->contents != (unsigned char *) locsyms))
4321 if (!info->keep_memory)
4324 symtab_hdr->contents = (unsigned char *) locsyms;
4330 /* Adjust a symbol defined by a dynamic object and referenced by a
4331 regular object. The current definition is in some section of the
4332 dynamic object, but we're not including those sections. We have to
4333 change the definition to something the rest of the link can
4337 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4338 struct elf_link_hash_entry *h)
4340 struct ppc_elf_link_hash_table *htab;
4344 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4345 h->root.root.string);
4348 /* Make sure we know what is going on here. */
4349 htab = ppc_elf_hash_table (info);
4350 BFD_ASSERT (htab->elf.dynobj != NULL
4352 || h->u.weakdef != NULL
4355 && !h->def_regular)));
4357 /* Deal with function syms. */
4358 if (h->type == STT_FUNC
4361 /* Clear procedure linkage table information for any symbol that
4362 won't need a .plt entry. */
4363 struct plt_entry *ent;
4364 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4365 if (ent->plt.refcount > 0)
4368 || SYMBOL_CALLS_LOCAL (info, h)
4369 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4370 && h->root.type == bfd_link_hash_undefweak))
4372 /* A PLT entry is not required/allowed when:
4374 1. We are not using ld.so; because then the PLT entry
4375 can't be set up, so we can't use one. In this case,
4376 ppc_elf_adjust_dynamic_symbol won't even be called.
4378 2. GC has rendered the entry unused.
4380 3. We know for certain that a call to this symbol
4381 will go to this object, or will remain undefined. */
4382 h->plt.plist = NULL;
4388 h->plt.plist = NULL;
4390 /* If this is a weak symbol, and there is a real definition, the
4391 processor independent code will have arranged for us to see the
4392 real definition first, and we can just use the same value. */
4393 if (h->u.weakdef != NULL)
4395 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4396 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4397 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4398 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4399 if (ELIMINATE_COPY_RELOCS)
4400 h->non_got_ref = h->u.weakdef->non_got_ref;
4404 /* This is a reference to a symbol defined by a dynamic object which
4405 is not a function. */
4407 /* If we are creating a shared library, we must presume that the
4408 only references to the symbol are via the global offset table.
4409 For such cases we need not do anything here; the relocations will
4410 be handled correctly by relocate_section. */
4414 /* If there are no references to this symbol that do not use the
4415 GOT, we don't need to generate a copy reloc. */
4416 if (!h->non_got_ref)
4419 /* If we didn't find any dynamic relocs in read-only sections, then we'll
4420 be keeping the dynamic relocs and avoiding the copy reloc. We can't
4421 do this if there are any small data relocations. */
4422 if (ELIMINATE_COPY_RELOCS
4423 && !ppc_elf_hash_entry (h)->has_sda_refs)
4425 struct ppc_elf_dyn_relocs *p;
4426 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
4428 s = p->sec->output_section;
4429 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4442 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
4443 h->root.root.string);
4447 /* We must allocate the symbol in our .dynbss section, which will
4448 become part of the .bss section of the executable. There will be
4449 an entry for this symbol in the .dynsym section. The dynamic
4450 object will contain position independent code, so all references
4451 from the dynamic object to this symbol will go through the global
4452 offset table. The dynamic linker will use the .dynsym entry to
4453 determine the address it must put in the global offset table, so
4454 both the dynamic object and the regular object will refer to the
4455 same memory location for the variable.
4457 Of course, if the symbol is referenced using SDAREL relocs, we
4458 must instead allocate it in .sbss. */
4460 if (ppc_elf_hash_entry (h)->has_sda_refs)
4464 BFD_ASSERT (s != NULL);
4466 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
4467 copy the initial value out of the dynamic object and into the
4468 runtime process image. We need to remember the offset into the
4469 .rela.bss section we are going to use. */
4470 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4474 if (ppc_elf_hash_entry (h)->has_sda_refs)
4475 srel = htab->relsbss;
4477 srel = htab->relbss;
4478 BFD_ASSERT (srel != NULL);
4479 srel->size += sizeof (Elf32_External_Rela);
4483 return _bfd_elf_adjust_dynamic_copy (h, s);
4486 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
4487 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
4488 specifying the addend on the plt relocation. For -fpic code, the sym
4489 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
4490 xxxxxxxx.got2.plt_pic32.<callee>. */
4493 add_stub_sym (struct plt_entry *ent,
4494 struct elf_link_hash_entry *h,
4495 struct bfd_link_info *info)
4497 struct elf_link_hash_entry *sh;
4498 size_t len1, len2, len3;
4501 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
4503 if (info->shared || info->pie)
4504 stub = ".plt_pic32.";
4506 stub = ".plt_call32.";
4508 len1 = strlen (h->root.root.string);
4509 len2 = strlen (stub);
4512 len3 = strlen (ent->sec->name);
4513 name = bfd_malloc (len1 + len2 + len3 + 9);
4516 sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
4518 memcpy (name + 8, ent->sec->name, len3);
4519 memcpy (name + 8 + len3, stub, len2);
4520 memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
4521 sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
4524 if (sh->root.type == bfd_link_hash_new)
4526 sh->root.type = bfd_link_hash_defined;
4527 sh->root.u.def.section = htab->glink;
4528 sh->root.u.def.value = ent->glink_offset;
4529 sh->ref_regular = 1;
4530 sh->def_regular = 1;
4531 sh->ref_regular_nonweak = 1;
4532 sh->forced_local = 1;
4538 /* Allocate NEED contiguous space in .got, and return the offset.
4539 Handles allocation of the got header when crossing 32k. */
4542 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
4545 unsigned int max_before_header;
4547 if (htab->plt_type == PLT_VXWORKS)
4549 where = htab->got->size;
4550 htab->got->size += need;
4554 max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
4555 if (need <= htab->got_gap)
4557 where = max_before_header - htab->got_gap;
4558 htab->got_gap -= need;
4562 if (htab->got->size + need > max_before_header
4563 && htab->got->size <= max_before_header)
4565 htab->got_gap = max_before_header - htab->got->size;
4566 htab->got->size = max_before_header + htab->got_header_size;
4568 where = htab->got->size;
4569 htab->got->size += need;
4575 /* Allocate space in associated reloc sections for dynamic relocs. */
4578 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4580 struct bfd_link_info *info = inf;
4581 struct ppc_elf_link_hash_entry *eh;
4582 struct ppc_elf_link_hash_table *htab;
4583 struct ppc_elf_dyn_relocs *p;
4585 if (h->root.type == bfd_link_hash_indirect)
4588 if (h->root.type == bfd_link_hash_warning)
4589 /* When warning symbols are created, they **replace** the "real"
4590 entry in the hash table, thus we never get to see the real
4591 symbol in a hash traversal. So look at it now. */
4592 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4594 htab = ppc_elf_hash_table (info);
4595 if (htab->elf.dynamic_sections_created)
4597 struct plt_entry *ent;
4598 bfd_boolean doneone = FALSE;
4599 bfd_vma plt_offset = 0, glink_offset = 0;
4601 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4602 if (ent->plt.refcount > 0)
4604 /* Make sure this symbol is output as a dynamic symbol. */
4605 if (h->dynindx == -1
4606 && !h->forced_local)
4608 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4613 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
4615 asection *s = htab->plt;
4617 if (htab->plt_type == PLT_NEW)
4621 plt_offset = s->size;
4624 ent->plt.offset = plt_offset;
4627 if (!doneone || info->shared || info->pie)
4629 glink_offset = s->size;
4630 s->size += GLINK_ENTRY_SIZE;
4636 h->root.u.def.section = s;
4637 h->root.u.def.value = glink_offset;
4639 ent->glink_offset = glink_offset;
4641 if (htab->emit_stub_syms
4642 && !add_stub_sym (ent, h, info))
4649 /* If this is the first .plt entry, make room
4650 for the special first entry. */
4652 s->size += htab->plt_initial_entry_size;
4654 /* The PowerPC PLT is actually composed of two
4655 parts, the first part is 2 words (for a load
4656 and a jump), and then there is a remaining
4657 word available at the end. */
4658 plt_offset = (htab->plt_initial_entry_size
4659 + (htab->plt_slot_size
4661 - htab->plt_initial_entry_size)
4662 / htab->plt_entry_size)));
4664 /* If this symbol is not defined in a regular
4665 file, and we are not generating a shared
4666 library, then set the symbol to this location
4667 in the .plt. This is required to make
4668 function pointers compare as equal between
4669 the normal executable and the shared library. */
4673 h->root.u.def.section = s;
4674 h->root.u.def.value = plt_offset;
4677 /* Make room for this entry. */
4678 s->size += htab->plt_entry_size;
4679 /* After the 8192nd entry, room for two entries
4681 if (htab->plt_type == PLT_OLD
4682 && (s->size - htab->plt_initial_entry_size)
4683 / htab->plt_entry_size
4684 > PLT_NUM_SINGLE_ENTRIES)
4685 s->size += htab->plt_entry_size;
4687 ent->plt.offset = plt_offset;
4690 /* We also need to make an entry in the .rela.plt section. */
4693 htab->relplt->size += sizeof (Elf32_External_Rela);
4695 if (htab->plt_type == PLT_VXWORKS)
4697 /* Allocate space for the unloaded relocations. */
4701 == (bfd_vma) htab->plt_initial_entry_size)
4703 htab->srelplt2->size
4704 += sizeof (Elf32_External_Rela)
4705 * VXWORKS_PLTRESOLVE_RELOCS;
4708 htab->srelplt2->size
4709 += sizeof (Elf32_External_Rela)
4710 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS;
4713 /* Every PLT entry has an associated GOT entry in
4715 htab->sgotplt->size += 4;
4721 ent->plt.offset = (bfd_vma) -1;
4724 ent->plt.offset = (bfd_vma) -1;
4728 h->plt.plist = NULL;
4734 h->plt.plist = NULL;
4738 eh = (struct ppc_elf_link_hash_entry *) h;
4739 if (eh->elf.got.refcount > 0)
4741 /* Make sure this symbol is output as a dynamic symbol. */
4742 if (eh->elf.dynindx == -1
4743 && !eh->elf.forced_local)
4745 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
4749 if (eh->tls_mask == (TLS_TLS | TLS_LD)
4750 && !eh->elf.def_dynamic)
4752 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4753 htab->tlsld_got.refcount += 1;
4754 eh->elf.got.offset = (bfd_vma) -1;
4759 unsigned int need = 0;
4760 if ((eh->tls_mask & TLS_TLS) != 0)
4762 if ((eh->tls_mask & TLS_LD) != 0)
4764 if ((eh->tls_mask & TLS_GD) != 0)
4766 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
4768 if ((eh->tls_mask & TLS_DTPREL) != 0)
4773 eh->elf.got.offset = allocate_got (htab, need);
4774 dyn = htab->elf.dynamic_sections_created;
4776 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
4777 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
4778 || eh->elf.root.type != bfd_link_hash_undefweak))
4780 /* All the entries we allocated need relocs.
4781 Except LD only needs one. */
4782 if ((eh->tls_mask & TLS_LD) != 0)
4784 htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4);
4789 eh->elf.got.offset = (bfd_vma) -1;
4791 if (eh->dyn_relocs == NULL)
4794 /* In the shared -Bsymbolic case, discard space allocated for
4795 dynamic pc-relative relocs against symbols which turn out to be
4796 defined in regular objects. For the normal shared case, discard
4797 space for relocs that have become local due to symbol visibility
4802 /* Relocs that use pc_count are those that appear on a call insn,
4803 or certain REL relocs (see must_be_dyn_reloc) that can be
4804 generated via assembly. We want calls to protected symbols to
4805 resolve directly to the function rather than going via the plt.
4806 If people want function pointer comparisons to work as expected
4807 then they should avoid writing weird assembly. */
4808 if (SYMBOL_CALLS_LOCAL (info, h))
4810 struct ppc_elf_dyn_relocs **pp;
4812 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4814 p->count -= p->pc_count;
4823 /* Also discard relocs on undefined weak syms with non-default
4825 if (eh->dyn_relocs != NULL
4826 && h->root.type == bfd_link_hash_undefweak)
4828 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4829 eh->dyn_relocs = NULL;
4831 /* Make sure undefined weak symbols are output as a dynamic
4833 else if (h->dynindx == -1
4834 && !h->forced_local)
4836 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4841 else if (ELIMINATE_COPY_RELOCS)
4843 /* For the non-shared case, discard space for relocs against
4844 symbols which turn out to need copy relocs or are not
4851 /* Make sure this symbol is output as a dynamic symbol.
4852 Undefined weak syms won't yet be marked as dynamic. */
4853 if (h->dynindx == -1
4854 && !h->forced_local)
4856 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4860 /* If that succeeded, we know we'll be keeping all the
4862 if (h->dynindx != -1)
4866 eh->dyn_relocs = NULL;
4871 /* Finally, allocate space. */
4872 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4874 asection *sreloc = elf_section_data (p->sec)->sreloc;
4875 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4881 /* Find any dynamic relocs that apply to read-only sections. */
4884 readonly_dynrelocs (struct elf_link_hash_entry *h, void *info)
4886 struct ppc_elf_dyn_relocs *p;
4888 if (h->root.type == bfd_link_hash_indirect)
4891 if (h->root.type == bfd_link_hash_warning)
4892 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4894 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
4896 asection *s = p->sec->output_section;
4899 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
4900 == (SEC_READONLY | SEC_ALLOC)))
4902 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
4904 /* Not an error, just cut short the traversal. */
4911 /* Set the sizes of the dynamic sections. */
4914 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4915 struct bfd_link_info *info)
4917 struct ppc_elf_link_hash_table *htab;
4923 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
4926 htab = ppc_elf_hash_table (info);
4927 BFD_ASSERT (htab->elf.dynobj != NULL);
4929 if (elf_hash_table (info)->dynamic_sections_created)
4931 /* Set the contents of the .interp section to the interpreter. */
4932 if (info->executable)
4934 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
4935 BFD_ASSERT (s != NULL);
4936 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4937 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4941 if (htab->plt_type == PLT_OLD)
4942 htab->got_header_size = 16;
4943 else if (htab->plt_type == PLT_NEW)
4944 htab->got_header_size = 12;
4946 /* Set up .got offsets for local syms, and space for local dynamic
4948 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4950 bfd_signed_vma *local_got;
4951 bfd_signed_vma *end_local_got;
4953 bfd_size_type locsymcount;
4954 Elf_Internal_Shdr *symtab_hdr;
4956 if (!is_ppc_elf_target (ibfd->xvec))
4959 for (s = ibfd->sections; s != NULL; s = s->next)
4961 struct ppc_elf_dyn_relocs *p;
4963 for (p = ((struct ppc_elf_dyn_relocs *)
4964 elf_section_data (s)->local_dynrel);
4968 if (!bfd_is_abs_section (p->sec)
4969 && bfd_is_abs_section (p->sec->output_section))
4971 /* Input section has been discarded, either because
4972 it is a copy of a linkonce section or due to
4973 linker script /DISCARD/, so we'll be discarding
4976 else if (p->count != 0)
4978 elf_section_data (p->sec)->sreloc->size
4979 += p->count * sizeof (Elf32_External_Rela);
4980 if ((p->sec->output_section->flags
4981 & (SEC_READONLY | SEC_ALLOC))
4982 == (SEC_READONLY | SEC_ALLOC))
4983 info->flags |= DF_TEXTREL;
4988 local_got = elf_local_got_refcounts (ibfd);
4992 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4993 locsymcount = symtab_hdr->sh_info;
4994 end_local_got = local_got + locsymcount;
4995 lgot_masks = (char *) end_local_got;
4996 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
4999 if (*lgot_masks == (TLS_TLS | TLS_LD))
5001 /* If just an LD reloc, we'll just use
5002 htab->tlsld_got.offset. */
5003 htab->tlsld_got.refcount += 1;
5004 *local_got = (bfd_vma) -1;
5008 unsigned int need = 0;
5009 if ((*lgot_masks & TLS_TLS) != 0)
5011 if ((*lgot_masks & TLS_GD) != 0)
5013 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
5015 if ((*lgot_masks & TLS_DTPREL) != 0)
5020 *local_got = allocate_got (htab, need);
5022 htab->relgot->size += (need
5023 * (sizeof (Elf32_External_Rela) / 4));
5027 *local_got = (bfd_vma) -1;
5030 /* Allocate space for global sym dynamic relocs. */
5031 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
5033 if (htab->tlsld_got.refcount > 0)
5035 htab->tlsld_got.offset = allocate_got (htab, 8);
5037 htab->relgot->size += sizeof (Elf32_External_Rela);
5040 htab->tlsld_got.offset = (bfd_vma) -1;
5042 if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
5044 unsigned int g_o_t = 32768;
5046 /* If we haven't allocated the header, do so now. When we get here,
5047 for old plt/got the got size will be 0 to 32764 (not allocated),
5048 or 32780 to 65536 (header allocated). For new plt/got, the
5049 corresponding ranges are 0 to 32768 and 32780 to 65536. */
5050 if (htab->got->size <= 32768)
5052 g_o_t = htab->got->size;
5053 if (htab->plt_type == PLT_OLD)
5055 htab->got->size += htab->got_header_size;
5058 htab->elf.hgot->root.u.def.value = g_o_t;
5061 if (htab->glink != NULL && htab->glink->size != 0)
5063 htab->glink_pltresolve = htab->glink->size;
5064 /* Space for the branch table. */
5065 htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
5066 /* Pad out to align the start of PLTresolve. */
5067 htab->glink->size += -htab->glink->size & 15;
5068 htab->glink->size += GLINK_PLTRESOLVE;
5070 if (htab->emit_stub_syms)
5072 struct elf_link_hash_entry *sh;
5073 sh = elf_link_hash_lookup (&htab->elf, "__glink",
5074 TRUE, FALSE, FALSE);
5077 if (sh->root.type == bfd_link_hash_new)
5079 sh->root.type = bfd_link_hash_defined;
5080 sh->root.u.def.section = htab->glink;
5081 sh->root.u.def.value = htab->glink_pltresolve;
5082 sh->ref_regular = 1;
5083 sh->def_regular = 1;
5084 sh->ref_regular_nonweak = 1;
5085 sh->forced_local = 1;
5088 sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
5089 TRUE, FALSE, FALSE);
5092 if (sh->root.type == bfd_link_hash_new)
5094 sh->root.type = bfd_link_hash_defined;
5095 sh->root.u.def.section = htab->glink;
5096 sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
5097 sh->ref_regular = 1;
5098 sh->def_regular = 1;
5099 sh->ref_regular_nonweak = 1;
5100 sh->forced_local = 1;
5106 /* We've now determined the sizes of the various dynamic sections.
5107 Allocate memory for them. */
5109 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
5111 bfd_boolean strip_section = TRUE;
5113 if ((s->flags & SEC_LINKER_CREATED) == 0)
5119 || s == htab->sgotplt
5121 || s == htab->dynbss
5122 || s == htab->dynsbss)
5124 /* We'd like to strip these sections if they aren't needed, but if
5125 we've exported dynamic symbols from them we must leave them.
5126 It's too late to tell BFD to get rid of the symbols. */
5127 if ((s == htab->plt || s == htab->got) && htab->elf.hplt != NULL)
5128 strip_section = FALSE;
5129 /* Strip this section if we don't need it; see the
5132 else if (s == htab->sdata[0].section
5133 || s == htab->sdata[1].section)
5135 /* Strip these too. */
5137 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
5141 /* Remember whether there are any relocation sections. */
5144 /* We use the reloc_count field as a counter if we need
5145 to copy relocs into the output file. */
5151 /* It's not one of our sections, so don't allocate space. */
5155 if (s->size == 0 && strip_section)
5157 /* If we don't need this section, strip it from the
5158 output file. This is mostly to handle .rela.bss and
5159 .rela.plt. We must create both sections in
5160 create_dynamic_sections, because they must be created
5161 before the linker maps input sections to output
5162 sections. The linker does that before
5163 adjust_dynamic_symbol is called, and it is that
5164 function which decides whether anything needs to go
5165 into these sections. */
5166 s->flags |= SEC_EXCLUDE;
5170 if ((s->flags & SEC_HAS_CONTENTS) == 0)
5173 /* Allocate memory for the section contents. */
5174 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
5175 if (s->contents == NULL)
5179 if (htab->elf.dynamic_sections_created)
5181 /* Add some entries to the .dynamic section. We fill in the
5182 values later, in ppc_elf_finish_dynamic_sections, but we
5183 must add the entries now so that we get the correct size for
5184 the .dynamic section. The DT_DEBUG entry is filled in by the
5185 dynamic linker and used by the debugger. */
5186 #define add_dynamic_entry(TAG, VAL) \
5187 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5189 if (info->executable)
5191 if (!add_dynamic_entry (DT_DEBUG, 0))
5195 if (htab->plt != NULL && htab->plt->size != 0)
5197 if (!add_dynamic_entry (DT_PLTGOT, 0)
5198 || !add_dynamic_entry (DT_PLTRELSZ, 0)
5199 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
5200 || !add_dynamic_entry (DT_JMPREL, 0))
5204 if (htab->glink != NULL && htab->glink->size != 0)
5206 if (!add_dynamic_entry (DT_PPC_GOT, 0))
5212 if (!add_dynamic_entry (DT_RELA, 0)
5213 || !add_dynamic_entry (DT_RELASZ, 0)
5214 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
5218 /* If any dynamic relocs apply to a read-only section, then we
5219 need a DT_TEXTREL entry. */
5220 if ((info->flags & DF_TEXTREL) == 0)
5221 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
5224 if ((info->flags & DF_TEXTREL) != 0)
5226 if (!add_dynamic_entry (DT_TEXTREL, 0))
5230 #undef add_dynamic_entry
5235 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5237 static const int shared_stub_entry[] =
5239 0x7c0802a6, /* mflr 0 */
5240 0x429f0005, /* bcl 20, 31, .Lxxx */
5241 0x7d6802a6, /* mflr 11 */
5242 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
5243 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
5244 0x7c0803a6, /* mtlr 0 */
5245 0x7d6903a6, /* mtctr 11 */
5246 0x4e800420, /* bctr */
5249 static const int stub_entry[] =
5251 0x3d600000, /* lis 11,xxx@ha */
5252 0x396b0000, /* addi 11,11,xxx@l */
5253 0x7d6903a6, /* mtctr 11 */
5254 0x4e800420, /* bctr */
5258 ppc_elf_relax_section (bfd *abfd,
5260 struct bfd_link_info *link_info,
5265 struct one_fixup *next;
5271 Elf_Internal_Shdr *symtab_hdr;
5272 bfd_byte *contents = NULL;
5273 Elf_Internal_Sym *isymbuf = NULL;
5274 Elf_Internal_Rela *internal_relocs = NULL;
5275 Elf_Internal_Rela *irel, *irelend;
5276 struct one_fixup *fixups = NULL;
5277 bfd_boolean changed;
5278 struct ppc_elf_link_hash_table *htab;
5279 bfd_size_type trampoff;
5284 /* Nothing to do if there are no relocations, and no need to do
5285 anything with non-alloc sections. */
5286 if ((isec->flags & SEC_ALLOC) == 0
5287 || (isec->flags & SEC_RELOC) == 0
5288 || isec->reloc_count == 0)
5291 trampoff = (isec->size + 3) & (bfd_vma) -4;
5292 /* Space for a branch around any trampolines. */
5295 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5297 /* Get a copy of the native relocations. */
5298 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
5299 link_info->keep_memory);
5300 if (internal_relocs == NULL)
5303 htab = ppc_elf_hash_table (link_info);
5304 got2 = bfd_get_section_by_name (abfd, ".got2");
5306 irelend = internal_relocs + isec->reloc_count;
5307 for (irel = internal_relocs; irel < irelend; irel++)
5309 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
5310 bfd_vma symaddr, reladdr, toff, roff;
5312 struct one_fixup *f;
5313 size_t insn_offset = 0;
5314 bfd_vma max_branch_offset, val;
5317 unsigned char sym_type;
5322 case R_PPC_LOCAL24PC:
5323 case R_PPC_PLTREL24:
5324 max_branch_offset = 1 << 25;
5328 case R_PPC_REL14_BRTAKEN:
5329 case R_PPC_REL14_BRNTAKEN:
5330 max_branch_offset = 1 << 15;
5337 /* Get the value of the symbol referred to by the reloc. */
5338 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
5340 /* A local symbol. */
5341 Elf_Internal_Sym *isym;
5343 /* Read this BFD's local symbols. */
5344 if (isymbuf == NULL)
5346 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5347 if (isymbuf == NULL)
5348 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
5349 symtab_hdr->sh_info, 0,
5354 isym = isymbuf + ELF32_R_SYM (irel->r_info);
5355 if (isym->st_shndx == SHN_UNDEF)
5356 continue; /* We can't do anything with undefined symbols. */
5357 else if (isym->st_shndx == SHN_ABS)
5358 tsec = bfd_abs_section_ptr;
5359 else if (isym->st_shndx == SHN_COMMON)
5360 tsec = bfd_com_section_ptr;
5362 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
5364 toff = isym->st_value;
5365 sym_type = ELF_ST_TYPE (isym->st_info);
5369 /* Global symbol handling. */
5371 struct elf_link_hash_entry *h;
5373 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
5374 h = elf_sym_hashes (abfd)[indx];
5376 while (h->root.type == bfd_link_hash_indirect
5377 || h->root.type == bfd_link_hash_warning)
5378 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5382 if (r_type == R_PPC_PLTREL24
5383 && htab->plt != NULL)
5385 struct plt_entry *ent = find_plt_ent (h, got2, irel->r_addend);
5389 if (htab->plt_type == PLT_NEW)
5392 toff = ent->glink_offset;
5397 toff = ent->plt.offset;
5403 else if (h->root.type == bfd_link_hash_defined
5404 || h->root.type == bfd_link_hash_defweak)
5406 tsec = h->root.u.def.section;
5407 toff = h->root.u.def.value;
5415 /* If the branch and target are in the same section, you have
5416 no hope of adding stubs. We'll error out later should the
5421 /* There probably isn't any reason to handle symbols in
5422 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
5423 attribute for a code section, and we are only looking at
5424 branches. However, implement it correctly here as a
5425 reference for other target relax_section functions. */
5426 if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
5428 /* At this stage in linking, no SEC_MERGE symbol has been
5429 adjusted, so all references to such symbols need to be
5430 passed through _bfd_merged_section_offset. (Later, in
5431 relocate_section, all SEC_MERGE symbols *except* for
5432 section symbols have been adjusted.)
5434 gas may reduce relocations against symbols in SEC_MERGE
5435 sections to a relocation against the section symbol when
5436 the original addend was zero. When the reloc is against
5437 a section symbol we should include the addend in the
5438 offset passed to _bfd_merged_section_offset, since the
5439 location of interest is the original symbol. On the
5440 other hand, an access to "sym+addend" where "sym" is not
5441 a section symbol should not include the addend; Such an
5442 access is presumed to be an offset from "sym"; The
5443 location of interest is just "sym". */
5444 if (sym_type == STT_SECTION)
5445 toff += irel->r_addend;
5447 toff = _bfd_merged_section_offset (abfd, &tsec,
5448 elf_section_data (tsec)->sec_info,
5451 if (sym_type != STT_SECTION)
5452 toff += irel->r_addend;
5454 /* PLTREL24 addends are special. */
5455 else if (r_type != R_PPC_PLTREL24)
5456 toff += irel->r_addend;
5458 /* Attempted -shared link of non-pic code loses. */
5459 if (tsec->output_section == NULL)
5462 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
5464 roff = irel->r_offset;
5465 reladdr = isec->output_section->vma + isec->output_offset + roff;
5467 /* If the branch is in range, no need to do anything. */
5468 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
5471 /* Look for an existing fixup to this address. */
5472 for (f = fixups; f ; f = f->next)
5473 if (f->tsec == tsec && f->toff == toff)
5479 unsigned long stub_rtype;
5481 val = trampoff - roff;
5482 if (val >= max_branch_offset)
5483 /* Oh dear, we can't reach a trampoline. Don't try to add
5484 one. We'll report an error later. */
5487 if (link_info->shared)
5489 size = 4 * ARRAY_SIZE (shared_stub_entry);
5491 stub_rtype = R_PPC_RELAX32PC;
5495 size = 4 * ARRAY_SIZE (stub_entry);
5497 stub_rtype = R_PPC_RELAX32;
5500 if (R_PPC_RELAX32_PLT - R_PPC_RELAX32
5501 != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC)
5503 if (tsec == htab->plt
5504 || tsec == htab->glink)
5505 stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32;
5507 /* Hijack the old relocation. Since we need two
5508 relocations for this use a "composite" reloc. */
5509 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
5511 irel->r_offset = trampoff + insn_offset;
5513 /* Record the fixup so we don't do it again this section. */
5514 f = bfd_malloc (sizeof (*f));
5518 f->trampoff = trampoff;
5525 val = f->trampoff - roff;
5526 if (val >= max_branch_offset)
5529 /* Nop out the reloc, since we're finalizing things here. */
5530 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
5533 /* Get the section contents. */
5534 if (contents == NULL)
5536 /* Get cached copy if it exists. */
5537 if (elf_section_data (isec)->this_hdr.contents != NULL)
5538 contents = elf_section_data (isec)->this_hdr.contents;
5541 /* Go get them off disk. */
5542 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
5547 /* Fix up the existing branch to hit the trampoline. */
5548 hit_addr = contents + roff;
5552 case R_PPC_LOCAL24PC:
5553 case R_PPC_PLTREL24:
5554 t0 = bfd_get_32 (abfd, hit_addr);
5556 t0 |= val & 0x3fffffc;
5557 bfd_put_32 (abfd, t0, hit_addr);
5561 case R_PPC_REL14_BRTAKEN:
5562 case R_PPC_REL14_BRNTAKEN:
5563 t0 = bfd_get_32 (abfd, hit_addr);
5566 bfd_put_32 (abfd, t0, hit_addr);
5571 /* Write out the trampolines. */
5572 changed = fixups != NULL;
5582 struct one_fixup *f = fixups;
5583 fixups = fixups->next;
5588 contents = bfd_realloc (contents, trampoff);
5589 if (contents == NULL)
5592 isec->size = (isec->size + 3) & (bfd_vma) -4;
5593 /* Branch around the trampolines. */
5594 val = trampoff - isec->size + 0x48000000;
5595 dest = contents + isec->size;
5596 isec->size = trampoff;
5597 bfd_put_32 (abfd, val, dest);
5600 if (link_info->shared)
5602 stub = shared_stub_entry;
5603 size = ARRAY_SIZE (shared_stub_entry);
5608 size = ARRAY_SIZE (stub_entry);
5612 while (dest < contents + trampoff)
5614 bfd_put_32 (abfd, stub[i], dest);
5620 BFD_ASSERT (i == 0);
5624 && symtab_hdr->contents != (unsigned char *) isymbuf)
5626 if (! link_info->keep_memory)
5630 /* Cache the symbols for elf_link_input_bfd. */
5631 symtab_hdr->contents = (unsigned char *) isymbuf;
5635 if (contents != NULL
5636 && elf_section_data (isec)->this_hdr.contents != contents)
5638 if (!changed && !link_info->keep_memory)
5642 /* Cache the section contents for elf_link_input_bfd. */
5643 elf_section_data (isec)->this_hdr.contents = contents;
5647 if (elf_section_data (isec)->relocs != internal_relocs)
5650 free (internal_relocs);
5652 elf_section_data (isec)->relocs = internal_relocs;
5659 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
5661 if (contents != NULL
5662 && elf_section_data (isec)->this_hdr.contents != contents)
5664 if (internal_relocs != NULL
5665 && elf_section_data (isec)->relocs != internal_relocs)
5666 free (internal_relocs);
5670 /* What to do when ld finds relocations against symbols defined in
5671 discarded sections. */
5674 ppc_elf_action_discarded (asection *sec)
5676 if (strcmp (".fixup", sec->name) == 0)
5679 if (strcmp (".got2", sec->name) == 0)
5682 return _bfd_elf_default_action_discarded (sec);
5685 /* Fill in the address for a pointer generated in a linker section. */
5688 elf_finish_pointer_linker_section (bfd *input_bfd,
5689 elf_linker_section_t *lsect,
5690 struct elf_link_hash_entry *h,
5692 const Elf_Internal_Rela *rel)
5694 elf_linker_section_pointers_t *linker_section_ptr;
5696 BFD_ASSERT (lsect != NULL);
5700 /* Handle global symbol. */
5701 struct ppc_elf_link_hash_entry *eh;
5703 eh = (struct ppc_elf_link_hash_entry *) h;
5704 BFD_ASSERT (eh->elf.def_regular);
5705 linker_section_ptr = eh->linker_section_pointer;
5709 /* Handle local symbol. */
5710 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
5712 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
5713 linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
5716 linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
5719 BFD_ASSERT (linker_section_ptr != NULL);
5721 /* Offset will always be a multiple of four, so use the bottom bit
5722 as a "written" flag. */
5723 if ((linker_section_ptr->offset & 1) == 0)
5725 bfd_put_32 (lsect->section->owner,
5726 relocation + linker_section_ptr->addend,
5727 lsect->section->contents + linker_section_ptr->offset);
5728 linker_section_ptr->offset += 1;
5731 relocation = (lsect->section->output_offset
5732 + linker_section_ptr->offset - 1
5737 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
5738 lsect->name, (long) relocation, (long) relocation);
5741 /* Subtract out the addend, because it will get added back in by the normal
5743 return relocation - linker_section_ptr->addend;
5746 /* The RELOCATE_SECTION function is called by the ELF backend linker
5747 to handle the relocations for a section.
5749 The relocs are always passed as Rela structures; if the section
5750 actually uses Rel structures, the r_addend field will always be
5753 This function is responsible for adjust the section contents as
5754 necessary, and (if using Rela relocs and generating a
5755 relocatable output file) adjusting the reloc addend as
5758 This function does not have to worry about setting the reloc
5759 address or the reloc symbol index.
5761 LOCAL_SYMS is a pointer to the swapped in local symbols.
5763 LOCAL_SECTIONS is an array giving the section in the input file
5764 corresponding to the st_shndx field of each local symbol.
5766 The global hash table entry for the global symbols can be found
5767 via elf_sym_hashes (input_bfd).
5769 When generating relocatable output, this function must handle
5770 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5771 going to be the section symbol corresponding to the output
5772 section, which means that the addend must be adjusted
5776 ppc_elf_relocate_section (bfd *output_bfd,
5777 struct bfd_link_info *info,
5779 asection *input_section,
5781 Elf_Internal_Rela *relocs,
5782 Elf_Internal_Sym *local_syms,
5783 asection **local_sections)
5785 Elf_Internal_Shdr *symtab_hdr;
5786 struct elf_link_hash_entry **sym_hashes;
5787 struct ppc_elf_link_hash_table *htab;
5788 Elf_Internal_Rela *rel;
5789 Elf_Internal_Rela *relend;
5790 Elf_Internal_Rela outrel;
5792 asection *got2, *sreloc = NULL;
5793 bfd_vma *local_got_offsets;
5794 bfd_boolean ret = TRUE;
5795 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
5798 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
5799 "%ld relocations%s",
5800 input_bfd, input_section,
5801 (long) input_section->reloc_count,
5802 (info->relocatable) ? " (relocatable)" : "");
5805 got2 = bfd_get_section_by_name (input_bfd, ".got2");
5807 /* Initialize howto table if not already done. */
5808 if (!ppc_elf_howto_table[R_PPC_ADDR32])
5809 ppc_elf_howto_init ();
5811 htab = ppc_elf_hash_table (info);
5812 local_got_offsets = elf_local_got_offsets (input_bfd);
5813 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5814 sym_hashes = elf_sym_hashes (input_bfd);
5816 relend = relocs + input_section->reloc_count;
5817 for (; rel < relend; rel++)
5819 enum elf_ppc_reloc_type r_type;
5821 bfd_reloc_status_type r;
5822 Elf_Internal_Sym *sym;
5824 struct elf_link_hash_entry *h;
5825 const char *sym_name;
5826 reloc_howto_type *howto;
5827 unsigned long r_symndx;
5829 bfd_vma branch_bit, insn, from;
5830 bfd_boolean unresolved_reloc;
5832 unsigned int tls_type, tls_mask, tls_gd;
5834 r_type = ELF32_R_TYPE (rel->r_info);
5838 unresolved_reloc = FALSE;
5840 r_symndx = ELF32_R_SYM (rel->r_info);
5842 if (r_symndx < symtab_hdr->sh_info)
5844 sym = local_syms + r_symndx;
5845 sec = local_sections[r_symndx];
5846 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
5848 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5852 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5853 r_symndx, symtab_hdr, sym_hashes,
5855 unresolved_reloc, warned);
5857 sym_name = h->root.root.string;
5860 if (sec != NULL && elf_discarded_section (sec))
5862 /* For relocs against symbols from removed linkonce sections,
5863 or sections discarded by a linker script, we just want the
5864 section contents zeroed. Avoid any special processing. */
5866 if (r_type < R_PPC_max)
5867 howto = ppc_elf_howto_table[r_type];
5868 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
5874 if (info->relocatable)
5877 && r_type == R_PPC_PLTREL24
5878 && rel->r_addend >= 32768)
5880 /* R_PPC_PLTREL24 is rather special. If non-zero, the
5881 addend specifies the GOT pointer offset within .got2. */
5882 rel->r_addend += got2->output_offset;
5887 /* TLS optimizations. Replace instruction sequences and relocs
5888 based on information we collected in tls_optimize. We edit
5889 RELOCS so that --emit-relocs will output something sensible
5890 for the final instruction stream. */
5894 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
5895 else if (local_got_offsets != NULL)
5898 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
5899 tls_mask = lgot_masks[r_symndx];
5902 /* Ensure reloc mapping code below stays sane. */
5903 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
5904 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
5905 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
5906 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
5907 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
5908 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
5909 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
5910 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
5917 case R_PPC_GOT_TPREL16:
5918 case R_PPC_GOT_TPREL16_LO:
5920 && (tls_mask & TLS_TPREL) == 0)
5923 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
5925 insn |= 0x3c020000; /* addis 0,2,0 */
5926 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
5927 r_type = R_PPC_TPREL16_HA;
5928 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5934 && (tls_mask & TLS_TPREL) == 0)
5937 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5938 if ((insn & ((31 << 26) | (31 << 11)))
5939 == ((31 << 26) | (2 << 11)))
5940 rtra = insn & ((1 << 26) - (1 << 16));
5941 else if ((insn & ((31 << 26) | (31 << 16)))
5942 == ((31 << 26) | (2 << 16)))
5943 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
5946 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
5949 else if ((insn & (31 << 1)) == 23 << 1
5950 && ((insn & (31 << 6)) < 14 << 6
5951 || ((insn & (31 << 6)) >= 16 << 6
5952 && (insn & (31 << 6)) < 24 << 6)))
5953 /* load and store indexed -> dform. */
5954 insn = (32 | ((insn >> 6) & 31)) << 26;
5955 else if ((insn & (31 << 1)) == 21 << 1
5956 && (insn & (0x1a << 6)) == 0)
5957 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
5958 insn = (((58 | ((insn >> 6) & 4)) << 26)
5959 | ((insn >> 6) & 1));
5960 else if ((insn & (31 << 1)) == 21 << 1
5961 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
5963 insn = (58 << 26) | 2;
5967 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5968 r_type = R_PPC_TPREL16_LO;
5969 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5971 /* Was PPC_TLS which sits on insn boundary, now
5972 PPC_TPREL16_LO which is at low-order half-word. */
5973 rel->r_offset += d_offset;
5977 case R_PPC_GOT_TLSGD16_HI:
5978 case R_PPC_GOT_TLSGD16_HA:
5979 tls_gd = TLS_TPRELGD;
5980 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5984 case R_PPC_GOT_TLSLD16_HI:
5985 case R_PPC_GOT_TLSLD16_HA:
5986 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5989 if ((tls_mask & tls_gd) != 0)
5990 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5991 + R_PPC_GOT_TPREL16);
5994 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
5995 rel->r_offset -= d_offset;
5996 r_type = R_PPC_NONE;
5998 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6002 case R_PPC_GOT_TLSGD16:
6003 case R_PPC_GOT_TLSGD16_LO:
6004 tls_gd = TLS_TPRELGD;
6005 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
6009 case R_PPC_GOT_TLSLD16:
6010 case R_PPC_GOT_TLSLD16_LO:
6011 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
6013 unsigned int insn1, insn2;
6017 offset = (bfd_vma) -1;
6018 /* If not using the newer R_PPC_TLSGD/LD to mark
6019 __tls_get_addr calls, we must trust that the call
6020 stays with its arg setup insns, ie. that the next
6021 reloc is the __tls_get_addr call associated with
6022 the current reloc. Edit both insns. */
6023 if (input_section->has_tls_get_addr_call
6025 && branch_reloc_hash_match (input_bfd, rel + 1,
6026 htab->tls_get_addr))
6027 offset = rel[1].r_offset;
6028 if ((tls_mask & tls_gd) != 0)
6031 insn1 = bfd_get_32 (output_bfd,
6032 contents + rel->r_offset - d_offset);
6033 insn1 &= (1 << 26) - 1;
6034 insn1 |= 32 << 26; /* lwz */
6035 if (offset != (bfd_vma) -1)
6038 = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6040 insn2 = 0x7c631214; /* add 3,3,2 */
6041 bfd_put_32 (output_bfd, insn2, contents + offset);
6043 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
6044 + R_PPC_GOT_TPREL16);
6045 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6050 insn1 = 0x3c620000; /* addis 3,2,0 */
6053 /* Was an LD reloc. */
6055 r_symndx < symtab_hdr->sh_info;
6057 if (local_sections[r_symndx] == sec)
6059 if (r_symndx >= symtab_hdr->sh_info)
6061 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
6063 rel->r_addend -= (local_syms[r_symndx].st_value
6064 + sec->output_offset
6065 + sec->output_section->vma);
6067 r_type = R_PPC_TPREL16_HA;
6068 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6069 if (offset != (bfd_vma) -1)
6071 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
6072 rel[1].r_offset = offset + d_offset;
6073 rel[1].r_addend = rel->r_addend;
6074 insn2 = 0x38630000; /* addi 3,3,0 */
6075 bfd_put_32 (output_bfd, insn2, contents + offset);
6078 bfd_put_32 (output_bfd, insn1,
6079 contents + rel->r_offset - d_offset);
6082 /* We changed the symbol on an LD reloc. Start over
6083 in order to get h, sym, sec etc. right. */
6091 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
6094 bfd_vma offset = rel->r_offset;
6096 if ((tls_mask & TLS_TPRELGD) != 0)
6099 r_type = R_PPC_NONE;
6100 insn2 = 0x7c631214; /* add 3,3,2 */
6105 r_type = R_PPC_TPREL16_LO;
6106 rel->r_offset += d_offset;
6107 insn2 = 0x38630000; /* addi 3,3,0 */
6109 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6110 bfd_put_32 (output_bfd, insn2, contents + offset);
6111 /* Zap the reloc on the _tls_get_addr call too. */
6112 BFD_ASSERT (offset == rel[1].r_offset);
6113 rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6119 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
6124 r_symndx < symtab_hdr->sh_info;
6126 if (local_sections[r_symndx] == sec)
6128 if (r_symndx >= symtab_hdr->sh_info)
6130 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
6132 rel->r_addend -= (local_syms[r_symndx].st_value
6133 + sec->output_offset
6134 + sec->output_section->vma);
6136 rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
6137 rel->r_offset += d_offset;
6138 insn2 = 0x38630000; /* addi 3,3,0 */
6139 bfd_put_32 (output_bfd, insn2,
6140 contents + rel->r_offset - d_offset);
6141 /* Zap the reloc on the _tls_get_addr call too. */
6142 BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
6143 rel[1].r_info = ELF32_R_INFO (ELF32_R_SYM (rel[1].r_info),
6151 /* Handle other relocations that tweak non-addend part of insn. */
6158 /* Branch taken prediction relocations. */
6159 case R_PPC_ADDR14_BRTAKEN:
6160 case R_PPC_REL14_BRTAKEN:
6161 branch_bit = BRANCH_PREDICT_BIT;
6164 /* Branch not taken prediction relocations. */
6165 case R_PPC_ADDR14_BRNTAKEN:
6166 case R_PPC_REL14_BRNTAKEN:
6167 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
6168 insn &= ~BRANCH_PREDICT_BIT;
6171 from = (rel->r_offset
6172 + input_section->output_offset
6173 + input_section->output_section->vma);
6175 /* Invert 'y' bit if not the default. */
6176 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
6177 insn ^= BRANCH_PREDICT_BIT;
6179 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
6183 addend = rel->r_addend;
6186 if (r_type < R_PPC_max)
6187 howto = ppc_elf_howto_table[r_type];
6188 switch ((int) r_type)
6191 (*_bfd_error_handler)
6192 (_("%B: unknown relocation type %d for symbol %s"),
6193 input_bfd, (int) r_type, sym_name);
6195 bfd_set_error (bfd_error_bad_value);
6203 case R_PPC_EMB_MRKREF:
6204 case R_PPC_GNU_VTINHERIT:
6205 case R_PPC_GNU_VTENTRY:
6208 /* GOT16 relocations. Like an ADDR16 using the symbol's
6209 address in the GOT as relocation value instead of the
6210 symbol's value itself. Also, create a GOT entry for the
6211 symbol and put the symbol value there. */
6212 case R_PPC_GOT_TLSGD16:
6213 case R_PPC_GOT_TLSGD16_LO:
6214 case R_PPC_GOT_TLSGD16_HI:
6215 case R_PPC_GOT_TLSGD16_HA:
6216 tls_type = TLS_TLS | TLS_GD;
6219 case R_PPC_GOT_TLSLD16:
6220 case R_PPC_GOT_TLSLD16_LO:
6221 case R_PPC_GOT_TLSLD16_HI:
6222 case R_PPC_GOT_TLSLD16_HA:
6223 tls_type = TLS_TLS | TLS_LD;
6226 case R_PPC_GOT_TPREL16:
6227 case R_PPC_GOT_TPREL16_LO:
6228 case R_PPC_GOT_TPREL16_HI:
6229 case R_PPC_GOT_TPREL16_HA:
6230 tls_type = TLS_TLS | TLS_TPREL;
6233 case R_PPC_GOT_DTPREL16:
6234 case R_PPC_GOT_DTPREL16_LO:
6235 case R_PPC_GOT_DTPREL16_HI:
6236 case R_PPC_GOT_DTPREL16_HA:
6237 tls_type = TLS_TLS | TLS_DTPREL;
6241 case R_PPC_GOT16_LO:
6242 case R_PPC_GOT16_HI:
6243 case R_PPC_GOT16_HA:
6247 /* Relocation is to the entry for this symbol in the global
6253 if (htab->got == NULL)
6257 if (tls_type == (TLS_TLS | TLS_LD)
6259 || !h->def_dynamic))
6260 offp = &htab->tlsld_got.offset;
6264 dyn = htab->elf.dynamic_sections_created;
6265 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6267 && SYMBOL_REFERENCES_LOCAL (info, h)))
6268 /* This is actually a static link, or it is a
6269 -Bsymbolic link and the symbol is defined
6270 locally, or the symbol was forced to be local
6271 because of a version file. */
6276 unresolved_reloc = FALSE;
6278 offp = &h->got.offset;
6282 if (local_got_offsets == NULL)
6284 offp = &local_got_offsets[r_symndx];
6287 /* The offset must always be a multiple of 4. We use the
6288 least significant bit to record whether we have already
6289 processed this entry. */
6295 unsigned int tls_m = (tls_mask
6296 & (TLS_LD | TLS_GD | TLS_DTPREL
6297 | TLS_TPREL | TLS_TPRELGD));
6299 if (offp == &htab->tlsld_got.offset)
6305 /* We might have multiple got entries for this sym.
6306 Initialize them all. */
6311 if ((tls_m & TLS_LD) != 0)
6313 tls_ty = TLS_TLS | TLS_LD;
6316 else if ((tls_m & TLS_GD) != 0)
6318 tls_ty = TLS_TLS | TLS_GD;
6321 else if ((tls_m & TLS_DTPREL) != 0)
6323 tls_ty = TLS_TLS | TLS_DTPREL;
6324 tls_m &= ~TLS_DTPREL;
6326 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
6328 tls_ty = TLS_TLS | TLS_TPREL;
6332 /* Generate relocs for the dynamic linker. */
6333 if ((info->shared || indx != 0)
6335 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6336 || h->root.type != bfd_link_hash_undefweak))
6338 outrel.r_offset = (htab->got->output_section->vma
6339 + htab->got->output_offset
6341 outrel.r_addend = 0;
6342 if (tls_ty & (TLS_LD | TLS_GD))
6344 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
6345 if (tls_ty == (TLS_TLS | TLS_GD))
6347 loc = htab->relgot->contents;
6348 loc += (htab->relgot->reloc_count++
6349 * sizeof (Elf32_External_Rela));
6350 bfd_elf32_swap_reloca_out (output_bfd,
6352 outrel.r_offset += 4;
6354 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
6357 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
6358 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
6359 else if (tls_ty == (TLS_TLS | TLS_TPREL))
6360 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
6362 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
6364 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
6367 outrel.r_addend += relocation;
6368 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
6369 outrel.r_addend -= htab->elf.tls_sec->vma;
6371 loc = htab->relgot->contents;
6372 loc += (htab->relgot->reloc_count++
6373 * sizeof (Elf32_External_Rela));
6374 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
6377 /* Init the .got section contents if we're not
6378 emitting a reloc. */
6381 bfd_vma value = relocation;
6383 if (tls_ty == (TLS_TLS | TLS_LD))
6385 else if (tls_ty != 0)
6387 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
6388 if (tls_ty == (TLS_TLS | TLS_TPREL))
6389 value += DTP_OFFSET - TP_OFFSET;
6391 if (tls_ty == (TLS_TLS | TLS_GD))
6393 bfd_put_32 (output_bfd, value,
6394 htab->got->contents + off + 4);
6398 bfd_put_32 (output_bfd, value,
6399 htab->got->contents + off);
6403 if (tls_ty & (TLS_LD | TLS_GD))
6412 if (off >= (bfd_vma) -2)
6415 if ((tls_type & TLS_TLS) != 0)
6417 if (tls_type != (TLS_TLS | TLS_LD))
6419 if ((tls_mask & TLS_LD) != 0
6421 || !h->def_dynamic))
6423 if (tls_type != (TLS_TLS | TLS_GD))
6425 if ((tls_mask & TLS_GD) != 0)
6427 if (tls_type != (TLS_TLS | TLS_DTPREL))
6429 if ((tls_mask & TLS_DTPREL) != 0)
6436 relocation = htab->got->output_offset + off;
6437 relocation -= htab->elf.hgot->root.u.def.value;
6439 /* Addends on got relocations don't make much sense.
6440 x+off@got is actually x@got+off, and since the got is
6441 generated by a hash table traversal, the value in the
6442 got at entry m+n bears little relation to the entry m. */
6444 (*_bfd_error_handler)
6445 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
6448 (long) rel->r_offset,
6454 /* Relocations that need no special processing. */
6455 case R_PPC_LOCAL24PC:
6456 /* It makes no sense to point a local relocation
6457 at a symbol not in this object. */
6458 if (unresolved_reloc)
6460 if (! (*info->callbacks->undefined_symbol) (info,
6461 h->root.root.string,
6471 case R_PPC_DTPREL16:
6472 case R_PPC_DTPREL16_LO:
6473 case R_PPC_DTPREL16_HI:
6474 case R_PPC_DTPREL16_HA:
6475 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
6478 /* Relocations that may need to be propagated if this is a shared
6481 case R_PPC_TPREL16_LO:
6482 case R_PPC_TPREL16_HI:
6483 case R_PPC_TPREL16_HA:
6484 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
6485 /* The TPREL16 relocs shouldn't really be used in shared
6486 libs as they will result in DT_TEXTREL being set, but
6487 support them anyway. */
6491 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
6494 case R_PPC_DTPREL32:
6495 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
6498 case R_PPC_DTPMOD32:
6504 case R_PPC_REL16_LO:
6505 case R_PPC_REL16_HI:
6506 case R_PPC_REL16_HA:
6512 case R_PPC_REL14_BRTAKEN:
6513 case R_PPC_REL14_BRNTAKEN:
6514 /* If these relocations are not to a named symbol, they can be
6515 handled right here, no need to bother the dynamic linker. */
6516 if (SYMBOL_REFERENCES_LOCAL (info, h)
6517 || h == htab->elf.hgot)
6521 /* Relocations that always need to be propagated if this is a shared
6526 case R_PPC_ADDR16_LO:
6527 case R_PPC_ADDR16_HI:
6528 case R_PPC_ADDR16_HA:
6530 case R_PPC_ADDR14_BRTAKEN:
6531 case R_PPC_ADDR14_BRNTAKEN:
6535 if ((input_section->flags & SEC_ALLOC) == 0)
6541 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6542 || h->root.type != bfd_link_hash_undefweak)
6543 && (must_be_dyn_reloc (info, r_type)
6544 || !SYMBOL_CALLS_LOCAL (info, h)))
6545 || (ELIMINATE_COPY_RELOCS
6551 && !h->def_regular))
6556 fprintf (stderr, "ppc_elf_relocate_section needs to "
6557 "create relocation for %s\n",
6558 (h && h->root.root.string
6559 ? h->root.root.string : "<unknown>"));
6562 /* When generating a shared object, these relocations
6563 are copied into the output file to be resolved at run
6569 name = (bfd_elf_string_from_elf_section
6571 elf_elfheader (input_bfd)->e_shstrndx,
6572 elf_section_data (input_section)->rel_hdr.sh_name));
6576 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
6577 && strcmp (bfd_get_section_name (input_bfd,
6581 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
6582 BFD_ASSERT (sreloc != NULL);
6588 _bfd_elf_section_offset (output_bfd, info, input_section,
6590 if (outrel.r_offset == (bfd_vma) -1
6591 || outrel.r_offset == (bfd_vma) -2)
6592 skip = (int) outrel.r_offset;
6593 outrel.r_offset += (input_section->output_section->vma
6594 + input_section->output_offset);
6597 memset (&outrel, 0, sizeof outrel);
6598 else if (!SYMBOL_REFERENCES_LOCAL (info, h))
6600 unresolved_reloc = FALSE;
6601 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6602 outrel.r_addend = rel->r_addend;
6606 outrel.r_addend = relocation + rel->r_addend;
6608 if (r_type == R_PPC_ADDR32)
6609 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
6614 if (r_symndx == 0 || bfd_is_abs_section (sec))
6616 else if (sec == NULL || sec->owner == NULL)
6618 bfd_set_error (bfd_error_bad_value);
6625 /* We are turning this relocation into one
6626 against a section symbol. It would be
6627 proper to subtract the symbol's value,
6628 osec->vma, from the emitted reloc addend,
6629 but ld.so expects buggy relocs. */
6630 osec = sec->output_section;
6631 indx = elf_section_data (osec)->dynindx;
6634 osec = htab->elf.text_index_section;
6635 indx = elf_section_data (osec)->dynindx;
6637 BFD_ASSERT (indx != 0);
6640 printf ("indx=%ld section=%s flags=%08x name=%s\n",
6641 indx, osec->name, osec->flags,
6642 h->root.root.string);
6646 outrel.r_info = ELF32_R_INFO (indx, r_type);
6650 loc = sreloc->contents;
6651 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
6652 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
6657 /* This reloc will be computed at runtime. We clear the memory
6658 so that it contains predictable value. */
6660 && ((input_section->flags & SEC_ALLOC) != 0
6661 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
6663 relocation = howto->pc_relative ? outrel.r_offset : 0;
6670 case R_PPC_RELAX32PC_PLT:
6671 case R_PPC_RELAX32_PLT:
6673 struct plt_entry *ent = find_plt_ent (h, got2, addend);
6675 if (htab->plt_type == PLT_NEW)
6676 relocation = (htab->glink->output_section->vma
6677 + htab->glink->output_offset
6678 + ent->glink_offset);
6680 relocation = (htab->plt->output_section->vma
6681 + htab->plt->output_offset
6685 if (r_type == R_PPC_RELAX32_PLT)
6689 case R_PPC_RELAX32PC:
6690 relocation -= (input_section->output_section->vma
6691 + input_section->output_offset
6692 + rel->r_offset - 4);
6701 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
6702 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
6704 /* We're clearing the bits for R_PPC_ADDR16_HA
6705 and R_PPC_ADDR16_LO here. */
6709 /* t0 is HA, t1 is LO */
6710 relocation += addend;
6711 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
6712 t1 |= relocation & 0xffff;
6714 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
6715 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
6719 /* Indirect .sdata relocation. */
6720 case R_PPC_EMB_SDAI16:
6721 BFD_ASSERT (htab->sdata[0].section != NULL);
6723 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
6724 h, relocation, rel);
6727 /* Indirect .sdata2 relocation. */
6728 case R_PPC_EMB_SDA2I16:
6729 BFD_ASSERT (htab->sdata[1].section != NULL);
6731 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
6732 h, relocation, rel);
6735 /* Handle the TOC16 reloc. We want to use the offset within the .got
6736 section, not the actual VMA. This is appropriate when generating
6737 an embedded ELF object, for which the .got section acts like the
6738 AIX .toc section. */
6739 case R_PPC_TOC16: /* phony GOT16 relocations */
6740 BFD_ASSERT (sec != NULL);
6741 BFD_ASSERT (bfd_is_und_section (sec)
6742 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
6743 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
6745 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
6748 case R_PPC_PLTREL24:
6749 /* Relocation is to the entry for this symbol in the
6750 procedure linkage table. */
6752 struct plt_entry *ent = find_plt_ent (h, got2, addend);
6756 || htab->plt == NULL)
6758 /* We didn't make a PLT entry for this symbol. This
6759 happens when statically linking PIC code, or when
6760 using -Bsymbolic. */
6764 unresolved_reloc = FALSE;
6765 if (htab->plt_type == PLT_NEW)
6766 relocation = (htab->glink->output_section->vma
6767 + htab->glink->output_offset
6768 + ent->glink_offset);
6770 relocation = (htab->plt->output_section->vma
6771 + htab->plt->output_offset
6776 /* Relocate against _SDA_BASE_. */
6777 case R_PPC_SDAREL16:
6780 struct elf_link_hash_entry *sh;
6782 BFD_ASSERT (sec != NULL);
6783 name = bfd_get_section_name (abfd, sec->output_section);
6784 if (! ((CONST_STRNEQ (name, ".sdata")
6785 && (name[6] == 0 || name[6] == '.'))
6786 || (CONST_STRNEQ (name, ".sbss")
6787 && (name[5] == 0 || name[5] == '.'))))
6789 (*_bfd_error_handler)
6790 (_("%B: the target (%s) of a %s relocation is "
6791 "in the wrong output section (%s)"),
6797 sh = htab->sdata[0].sym;
6798 addend -= (sh->root.u.def.value
6799 + sh->root.u.def.section->output_offset
6800 + sh->root.u.def.section->output_section->vma);
6804 /* Relocate against _SDA2_BASE_. */
6805 case R_PPC_EMB_SDA2REL:
6808 struct elf_link_hash_entry *sh;
6810 BFD_ASSERT (sec != NULL);
6811 name = bfd_get_section_name (abfd, sec->output_section);
6812 if (! (CONST_STRNEQ (name, ".sdata2")
6813 || CONST_STRNEQ (name, ".sbss2")))
6815 (*_bfd_error_handler)
6816 (_("%B: the target (%s) of a %s relocation is "
6817 "in the wrong output section (%s)"),
6823 bfd_set_error (bfd_error_bad_value);
6827 sh = htab->sdata[1].sym;
6828 addend -= (sh->root.u.def.value
6829 + sh->root.u.def.section->output_offset
6830 + sh->root.u.def.section->output_section->vma);
6834 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
6835 case R_PPC_EMB_SDA21:
6836 case R_PPC_EMB_RELSDA:
6840 struct elf_link_hash_entry *sh;
6842 BFD_ASSERT (sec != NULL);
6843 name = bfd_get_section_name (abfd, sec->output_section);
6844 if (((CONST_STRNEQ (name, ".sdata")
6845 && (name[6] == 0 || name[6] == '.'))
6846 || (CONST_STRNEQ (name, ".sbss")
6847 && (name[5] == 0 || name[5] == '.'))))
6850 sh = htab->sdata[0].sym;
6851 addend -= (sh->root.u.def.value
6852 + sh->root.u.def.section->output_offset
6853 + sh->root.u.def.section->output_section->vma);
6856 else if (CONST_STRNEQ (name, ".sdata2")
6857 || CONST_STRNEQ (name, ".sbss2"))
6860 sh = htab->sdata[1].sym;
6861 addend -= (sh->root.u.def.value
6862 + sh->root.u.def.section->output_offset
6863 + sh->root.u.def.section->output_section->vma);
6866 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
6867 || strcmp (name, ".PPC.EMB.sbss0") == 0)
6874 (*_bfd_error_handler)
6875 (_("%B: the target (%s) of a %s relocation is "
6876 "in the wrong output section (%s)"),
6882 bfd_set_error (bfd_error_bad_value);
6887 if (r_type == R_PPC_EMB_SDA21)
6888 { /* fill in register field */
6889 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
6890 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
6891 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
6896 /* Relocate against the beginning of the section. */
6898 case R_PPC_SECTOFF_LO:
6899 case R_PPC_SECTOFF_HI:
6900 case R_PPC_SECTOFF_HA:
6901 BFD_ASSERT (sec != NULL);
6902 addend -= sec->output_section->vma;
6905 /* Negative relocations. */
6906 case R_PPC_EMB_NADDR32:
6907 case R_PPC_EMB_NADDR16:
6908 case R_PPC_EMB_NADDR16_LO:
6909 case R_PPC_EMB_NADDR16_HI:
6910 case R_PPC_EMB_NADDR16_HA:
6911 addend -= 2 * relocation;
6915 case R_PPC_GLOB_DAT:
6916 case R_PPC_JMP_SLOT:
6917 case R_PPC_RELATIVE:
6919 case R_PPC_PLTREL32:
6920 case R_PPC_PLT16_LO:
6921 case R_PPC_PLT16_HI:
6922 case R_PPC_PLT16_HA:
6924 case R_PPC_EMB_RELSEC16:
6925 case R_PPC_EMB_RELST_LO:
6926 case R_PPC_EMB_RELST_HI:
6927 case R_PPC_EMB_RELST_HA:
6928 case R_PPC_EMB_BIT_FLD:
6929 (*_bfd_error_handler)
6930 (_("%B: relocation %s is not yet supported for symbol %s."),
6935 bfd_set_error (bfd_error_invalid_operation);
6940 /* Do any further special processing. */
6946 case R_PPC_ADDR16_HA:
6947 case R_PPC_REL16_HA:
6948 case R_PPC_SECTOFF_HA:
6949 case R_PPC_TPREL16_HA:
6950 case R_PPC_DTPREL16_HA:
6951 case R_PPC_EMB_NADDR16_HA:
6952 case R_PPC_EMB_RELST_HA:
6953 /* It's just possible that this symbol is a weak symbol
6954 that's not actually defined anywhere. In that case,
6955 'sec' would be NULL, and we should leave the symbol
6956 alone (it will be set to zero elsewhere in the link). */
6961 case R_PPC_PLT16_HA:
6962 case R_PPC_GOT16_HA:
6963 case R_PPC_GOT_TLSGD16_HA:
6964 case R_PPC_GOT_TLSLD16_HA:
6965 case R_PPC_GOT_TPREL16_HA:
6966 case R_PPC_GOT_DTPREL16_HA:
6967 /* Add 0x10000 if sign bit in 0:15 is set.
6968 Bits 0:15 are not used. */
6974 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
6975 "offset = %ld, addend = %ld\n",
6980 (long) rel->r_offset,
6984 if (unresolved_reloc
6985 && !((input_section->flags & SEC_DEBUGGING) != 0
6988 (*_bfd_error_handler)
6989 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6992 (long) rel->r_offset,
6998 r = _bfd_final_link_relocate (howto,
7006 if (r != bfd_reloc_ok)
7008 if (r == bfd_reloc_overflow)
7013 && h->root.type == bfd_link_hash_undefweak
7014 && howto->pc_relative)
7016 /* Assume this is a call protected by other code that
7017 detect the symbol is undefined. If this is the case,
7018 we can safely ignore the overflow. If not, the
7019 program is hosed anyway, and a little warning isn't
7025 if (! (*info->callbacks->reloc_overflow) (info,
7026 (h ? &h->root : NULL),
7037 (*_bfd_error_handler)
7038 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
7039 input_bfd, input_section,
7040 (long) rel->r_offset, howto->name, sym_name, (int) r);
7047 fprintf (stderr, "\n");
7053 #define PPC_LO(v) ((v) & 0xffff)
7054 #define PPC_HI(v) (((v) >> 16) & 0xffff)
7055 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
7057 /* Finish up dynamic symbol handling. We set the contents of various
7058 dynamic sections here. */
7061 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
7062 struct bfd_link_info *info,
7063 struct elf_link_hash_entry *h,
7064 Elf_Internal_Sym *sym)
7066 struct ppc_elf_link_hash_table *htab;
7067 struct plt_entry *ent;
7068 bfd_boolean doneone;
7071 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
7072 h->root.root.string);
7075 htab = ppc_elf_hash_table (info);
7076 BFD_ASSERT (htab->elf.dynobj != NULL);
7079 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
7080 if (ent->plt.offset != (bfd_vma) -1)
7084 Elf_Internal_Rela rela;
7086 bfd_vma reloc_index;
7088 if (htab->plt_type == PLT_NEW)
7089 reloc_index = ent->plt.offset / 4;
7092 reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
7093 / htab->plt_slot_size);
7094 if (reloc_index > PLT_NUM_SINGLE_ENTRIES
7095 && htab->plt_type == PLT_OLD)
7096 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
7099 /* This symbol has an entry in the procedure linkage table.
7101 if (htab->plt_type == PLT_VXWORKS)
7104 const bfd_vma *plt_entry;
7106 /* The first three entries in .got.plt are reserved. */
7107 got_offset = (reloc_index + 3) * 4;
7109 /* Use the right PLT. */
7110 plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
7111 : ppc_elf_vxworks_plt_entry;
7113 /* Fill in the .plt on VxWorks. */
7116 bfd_vma got_offset_hi = (got_offset >> 16)
7117 + ((got_offset & 0x8000) >> 15);
7119 bfd_put_32 (output_bfd,
7120 plt_entry[0] | (got_offset_hi & 0xffff),
7121 htab->plt->contents + ent->plt.offset + 0);
7122 bfd_put_32 (output_bfd,
7123 plt_entry[1] | (got_offset & 0xffff),
7124 htab->plt->contents + ent->plt.offset + 4);
7130 + htab->elf.hgot->root.u.def.value
7131 + htab->elf.hgot->root.u.def.section->output_offset
7132 + htab->elf.hgot->root.u.def.section->output_section->vma);
7133 bfd_vma got_loc_hi = (got_loc >> 16)
7134 + ((got_loc & 0x8000) >> 15);
7136 bfd_put_32 (output_bfd,
7137 plt_entry[0] | (got_loc_hi & 0xffff),
7138 htab->plt->contents + ent->plt.offset + 0);
7139 bfd_put_32 (output_bfd,
7140 plt_entry[1] | (got_loc & 0xffff),
7141 htab->plt->contents + ent->plt.offset + 4);
7144 bfd_put_32 (output_bfd, plt_entry[2],
7145 htab->plt->contents + ent->plt.offset + 8);
7146 bfd_put_32 (output_bfd, plt_entry[3],
7147 htab->plt->contents + ent->plt.offset + 12);
7149 /* This instruction is an immediate load. The value loaded is
7150 the byte offset of the R_PPC_JMP_SLOT relocation from the
7151 start of the .rela.plt section. The value is stored in the
7152 low-order 16 bits of the load instruction. */
7153 /* NOTE: It appears that this is now an index rather than a
7154 prescaled offset. */
7155 bfd_put_32 (output_bfd,
7156 plt_entry[4] | reloc_index,
7157 htab->plt->contents + ent->plt.offset + 16);
7158 /* This instruction is a PC-relative branch whose target is
7159 the start of the PLT section. The address of this branch
7160 instruction is 20 bytes beyond the start of this PLT entry.
7161 The address is encoded in bits 6-29, inclusive. The value
7162 stored is right-shifted by two bits, permitting a 26-bit
7164 bfd_put_32 (output_bfd,
7166 | (-(ent->plt.offset + 20) & 0x03fffffc)),
7167 htab->plt->contents + ent->plt.offset + 20);
7168 bfd_put_32 (output_bfd, plt_entry[6],
7169 htab->plt->contents + ent->plt.offset + 24);
7170 bfd_put_32 (output_bfd, plt_entry[7],
7171 htab->plt->contents + ent->plt.offset + 28);
7173 /* Fill in the GOT entry corresponding to this PLT slot with
7174 the address immediately after the the "bctr" instruction
7175 in this PLT entry. */
7176 bfd_put_32 (output_bfd, (htab->plt->output_section->vma
7177 + htab->plt->output_offset
7178 + ent->plt.offset + 16),
7179 htab->sgotplt->contents + got_offset);
7183 /* Fill in a couple of entries in .rela.plt.unloaded. */
7184 loc = htab->srelplt2->contents
7185 + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
7186 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
7187 * sizeof (Elf32_External_Rela));
7189 /* Provide the @ha relocation for the first instruction. */
7190 rela.r_offset = (htab->plt->output_section->vma
7191 + htab->plt->output_offset
7192 + ent->plt.offset + 2);
7193 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
7195 rela.r_addend = got_offset;
7196 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7197 loc += sizeof (Elf32_External_Rela);
7199 /* Provide the @l relocation for the second instruction. */
7200 rela.r_offset = (htab->plt->output_section->vma
7201 + htab->plt->output_offset
7202 + ent->plt.offset + 6);
7203 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
7205 rela.r_addend = got_offset;
7206 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7207 loc += sizeof (Elf32_External_Rela);
7209 /* Provide a relocation for the GOT entry corresponding to this
7210 PLT slot. Point it at the middle of the .plt entry. */
7211 rela.r_offset = (htab->sgotplt->output_section->vma
7212 + htab->sgotplt->output_offset
7214 rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
7216 rela.r_addend = ent->plt.offset + 16;
7217 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7220 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
7221 In particular, the offset for the relocation is not the
7222 address of the PLT entry for this function, as specified
7223 by the ABI. Instead, the offset is set to the address of
7224 the GOT slot for this function. See EABI 4.4.4.1. */
7225 rela.r_offset = (htab->sgotplt->output_section->vma
7226 + htab->sgotplt->output_offset
7232 rela.r_offset = (htab->plt->output_section->vma
7233 + htab->plt->output_offset
7235 if (htab->plt_type == PLT_OLD)
7237 /* We don't need to fill in the .plt. The ppc dynamic
7238 linker will fill it in. */
7242 bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
7243 + htab->glink->output_section->vma
7244 + htab->glink->output_offset);
7245 bfd_put_32 (output_bfd, val,
7246 htab->plt->contents + ent->plt.offset);
7250 /* Fill in the entry in the .rela.plt section. */
7251 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
7254 loc = (htab->relplt->contents
7255 + reloc_index * sizeof (Elf32_External_Rela));
7256 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7258 if (!h->def_regular)
7260 /* Mark the symbol as undefined, rather than as defined in
7261 the .plt section. Leave the value alone. */
7262 sym->st_shndx = SHN_UNDEF;
7263 /* If the symbol is weak, we do need to clear the value.
7264 Otherwise, the PLT entry would provide a definition for
7265 the symbol even if the symbol wasn't defined anywhere,
7266 and so the symbol would never be NULL. */
7267 if (!h->ref_regular_nonweak)
7273 if (htab->plt_type == PLT_NEW)
7278 plt = (ent->plt.offset
7279 + htab->plt->output_section->vma
7280 + htab->plt->output_offset);
7281 p = (unsigned char *) htab->glink->contents + ent->glink_offset;
7283 if (info->shared || info->pie)
7287 if (ent->addend >= 32768)
7289 + ent->sec->output_section->vma
7290 + ent->sec->output_offset);
7291 else if (htab->elf.hgot != NULL)
7292 got = (htab->elf.hgot->root.u.def.value
7293 + htab->elf.hgot->root.u.def.section->output_section->vma
7294 + htab->elf.hgot->root.u.def.section->output_offset);
7298 if (plt + 0x8000 < 0x10000)
7300 bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
7302 bfd_put_32 (output_bfd, MTCTR_11, p);
7304 bfd_put_32 (output_bfd, BCTR, p);
7306 bfd_put_32 (output_bfd, NOP, p);
7311 bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
7313 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
7315 bfd_put_32 (output_bfd, MTCTR_11, p);
7317 bfd_put_32 (output_bfd, BCTR, p);
7323 bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
7325 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
7327 bfd_put_32 (output_bfd, MTCTR_11, p);
7329 bfd_put_32 (output_bfd, BCTR, p);
7332 /* We only need one non-PIC glink stub. */
7343 Elf_Internal_Rela rela;
7346 /* This symbols needs a copy reloc. Set it up. */
7349 fprintf (stderr, ", copy");
7352 BFD_ASSERT (h->dynindx != -1);
7354 if (ppc_elf_hash_entry (h)->has_sda_refs)
7358 BFD_ASSERT (s != NULL);
7360 rela.r_offset = (h->root.u.def.value
7361 + h->root.u.def.section->output_section->vma
7362 + h->root.u.def.section->output_offset);
7363 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
7365 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
7366 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7370 fprintf (stderr, "\n");
7373 /* Mark some specially defined symbols as absolute. */
7374 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
7375 || (!htab->is_vxworks
7376 && (h == htab->elf.hgot
7377 || strcmp (h->root.root.string,
7378 "_PROCEDURE_LINKAGE_TABLE_") == 0)))
7379 sym->st_shndx = SHN_ABS;
7384 static enum elf_reloc_type_class
7385 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
7387 switch (ELF32_R_TYPE (rela->r_info))
7389 case R_PPC_RELATIVE:
7390 return reloc_class_relative;
7393 case R_PPC_JMP_SLOT:
7394 return reloc_class_plt;
7396 return reloc_class_copy;
7398 return reloc_class_normal;
7402 /* Finish up the dynamic sections. */
7405 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
7406 struct bfd_link_info *info)
7410 struct ppc_elf_link_hash_table *htab;
7415 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
7418 htab = ppc_elf_hash_table (info);
7419 dynobj = elf_hash_table (info)->dynobj;
7420 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
7421 if (htab->is_vxworks)
7422 splt = bfd_get_section_by_name (dynobj, ".plt");
7427 if (htab->elf.hgot != NULL)
7428 got = (htab->elf.hgot->root.u.def.value
7429 + htab->elf.hgot->root.u.def.section->output_section->vma
7430 + htab->elf.hgot->root.u.def.section->output_offset);
7432 if (htab->elf.dynamic_sections_created)
7434 Elf32_External_Dyn *dyncon, *dynconend;
7436 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
7438 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7439 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
7440 for (; dyncon < dynconend; dyncon++)
7442 Elf_Internal_Dyn dyn;
7445 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
7450 if (htab->is_vxworks)
7454 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
7458 dyn.d_un.d_val = htab->relplt->size;
7463 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
7467 dyn.d_un.d_ptr = got;
7471 if (htab->is_vxworks)
7474 dyn.d_un.d_ptr -= htab->relplt->size;
7483 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7487 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
7488 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
7489 if (htab->got != NULL)
7491 unsigned char *p = htab->got->contents;
7494 p += htab->elf.hgot->root.u.def.value;
7495 if (htab->plt_type == PLT_OLD)
7496 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
7500 val = sdyn->output_section->vma + sdyn->output_offset;
7501 bfd_put_32 (output_bfd, val, p);
7503 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
7506 /* Fill in the first entry in the VxWorks procedure linkage table. */
7507 if (splt && splt->size > 0)
7509 /* Use the right PLT. */
7510 static const bfd_vma *plt_entry = NULL;
7511 plt_entry = info->shared ?
7512 ppc_elf_vxworks_pic_plt0_entry : ppc_elf_vxworks_plt0_entry;
7517 (htab->elf.hgot->root.u.def.section->output_section->vma
7518 + htab->elf.hgot->root.u.def.section->output_offset
7519 + htab->elf.hgot->root.u.def.value);
7520 bfd_vma got_hi = (got_value >> 16) + ((got_value & 0x8000) >> 15);
7522 bfd_put_32 (output_bfd, plt_entry[0] | (got_hi & 0xffff),
7523 splt->contents + 0);
7524 bfd_put_32 (output_bfd, plt_entry[1] | (got_value & 0xffff),
7525 splt->contents + 4);
7529 bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0);
7530 bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4);
7532 bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8);
7533 bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
7534 bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
7535 bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
7536 bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
7537 bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
7541 Elf_Internal_Rela rela;
7544 loc = htab->srelplt2->contents;
7546 /* Output the @ha relocation for the first instruction. */
7547 rela.r_offset = (htab->plt->output_section->vma
7548 + htab->plt->output_offset
7550 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
7552 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7553 loc += sizeof (Elf32_External_Rela);
7555 /* Output the @l relocation for the second instruction. */
7556 rela.r_offset = (htab->plt->output_section->vma
7557 + htab->plt->output_offset
7559 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
7561 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7562 loc += sizeof (Elf32_External_Rela);
7564 /* Fix up the remaining relocations. They may have the wrong
7565 symbol index for _G_O_T_ or _P_L_T_ depending on the order
7566 in which symbols were output. */
7567 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
7569 Elf_Internal_Rela rel;
7571 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7572 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
7573 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7574 loc += sizeof (Elf32_External_Rela);
7576 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7577 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
7578 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7579 loc += sizeof (Elf32_External_Rela);
7581 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7582 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
7583 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
7584 loc += sizeof (Elf32_External_Rela);
7589 if (htab->glink != NULL && htab->glink->contents != NULL)
7592 unsigned char *endp;
7597 * PIC glink code is the following:
7599 * # ith PLT code stub.
7600 * addis 11,30,(plt+(i-1)*4-got)@ha
7601 * lwz 11,(plt+(i-1)*4-got)@l(11)
7605 * # A table of branches, one for each plt entry.
7606 * # The idea is that the plt call stub loads ctr (and r11) with these
7607 * # addresses, so (r11 - res_0) gives the plt index * 4.
7608 * res_0: b PLTresolve
7609 * res_1: b PLTresolve
7611 * # Some number of entries towards the end can be nops
7617 * addis 11,11,(1f-res_0)@ha
7620 * 1: addi 11,11,(1b-res_0)@l
7623 * sub 11,11,12 # r11 = index * 4
7624 * addis 12,12,(got+4-1b)@ha
7625 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
7626 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
7629 * add 11,0,11 # r11 = index * 12 = reloc offset.
7632 static const unsigned int pic_plt_resolve[] =
7652 static const unsigned int plt_resolve[] =
7672 if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
7674 if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
7677 /* Build the branch table, one for each plt entry (less one),
7678 and perhaps some padding. */
7679 p = htab->glink->contents;
7680 p += htab->glink_pltresolve;
7681 endp = htab->glink->contents;
7682 endp += htab->glink->size - GLINK_PLTRESOLVE;
7683 while (p < endp - 8 * 4)
7685 bfd_put_32 (output_bfd, B + endp - p, p);
7690 bfd_put_32 (output_bfd, NOP, p);
7694 res0 = (htab->glink_pltresolve
7695 + htab->glink->output_section->vma
7696 + htab->glink->output_offset);
7698 /* Last comes the PLTresolve stub. */
7699 if (info->shared || info->pie)
7703 for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
7705 bfd_put_32 (output_bfd, pic_plt_resolve[i], p);
7708 p -= 4 * ARRAY_SIZE (pic_plt_resolve);
7710 bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
7711 + htab->glink->output_section->vma
7712 + htab->glink->output_offset);
7714 bfd_put_32 (output_bfd,
7715 ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
7716 bfd_put_32 (output_bfd,
7717 ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
7718 bfd_put_32 (output_bfd,
7719 ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
7720 if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
7722 bfd_put_32 (output_bfd,
7723 LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
7724 bfd_put_32 (output_bfd,
7725 LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
7729 bfd_put_32 (output_bfd,
7730 LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
7731 bfd_put_32 (output_bfd,
7732 LWZ_12_12 + 4, p + 9*4);
7737 for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
7739 bfd_put_32 (output_bfd, plt_resolve[i], p);
7742 p -= 4 * ARRAY_SIZE (plt_resolve);
7744 bfd_put_32 (output_bfd,
7745 LIS_12 + PPC_HA (got + 4), p + 0*4);
7746 bfd_put_32 (output_bfd,
7747 ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
7748 bfd_put_32 (output_bfd,
7749 ADDI_11_11 + PPC_LO (-res0), p + 3*4);
7750 if (PPC_HA (got + 4) == PPC_HA (got + 8))
7752 bfd_put_32 (output_bfd,
7753 LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
7754 bfd_put_32 (output_bfd,
7755 LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
7759 bfd_put_32 (output_bfd,
7760 LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
7761 bfd_put_32 (output_bfd,
7762 LWZ_12_12 + 4, p + 6*4);
7770 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
7771 #define TARGET_LITTLE_NAME "elf32-powerpcle"
7772 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
7773 #define TARGET_BIG_NAME "elf32-powerpc-freebsd"
7774 #define ELF_ARCH bfd_arch_powerpc
7775 #define ELF_MACHINE_CODE EM_PPC
7776 #ifdef __QNXTARGET__
7777 #define ELF_MAXPAGESIZE 0x1000
7779 #define ELF_MAXPAGESIZE 0x10000
7781 #define ELF_MINPAGESIZE 0x1000
7782 #define ELF_COMMONPAGESIZE 0x1000
7783 #define elf_info_to_howto ppc_elf_info_to_howto
7785 #ifdef EM_CYGNUS_POWERPC
7786 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
7790 #define ELF_MACHINE_ALT2 EM_PPC_OLD
7793 #define elf_backend_plt_not_loaded 1
7794 #define elf_backend_can_gc_sections 1
7795 #define elf_backend_can_refcount 1
7796 #define elf_backend_rela_normal 1
7798 #define bfd_elf32_mkobject ppc_elf_mkobject
7799 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
7800 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
7801 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
7802 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
7803 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
7804 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
7806 #define elf_backend_object_p ppc_elf_object_p
7807 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
7808 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
7809 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
7810 #define elf_backend_relocate_section ppc_elf_relocate_section
7811 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
7812 #define elf_backend_check_relocs ppc_elf_check_relocs
7813 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
7814 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
7815 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
7816 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
7817 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
7818 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
7819 #define elf_backend_fake_sections ppc_elf_fake_sections
7820 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
7821 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
7822 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
7823 #define elf_backend_write_core_note ppc_elf_write_core_note
7824 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
7825 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
7826 #define elf_backend_final_write_processing ppc_elf_final_write_processing
7827 #define elf_backend_write_section ppc_elf_write_section
7828 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
7829 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
7830 #define elf_backend_action_discarded ppc_elf_action_discarded
7831 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
7833 #include "elf32-target.h"
7835 /* VxWorks Target */
7837 #undef TARGET_LITTLE_SYM
7838 #undef TARGET_LITTLE_NAME
7840 #undef TARGET_BIG_SYM
7841 #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
7842 #undef TARGET_BIG_NAME
7843 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
7845 /* VxWorks uses the elf default section flags for .plt. */
7846 static const struct bfd_elf_special_section *
7847 ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
7849 if (sec->name == NULL)
7852 if (strcmp (sec->name, ".plt") == 0)
7853 return _bfd_elf_get_sec_type_attr (abfd, sec);
7855 return ppc_elf_get_sec_type_attr (abfd, sec);
7858 /* Like ppc_elf_link_hash_table_create, but overrides
7859 appropriately for VxWorks. */
7860 static struct bfd_link_hash_table *
7861 ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
7863 struct bfd_link_hash_table *ret;
7865 ret = ppc_elf_link_hash_table_create (abfd);
7868 struct ppc_elf_link_hash_table *htab
7869 = (struct ppc_elf_link_hash_table *)ret;
7870 htab->is_vxworks = 1;
7871 htab->plt_type = PLT_VXWORKS;
7872 htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
7873 htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
7874 htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
7879 /* Tweak magic VxWorks symbols as they are loaded. */
7881 ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
7882 struct bfd_link_info *info,
7883 Elf_Internal_Sym *sym,
7884 const char **namep ATTRIBUTE_UNUSED,
7885 flagword *flagsp ATTRIBUTE_UNUSED,
7889 if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
7893 return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
7897 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
7899 ppc_elf_final_write_processing(abfd, linker);
7900 elf_vxworks_final_write_processing(abfd, linker);
7903 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
7905 #undef elf_backend_want_plt_sym
7906 #define elf_backend_want_plt_sym 1
7907 #undef elf_backend_want_got_plt
7908 #define elf_backend_want_got_plt 1
7909 #undef elf_backend_got_symbol_offset
7910 #define elf_backend_got_symbol_offset 0
7911 #undef elf_backend_plt_not_loaded
7912 #define elf_backend_plt_not_loaded 0
7913 #undef elf_backend_plt_readonly
7914 #define elf_backend_plt_readonly 1
7915 #undef elf_backend_got_header_size
7916 #define elf_backend_got_header_size 12
7918 #undef bfd_elf32_bfd_link_hash_table_create
7919 #define bfd_elf32_bfd_link_hash_table_create \
7920 ppc_elf_vxworks_link_hash_table_create
7921 #undef elf_backend_add_symbol_hook
7922 #define elf_backend_add_symbol_hook \
7923 ppc_elf_vxworks_add_symbol_hook
7924 #undef elf_backend_link_output_symbol_hook
7925 #define elf_backend_link_output_symbol_hook \
7926 elf_vxworks_link_output_symbol_hook
7927 #undef elf_backend_final_write_processing
7928 #define elf_backend_final_write_processing \
7929 ppc_elf_vxworks_final_write_processing
7930 #undef elf_backend_get_sec_type_attr
7931 #define elf_backend_get_sec_type_attr \
7932 ppc_elf_vxworks_get_sec_type_attr
7933 #undef elf_backend_emit_relocs
7934 #define elf_backend_emit_relocs \
7935 elf_vxworks_emit_relocs
7938 #define elf32_bed ppc_elf_vxworks_bed
7940 #include "elf32-target.h"