1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 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. */
34 #include "elf32-ppc.h"
36 /* RELA relocations are used here. */
38 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
39 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
40 static bfd_reloc_status_type ppc_elf_unhandled_reloc
41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
43 /* Branch prediction bit for branch taken relocs. */
44 #define BRANCH_PREDICT_BIT 0x200000
45 /* Mask to set RA in memory instructions. */
46 #define RA_REGISTER_MASK 0x001f0000
47 /* Value to shift register by to insert RA. */
48 #define RA_REGISTER_SHIFT 16
50 /* The name of the dynamic interpreter. This is put in the .interp
52 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
54 /* For old-style PLT. */
55 /* The size in bytes of an entry in the procedure linkage table. */
56 #define PLT_ENTRY_SIZE 12
57 /* The initial size of the plt reserved for the dynamic linker. */
58 #define PLT_INITIAL_ENTRY_SIZE 72
59 /* The size of the gap between entries in the PLT. */
60 #define PLT_SLOT_SIZE 8
61 /* The number of single-slot PLT entries (the rest use two slots). */
62 #define PLT_NUM_SINGLE_ENTRIES 8192
64 /* For new-style .glink and .plt. */
65 #define GLINK_PLTRESOLVE 12*4
66 #define GLINK_ENTRY_SIZE 4*4
68 /* Some instructions. */
69 #define NOP 0x60000000
71 #define ADDIS_11_11 0x3d6b0000
72 #define ADDI_11_11 0x396b0000
73 #define SUB_11_11_30 0x7d7e5850
74 #define ADD_0_11_11 0x7c0b5a14
75 #define ADD_11_0_11 0x7d605a14
76 #define LWZ_0_4_30 0x801e0004
77 #define MTCTR_0 0x7c0903a6
78 #define LWZ_12_8_30 0x819e0008
79 #define BCTR 0x4e800420
80 #define ADDIS_11_30 0x3d7e0000
81 #define LWZ_11_X_11 0x816b0000
82 #define LWZ_11_X_30 0x817e0000
83 #define MTCTR_11 0x7d6903a6
85 /* Offset of tp and dtp pointers from start of TLS block. */
86 #define TP_OFFSET 0x7000
87 #define DTP_OFFSET 0x8000
89 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
91 static reloc_howto_type ppc_elf_howto_raw[] = {
92 /* This reloc does nothing. */
93 HOWTO (R_PPC_NONE, /* type */
95 2, /* size (0 = byte, 1 = short, 2 = long) */
97 FALSE, /* pc_relative */
99 complain_overflow_bitfield, /* complain_on_overflow */
100 bfd_elf_generic_reloc, /* special_function */
101 "R_PPC_NONE", /* name */
102 FALSE, /* partial_inplace */
105 FALSE), /* pcrel_offset */
107 /* A standard 32 bit relocation. */
108 HOWTO (R_PPC_ADDR32, /* type */
110 2, /* size (0 = byte, 1 = short, 2 = long) */
112 FALSE, /* pc_relative */
114 complain_overflow_bitfield, /* complain_on_overflow */
115 bfd_elf_generic_reloc, /* special_function */
116 "R_PPC_ADDR32", /* name */
117 FALSE, /* partial_inplace */
119 0xffffffff, /* dst_mask */
120 FALSE), /* pcrel_offset */
122 /* An absolute 26 bit branch; the lower two bits must be zero.
123 FIXME: we don't check that, we just clear them. */
124 HOWTO (R_PPC_ADDR24, /* type */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
128 FALSE, /* pc_relative */
130 complain_overflow_bitfield, /* complain_on_overflow */
131 bfd_elf_generic_reloc, /* special_function */
132 "R_PPC_ADDR24", /* name */
133 FALSE, /* partial_inplace */
135 0x3fffffc, /* dst_mask */
136 FALSE), /* pcrel_offset */
138 /* A standard 16 bit relocation. */
139 HOWTO (R_PPC_ADDR16, /* type */
141 1, /* size (0 = byte, 1 = short, 2 = long) */
143 FALSE, /* pc_relative */
145 complain_overflow_bitfield, /* complain_on_overflow */
146 bfd_elf_generic_reloc, /* special_function */
147 "R_PPC_ADDR16", /* name */
148 FALSE, /* partial_inplace */
150 0xffff, /* dst_mask */
151 FALSE), /* pcrel_offset */
153 /* A 16 bit relocation without overflow. */
154 HOWTO (R_PPC_ADDR16_LO, /* type */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE, /* pc_relative */
160 complain_overflow_dont,/* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_PPC_ADDR16_LO", /* name */
163 FALSE, /* partial_inplace */
165 0xffff, /* dst_mask */
166 FALSE), /* pcrel_offset */
168 /* The high order 16 bits of an address. */
169 HOWTO (R_PPC_ADDR16_HI, /* type */
171 1, /* size (0 = byte, 1 = short, 2 = long) */
173 FALSE, /* pc_relative */
175 complain_overflow_dont, /* complain_on_overflow */
176 bfd_elf_generic_reloc, /* special_function */
177 "R_PPC_ADDR16_HI", /* name */
178 FALSE, /* partial_inplace */
180 0xffff, /* dst_mask */
181 FALSE), /* pcrel_offset */
183 /* The high order 16 bits of an address, plus 1 if the contents of
184 the low 16 bits, treated as a signed number, is negative. */
185 HOWTO (R_PPC_ADDR16_HA, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE, /* pc_relative */
191 complain_overflow_dont, /* complain_on_overflow */
192 ppc_elf_addr16_ha_reloc, /* special_function */
193 "R_PPC_ADDR16_HA", /* name */
194 FALSE, /* partial_inplace */
196 0xffff, /* dst_mask */
197 FALSE), /* pcrel_offset */
199 /* An absolute 16 bit branch; the lower two bits must be zero.
200 FIXME: we don't check that, we just clear them. */
201 HOWTO (R_PPC_ADDR14, /* type */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
205 FALSE, /* pc_relative */
207 complain_overflow_bitfield, /* complain_on_overflow */
208 bfd_elf_generic_reloc, /* special_function */
209 "R_PPC_ADDR14", /* name */
210 FALSE, /* partial_inplace */
212 0xfffc, /* dst_mask */
213 FALSE), /* pcrel_offset */
215 /* An absolute 16 bit branch, for which bit 10 should be set to
216 indicate that the branch is expected to be taken. The lower two
217 bits must be zero. */
218 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 FALSE, /* pc_relative */
224 complain_overflow_bitfield, /* complain_on_overflow */
225 bfd_elf_generic_reloc, /* special_function */
226 "R_PPC_ADDR14_BRTAKEN",/* name */
227 FALSE, /* partial_inplace */
229 0xfffc, /* dst_mask */
230 FALSE), /* pcrel_offset */
232 /* An absolute 16 bit branch, for which bit 10 should be set to
233 indicate that the branch is not expected to be taken. The lower
234 two bits must be zero. */
235 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
237 2, /* size (0 = byte, 1 = short, 2 = long) */
239 FALSE, /* pc_relative */
241 complain_overflow_bitfield, /* complain_on_overflow */
242 bfd_elf_generic_reloc, /* special_function */
243 "R_PPC_ADDR14_BRNTAKEN",/* name */
244 FALSE, /* partial_inplace */
246 0xfffc, /* dst_mask */
247 FALSE), /* pcrel_offset */
249 /* A relative 26 bit branch; the lower two bits must be zero. */
250 HOWTO (R_PPC_REL24, /* type */
252 2, /* size (0 = byte, 1 = short, 2 = long) */
254 TRUE, /* pc_relative */
256 complain_overflow_signed, /* complain_on_overflow */
257 bfd_elf_generic_reloc, /* special_function */
258 "R_PPC_REL24", /* name */
259 FALSE, /* partial_inplace */
261 0x3fffffc, /* dst_mask */
262 TRUE), /* pcrel_offset */
264 /* A relative 16 bit branch; the lower two bits must be zero. */
265 HOWTO (R_PPC_REL14, /* type */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
269 TRUE, /* pc_relative */
271 complain_overflow_signed, /* complain_on_overflow */
272 bfd_elf_generic_reloc, /* special_function */
273 "R_PPC_REL14", /* name */
274 FALSE, /* partial_inplace */
276 0xfffc, /* dst_mask */
277 TRUE), /* pcrel_offset */
279 /* A relative 16 bit branch. Bit 10 should be set to indicate that
280 the branch is expected to be taken. The lower two bits must be
282 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 TRUE, /* pc_relative */
288 complain_overflow_signed, /* complain_on_overflow */
289 bfd_elf_generic_reloc, /* special_function */
290 "R_PPC_REL14_BRTAKEN", /* name */
291 FALSE, /* partial_inplace */
293 0xfffc, /* dst_mask */
294 TRUE), /* pcrel_offset */
296 /* A relative 16 bit branch. Bit 10 should be set to indicate that
297 the branch is not expected to be taken. The lower two bits must
299 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 TRUE, /* pc_relative */
305 complain_overflow_signed, /* complain_on_overflow */
306 bfd_elf_generic_reloc, /* special_function */
307 "R_PPC_REL14_BRNTAKEN",/* name */
308 FALSE, /* partial_inplace */
310 0xfffc, /* dst_mask */
311 TRUE), /* pcrel_offset */
313 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
315 HOWTO (R_PPC_GOT16, /* type */
317 1, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE, /* pc_relative */
321 complain_overflow_signed, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_PPC_GOT16", /* name */
324 FALSE, /* partial_inplace */
326 0xffff, /* dst_mask */
327 FALSE), /* pcrel_offset */
329 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
331 HOWTO (R_PPC_GOT16_LO, /* type */
333 1, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE, /* pc_relative */
337 complain_overflow_dont, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_PPC_GOT16_LO", /* name */
340 FALSE, /* partial_inplace */
342 0xffff, /* dst_mask */
343 FALSE), /* pcrel_offset */
345 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
347 HOWTO (R_PPC_GOT16_HI, /* type */
349 1, /* size (0 = byte, 1 = short, 2 = long) */
351 FALSE, /* pc_relative */
353 complain_overflow_bitfield, /* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_PPC_GOT16_HI", /* name */
356 FALSE, /* partial_inplace */
358 0xffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
361 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
363 HOWTO (R_PPC_GOT16_HA, /* type */
365 1, /* size (0 = byte, 1 = short, 2 = long) */
367 FALSE, /* pc_relative */
369 complain_overflow_bitfield, /* complain_on_overflow */
370 ppc_elf_addr16_ha_reloc, /* special_function */
371 "R_PPC_GOT16_HA", /* name */
372 FALSE, /* partial_inplace */
374 0xffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
377 /* Like R_PPC_REL24, but referring to the procedure linkage table
378 entry for the symbol. */
379 HOWTO (R_PPC_PLTREL24, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 TRUE, /* pc_relative */
385 complain_overflow_signed, /* complain_on_overflow */
386 bfd_elf_generic_reloc, /* special_function */
387 "R_PPC_PLTREL24", /* name */
388 FALSE, /* partial_inplace */
390 0x3fffffc, /* dst_mask */
391 TRUE), /* pcrel_offset */
393 /* This is used only by the dynamic linker. The symbol should exist
394 both in the object being run and in some shared library. The
395 dynamic linker copies the data addressed by the symbol from the
396 shared library into the object, because the object being
397 run has to have the data at some particular address. */
398 HOWTO (R_PPC_COPY, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE, /* pc_relative */
404 complain_overflow_bitfield, /* complain_on_overflow */
405 bfd_elf_generic_reloc, /* special_function */
406 "R_PPC_COPY", /* name */
407 FALSE, /* partial_inplace */
410 FALSE), /* pcrel_offset */
412 /* Like R_PPC_ADDR32, but used when setting global offset table
414 HOWTO (R_PPC_GLOB_DAT, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 FALSE, /* pc_relative */
420 complain_overflow_bitfield, /* complain_on_overflow */
421 bfd_elf_generic_reloc, /* special_function */
422 "R_PPC_GLOB_DAT", /* name */
423 FALSE, /* partial_inplace */
425 0xffffffff, /* dst_mask */
426 FALSE), /* pcrel_offset */
428 /* Marks a procedure linkage table entry for a symbol. */
429 HOWTO (R_PPC_JMP_SLOT, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 FALSE, /* pc_relative */
435 complain_overflow_bitfield, /* complain_on_overflow */
436 bfd_elf_generic_reloc, /* special_function */
437 "R_PPC_JMP_SLOT", /* name */
438 FALSE, /* partial_inplace */
441 FALSE), /* pcrel_offset */
443 /* Used only by the dynamic linker. When the object is run, this
444 longword is set to the load address of the object, plus the
446 HOWTO (R_PPC_RELATIVE, /* type */
448 2, /* size (0 = byte, 1 = short, 2 = long) */
450 FALSE, /* pc_relative */
452 complain_overflow_bitfield, /* complain_on_overflow */
453 bfd_elf_generic_reloc, /* special_function */
454 "R_PPC_RELATIVE", /* name */
455 FALSE, /* partial_inplace */
457 0xffffffff, /* dst_mask */
458 FALSE), /* pcrel_offset */
460 /* Like R_PPC_REL24, but uses the value of the symbol within the
461 object rather than the final value. Normally used for
462 _GLOBAL_OFFSET_TABLE_. */
463 HOWTO (R_PPC_LOCAL24PC, /* type */
465 2, /* size (0 = byte, 1 = short, 2 = long) */
467 TRUE, /* pc_relative */
469 complain_overflow_signed, /* complain_on_overflow */
470 bfd_elf_generic_reloc, /* special_function */
471 "R_PPC_LOCAL24PC", /* name */
472 FALSE, /* partial_inplace */
474 0x3fffffc, /* dst_mask */
475 TRUE), /* pcrel_offset */
477 /* Like R_PPC_ADDR32, but may be unaligned. */
478 HOWTO (R_PPC_UADDR32, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 FALSE, /* pc_relative */
484 complain_overflow_bitfield, /* complain_on_overflow */
485 bfd_elf_generic_reloc, /* special_function */
486 "R_PPC_UADDR32", /* name */
487 FALSE, /* partial_inplace */
489 0xffffffff, /* dst_mask */
490 FALSE), /* pcrel_offset */
492 /* Like R_PPC_ADDR16, but may be unaligned. */
493 HOWTO (R_PPC_UADDR16, /* type */
495 1, /* size (0 = byte, 1 = short, 2 = long) */
497 FALSE, /* pc_relative */
499 complain_overflow_bitfield, /* complain_on_overflow */
500 bfd_elf_generic_reloc, /* special_function */
501 "R_PPC_UADDR16", /* name */
502 FALSE, /* partial_inplace */
504 0xffff, /* dst_mask */
505 FALSE), /* pcrel_offset */
507 /* 32-bit PC relative */
508 HOWTO (R_PPC_REL32, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 TRUE, /* pc_relative */
514 complain_overflow_bitfield, /* complain_on_overflow */
515 bfd_elf_generic_reloc, /* special_function */
516 "R_PPC_REL32", /* name */
517 FALSE, /* partial_inplace */
519 0xffffffff, /* dst_mask */
520 TRUE), /* pcrel_offset */
522 /* 32-bit relocation to the symbol's procedure linkage table.
523 FIXME: not supported. */
524 HOWTO (R_PPC_PLT32, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE, /* pc_relative */
530 complain_overflow_bitfield, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_PPC_PLT32", /* name */
533 FALSE, /* partial_inplace */
536 FALSE), /* pcrel_offset */
538 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
539 FIXME: not supported. */
540 HOWTO (R_PPC_PLTREL32, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 TRUE, /* pc_relative */
546 complain_overflow_bitfield, /* complain_on_overflow */
547 bfd_elf_generic_reloc, /* special_function */
548 "R_PPC_PLTREL32", /* name */
549 FALSE, /* partial_inplace */
552 TRUE), /* pcrel_offset */
554 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
556 HOWTO (R_PPC_PLT16_LO, /* type */
558 1, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE, /* pc_relative */
562 complain_overflow_dont, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_PPC_PLT16_LO", /* name */
565 FALSE, /* partial_inplace */
567 0xffff, /* dst_mask */
568 FALSE), /* pcrel_offset */
570 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
572 HOWTO (R_PPC_PLT16_HI, /* type */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
576 FALSE, /* pc_relative */
578 complain_overflow_bitfield, /* complain_on_overflow */
579 bfd_elf_generic_reloc, /* special_function */
580 "R_PPC_PLT16_HI", /* name */
581 FALSE, /* partial_inplace */
583 0xffff, /* dst_mask */
584 FALSE), /* pcrel_offset */
586 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
588 HOWTO (R_PPC_PLT16_HA, /* type */
590 1, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE, /* pc_relative */
594 complain_overflow_bitfield, /* complain_on_overflow */
595 ppc_elf_addr16_ha_reloc, /* special_function */
596 "R_PPC_PLT16_HA", /* name */
597 FALSE, /* partial_inplace */
599 0xffff, /* dst_mask */
600 FALSE), /* pcrel_offset */
602 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
604 HOWTO (R_PPC_SDAREL16, /* type */
606 1, /* size (0 = byte, 1 = short, 2 = long) */
608 FALSE, /* pc_relative */
610 complain_overflow_signed, /* complain_on_overflow */
611 bfd_elf_generic_reloc, /* special_function */
612 "R_PPC_SDAREL16", /* name */
613 FALSE, /* partial_inplace */
615 0xffff, /* dst_mask */
616 FALSE), /* pcrel_offset */
618 /* 16-bit section relative relocation. */
619 HOWTO (R_PPC_SECTOFF, /* type */
621 1, /* size (0 = byte, 1 = short, 2 = long) */
623 FALSE, /* pc_relative */
625 complain_overflow_bitfield, /* complain_on_overflow */
626 bfd_elf_generic_reloc, /* special_function */
627 "R_PPC_SECTOFF", /* name */
628 FALSE, /* partial_inplace */
630 0xffff, /* dst_mask */
631 FALSE), /* pcrel_offset */
633 /* 16-bit lower half section relative relocation. */
634 HOWTO (R_PPC_SECTOFF_LO, /* type */
636 1, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE, /* pc_relative */
640 complain_overflow_dont, /* complain_on_overflow */
641 bfd_elf_generic_reloc, /* special_function */
642 "R_PPC_SECTOFF_LO", /* name */
643 FALSE, /* partial_inplace */
645 0xffff, /* dst_mask */
646 FALSE), /* pcrel_offset */
648 /* 16-bit upper half section relative relocation. */
649 HOWTO (R_PPC_SECTOFF_HI, /* type */
651 1, /* size (0 = byte, 1 = short, 2 = long) */
653 FALSE, /* pc_relative */
655 complain_overflow_bitfield, /* complain_on_overflow */
656 bfd_elf_generic_reloc, /* special_function */
657 "R_PPC_SECTOFF_HI", /* name */
658 FALSE, /* partial_inplace */
660 0xffff, /* dst_mask */
661 FALSE), /* pcrel_offset */
663 /* 16-bit upper half adjusted section relative relocation. */
664 HOWTO (R_PPC_SECTOFF_HA, /* type */
666 1, /* size (0 = byte, 1 = short, 2 = long) */
668 FALSE, /* pc_relative */
670 complain_overflow_bitfield, /* complain_on_overflow */
671 ppc_elf_addr16_ha_reloc, /* special_function */
672 "R_PPC_SECTOFF_HA", /* name */
673 FALSE, /* partial_inplace */
675 0xffff, /* dst_mask */
676 FALSE), /* pcrel_offset */
678 /* Marker reloc for TLS. */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 FALSE, /* pc_relative */
685 complain_overflow_dont, /* complain_on_overflow */
686 bfd_elf_generic_reloc, /* special_function */
687 "R_PPC_TLS", /* name */
688 FALSE, /* partial_inplace */
691 FALSE), /* pcrel_offset */
693 /* Computes the load module index of the load module that contains the
694 definition of its TLS sym. */
695 HOWTO (R_PPC_DTPMOD32,
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE, /* pc_relative */
701 complain_overflow_dont, /* complain_on_overflow */
702 ppc_elf_unhandled_reloc, /* special_function */
703 "R_PPC_DTPMOD32", /* name */
704 FALSE, /* partial_inplace */
706 0xffffffff, /* dst_mask */
707 FALSE), /* pcrel_offset */
709 /* Computes a dtv-relative displacement, the difference between the value
710 of sym+add and the base address of the thread-local storage block that
711 contains the definition of sym, minus 0x8000. */
712 HOWTO (R_PPC_DTPREL32,
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE, /* pc_relative */
718 complain_overflow_dont, /* complain_on_overflow */
719 ppc_elf_unhandled_reloc, /* special_function */
720 "R_PPC_DTPREL32", /* name */
721 FALSE, /* partial_inplace */
723 0xffffffff, /* dst_mask */
724 FALSE), /* pcrel_offset */
726 /* A 16 bit dtprel reloc. */
727 HOWTO (R_PPC_DTPREL16,
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE, /* pc_relative */
733 complain_overflow_signed, /* complain_on_overflow */
734 ppc_elf_unhandled_reloc, /* special_function */
735 "R_PPC_DTPREL16", /* name */
736 FALSE, /* partial_inplace */
738 0xffff, /* dst_mask */
739 FALSE), /* pcrel_offset */
741 /* Like DTPREL16, but no overflow. */
742 HOWTO (R_PPC_DTPREL16_LO,
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE, /* pc_relative */
748 complain_overflow_dont, /* complain_on_overflow */
749 ppc_elf_unhandled_reloc, /* special_function */
750 "R_PPC_DTPREL16_LO", /* name */
751 FALSE, /* partial_inplace */
753 0xffff, /* dst_mask */
754 FALSE), /* pcrel_offset */
756 /* Like DTPREL16_LO, but next higher group of 16 bits. */
757 HOWTO (R_PPC_DTPREL16_HI,
759 1, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE, /* pc_relative */
763 complain_overflow_dont, /* complain_on_overflow */
764 ppc_elf_unhandled_reloc, /* special_function */
765 "R_PPC_DTPREL16_HI", /* name */
766 FALSE, /* partial_inplace */
768 0xffff, /* dst_mask */
769 FALSE), /* pcrel_offset */
771 /* Like DTPREL16_HI, but adjust for low 16 bits. */
772 HOWTO (R_PPC_DTPREL16_HA,
774 1, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE, /* pc_relative */
778 complain_overflow_dont, /* complain_on_overflow */
779 ppc_elf_unhandled_reloc, /* special_function */
780 "R_PPC_DTPREL16_HA", /* name */
781 FALSE, /* partial_inplace */
783 0xffff, /* dst_mask */
784 FALSE), /* pcrel_offset */
786 /* Computes a tp-relative displacement, the difference between the value of
787 sym+add and the value of the thread pointer (r13). */
788 HOWTO (R_PPC_TPREL32,
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 FALSE, /* pc_relative */
794 complain_overflow_dont, /* complain_on_overflow */
795 ppc_elf_unhandled_reloc, /* special_function */
796 "R_PPC_TPREL32", /* name */
797 FALSE, /* partial_inplace */
799 0xffffffff, /* dst_mask */
800 FALSE), /* pcrel_offset */
802 /* A 16 bit tprel reloc. */
803 HOWTO (R_PPC_TPREL16,
805 1, /* size (0 = byte, 1 = short, 2 = long) */
807 FALSE, /* pc_relative */
809 complain_overflow_signed, /* complain_on_overflow */
810 ppc_elf_unhandled_reloc, /* special_function */
811 "R_PPC_TPREL16", /* name */
812 FALSE, /* partial_inplace */
814 0xffff, /* dst_mask */
815 FALSE), /* pcrel_offset */
817 /* Like TPREL16, but no overflow. */
818 HOWTO (R_PPC_TPREL16_LO,
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 FALSE, /* pc_relative */
824 complain_overflow_dont, /* complain_on_overflow */
825 ppc_elf_unhandled_reloc, /* special_function */
826 "R_PPC_TPREL16_LO", /* name */
827 FALSE, /* partial_inplace */
829 0xffff, /* dst_mask */
830 FALSE), /* pcrel_offset */
832 /* Like TPREL16_LO, but next higher group of 16 bits. */
833 HOWTO (R_PPC_TPREL16_HI,
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 FALSE, /* pc_relative */
839 complain_overflow_dont, /* complain_on_overflow */
840 ppc_elf_unhandled_reloc, /* special_function */
841 "R_PPC_TPREL16_HI", /* name */
842 FALSE, /* partial_inplace */
844 0xffff, /* dst_mask */
845 FALSE), /* pcrel_offset */
847 /* Like TPREL16_HI, but adjust for low 16 bits. */
848 HOWTO (R_PPC_TPREL16_HA,
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 FALSE, /* pc_relative */
854 complain_overflow_dont, /* complain_on_overflow */
855 ppc_elf_unhandled_reloc, /* special_function */
856 "R_PPC_TPREL16_HA", /* name */
857 FALSE, /* partial_inplace */
859 0xffff, /* dst_mask */
860 FALSE), /* pcrel_offset */
862 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
863 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
864 to the first entry. */
865 HOWTO (R_PPC_GOT_TLSGD16,
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE, /* pc_relative */
871 complain_overflow_signed, /* complain_on_overflow */
872 ppc_elf_unhandled_reloc, /* special_function */
873 "R_PPC_GOT_TLSGD16", /* name */
874 FALSE, /* partial_inplace */
876 0xffff, /* dst_mask */
877 FALSE), /* pcrel_offset */
879 /* Like GOT_TLSGD16, but no overflow. */
880 HOWTO (R_PPC_GOT_TLSGD16_LO,
882 1, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE, /* pc_relative */
886 complain_overflow_dont, /* complain_on_overflow */
887 ppc_elf_unhandled_reloc, /* special_function */
888 "R_PPC_GOT_TLSGD16_LO", /* name */
889 FALSE, /* partial_inplace */
891 0xffff, /* dst_mask */
892 FALSE), /* pcrel_offset */
894 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
895 HOWTO (R_PPC_GOT_TLSGD16_HI,
897 1, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE, /* pc_relative */
901 complain_overflow_dont, /* complain_on_overflow */
902 ppc_elf_unhandled_reloc, /* special_function */
903 "R_PPC_GOT_TLSGD16_HI", /* name */
904 FALSE, /* partial_inplace */
906 0xffff, /* dst_mask */
907 FALSE), /* pcrel_offset */
909 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
910 HOWTO (R_PPC_GOT_TLSGD16_HA,
912 1, /* size (0 = byte, 1 = short, 2 = long) */
914 FALSE, /* pc_relative */
916 complain_overflow_dont, /* complain_on_overflow */
917 ppc_elf_unhandled_reloc, /* special_function */
918 "R_PPC_GOT_TLSGD16_HA", /* name */
919 FALSE, /* partial_inplace */
921 0xffff, /* dst_mask */
922 FALSE), /* pcrel_offset */
924 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
925 with values (sym+add)@dtpmod and zero, and computes the offset to the
927 HOWTO (R_PPC_GOT_TLSLD16,
929 1, /* size (0 = byte, 1 = short, 2 = long) */
931 FALSE, /* pc_relative */
933 complain_overflow_signed, /* complain_on_overflow */
934 ppc_elf_unhandled_reloc, /* special_function */
935 "R_PPC_GOT_TLSLD16", /* name */
936 FALSE, /* partial_inplace */
938 0xffff, /* dst_mask */
939 FALSE), /* pcrel_offset */
941 /* Like GOT_TLSLD16, but no overflow. */
942 HOWTO (R_PPC_GOT_TLSLD16_LO,
944 1, /* size (0 = byte, 1 = short, 2 = long) */
946 FALSE, /* pc_relative */
948 complain_overflow_dont, /* complain_on_overflow */
949 ppc_elf_unhandled_reloc, /* special_function */
950 "R_PPC_GOT_TLSLD16_LO", /* name */
951 FALSE, /* partial_inplace */
953 0xffff, /* dst_mask */
954 FALSE), /* pcrel_offset */
956 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
957 HOWTO (R_PPC_GOT_TLSLD16_HI,
959 1, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE, /* pc_relative */
963 complain_overflow_dont, /* complain_on_overflow */
964 ppc_elf_unhandled_reloc, /* special_function */
965 "R_PPC_GOT_TLSLD16_HI", /* name */
966 FALSE, /* partial_inplace */
968 0xffff, /* dst_mask */
969 FALSE), /* pcrel_offset */
971 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
972 HOWTO (R_PPC_GOT_TLSLD16_HA,
974 1, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE, /* pc_relative */
978 complain_overflow_dont, /* complain_on_overflow */
979 ppc_elf_unhandled_reloc, /* special_function */
980 "R_PPC_GOT_TLSLD16_HA", /* name */
981 FALSE, /* partial_inplace */
983 0xffff, /* dst_mask */
984 FALSE), /* pcrel_offset */
986 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
987 the offset to the entry. */
988 HOWTO (R_PPC_GOT_DTPREL16,
990 1, /* size (0 = byte, 1 = short, 2 = long) */
992 FALSE, /* pc_relative */
994 complain_overflow_signed, /* complain_on_overflow */
995 ppc_elf_unhandled_reloc, /* special_function */
996 "R_PPC_GOT_DTPREL16", /* name */
997 FALSE, /* partial_inplace */
999 0xffff, /* dst_mask */
1000 FALSE), /* pcrel_offset */
1002 /* Like GOT_DTPREL16, but no overflow. */
1003 HOWTO (R_PPC_GOT_DTPREL16_LO,
1005 1, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE, /* pc_relative */
1009 complain_overflow_dont, /* complain_on_overflow */
1010 ppc_elf_unhandled_reloc, /* special_function */
1011 "R_PPC_GOT_DTPREL16_LO", /* name */
1012 FALSE, /* partial_inplace */
1014 0xffff, /* dst_mask */
1015 FALSE), /* pcrel_offset */
1017 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1018 HOWTO (R_PPC_GOT_DTPREL16_HI,
1019 16, /* rightshift */
1020 1, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE, /* pc_relative */
1024 complain_overflow_dont, /* complain_on_overflow */
1025 ppc_elf_unhandled_reloc, /* special_function */
1026 "R_PPC_GOT_DTPREL16_HI", /* name */
1027 FALSE, /* partial_inplace */
1029 0xffff, /* dst_mask */
1030 FALSE), /* pcrel_offset */
1032 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1033 HOWTO (R_PPC_GOT_DTPREL16_HA,
1034 16, /* rightshift */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE, /* pc_relative */
1039 complain_overflow_dont, /* complain_on_overflow */
1040 ppc_elf_unhandled_reloc, /* special_function */
1041 "R_PPC_GOT_DTPREL16_HA", /* name */
1042 FALSE, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE), /* pcrel_offset */
1047 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1048 offset to the entry. */
1049 HOWTO (R_PPC_GOT_TPREL16,
1051 1, /* size (0 = byte, 1 = short, 2 = long) */
1053 FALSE, /* pc_relative */
1055 complain_overflow_signed, /* complain_on_overflow */
1056 ppc_elf_unhandled_reloc, /* special_function */
1057 "R_PPC_GOT_TPREL16", /* name */
1058 FALSE, /* partial_inplace */
1060 0xffff, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1063 /* Like GOT_TPREL16, but no overflow. */
1064 HOWTO (R_PPC_GOT_TPREL16_LO,
1066 1, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE, /* pc_relative */
1070 complain_overflow_dont, /* complain_on_overflow */
1071 ppc_elf_unhandled_reloc, /* special_function */
1072 "R_PPC_GOT_TPREL16_LO", /* name */
1073 FALSE, /* partial_inplace */
1075 0xffff, /* dst_mask */
1076 FALSE), /* pcrel_offset */
1078 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1079 HOWTO (R_PPC_GOT_TPREL16_HI,
1080 16, /* rightshift */
1081 1, /* size (0 = byte, 1 = short, 2 = long) */
1083 FALSE, /* pc_relative */
1085 complain_overflow_dont, /* complain_on_overflow */
1086 ppc_elf_unhandled_reloc, /* special_function */
1087 "R_PPC_GOT_TPREL16_HI", /* name */
1088 FALSE, /* partial_inplace */
1090 0xffff, /* dst_mask */
1091 FALSE), /* pcrel_offset */
1093 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1094 HOWTO (R_PPC_GOT_TPREL16_HA,
1095 16, /* rightshift */
1096 1, /* size (0 = byte, 1 = short, 2 = long) */
1098 FALSE, /* pc_relative */
1100 complain_overflow_dont, /* complain_on_overflow */
1101 ppc_elf_unhandled_reloc, /* special_function */
1102 "R_PPC_GOT_TPREL16_HA", /* name */
1103 FALSE, /* partial_inplace */
1105 0xffff, /* dst_mask */
1106 FALSE), /* pcrel_offset */
1108 /* The remaining relocs are from the Embedded ELF ABI, and are not
1109 in the SVR4 ELF ABI. */
1111 /* 32 bit value resulting from the addend minus the symbol. */
1112 HOWTO (R_PPC_EMB_NADDR32, /* type */
1114 2, /* size (0 = byte, 1 = short, 2 = long) */
1116 FALSE, /* pc_relative */
1118 complain_overflow_bitfield, /* complain_on_overflow */
1119 bfd_elf_generic_reloc, /* special_function */
1120 "R_PPC_EMB_NADDR32", /* name */
1121 FALSE, /* partial_inplace */
1123 0xffffffff, /* dst_mask */
1124 FALSE), /* pcrel_offset */
1126 /* 16 bit value resulting from the addend minus the symbol. */
1127 HOWTO (R_PPC_EMB_NADDR16, /* type */
1129 1, /* size (0 = byte, 1 = short, 2 = long) */
1131 FALSE, /* pc_relative */
1133 complain_overflow_bitfield, /* complain_on_overflow */
1134 bfd_elf_generic_reloc, /* special_function */
1135 "R_PPC_EMB_NADDR16", /* name */
1136 FALSE, /* partial_inplace */
1138 0xffff, /* dst_mask */
1139 FALSE), /* pcrel_offset */
1141 /* 16 bit value resulting from the addend minus the symbol. */
1142 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1144 1, /* size (0 = byte, 1 = short, 2 = long) */
1146 FALSE, /* pc_relative */
1148 complain_overflow_dont,/* complain_on_overflow */
1149 bfd_elf_generic_reloc, /* special_function */
1150 "R_PPC_EMB_ADDR16_LO", /* name */
1151 FALSE, /* partial_inplace */
1153 0xffff, /* dst_mask */
1154 FALSE), /* pcrel_offset */
1156 /* The high order 16 bits of the addend minus the symbol. */
1157 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1158 16, /* rightshift */
1159 1, /* size (0 = byte, 1 = short, 2 = long) */
1161 FALSE, /* pc_relative */
1163 complain_overflow_dont, /* complain_on_overflow */
1164 bfd_elf_generic_reloc, /* special_function */
1165 "R_PPC_EMB_NADDR16_HI", /* name */
1166 FALSE, /* partial_inplace */
1168 0xffff, /* dst_mask */
1169 FALSE), /* pcrel_offset */
1171 /* The high order 16 bits of the result of the addend minus the address,
1172 plus 1 if the contents of the low 16 bits, treated as a signed number,
1174 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1175 16, /* rightshift */
1176 1, /* size (0 = byte, 1 = short, 2 = long) */
1178 FALSE, /* pc_relative */
1180 complain_overflow_dont, /* complain_on_overflow */
1181 ppc_elf_addr16_ha_reloc, /* special_function */
1182 "R_PPC_EMB_NADDR16_HA", /* name */
1183 FALSE, /* partial_inplace */
1185 0xffff, /* dst_mask */
1186 FALSE), /* pcrel_offset */
1188 /* 16 bit value resulting from allocating a 4 byte word to hold an
1189 address in the .sdata section, and returning the offset from
1190 _SDA_BASE_ for that relocation. */
1191 HOWTO (R_PPC_EMB_SDAI16, /* type */
1193 1, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE, /* pc_relative */
1197 complain_overflow_bitfield, /* complain_on_overflow */
1198 bfd_elf_generic_reloc, /* special_function */
1199 "R_PPC_EMB_SDAI16", /* name */
1200 FALSE, /* partial_inplace */
1202 0xffff, /* dst_mask */
1203 FALSE), /* pcrel_offset */
1205 /* 16 bit value resulting from allocating a 4 byte word to hold an
1206 address in the .sdata2 section, and returning the offset from
1207 _SDA2_BASE_ for that relocation. */
1208 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE, /* pc_relative */
1214 complain_overflow_bitfield, /* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_PPC_EMB_SDA2I16", /* name */
1217 FALSE, /* partial_inplace */
1219 0xffff, /* dst_mask */
1220 FALSE), /* pcrel_offset */
1222 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1223 small data items. */
1224 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1226 1, /* size (0 = byte, 1 = short, 2 = long) */
1228 FALSE, /* pc_relative */
1230 complain_overflow_signed, /* complain_on_overflow */
1231 bfd_elf_generic_reloc, /* special_function */
1232 "R_PPC_EMB_SDA2REL", /* name */
1233 FALSE, /* partial_inplace */
1235 0xffff, /* dst_mask */
1236 FALSE), /* pcrel_offset */
1238 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1239 signed offset from the appropriate base, and filling in the register
1240 field with the appropriate register (0, 2, or 13). */
1241 HOWTO (R_PPC_EMB_SDA21, /* type */
1243 2, /* size (0 = byte, 1 = short, 2 = long) */
1245 FALSE, /* pc_relative */
1247 complain_overflow_signed, /* complain_on_overflow */
1248 bfd_elf_generic_reloc, /* special_function */
1249 "R_PPC_EMB_SDA21", /* name */
1250 FALSE, /* partial_inplace */
1252 0xffff, /* dst_mask */
1253 FALSE), /* pcrel_offset */
1255 /* Relocation not handled: R_PPC_EMB_MRKREF */
1256 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1257 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1258 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1259 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1260 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1262 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1263 in the 16 bit signed offset from the appropriate base, and filling in the
1264 register field with the appropriate register (0, 2, or 13). */
1265 HOWTO (R_PPC_EMB_RELSDA, /* type */
1267 1, /* size (0 = byte, 1 = short, 2 = long) */
1269 TRUE, /* pc_relative */
1271 complain_overflow_signed, /* complain_on_overflow */
1272 bfd_elf_generic_reloc, /* special_function */
1273 "R_PPC_EMB_RELSDA", /* name */
1274 FALSE, /* partial_inplace */
1276 0xffff, /* dst_mask */
1277 FALSE), /* pcrel_offset */
1279 /* A 16 bit relative relocation. */
1280 HOWTO (R_PPC_REL16, /* type */
1282 1, /* size (0 = byte, 1 = short, 2 = long) */
1284 TRUE, /* pc_relative */
1286 complain_overflow_bitfield, /* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_PPC_REL16", /* name */
1289 FALSE, /* partial_inplace */
1291 0xffff, /* dst_mask */
1292 TRUE), /* pcrel_offset */
1294 /* A 16 bit relative relocation without overflow. */
1295 HOWTO (R_PPC_REL16_LO, /* type */
1297 1, /* size (0 = byte, 1 = short, 2 = long) */
1299 TRUE, /* pc_relative */
1301 complain_overflow_dont,/* complain_on_overflow */
1302 bfd_elf_generic_reloc, /* special_function */
1303 "R_PPC_REL16_LO", /* name */
1304 FALSE, /* partial_inplace */
1306 0xffff, /* dst_mask */
1307 TRUE), /* pcrel_offset */
1309 /* The high order 16 bits of a relative address. */
1310 HOWTO (R_PPC_REL16_HI, /* type */
1311 16, /* rightshift */
1312 1, /* size (0 = byte, 1 = short, 2 = long) */
1314 TRUE, /* pc_relative */
1316 complain_overflow_dont, /* complain_on_overflow */
1317 bfd_elf_generic_reloc, /* special_function */
1318 "R_PPC_REL16_HI", /* name */
1319 FALSE, /* partial_inplace */
1321 0xffff, /* dst_mask */
1322 TRUE), /* pcrel_offset */
1324 /* The high order 16 bits of a relative address, plus 1 if the contents of
1325 the low 16 bits, treated as a signed number, is negative. */
1326 HOWTO (R_PPC_REL16_HA, /* type */
1327 16, /* rightshift */
1328 1, /* size (0 = byte, 1 = short, 2 = long) */
1330 TRUE, /* pc_relative */
1332 complain_overflow_dont, /* complain_on_overflow */
1333 ppc_elf_addr16_ha_reloc, /* special_function */
1334 "R_PPC_REL16_HA", /* name */
1335 FALSE, /* partial_inplace */
1337 0xffff, /* dst_mask */
1338 TRUE), /* pcrel_offset */
1340 /* GNU extension to record C++ vtable hierarchy. */
1341 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1343 0, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE, /* pc_relative */
1347 complain_overflow_dont, /* complain_on_overflow */
1348 NULL, /* special_function */
1349 "R_PPC_GNU_VTINHERIT", /* name */
1350 FALSE, /* partial_inplace */
1353 FALSE), /* pcrel_offset */
1355 /* GNU extension to record C++ vtable member usage. */
1356 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1358 0, /* size (0 = byte, 1 = short, 2 = long) */
1360 FALSE, /* pc_relative */
1362 complain_overflow_dont, /* complain_on_overflow */
1363 NULL, /* special_function */
1364 "R_PPC_GNU_VTENTRY", /* name */
1365 FALSE, /* partial_inplace */
1368 FALSE), /* pcrel_offset */
1370 /* Phony reloc to handle AIX style TOC entries. */
1371 HOWTO (R_PPC_TOC16, /* type */
1373 1, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE, /* pc_relative */
1377 complain_overflow_signed, /* complain_on_overflow */
1378 bfd_elf_generic_reloc, /* special_function */
1379 "R_PPC_TOC16", /* name */
1380 FALSE, /* partial_inplace */
1382 0xffff, /* dst_mask */
1383 FALSE), /* pcrel_offset */
1386 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1389 ppc_elf_howto_init (void)
1391 unsigned int i, type;
1394 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1397 type = ppc_elf_howto_raw[i].type;
1398 if (type >= (sizeof (ppc_elf_howto_table)
1399 / sizeof (ppc_elf_howto_table[0])))
1401 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1405 static reloc_howto_type *
1406 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1407 bfd_reloc_code_real_type code)
1409 enum elf_ppc_reloc_type r;
1411 /* Initialize howto table if not already done. */
1412 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1413 ppc_elf_howto_init ();
1420 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1421 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1422 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1423 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1424 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1425 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1426 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1427 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1428 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1429 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1430 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1431 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1432 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1433 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1434 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1435 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1436 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1437 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1438 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1439 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1440 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1441 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1442 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1443 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1444 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1445 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1446 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1447 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1448 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1449 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1450 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1451 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1452 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1453 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1454 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1455 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1456 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1457 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1458 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1459 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1460 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1461 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1462 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1463 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1464 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1465 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1466 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1467 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1468 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1469 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1470 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1471 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1472 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1473 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1474 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1475 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1476 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1477 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1478 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1479 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1480 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1481 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1482 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1483 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1484 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1485 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1486 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1487 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1488 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1489 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1490 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1491 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1492 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1493 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1494 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1495 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1496 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1497 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1498 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1499 case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
1500 case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
1501 case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
1502 case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
1503 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1504 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1507 return ppc_elf_howto_table[r];
1510 /* Set the howto pointer for a PowerPC ELF reloc. */
1513 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1515 Elf_Internal_Rela *dst)
1517 /* Initialize howto table if not already done. */
1518 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1519 ppc_elf_howto_init ();
1521 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1522 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1525 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1527 static bfd_reloc_status_type
1528 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1529 arelent *reloc_entry,
1531 void *data ATTRIBUTE_UNUSED,
1532 asection *input_section,
1534 char **error_message ATTRIBUTE_UNUSED)
1538 if (output_bfd != NULL)
1540 reloc_entry->address += input_section->output_offset;
1541 return bfd_reloc_ok;
1544 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1545 return bfd_reloc_outofrange;
1547 if (bfd_is_com_section (symbol->section))
1550 relocation = symbol->value;
1552 relocation += symbol->section->output_section->vma;
1553 relocation += symbol->section->output_offset;
1554 relocation += reloc_entry->addend;
1555 if (reloc_entry->howto->pc_relative)
1556 relocation -= reloc_entry->address;
1558 reloc_entry->addend += (relocation & 0x8000) << 1;
1560 return bfd_reloc_continue;
1563 static bfd_reloc_status_type
1564 ppc_elf_unhandled_reloc (bfd *abfd,
1565 arelent *reloc_entry,
1568 asection *input_section,
1570 char **error_message)
1572 /* If this is a relocatable link (output_bfd test tells us), just
1573 call the generic function. Any adjustment will be done at final
1575 if (output_bfd != NULL)
1576 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1577 input_section, output_bfd, error_message);
1579 if (error_message != NULL)
1581 static char buf[60];
1582 sprintf (buf, _("generic linker can't handle %s"),
1583 reloc_entry->howto->name);
1584 *error_message = buf;
1586 return bfd_reloc_dangerous;
1589 /* Sections created by the linker. */
1591 typedef struct elf_linker_section
1593 /* Pointer to the bfd section. */
1597 /* Associated bss section name. */
1598 const char *bss_name;
1599 /* Associated symbol name. */
1600 const char *sym_name;
1601 /* Value of symbol. */
1603 } elf_linker_section_t;
1605 /* Linked list of allocated pointer entries. This hangs off of the
1606 symbol lists, and provides allows us to return different pointers,
1607 based on different addend's. */
1609 typedef struct elf_linker_section_pointers
1611 /* next allocated pointer for this symbol */
1612 struct elf_linker_section_pointers *next;
1613 /* offset of pointer from beginning of section */
1617 /* which linker section this is */
1618 elf_linker_section_t *lsect;
1619 } elf_linker_section_pointers_t;
1621 struct ppc_elf_obj_tdata
1623 struct elf_obj_tdata elf;
1625 /* A mapping from local symbols to offsets into the various linker
1626 sections added. This is index by the symbol index. */
1627 elf_linker_section_pointers_t **linker_section_pointers;
1630 #define ppc_elf_tdata(bfd) \
1631 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1633 #define elf_local_ptr_offsets(bfd) \
1634 (ppc_elf_tdata (bfd)->linker_section_pointers)
1636 /* Override the generic function because we store some extras. */
1639 ppc_elf_mkobject (bfd *abfd)
1641 bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
1642 abfd->tdata.any = bfd_zalloc (abfd, amt);
1643 if (abfd->tdata.any == NULL)
1648 /* Fix bad default arch selected for a 32 bit input bfd when the
1649 default is 64 bit. */
1652 ppc_elf_object_p (bfd *abfd)
1654 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
1656 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
1658 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
1660 /* Relies on arch after 64 bit default being 32 bit default. */
1661 abfd->arch_info = abfd->arch_info->next;
1662 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
1668 /* Function to set whether a module needs the -mrelocatable bit set. */
1671 ppc_elf_set_private_flags (bfd *abfd, flagword flags)
1673 BFD_ASSERT (!elf_flags_init (abfd)
1674 || elf_elfheader (abfd)->e_flags == flags);
1676 elf_elfheader (abfd)->e_flags = flags;
1677 elf_flags_init (abfd) = TRUE;
1681 /* Support for core dump NOTE sections. */
1684 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1689 switch (note->descsz)
1694 case 268: /* Linux/PPC. */
1696 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1699 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1708 /* Make a ".reg/999" section. */
1709 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1710 size, note->descpos + offset);
1714 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1716 switch (note->descsz)
1721 case 128: /* Linux/PPC elf_prpsinfo. */
1722 elf_tdata (abfd)->core_program
1723 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1724 elf_tdata (abfd)->core_command
1725 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1728 /* Note that for some reason, a spurious space is tacked
1729 onto the end of the args in some (at least one anyway)
1730 implementations, so strip it off if it exists. */
1733 char *command = elf_tdata (abfd)->core_command;
1734 int n = strlen (command);
1736 if (0 < n && command[n - 1] == ' ')
1737 command[n - 1] = '\0';
1743 /* Return address for Ith PLT stub in section PLT, for relocation REL
1744 or (bfd_vma) -1 if it should not be included. */
1747 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
1748 const asection *plt ATTRIBUTE_UNUSED,
1751 return rel->address;
1754 /* Handle a PowerPC specific section when reading an object file. This
1755 is called when bfd_section_from_shdr finds a section with an unknown
1759 ppc_elf_section_from_shdr (bfd *abfd,
1760 Elf_Internal_Shdr *hdr,
1767 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1770 newsect = hdr->bfd_section;
1771 flags = bfd_get_section_flags (abfd, newsect);
1772 if (hdr->sh_flags & SHF_EXCLUDE)
1773 flags |= SEC_EXCLUDE;
1775 if (hdr->sh_type == SHT_ORDERED)
1776 flags |= SEC_SORT_ENTRIES;
1778 bfd_set_section_flags (abfd, newsect, flags);
1782 /* Set up any other section flags and such that may be necessary. */
1785 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1786 Elf_Internal_Shdr *shdr,
1789 if ((asect->flags & SEC_EXCLUDE) != 0)
1790 shdr->sh_flags |= SHF_EXCLUDE;
1792 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1793 shdr->sh_type = SHT_ORDERED;
1798 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1799 need to bump up the number of section headers. */
1802 ppc_elf_additional_program_headers (bfd *abfd)
1807 s = bfd_get_section_by_name (abfd, ".sbss2");
1808 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1811 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1812 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1818 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1819 .PPC.EMB.sbss0 a normal section, and not a bss section so
1820 that the linker doesn't crater when trying to make more than
1823 static struct bfd_elf_special_section const
1824 ppc_special_sections_p[] =
1826 { ".plt", 4, 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
1827 { NULL, 0, 0, 0, 0 }
1830 static struct bfd_elf_special_section const
1831 ppc_special_sections_s[] =
1833 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
1834 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
1835 { ".sdata2", 7, -2, SHT_PROGBITS, SHF_ALLOC },
1836 { ".sbss2", 6, -2, SHT_PROGBITS, SHF_ALLOC },
1837 { NULL, 0, 0, 0, 0 }
1840 static struct bfd_elf_special_section const
1841 ppc_special_sections_t[] =
1843 { ".tags", 5, 0, SHT_ORDERED, SHF_ALLOC },
1844 { NULL, 0, 0, 0, 0 }
1847 static struct bfd_elf_special_section const
1848 ppc_special_sections_other[]=
1850 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE, 0 },
1851 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS, SHF_ALLOC },
1852 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS, SHF_ALLOC },
1853 { NULL, 0, 0, 0, 0 }
1856 static struct bfd_elf_special_section const *
1857 ppc_elf_special_sections[27]=
1874 ppc_special_sections_p, /* 'p' */
1877 ppc_special_sections_s, /* 's' */
1878 ppc_special_sections_t, /* 's' */
1885 ppc_special_sections_other, /* other */
1888 /* Very simple linked list structure for recording apuinfo values. */
1889 typedef struct apuinfo_list
1891 struct apuinfo_list *next;
1892 unsigned long value;
1896 static apuinfo_list *head;
1900 apuinfo_list_init (void)
1906 apuinfo_list_add (unsigned long value)
1908 apuinfo_list *entry = head;
1910 while (entry != NULL)
1912 if (entry->value == value)
1914 entry = entry->next;
1917 entry = bfd_malloc (sizeof (* entry));
1921 entry->value = value;
1927 apuinfo_list_length (void)
1929 apuinfo_list *entry;
1930 unsigned long count;
1932 for (entry = head, count = 0;
1934 entry = entry->next)
1940 static inline unsigned long
1941 apuinfo_list_element (unsigned long number)
1943 apuinfo_list * entry;
1947 entry = entry->next)
1950 return entry ? entry->value : 0;
1954 apuinfo_list_finish (void)
1956 apuinfo_list *entry;
1958 for (entry = head; entry;)
1960 apuinfo_list *next = entry->next;
1968 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
1969 #define APUINFO_LABEL "APUinfo"
1971 /* Scan the input BFDs and create a linked list of
1972 the APUinfo values that will need to be emitted. */
1975 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
1980 unsigned num_input_sections;
1981 bfd_size_type output_section_size;
1983 unsigned num_entries;
1984 unsigned long offset;
1985 unsigned long length;
1986 const char *error_message = NULL;
1988 if (link_info == NULL)
1991 /* Scan the input bfds, looking for apuinfo sections. */
1992 num_input_sections = 0;
1993 output_section_size = 0;
1995 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
1997 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2000 ++ num_input_sections;
2001 output_section_size += asec->size;
2005 /* We need at least one input sections
2006 in order to make merging worthwhile. */
2007 if (num_input_sections < 1)
2010 /* Just make sure that the output section exists as well. */
2011 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2015 /* Allocate a buffer for the contents of the input sections. */
2016 buffer = bfd_malloc (output_section_size);
2021 apuinfo_list_init ();
2023 /* Read in the input sections contents. */
2024 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2026 unsigned long datum;
2029 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2033 length = asec->size;
2036 error_message = _("corrupt or empty %s section in %B");
2040 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
2041 || (bfd_bread (buffer + offset, length, ibfd) != length))
2043 error_message = _("unable to read in %s section from %B");
2047 /* Process the contents of the section. */
2048 ptr = buffer + offset;
2049 error_message = _("corrupt %s section in %B");
2051 /* Verify the contents of the header. Note - we have to
2052 extract the values this way in order to allow for a
2053 host whose endian-ness is different from the target. */
2054 datum = bfd_get_32 (ibfd, ptr);
2055 if (datum != sizeof APUINFO_LABEL)
2058 datum = bfd_get_32 (ibfd, ptr + 8);
2062 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
2065 /* Get the number of bytes used for apuinfo entries. */
2066 datum = bfd_get_32 (ibfd, ptr + 4);
2067 if (datum + 20 != length)
2070 /* Make sure that we do not run off the end of the section. */
2071 if (offset + length > output_section_size)
2074 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2075 for (i = 0; i < datum; i += 4)
2076 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
2078 /* Update the offset. */
2082 error_message = NULL;
2084 /* Compute the size of the output section. */
2085 num_entries = apuinfo_list_length ();
2086 output_section_size = 20 + num_entries * 4;
2088 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2090 if (! bfd_set_section_size (abfd, asec, output_section_size))
2092 error_message = _("warning: unable to set size of %s section in %B");
2098 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2101 /* Prevent the output section from accumulating the input sections'
2102 contents. We have already stored this in our linked list structure. */
2105 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
2107 bfd_byte *contents ATTRIBUTE_UNUSED)
2109 return (apuinfo_list_length ()
2110 && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
2113 /* Finally we can generate the output section. */
2116 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
2121 unsigned num_entries;
2122 bfd_size_type length;
2124 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2128 if (apuinfo_list_length () == 0)
2131 length = asec->size;
2135 buffer = bfd_malloc (length);
2138 (*_bfd_error_handler)
2139 (_("failed to allocate space for new APUinfo section."));
2143 /* Create the apuinfo header. */
2144 num_entries = apuinfo_list_length ();
2145 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2146 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2147 bfd_put_32 (abfd, 0x2, buffer + 8);
2148 strcpy ((char *) buffer + 12, APUINFO_LABEL);
2151 for (i = 0; i < num_entries; i++)
2153 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2157 if (length != asec->size)
2158 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
2160 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2161 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
2165 apuinfo_list_finish ();
2168 /* The following functions are specific to the ELF linker, while
2169 functions above are used generally. They appear in this file more
2170 or less in the order in which they are called. eg.
2171 ppc_elf_check_relocs is called early in the link process,
2172 ppc_elf_finish_dynamic_sections is one of the last functions
2175 /* The PPC linker needs to keep track of the number of relocs that it
2176 decides to copy as dynamic relocs in check_relocs for each symbol.
2177 This is so that it can later discard them if they are found to be
2178 unnecessary. We store the information in a field extending the
2179 regular ELF linker hash table. */
2181 struct ppc_elf_dyn_relocs
2183 struct ppc_elf_dyn_relocs *next;
2185 /* The input section of the reloc. */
2188 /* Total number of relocs copied for the input section. */
2189 bfd_size_type count;
2191 /* Number of pc-relative relocs copied for the input section. */
2192 bfd_size_type pc_count;
2195 /* Of those relocs that might be copied as dynamic relocs, this macro
2196 selects those that must be copied when linking a shared library,
2197 even when the symbol is local. */
2199 #define MUST_BE_DYN_RELOC(RTYPE) \
2200 ((RTYPE) != R_PPC_REL24 \
2201 && (RTYPE) != R_PPC_REL14 \
2202 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2203 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2204 && (RTYPE) != R_PPC_REL32)
2206 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2207 copying dynamic variables from a shared lib into an app's dynbss
2208 section, and instead use a dynamic relocation to point into the
2210 #define ELIMINATE_COPY_RELOCS 1
2212 /* PPC ELF linker hash entry. */
2214 struct ppc_elf_link_hash_entry
2216 struct elf_link_hash_entry elf;
2218 /* If this symbol is used in the linker created sections, the processor
2219 specific backend uses this field to map the field into the offset
2220 from the beginning of the section. */
2221 elf_linker_section_pointers_t *linker_section_pointer;
2223 /* Track dynamic relocs copied for this symbol. */
2224 struct ppc_elf_dyn_relocs *dyn_relocs;
2226 /* Contexts in which symbol is used in the GOT (or TOC).
2227 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2228 corresponding relocs are encountered during check_relocs.
2229 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2230 indicate the corresponding GOT entry type is not needed. */
2231 #define TLS_GD 1 /* GD reloc. */
2232 #define TLS_LD 2 /* LD reloc. */
2233 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2234 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2235 #define TLS_TLS 16 /* Any TLS reloc. */
2236 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2240 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2242 /* PPC ELF linker hash table. */
2244 struct ppc_elf_link_hash_table
2246 struct elf_link_hash_table elf;
2248 /* Short-cuts to get to dynamic linker sections. */
2258 elf_linker_section_t sdata[2];
2261 /* Shortcut to .__tls_get_addr. */
2262 struct elf_link_hash_entry *tls_get_addr;
2264 /* TLS local dynamic got entry handling. */
2266 bfd_signed_vma refcount;
2270 /* Offset of PltResolve function in glink. */
2271 bfd_vma glink_pltresolve;
2273 /* Size of reserved GOT entries. */
2274 unsigned int got_header_size;
2275 /* Non-zero if allocating the header left a gap. */
2276 unsigned int got_gap;
2278 /* Whether to use new plt/got layout or not. */
2279 unsigned int new_plt:1;
2280 unsigned int old_plt:1;
2282 /* Small local sym to section mapping cache. */
2283 struct sym_sec_cache sym_sec;
2286 /* Get the PPC ELF linker hash table from a link_info structure. */
2288 #define ppc_elf_hash_table(p) \
2289 ((struct ppc_elf_link_hash_table *) (p)->hash)
2291 /* Create an entry in a PPC ELF linker hash table. */
2293 static struct bfd_hash_entry *
2294 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2295 struct bfd_hash_table *table,
2298 /* Allocate the structure if it has not already been allocated by a
2302 entry = bfd_hash_allocate (table,
2303 sizeof (struct ppc_elf_link_hash_entry));
2308 /* Call the allocation method of the superclass. */
2309 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2312 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
2313 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
2314 ppc_elf_hash_entry (entry)->tls_mask = 0;
2320 /* Create a PPC ELF linker hash table. */
2322 static struct bfd_link_hash_table *
2323 ppc_elf_link_hash_table_create (bfd *abfd)
2325 struct ppc_elf_link_hash_table *ret;
2327 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
2331 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
2332 ppc_elf_link_hash_newfunc))
2338 ret->sdata[0].name = ".sdata";
2339 ret->sdata[0].sym_name = "_SDA_BASE_";
2340 ret->sdata[0].bss_name = ".sbss";
2342 ret->sdata[1].name = ".sdata2";
2343 ret->sdata[1].sym_name = "_SDA2_BASE_";
2344 ret->sdata[1].bss_name = ".sbss2";
2346 return &ret->elf.root;
2349 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2352 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2354 struct ppc_elf_link_hash_table *htab;
2358 if (!_bfd_elf_create_got_section (abfd, info))
2361 htab = ppc_elf_hash_table (info);
2362 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2366 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2367 | SEC_LINKER_CREATED);
2368 if (!bfd_set_section_flags (abfd, s, flags))
2371 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2372 | SEC_LINKER_CREATED | SEC_READONLY);
2373 htab->relgot = bfd_make_section_with_flags (abfd, ".rela.got", flags);
2375 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2381 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2382 to output sections (just like _bfd_elf_create_dynamic_sections has
2383 to create .dynbss and .rela.bss). */
2386 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2388 struct ppc_elf_link_hash_table *htab;
2392 htab = ppc_elf_hash_table (info);
2394 if (htab->got == NULL
2395 && !ppc_elf_create_got (abfd, info))
2398 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2401 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
2402 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2404 s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags | SEC_CODE);
2407 || !bfd_set_section_alignment (abfd, s, 4))
2410 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2411 s = bfd_make_section_with_flags (abfd, ".dynsbss",
2412 SEC_ALLOC | SEC_LINKER_CREATED);
2419 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2420 s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags);
2423 || ! bfd_set_section_alignment (abfd, s, 2))
2427 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2428 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2432 flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
2433 return bfd_set_section_flags (abfd, s, flags);
2436 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2439 ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
2440 struct elf_link_hash_entry *dir,
2441 struct elf_link_hash_entry *ind)
2443 struct ppc_elf_link_hash_entry *edir, *eind;
2445 edir = (struct ppc_elf_link_hash_entry *) dir;
2446 eind = (struct ppc_elf_link_hash_entry *) ind;
2448 if (eind->dyn_relocs != NULL)
2450 if (edir->dyn_relocs != NULL)
2452 struct ppc_elf_dyn_relocs **pp;
2453 struct ppc_elf_dyn_relocs *p;
2455 if (ind->root.type == bfd_link_hash_indirect)
2458 /* Add reloc counts against the weak sym to the strong sym
2459 list. Merge any entries against the same section. */
2460 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2462 struct ppc_elf_dyn_relocs *q;
2464 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2465 if (q->sec == p->sec)
2467 q->pc_count += p->pc_count;
2468 q->count += p->count;
2475 *pp = edir->dyn_relocs;
2478 edir->dyn_relocs = eind->dyn_relocs;
2479 eind->dyn_relocs = NULL;
2482 edir->tls_mask |= eind->tls_mask;
2484 if (ELIMINATE_COPY_RELOCS
2485 && ind->root.type != bfd_link_hash_indirect
2486 && dir->dynamic_adjusted)
2488 /* If called to transfer flags for a weakdef during processing
2489 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2490 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2491 dir->ref_dynamic |= ind->ref_dynamic;
2492 dir->ref_regular |= ind->ref_regular;
2493 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
2494 dir->needs_plt |= ind->needs_plt;
2497 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
2500 /* Return 1 if target is one of ours. */
2503 is_ppc_elf_target (const struct bfd_target *targ)
2505 extern const bfd_target bfd_elf32_powerpc_vec;
2506 extern const bfd_target bfd_elf32_powerpcle_vec;
2508 return targ == &bfd_elf32_powerpc_vec || targ == &bfd_elf32_powerpcle_vec;
2511 /* Hook called by the linker routine which adds symbols from an object
2512 file. We use it to put .comm items in .sbss, and not .bss. */
2515 ppc_elf_add_symbol_hook (bfd *abfd,
2516 struct bfd_link_info *info,
2517 Elf_Internal_Sym *sym,
2518 const char **namep ATTRIBUTE_UNUSED,
2519 flagword *flagsp ATTRIBUTE_UNUSED,
2523 if (sym->st_shndx == SHN_COMMON
2524 && !info->relocatable
2525 && sym->st_size <= elf_gp_size (abfd)
2526 && is_ppc_elf_target (info->hash->creator))
2528 /* Common symbols less than or equal to -G nn bytes are automatically
2530 struct ppc_elf_link_hash_table *htab;
2532 htab = ppc_elf_hash_table (info);
2533 if (htab->sbss == NULL)
2535 flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
2537 if (!htab->elf.dynobj)
2538 htab->elf.dynobj = abfd;
2540 htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2543 if (htab->sbss == NULL)
2548 *valp = sym->st_size;
2554 /* Create a special linker section. */
2557 ppc_elf_create_linker_section (bfd *abfd,
2558 struct bfd_link_info *info,
2560 elf_linker_section_t *lsect)
2562 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2565 flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2566 | SEC_LINKER_CREATED);
2568 /* Record the first bfd that needs the special sections. */
2569 if (!htab->elf.dynobj)
2570 htab->elf.dynobj = abfd;
2572 s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2576 || !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2583 /* Find a linker generated pointer with a given addend and type. */
2585 static elf_linker_section_pointers_t *
2586 elf_find_pointer_linker_section
2587 (elf_linker_section_pointers_t *linker_pointers,
2589 elf_linker_section_t *lsect)
2591 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
2592 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
2593 return linker_pointers;
2598 /* Allocate a pointer to live in a linker created section. */
2601 elf_create_pointer_linker_section (bfd *abfd,
2602 elf_linker_section_t *lsect,
2603 struct elf_link_hash_entry *h,
2604 const Elf_Internal_Rela *rel)
2606 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
2607 elf_linker_section_pointers_t *linker_section_ptr;
2608 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2611 BFD_ASSERT (lsect != NULL);
2613 /* Is this a global symbol? */
2616 struct ppc_elf_link_hash_entry *eh;
2618 /* Has this symbol already been allocated? If so, our work is done. */
2619 eh = (struct ppc_elf_link_hash_entry *) h;
2620 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
2625 ptr_linker_section_ptr = &eh->linker_section_pointer;
2629 /* Allocation of a pointer to a local symbol. */
2630 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
2632 /* Allocate a table to hold the local symbols if first time. */
2635 unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info;
2638 amt *= sizeof (elf_linker_section_pointers_t *);
2639 ptr = bfd_zalloc (abfd, amt);
2644 elf_local_ptr_offsets (abfd) = ptr;
2647 /* Has this symbol already been allocated? If so, our work is done. */
2648 if (elf_find_pointer_linker_section (ptr[r_symndx],
2653 ptr_linker_section_ptr = &ptr[r_symndx];
2656 /* Allocate space for a pointer in the linker section, and allocate
2657 a new pointer record from internal memory. */
2658 BFD_ASSERT (ptr_linker_section_ptr != NULL);
2659 amt = sizeof (elf_linker_section_pointers_t);
2660 linker_section_ptr = bfd_alloc (abfd, amt);
2662 if (!linker_section_ptr)
2665 linker_section_ptr->next = *ptr_linker_section_ptr;
2666 linker_section_ptr->addend = rel->r_addend;
2667 linker_section_ptr->lsect = lsect;
2668 *ptr_linker_section_ptr = linker_section_ptr;
2670 linker_section_ptr->offset = lsect->section->size;
2671 lsect->section->size += 4;
2675 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2676 lsect->name, (long) linker_section_ptr->offset,
2677 (long) lsect->section->size);
2684 update_local_sym_info (bfd *abfd,
2685 Elf_Internal_Shdr *symtab_hdr,
2686 unsigned long r_symndx,
2689 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
2690 char *local_got_tls_masks;
2692 if (local_got_refcounts == NULL)
2694 bfd_size_type size = symtab_hdr->sh_info;
2696 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
2697 local_got_refcounts = bfd_zalloc (abfd, size);
2698 if (local_got_refcounts == NULL)
2700 elf_local_got_refcounts (abfd) = local_got_refcounts;
2703 local_got_refcounts[r_symndx] += 1;
2704 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
2705 local_got_tls_masks[r_symndx] |= tls_type;
2710 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
2712 (*_bfd_error_handler)
2713 (_("%B: relocation %s cannot be used when making a shared object"),
2715 ppc_elf_howto_table[r_type]->name);
2716 bfd_set_error (bfd_error_bad_value);
2719 /* Look through the relocs for a section during the first phase, and
2720 allocate space in the global offset table or procedure linkage
2724 ppc_elf_check_relocs (bfd *abfd,
2725 struct bfd_link_info *info,
2727 const Elf_Internal_Rela *relocs)
2729 struct ppc_elf_link_hash_table *htab;
2730 Elf_Internal_Shdr *symtab_hdr;
2731 struct elf_link_hash_entry **sym_hashes;
2732 const Elf_Internal_Rela *rel;
2733 const Elf_Internal_Rela *rel_end;
2736 if (info->relocatable)
2739 /* Don't do anything special with non-loaded, non-alloced sections.
2740 In particular, any relocs in such sections should not affect GOT
2741 and PLT reference counting (ie. we don't allow them to create GOT
2742 or PLT entries), there's no possibility or desire to optimize TLS
2743 relocs, and there's not much point in propagating relocs to shared
2744 libs that the dynamic linker won't relocate. */
2745 if ((sec->flags & SEC_ALLOC) == 0)
2749 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
2753 /* Initialize howto table if not already done. */
2754 if (!ppc_elf_howto_table[R_PPC_ADDR32])
2755 ppc_elf_howto_init ();
2757 htab = ppc_elf_hash_table (info);
2758 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2759 sym_hashes = elf_sym_hashes (abfd);
2762 rel_end = relocs + sec->reloc_count;
2763 for (rel = relocs; rel < rel_end; rel++)
2765 unsigned long r_symndx;
2766 enum elf_ppc_reloc_type r_type;
2767 struct elf_link_hash_entry *h;
2770 r_symndx = ELF32_R_SYM (rel->r_info);
2771 if (r_symndx < symtab_hdr->sh_info)
2774 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2776 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2777 This shows up in particular in an R_PPC_ADDR32 in the eabi
2780 && htab->got == NULL
2781 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2783 if (htab->elf.dynobj == NULL)
2784 htab->elf.dynobj = abfd;
2785 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2787 BFD_ASSERT (h == htab->elf.hgot);
2790 r_type = ELF32_R_TYPE (rel->r_info);
2793 case R_PPC_GOT_TLSLD16:
2794 case R_PPC_GOT_TLSLD16_LO:
2795 case R_PPC_GOT_TLSLD16_HI:
2796 case R_PPC_GOT_TLSLD16_HA:
2797 htab->tlsld_got.refcount += 1;
2798 tls_type = TLS_TLS | TLS_LD;
2801 case R_PPC_GOT_TLSGD16:
2802 case R_PPC_GOT_TLSGD16_LO:
2803 case R_PPC_GOT_TLSGD16_HI:
2804 case R_PPC_GOT_TLSGD16_HA:
2805 tls_type = TLS_TLS | TLS_GD;
2808 case R_PPC_GOT_TPREL16:
2809 case R_PPC_GOT_TPREL16_LO:
2810 case R_PPC_GOT_TPREL16_HI:
2811 case R_PPC_GOT_TPREL16_HA:
2813 info->flags |= DF_STATIC_TLS;
2814 tls_type = TLS_TLS | TLS_TPREL;
2817 case R_PPC_GOT_DTPREL16:
2818 case R_PPC_GOT_DTPREL16_LO:
2819 case R_PPC_GOT_DTPREL16_HI:
2820 case R_PPC_GOT_DTPREL16_HA:
2821 tls_type = TLS_TLS | TLS_DTPREL;
2823 sec->has_tls_reloc = 1;
2826 /* GOT16 relocations */
2828 case R_PPC_GOT16_LO:
2829 case R_PPC_GOT16_HI:
2830 case R_PPC_GOT16_HA:
2831 /* This symbol requires a global offset table entry. */
2832 if (htab->got == NULL)
2834 if (htab->elf.dynobj == NULL)
2835 htab->elf.dynobj = abfd;
2836 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2841 h->got.refcount += 1;
2842 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
2845 /* This is a global offset table entry for a local symbol. */
2846 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
2850 /* Indirect .sdata relocation. */
2851 case R_PPC_EMB_SDAI16:
2854 bad_shared_reloc (abfd, r_type);
2857 if (htab->sdata[0].section == NULL
2858 && !ppc_elf_create_linker_section (abfd, info, 0,
2861 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
2866 /* Indirect .sdata2 relocation. */
2867 case R_PPC_EMB_SDA2I16:
2870 bad_shared_reloc (abfd, r_type);
2873 if (htab->sdata[1].section == NULL
2874 && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
2877 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
2882 case R_PPC_SDAREL16:
2883 case R_PPC_EMB_SDA2REL:
2884 case R_PPC_EMB_SDA21:
2885 case R_PPC_EMB_RELSDA:
2886 case R_PPC_EMB_NADDR32:
2887 case R_PPC_EMB_NADDR16:
2888 case R_PPC_EMB_NADDR16_LO:
2889 case R_PPC_EMB_NADDR16_HI:
2890 case R_PPC_EMB_NADDR16_HA:
2893 bad_shared_reloc (abfd, r_type);
2899 case R_PPC_PLTREL24:
2900 case R_PPC_PLTREL32:
2901 case R_PPC_PLT16_LO:
2902 case R_PPC_PLT16_HI:
2903 case R_PPC_PLT16_HA:
2905 fprintf (stderr, "Reloc requires a PLT entry\n");
2907 /* This symbol requires a procedure linkage table entry. We
2908 actually build the entry in finish_dynamic_symbol,
2909 because this might be a case of linking PIC code without
2910 linking in any dynamic objects, in which case we don't
2911 need to generate a procedure linkage table after all. */
2915 /* It does not make sense to have a procedure linkage
2916 table entry for a local symbol. */
2917 (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
2921 (long) rel->r_offset,
2922 ppc_elf_howto_table[r_type]->name);
2923 bfd_set_error (bfd_error_bad_value);
2931 /* The following relocations don't need to propagate the
2932 relocation if linking a shared object since they are
2933 section relative. */
2935 case R_PPC_SECTOFF_LO:
2936 case R_PPC_SECTOFF_HI:
2937 case R_PPC_SECTOFF_HA:
2938 case R_PPC_DTPREL16:
2939 case R_PPC_DTPREL16_LO:
2940 case R_PPC_DTPREL16_HI:
2941 case R_PPC_DTPREL16_HA:
2946 case R_PPC_REL16_LO:
2947 case R_PPC_REL16_HI:
2948 case R_PPC_REL16_HA:
2952 /* This are just markers. */
2954 case R_PPC_EMB_MRKREF:
2959 /* These should only appear in dynamic objects. */
2961 case R_PPC_GLOB_DAT:
2962 case R_PPC_JMP_SLOT:
2963 case R_PPC_RELATIVE:
2966 /* These aren't handled yet. We'll report an error later. */
2968 case R_PPC_EMB_RELSEC16:
2969 case R_PPC_EMB_RELST_LO:
2970 case R_PPC_EMB_RELST_HI:
2971 case R_PPC_EMB_RELST_HA:
2972 case R_PPC_EMB_BIT_FLD:
2975 /* This refers only to functions defined in the shared library. */
2976 case R_PPC_LOCAL24PC:
2977 if (h && h == htab->elf.hgot)
2981 /* This relocation describes the C++ object vtable hierarchy.
2982 Reconstruct it for later use during GC. */
2983 case R_PPC_GNU_VTINHERIT:
2984 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2988 /* This relocation describes which C++ vtable entries are actually
2989 used. Record for later use during GC. */
2990 case R_PPC_GNU_VTENTRY:
2991 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2995 /* We shouldn't really be seeing these. */
2998 info->flags |= DF_STATIC_TLS;
3002 case R_PPC_DTPMOD32:
3003 case R_PPC_DTPREL32:
3007 case R_PPC_TPREL16_LO:
3008 case R_PPC_TPREL16_HI:
3009 case R_PPC_TPREL16_HA:
3011 info->flags |= DF_STATIC_TLS;
3014 /* When creating a shared object, we must copy these
3015 relocs into the output file. We create a reloc
3016 section in dynobj and make room for the reloc. */
3019 case R_PPC_REL14_BRTAKEN:
3020 case R_PPC_REL14_BRNTAKEN:
3024 if (h == htab->elf.hgot)
3034 case R_PPC_ADDR16_LO:
3035 case R_PPC_ADDR16_HI:
3036 case R_PPC_ADDR16_HA:
3038 case R_PPC_ADDR14_BRTAKEN:
3039 case R_PPC_ADDR14_BRNTAKEN:
3042 if (h != NULL && !info->shared)
3044 /* We may need a plt entry if the symbol turns out to be
3045 a function defined in a dynamic object. */
3048 /* We may need a copy reloc too. */
3053 /* If we are creating a shared library, and this is a reloc
3054 against a global symbol, or a non PC relative reloc
3055 against a local symbol, then we need to copy the reloc
3056 into the shared library. However, if we are linking with
3057 -Bsymbolic, we do not need to copy a reloc against a
3058 global symbol which is defined in an object we are
3059 including in the link (i.e., DEF_REGULAR is set). At
3060 this point we have not seen all the input files, so it is
3061 possible that DEF_REGULAR is not set now but will be set
3062 later (it is never cleared). In case of a weak definition,
3063 DEF_REGULAR may be cleared later by a strong definition in
3064 a shared library. We account for that possibility below by
3065 storing information in the dyn_relocs field of the hash
3066 table entry. A similar situation occurs when creating
3067 shared libraries and symbol visibility changes render the
3070 If on the other hand, we are creating an executable, we
3071 may need to keep relocations for symbols satisfied by a
3072 dynamic library if we manage to avoid copy relocs for the
3075 && (MUST_BE_DYN_RELOC (r_type)
3077 && (! info->symbolic
3078 || h->root.type == bfd_link_hash_defweak
3079 || !h->def_regular))))
3080 || (ELIMINATE_COPY_RELOCS
3083 && (h->root.type == bfd_link_hash_defweak
3084 || !h->def_regular)))
3086 struct ppc_elf_dyn_relocs *p;
3087 struct ppc_elf_dyn_relocs **head;
3091 "ppc_elf_check_relocs needs to "
3092 "create relocation for %s\n",
3093 (h && h->root.root.string
3094 ? h->root.root.string : "<unknown>"));
3100 name = (bfd_elf_string_from_elf_section
3102 elf_elfheader (abfd)->e_shstrndx,
3103 elf_section_data (sec)->rel_hdr.sh_name));
3107 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3108 && strcmp (bfd_get_section_name (abfd, sec),
3111 if (htab->elf.dynobj == NULL)
3112 htab->elf.dynobj = abfd;
3113 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3118 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3119 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3120 | SEC_ALLOC | SEC_LOAD);
3121 sreloc = bfd_make_section_with_flags (htab->elf.dynobj,
3125 || ! bfd_set_section_alignment (htab->elf.dynobj,
3129 elf_section_data (sec)->sreloc = sreloc;
3132 /* If this is a global symbol, we count the number of
3133 relocations we need for this symbol. */
3136 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3140 /* Track dynamic relocs needed for local syms too.
3141 We really need local syms available to do this
3145 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3150 head = ((struct ppc_elf_dyn_relocs **)
3151 &elf_section_data (s)->local_dynrel);
3155 if (p == NULL || p->sec != sec)
3157 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3168 if (!MUST_BE_DYN_RELOC (r_type))
3179 /* Merge backend specific data from an object file to the output
3180 object file when linking. */
3183 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
3189 if (!is_ppc_elf_target (ibfd->xvec)
3190 || !is_ppc_elf_target (obfd->xvec))
3193 /* Check if we have the same endianess. */
3194 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
3197 new_flags = elf_elfheader (ibfd)->e_flags;
3198 old_flags = elf_elfheader (obfd)->e_flags;
3199 if (!elf_flags_init (obfd))
3201 /* First call, no flags set. */
3202 elf_flags_init (obfd) = TRUE;
3203 elf_elfheader (obfd)->e_flags = new_flags;
3206 /* Compatible flags are ok. */
3207 else if (new_flags == old_flags)
3210 /* Incompatible flags. */
3213 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
3214 to be linked with either. */
3216 if ((new_flags & EF_PPC_RELOCATABLE) != 0
3217 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
3220 (*_bfd_error_handler)
3221 (_("%B: compiled with -mrelocatable and linked with "
3222 "modules compiled normally"), ibfd);
3224 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
3225 && (old_flags & EF_PPC_RELOCATABLE) != 0)
3228 (*_bfd_error_handler)
3229 (_("%B: compiled normally and linked with "
3230 "modules compiled with -mrelocatable"), ibfd);
3233 /* The output is -mrelocatable-lib iff both the input files are. */
3234 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
3235 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
3237 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
3238 but each input file is either -mrelocatable or -mrelocatable-lib. */
3239 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
3240 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
3241 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
3242 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
3244 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
3245 any module uses it. */
3246 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
3248 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3249 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3251 /* Warn about any other mismatches. */
3252 if (new_flags != old_flags)
3255 (*_bfd_error_handler)
3256 (_("%B: uses different e_flags (0x%lx) fields "
3257 "than previous modules (0x%lx)"),
3258 ibfd, (long) new_flags, (long) old_flags);
3263 bfd_set_error (bfd_error_bad_value);
3271 /* Choose which PLT scheme to use, and set .plt flags appropriately.
3272 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
3274 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
3275 struct bfd_link_info *info,
3278 struct ppc_elf_link_hash_table *htab;
3280 htab = ppc_elf_hash_table (info);
3281 if (force_old_plt || !htab->new_plt)
3286 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3287 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3289 /* The new PLT is a loaded section. */
3290 if (htab->plt != NULL
3291 && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
3294 /* The new GOT is not executable. */
3295 if (htab->got != NULL
3296 && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
3301 /* Stop an unused .glink section from affecting .text alignment. */
3302 if (htab->glink != NULL
3303 && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
3306 return !htab->old_plt;
3309 /* Return the section that should be marked against GC for a given
3313 ppc_elf_gc_mark_hook (asection *sec,
3314 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3315 Elf_Internal_Rela *rel,
3316 struct elf_link_hash_entry *h,
3317 Elf_Internal_Sym *sym)
3321 switch (ELF32_R_TYPE (rel->r_info))
3323 case R_PPC_GNU_VTINHERIT:
3324 case R_PPC_GNU_VTENTRY:
3328 switch (h->root.type)
3330 case bfd_link_hash_defined:
3331 case bfd_link_hash_defweak:
3332 return h->root.u.def.section;
3334 case bfd_link_hash_common:
3335 return h->root.u.c.p->section;
3343 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3348 /* Update the got, plt and dynamic reloc reference counts for the
3349 section being removed. */
3352 ppc_elf_gc_sweep_hook (bfd *abfd,
3353 struct bfd_link_info *info,
3355 const Elf_Internal_Rela *relocs)
3357 struct ppc_elf_link_hash_table *htab;
3358 Elf_Internal_Shdr *symtab_hdr;
3359 struct elf_link_hash_entry **sym_hashes;
3360 bfd_signed_vma *local_got_refcounts;
3361 const Elf_Internal_Rela *rel, *relend;
3363 if ((sec->flags & SEC_ALLOC) == 0)
3366 elf_section_data (sec)->local_dynrel = NULL;
3368 htab = ppc_elf_hash_table (info);
3369 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3370 sym_hashes = elf_sym_hashes (abfd);
3371 local_got_refcounts = elf_local_got_refcounts (abfd);
3373 relend = relocs + sec->reloc_count;
3374 for (rel = relocs; rel < relend; rel++)
3376 unsigned long r_symndx;
3377 enum elf_ppc_reloc_type r_type;
3378 struct elf_link_hash_entry *h = NULL;
3380 r_symndx = ELF32_R_SYM (rel->r_info);
3381 if (r_symndx >= symtab_hdr->sh_info)
3383 struct ppc_elf_dyn_relocs **pp, *p;
3384 struct ppc_elf_link_hash_entry *eh;
3386 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3387 while (h->root.type == bfd_link_hash_indirect
3388 || h->root.type == bfd_link_hash_warning)
3389 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3390 eh = (struct ppc_elf_link_hash_entry *) h;
3392 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3395 /* Everything must go for SEC. */
3401 r_type = ELF32_R_TYPE (rel->r_info);
3404 case R_PPC_GOT_TLSLD16:
3405 case R_PPC_GOT_TLSLD16_LO:
3406 case R_PPC_GOT_TLSLD16_HI:
3407 case R_PPC_GOT_TLSLD16_HA:
3408 htab->tlsld_got.refcount -= 1;
3411 case R_PPC_GOT_TLSGD16:
3412 case R_PPC_GOT_TLSGD16_LO:
3413 case R_PPC_GOT_TLSGD16_HI:
3414 case R_PPC_GOT_TLSGD16_HA:
3415 case R_PPC_GOT_TPREL16:
3416 case R_PPC_GOT_TPREL16_LO:
3417 case R_PPC_GOT_TPREL16_HI:
3418 case R_PPC_GOT_TPREL16_HA:
3419 case R_PPC_GOT_DTPREL16:
3420 case R_PPC_GOT_DTPREL16_LO:
3421 case R_PPC_GOT_DTPREL16_HI:
3422 case R_PPC_GOT_DTPREL16_HA:
3424 case R_PPC_GOT16_LO:
3425 case R_PPC_GOT16_HI:
3426 case R_PPC_GOT16_HA:
3429 if (h->got.refcount > 0)
3432 else if (local_got_refcounts != NULL)
3434 if (local_got_refcounts[r_symndx] > 0)
3435 local_got_refcounts[r_symndx]--;
3441 case R_PPC_REL14_BRTAKEN:
3442 case R_PPC_REL14_BRNTAKEN:
3444 if (h == NULL || h == htab->elf.hgot)
3451 case R_PPC_ADDR16_LO:
3452 case R_PPC_ADDR16_HI:
3453 case R_PPC_ADDR16_HA:
3455 case R_PPC_ADDR14_BRTAKEN:
3456 case R_PPC_ADDR14_BRNTAKEN:
3460 case R_PPC_PLTREL24:
3461 case R_PPC_PLT16_LO:
3462 case R_PPC_PLT16_HI:
3463 case R_PPC_PLT16_HA:
3466 if (h->plt.refcount > 0)
3478 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
3481 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
3483 struct ppc_elf_link_hash_table *htab;
3485 htab = ppc_elf_hash_table (info);
3487 && htab->plt != NULL
3488 && htab->plt->output_section != NULL)
3490 elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
3491 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
3494 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3495 FALSE, FALSE, TRUE);
3496 return _bfd_elf_tls_setup (obfd, info);
3499 /* Run through all the TLS relocs looking for optimization
3503 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
3504 struct bfd_link_info *info)
3508 struct ppc_elf_link_hash_table *htab;
3510 if (info->relocatable || info->shared)
3513 htab = ppc_elf_hash_table (info);
3514 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3516 Elf_Internal_Sym *locsyms = NULL;
3517 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3519 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3520 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
3522 Elf_Internal_Rela *relstart, *rel, *relend;
3523 int expecting_tls_get_addr;
3525 /* Read the relocations. */
3526 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
3528 if (relstart == NULL)
3531 expecting_tls_get_addr = 0;
3532 relend = relstart + sec->reloc_count;
3533 for (rel = relstart; rel < relend; rel++)
3535 enum elf_ppc_reloc_type r_type;
3536 unsigned long r_symndx;
3537 struct elf_link_hash_entry *h = NULL;
3539 char tls_set, tls_clear;
3540 bfd_boolean is_local;
3542 r_symndx = ELF32_R_SYM (rel->r_info);
3543 if (r_symndx >= symtab_hdr->sh_info)
3545 struct elf_link_hash_entry **sym_hashes;
3547 sym_hashes = elf_sym_hashes (ibfd);
3548 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3549 while (h->root.type == bfd_link_hash_indirect
3550 || h->root.type == bfd_link_hash_warning)
3551 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3559 r_type = ELF32_R_TYPE (rel->r_info);
3562 case R_PPC_GOT_TLSLD16:
3563 case R_PPC_GOT_TLSLD16_LO:
3564 case R_PPC_GOT_TLSLD16_HI:
3565 case R_PPC_GOT_TLSLD16_HA:
3566 /* These relocs should never be against a symbol
3567 defined in a shared lib. Leave them alone if
3568 that turns out to be the case. */
3569 expecting_tls_get_addr = 0;
3570 htab->tlsld_got.refcount -= 1;
3577 expecting_tls_get_addr = 1;
3580 case R_PPC_GOT_TLSGD16:
3581 case R_PPC_GOT_TLSGD16_LO:
3582 case R_PPC_GOT_TLSGD16_HI:
3583 case R_PPC_GOT_TLSGD16_HA:
3589 tls_set = TLS_TLS | TLS_TPRELGD;
3591 expecting_tls_get_addr = 1;
3594 case R_PPC_GOT_TPREL16:
3595 case R_PPC_GOT_TPREL16_LO:
3596 case R_PPC_GOT_TPREL16_HI:
3597 case R_PPC_GOT_TPREL16_HA:
3598 expecting_tls_get_addr = 0;
3603 tls_clear = TLS_TPREL;
3610 case R_PPC_REL14_BRTAKEN:
3611 case R_PPC_REL14_BRNTAKEN:
3613 if (expecting_tls_get_addr
3615 && h == htab->tls_get_addr)
3617 if (h->plt.refcount > 0)
3618 h->plt.refcount -= 1;
3620 expecting_tls_get_addr = 0;
3624 expecting_tls_get_addr = 0;
3632 /* We managed to get rid of a got entry. */
3633 if (h->got.refcount > 0)
3634 h->got.refcount -= 1;
3636 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
3640 Elf_Internal_Sym *sym;
3641 bfd_signed_vma *lgot_refs;
3644 if (locsyms == NULL)
3646 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
3647 if (locsyms == NULL)
3648 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3649 symtab_hdr->sh_info,
3650 0, NULL, NULL, NULL);
3651 if (locsyms == NULL)
3653 if (elf_section_data (sec)->relocs != relstart)
3658 sym = locsyms + r_symndx;
3659 lgot_refs = elf_local_got_refcounts (ibfd);
3660 if (lgot_refs == NULL)
3664 /* We managed to get rid of a got entry. */
3665 if (lgot_refs[r_symndx] > 0)
3666 lgot_refs[r_symndx] -= 1;
3668 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
3669 tls_mask = &lgot_masks[r_symndx];
3672 *tls_mask |= tls_set;
3673 *tls_mask &= ~tls_clear;
3676 if (elf_section_data (sec)->relocs != relstart)
3681 && (symtab_hdr->contents != (unsigned char *) locsyms))
3683 if (!info->keep_memory)
3686 symtab_hdr->contents = (unsigned char *) locsyms;
3692 /* Adjust a symbol defined by a dynamic object and referenced by a
3693 regular object. The current definition is in some section of the
3694 dynamic object, but we're not including those sections. We have to
3695 change the definition to something the rest of the link can
3699 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3700 struct elf_link_hash_entry *h)
3702 struct ppc_elf_link_hash_table *htab;
3704 unsigned int power_of_two;
3707 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
3708 h->root.root.string);
3711 /* Make sure we know what is going on here. */
3712 htab = ppc_elf_hash_table (info);
3713 BFD_ASSERT (htab->elf.dynobj != NULL
3715 || h->u.weakdef != NULL
3718 && !h->def_regular)));
3720 /* Deal with function syms. */
3721 if (h->type == STT_FUNC
3724 /* Clear procedure linkage table information for any symbol that
3725 won't need a .plt entry. */
3726 if (h->plt.refcount <= 0
3727 || SYMBOL_CALLS_LOCAL (info, h)
3728 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3729 && h->root.type == bfd_link_hash_undefweak))
3731 /* A PLT entry is not required/allowed when:
3733 1. We are not using ld.so; because then the PLT entry
3734 can't be set up, so we can't use one. In this case,
3735 ppc_elf_adjust_dynamic_symbol won't even be called.
3737 2. GC has rendered the entry unused.
3739 3. We know for certain that a call to this symbol
3740 will go to this object, or will remain undefined. */
3741 h->plt.offset = (bfd_vma) -1;
3747 h->plt.offset = (bfd_vma) -1;
3749 /* If this is a weak symbol, and there is a real definition, the
3750 processor independent code will have arranged for us to see the
3751 real definition first, and we can just use the same value. */
3752 if (h->u.weakdef != NULL)
3754 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3755 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3756 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3757 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3758 if (ELIMINATE_COPY_RELOCS)
3759 h->non_got_ref = h->u.weakdef->non_got_ref;
3763 /* This is a reference to a symbol defined by a dynamic object which
3764 is not a function. */
3766 /* If we are creating a shared library, we must presume that the
3767 only references to the symbol are via the global offset table.
3768 For such cases we need not do anything here; the relocations will
3769 be handled correctly by relocate_section. */
3773 /* If there are no references to this symbol that do not use the
3774 GOT, we don't need to generate a copy reloc. */
3775 if (!h->non_got_ref)
3778 if (ELIMINATE_COPY_RELOCS)
3780 struct ppc_elf_dyn_relocs *p;
3781 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3783 s = p->sec->output_section;
3784 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3788 /* If we didn't find any dynamic relocs in read-only sections, then
3789 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3797 /* We must allocate the symbol in our .dynbss section, which will
3798 become part of the .bss section of the executable. There will be
3799 an entry for this symbol in the .dynsym section. The dynamic
3800 object will contain position independent code, so all references
3801 from the dynamic object to this symbol will go through the global
3802 offset table. The dynamic linker will use the .dynsym entry to
3803 determine the address it must put in the global offset table, so
3804 both the dynamic object and the regular object will refer to the
3805 same memory location for the variable.
3807 Of course, if the symbol is sufficiently small, we must instead
3808 allocate it in .sbss. FIXME: It would be better to do this if and
3809 only if there were actually SDAREL relocs for that symbol. */
3811 if (h->size <= elf_gp_size (htab->elf.dynobj))
3815 BFD_ASSERT (s != NULL);
3817 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3818 copy the initial value out of the dynamic object and into the
3819 runtime process image. We need to remember the offset into the
3820 .rela.bss section we are going to use. */
3821 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3825 if (h->size <= elf_gp_size (htab->elf.dynobj))
3826 srel = htab->relsbss;
3828 srel = htab->relbss;
3829 BFD_ASSERT (srel != NULL);
3830 srel->size += sizeof (Elf32_External_Rela);
3834 /* We need to figure out the alignment required for this symbol. I
3835 have no idea how ELF linkers handle this. */
3836 power_of_two = bfd_log2 (h->size);
3837 if (power_of_two > 4)
3840 /* Apply the required alignment. */
3841 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
3842 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3844 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3848 /* Define the symbol as being at this point in the section. */
3849 h->root.u.def.section = s;
3850 h->root.u.def.value = s->size;
3852 /* Increment the section size to make room for the symbol. */
3858 /* Allocate NEED contiguous space in .got, and return the offset.
3859 Handles allocation of the got header when crossing 32k. */
3862 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
3865 unsigned int max_before_header = 32768;
3868 max_before_header = 32764;
3870 if (need <= htab->got_gap)
3872 where = max_before_header - htab->got_gap;
3873 htab->got_gap -= need;
3877 if (htab->got->size + need > max_before_header
3878 && htab->got->size <= max_before_header)
3880 htab->got_gap = max_before_header - htab->got->size;
3881 htab->got->size = max_before_header + htab->got_header_size;
3883 where = htab->got->size;
3884 htab->got->size += need;
3889 /* Allocate space in associated reloc sections for dynamic relocs. */
3892 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3894 struct bfd_link_info *info = inf;
3895 struct ppc_elf_link_hash_entry *eh;
3896 struct ppc_elf_link_hash_table *htab;
3897 struct ppc_elf_dyn_relocs *p;
3899 if (h->root.type == bfd_link_hash_indirect)
3902 if (h->root.type == bfd_link_hash_warning)
3903 /* When warning symbols are created, they **replace** the "real"
3904 entry in the hash table, thus we never get to see the real
3905 symbol in a hash traversal. So look at it now. */
3906 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3908 htab = ppc_elf_hash_table (info);
3909 if (htab->elf.dynamic_sections_created
3910 && h->plt.refcount > 0)
3912 /* Make sure this symbol is output as a dynamic symbol. */
3913 if (h->dynindx == -1
3914 && !h->forced_local)
3916 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3921 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3923 asection *s = htab->plt;
3927 h->plt.offset = s->size;
3934 h->root.u.def.section = s;
3935 h->root.u.def.value = s->size;
3937 s->size += GLINK_ENTRY_SIZE;
3941 /* If this is the first .plt entry, make room for the
3942 special first entry. */
3944 s->size += PLT_INITIAL_ENTRY_SIZE;
3946 /* The PowerPC PLT is actually composed of two parts, the
3947 first part is 2 words (for a load and a jump), and then
3948 there is a remaining word available at the end. */
3949 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
3951 * ((s->size - PLT_INITIAL_ENTRY_SIZE)
3952 / PLT_ENTRY_SIZE)));
3954 /* If this symbol is not defined in a regular file, and we
3955 are not generating a shared library, then set the symbol
3956 to this location in the .plt. This is required to make
3957 function pointers compare as equal between the normal
3958 executable and the shared library. */
3962 h->root.u.def.section = s;
3963 h->root.u.def.value = h->plt.offset;
3966 /* Make room for this entry. After the 8192nd entry, room
3967 for two entries is allocated. */
3968 s->size += PLT_ENTRY_SIZE;
3969 if ((s->size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
3970 > PLT_NUM_SINGLE_ENTRIES)
3971 s->size += PLT_ENTRY_SIZE;
3974 /* We also need to make an entry in the .rela.plt section. */
3975 htab->relplt->size += sizeof (Elf32_External_Rela);
3979 h->plt.offset = (bfd_vma) -1;
3985 h->plt.offset = (bfd_vma) -1;
3989 eh = (struct ppc_elf_link_hash_entry *) h;
3990 if (eh->elf.got.refcount > 0)
3992 /* Make sure this symbol is output as a dynamic symbol. */
3993 if (eh->elf.dynindx == -1
3994 && !eh->elf.forced_local)
3996 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
4000 if (eh->tls_mask == (TLS_TLS | TLS_LD)
4001 && !eh->elf.def_dynamic)
4002 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4003 eh->elf.got.offset = (bfd_vma) -1;
4007 unsigned int need = 0;
4008 if ((eh->tls_mask & TLS_TLS) != 0)
4010 if ((eh->tls_mask & TLS_LD) != 0)
4012 if ((eh->tls_mask & TLS_GD) != 0)
4014 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
4016 if ((eh->tls_mask & TLS_DTPREL) != 0)
4021 eh->elf.got.offset = allocate_got (htab, need);
4022 dyn = htab->elf.dynamic_sections_created;
4024 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
4025 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
4026 || eh->elf.root.type != bfd_link_hash_undefweak))
4028 /* All the entries we allocated need relocs.
4029 Except LD only needs one. */
4030 if ((eh->tls_mask & TLS_LD) != 0)
4032 htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4);
4037 eh->elf.got.offset = (bfd_vma) -1;
4039 if (eh->dyn_relocs == NULL)
4042 /* In the shared -Bsymbolic case, discard space allocated for
4043 dynamic pc-relative relocs against symbols which turn out to be
4044 defined in regular objects. For the normal shared case, discard
4045 space for relocs that have become local due to symbol visibility
4050 /* Relocs that use pc_count are those that appear on a call insn,
4051 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
4052 generated via assembly. We want calls to protected symbols to
4053 resolve directly to the function rather than going via the plt.
4054 If people want function pointer comparisons to work as expected
4055 then they should avoid writing weird assembly. */
4056 if (SYMBOL_CALLS_LOCAL (info, h))
4058 struct ppc_elf_dyn_relocs **pp;
4060 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4062 p->count -= p->pc_count;
4071 /* Also discard relocs on undefined weak syms with non-default
4073 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4074 && h->root.type == bfd_link_hash_undefweak)
4075 eh->dyn_relocs = NULL;
4077 /* Make sure undefined weak symbols are output as a dynamic symbol
4080 && eh->dyn_relocs != NULL
4082 && h->root.type == bfd_link_hash_undefweak
4083 && !h->forced_local)
4085 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4089 else if (ELIMINATE_COPY_RELOCS)
4091 /* For the non-shared case, discard space for relocs against
4092 symbols which turn out to need copy relocs or are not
4099 /* Make sure this symbol is output as a dynamic symbol.
4100 Undefined weak syms won't yet be marked as dynamic. */
4101 if (h->dynindx == -1
4102 && !h->forced_local)
4104 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4108 /* If that succeeded, we know we'll be keeping all the
4110 if (h->dynindx != -1)
4114 eh->dyn_relocs = NULL;
4119 /* Finally, allocate space. */
4120 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4122 asection *sreloc = elf_section_data (p->sec)->sreloc;
4123 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4129 /* Find any dynamic relocs that apply to read-only sections. */
4132 readonly_dynrelocs (struct elf_link_hash_entry *h, void *info)
4134 struct ppc_elf_dyn_relocs *p;
4136 if (h->root.type == bfd_link_hash_indirect)
4139 if (h->root.type == bfd_link_hash_warning)
4140 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4142 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
4144 asection *s = p->sec->output_section;
4147 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
4148 == (SEC_READONLY | SEC_ALLOC)))
4150 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
4152 /* Not an error, just cut short the traversal. */
4159 /* Set the sizes of the dynamic sections. */
4162 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4163 struct bfd_link_info *info)
4165 struct ppc_elf_link_hash_table *htab;
4171 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
4174 htab = ppc_elf_hash_table (info);
4175 BFD_ASSERT (htab->elf.dynobj != NULL);
4177 if (elf_hash_table (info)->dynamic_sections_created)
4179 /* Set the contents of the .interp section to the interpreter. */
4180 if (info->executable)
4182 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
4183 BFD_ASSERT (s != NULL);
4184 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4185 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4190 htab->got_header_size = 16;
4192 htab->got_header_size = 12;
4194 /* Set up .got offsets for local syms, and space for local dynamic
4196 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4198 bfd_signed_vma *local_got;
4199 bfd_signed_vma *end_local_got;
4201 bfd_size_type locsymcount;
4202 Elf_Internal_Shdr *symtab_hdr;
4204 if (!is_ppc_elf_target (ibfd->xvec))
4207 for (s = ibfd->sections; s != NULL; s = s->next)
4209 struct ppc_elf_dyn_relocs *p;
4211 for (p = ((struct ppc_elf_dyn_relocs *)
4212 elf_section_data (s)->local_dynrel);
4216 if (!bfd_is_abs_section (p->sec)
4217 && bfd_is_abs_section (p->sec->output_section))
4219 /* Input section has been discarded, either because
4220 it is a copy of a linkonce section or due to
4221 linker script /DISCARD/, so we'll be discarding
4224 else if (p->count != 0)
4226 elf_section_data (p->sec)->sreloc->size
4227 += p->count * sizeof (Elf32_External_Rela);
4228 if ((p->sec->output_section->flags
4229 & (SEC_READONLY | SEC_ALLOC))
4230 == (SEC_READONLY | SEC_ALLOC))
4231 info->flags |= DF_TEXTREL;
4236 local_got = elf_local_got_refcounts (ibfd);
4240 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4241 locsymcount = symtab_hdr->sh_info;
4242 end_local_got = local_got + locsymcount;
4243 lgot_masks = (char *) end_local_got;
4244 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
4247 if (*lgot_masks == (TLS_TLS | TLS_LD))
4249 /* If just an LD reloc, we'll just use
4250 htab->tlsld_got.offset. */
4251 htab->tlsld_got.refcount += 1;
4252 *local_got = (bfd_vma) -1;
4256 unsigned int need = 0;
4257 if ((*lgot_masks & TLS_TLS) != 0)
4259 if ((*lgot_masks & TLS_GD) != 0)
4261 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
4263 if ((*lgot_masks & TLS_DTPREL) != 0)
4268 *local_got = allocate_got (htab, need);
4270 htab->relgot->size += (need
4271 * (sizeof (Elf32_External_Rela) / 4));
4275 *local_got = (bfd_vma) -1;
4278 if (htab->tlsld_got.refcount > 0)
4280 htab->tlsld_got.offset = allocate_got (htab, 8);
4282 htab->relgot->size += sizeof (Elf32_External_Rela);
4285 htab->tlsld_got.offset = (bfd_vma) -1;
4287 /* Allocate space for global sym dynamic relocs. */
4288 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
4290 if (htab->got != NULL)
4292 unsigned int g_o_t = 32768;
4294 /* If we haven't allocated the header, do so now. */
4295 if (htab->got->size <= 32768)
4297 g_o_t = htab->got->size;
4298 htab->got->size += htab->got_header_size;
4303 htab->elf.hgot->root.u.def.value = g_o_t;
4306 if (htab->glink != NULL && htab->glink->size != 0)
4308 htab->glink_pltresolve = htab->glink->size;
4309 /* Space for the branch table. */
4310 htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
4311 /* Pad out to align the start of PLTresolve. */
4312 htab->glink->size += -htab->glink->size & 15;
4313 htab->glink->size += GLINK_PLTRESOLVE;
4316 /* We've now determined the sizes of the various dynamic sections.
4317 Allocate memory for them. */
4319 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
4321 if ((s->flags & SEC_LINKER_CREATED) == 0)
4329 /* Strip this section if we don't need it; see the
4332 else if (s == htab->sdata[0].section
4333 || s == htab->sdata[1].section)
4335 /* Strip these too. */
4337 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4341 /* If we don't need this section, strip it from the
4342 output file. This is mostly to handle .rela.bss and
4343 .rela.plt. We must create both sections in
4344 create_dynamic_sections, because they must be created
4345 before the linker maps input sections to output
4346 sections. The linker does that before
4347 adjust_dynamic_symbol is called, and it is that
4348 function which decides whether anything needs to go
4349 into these sections. */
4353 /* Remember whether there are any relocation sections. */
4356 /* We use the reloc_count field as a counter if we need
4357 to copy relocs into the output file. */
4363 /* It's not one of our sections, so don't allocate space. */
4369 s->flags |= SEC_EXCLUDE;
4373 if ((s->flags & SEC_HAS_CONTENTS) == 0)
4376 /* Allocate memory for the section contents. */
4377 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
4378 if (s->contents == NULL)
4382 if (htab->elf.dynamic_sections_created)
4384 /* Add some entries to the .dynamic section. We fill in the
4385 values later, in ppc_elf_finish_dynamic_sections, but we
4386 must add the entries now so that we get the correct size for
4387 the .dynamic section. The DT_DEBUG entry is filled in by the
4388 dynamic linker and used by the debugger. */
4389 #define add_dynamic_entry(TAG, VAL) \
4390 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4392 if (info->executable)
4394 if (!add_dynamic_entry (DT_DEBUG, 0))
4398 if (htab->plt != NULL && htab->plt->size != 0)
4400 if (!add_dynamic_entry (DT_PLTGOT, 0)
4401 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4402 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4403 || !add_dynamic_entry (DT_JMPREL, 0))
4407 if (htab->glink != NULL && htab->glink->size != 0)
4409 if (!add_dynamic_entry (DT_PPC_GLINK, 0))
4415 if (!add_dynamic_entry (DT_RELA, 0)
4416 || !add_dynamic_entry (DT_RELASZ, 0)
4417 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
4421 /* If any dynamic relocs apply to a read-only section, then we
4422 need a DT_TEXTREL entry. */
4423 if ((info->flags & DF_TEXTREL) == 0)
4424 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
4427 if ((info->flags & DF_TEXTREL) != 0)
4429 if (!add_dynamic_entry (DT_TEXTREL, 0))
4433 #undef add_dynamic_entry
4438 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
4440 static const int shared_stub_entry[] =
4442 0x7c0802a6, /* mflr 0 */
4443 0x429f0005, /* bcl 20, 31, .Lxxx */
4444 0x7d6802a6, /* mflr 11 */
4445 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
4446 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
4447 0x7c0803a6, /* mtlr 0 */
4448 0x7d6903a6, /* mtctr 11 */
4449 0x4e800420, /* bctr */
4452 static const int stub_entry[] =
4454 0x3d600000, /* lis 11,xxx@ha */
4455 0x396b0000, /* addi 11,11,xxx@l */
4456 0x7d6903a6, /* mtctr 11 */
4457 0x4e800420, /* bctr */
4461 ppc_elf_relax_section (bfd *abfd,
4463 struct bfd_link_info *link_info,
4468 struct one_fixup *next;
4474 Elf_Internal_Shdr *symtab_hdr;
4475 bfd_byte *contents = NULL;
4476 Elf_Internal_Sym *isymbuf = NULL;
4477 Elf_Internal_Rela *internal_relocs = NULL;
4478 Elf_Internal_Rela *irel, *irelend;
4479 struct one_fixup *fixups = NULL;
4480 bfd_boolean changed;
4481 struct ppc_elf_link_hash_table *htab;
4482 bfd_size_type trampoff;
4486 /* Nothing to do if there are no relocations, and no need to do
4487 anything with non-alloc sections. */
4488 if ((isec->flags & SEC_ALLOC) == 0
4489 || (isec->flags & SEC_RELOC) == 0
4490 || isec->reloc_count == 0)
4493 trampoff = (isec->size + 3) & (bfd_vma) -4;
4494 /* Space for a branch around any trampolines. */
4497 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4499 /* Get a copy of the native relocations. */
4500 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
4501 link_info->keep_memory);
4502 if (internal_relocs == NULL)
4505 htab = ppc_elf_hash_table (link_info);
4506 irelend = internal_relocs + isec->reloc_count;
4508 for (irel = internal_relocs; irel < irelend; irel++)
4510 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
4511 bfd_vma symaddr, reladdr, toff, roff;
4513 struct one_fixup *f;
4514 size_t insn_offset = 0;
4515 bfd_vma max_branch_offset, val;
4518 unsigned char sym_type;
4523 case R_PPC_LOCAL24PC:
4524 case R_PPC_PLTREL24:
4525 max_branch_offset = 1 << 25;
4529 case R_PPC_REL14_BRTAKEN:
4530 case R_PPC_REL14_BRNTAKEN:
4531 max_branch_offset = 1 << 15;
4538 /* Get the value of the symbol referred to by the reloc. */
4539 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4541 /* A local symbol. */
4542 Elf_Internal_Sym *isym;
4544 /* Read this BFD's local symbols. */
4545 if (isymbuf == NULL)
4547 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4548 if (isymbuf == NULL)
4549 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4550 symtab_hdr->sh_info, 0,
4555 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4556 if (isym->st_shndx == SHN_UNDEF)
4557 continue; /* We can't do anything with undefined symbols. */
4558 else if (isym->st_shndx == SHN_ABS)
4559 tsec = bfd_abs_section_ptr;
4560 else if (isym->st_shndx == SHN_COMMON)
4561 tsec = bfd_com_section_ptr;
4563 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4565 toff = isym->st_value;
4566 sym_type = ELF_ST_TYPE (isym->st_info);
4570 /* Global symbol handling. */
4572 struct elf_link_hash_entry *h;
4574 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4575 h = elf_sym_hashes (abfd)[indx];
4577 while (h->root.type == bfd_link_hash_indirect
4578 || h->root.type == bfd_link_hash_warning)
4579 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4581 if (r_type == R_PPC_PLTREL24
4582 && htab->plt != NULL
4583 && h->plt.offset != (bfd_vma) -1)
4588 toff = h->plt.offset * (GLINK_ENTRY_SIZE / 4);
4593 toff = h->plt.offset;
4596 else if (h->root.type == bfd_link_hash_defined
4597 || h->root.type == bfd_link_hash_defweak)
4599 tsec = h->root.u.def.section;
4600 toff = h->root.u.def.value;
4608 /* If the branch and target are in the same section, you have
4609 no hope of adding stubs. We'll error out later should the
4614 /* There probably isn't any reason to handle symbols in
4615 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
4616 attribute for a code section, and we are only looking at
4617 branches. However, implement it correctly here as a
4618 reference for other target relax_section functions. */
4619 if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
4621 /* At this stage in linking, no SEC_MERGE symbol has been
4622 adjusted, so all references to such symbols need to be
4623 passed through _bfd_merged_section_offset. (Later, in
4624 relocate_section, all SEC_MERGE symbols *except* for
4625 section symbols have been adjusted.)
4627 gas may reduce relocations against symbols in SEC_MERGE
4628 sections to a relocation against the section symbol when
4629 the original addend was zero. When the reloc is against
4630 a section symbol we should include the addend in the
4631 offset passed to _bfd_merged_section_offset, since the
4632 location of interest is the original symbol. On the
4633 other hand, an access to "sym+addend" where "sym" is not
4634 a section symbol should not include the addend; Such an
4635 access is presumed to be an offset from "sym"; The
4636 location of interest is just "sym". */
4637 if (sym_type == STT_SECTION)
4638 toff += irel->r_addend;
4640 toff = _bfd_merged_section_offset (abfd, &tsec,
4641 elf_section_data (tsec)->sec_info,
4644 if (sym_type != STT_SECTION)
4645 toff += irel->r_addend;
4648 toff += irel->r_addend;
4650 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
4652 roff = irel->r_offset;
4653 reladdr = isec->output_section->vma + isec->output_offset + roff;
4655 /* If the branch is in range, no need to do anything. */
4656 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
4659 /* Look for an existing fixup to this address. */
4660 for (f = fixups; f ; f = f->next)
4661 if (f->tsec == tsec && f->toff == toff)
4667 unsigned long stub_rtype;
4669 val = trampoff - roff;
4670 if (val >= max_branch_offset)
4671 /* Oh dear, we can't reach a trampoline. Don't try to add
4672 one. We'll report an error later. */
4675 if (link_info->shared)
4677 size = 4 * ARRAY_SIZE (shared_stub_entry);
4679 stub_rtype = R_PPC_RELAX32PC;
4683 size = 4 * ARRAY_SIZE (stub_entry);
4685 stub_rtype = R_PPC_RELAX32;
4688 if (R_PPC_RELAX32_PLT - R_PPC_RELAX32
4689 != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC)
4691 if (tsec == htab->plt
4692 || tsec == htab->glink)
4693 stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32;
4695 /* Hijack the old relocation. Since we need two
4696 relocations for this use a "composite" reloc. */
4697 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4699 irel->r_offset = trampoff + insn_offset;
4701 /* Record the fixup so we don't do it again this section. */
4702 f = bfd_malloc (sizeof (*f));
4706 f->trampoff = trampoff;
4713 val = f->trampoff - roff;
4714 if (val >= max_branch_offset)
4717 /* Nop out the reloc, since we're finalizing things here. */
4718 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
4721 /* Get the section contents. */
4722 if (contents == NULL)
4724 /* Get cached copy if it exists. */
4725 if (elf_section_data (isec)->this_hdr.contents != NULL)
4726 contents = elf_section_data (isec)->this_hdr.contents;
4729 /* Go get them off disk. */
4730 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
4735 /* Fix up the existing branch to hit the trampoline. */
4736 hit_addr = contents + roff;
4740 case R_PPC_LOCAL24PC:
4741 case R_PPC_PLTREL24:
4742 t0 = bfd_get_32 (abfd, hit_addr);
4744 t0 |= val & 0x3fffffc;
4745 bfd_put_32 (abfd, t0, hit_addr);
4749 case R_PPC_REL14_BRTAKEN:
4750 case R_PPC_REL14_BRNTAKEN:
4751 t0 = bfd_get_32 (abfd, hit_addr);
4754 bfd_put_32 (abfd, t0, hit_addr);
4759 /* Write out the trampolines. */
4760 changed = fixups != NULL;
4770 struct one_fixup *f = fixups;
4771 fixups = fixups->next;
4776 contents = bfd_realloc (contents, trampoff);
4777 if (contents == NULL)
4780 isec->size = (isec->size + 3) & (bfd_vma) -4;
4781 /* Branch around the trampolines. */
4782 val = trampoff - isec->size + 0x48000000;
4783 dest = contents + isec->size;
4784 isec->size = trampoff;
4785 bfd_put_32 (abfd, val, dest);
4788 if (link_info->shared)
4790 stub = shared_stub_entry;
4791 size = ARRAY_SIZE (shared_stub_entry);
4796 size = ARRAY_SIZE (stub_entry);
4800 while (dest < contents + trampoff)
4802 bfd_put_32 (abfd, stub[i], dest);
4808 BFD_ASSERT (i == 0);
4812 && symtab_hdr->contents != (unsigned char *) isymbuf)
4814 if (! link_info->keep_memory)
4818 /* Cache the symbols for elf_link_input_bfd. */
4819 symtab_hdr->contents = (unsigned char *) isymbuf;
4823 if (contents != NULL
4824 && elf_section_data (isec)->this_hdr.contents != contents)
4826 if (!changed && !link_info->keep_memory)
4830 /* Cache the section contents for elf_link_input_bfd. */
4831 elf_section_data (isec)->this_hdr.contents = contents;
4835 if (elf_section_data (isec)->relocs != internal_relocs)
4838 free (internal_relocs);
4840 elf_section_data (isec)->relocs = internal_relocs;
4847 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
4849 if (contents != NULL
4850 && elf_section_data (isec)->this_hdr.contents != contents)
4852 if (internal_relocs != NULL
4853 && elf_section_data (isec)->relocs != internal_relocs)
4854 free (internal_relocs);
4858 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms. They are
4859 set here rather than via PROVIDE in the default linker script,
4860 because using PROVIDE inside an output section statement results in
4861 unnecessary output sections. Using PROVIDE outside an output section
4862 statement runs the risk of section alignment affecting where the
4866 ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
4868 struct ppc_elf_link_hash_table *htab;
4873 htab = ppc_elf_hash_table (info);
4875 for (i = 0; i < 2; i++)
4877 elf_linker_section_t *lsect = &htab->sdata[i];
4881 s = s->output_section;
4883 s = bfd_get_section_by_name (obfd, lsect->name);
4885 s = bfd_get_section_by_name (obfd, lsect->bss_name);
4889 val = s->vma + 32768;
4890 lsect->sym_val = val;
4892 _bfd_elf_provide_symbol (info, lsect->sym_name, val);
4895 s = bfd_get_section_by_name (obfd, ".sbss");
4899 _bfd_elf_provide_symbol (info, "__sbss_start", val);
4900 _bfd_elf_provide_symbol (info, "___sbss_start", val);
4903 _bfd_elf_provide_symbol (info, "__sbss_end", val);
4904 _bfd_elf_provide_symbol (info, "___sbss_end", val);
4908 /* Fill in the address for a pointer generated in a linker section. */
4911 elf_finish_pointer_linker_section (bfd *input_bfd,
4912 elf_linker_section_t *lsect,
4913 struct elf_link_hash_entry *h,
4915 const Elf_Internal_Rela *rel)
4917 elf_linker_section_pointers_t *linker_section_ptr;
4919 BFD_ASSERT (lsect != NULL);
4923 /* Handle global symbol. */
4924 struct ppc_elf_link_hash_entry *eh;
4926 eh = (struct ppc_elf_link_hash_entry *) h;
4927 BFD_ASSERT (eh->elf.def_regular);
4928 linker_section_ptr = eh->linker_section_pointer;
4932 /* Handle local symbol. */
4933 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
4935 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
4936 linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
4939 linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
4942 BFD_ASSERT (linker_section_ptr != NULL);
4944 /* Offset will always be a multiple of four, so use the bottom bit
4945 as a "written" flag. */
4946 if ((linker_section_ptr->offset & 1) == 0)
4948 bfd_put_32 (lsect->section->owner,
4949 relocation + linker_section_ptr->addend,
4950 lsect->section->contents + linker_section_ptr->offset);
4951 linker_section_ptr->offset += 1;
4954 relocation = (lsect->section->output_offset
4955 + linker_section_ptr->offset - 1
4960 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
4961 lsect->name, (long) relocation, (long) relocation);
4964 /* Subtract out the addend, because it will get added back in by the normal
4966 return relocation - linker_section_ptr->addend;
4969 /* The RELOCATE_SECTION function is called by the ELF backend linker
4970 to handle the relocations for a section.
4972 The relocs are always passed as Rela structures; if the section
4973 actually uses Rel structures, the r_addend field will always be
4976 This function is responsible for adjust the section contents as
4977 necessary, and (if using Rela relocs and generating a
4978 relocatable output file) adjusting the reloc addend as
4981 This function does not have to worry about setting the reloc
4982 address or the reloc symbol index.
4984 LOCAL_SYMS is a pointer to the swapped in local symbols.
4986 LOCAL_SECTIONS is an array giving the section in the input file
4987 corresponding to the st_shndx field of each local symbol.
4989 The global hash table entry for the global symbols can be found
4990 via elf_sym_hashes (input_bfd).
4992 When generating relocatable output, this function must handle
4993 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4994 going to be the section symbol corresponding to the output
4995 section, which means that the addend must be adjusted
4999 ppc_elf_relocate_section (bfd *output_bfd,
5000 struct bfd_link_info *info,
5002 asection *input_section,
5004 Elf_Internal_Rela *relocs,
5005 Elf_Internal_Sym *local_syms,
5006 asection **local_sections)
5008 Elf_Internal_Shdr *symtab_hdr;
5009 struct elf_link_hash_entry **sym_hashes;
5010 struct ppc_elf_link_hash_table *htab;
5011 Elf_Internal_Rela *rel;
5012 Elf_Internal_Rela *relend;
5013 Elf_Internal_Rela outrel;
5015 asection *sreloc = NULL;
5016 bfd_vma *local_got_offsets;
5017 bfd_boolean ret = TRUE;
5020 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
5021 "%ld relocations%s",
5022 input_bfd, input_section,
5023 (long) input_section->reloc_count,
5024 (info->relocatable) ? " (relocatable)" : "");
5027 if (info->relocatable)
5030 /* Initialize howto table if not already done. */
5031 if (!ppc_elf_howto_table[R_PPC_ADDR32])
5032 ppc_elf_howto_init ();
5034 htab = ppc_elf_hash_table (info);
5035 local_got_offsets = elf_local_got_offsets (input_bfd);
5036 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5037 sym_hashes = elf_sym_hashes (input_bfd);
5039 relend = relocs + input_section->reloc_count;
5040 for (; rel < relend; rel++)
5042 enum elf_ppc_reloc_type r_type;
5044 bfd_reloc_status_type r;
5045 Elf_Internal_Sym *sym;
5047 struct elf_link_hash_entry *h;
5048 const char *sym_name;
5049 reloc_howto_type *howto;
5050 unsigned long r_symndx;
5052 bfd_vma branch_bit, insn, from;
5053 bfd_boolean unresolved_reloc;
5055 unsigned int tls_type, tls_mask, tls_gd;
5057 r_type = ELF32_R_TYPE (rel->r_info);
5061 unresolved_reloc = FALSE;
5063 r_symndx = ELF32_R_SYM (rel->r_info);
5065 if (r_symndx < symtab_hdr->sh_info)
5067 sym = local_syms + r_symndx;
5068 sec = local_sections[r_symndx];
5069 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
5071 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5075 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5076 r_symndx, symtab_hdr, sym_hashes,
5078 unresolved_reloc, warned);
5080 sym_name = h->root.root.string;
5083 /* TLS optimizations. Replace instruction sequences and relocs
5084 based on information we collected in tls_optimize. We edit
5085 RELOCS so that --emit-relocs will output something sensible
5086 for the final instruction stream. */
5089 if (IS_PPC_TLS_RELOC (r_type))
5092 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
5093 else if (local_got_offsets != NULL)
5096 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
5097 tls_mask = lgot_masks[r_symndx];
5101 /* Ensure reloc mapping code below stays sane. */
5102 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
5103 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
5104 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
5105 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
5106 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
5107 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
5108 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
5109 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
5116 case R_PPC_GOT_TPREL16:
5117 case R_PPC_GOT_TPREL16_LO:
5119 && (tls_mask & TLS_TPREL) == 0)
5122 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
5124 insn |= 0x3c020000; /* addis 0,2,0 */
5125 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
5126 r_type = R_PPC_TPREL16_HA;
5127 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5133 && (tls_mask & TLS_TPREL) == 0)
5136 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5137 if ((insn & ((31 << 26) | (31 << 11)))
5138 == ((31 << 26) | (2 << 11)))
5139 rtra = insn & ((1 << 26) - (1 << 16));
5140 else if ((insn & ((31 << 26) | (31 << 16)))
5141 == ((31 << 26) | (2 << 16)))
5142 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
5145 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
5148 else if ((insn & (31 << 1)) == 23 << 1
5149 && ((insn & (31 << 6)) < 14 << 6
5150 || ((insn & (31 << 6)) >= 16 << 6
5151 && (insn & (31 << 6)) < 24 << 6)))
5152 /* load and store indexed -> dform. */
5153 insn = (32 | ((insn >> 6) & 31)) << 26;
5154 else if ((insn & (31 << 1)) == 21 << 1
5155 && (insn & (0x1a << 6)) == 0)
5156 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
5157 insn = (((58 | ((insn >> 6) & 4)) << 26)
5158 | ((insn >> 6) & 1));
5159 else if ((insn & (31 << 1)) == 21 << 1
5160 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
5162 insn = (58 << 26) | 2;
5166 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5167 r_type = R_PPC_TPREL16_LO;
5168 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5169 /* Was PPC_TLS which sits on insn boundary, now
5170 PPC_TPREL16_LO which is at insn+2. */
5175 case R_PPC_GOT_TLSGD16_HI:
5176 case R_PPC_GOT_TLSGD16_HA:
5177 tls_gd = TLS_TPRELGD;
5178 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5182 case R_PPC_GOT_TLSLD16_HI:
5183 case R_PPC_GOT_TLSLD16_HA:
5184 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5187 if ((tls_mask & tls_gd) != 0)
5188 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5189 + R_PPC_GOT_TPREL16);
5192 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
5194 r_type = R_PPC_NONE;
5196 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5200 case R_PPC_GOT_TLSGD16:
5201 case R_PPC_GOT_TLSGD16_LO:
5202 tls_gd = TLS_TPRELGD;
5203 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5204 goto tls_get_addr_check;
5207 case R_PPC_GOT_TLSLD16:
5208 case R_PPC_GOT_TLSLD16_LO:
5209 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5212 if (rel + 1 < relend)
5214 enum elf_ppc_reloc_type r_type2;
5215 unsigned long r_symndx2;
5216 struct elf_link_hash_entry *h2;
5217 bfd_vma insn1, insn2;
5220 /* The next instruction should be a call to
5221 __tls_get_addr. Peek at the reloc to be sure. */
5222 r_type2 = ELF32_R_TYPE (rel[1].r_info);
5223 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
5224 if (r_symndx2 < symtab_hdr->sh_info
5225 || (r_type2 != R_PPC_REL14
5226 && r_type2 != R_PPC_REL14_BRTAKEN
5227 && r_type2 != R_PPC_REL14_BRNTAKEN
5228 && r_type2 != R_PPC_REL24
5229 && r_type2 != R_PPC_PLTREL24))
5232 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
5233 while (h2->root.type == bfd_link_hash_indirect
5234 || h2->root.type == bfd_link_hash_warning)
5235 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
5236 if (h2 == NULL || h2 != htab->tls_get_addr)
5239 /* OK, it checks out. Replace the call. */
5240 offset = rel[1].r_offset;
5241 insn1 = bfd_get_32 (output_bfd,
5242 contents + rel->r_offset - 2);
5243 if ((tls_mask & tls_gd) != 0)
5246 insn1 &= (1 << 26) - 1;
5247 insn1 |= 32 << 26; /* lwz */
5248 insn2 = 0x7c631214; /* add 3,3,2 */
5249 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
5250 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5251 + R_PPC_GOT_TPREL16);
5252 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5257 insn1 = 0x3c620000; /* addis 3,2,0 */
5258 insn2 = 0x38630000; /* addi 3,3,0 */
5261 /* Was an LD reloc. */
5263 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5264 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5266 r_type = R_PPC_TPREL16_HA;
5267 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5268 rel[1].r_info = ELF32_R_INFO (r_symndx,
5270 rel[1].r_offset += 2;
5272 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
5273 bfd_put_32 (output_bfd, insn2, contents + offset);
5276 /* We changed the symbol on an LD reloc. Start over
5277 in order to get h, sym, sec etc. right. */
5286 /* Handle other relocations that tweak non-addend part of insn. */
5293 /* Branch taken prediction relocations. */
5294 case R_PPC_ADDR14_BRTAKEN:
5295 case R_PPC_REL14_BRTAKEN:
5296 branch_bit = BRANCH_PREDICT_BIT;
5299 /* Branch not taken prediction relocations. */
5300 case R_PPC_ADDR14_BRNTAKEN:
5301 case R_PPC_REL14_BRNTAKEN:
5302 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5303 insn &= ~BRANCH_PREDICT_BIT;
5306 from = (rel->r_offset
5307 + input_section->output_offset
5308 + input_section->output_section->vma);
5310 /* Invert 'y' bit if not the default. */
5311 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
5312 insn ^= BRANCH_PREDICT_BIT;
5314 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5318 addend = rel->r_addend;
5321 if (r_type < R_PPC_max)
5322 howto = ppc_elf_howto_table[r_type];
5326 (*_bfd_error_handler)
5327 (_("%B: unknown relocation type %d for symbol %s"),
5328 input_bfd, (int) r_type, sym_name);
5330 bfd_set_error (bfd_error_bad_value);
5336 case R_PPC_EMB_MRKREF:
5337 case R_PPC_GNU_VTINHERIT:
5338 case R_PPC_GNU_VTENTRY:
5341 /* GOT16 relocations. Like an ADDR16 using the symbol's
5342 address in the GOT as relocation value instead of the
5343 symbol's value itself. Also, create a GOT entry for the
5344 symbol and put the symbol value there. */
5345 case R_PPC_GOT_TLSGD16:
5346 case R_PPC_GOT_TLSGD16_LO:
5347 case R_PPC_GOT_TLSGD16_HI:
5348 case R_PPC_GOT_TLSGD16_HA:
5349 tls_type = TLS_TLS | TLS_GD;
5352 case R_PPC_GOT_TLSLD16:
5353 case R_PPC_GOT_TLSLD16_LO:
5354 case R_PPC_GOT_TLSLD16_HI:
5355 case R_PPC_GOT_TLSLD16_HA:
5356 tls_type = TLS_TLS | TLS_LD;
5359 case R_PPC_GOT_TPREL16:
5360 case R_PPC_GOT_TPREL16_LO:
5361 case R_PPC_GOT_TPREL16_HI:
5362 case R_PPC_GOT_TPREL16_HA:
5363 tls_type = TLS_TLS | TLS_TPREL;
5366 case R_PPC_GOT_DTPREL16:
5367 case R_PPC_GOT_DTPREL16_LO:
5368 case R_PPC_GOT_DTPREL16_HI:
5369 case R_PPC_GOT_DTPREL16_HA:
5370 tls_type = TLS_TLS | TLS_DTPREL;
5374 case R_PPC_GOT16_LO:
5375 case R_PPC_GOT16_HI:
5376 case R_PPC_GOT16_HA:
5379 /* Relocation is to the entry for this symbol in the global
5385 if (htab->got == NULL)
5389 if (tls_type == (TLS_TLS | TLS_LD)
5391 || !h->def_dynamic))
5392 offp = &htab->tlsld_got.offset;
5396 dyn = htab->elf.dynamic_sections_created;
5397 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5399 && SYMBOL_REFERENCES_LOCAL (info, h)))
5400 /* This is actually a static link, or it is a
5401 -Bsymbolic link and the symbol is defined
5402 locally, or the symbol was forced to be local
5403 because of a version file. */
5408 unresolved_reloc = FALSE;
5410 offp = &h->got.offset;
5414 if (local_got_offsets == NULL)
5416 offp = &local_got_offsets[r_symndx];
5419 /* The offset must always be a multiple of 4. We use the
5420 least significant bit to record whether we have already
5421 processed this entry. */
5427 unsigned int tls_m = (tls_mask
5428 & (TLS_LD | TLS_GD | TLS_DTPREL
5429 | TLS_TPREL | TLS_TPRELGD));
5431 if (offp == &htab->tlsld_got.offset)
5437 /* We might have multiple got entries for this sym.
5438 Initialize them all. */
5443 if ((tls_m & TLS_LD) != 0)
5445 tls_ty = TLS_TLS | TLS_LD;
5448 else if ((tls_m & TLS_GD) != 0)
5450 tls_ty = TLS_TLS | TLS_GD;
5453 else if ((tls_m & TLS_DTPREL) != 0)
5455 tls_ty = TLS_TLS | TLS_DTPREL;
5456 tls_m &= ~TLS_DTPREL;
5458 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
5460 tls_ty = TLS_TLS | TLS_TPREL;
5464 /* Generate relocs for the dynamic linker. */
5465 if ((info->shared || indx != 0)
5467 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5468 || h->root.type != bfd_link_hash_undefweak))
5470 outrel.r_offset = (htab->got->output_section->vma
5471 + htab->got->output_offset
5473 outrel.r_addend = 0;
5474 if (tls_ty & (TLS_LD | TLS_GD))
5476 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
5477 if (tls_ty == (TLS_TLS | TLS_GD))
5479 loc = htab->relgot->contents;
5480 loc += (htab->relgot->reloc_count++
5481 * sizeof (Elf32_External_Rela));
5482 bfd_elf32_swap_reloca_out (output_bfd,
5484 outrel.r_offset += 4;
5486 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5489 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
5490 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5491 else if (tls_ty == (TLS_TLS | TLS_TPREL))
5492 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
5494 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
5496 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
5499 outrel.r_addend += relocation;
5500 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
5501 outrel.r_addend -= htab->elf.tls_sec->vma;
5503 loc = htab->relgot->contents;
5504 loc += (htab->relgot->reloc_count++
5505 * sizeof (Elf32_External_Rela));
5506 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5509 /* Init the .got section contents if we're not
5510 emitting a reloc. */
5513 bfd_vma value = relocation;
5515 if (tls_ty == (TLS_TLS | TLS_LD))
5517 else if (tls_ty != 0)
5519 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
5520 if (tls_ty == (TLS_TLS | TLS_TPREL))
5521 value += DTP_OFFSET - TP_OFFSET;
5523 if (tls_ty == (TLS_TLS | TLS_GD))
5525 bfd_put_32 (output_bfd, value,
5526 htab->got->contents + off + 4);
5530 bfd_put_32 (output_bfd, value,
5531 htab->got->contents + off);
5535 if (tls_ty & (TLS_LD | TLS_GD))
5544 if (off >= (bfd_vma) -2)
5547 if ((tls_type & TLS_TLS) != 0)
5549 if (tls_type != (TLS_TLS | TLS_LD))
5551 if ((tls_mask & TLS_LD) != 0
5553 || !h->def_dynamic))
5555 if (tls_type != (TLS_TLS | TLS_GD))
5557 if ((tls_mask & TLS_GD) != 0)
5559 if (tls_type != (TLS_TLS | TLS_DTPREL))
5561 if ((tls_mask & TLS_DTPREL) != 0)
5568 relocation = htab->got->output_offset + off;
5569 relocation -= htab->elf.hgot->root.u.def.value;
5571 /* Addends on got relocations don't make much sense.
5572 x+off@got is actually x@got+off, and since the got is
5573 generated by a hash table traversal, the value in the
5574 got at entry m+n bears little relation to the entry m. */
5576 (*_bfd_error_handler)
5577 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5580 (long) rel->r_offset,
5586 /* Relocations that need no special processing. */
5587 case R_PPC_LOCAL24PC:
5588 /* It makes no sense to point a local relocation
5589 at a symbol not in this object. */
5590 if (unresolved_reloc)
5592 if (! (*info->callbacks->undefined_symbol) (info,
5593 h->root.root.string,
5603 case R_PPC_DTPREL16:
5604 case R_PPC_DTPREL16_LO:
5605 case R_PPC_DTPREL16_HI:
5606 case R_PPC_DTPREL16_HA:
5607 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5610 /* Relocations that may need to be propagated if this is a shared
5613 case R_PPC_TPREL16_LO:
5614 case R_PPC_TPREL16_HI:
5615 case R_PPC_TPREL16_HA:
5616 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5617 /* The TPREL16 relocs shouldn't really be used in shared
5618 libs as they will result in DT_TEXTREL being set, but
5619 support them anyway. */
5623 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5626 case R_PPC_DTPREL32:
5627 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5630 case R_PPC_DTPMOD32:
5636 case R_PPC_REL16_LO:
5637 case R_PPC_REL16_HI:
5638 case R_PPC_REL16_HA:
5644 case R_PPC_REL14_BRTAKEN:
5645 case R_PPC_REL14_BRNTAKEN:
5646 /* If these relocations are not to a named symbol, they can be
5647 handled right here, no need to bother the dynamic linker. */
5648 if (SYMBOL_REFERENCES_LOCAL (info, h)
5649 || h == htab->elf.hgot)
5653 /* Relocations that always need to be propagated if this is a shared
5658 case R_PPC_ADDR16_LO:
5659 case R_PPC_ADDR16_HI:
5660 case R_PPC_ADDR16_HA:
5662 case R_PPC_ADDR14_BRTAKEN:
5663 case R_PPC_ADDR14_BRNTAKEN:
5666 /* r_symndx will be zero only for relocs against symbols
5667 from removed linkonce sections, or sections discarded by
5674 if ((input_section->flags & SEC_ALLOC) == 0)
5680 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5681 || h->root.type != bfd_link_hash_undefweak)
5682 && (MUST_BE_DYN_RELOC (r_type)
5683 || !SYMBOL_CALLS_LOCAL (info, h)))
5684 || (ELIMINATE_COPY_RELOCS
5690 && !h->def_regular))
5695 fprintf (stderr, "ppc_elf_relocate_section needs to "
5696 "create relocation for %s\n",
5697 (h && h->root.root.string
5698 ? h->root.root.string : "<unknown>"));
5701 /* When generating a shared object, these relocations
5702 are copied into the output file to be resolved at run
5708 name = (bfd_elf_string_from_elf_section
5710 elf_elfheader (input_bfd)->e_shstrndx,
5711 elf_section_data (input_section)->rel_hdr.sh_name));
5715 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5716 && strcmp (bfd_get_section_name (input_bfd,
5720 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
5721 BFD_ASSERT (sreloc != NULL);
5727 _bfd_elf_section_offset (output_bfd, info, input_section,
5729 if (outrel.r_offset == (bfd_vma) -1
5730 || outrel.r_offset == (bfd_vma) -2)
5731 skip = (int) outrel.r_offset;
5732 outrel.r_offset += (input_section->output_section->vma
5733 + input_section->output_offset);
5736 memset (&outrel, 0, sizeof outrel);
5737 else if (!SYMBOL_REFERENCES_LOCAL (info, h))
5739 unresolved_reloc = FALSE;
5740 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5741 outrel.r_addend = rel->r_addend;
5745 outrel.r_addend = relocation + rel->r_addend;
5747 if (r_type == R_PPC_ADDR32)
5748 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
5753 if (bfd_is_abs_section (sec))
5755 else if (sec == NULL || sec->owner == NULL)
5757 bfd_set_error (bfd_error_bad_value);
5764 /* We are turning this relocation into one
5765 against a section symbol. It would be
5766 proper to subtract the symbol's value,
5767 osec->vma, from the emitted reloc addend,
5768 but ld.so expects buggy relocs. */
5769 osec = sec->output_section;
5770 indx = elf_section_data (osec)->dynindx;
5771 BFD_ASSERT (indx > 0);
5774 printf ("indx=%d section=%s flags=%08x name=%s\n",
5775 indx, osec->name, osec->flags,
5776 h->root.root.string);
5780 outrel.r_info = ELF32_R_INFO (indx, r_type);
5784 loc = sreloc->contents;
5785 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5786 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5791 /* This reloc will be computed at runtime. We clear the memory
5792 so that it contains predictable value. */
5794 && ((input_section->flags & SEC_ALLOC) != 0
5795 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
5797 relocation = howto->pc_relative ? outrel.r_offset : 0;
5804 case R_PPC_RELAX32PC_PLT:
5805 case R_PPC_RELAX32_PLT:
5806 BFD_ASSERT (h != NULL
5807 && h->plt.offset != (bfd_vma) -1
5808 && htab->plt != NULL);
5811 relocation = (htab->glink->output_section->vma
5812 + htab->glink->output_offset
5813 + h->plt.offset * (GLINK_ENTRY_SIZE / 4));
5815 relocation = (htab->plt->output_section->vma
5816 + htab->plt->output_offset
5818 if (r_type == R_PPC_RELAX32_PLT)
5822 case R_PPC_RELAX32PC:
5823 relocation -= (input_section->output_section->vma
5824 + input_section->output_offset
5825 + rel->r_offset - 4);
5834 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
5835 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
5837 /* We're clearing the bits for R_PPC_ADDR16_HA
5838 and R_PPC_ADDR16_LO here. */
5842 /* t0 is HA, t1 is LO */
5843 relocation += addend;
5844 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
5845 t1 |= relocation & 0xffff;
5847 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
5848 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
5852 /* Indirect .sdata relocation. */
5853 case R_PPC_EMB_SDAI16:
5854 BFD_ASSERT (htab->sdata[0].section != NULL);
5856 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
5857 h, relocation, rel);
5860 /* Indirect .sdata2 relocation. */
5861 case R_PPC_EMB_SDA2I16:
5862 BFD_ASSERT (htab->sdata[1].section != NULL);
5864 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
5865 h, relocation, rel);
5868 /* Handle the TOC16 reloc. We want to use the offset within the .got
5869 section, not the actual VMA. This is appropriate when generating
5870 an embedded ELF object, for which the .got section acts like the
5871 AIX .toc section. */
5872 case R_PPC_TOC16: /* phony GOT16 relocations */
5873 BFD_ASSERT (sec != NULL);
5874 BFD_ASSERT (bfd_is_und_section (sec)
5875 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
5876 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
5878 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
5881 case R_PPC_PLTREL24:
5882 /* Relocation is to the entry for this symbol in the
5883 procedure linkage table. */
5884 BFD_ASSERT (h != NULL);
5886 if (h->plt.offset == (bfd_vma) -1
5887 || htab->plt == NULL)
5889 /* We didn't make a PLT entry for this symbol. This
5890 happens when statically linking PIC code, or when
5891 using -Bsymbolic. */
5895 unresolved_reloc = FALSE;
5897 relocation = (htab->glink->output_section->vma
5898 + htab->glink->output_offset
5899 + h->plt.offset * (GLINK_ENTRY_SIZE / 4));
5901 relocation = (htab->plt->output_section->vma
5902 + htab->plt->output_offset
5906 /* Relocate against _SDA_BASE_. */
5907 case R_PPC_SDAREL16:
5911 BFD_ASSERT (sec != NULL);
5912 name = bfd_get_section_name (abfd, sec->output_section);
5913 if (! ((strncmp (name, ".sdata", 6) == 0
5914 && (name[6] == 0 || name[6] == '.'))
5915 || (strncmp (name, ".sbss", 5) == 0
5916 && (name[5] == 0 || name[5] == '.'))))
5918 (*_bfd_error_handler)
5919 (_("%B: the target (%s) of a %s relocation is "
5920 "in the wrong output section (%s)"),
5926 addend -= htab->sdata[0].sym_val;
5930 /* Relocate against _SDA2_BASE_. */
5931 case R_PPC_EMB_SDA2REL:
5935 BFD_ASSERT (sec != NULL);
5936 name = bfd_get_section_name (abfd, sec->output_section);
5937 if (! (strncmp (name, ".sdata2", 7) == 0
5938 || strncmp (name, ".sbss2", 6) == 0))
5940 (*_bfd_error_handler)
5941 (_("%B: the target (%s) of a %s relocation is "
5942 "in the wrong output section (%s)"),
5948 bfd_set_error (bfd_error_bad_value);
5952 addend -= htab->sdata[1].sym_val;
5956 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5957 case R_PPC_EMB_SDA21:
5958 case R_PPC_EMB_RELSDA:
5963 BFD_ASSERT (sec != NULL);
5964 name = bfd_get_section_name (abfd, sec->output_section);
5965 if (((strncmp (name, ".sdata", 6) == 0
5966 && (name[6] == 0 || name[6] == '.'))
5967 || (strncmp (name, ".sbss", 5) == 0
5968 && (name[5] == 0 || name[5] == '.'))))
5971 addend -= htab->sdata[0].sym_val;
5974 else if (strncmp (name, ".sdata2", 7) == 0
5975 || strncmp (name, ".sbss2", 6) == 0)
5978 addend -= htab->sdata[1].sym_val;
5981 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
5982 || strcmp (name, ".PPC.EMB.sbss0") == 0)
5989 (*_bfd_error_handler)
5990 (_("%B: the target (%s) of a %s relocation is "
5991 "in the wrong output section (%s)"),
5997 bfd_set_error (bfd_error_bad_value);
6002 if (r_type == R_PPC_EMB_SDA21)
6003 { /* fill in register field */
6004 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
6005 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
6006 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
6011 /* Relocate against the beginning of the section. */
6013 case R_PPC_SECTOFF_LO:
6014 case R_PPC_SECTOFF_HI:
6015 case R_PPC_SECTOFF_HA:
6016 BFD_ASSERT (sec != NULL);
6017 addend -= sec->output_section->vma;
6020 /* Negative relocations. */
6021 case R_PPC_EMB_NADDR32:
6022 case R_PPC_EMB_NADDR16:
6023 case R_PPC_EMB_NADDR16_LO:
6024 case R_PPC_EMB_NADDR16_HI:
6025 case R_PPC_EMB_NADDR16_HA:
6026 addend -= 2 * relocation;
6030 case R_PPC_GLOB_DAT:
6031 case R_PPC_JMP_SLOT:
6032 case R_PPC_RELATIVE:
6034 case R_PPC_PLTREL32:
6035 case R_PPC_PLT16_LO:
6036 case R_PPC_PLT16_HI:
6037 case R_PPC_PLT16_HA:
6039 case R_PPC_EMB_RELSEC16:
6040 case R_PPC_EMB_RELST_LO:
6041 case R_PPC_EMB_RELST_HI:
6042 case R_PPC_EMB_RELST_HA:
6043 case R_PPC_EMB_BIT_FLD:
6044 (*_bfd_error_handler)
6045 (_("%B: relocation %s is not yet supported for symbol %s."),
6050 bfd_set_error (bfd_error_invalid_operation);
6055 /* Do any further special processing. */
6061 case R_PPC_ADDR16_HA:
6062 case R_PPC_REL16_HA:
6063 case R_PPC_GOT16_HA:
6064 case R_PPC_PLT16_HA:
6065 case R_PPC_SECTOFF_HA:
6066 case R_PPC_TPREL16_HA:
6067 case R_PPC_DTPREL16_HA:
6068 case R_PPC_GOT_TLSGD16_HA:
6069 case R_PPC_GOT_TLSLD16_HA:
6070 case R_PPC_GOT_TPREL16_HA:
6071 case R_PPC_GOT_DTPREL16_HA:
6072 case R_PPC_EMB_NADDR16_HA:
6073 case R_PPC_EMB_RELST_HA:
6074 /* It's just possible that this symbol is a weak symbol
6075 that's not actually defined anywhere. In that case,
6076 'sec' would be NULL, and we should leave the symbol
6077 alone (it will be set to zero elsewhere in the link). */
6079 /* Add 0x10000 if sign bit in 0:15 is set.
6080 Bits 0:15 are not used. */
6086 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
6087 "offset = %ld, addend = %ld\n",
6092 (long) rel->r_offset,
6096 if (unresolved_reloc
6097 && !((input_section->flags & SEC_DEBUGGING) != 0
6100 (*_bfd_error_handler)
6101 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6104 (long) rel->r_offset,
6110 r = _bfd_final_link_relocate (howto,
6118 if (r != bfd_reloc_ok)
6120 if (r == bfd_reloc_overflow)
6125 && h->root.type == bfd_link_hash_undefweak
6126 && howto->pc_relative)
6128 /* Assume this is a call protected by other code that
6129 detect the symbol is undefined. If this is the case,
6130 we can safely ignore the overflow. If not, the
6131 program is hosed anyway, and a little warning isn't
6137 if (! (*info->callbacks->reloc_overflow) (info,
6138 (h ? &h->root : NULL),
6149 (*_bfd_error_handler)
6150 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
6151 input_bfd, input_section,
6152 (long) rel->r_offset, howto->name, sym_name, (int) r);
6159 fprintf (stderr, "\n");
6165 /* Finish up dynamic symbol handling. We set the contents of various
6166 dynamic sections here. */
6169 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
6170 struct bfd_link_info *info,
6171 struct elf_link_hash_entry *h,
6172 Elf_Internal_Sym *sym)
6174 struct ppc_elf_link_hash_table *htab;
6177 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
6178 h->root.root.string);
6181 htab = ppc_elf_hash_table (info);
6182 BFD_ASSERT (htab->elf.dynobj != NULL);
6184 if (h->plt.offset != (bfd_vma) -1)
6186 Elf_Internal_Rela rela;
6188 bfd_vma reloc_index;
6191 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
6194 /* This symbol has an entry in the procedure linkage table. Set
6197 BFD_ASSERT (h->dynindx != -1);
6198 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
6202 /* We don't need to fill in the .plt. The ppc dynamic linker
6207 bfd_vma val = (htab->glink_pltresolve
6209 + htab->glink->output_section->vma
6210 + htab->glink->output_offset);
6211 bfd_put_32 (output_bfd, val, htab->plt->contents + h->plt.offset);
6214 /* Fill in the entry in the .rela.plt section. */
6215 rela.r_offset = (htab->plt->output_section->vma
6216 + htab->plt->output_offset
6218 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
6222 reloc_index = h->plt.offset / 4;
6225 reloc_index = ((h->plt.offset - PLT_INITIAL_ENTRY_SIZE)
6227 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
6228 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
6230 loc = (htab->relplt->contents
6231 + reloc_index * sizeof (Elf32_External_Rela));
6232 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6234 if (!h->def_regular)
6236 /* Mark the symbol as undefined, rather than as defined in
6237 the .plt section. Leave the value alone. */
6238 sym->st_shndx = SHN_UNDEF;
6239 /* If the symbol is weak, we do need to clear the value.
6240 Otherwise, the PLT entry would provide a definition for
6241 the symbol even if the symbol wasn't defined anywhere,
6242 and so the symbol would never be NULL. */
6243 if (!h->ref_regular_nonweak)
6251 Elf_Internal_Rela rela;
6254 /* This symbols needs a copy reloc. Set it up. */
6257 fprintf (stderr, ", copy");
6260 BFD_ASSERT (h->dynindx != -1);
6262 if (h->size <= elf_gp_size (htab->elf.dynobj))
6266 BFD_ASSERT (s != NULL);
6268 rela.r_offset = (h->root.u.def.value
6269 + h->root.u.def.section->output_section->vma
6270 + h->root.u.def.section->output_offset);
6271 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
6273 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6274 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6278 fprintf (stderr, "\n");
6281 /* Mark some specially defined symbols as absolute. */
6282 if (h == htab->elf.hgot
6283 || strcmp (h->root.root.string, "_DYNAMIC") == 0
6284 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
6285 sym->st_shndx = SHN_ABS;
6290 static enum elf_reloc_type_class
6291 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
6293 switch (ELF32_R_TYPE (rela->r_info))
6295 case R_PPC_RELATIVE:
6296 return reloc_class_relative;
6299 case R_PPC_JMP_SLOT:
6300 return reloc_class_plt;
6302 return reloc_class_copy;
6304 return reloc_class_normal;
6308 /* Finish up the dynamic sections. */
6311 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
6312 struct bfd_link_info *info)
6315 struct ppc_elf_link_hash_table *htab;
6318 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
6321 htab = ppc_elf_hash_table (info);
6322 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
6324 if (htab->elf.dynamic_sections_created)
6326 Elf32_External_Dyn *dyncon, *dynconend;
6328 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
6330 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6331 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6332 for (; dyncon < dynconend; dyncon++)
6334 Elf_Internal_Dyn dyn;
6337 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
6343 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6347 dyn.d_un.d_val = htab->relplt->size;
6352 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6357 dyn.d_un.d_ptr = (s->size - GLINK_PLTRESOLVE
6358 + s->output_section->vma + s->output_offset);
6365 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6369 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
6370 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
6371 if (htab->got != NULL)
6373 unsigned char *p = htab->got->contents;
6376 p += elf_hash_table (info)->hgot->root.u.def.value;
6378 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
6382 val = sdyn->output_section->vma + sdyn->output_offset;
6383 bfd_put_32 (output_bfd, val, p);
6385 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
6388 if (htab->glink != NULL && htab->glink->contents != NULL)
6391 unsigned char *endp;
6392 bfd_vma got, pltgot;
6394 static const unsigned int plt_resolve[] =
6408 #define PPC_LO(v) ((v) & 0xffff)
6409 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6410 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6412 got = (htab->elf.hgot->root.u.def.value
6413 + htab->elf.hgot->root.u.def.section->output_section->vma
6414 + htab->elf.hgot->root.u.def.section->output_offset);
6416 pltgot = (htab->plt->output_section->vma
6417 + htab->plt->output_offset
6420 /* Write the plt call stubs. */
6421 p = htab->glink->contents;
6422 endp = p + htab->glink_pltresolve;
6425 if (pltgot < 0x8000)
6427 bfd_put_32 (output_bfd, LWZ_11_X_30 + pltgot, p);
6429 bfd_put_32 (output_bfd, MTCTR_11, p);
6431 bfd_put_32 (output_bfd, BCTR, p);
6433 bfd_put_32 (output_bfd, NOP, p);
6438 bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (pltgot), p);
6440 bfd_put_32 (output_bfd, LWZ_11_X_11 + PPC_LO (pltgot), p);
6442 bfd_put_32 (output_bfd, MTCTR_11, p);
6444 bfd_put_32 (output_bfd, BCTR, p);
6450 /* Now build the branch table, one for each plt entry (less one),
6451 and perhaps some padding. */
6452 endp = htab->glink->contents;
6453 endp += htab->glink->size - GLINK_PLTRESOLVE;
6454 while (p < endp - 8 * 4)
6456 bfd_put_32 (output_bfd, B + endp - p, p);
6461 bfd_put_32 (output_bfd, NOP, p);
6465 got -= (htab->glink_pltresolve
6466 + htab->glink->output_section->vma
6467 + htab->glink->output_offset);
6469 /* Last comes the PLTresolve stub. */
6470 bfd_put_32 (output_bfd, ADDIS_11_11 + PPC_HA (got), p);
6472 bfd_put_32 (output_bfd, ADDI_11_11 + PPC_LO (got), p);
6475 for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
6477 bfd_put_32 (output_bfd, plt_resolve[i], p);
6480 if (ARRAY_SIZE (plt_resolve) + 2 != GLINK_PLTRESOLVE / 4)
6487 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6488 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6489 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6490 #define TARGET_BIG_NAME "elf32-powerpc"
6491 #define ELF_ARCH bfd_arch_powerpc
6492 #define ELF_MACHINE_CODE EM_PPC
6493 #ifdef __QNXTARGET__
6494 #define ELF_MAXPAGESIZE 0x1000
6496 #define ELF_MAXPAGESIZE 0x10000
6498 #define ELF_MINPAGESIZE 0x1000
6499 #define elf_info_to_howto ppc_elf_info_to_howto
6501 #ifdef EM_CYGNUS_POWERPC
6502 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6506 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6509 #define elf_backend_plt_not_loaded 1
6510 #define elf_backend_can_gc_sections 1
6511 #define elf_backend_can_refcount 1
6512 #define elf_backend_rela_normal 1
6514 #define bfd_elf32_mkobject ppc_elf_mkobject
6515 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6516 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6517 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6518 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6519 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6521 #define elf_backend_object_p ppc_elf_object_p
6522 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6523 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6524 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6525 #define elf_backend_relocate_section ppc_elf_relocate_section
6526 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6527 #define elf_backend_check_relocs ppc_elf_check_relocs
6528 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6529 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6530 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6531 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6532 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6533 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6534 #define elf_backend_fake_sections ppc_elf_fake_sections
6535 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6536 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6537 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6538 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6539 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6540 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6541 #define elf_backend_write_section ppc_elf_write_section
6542 #define elf_backend_special_sections ppc_elf_special_sections
6543 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6545 #include "elf32-target.h"