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
84 #define LIS_11 0x3d600000
85 #define LIS_12 0x3d800000
86 #define LWZU_0_X_12 0x840c0000
87 #define LWZ_0_X_12 0x800c0000
88 #define LWZ_12_4_12 0x818c0004
89 #define LWZ_12_X_12 0x818c0000
91 /* Offset of tp and dtp pointers from start of TLS block. */
92 #define TP_OFFSET 0x7000
93 #define DTP_OFFSET 0x8000
95 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
97 static reloc_howto_type ppc_elf_howto_raw[] = {
98 /* This reloc does nothing. */
99 HOWTO (R_PPC_NONE, /* type */
101 2, /* size (0 = byte, 1 = short, 2 = long) */
103 FALSE, /* pc_relative */
105 complain_overflow_bitfield, /* complain_on_overflow */
106 bfd_elf_generic_reloc, /* special_function */
107 "R_PPC_NONE", /* name */
108 FALSE, /* partial_inplace */
111 FALSE), /* pcrel_offset */
113 /* A standard 32 bit relocation. */
114 HOWTO (R_PPC_ADDR32, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 FALSE, /* pc_relative */
120 complain_overflow_bitfield, /* complain_on_overflow */
121 bfd_elf_generic_reloc, /* special_function */
122 "R_PPC_ADDR32", /* name */
123 FALSE, /* partial_inplace */
125 0xffffffff, /* dst_mask */
126 FALSE), /* pcrel_offset */
128 /* An absolute 26 bit branch; the lower two bits must be zero.
129 FIXME: we don't check that, we just clear them. */
130 HOWTO (R_PPC_ADDR24, /* type */
132 2, /* size (0 = byte, 1 = short, 2 = long) */
134 FALSE, /* pc_relative */
136 complain_overflow_bitfield, /* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_PPC_ADDR24", /* name */
139 FALSE, /* partial_inplace */
141 0x3fffffc, /* dst_mask */
142 FALSE), /* pcrel_offset */
144 /* A standard 16 bit relocation. */
145 HOWTO (R_PPC_ADDR16, /* type */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
149 FALSE, /* pc_relative */
151 complain_overflow_bitfield, /* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_PPC_ADDR16", /* name */
154 FALSE, /* partial_inplace */
156 0xffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
159 /* A 16 bit relocation without overflow. */
160 HOWTO (R_PPC_ADDR16_LO, /* type */
162 1, /* size (0 = byte, 1 = short, 2 = long) */
164 FALSE, /* pc_relative */
166 complain_overflow_dont,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_PPC_ADDR16_LO", /* name */
169 FALSE, /* partial_inplace */
171 0xffff, /* dst_mask */
172 FALSE), /* pcrel_offset */
174 /* The high order 16 bits of an address. */
175 HOWTO (R_PPC_ADDR16_HI, /* type */
177 1, /* size (0 = byte, 1 = short, 2 = long) */
179 FALSE, /* pc_relative */
181 complain_overflow_dont, /* complain_on_overflow */
182 bfd_elf_generic_reloc, /* special_function */
183 "R_PPC_ADDR16_HI", /* name */
184 FALSE, /* partial_inplace */
186 0xffff, /* dst_mask */
187 FALSE), /* pcrel_offset */
189 /* The high order 16 bits of an address, plus 1 if the contents of
190 the low 16 bits, treated as a signed number, is negative. */
191 HOWTO (R_PPC_ADDR16_HA, /* type */
193 1, /* size (0 = byte, 1 = short, 2 = long) */
195 FALSE, /* pc_relative */
197 complain_overflow_dont, /* complain_on_overflow */
198 ppc_elf_addr16_ha_reloc, /* special_function */
199 "R_PPC_ADDR16_HA", /* name */
200 FALSE, /* partial_inplace */
202 0xffff, /* dst_mask */
203 FALSE), /* pcrel_offset */
205 /* An absolute 16 bit branch; the lower two bits must be zero.
206 FIXME: we don't check that, we just clear them. */
207 HOWTO (R_PPC_ADDR14, /* type */
209 2, /* size (0 = byte, 1 = short, 2 = long) */
211 FALSE, /* pc_relative */
213 complain_overflow_bitfield, /* complain_on_overflow */
214 bfd_elf_generic_reloc, /* special_function */
215 "R_PPC_ADDR14", /* name */
216 FALSE, /* partial_inplace */
218 0xfffc, /* dst_mask */
219 FALSE), /* pcrel_offset */
221 /* An absolute 16 bit branch, for which bit 10 should be set to
222 indicate that the branch is expected to be taken. The lower two
223 bits must be zero. */
224 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
226 2, /* size (0 = byte, 1 = short, 2 = long) */
228 FALSE, /* pc_relative */
230 complain_overflow_bitfield, /* complain_on_overflow */
231 bfd_elf_generic_reloc, /* special_function */
232 "R_PPC_ADDR14_BRTAKEN",/* name */
233 FALSE, /* partial_inplace */
235 0xfffc, /* dst_mask */
236 FALSE), /* pcrel_offset */
238 /* An absolute 16 bit branch, for which bit 10 should be set to
239 indicate that the branch is not expected to be taken. The lower
240 two bits must be zero. */
241 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE, /* pc_relative */
247 complain_overflow_bitfield, /* complain_on_overflow */
248 bfd_elf_generic_reloc, /* special_function */
249 "R_PPC_ADDR14_BRNTAKEN",/* name */
250 FALSE, /* partial_inplace */
252 0xfffc, /* dst_mask */
253 FALSE), /* pcrel_offset */
255 /* A relative 26 bit branch; the lower two bits must be zero. */
256 HOWTO (R_PPC_REL24, /* type */
258 2, /* size (0 = byte, 1 = short, 2 = long) */
260 TRUE, /* pc_relative */
262 complain_overflow_signed, /* complain_on_overflow */
263 bfd_elf_generic_reloc, /* special_function */
264 "R_PPC_REL24", /* name */
265 FALSE, /* partial_inplace */
267 0x3fffffc, /* dst_mask */
268 TRUE), /* pcrel_offset */
270 /* A relative 16 bit branch; the lower two bits must be zero. */
271 HOWTO (R_PPC_REL14, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 TRUE, /* pc_relative */
277 complain_overflow_signed, /* complain_on_overflow */
278 bfd_elf_generic_reloc, /* special_function */
279 "R_PPC_REL14", /* name */
280 FALSE, /* partial_inplace */
282 0xfffc, /* dst_mask */
283 TRUE), /* pcrel_offset */
285 /* A relative 16 bit branch. Bit 10 should be set to indicate that
286 the branch is expected to be taken. The lower two bits must be
288 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
292 TRUE, /* pc_relative */
294 complain_overflow_signed, /* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_PPC_REL14_BRTAKEN", /* name */
297 FALSE, /* partial_inplace */
299 0xfffc, /* dst_mask */
300 TRUE), /* pcrel_offset */
302 /* A relative 16 bit branch. Bit 10 should be set to indicate that
303 the branch is not expected to be taken. The lower two bits must
305 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 TRUE, /* pc_relative */
311 complain_overflow_signed, /* complain_on_overflow */
312 bfd_elf_generic_reloc, /* special_function */
313 "R_PPC_REL14_BRNTAKEN",/* name */
314 FALSE, /* partial_inplace */
316 0xfffc, /* dst_mask */
317 TRUE), /* pcrel_offset */
319 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
321 HOWTO (R_PPC_GOT16, /* type */
323 1, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE, /* pc_relative */
327 complain_overflow_signed, /* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_PPC_GOT16", /* name */
330 FALSE, /* partial_inplace */
332 0xffff, /* dst_mask */
333 FALSE), /* pcrel_offset */
335 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
337 HOWTO (R_PPC_GOT16_LO, /* type */
339 1, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE, /* pc_relative */
343 complain_overflow_dont, /* complain_on_overflow */
344 bfd_elf_generic_reloc, /* special_function */
345 "R_PPC_GOT16_LO", /* name */
346 FALSE, /* partial_inplace */
348 0xffff, /* dst_mask */
349 FALSE), /* pcrel_offset */
351 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
353 HOWTO (R_PPC_GOT16_HI, /* type */
355 1, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE, /* pc_relative */
359 complain_overflow_bitfield, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_PPC_GOT16_HI", /* name */
362 FALSE, /* partial_inplace */
364 0xffff, /* dst_mask */
365 FALSE), /* pcrel_offset */
367 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
369 HOWTO (R_PPC_GOT16_HA, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_bitfield, /* complain_on_overflow */
376 ppc_elf_addr16_ha_reloc, /* special_function */
377 "R_PPC_GOT16_HA", /* name */
378 FALSE, /* partial_inplace */
380 0xffff, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* Like R_PPC_REL24, but referring to the procedure linkage table
384 entry for the symbol. */
385 HOWTO (R_PPC_PLTREL24, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 TRUE, /* pc_relative */
391 complain_overflow_signed, /* complain_on_overflow */
392 bfd_elf_generic_reloc, /* special_function */
393 "R_PPC_PLTREL24", /* name */
394 FALSE, /* partial_inplace */
396 0x3fffffc, /* dst_mask */
397 TRUE), /* pcrel_offset */
399 /* This is used only by the dynamic linker. The symbol should exist
400 both in the object being run and in some shared library. The
401 dynamic linker copies the data addressed by the symbol from the
402 shared library into the object, because the object being
403 run has to have the data at some particular address. */
404 HOWTO (R_PPC_COPY, /* type */
406 2, /* size (0 = byte, 1 = short, 2 = long) */
408 FALSE, /* pc_relative */
410 complain_overflow_bitfield, /* complain_on_overflow */
411 bfd_elf_generic_reloc, /* special_function */
412 "R_PPC_COPY", /* name */
413 FALSE, /* partial_inplace */
416 FALSE), /* pcrel_offset */
418 /* Like R_PPC_ADDR32, but used when setting global offset table
420 HOWTO (R_PPC_GLOB_DAT, /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 FALSE, /* pc_relative */
426 complain_overflow_bitfield, /* complain_on_overflow */
427 bfd_elf_generic_reloc, /* special_function */
428 "R_PPC_GLOB_DAT", /* name */
429 FALSE, /* partial_inplace */
431 0xffffffff, /* dst_mask */
432 FALSE), /* pcrel_offset */
434 /* Marks a procedure linkage table entry for a symbol. */
435 HOWTO (R_PPC_JMP_SLOT, /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE, /* pc_relative */
441 complain_overflow_bitfield, /* complain_on_overflow */
442 bfd_elf_generic_reloc, /* special_function */
443 "R_PPC_JMP_SLOT", /* name */
444 FALSE, /* partial_inplace */
447 FALSE), /* pcrel_offset */
449 /* Used only by the dynamic linker. When the object is run, this
450 longword is set to the load address of the object, plus the
452 HOWTO (R_PPC_RELATIVE, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE, /* pc_relative */
458 complain_overflow_bitfield, /* complain_on_overflow */
459 bfd_elf_generic_reloc, /* special_function */
460 "R_PPC_RELATIVE", /* name */
461 FALSE, /* partial_inplace */
463 0xffffffff, /* dst_mask */
464 FALSE), /* pcrel_offset */
466 /* Like R_PPC_REL24, but uses the value of the symbol within the
467 object rather than the final value. Normally used for
468 _GLOBAL_OFFSET_TABLE_. */
469 HOWTO (R_PPC_LOCAL24PC, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 TRUE, /* pc_relative */
475 complain_overflow_signed, /* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 "R_PPC_LOCAL24PC", /* name */
478 FALSE, /* partial_inplace */
480 0x3fffffc, /* dst_mask */
481 TRUE), /* pcrel_offset */
483 /* Like R_PPC_ADDR32, but may be unaligned. */
484 HOWTO (R_PPC_UADDR32, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE, /* pc_relative */
490 complain_overflow_bitfield, /* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 "R_PPC_UADDR32", /* name */
493 FALSE, /* partial_inplace */
495 0xffffffff, /* dst_mask */
496 FALSE), /* pcrel_offset */
498 /* Like R_PPC_ADDR16, but may be unaligned. */
499 HOWTO (R_PPC_UADDR16, /* type */
501 1, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE, /* pc_relative */
505 complain_overflow_bitfield, /* complain_on_overflow */
506 bfd_elf_generic_reloc, /* special_function */
507 "R_PPC_UADDR16", /* name */
508 FALSE, /* partial_inplace */
510 0xffff, /* dst_mask */
511 FALSE), /* pcrel_offset */
513 /* 32-bit PC relative */
514 HOWTO (R_PPC_REL32, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 TRUE, /* pc_relative */
520 complain_overflow_bitfield, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 "R_PPC_REL32", /* name */
523 FALSE, /* partial_inplace */
525 0xffffffff, /* dst_mask */
526 TRUE), /* pcrel_offset */
528 /* 32-bit relocation to the symbol's procedure linkage table.
529 FIXME: not supported. */
530 HOWTO (R_PPC_PLT32, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 FALSE, /* pc_relative */
536 complain_overflow_bitfield, /* complain_on_overflow */
537 bfd_elf_generic_reloc, /* special_function */
538 "R_PPC_PLT32", /* name */
539 FALSE, /* partial_inplace */
542 FALSE), /* pcrel_offset */
544 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
545 FIXME: not supported. */
546 HOWTO (R_PPC_PLTREL32, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 TRUE, /* pc_relative */
552 complain_overflow_bitfield, /* complain_on_overflow */
553 bfd_elf_generic_reloc, /* special_function */
554 "R_PPC_PLTREL32", /* name */
555 FALSE, /* partial_inplace */
558 TRUE), /* pcrel_offset */
560 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
562 HOWTO (R_PPC_PLT16_LO, /* type */
564 1, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE, /* pc_relative */
568 complain_overflow_dont, /* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_PPC_PLT16_LO", /* name */
571 FALSE, /* partial_inplace */
573 0xffff, /* dst_mask */
574 FALSE), /* pcrel_offset */
576 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
578 HOWTO (R_PPC_PLT16_HI, /* type */
580 1, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE, /* pc_relative */
584 complain_overflow_bitfield, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_PPC_PLT16_HI", /* name */
587 FALSE, /* partial_inplace */
589 0xffff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
594 HOWTO (R_PPC_PLT16_HA, /* type */
596 1, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE, /* pc_relative */
600 complain_overflow_bitfield, /* complain_on_overflow */
601 ppc_elf_addr16_ha_reloc, /* special_function */
602 "R_PPC_PLT16_HA", /* name */
603 FALSE, /* partial_inplace */
605 0xffff, /* dst_mask */
606 FALSE), /* pcrel_offset */
608 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
610 HOWTO (R_PPC_SDAREL16, /* type */
612 1, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE, /* pc_relative */
616 complain_overflow_signed, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_PPC_SDAREL16", /* name */
619 FALSE, /* partial_inplace */
621 0xffff, /* dst_mask */
622 FALSE), /* pcrel_offset */
624 /* 16-bit section relative relocation. */
625 HOWTO (R_PPC_SECTOFF, /* type */
627 1, /* size (0 = byte, 1 = short, 2 = long) */
629 FALSE, /* pc_relative */
631 complain_overflow_bitfield, /* complain_on_overflow */
632 bfd_elf_generic_reloc, /* special_function */
633 "R_PPC_SECTOFF", /* name */
634 FALSE, /* partial_inplace */
636 0xffff, /* dst_mask */
637 FALSE), /* pcrel_offset */
639 /* 16-bit lower half section relative relocation. */
640 HOWTO (R_PPC_SECTOFF_LO, /* type */
642 1, /* size (0 = byte, 1 = short, 2 = long) */
644 FALSE, /* pc_relative */
646 complain_overflow_dont, /* complain_on_overflow */
647 bfd_elf_generic_reloc, /* special_function */
648 "R_PPC_SECTOFF_LO", /* name */
649 FALSE, /* partial_inplace */
651 0xffff, /* dst_mask */
652 FALSE), /* pcrel_offset */
654 /* 16-bit upper half section relative relocation. */
655 HOWTO (R_PPC_SECTOFF_HI, /* type */
657 1, /* size (0 = byte, 1 = short, 2 = long) */
659 FALSE, /* pc_relative */
661 complain_overflow_bitfield, /* complain_on_overflow */
662 bfd_elf_generic_reloc, /* special_function */
663 "R_PPC_SECTOFF_HI", /* name */
664 FALSE, /* partial_inplace */
666 0xffff, /* dst_mask */
667 FALSE), /* pcrel_offset */
669 /* 16-bit upper half adjusted section relative relocation. */
670 HOWTO (R_PPC_SECTOFF_HA, /* type */
672 1, /* size (0 = byte, 1 = short, 2 = long) */
674 FALSE, /* pc_relative */
676 complain_overflow_bitfield, /* complain_on_overflow */
677 ppc_elf_addr16_ha_reloc, /* special_function */
678 "R_PPC_SECTOFF_HA", /* name */
679 FALSE, /* partial_inplace */
681 0xffff, /* dst_mask */
682 FALSE), /* pcrel_offset */
684 /* Marker reloc for TLS. */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE, /* pc_relative */
691 complain_overflow_dont, /* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_PPC_TLS", /* name */
694 FALSE, /* partial_inplace */
697 FALSE), /* pcrel_offset */
699 /* Computes the load module index of the load module that contains the
700 definition of its TLS sym. */
701 HOWTO (R_PPC_DTPMOD32,
703 2, /* size (0 = byte, 1 = short, 2 = long) */
705 FALSE, /* pc_relative */
707 complain_overflow_dont, /* complain_on_overflow */
708 ppc_elf_unhandled_reloc, /* special_function */
709 "R_PPC_DTPMOD32", /* name */
710 FALSE, /* partial_inplace */
712 0xffffffff, /* dst_mask */
713 FALSE), /* pcrel_offset */
715 /* Computes a dtv-relative displacement, the difference between the value
716 of sym+add and the base address of the thread-local storage block that
717 contains the definition of sym, minus 0x8000. */
718 HOWTO (R_PPC_DTPREL32,
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 FALSE, /* pc_relative */
724 complain_overflow_dont, /* complain_on_overflow */
725 ppc_elf_unhandled_reloc, /* special_function */
726 "R_PPC_DTPREL32", /* name */
727 FALSE, /* partial_inplace */
729 0xffffffff, /* dst_mask */
730 FALSE), /* pcrel_offset */
732 /* A 16 bit dtprel reloc. */
733 HOWTO (R_PPC_DTPREL16,
735 1, /* size (0 = byte, 1 = short, 2 = long) */
737 FALSE, /* pc_relative */
739 complain_overflow_signed, /* complain_on_overflow */
740 ppc_elf_unhandled_reloc, /* special_function */
741 "R_PPC_DTPREL16", /* name */
742 FALSE, /* partial_inplace */
744 0xffff, /* dst_mask */
745 FALSE), /* pcrel_offset */
747 /* Like DTPREL16, but no overflow. */
748 HOWTO (R_PPC_DTPREL16_LO,
750 1, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE, /* pc_relative */
754 complain_overflow_dont, /* complain_on_overflow */
755 ppc_elf_unhandled_reloc, /* special_function */
756 "R_PPC_DTPREL16_LO", /* name */
757 FALSE, /* partial_inplace */
759 0xffff, /* dst_mask */
760 FALSE), /* pcrel_offset */
762 /* Like DTPREL16_LO, but next higher group of 16 bits. */
763 HOWTO (R_PPC_DTPREL16_HI,
765 1, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE, /* pc_relative */
769 complain_overflow_dont, /* complain_on_overflow */
770 ppc_elf_unhandled_reloc, /* special_function */
771 "R_PPC_DTPREL16_HI", /* name */
772 FALSE, /* partial_inplace */
774 0xffff, /* dst_mask */
775 FALSE), /* pcrel_offset */
777 /* Like DTPREL16_HI, but adjust for low 16 bits. */
778 HOWTO (R_PPC_DTPREL16_HA,
780 1, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE, /* pc_relative */
784 complain_overflow_dont, /* complain_on_overflow */
785 ppc_elf_unhandled_reloc, /* special_function */
786 "R_PPC_DTPREL16_HA", /* name */
787 FALSE, /* partial_inplace */
789 0xffff, /* dst_mask */
790 FALSE), /* pcrel_offset */
792 /* Computes a tp-relative displacement, the difference between the value of
793 sym+add and the value of the thread pointer (r13). */
794 HOWTO (R_PPC_TPREL32,
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE, /* pc_relative */
800 complain_overflow_dont, /* complain_on_overflow */
801 ppc_elf_unhandled_reloc, /* special_function */
802 "R_PPC_TPREL32", /* name */
803 FALSE, /* partial_inplace */
805 0xffffffff, /* dst_mask */
806 FALSE), /* pcrel_offset */
808 /* A 16 bit tprel reloc. */
809 HOWTO (R_PPC_TPREL16,
811 1, /* size (0 = byte, 1 = short, 2 = long) */
813 FALSE, /* pc_relative */
815 complain_overflow_signed, /* complain_on_overflow */
816 ppc_elf_unhandled_reloc, /* special_function */
817 "R_PPC_TPREL16", /* name */
818 FALSE, /* partial_inplace */
820 0xffff, /* dst_mask */
821 FALSE), /* pcrel_offset */
823 /* Like TPREL16, but no overflow. */
824 HOWTO (R_PPC_TPREL16_LO,
826 1, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE, /* pc_relative */
830 complain_overflow_dont, /* complain_on_overflow */
831 ppc_elf_unhandled_reloc, /* special_function */
832 "R_PPC_TPREL16_LO", /* name */
833 FALSE, /* partial_inplace */
835 0xffff, /* dst_mask */
836 FALSE), /* pcrel_offset */
838 /* Like TPREL16_LO, but next higher group of 16 bits. */
839 HOWTO (R_PPC_TPREL16_HI,
841 1, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE, /* pc_relative */
845 complain_overflow_dont, /* complain_on_overflow */
846 ppc_elf_unhandled_reloc, /* special_function */
847 "R_PPC_TPREL16_HI", /* name */
848 FALSE, /* partial_inplace */
850 0xffff, /* dst_mask */
851 FALSE), /* pcrel_offset */
853 /* Like TPREL16_HI, but adjust for low 16 bits. */
854 HOWTO (R_PPC_TPREL16_HA,
856 1, /* size (0 = byte, 1 = short, 2 = long) */
858 FALSE, /* pc_relative */
860 complain_overflow_dont, /* complain_on_overflow */
861 ppc_elf_unhandled_reloc, /* special_function */
862 "R_PPC_TPREL16_HA", /* name */
863 FALSE, /* partial_inplace */
865 0xffff, /* dst_mask */
866 FALSE), /* pcrel_offset */
868 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
869 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
870 to the first entry. */
871 HOWTO (R_PPC_GOT_TLSGD16,
873 1, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_signed, /* complain_on_overflow */
878 ppc_elf_unhandled_reloc, /* special_function */
879 "R_PPC_GOT_TLSGD16", /* name */
880 FALSE, /* partial_inplace */
882 0xffff, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* Like GOT_TLSGD16, but no overflow. */
886 HOWTO (R_PPC_GOT_TLSGD16_LO,
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE, /* pc_relative */
892 complain_overflow_dont, /* complain_on_overflow */
893 ppc_elf_unhandled_reloc, /* special_function */
894 "R_PPC_GOT_TLSGD16_LO", /* name */
895 FALSE, /* partial_inplace */
897 0xffff, /* dst_mask */
898 FALSE), /* pcrel_offset */
900 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
901 HOWTO (R_PPC_GOT_TLSGD16_HI,
903 1, /* size (0 = byte, 1 = short, 2 = long) */
905 FALSE, /* pc_relative */
907 complain_overflow_dont, /* complain_on_overflow */
908 ppc_elf_unhandled_reloc, /* special_function */
909 "R_PPC_GOT_TLSGD16_HI", /* name */
910 FALSE, /* partial_inplace */
912 0xffff, /* dst_mask */
913 FALSE), /* pcrel_offset */
915 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
916 HOWTO (R_PPC_GOT_TLSGD16_HA,
918 1, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE, /* pc_relative */
922 complain_overflow_dont, /* complain_on_overflow */
923 ppc_elf_unhandled_reloc, /* special_function */
924 "R_PPC_GOT_TLSGD16_HA", /* name */
925 FALSE, /* partial_inplace */
927 0xffff, /* dst_mask */
928 FALSE), /* pcrel_offset */
930 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
931 with values (sym+add)@dtpmod and zero, and computes the offset to the
933 HOWTO (R_PPC_GOT_TLSLD16,
935 1, /* size (0 = byte, 1 = short, 2 = long) */
937 FALSE, /* pc_relative */
939 complain_overflow_signed, /* complain_on_overflow */
940 ppc_elf_unhandled_reloc, /* special_function */
941 "R_PPC_GOT_TLSLD16", /* name */
942 FALSE, /* partial_inplace */
944 0xffff, /* dst_mask */
945 FALSE), /* pcrel_offset */
947 /* Like GOT_TLSLD16, but no overflow. */
948 HOWTO (R_PPC_GOT_TLSLD16_LO,
950 1, /* size (0 = byte, 1 = short, 2 = long) */
952 FALSE, /* pc_relative */
954 complain_overflow_dont, /* complain_on_overflow */
955 ppc_elf_unhandled_reloc, /* special_function */
956 "R_PPC_GOT_TLSLD16_LO", /* name */
957 FALSE, /* partial_inplace */
959 0xffff, /* dst_mask */
960 FALSE), /* pcrel_offset */
962 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
963 HOWTO (R_PPC_GOT_TLSLD16_HI,
965 1, /* size (0 = byte, 1 = short, 2 = long) */
967 FALSE, /* pc_relative */
969 complain_overflow_dont, /* complain_on_overflow */
970 ppc_elf_unhandled_reloc, /* special_function */
971 "R_PPC_GOT_TLSLD16_HI", /* name */
972 FALSE, /* partial_inplace */
974 0xffff, /* dst_mask */
975 FALSE), /* pcrel_offset */
977 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
978 HOWTO (R_PPC_GOT_TLSLD16_HA,
980 1, /* size (0 = byte, 1 = short, 2 = long) */
982 FALSE, /* pc_relative */
984 complain_overflow_dont, /* complain_on_overflow */
985 ppc_elf_unhandled_reloc, /* special_function */
986 "R_PPC_GOT_TLSLD16_HA", /* name */
987 FALSE, /* partial_inplace */
989 0xffff, /* dst_mask */
990 FALSE), /* pcrel_offset */
992 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
993 the offset to the entry. */
994 HOWTO (R_PPC_GOT_DTPREL16,
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE, /* pc_relative */
1000 complain_overflow_signed, /* complain_on_overflow */
1001 ppc_elf_unhandled_reloc, /* special_function */
1002 "R_PPC_GOT_DTPREL16", /* name */
1003 FALSE, /* partial_inplace */
1005 0xffff, /* dst_mask */
1006 FALSE), /* pcrel_offset */
1008 /* Like GOT_DTPREL16, but no overflow. */
1009 HOWTO (R_PPC_GOT_DTPREL16_LO,
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE, /* pc_relative */
1015 complain_overflow_dont, /* complain_on_overflow */
1016 ppc_elf_unhandled_reloc, /* special_function */
1017 "R_PPC_GOT_DTPREL16_LO", /* name */
1018 FALSE, /* partial_inplace */
1020 0xffff, /* dst_mask */
1021 FALSE), /* pcrel_offset */
1023 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1024 HOWTO (R_PPC_GOT_DTPREL16_HI,
1025 16, /* rightshift */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE, /* pc_relative */
1030 complain_overflow_dont, /* complain_on_overflow */
1031 ppc_elf_unhandled_reloc, /* special_function */
1032 "R_PPC_GOT_DTPREL16_HI", /* name */
1033 FALSE, /* partial_inplace */
1035 0xffff, /* dst_mask */
1036 FALSE), /* pcrel_offset */
1038 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1039 HOWTO (R_PPC_GOT_DTPREL16_HA,
1040 16, /* rightshift */
1041 1, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE, /* pc_relative */
1045 complain_overflow_dont, /* complain_on_overflow */
1046 ppc_elf_unhandled_reloc, /* special_function */
1047 "R_PPC_GOT_DTPREL16_HA", /* name */
1048 FALSE, /* partial_inplace */
1050 0xffff, /* dst_mask */
1051 FALSE), /* pcrel_offset */
1053 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1054 offset to the entry. */
1055 HOWTO (R_PPC_GOT_TPREL16,
1057 1, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE, /* pc_relative */
1061 complain_overflow_signed, /* complain_on_overflow */
1062 ppc_elf_unhandled_reloc, /* special_function */
1063 "R_PPC_GOT_TPREL16", /* name */
1064 FALSE, /* partial_inplace */
1066 0xffff, /* dst_mask */
1067 FALSE), /* pcrel_offset */
1069 /* Like GOT_TPREL16, but no overflow. */
1070 HOWTO (R_PPC_GOT_TPREL16_LO,
1072 1, /* size (0 = byte, 1 = short, 2 = long) */
1074 FALSE, /* pc_relative */
1076 complain_overflow_dont, /* complain_on_overflow */
1077 ppc_elf_unhandled_reloc, /* special_function */
1078 "R_PPC_GOT_TPREL16_LO", /* name */
1079 FALSE, /* partial_inplace */
1081 0xffff, /* dst_mask */
1082 FALSE), /* pcrel_offset */
1084 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1085 HOWTO (R_PPC_GOT_TPREL16_HI,
1086 16, /* rightshift */
1087 1, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE, /* pc_relative */
1091 complain_overflow_dont, /* complain_on_overflow */
1092 ppc_elf_unhandled_reloc, /* special_function */
1093 "R_PPC_GOT_TPREL16_HI", /* name */
1094 FALSE, /* partial_inplace */
1096 0xffff, /* dst_mask */
1097 FALSE), /* pcrel_offset */
1099 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1100 HOWTO (R_PPC_GOT_TPREL16_HA,
1101 16, /* rightshift */
1102 1, /* size (0 = byte, 1 = short, 2 = long) */
1104 FALSE, /* pc_relative */
1106 complain_overflow_dont, /* complain_on_overflow */
1107 ppc_elf_unhandled_reloc, /* special_function */
1108 "R_PPC_GOT_TPREL16_HA", /* name */
1109 FALSE, /* partial_inplace */
1111 0xffff, /* dst_mask */
1112 FALSE), /* pcrel_offset */
1114 /* The remaining relocs are from the Embedded ELF ABI, and are not
1115 in the SVR4 ELF ABI. */
1117 /* 32 bit value resulting from the addend minus the symbol. */
1118 HOWTO (R_PPC_EMB_NADDR32, /* type */
1120 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE, /* pc_relative */
1124 complain_overflow_bitfield, /* complain_on_overflow */
1125 bfd_elf_generic_reloc, /* special_function */
1126 "R_PPC_EMB_NADDR32", /* name */
1127 FALSE, /* partial_inplace */
1129 0xffffffff, /* dst_mask */
1130 FALSE), /* pcrel_offset */
1132 /* 16 bit value resulting from the addend minus the symbol. */
1133 HOWTO (R_PPC_EMB_NADDR16, /* type */
1135 1, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE, /* pc_relative */
1139 complain_overflow_bitfield, /* complain_on_overflow */
1140 bfd_elf_generic_reloc, /* special_function */
1141 "R_PPC_EMB_NADDR16", /* name */
1142 FALSE, /* partial_inplace */
1144 0xffff, /* dst_mask */
1145 FALSE), /* pcrel_offset */
1147 /* 16 bit value resulting from the addend minus the symbol. */
1148 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE, /* pc_relative */
1154 complain_overflow_dont,/* complain_on_overflow */
1155 bfd_elf_generic_reloc, /* special_function */
1156 "R_PPC_EMB_ADDR16_LO", /* name */
1157 FALSE, /* partial_inplace */
1159 0xffff, /* dst_mask */
1160 FALSE), /* pcrel_offset */
1162 /* The high order 16 bits of the addend minus the symbol. */
1163 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1164 16, /* rightshift */
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE, /* pc_relative */
1169 complain_overflow_dont, /* complain_on_overflow */
1170 bfd_elf_generic_reloc, /* special_function */
1171 "R_PPC_EMB_NADDR16_HI", /* name */
1172 FALSE, /* partial_inplace */
1174 0xffff, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1177 /* The high order 16 bits of the result of the addend minus the address,
1178 plus 1 if the contents of the low 16 bits, treated as a signed number,
1180 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1181 16, /* rightshift */
1182 1, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE, /* pc_relative */
1186 complain_overflow_dont, /* complain_on_overflow */
1187 ppc_elf_addr16_ha_reloc, /* special_function */
1188 "R_PPC_EMB_NADDR16_HA", /* name */
1189 FALSE, /* partial_inplace */
1191 0xffff, /* dst_mask */
1192 FALSE), /* pcrel_offset */
1194 /* 16 bit value resulting from allocating a 4 byte word to hold an
1195 address in the .sdata section, and returning the offset from
1196 _SDA_BASE_ for that relocation. */
1197 HOWTO (R_PPC_EMB_SDAI16, /* type */
1199 1, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE, /* pc_relative */
1203 complain_overflow_bitfield, /* complain_on_overflow */
1204 bfd_elf_generic_reloc, /* special_function */
1205 "R_PPC_EMB_SDAI16", /* name */
1206 FALSE, /* partial_inplace */
1208 0xffff, /* dst_mask */
1209 FALSE), /* pcrel_offset */
1211 /* 16 bit value resulting from allocating a 4 byte word to hold an
1212 address in the .sdata2 section, and returning the offset from
1213 _SDA2_BASE_ for that relocation. */
1214 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1216 1, /* size (0 = byte, 1 = short, 2 = long) */
1218 FALSE, /* pc_relative */
1220 complain_overflow_bitfield, /* complain_on_overflow */
1221 bfd_elf_generic_reloc, /* special_function */
1222 "R_PPC_EMB_SDA2I16", /* name */
1223 FALSE, /* partial_inplace */
1225 0xffff, /* dst_mask */
1226 FALSE), /* pcrel_offset */
1228 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1229 small data items. */
1230 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1232 1, /* size (0 = byte, 1 = short, 2 = long) */
1234 FALSE, /* pc_relative */
1236 complain_overflow_signed, /* complain_on_overflow */
1237 bfd_elf_generic_reloc, /* special_function */
1238 "R_PPC_EMB_SDA2REL", /* name */
1239 FALSE, /* partial_inplace */
1241 0xffff, /* dst_mask */
1242 FALSE), /* pcrel_offset */
1244 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1245 signed offset from the appropriate base, and filling in the register
1246 field with the appropriate register (0, 2, or 13). */
1247 HOWTO (R_PPC_EMB_SDA21, /* type */
1249 2, /* size (0 = byte, 1 = short, 2 = long) */
1251 FALSE, /* pc_relative */
1253 complain_overflow_signed, /* complain_on_overflow */
1254 bfd_elf_generic_reloc, /* special_function */
1255 "R_PPC_EMB_SDA21", /* name */
1256 FALSE, /* partial_inplace */
1258 0xffff, /* dst_mask */
1259 FALSE), /* pcrel_offset */
1261 /* Relocation not handled: R_PPC_EMB_MRKREF */
1262 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1263 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1264 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1265 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1266 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1268 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1269 in the 16 bit signed offset from the appropriate base, and filling in the
1270 register field with the appropriate register (0, 2, or 13). */
1271 HOWTO (R_PPC_EMB_RELSDA, /* type */
1273 1, /* size (0 = byte, 1 = short, 2 = long) */
1275 TRUE, /* pc_relative */
1277 complain_overflow_signed, /* complain_on_overflow */
1278 bfd_elf_generic_reloc, /* special_function */
1279 "R_PPC_EMB_RELSDA", /* name */
1280 FALSE, /* partial_inplace */
1282 0xffff, /* dst_mask */
1283 FALSE), /* pcrel_offset */
1285 /* A 16 bit relative relocation. */
1286 HOWTO (R_PPC_REL16, /* type */
1288 1, /* size (0 = byte, 1 = short, 2 = long) */
1290 TRUE, /* pc_relative */
1292 complain_overflow_bitfield, /* complain_on_overflow */
1293 bfd_elf_generic_reloc, /* special_function */
1294 "R_PPC_REL16", /* name */
1295 FALSE, /* partial_inplace */
1297 0xffff, /* dst_mask */
1298 TRUE), /* pcrel_offset */
1300 /* A 16 bit relative relocation without overflow. */
1301 HOWTO (R_PPC_REL16_LO, /* type */
1303 1, /* size (0 = byte, 1 = short, 2 = long) */
1305 TRUE, /* pc_relative */
1307 complain_overflow_dont,/* complain_on_overflow */
1308 bfd_elf_generic_reloc, /* special_function */
1309 "R_PPC_REL16_LO", /* name */
1310 FALSE, /* partial_inplace */
1312 0xffff, /* dst_mask */
1313 TRUE), /* pcrel_offset */
1315 /* The high order 16 bits of a relative address. */
1316 HOWTO (R_PPC_REL16_HI, /* type */
1317 16, /* rightshift */
1318 1, /* size (0 = byte, 1 = short, 2 = long) */
1320 TRUE, /* pc_relative */
1322 complain_overflow_dont, /* complain_on_overflow */
1323 bfd_elf_generic_reloc, /* special_function */
1324 "R_PPC_REL16_HI", /* name */
1325 FALSE, /* partial_inplace */
1327 0xffff, /* dst_mask */
1328 TRUE), /* pcrel_offset */
1330 /* The high order 16 bits of a relative address, plus 1 if the contents of
1331 the low 16 bits, treated as a signed number, is negative. */
1332 HOWTO (R_PPC_REL16_HA, /* type */
1333 16, /* rightshift */
1334 1, /* size (0 = byte, 1 = short, 2 = long) */
1336 TRUE, /* pc_relative */
1338 complain_overflow_dont, /* complain_on_overflow */
1339 ppc_elf_addr16_ha_reloc, /* special_function */
1340 "R_PPC_REL16_HA", /* name */
1341 FALSE, /* partial_inplace */
1343 0xffff, /* dst_mask */
1344 TRUE), /* pcrel_offset */
1346 /* GNU extension to record C++ vtable hierarchy. */
1347 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1349 0, /* size (0 = byte, 1 = short, 2 = long) */
1351 FALSE, /* pc_relative */
1353 complain_overflow_dont, /* complain_on_overflow */
1354 NULL, /* special_function */
1355 "R_PPC_GNU_VTINHERIT", /* name */
1356 FALSE, /* partial_inplace */
1359 FALSE), /* pcrel_offset */
1361 /* GNU extension to record C++ vtable member usage. */
1362 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1364 0, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE, /* pc_relative */
1368 complain_overflow_dont, /* complain_on_overflow */
1369 NULL, /* special_function */
1370 "R_PPC_GNU_VTENTRY", /* name */
1371 FALSE, /* partial_inplace */
1374 FALSE), /* pcrel_offset */
1376 /* Phony reloc to handle AIX style TOC entries. */
1377 HOWTO (R_PPC_TOC16, /* type */
1379 1, /* size (0 = byte, 1 = short, 2 = long) */
1381 FALSE, /* pc_relative */
1383 complain_overflow_signed, /* complain_on_overflow */
1384 bfd_elf_generic_reloc, /* special_function */
1385 "R_PPC_TOC16", /* name */
1386 FALSE, /* partial_inplace */
1388 0xffff, /* dst_mask */
1389 FALSE), /* pcrel_offset */
1392 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1395 ppc_elf_howto_init (void)
1397 unsigned int i, type;
1400 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1403 type = ppc_elf_howto_raw[i].type;
1404 if (type >= (sizeof (ppc_elf_howto_table)
1405 / sizeof (ppc_elf_howto_table[0])))
1407 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1411 static reloc_howto_type *
1412 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1413 bfd_reloc_code_real_type code)
1415 enum elf_ppc_reloc_type r;
1417 /* Initialize howto table if not already done. */
1418 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1419 ppc_elf_howto_init ();
1426 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1427 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1428 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1429 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1430 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1431 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1432 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1433 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1434 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1435 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1436 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1437 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1438 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1439 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1440 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1441 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1442 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1443 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1444 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1445 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1446 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1447 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1448 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1449 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1450 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1451 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1452 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1453 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1454 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1455 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1456 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1457 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1458 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1459 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1460 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1461 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1462 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1463 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1464 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1465 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1466 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1467 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1468 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1469 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1470 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1471 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1472 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1473 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1474 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1475 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1476 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1477 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1478 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1479 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1480 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1481 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1482 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1483 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1484 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1485 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1486 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1487 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1488 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1489 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1490 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1491 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1492 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1493 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1494 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1495 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1496 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1497 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1498 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1499 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1500 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1501 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1502 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1503 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1504 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1505 case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
1506 case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
1507 case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
1508 case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
1509 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1510 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1513 return ppc_elf_howto_table[r];
1516 /* Set the howto pointer for a PowerPC ELF reloc. */
1519 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1521 Elf_Internal_Rela *dst)
1523 /* Initialize howto table if not already done. */
1524 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1525 ppc_elf_howto_init ();
1527 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1528 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1531 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1533 static bfd_reloc_status_type
1534 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1535 arelent *reloc_entry,
1537 void *data ATTRIBUTE_UNUSED,
1538 asection *input_section,
1540 char **error_message ATTRIBUTE_UNUSED)
1544 if (output_bfd != NULL)
1546 reloc_entry->address += input_section->output_offset;
1547 return bfd_reloc_ok;
1550 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1551 return bfd_reloc_outofrange;
1553 if (bfd_is_com_section (symbol->section))
1556 relocation = symbol->value;
1558 relocation += symbol->section->output_section->vma;
1559 relocation += symbol->section->output_offset;
1560 relocation += reloc_entry->addend;
1561 if (reloc_entry->howto->pc_relative)
1562 relocation -= reloc_entry->address;
1564 reloc_entry->addend += (relocation & 0x8000) << 1;
1566 return bfd_reloc_continue;
1569 static bfd_reloc_status_type
1570 ppc_elf_unhandled_reloc (bfd *abfd,
1571 arelent *reloc_entry,
1574 asection *input_section,
1576 char **error_message)
1578 /* If this is a relocatable link (output_bfd test tells us), just
1579 call the generic function. Any adjustment will be done at final
1581 if (output_bfd != NULL)
1582 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1583 input_section, output_bfd, error_message);
1585 if (error_message != NULL)
1587 static char buf[60];
1588 sprintf (buf, _("generic linker can't handle %s"),
1589 reloc_entry->howto->name);
1590 *error_message = buf;
1592 return bfd_reloc_dangerous;
1595 /* Sections created by the linker. */
1597 typedef struct elf_linker_section
1599 /* Pointer to the bfd section. */
1603 /* Associated bss section name. */
1604 const char *bss_name;
1605 /* Associated symbol name. */
1606 const char *sym_name;
1607 /* Value of symbol. */
1609 } elf_linker_section_t;
1611 /* Linked list of allocated pointer entries. This hangs off of the
1612 symbol lists, and provides allows us to return different pointers,
1613 based on different addend's. */
1615 typedef struct elf_linker_section_pointers
1617 /* next allocated pointer for this symbol */
1618 struct elf_linker_section_pointers *next;
1619 /* offset of pointer from beginning of section */
1623 /* which linker section this is */
1624 elf_linker_section_t *lsect;
1625 } elf_linker_section_pointers_t;
1627 struct ppc_elf_obj_tdata
1629 struct elf_obj_tdata elf;
1631 /* A mapping from local symbols to offsets into the various linker
1632 sections added. This is index by the symbol index. */
1633 elf_linker_section_pointers_t **linker_section_pointers;
1636 #define ppc_elf_tdata(bfd) \
1637 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1639 #define elf_local_ptr_offsets(bfd) \
1640 (ppc_elf_tdata (bfd)->linker_section_pointers)
1642 /* Override the generic function because we store some extras. */
1645 ppc_elf_mkobject (bfd *abfd)
1647 bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
1648 abfd->tdata.any = bfd_zalloc (abfd, amt);
1649 if (abfd->tdata.any == NULL)
1654 /* Fix bad default arch selected for a 32 bit input bfd when the
1655 default is 64 bit. */
1658 ppc_elf_object_p (bfd *abfd)
1660 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
1662 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
1664 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
1666 /* Relies on arch after 64 bit default being 32 bit default. */
1667 abfd->arch_info = abfd->arch_info->next;
1668 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
1674 /* Function to set whether a module needs the -mrelocatable bit set. */
1677 ppc_elf_set_private_flags (bfd *abfd, flagword flags)
1679 BFD_ASSERT (!elf_flags_init (abfd)
1680 || elf_elfheader (abfd)->e_flags == flags);
1682 elf_elfheader (abfd)->e_flags = flags;
1683 elf_flags_init (abfd) = TRUE;
1687 /* Support for core dump NOTE sections. */
1690 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1695 switch (note->descsz)
1700 case 268: /* Linux/PPC. */
1702 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1705 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1714 /* Make a ".reg/999" section. */
1715 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1716 size, note->descpos + offset);
1720 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1722 switch (note->descsz)
1727 case 128: /* Linux/PPC elf_prpsinfo. */
1728 elf_tdata (abfd)->core_program
1729 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1730 elf_tdata (abfd)->core_command
1731 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1734 /* Note that for some reason, a spurious space is tacked
1735 onto the end of the args in some (at least one anyway)
1736 implementations, so strip it off if it exists. */
1739 char *command = elf_tdata (abfd)->core_command;
1740 int n = strlen (command);
1742 if (0 < n && command[n - 1] == ' ')
1743 command[n - 1] = '\0';
1749 /* Return address for Ith PLT stub in section PLT, for relocation REL
1750 or (bfd_vma) -1 if it should not be included. */
1753 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
1754 const asection *plt ATTRIBUTE_UNUSED,
1757 return rel->address;
1760 /* Handle a PowerPC specific section when reading an object file. This
1761 is called when bfd_section_from_shdr finds a section with an unknown
1765 ppc_elf_section_from_shdr (bfd *abfd,
1766 Elf_Internal_Shdr *hdr,
1773 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
1776 newsect = hdr->bfd_section;
1777 flags = bfd_get_section_flags (abfd, newsect);
1778 if (hdr->sh_flags & SHF_EXCLUDE)
1779 flags |= SEC_EXCLUDE;
1781 if (hdr->sh_type == SHT_ORDERED)
1782 flags |= SEC_SORT_ENTRIES;
1784 bfd_set_section_flags (abfd, newsect, flags);
1788 /* Set up any other section flags and such that may be necessary. */
1791 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1792 Elf_Internal_Shdr *shdr,
1795 if ((asect->flags & SEC_EXCLUDE) != 0)
1796 shdr->sh_flags |= SHF_EXCLUDE;
1798 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1799 shdr->sh_type = SHT_ORDERED;
1804 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1805 need to bump up the number of section headers. */
1808 ppc_elf_additional_program_headers (bfd *abfd)
1813 s = bfd_get_section_by_name (abfd, ".sbss2");
1814 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1817 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1818 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
1824 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1825 .PPC.EMB.sbss0 a normal section, and not a bss section so
1826 that the linker doesn't crater when trying to make more than
1829 static struct bfd_elf_special_section const
1830 ppc_special_sections_p[] =
1832 { ".plt", 4, 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
1833 { NULL, 0, 0, 0, 0 }
1836 static struct bfd_elf_special_section const
1837 ppc_special_sections_s[] =
1839 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
1840 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
1841 { ".sdata2", 7, -2, SHT_PROGBITS, SHF_ALLOC },
1842 { ".sbss2", 6, -2, SHT_PROGBITS, SHF_ALLOC },
1843 { NULL, 0, 0, 0, 0 }
1846 static struct bfd_elf_special_section const
1847 ppc_special_sections_t[] =
1849 { ".tags", 5, 0, SHT_ORDERED, SHF_ALLOC },
1850 { NULL, 0, 0, 0, 0 }
1853 static struct bfd_elf_special_section const
1854 ppc_special_sections_other[]=
1856 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE, 0 },
1857 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS, SHF_ALLOC },
1858 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS, SHF_ALLOC },
1859 { NULL, 0, 0, 0, 0 }
1862 static struct bfd_elf_special_section const *
1863 ppc_elf_special_sections[27]=
1880 ppc_special_sections_p, /* 'p' */
1883 ppc_special_sections_s, /* 's' */
1884 ppc_special_sections_t, /* 's' */
1891 ppc_special_sections_other, /* other */
1894 /* Very simple linked list structure for recording apuinfo values. */
1895 typedef struct apuinfo_list
1897 struct apuinfo_list *next;
1898 unsigned long value;
1902 static apuinfo_list *head;
1906 apuinfo_list_init (void)
1912 apuinfo_list_add (unsigned long value)
1914 apuinfo_list *entry = head;
1916 while (entry != NULL)
1918 if (entry->value == value)
1920 entry = entry->next;
1923 entry = bfd_malloc (sizeof (* entry));
1927 entry->value = value;
1933 apuinfo_list_length (void)
1935 apuinfo_list *entry;
1936 unsigned long count;
1938 for (entry = head, count = 0;
1940 entry = entry->next)
1946 static inline unsigned long
1947 apuinfo_list_element (unsigned long number)
1949 apuinfo_list * entry;
1953 entry = entry->next)
1956 return entry ? entry->value : 0;
1960 apuinfo_list_finish (void)
1962 apuinfo_list *entry;
1964 for (entry = head; entry;)
1966 apuinfo_list *next = entry->next;
1974 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
1975 #define APUINFO_LABEL "APUinfo"
1977 /* Scan the input BFDs and create a linked list of
1978 the APUinfo values that will need to be emitted. */
1981 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
1986 unsigned num_input_sections;
1987 bfd_size_type output_section_size;
1989 unsigned num_entries;
1990 unsigned long offset;
1991 unsigned long length;
1992 const char *error_message = NULL;
1994 if (link_info == NULL)
1997 /* Scan the input bfds, looking for apuinfo sections. */
1998 num_input_sections = 0;
1999 output_section_size = 0;
2001 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2003 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2006 ++ num_input_sections;
2007 output_section_size += asec->size;
2011 /* We need at least one input sections
2012 in order to make merging worthwhile. */
2013 if (num_input_sections < 1)
2016 /* Just make sure that the output section exists as well. */
2017 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2021 /* Allocate a buffer for the contents of the input sections. */
2022 buffer = bfd_malloc (output_section_size);
2027 apuinfo_list_init ();
2029 /* Read in the input sections contents. */
2030 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
2032 unsigned long datum;
2035 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2039 length = asec->size;
2042 error_message = _("corrupt or empty %s section in %B");
2046 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
2047 || (bfd_bread (buffer + offset, length, ibfd) != length))
2049 error_message = _("unable to read in %s section from %B");
2053 /* Process the contents of the section. */
2054 ptr = buffer + offset;
2055 error_message = _("corrupt %s section in %B");
2057 /* Verify the contents of the header. Note - we have to
2058 extract the values this way in order to allow for a
2059 host whose endian-ness is different from the target. */
2060 datum = bfd_get_32 (ibfd, ptr);
2061 if (datum != sizeof APUINFO_LABEL)
2064 datum = bfd_get_32 (ibfd, ptr + 8);
2068 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
2071 /* Get the number of bytes used for apuinfo entries. */
2072 datum = bfd_get_32 (ibfd, ptr + 4);
2073 if (datum + 20 != length)
2076 /* Make sure that we do not run off the end of the section. */
2077 if (offset + length > output_section_size)
2080 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2081 for (i = 0; i < datum; i += 4)
2082 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i));
2084 /* Update the offset. */
2088 error_message = NULL;
2090 /* Compute the size of the output section. */
2091 num_entries = apuinfo_list_length ();
2092 output_section_size = 20 + num_entries * 4;
2094 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2096 if (! bfd_set_section_size (abfd, asec, output_section_size))
2098 error_message = _("warning: unable to set size of %s section in %B");
2104 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2107 /* Prevent the output section from accumulating the input sections'
2108 contents. We have already stored this in our linked list structure. */
2111 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
2113 bfd_byte *contents ATTRIBUTE_UNUSED)
2115 return (apuinfo_list_length ()
2116 && strcmp (asec->name, APUINFO_SECTION_NAME) == 0);
2119 /* Finally we can generate the output section. */
2122 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
2127 unsigned num_entries;
2128 bfd_size_type length;
2130 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2134 if (apuinfo_list_length () == 0)
2137 length = asec->size;
2141 buffer = bfd_malloc (length);
2144 (*_bfd_error_handler)
2145 (_("failed to allocate space for new APUinfo section."));
2149 /* Create the apuinfo header. */
2150 num_entries = apuinfo_list_length ();
2151 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2152 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2153 bfd_put_32 (abfd, 0x2, buffer + 8);
2154 strcpy ((char *) buffer + 12, APUINFO_LABEL);
2157 for (i = 0; i < num_entries; i++)
2159 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2163 if (length != asec->size)
2164 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
2166 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2167 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
2171 apuinfo_list_finish ();
2174 /* The following functions are specific to the ELF linker, while
2175 functions above are used generally. They appear in this file more
2176 or less in the order in which they are called. eg.
2177 ppc_elf_check_relocs is called early in the link process,
2178 ppc_elf_finish_dynamic_sections is one of the last functions
2181 /* The PPC linker needs to keep track of the number of relocs that it
2182 decides to copy as dynamic relocs in check_relocs for each symbol.
2183 This is so that it can later discard them if they are found to be
2184 unnecessary. We store the information in a field extending the
2185 regular ELF linker hash table. */
2187 struct ppc_elf_dyn_relocs
2189 struct ppc_elf_dyn_relocs *next;
2191 /* The input section of the reloc. */
2194 /* Total number of relocs copied for the input section. */
2195 bfd_size_type count;
2197 /* Number of pc-relative relocs copied for the input section. */
2198 bfd_size_type pc_count;
2201 /* Of those relocs that might be copied as dynamic relocs, this macro
2202 selects those that must be copied when linking a shared library,
2203 even when the symbol is local. */
2205 #define MUST_BE_DYN_RELOC(RTYPE) \
2206 ((RTYPE) != R_PPC_REL24 \
2207 && (RTYPE) != R_PPC_REL14 \
2208 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2209 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2210 && (RTYPE) != R_PPC_REL32)
2212 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2213 copying dynamic variables from a shared lib into an app's dynbss
2214 section, and instead use a dynamic relocation to point into the
2216 #define ELIMINATE_COPY_RELOCS 1
2218 /* PPC ELF linker hash entry. */
2220 struct ppc_elf_link_hash_entry
2222 struct elf_link_hash_entry elf;
2224 /* If this symbol is used in the linker created sections, the processor
2225 specific backend uses this field to map the field into the offset
2226 from the beginning of the section. */
2227 elf_linker_section_pointers_t *linker_section_pointer;
2229 /* Track dynamic relocs copied for this symbol. */
2230 struct ppc_elf_dyn_relocs *dyn_relocs;
2232 /* Contexts in which symbol is used in the GOT (or TOC).
2233 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2234 corresponding relocs are encountered during check_relocs.
2235 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2236 indicate the corresponding GOT entry type is not needed. */
2237 #define TLS_GD 1 /* GD reloc. */
2238 #define TLS_LD 2 /* LD reloc. */
2239 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2240 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2241 #define TLS_TLS 16 /* Any TLS reloc. */
2242 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2246 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2248 /* PPC ELF linker hash table. */
2250 struct ppc_elf_link_hash_table
2252 struct elf_link_hash_table elf;
2254 /* Short-cuts to get to dynamic linker sections. */
2264 elf_linker_section_t sdata[2];
2267 /* Shortcut to .__tls_get_addr. */
2268 struct elf_link_hash_entry *tls_get_addr;
2270 /* TLS local dynamic got entry handling. */
2272 bfd_signed_vma refcount;
2276 /* Offset of PltResolve function in glink. */
2277 bfd_vma glink_pltresolve;
2279 /* Size of reserved GOT entries. */
2280 unsigned int got_header_size;
2281 /* Non-zero if allocating the header left a gap. */
2282 unsigned int got_gap;
2284 /* Whether to use new plt/got layout or not. */
2285 unsigned int new_plt:1;
2286 unsigned int old_plt:1;
2288 /* Small local sym to section mapping cache. */
2289 struct sym_sec_cache sym_sec;
2292 /* Get the PPC ELF linker hash table from a link_info structure. */
2294 #define ppc_elf_hash_table(p) \
2295 ((struct ppc_elf_link_hash_table *) (p)->hash)
2297 /* Create an entry in a PPC ELF linker hash table. */
2299 static struct bfd_hash_entry *
2300 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2301 struct bfd_hash_table *table,
2304 /* Allocate the structure if it has not already been allocated by a
2308 entry = bfd_hash_allocate (table,
2309 sizeof (struct ppc_elf_link_hash_entry));
2314 /* Call the allocation method of the superclass. */
2315 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2318 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
2319 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
2320 ppc_elf_hash_entry (entry)->tls_mask = 0;
2326 /* Create a PPC ELF linker hash table. */
2328 static struct bfd_link_hash_table *
2329 ppc_elf_link_hash_table_create (bfd *abfd)
2331 struct ppc_elf_link_hash_table *ret;
2333 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
2337 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
2338 ppc_elf_link_hash_newfunc))
2344 ret->sdata[0].name = ".sdata";
2345 ret->sdata[0].sym_name = "_SDA_BASE_";
2346 ret->sdata[0].bss_name = ".sbss";
2348 ret->sdata[1].name = ".sdata2";
2349 ret->sdata[1].sym_name = "_SDA2_BASE_";
2350 ret->sdata[1].bss_name = ".sbss2";
2352 return &ret->elf.root;
2355 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2358 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2360 struct ppc_elf_link_hash_table *htab;
2364 if (!_bfd_elf_create_got_section (abfd, info))
2367 htab = ppc_elf_hash_table (info);
2368 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2372 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2373 | SEC_LINKER_CREATED);
2374 if (!bfd_set_section_flags (abfd, s, flags))
2377 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2378 | SEC_LINKER_CREATED | SEC_READONLY);
2379 htab->relgot = bfd_make_section_with_flags (abfd, ".rela.got", flags);
2381 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2387 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2388 to output sections (just like _bfd_elf_create_dynamic_sections has
2389 to create .dynbss and .rela.bss). */
2392 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2394 struct ppc_elf_link_hash_table *htab;
2398 htab = ppc_elf_hash_table (info);
2400 if (htab->got == NULL
2401 && !ppc_elf_create_got (abfd, info))
2404 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2407 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
2408 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2410 s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags | SEC_CODE);
2413 || !bfd_set_section_alignment (abfd, s, 4))
2416 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2417 s = bfd_make_section_with_flags (abfd, ".dynsbss",
2418 SEC_ALLOC | SEC_LINKER_CREATED);
2425 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2426 s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags);
2429 || ! bfd_set_section_alignment (abfd, s, 2))
2433 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2434 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2438 flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
2439 return bfd_set_section_flags (abfd, s, flags);
2442 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2445 ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
2446 struct elf_link_hash_entry *dir,
2447 struct elf_link_hash_entry *ind)
2449 struct ppc_elf_link_hash_entry *edir, *eind;
2451 edir = (struct ppc_elf_link_hash_entry *) dir;
2452 eind = (struct ppc_elf_link_hash_entry *) ind;
2454 if (eind->dyn_relocs != NULL)
2456 if (edir->dyn_relocs != NULL)
2458 struct ppc_elf_dyn_relocs **pp;
2459 struct ppc_elf_dyn_relocs *p;
2461 if (ind->root.type == bfd_link_hash_indirect)
2464 /* Add reloc counts against the weak sym to the strong sym
2465 list. Merge any entries against the same section. */
2466 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2468 struct ppc_elf_dyn_relocs *q;
2470 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2471 if (q->sec == p->sec)
2473 q->pc_count += p->pc_count;
2474 q->count += p->count;
2481 *pp = edir->dyn_relocs;
2484 edir->dyn_relocs = eind->dyn_relocs;
2485 eind->dyn_relocs = NULL;
2488 edir->tls_mask |= eind->tls_mask;
2490 if (ELIMINATE_COPY_RELOCS
2491 && ind->root.type != bfd_link_hash_indirect
2492 && dir->dynamic_adjusted)
2494 /* If called to transfer flags for a weakdef during processing
2495 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2496 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2497 dir->ref_dynamic |= ind->ref_dynamic;
2498 dir->ref_regular |= ind->ref_regular;
2499 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
2500 dir->needs_plt |= ind->needs_plt;
2503 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
2506 /* Return 1 if target is one of ours. */
2509 is_ppc_elf_target (const struct bfd_target *targ)
2511 extern const bfd_target bfd_elf32_powerpc_vec;
2512 extern const bfd_target bfd_elf32_powerpcle_vec;
2514 return targ == &bfd_elf32_powerpc_vec || targ == &bfd_elf32_powerpcle_vec;
2517 /* Hook called by the linker routine which adds symbols from an object
2518 file. We use it to put .comm items in .sbss, and not .bss. */
2521 ppc_elf_add_symbol_hook (bfd *abfd,
2522 struct bfd_link_info *info,
2523 Elf_Internal_Sym *sym,
2524 const char **namep ATTRIBUTE_UNUSED,
2525 flagword *flagsp ATTRIBUTE_UNUSED,
2529 if (sym->st_shndx == SHN_COMMON
2530 && !info->relocatable
2531 && sym->st_size <= elf_gp_size (abfd)
2532 && is_ppc_elf_target (info->hash->creator))
2534 /* Common symbols less than or equal to -G nn bytes are automatically
2536 struct ppc_elf_link_hash_table *htab;
2538 htab = ppc_elf_hash_table (info);
2539 if (htab->sbss == NULL)
2541 flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
2543 if (!htab->elf.dynobj)
2544 htab->elf.dynobj = abfd;
2546 htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2549 if (htab->sbss == NULL)
2554 *valp = sym->st_size;
2560 /* Create a special linker section. */
2563 ppc_elf_create_linker_section (bfd *abfd,
2564 struct bfd_link_info *info,
2566 elf_linker_section_t *lsect)
2568 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2571 flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2572 | SEC_LINKER_CREATED);
2574 /* Record the first bfd that needs the special sections. */
2575 if (!htab->elf.dynobj)
2576 htab->elf.dynobj = abfd;
2578 s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
2582 || !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
2589 /* Find a linker generated pointer with a given addend and type. */
2591 static elf_linker_section_pointers_t *
2592 elf_find_pointer_linker_section
2593 (elf_linker_section_pointers_t *linker_pointers,
2595 elf_linker_section_t *lsect)
2597 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
2598 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
2599 return linker_pointers;
2604 /* Allocate a pointer to live in a linker created section. */
2607 elf_create_pointer_linker_section (bfd *abfd,
2608 elf_linker_section_t *lsect,
2609 struct elf_link_hash_entry *h,
2610 const Elf_Internal_Rela *rel)
2612 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
2613 elf_linker_section_pointers_t *linker_section_ptr;
2614 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
2617 BFD_ASSERT (lsect != NULL);
2619 /* Is this a global symbol? */
2622 struct ppc_elf_link_hash_entry *eh;
2624 /* Has this symbol already been allocated? If so, our work is done. */
2625 eh = (struct ppc_elf_link_hash_entry *) h;
2626 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
2631 ptr_linker_section_ptr = &eh->linker_section_pointer;
2635 /* Allocation of a pointer to a local symbol. */
2636 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
2638 /* Allocate a table to hold the local symbols if first time. */
2641 unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info;
2644 amt *= sizeof (elf_linker_section_pointers_t *);
2645 ptr = bfd_zalloc (abfd, amt);
2650 elf_local_ptr_offsets (abfd) = ptr;
2653 /* Has this symbol already been allocated? If so, our work is done. */
2654 if (elf_find_pointer_linker_section (ptr[r_symndx],
2659 ptr_linker_section_ptr = &ptr[r_symndx];
2662 /* Allocate space for a pointer in the linker section, and allocate
2663 a new pointer record from internal memory. */
2664 BFD_ASSERT (ptr_linker_section_ptr != NULL);
2665 amt = sizeof (elf_linker_section_pointers_t);
2666 linker_section_ptr = bfd_alloc (abfd, amt);
2668 if (!linker_section_ptr)
2671 linker_section_ptr->next = *ptr_linker_section_ptr;
2672 linker_section_ptr->addend = rel->r_addend;
2673 linker_section_ptr->lsect = lsect;
2674 *ptr_linker_section_ptr = linker_section_ptr;
2676 linker_section_ptr->offset = lsect->section->size;
2677 lsect->section->size += 4;
2681 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2682 lsect->name, (long) linker_section_ptr->offset,
2683 (long) lsect->section->size);
2690 update_local_sym_info (bfd *abfd,
2691 Elf_Internal_Shdr *symtab_hdr,
2692 unsigned long r_symndx,
2695 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
2696 char *local_got_tls_masks;
2698 if (local_got_refcounts == NULL)
2700 bfd_size_type size = symtab_hdr->sh_info;
2702 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
2703 local_got_refcounts = bfd_zalloc (abfd, size);
2704 if (local_got_refcounts == NULL)
2706 elf_local_got_refcounts (abfd) = local_got_refcounts;
2709 local_got_refcounts[r_symndx] += 1;
2710 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
2711 local_got_tls_masks[r_symndx] |= tls_type;
2716 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
2718 (*_bfd_error_handler)
2719 (_("%B: relocation %s cannot be used when making a shared object"),
2721 ppc_elf_howto_table[r_type]->name);
2722 bfd_set_error (bfd_error_bad_value);
2725 /* Look through the relocs for a section during the first phase, and
2726 allocate space in the global offset table or procedure linkage
2730 ppc_elf_check_relocs (bfd *abfd,
2731 struct bfd_link_info *info,
2733 const Elf_Internal_Rela *relocs)
2735 struct ppc_elf_link_hash_table *htab;
2736 Elf_Internal_Shdr *symtab_hdr;
2737 struct elf_link_hash_entry **sym_hashes;
2738 const Elf_Internal_Rela *rel;
2739 const Elf_Internal_Rela *rel_end;
2742 if (info->relocatable)
2745 /* Don't do anything special with non-loaded, non-alloced sections.
2746 In particular, any relocs in such sections should not affect GOT
2747 and PLT reference counting (ie. we don't allow them to create GOT
2748 or PLT entries), there's no possibility or desire to optimize TLS
2749 relocs, and there's not much point in propagating relocs to shared
2750 libs that the dynamic linker won't relocate. */
2751 if ((sec->flags & SEC_ALLOC) == 0)
2755 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
2759 /* Initialize howto table if not already done. */
2760 if (!ppc_elf_howto_table[R_PPC_ADDR32])
2761 ppc_elf_howto_init ();
2763 htab = ppc_elf_hash_table (info);
2764 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2765 sym_hashes = elf_sym_hashes (abfd);
2768 rel_end = relocs + sec->reloc_count;
2769 for (rel = relocs; rel < rel_end; rel++)
2771 unsigned long r_symndx;
2772 enum elf_ppc_reloc_type r_type;
2773 struct elf_link_hash_entry *h;
2776 r_symndx = ELF32_R_SYM (rel->r_info);
2777 if (r_symndx < symtab_hdr->sh_info)
2780 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2782 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2783 This shows up in particular in an R_PPC_ADDR32 in the eabi
2786 && htab->got == NULL
2787 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2789 if (htab->elf.dynobj == NULL)
2790 htab->elf.dynobj = abfd;
2791 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2793 BFD_ASSERT (h == htab->elf.hgot);
2796 r_type = ELF32_R_TYPE (rel->r_info);
2799 case R_PPC_GOT_TLSLD16:
2800 case R_PPC_GOT_TLSLD16_LO:
2801 case R_PPC_GOT_TLSLD16_HI:
2802 case R_PPC_GOT_TLSLD16_HA:
2803 htab->tlsld_got.refcount += 1;
2804 tls_type = TLS_TLS | TLS_LD;
2807 case R_PPC_GOT_TLSGD16:
2808 case R_PPC_GOT_TLSGD16_LO:
2809 case R_PPC_GOT_TLSGD16_HI:
2810 case R_PPC_GOT_TLSGD16_HA:
2811 tls_type = TLS_TLS | TLS_GD;
2814 case R_PPC_GOT_TPREL16:
2815 case R_PPC_GOT_TPREL16_LO:
2816 case R_PPC_GOT_TPREL16_HI:
2817 case R_PPC_GOT_TPREL16_HA:
2819 info->flags |= DF_STATIC_TLS;
2820 tls_type = TLS_TLS | TLS_TPREL;
2823 case R_PPC_GOT_DTPREL16:
2824 case R_PPC_GOT_DTPREL16_LO:
2825 case R_PPC_GOT_DTPREL16_HI:
2826 case R_PPC_GOT_DTPREL16_HA:
2827 tls_type = TLS_TLS | TLS_DTPREL;
2829 sec->has_tls_reloc = 1;
2832 /* GOT16 relocations */
2834 case R_PPC_GOT16_LO:
2835 case R_PPC_GOT16_HI:
2836 case R_PPC_GOT16_HA:
2837 /* This symbol requires a global offset table entry. */
2838 if (htab->got == NULL)
2840 if (htab->elf.dynobj == NULL)
2841 htab->elf.dynobj = abfd;
2842 if (!ppc_elf_create_got (htab->elf.dynobj, info))
2847 h->got.refcount += 1;
2848 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
2851 /* This is a global offset table entry for a local symbol. */
2852 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
2856 /* Indirect .sdata relocation. */
2857 case R_PPC_EMB_SDAI16:
2860 bad_shared_reloc (abfd, r_type);
2863 if (htab->sdata[0].section == NULL
2864 && !ppc_elf_create_linker_section (abfd, info, 0,
2867 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
2872 /* Indirect .sdata2 relocation. */
2873 case R_PPC_EMB_SDA2I16:
2876 bad_shared_reloc (abfd, r_type);
2879 if (htab->sdata[1].section == NULL
2880 && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
2883 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
2888 case R_PPC_SDAREL16:
2889 case R_PPC_EMB_SDA2REL:
2890 case R_PPC_EMB_SDA21:
2891 case R_PPC_EMB_RELSDA:
2892 case R_PPC_EMB_NADDR32:
2893 case R_PPC_EMB_NADDR16:
2894 case R_PPC_EMB_NADDR16_LO:
2895 case R_PPC_EMB_NADDR16_HI:
2896 case R_PPC_EMB_NADDR16_HA:
2899 bad_shared_reloc (abfd, r_type);
2905 case R_PPC_PLTREL24:
2906 case R_PPC_PLTREL32:
2907 case R_PPC_PLT16_LO:
2908 case R_PPC_PLT16_HI:
2909 case R_PPC_PLT16_HA:
2911 fprintf (stderr, "Reloc requires a PLT entry\n");
2913 /* This symbol requires a procedure linkage table entry. We
2914 actually build the entry in finish_dynamic_symbol,
2915 because this might be a case of linking PIC code without
2916 linking in any dynamic objects, in which case we don't
2917 need to generate a procedure linkage table after all. */
2921 /* It does not make sense to have a procedure linkage
2922 table entry for a local symbol. */
2923 (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
2927 (long) rel->r_offset,
2928 ppc_elf_howto_table[r_type]->name);
2929 bfd_set_error (bfd_error_bad_value);
2937 /* The following relocations don't need to propagate the
2938 relocation if linking a shared object since they are
2939 section relative. */
2941 case R_PPC_SECTOFF_LO:
2942 case R_PPC_SECTOFF_HI:
2943 case R_PPC_SECTOFF_HA:
2944 case R_PPC_DTPREL16:
2945 case R_PPC_DTPREL16_LO:
2946 case R_PPC_DTPREL16_HI:
2947 case R_PPC_DTPREL16_HA:
2952 case R_PPC_REL16_LO:
2953 case R_PPC_REL16_HI:
2954 case R_PPC_REL16_HA:
2958 /* This are just markers. */
2960 case R_PPC_EMB_MRKREF:
2965 /* These should only appear in dynamic objects. */
2967 case R_PPC_GLOB_DAT:
2968 case R_PPC_JMP_SLOT:
2969 case R_PPC_RELATIVE:
2972 /* These aren't handled yet. We'll report an error later. */
2974 case R_PPC_EMB_RELSEC16:
2975 case R_PPC_EMB_RELST_LO:
2976 case R_PPC_EMB_RELST_HI:
2977 case R_PPC_EMB_RELST_HA:
2978 case R_PPC_EMB_BIT_FLD:
2981 /* This refers only to functions defined in the shared library. */
2982 case R_PPC_LOCAL24PC:
2983 if (h && h == htab->elf.hgot)
2987 /* This relocation describes the C++ object vtable hierarchy.
2988 Reconstruct it for later use during GC. */
2989 case R_PPC_GNU_VTINHERIT:
2990 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2994 /* This relocation describes which C++ vtable entries are actually
2995 used. Record for later use during GC. */
2996 case R_PPC_GNU_VTENTRY:
2997 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3001 /* We shouldn't really be seeing these. */
3004 info->flags |= DF_STATIC_TLS;
3008 case R_PPC_DTPMOD32:
3009 case R_PPC_DTPREL32:
3013 case R_PPC_TPREL16_LO:
3014 case R_PPC_TPREL16_HI:
3015 case R_PPC_TPREL16_HA:
3017 info->flags |= DF_STATIC_TLS;
3020 /* When creating a shared object, we must copy these
3021 relocs into the output file. We create a reloc
3022 section in dynobj and make room for the reloc. */
3025 case R_PPC_REL14_BRTAKEN:
3026 case R_PPC_REL14_BRNTAKEN:
3030 if (h == htab->elf.hgot)
3040 case R_PPC_ADDR16_LO:
3041 case R_PPC_ADDR16_HI:
3042 case R_PPC_ADDR16_HA:
3044 case R_PPC_ADDR14_BRTAKEN:
3045 case R_PPC_ADDR14_BRNTAKEN:
3048 if (h != NULL && !info->shared)
3050 /* We may need a plt entry if the symbol turns out to be
3051 a function defined in a dynamic object. */
3054 /* We may need a copy reloc too. */
3059 /* If we are creating a shared library, and this is a reloc
3060 against a global symbol, or a non PC relative reloc
3061 against a local symbol, then we need to copy the reloc
3062 into the shared library. However, if we are linking with
3063 -Bsymbolic, we do not need to copy a reloc against a
3064 global symbol which is defined in an object we are
3065 including in the link (i.e., DEF_REGULAR is set). At
3066 this point we have not seen all the input files, so it is
3067 possible that DEF_REGULAR is not set now but will be set
3068 later (it is never cleared). In case of a weak definition,
3069 DEF_REGULAR may be cleared later by a strong definition in
3070 a shared library. We account for that possibility below by
3071 storing information in the dyn_relocs field of the hash
3072 table entry. A similar situation occurs when creating
3073 shared libraries and symbol visibility changes render the
3076 If on the other hand, we are creating an executable, we
3077 may need to keep relocations for symbols satisfied by a
3078 dynamic library if we manage to avoid copy relocs for the
3081 && (MUST_BE_DYN_RELOC (r_type)
3083 && (! info->symbolic
3084 || h->root.type == bfd_link_hash_defweak
3085 || !h->def_regular))))
3086 || (ELIMINATE_COPY_RELOCS
3089 && (h->root.type == bfd_link_hash_defweak
3090 || !h->def_regular)))
3092 struct ppc_elf_dyn_relocs *p;
3093 struct ppc_elf_dyn_relocs **head;
3097 "ppc_elf_check_relocs needs to "
3098 "create relocation for %s\n",
3099 (h && h->root.root.string
3100 ? h->root.root.string : "<unknown>"));
3106 name = (bfd_elf_string_from_elf_section
3108 elf_elfheader (abfd)->e_shstrndx,
3109 elf_section_data (sec)->rel_hdr.sh_name));
3113 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3114 && strcmp (bfd_get_section_name (abfd, sec),
3117 if (htab->elf.dynobj == NULL)
3118 htab->elf.dynobj = abfd;
3119 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3124 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3125 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3126 | SEC_ALLOC | SEC_LOAD);
3127 sreloc = bfd_make_section_with_flags (htab->elf.dynobj,
3131 || ! bfd_set_section_alignment (htab->elf.dynobj,
3135 elf_section_data (sec)->sreloc = sreloc;
3138 /* If this is a global symbol, we count the number of
3139 relocations we need for this symbol. */
3142 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3146 /* Track dynamic relocs needed for local syms too.
3147 We really need local syms available to do this
3151 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3156 head = ((struct ppc_elf_dyn_relocs **)
3157 &elf_section_data (s)->local_dynrel);
3161 if (p == NULL || p->sec != sec)
3163 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3174 if (!MUST_BE_DYN_RELOC (r_type))
3185 /* Merge backend specific data from an object file to the output
3186 object file when linking. */
3189 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
3195 if (!is_ppc_elf_target (ibfd->xvec)
3196 || !is_ppc_elf_target (obfd->xvec))
3199 /* Check if we have the same endianess. */
3200 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
3203 new_flags = elf_elfheader (ibfd)->e_flags;
3204 old_flags = elf_elfheader (obfd)->e_flags;
3205 if (!elf_flags_init (obfd))
3207 /* First call, no flags set. */
3208 elf_flags_init (obfd) = TRUE;
3209 elf_elfheader (obfd)->e_flags = new_flags;
3212 /* Compatible flags are ok. */
3213 else if (new_flags == old_flags)
3216 /* Incompatible flags. */
3219 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
3220 to be linked with either. */
3222 if ((new_flags & EF_PPC_RELOCATABLE) != 0
3223 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
3226 (*_bfd_error_handler)
3227 (_("%B: compiled with -mrelocatable and linked with "
3228 "modules compiled normally"), ibfd);
3230 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
3231 && (old_flags & EF_PPC_RELOCATABLE) != 0)
3234 (*_bfd_error_handler)
3235 (_("%B: compiled normally and linked with "
3236 "modules compiled with -mrelocatable"), ibfd);
3239 /* The output is -mrelocatable-lib iff both the input files are. */
3240 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
3241 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
3243 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
3244 but each input file is either -mrelocatable or -mrelocatable-lib. */
3245 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
3246 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
3247 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
3248 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
3250 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
3251 any module uses it. */
3252 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
3254 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3255 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
3257 /* Warn about any other mismatches. */
3258 if (new_flags != old_flags)
3261 (*_bfd_error_handler)
3262 (_("%B: uses different e_flags (0x%lx) fields "
3263 "than previous modules (0x%lx)"),
3264 ibfd, (long) new_flags, (long) old_flags);
3269 bfd_set_error (bfd_error_bad_value);
3277 /* Choose which PLT scheme to use, and set .plt flags appropriately.
3278 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
3280 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
3281 struct bfd_link_info *info,
3284 struct ppc_elf_link_hash_table *htab;
3286 htab = ppc_elf_hash_table (info);
3287 if (force_old_plt || !htab->new_plt)
3292 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3293 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3295 /* The new PLT is a loaded section. */
3296 if (htab->plt != NULL
3297 && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
3300 /* The new GOT is not executable. */
3301 if (htab->got != NULL
3302 && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
3307 /* Stop an unused .glink section from affecting .text alignment. */
3308 if (htab->glink != NULL
3309 && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
3312 return !htab->old_plt;
3315 /* Return the section that should be marked against GC for a given
3319 ppc_elf_gc_mark_hook (asection *sec,
3320 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3321 Elf_Internal_Rela *rel,
3322 struct elf_link_hash_entry *h,
3323 Elf_Internal_Sym *sym)
3327 switch (ELF32_R_TYPE (rel->r_info))
3329 case R_PPC_GNU_VTINHERIT:
3330 case R_PPC_GNU_VTENTRY:
3334 switch (h->root.type)
3336 case bfd_link_hash_defined:
3337 case bfd_link_hash_defweak:
3338 return h->root.u.def.section;
3340 case bfd_link_hash_common:
3341 return h->root.u.c.p->section;
3349 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3354 /* Update the got, plt and dynamic reloc reference counts for the
3355 section being removed. */
3358 ppc_elf_gc_sweep_hook (bfd *abfd,
3359 struct bfd_link_info *info,
3361 const Elf_Internal_Rela *relocs)
3363 struct ppc_elf_link_hash_table *htab;
3364 Elf_Internal_Shdr *symtab_hdr;
3365 struct elf_link_hash_entry **sym_hashes;
3366 bfd_signed_vma *local_got_refcounts;
3367 const Elf_Internal_Rela *rel, *relend;
3369 if ((sec->flags & SEC_ALLOC) == 0)
3372 elf_section_data (sec)->local_dynrel = NULL;
3374 htab = ppc_elf_hash_table (info);
3375 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3376 sym_hashes = elf_sym_hashes (abfd);
3377 local_got_refcounts = elf_local_got_refcounts (abfd);
3379 relend = relocs + sec->reloc_count;
3380 for (rel = relocs; rel < relend; rel++)
3382 unsigned long r_symndx;
3383 enum elf_ppc_reloc_type r_type;
3384 struct elf_link_hash_entry *h = NULL;
3386 r_symndx = ELF32_R_SYM (rel->r_info);
3387 if (r_symndx >= symtab_hdr->sh_info)
3389 struct ppc_elf_dyn_relocs **pp, *p;
3390 struct ppc_elf_link_hash_entry *eh;
3392 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3393 while (h->root.type == bfd_link_hash_indirect
3394 || h->root.type == bfd_link_hash_warning)
3395 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3396 eh = (struct ppc_elf_link_hash_entry *) h;
3398 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3401 /* Everything must go for SEC. */
3407 r_type = ELF32_R_TYPE (rel->r_info);
3410 case R_PPC_GOT_TLSLD16:
3411 case R_PPC_GOT_TLSLD16_LO:
3412 case R_PPC_GOT_TLSLD16_HI:
3413 case R_PPC_GOT_TLSLD16_HA:
3414 htab->tlsld_got.refcount -= 1;
3417 case R_PPC_GOT_TLSGD16:
3418 case R_PPC_GOT_TLSGD16_LO:
3419 case R_PPC_GOT_TLSGD16_HI:
3420 case R_PPC_GOT_TLSGD16_HA:
3421 case R_PPC_GOT_TPREL16:
3422 case R_PPC_GOT_TPREL16_LO:
3423 case R_PPC_GOT_TPREL16_HI:
3424 case R_PPC_GOT_TPREL16_HA:
3425 case R_PPC_GOT_DTPREL16:
3426 case R_PPC_GOT_DTPREL16_LO:
3427 case R_PPC_GOT_DTPREL16_HI:
3428 case R_PPC_GOT_DTPREL16_HA:
3430 case R_PPC_GOT16_LO:
3431 case R_PPC_GOT16_HI:
3432 case R_PPC_GOT16_HA:
3435 if (h->got.refcount > 0)
3438 else if (local_got_refcounts != NULL)
3440 if (local_got_refcounts[r_symndx] > 0)
3441 local_got_refcounts[r_symndx]--;
3447 case R_PPC_REL14_BRTAKEN:
3448 case R_PPC_REL14_BRNTAKEN:
3450 if (h == NULL || h == htab->elf.hgot)
3457 case R_PPC_ADDR16_LO:
3458 case R_PPC_ADDR16_HI:
3459 case R_PPC_ADDR16_HA:
3461 case R_PPC_ADDR14_BRTAKEN:
3462 case R_PPC_ADDR14_BRNTAKEN:
3466 case R_PPC_PLTREL24:
3467 case R_PPC_PLT16_LO:
3468 case R_PPC_PLT16_HI:
3469 case R_PPC_PLT16_HA:
3472 if (h->plt.refcount > 0)
3484 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
3487 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
3489 struct ppc_elf_link_hash_table *htab;
3491 htab = ppc_elf_hash_table (info);
3493 && htab->plt != NULL
3494 && htab->plt->output_section != NULL)
3496 elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
3497 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
3500 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3501 FALSE, FALSE, TRUE);
3502 return _bfd_elf_tls_setup (obfd, info);
3505 /* Run through all the TLS relocs looking for optimization
3509 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
3510 struct bfd_link_info *info)
3514 struct ppc_elf_link_hash_table *htab;
3516 if (info->relocatable || info->shared)
3519 htab = ppc_elf_hash_table (info);
3520 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3522 Elf_Internal_Sym *locsyms = NULL;
3523 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3525 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3526 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
3528 Elf_Internal_Rela *relstart, *rel, *relend;
3529 int expecting_tls_get_addr;
3531 /* Read the relocations. */
3532 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
3534 if (relstart == NULL)
3537 expecting_tls_get_addr = 0;
3538 relend = relstart + sec->reloc_count;
3539 for (rel = relstart; rel < relend; rel++)
3541 enum elf_ppc_reloc_type r_type;
3542 unsigned long r_symndx;
3543 struct elf_link_hash_entry *h = NULL;
3545 char tls_set, tls_clear;
3546 bfd_boolean is_local;
3548 r_symndx = ELF32_R_SYM (rel->r_info);
3549 if (r_symndx >= symtab_hdr->sh_info)
3551 struct elf_link_hash_entry **sym_hashes;
3553 sym_hashes = elf_sym_hashes (ibfd);
3554 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3555 while (h->root.type == bfd_link_hash_indirect
3556 || h->root.type == bfd_link_hash_warning)
3557 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3565 r_type = ELF32_R_TYPE (rel->r_info);
3568 case R_PPC_GOT_TLSLD16:
3569 case R_PPC_GOT_TLSLD16_LO:
3570 case R_PPC_GOT_TLSLD16_HI:
3571 case R_PPC_GOT_TLSLD16_HA:
3572 /* These relocs should never be against a symbol
3573 defined in a shared lib. Leave them alone if
3574 that turns out to be the case. */
3575 expecting_tls_get_addr = 0;
3576 htab->tlsld_got.refcount -= 1;
3583 expecting_tls_get_addr = 1;
3586 case R_PPC_GOT_TLSGD16:
3587 case R_PPC_GOT_TLSGD16_LO:
3588 case R_PPC_GOT_TLSGD16_HI:
3589 case R_PPC_GOT_TLSGD16_HA:
3595 tls_set = TLS_TLS | TLS_TPRELGD;
3597 expecting_tls_get_addr = 1;
3600 case R_PPC_GOT_TPREL16:
3601 case R_PPC_GOT_TPREL16_LO:
3602 case R_PPC_GOT_TPREL16_HI:
3603 case R_PPC_GOT_TPREL16_HA:
3604 expecting_tls_get_addr = 0;
3609 tls_clear = TLS_TPREL;
3616 case R_PPC_REL14_BRTAKEN:
3617 case R_PPC_REL14_BRNTAKEN:
3619 if (expecting_tls_get_addr
3621 && h == htab->tls_get_addr)
3623 if (h->plt.refcount > 0)
3624 h->plt.refcount -= 1;
3626 expecting_tls_get_addr = 0;
3630 expecting_tls_get_addr = 0;
3638 /* We managed to get rid of a got entry. */
3639 if (h->got.refcount > 0)
3640 h->got.refcount -= 1;
3642 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
3646 Elf_Internal_Sym *sym;
3647 bfd_signed_vma *lgot_refs;
3650 if (locsyms == NULL)
3652 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
3653 if (locsyms == NULL)
3654 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3655 symtab_hdr->sh_info,
3656 0, NULL, NULL, NULL);
3657 if (locsyms == NULL)
3659 if (elf_section_data (sec)->relocs != relstart)
3664 sym = locsyms + r_symndx;
3665 lgot_refs = elf_local_got_refcounts (ibfd);
3666 if (lgot_refs == NULL)
3670 /* We managed to get rid of a got entry. */
3671 if (lgot_refs[r_symndx] > 0)
3672 lgot_refs[r_symndx] -= 1;
3674 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
3675 tls_mask = &lgot_masks[r_symndx];
3678 *tls_mask |= tls_set;
3679 *tls_mask &= ~tls_clear;
3682 if (elf_section_data (sec)->relocs != relstart)
3687 && (symtab_hdr->contents != (unsigned char *) locsyms))
3689 if (!info->keep_memory)
3692 symtab_hdr->contents = (unsigned char *) locsyms;
3698 /* Adjust a symbol defined by a dynamic object and referenced by a
3699 regular object. The current definition is in some section of the
3700 dynamic object, but we're not including those sections. We have to
3701 change the definition to something the rest of the link can
3705 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3706 struct elf_link_hash_entry *h)
3708 struct ppc_elf_link_hash_table *htab;
3710 unsigned int power_of_two;
3713 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
3714 h->root.root.string);
3717 /* Make sure we know what is going on here. */
3718 htab = ppc_elf_hash_table (info);
3719 BFD_ASSERT (htab->elf.dynobj != NULL
3721 || h->u.weakdef != NULL
3724 && !h->def_regular)));
3726 /* Deal with function syms. */
3727 if (h->type == STT_FUNC
3730 /* Clear procedure linkage table information for any symbol that
3731 won't need a .plt entry. */
3732 if (h->plt.refcount <= 0
3733 || SYMBOL_CALLS_LOCAL (info, h)
3734 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3735 && h->root.type == bfd_link_hash_undefweak))
3737 /* A PLT entry is not required/allowed when:
3739 1. We are not using ld.so; because then the PLT entry
3740 can't be set up, so we can't use one. In this case,
3741 ppc_elf_adjust_dynamic_symbol won't even be called.
3743 2. GC has rendered the entry unused.
3745 3. We know for certain that a call to this symbol
3746 will go to this object, or will remain undefined. */
3747 h->plt.offset = (bfd_vma) -1;
3753 h->plt.offset = (bfd_vma) -1;
3755 /* If this is a weak symbol, and there is a real definition, the
3756 processor independent code will have arranged for us to see the
3757 real definition first, and we can just use the same value. */
3758 if (h->u.weakdef != NULL)
3760 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3761 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3762 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3763 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3764 if (ELIMINATE_COPY_RELOCS)
3765 h->non_got_ref = h->u.weakdef->non_got_ref;
3769 /* This is a reference to a symbol defined by a dynamic object which
3770 is not a function. */
3772 /* If we are creating a shared library, we must presume that the
3773 only references to the symbol are via the global offset table.
3774 For such cases we need not do anything here; the relocations will
3775 be handled correctly by relocate_section. */
3779 /* If there are no references to this symbol that do not use the
3780 GOT, we don't need to generate a copy reloc. */
3781 if (!h->non_got_ref)
3784 if (ELIMINATE_COPY_RELOCS)
3786 struct ppc_elf_dyn_relocs *p;
3787 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
3789 s = p->sec->output_section;
3790 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3794 /* If we didn't find any dynamic relocs in read-only sections, then
3795 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3803 /* We must allocate the symbol in our .dynbss section, which will
3804 become part of the .bss section of the executable. There will be
3805 an entry for this symbol in the .dynsym section. The dynamic
3806 object will contain position independent code, so all references
3807 from the dynamic object to this symbol will go through the global
3808 offset table. The dynamic linker will use the .dynsym entry to
3809 determine the address it must put in the global offset table, so
3810 both the dynamic object and the regular object will refer to the
3811 same memory location for the variable.
3813 Of course, if the symbol is sufficiently small, we must instead
3814 allocate it in .sbss. FIXME: It would be better to do this if and
3815 only if there were actually SDAREL relocs for that symbol. */
3817 if (h->size <= elf_gp_size (htab->elf.dynobj))
3821 BFD_ASSERT (s != NULL);
3823 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3824 copy the initial value out of the dynamic object and into the
3825 runtime process image. We need to remember the offset into the
3826 .rela.bss section we are going to use. */
3827 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3831 if (h->size <= elf_gp_size (htab->elf.dynobj))
3832 srel = htab->relsbss;
3834 srel = htab->relbss;
3835 BFD_ASSERT (srel != NULL);
3836 srel->size += sizeof (Elf32_External_Rela);
3840 /* We need to figure out the alignment required for this symbol. I
3841 have no idea how ELF linkers handle this. */
3842 power_of_two = bfd_log2 (h->size);
3843 if (power_of_two > 4)
3846 /* Apply the required alignment. */
3847 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
3848 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3850 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3854 /* Define the symbol as being at this point in the section. */
3855 h->root.u.def.section = s;
3856 h->root.u.def.value = s->size;
3858 /* Increment the section size to make room for the symbol. */
3864 /* Allocate NEED contiguous space in .got, and return the offset.
3865 Handles allocation of the got header when crossing 32k. */
3868 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
3871 unsigned int max_before_header = 32768;
3874 max_before_header = 32764;
3876 if (need <= htab->got_gap)
3878 where = max_before_header - htab->got_gap;
3879 htab->got_gap -= need;
3883 if (htab->got->size + need > max_before_header
3884 && htab->got->size <= max_before_header)
3886 htab->got_gap = max_before_header - htab->got->size;
3887 htab->got->size = max_before_header + htab->got_header_size;
3889 where = htab->got->size;
3890 htab->got->size += need;
3895 /* Allocate space in associated reloc sections for dynamic relocs. */
3898 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
3900 struct bfd_link_info *info = inf;
3901 struct ppc_elf_link_hash_entry *eh;
3902 struct ppc_elf_link_hash_table *htab;
3903 struct ppc_elf_dyn_relocs *p;
3905 if (h->root.type == bfd_link_hash_indirect)
3908 if (h->root.type == bfd_link_hash_warning)
3909 /* When warning symbols are created, they **replace** the "real"
3910 entry in the hash table, thus we never get to see the real
3911 symbol in a hash traversal. So look at it now. */
3912 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3914 htab = ppc_elf_hash_table (info);
3915 if (htab->elf.dynamic_sections_created
3916 && h->plt.refcount > 0)
3918 /* Make sure this symbol is output as a dynamic symbol. */
3919 if (h->dynindx == -1
3920 && !h->forced_local)
3922 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3927 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
3929 asection *s = htab->plt;
3933 h->plt.offset = s->size;
3940 h->root.u.def.section = s;
3941 h->root.u.def.value = s->size;
3943 s->size += GLINK_ENTRY_SIZE;
3947 /* If this is the first .plt entry, make room for the
3948 special first entry. */
3950 s->size += PLT_INITIAL_ENTRY_SIZE;
3952 /* The PowerPC PLT is actually composed of two parts, the
3953 first part is 2 words (for a load and a jump), and then
3954 there is a remaining word available at the end. */
3955 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
3957 * ((s->size - PLT_INITIAL_ENTRY_SIZE)
3958 / PLT_ENTRY_SIZE)));
3960 /* If this symbol is not defined in a regular file, and we
3961 are not generating a shared library, then set the symbol
3962 to this location in the .plt. This is required to make
3963 function pointers compare as equal between the normal
3964 executable and the shared library. */
3968 h->root.u.def.section = s;
3969 h->root.u.def.value = h->plt.offset;
3972 /* Make room for this entry. After the 8192nd entry, room
3973 for two entries is allocated. */
3974 s->size += PLT_ENTRY_SIZE;
3975 if ((s->size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
3976 > PLT_NUM_SINGLE_ENTRIES)
3977 s->size += PLT_ENTRY_SIZE;
3980 /* We also need to make an entry in the .rela.plt section. */
3981 htab->relplt->size += sizeof (Elf32_External_Rela);
3985 h->plt.offset = (bfd_vma) -1;
3991 h->plt.offset = (bfd_vma) -1;
3995 eh = (struct ppc_elf_link_hash_entry *) h;
3996 if (eh->elf.got.refcount > 0)
3998 /* Make sure this symbol is output as a dynamic symbol. */
3999 if (eh->elf.dynindx == -1
4000 && !eh->elf.forced_local)
4002 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
4006 if (eh->tls_mask == (TLS_TLS | TLS_LD)
4007 && !eh->elf.def_dynamic)
4008 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4009 eh->elf.got.offset = (bfd_vma) -1;
4013 unsigned int need = 0;
4014 if ((eh->tls_mask & TLS_TLS) != 0)
4016 if ((eh->tls_mask & TLS_LD) != 0)
4018 if ((eh->tls_mask & TLS_GD) != 0)
4020 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
4022 if ((eh->tls_mask & TLS_DTPREL) != 0)
4027 eh->elf.got.offset = allocate_got (htab, need);
4028 dyn = htab->elf.dynamic_sections_created;
4030 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
4031 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
4032 || eh->elf.root.type != bfd_link_hash_undefweak))
4034 /* All the entries we allocated need relocs.
4035 Except LD only needs one. */
4036 if ((eh->tls_mask & TLS_LD) != 0)
4038 htab->relgot->size += need * (sizeof (Elf32_External_Rela) / 4);
4043 eh->elf.got.offset = (bfd_vma) -1;
4045 if (eh->dyn_relocs == NULL)
4048 /* In the shared -Bsymbolic case, discard space allocated for
4049 dynamic pc-relative relocs against symbols which turn out to be
4050 defined in regular objects. For the normal shared case, discard
4051 space for relocs that have become local due to symbol visibility
4056 /* Relocs that use pc_count are those that appear on a call insn,
4057 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
4058 generated via assembly. We want calls to protected symbols to
4059 resolve directly to the function rather than going via the plt.
4060 If people want function pointer comparisons to work as expected
4061 then they should avoid writing weird assembly. */
4062 if (SYMBOL_CALLS_LOCAL (info, h))
4064 struct ppc_elf_dyn_relocs **pp;
4066 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4068 p->count -= p->pc_count;
4077 /* Also discard relocs on undefined weak syms with non-default
4079 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4080 && h->root.type == bfd_link_hash_undefweak)
4081 eh->dyn_relocs = NULL;
4083 /* Make sure undefined weak symbols are output as a dynamic symbol
4086 && eh->dyn_relocs != NULL
4088 && h->root.type == bfd_link_hash_undefweak
4089 && !h->forced_local)
4091 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4095 else if (ELIMINATE_COPY_RELOCS)
4097 /* For the non-shared case, discard space for relocs against
4098 symbols which turn out to need copy relocs or are not
4105 /* Make sure this symbol is output as a dynamic symbol.
4106 Undefined weak syms won't yet be marked as dynamic. */
4107 if (h->dynindx == -1
4108 && !h->forced_local)
4110 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4114 /* If that succeeded, we know we'll be keeping all the
4116 if (h->dynindx != -1)
4120 eh->dyn_relocs = NULL;
4125 /* Finally, allocate space. */
4126 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4128 asection *sreloc = elf_section_data (p->sec)->sreloc;
4129 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4135 /* Find any dynamic relocs that apply to read-only sections. */
4138 readonly_dynrelocs (struct elf_link_hash_entry *h, void *info)
4140 struct ppc_elf_dyn_relocs *p;
4142 if (h->root.type == bfd_link_hash_indirect)
4145 if (h->root.type == bfd_link_hash_warning)
4146 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4148 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
4150 asection *s = p->sec->output_section;
4153 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
4154 == (SEC_READONLY | SEC_ALLOC)))
4156 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
4158 /* Not an error, just cut short the traversal. */
4165 /* Set the sizes of the dynamic sections. */
4168 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4169 struct bfd_link_info *info)
4171 struct ppc_elf_link_hash_table *htab;
4177 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
4180 htab = ppc_elf_hash_table (info);
4181 BFD_ASSERT (htab->elf.dynobj != NULL);
4183 if (elf_hash_table (info)->dynamic_sections_created)
4185 /* Set the contents of the .interp section to the interpreter. */
4186 if (info->executable)
4188 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
4189 BFD_ASSERT (s != NULL);
4190 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4191 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4196 htab->got_header_size = 16;
4198 htab->got_header_size = 12;
4200 /* Set up .got offsets for local syms, and space for local dynamic
4202 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4204 bfd_signed_vma *local_got;
4205 bfd_signed_vma *end_local_got;
4207 bfd_size_type locsymcount;
4208 Elf_Internal_Shdr *symtab_hdr;
4210 if (!is_ppc_elf_target (ibfd->xvec))
4213 for (s = ibfd->sections; s != NULL; s = s->next)
4215 struct ppc_elf_dyn_relocs *p;
4217 for (p = ((struct ppc_elf_dyn_relocs *)
4218 elf_section_data (s)->local_dynrel);
4222 if (!bfd_is_abs_section (p->sec)
4223 && bfd_is_abs_section (p->sec->output_section))
4225 /* Input section has been discarded, either because
4226 it is a copy of a linkonce section or due to
4227 linker script /DISCARD/, so we'll be discarding
4230 else if (p->count != 0)
4232 elf_section_data (p->sec)->sreloc->size
4233 += p->count * sizeof (Elf32_External_Rela);
4234 if ((p->sec->output_section->flags
4235 & (SEC_READONLY | SEC_ALLOC))
4236 == (SEC_READONLY | SEC_ALLOC))
4237 info->flags |= DF_TEXTREL;
4242 local_got = elf_local_got_refcounts (ibfd);
4246 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4247 locsymcount = symtab_hdr->sh_info;
4248 end_local_got = local_got + locsymcount;
4249 lgot_masks = (char *) end_local_got;
4250 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
4253 if (*lgot_masks == (TLS_TLS | TLS_LD))
4255 /* If just an LD reloc, we'll just use
4256 htab->tlsld_got.offset. */
4257 htab->tlsld_got.refcount += 1;
4258 *local_got = (bfd_vma) -1;
4262 unsigned int need = 0;
4263 if ((*lgot_masks & TLS_TLS) != 0)
4265 if ((*lgot_masks & TLS_GD) != 0)
4267 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
4269 if ((*lgot_masks & TLS_DTPREL) != 0)
4274 *local_got = allocate_got (htab, need);
4276 htab->relgot->size += (need
4277 * (sizeof (Elf32_External_Rela) / 4));
4281 *local_got = (bfd_vma) -1;
4284 if (htab->tlsld_got.refcount > 0)
4286 htab->tlsld_got.offset = allocate_got (htab, 8);
4288 htab->relgot->size += sizeof (Elf32_External_Rela);
4291 htab->tlsld_got.offset = (bfd_vma) -1;
4293 /* Allocate space for global sym dynamic relocs. */
4294 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
4296 if (htab->got != NULL)
4298 unsigned int g_o_t = 32768;
4300 /* If we haven't allocated the header, do so now. */
4301 if (htab->got->size <= 32768)
4303 g_o_t = htab->got->size;
4304 htab->got->size += htab->got_header_size;
4309 htab->elf.hgot->root.u.def.value = g_o_t;
4312 if (htab->glink != NULL && htab->glink->size != 0)
4314 htab->glink_pltresolve = htab->glink->size;
4315 /* Space for the branch table. */
4316 htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
4317 /* Pad out to align the start of PLTresolve. */
4318 htab->glink->size += -htab->glink->size & 15;
4319 htab->glink->size += GLINK_PLTRESOLVE;
4322 /* We've now determined the sizes of the various dynamic sections.
4323 Allocate memory for them. */
4325 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
4327 if ((s->flags & SEC_LINKER_CREATED) == 0)
4335 /* Strip this section if we don't need it; see the
4338 else if (s == htab->sdata[0].section
4339 || s == htab->sdata[1].section)
4341 /* Strip these too. */
4343 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4347 /* If we don't need this section, strip it from the
4348 output file. This is mostly to handle .rela.bss and
4349 .rela.plt. We must create both sections in
4350 create_dynamic_sections, because they must be created
4351 before the linker maps input sections to output
4352 sections. The linker does that before
4353 adjust_dynamic_symbol is called, and it is that
4354 function which decides whether anything needs to go
4355 into these sections. */
4359 /* Remember whether there are any relocation sections. */
4362 /* We use the reloc_count field as a counter if we need
4363 to copy relocs into the output file. */
4369 /* It's not one of our sections, so don't allocate space. */
4375 s->flags |= SEC_EXCLUDE;
4379 if ((s->flags & SEC_HAS_CONTENTS) == 0)
4382 /* Allocate memory for the section contents. */
4383 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
4384 if (s->contents == NULL)
4388 if (htab->elf.dynamic_sections_created)
4390 /* Add some entries to the .dynamic section. We fill in the
4391 values later, in ppc_elf_finish_dynamic_sections, but we
4392 must add the entries now so that we get the correct size for
4393 the .dynamic section. The DT_DEBUG entry is filled in by the
4394 dynamic linker and used by the debugger. */
4395 #define add_dynamic_entry(TAG, VAL) \
4396 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4398 if (info->executable)
4400 if (!add_dynamic_entry (DT_DEBUG, 0))
4404 if (htab->plt != NULL && htab->plt->size != 0)
4406 if (!add_dynamic_entry (DT_PLTGOT, 0)
4407 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4408 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4409 || !add_dynamic_entry (DT_JMPREL, 0))
4413 if (htab->glink != NULL && htab->glink->size != 0)
4415 if (!add_dynamic_entry (DT_PPC_GOT, 0))
4421 if (!add_dynamic_entry (DT_RELA, 0)
4422 || !add_dynamic_entry (DT_RELASZ, 0)
4423 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
4427 /* If any dynamic relocs apply to a read-only section, then we
4428 need a DT_TEXTREL entry. */
4429 if ((info->flags & DF_TEXTREL) == 0)
4430 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
4433 if ((info->flags & DF_TEXTREL) != 0)
4435 if (!add_dynamic_entry (DT_TEXTREL, 0))
4439 #undef add_dynamic_entry
4444 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
4446 static const int shared_stub_entry[] =
4448 0x7c0802a6, /* mflr 0 */
4449 0x429f0005, /* bcl 20, 31, .Lxxx */
4450 0x7d6802a6, /* mflr 11 */
4451 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
4452 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
4453 0x7c0803a6, /* mtlr 0 */
4454 0x7d6903a6, /* mtctr 11 */
4455 0x4e800420, /* bctr */
4458 static const int stub_entry[] =
4460 0x3d600000, /* lis 11,xxx@ha */
4461 0x396b0000, /* addi 11,11,xxx@l */
4462 0x7d6903a6, /* mtctr 11 */
4463 0x4e800420, /* bctr */
4467 ppc_elf_relax_section (bfd *abfd,
4469 struct bfd_link_info *link_info,
4474 struct one_fixup *next;
4480 Elf_Internal_Shdr *symtab_hdr;
4481 bfd_byte *contents = NULL;
4482 Elf_Internal_Sym *isymbuf = NULL;
4483 Elf_Internal_Rela *internal_relocs = NULL;
4484 Elf_Internal_Rela *irel, *irelend;
4485 struct one_fixup *fixups = NULL;
4486 bfd_boolean changed;
4487 struct ppc_elf_link_hash_table *htab;
4488 bfd_size_type trampoff;
4492 /* Nothing to do if there are no relocations, and no need to do
4493 anything with non-alloc sections. */
4494 if ((isec->flags & SEC_ALLOC) == 0
4495 || (isec->flags & SEC_RELOC) == 0
4496 || isec->reloc_count == 0)
4499 trampoff = (isec->size + 3) & (bfd_vma) -4;
4500 /* Space for a branch around any trampolines. */
4503 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4505 /* Get a copy of the native relocations. */
4506 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
4507 link_info->keep_memory);
4508 if (internal_relocs == NULL)
4511 htab = ppc_elf_hash_table (link_info);
4512 irelend = internal_relocs + isec->reloc_count;
4514 for (irel = internal_relocs; irel < irelend; irel++)
4516 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
4517 bfd_vma symaddr, reladdr, toff, roff;
4519 struct one_fixup *f;
4520 size_t insn_offset = 0;
4521 bfd_vma max_branch_offset, val;
4524 unsigned char sym_type;
4529 case R_PPC_LOCAL24PC:
4530 case R_PPC_PLTREL24:
4531 max_branch_offset = 1 << 25;
4535 case R_PPC_REL14_BRTAKEN:
4536 case R_PPC_REL14_BRNTAKEN:
4537 max_branch_offset = 1 << 15;
4544 /* Get the value of the symbol referred to by the reloc. */
4545 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4547 /* A local symbol. */
4548 Elf_Internal_Sym *isym;
4550 /* Read this BFD's local symbols. */
4551 if (isymbuf == NULL)
4553 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4554 if (isymbuf == NULL)
4555 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4556 symtab_hdr->sh_info, 0,
4561 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4562 if (isym->st_shndx == SHN_UNDEF)
4563 continue; /* We can't do anything with undefined symbols. */
4564 else if (isym->st_shndx == SHN_ABS)
4565 tsec = bfd_abs_section_ptr;
4566 else if (isym->st_shndx == SHN_COMMON)
4567 tsec = bfd_com_section_ptr;
4569 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4571 toff = isym->st_value;
4572 sym_type = ELF_ST_TYPE (isym->st_info);
4576 /* Global symbol handling. */
4578 struct elf_link_hash_entry *h;
4580 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4581 h = elf_sym_hashes (abfd)[indx];
4583 while (h->root.type == bfd_link_hash_indirect
4584 || h->root.type == bfd_link_hash_warning)
4585 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4587 if (r_type == R_PPC_PLTREL24
4588 && htab->plt != NULL
4589 && h->plt.offset != (bfd_vma) -1)
4594 toff = h->plt.offset * (GLINK_ENTRY_SIZE / 4);
4599 toff = h->plt.offset;
4602 else if (h->root.type == bfd_link_hash_defined
4603 || h->root.type == bfd_link_hash_defweak)
4605 tsec = h->root.u.def.section;
4606 toff = h->root.u.def.value;
4614 /* If the branch and target are in the same section, you have
4615 no hope of adding stubs. We'll error out later should the
4620 /* There probably isn't any reason to handle symbols in
4621 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
4622 attribute for a code section, and we are only looking at
4623 branches. However, implement it correctly here as a
4624 reference for other target relax_section functions. */
4625 if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
4627 /* At this stage in linking, no SEC_MERGE symbol has been
4628 adjusted, so all references to such symbols need to be
4629 passed through _bfd_merged_section_offset. (Later, in
4630 relocate_section, all SEC_MERGE symbols *except* for
4631 section symbols have been adjusted.)
4633 gas may reduce relocations against symbols in SEC_MERGE
4634 sections to a relocation against the section symbol when
4635 the original addend was zero. When the reloc is against
4636 a section symbol we should include the addend in the
4637 offset passed to _bfd_merged_section_offset, since the
4638 location of interest is the original symbol. On the
4639 other hand, an access to "sym+addend" where "sym" is not
4640 a section symbol should not include the addend; Such an
4641 access is presumed to be an offset from "sym"; The
4642 location of interest is just "sym". */
4643 if (sym_type == STT_SECTION)
4644 toff += irel->r_addend;
4646 toff = _bfd_merged_section_offset (abfd, &tsec,
4647 elf_section_data (tsec)->sec_info,
4650 if (sym_type != STT_SECTION)
4651 toff += irel->r_addend;
4654 toff += irel->r_addend;
4656 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
4658 roff = irel->r_offset;
4659 reladdr = isec->output_section->vma + isec->output_offset + roff;
4661 /* If the branch is in range, no need to do anything. */
4662 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
4665 /* Look for an existing fixup to this address. */
4666 for (f = fixups; f ; f = f->next)
4667 if (f->tsec == tsec && f->toff == toff)
4673 unsigned long stub_rtype;
4675 val = trampoff - roff;
4676 if (val >= max_branch_offset)
4677 /* Oh dear, we can't reach a trampoline. Don't try to add
4678 one. We'll report an error later. */
4681 if (link_info->shared)
4683 size = 4 * ARRAY_SIZE (shared_stub_entry);
4685 stub_rtype = R_PPC_RELAX32PC;
4689 size = 4 * ARRAY_SIZE (stub_entry);
4691 stub_rtype = R_PPC_RELAX32;
4694 if (R_PPC_RELAX32_PLT - R_PPC_RELAX32
4695 != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC)
4697 if (tsec == htab->plt
4698 || tsec == htab->glink)
4699 stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32;
4701 /* Hijack the old relocation. Since we need two
4702 relocations for this use a "composite" reloc. */
4703 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
4705 irel->r_offset = trampoff + insn_offset;
4707 /* Record the fixup so we don't do it again this section. */
4708 f = bfd_malloc (sizeof (*f));
4712 f->trampoff = trampoff;
4719 val = f->trampoff - roff;
4720 if (val >= max_branch_offset)
4723 /* Nop out the reloc, since we're finalizing things here. */
4724 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
4727 /* Get the section contents. */
4728 if (contents == NULL)
4730 /* Get cached copy if it exists. */
4731 if (elf_section_data (isec)->this_hdr.contents != NULL)
4732 contents = elf_section_data (isec)->this_hdr.contents;
4735 /* Go get them off disk. */
4736 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
4741 /* Fix up the existing branch to hit the trampoline. */
4742 hit_addr = contents + roff;
4746 case R_PPC_LOCAL24PC:
4747 case R_PPC_PLTREL24:
4748 t0 = bfd_get_32 (abfd, hit_addr);
4750 t0 |= val & 0x3fffffc;
4751 bfd_put_32 (abfd, t0, hit_addr);
4755 case R_PPC_REL14_BRTAKEN:
4756 case R_PPC_REL14_BRNTAKEN:
4757 t0 = bfd_get_32 (abfd, hit_addr);
4760 bfd_put_32 (abfd, t0, hit_addr);
4765 /* Write out the trampolines. */
4766 changed = fixups != NULL;
4776 struct one_fixup *f = fixups;
4777 fixups = fixups->next;
4782 contents = bfd_realloc (contents, trampoff);
4783 if (contents == NULL)
4786 isec->size = (isec->size + 3) & (bfd_vma) -4;
4787 /* Branch around the trampolines. */
4788 val = trampoff - isec->size + 0x48000000;
4789 dest = contents + isec->size;
4790 isec->size = trampoff;
4791 bfd_put_32 (abfd, val, dest);
4794 if (link_info->shared)
4796 stub = shared_stub_entry;
4797 size = ARRAY_SIZE (shared_stub_entry);
4802 size = ARRAY_SIZE (stub_entry);
4806 while (dest < contents + trampoff)
4808 bfd_put_32 (abfd, stub[i], dest);
4814 BFD_ASSERT (i == 0);
4818 && symtab_hdr->contents != (unsigned char *) isymbuf)
4820 if (! link_info->keep_memory)
4824 /* Cache the symbols for elf_link_input_bfd. */
4825 symtab_hdr->contents = (unsigned char *) isymbuf;
4829 if (contents != NULL
4830 && elf_section_data (isec)->this_hdr.contents != contents)
4832 if (!changed && !link_info->keep_memory)
4836 /* Cache the section contents for elf_link_input_bfd. */
4837 elf_section_data (isec)->this_hdr.contents = contents;
4841 if (elf_section_data (isec)->relocs != internal_relocs)
4844 free (internal_relocs);
4846 elf_section_data (isec)->relocs = internal_relocs;
4853 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
4855 if (contents != NULL
4856 && elf_section_data (isec)->this_hdr.contents != contents)
4858 if (internal_relocs != NULL
4859 && elf_section_data (isec)->relocs != internal_relocs)
4860 free (internal_relocs);
4864 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms. They are
4865 set here rather than via PROVIDE in the default linker script,
4866 because using PROVIDE inside an output section statement results in
4867 unnecessary output sections. Using PROVIDE outside an output section
4868 statement runs the risk of section alignment affecting where the
4872 ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
4874 struct ppc_elf_link_hash_table *htab;
4879 htab = ppc_elf_hash_table (info);
4881 for (i = 0; i < 2; i++)
4883 elf_linker_section_t *lsect = &htab->sdata[i];
4887 s = s->output_section;
4889 s = bfd_get_section_by_name (obfd, lsect->name);
4891 s = bfd_get_section_by_name (obfd, lsect->bss_name);
4895 val = s->vma + 32768;
4896 lsect->sym_val = val;
4898 _bfd_elf_provide_symbol (info, lsect->sym_name, val);
4901 s = bfd_get_section_by_name (obfd, ".sbss");
4905 _bfd_elf_provide_symbol (info, "__sbss_start", val);
4906 _bfd_elf_provide_symbol (info, "___sbss_start", val);
4909 _bfd_elf_provide_symbol (info, "__sbss_end", val);
4910 _bfd_elf_provide_symbol (info, "___sbss_end", val);
4914 /* Fill in the address for a pointer generated in a linker section. */
4917 elf_finish_pointer_linker_section (bfd *input_bfd,
4918 elf_linker_section_t *lsect,
4919 struct elf_link_hash_entry *h,
4921 const Elf_Internal_Rela *rel)
4923 elf_linker_section_pointers_t *linker_section_ptr;
4925 BFD_ASSERT (lsect != NULL);
4929 /* Handle global symbol. */
4930 struct ppc_elf_link_hash_entry *eh;
4932 eh = (struct ppc_elf_link_hash_entry *) h;
4933 BFD_ASSERT (eh->elf.def_regular);
4934 linker_section_ptr = eh->linker_section_pointer;
4938 /* Handle local symbol. */
4939 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
4941 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
4942 linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
4945 linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
4948 BFD_ASSERT (linker_section_ptr != NULL);
4950 /* Offset will always be a multiple of four, so use the bottom bit
4951 as a "written" flag. */
4952 if ((linker_section_ptr->offset & 1) == 0)
4954 bfd_put_32 (lsect->section->owner,
4955 relocation + linker_section_ptr->addend,
4956 lsect->section->contents + linker_section_ptr->offset);
4957 linker_section_ptr->offset += 1;
4960 relocation = (lsect->section->output_offset
4961 + linker_section_ptr->offset - 1
4966 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
4967 lsect->name, (long) relocation, (long) relocation);
4970 /* Subtract out the addend, because it will get added back in by the normal
4972 return relocation - linker_section_ptr->addend;
4975 /* The RELOCATE_SECTION function is called by the ELF backend linker
4976 to handle the relocations for a section.
4978 The relocs are always passed as Rela structures; if the section
4979 actually uses Rel structures, the r_addend field will always be
4982 This function is responsible for adjust the section contents as
4983 necessary, and (if using Rela relocs and generating a
4984 relocatable output file) adjusting the reloc addend as
4987 This function does not have to worry about setting the reloc
4988 address or the reloc symbol index.
4990 LOCAL_SYMS is a pointer to the swapped in local symbols.
4992 LOCAL_SECTIONS is an array giving the section in the input file
4993 corresponding to the st_shndx field of each local symbol.
4995 The global hash table entry for the global symbols can be found
4996 via elf_sym_hashes (input_bfd).
4998 When generating relocatable output, this function must handle
4999 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5000 going to be the section symbol corresponding to the output
5001 section, which means that the addend must be adjusted
5005 ppc_elf_relocate_section (bfd *output_bfd,
5006 struct bfd_link_info *info,
5008 asection *input_section,
5010 Elf_Internal_Rela *relocs,
5011 Elf_Internal_Sym *local_syms,
5012 asection **local_sections)
5014 Elf_Internal_Shdr *symtab_hdr;
5015 struct elf_link_hash_entry **sym_hashes;
5016 struct ppc_elf_link_hash_table *htab;
5017 Elf_Internal_Rela *rel;
5018 Elf_Internal_Rela *relend;
5019 Elf_Internal_Rela outrel;
5021 asection *sreloc = NULL;
5022 bfd_vma *local_got_offsets;
5023 bfd_boolean ret = TRUE;
5026 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
5027 "%ld relocations%s",
5028 input_bfd, input_section,
5029 (long) input_section->reloc_count,
5030 (info->relocatable) ? " (relocatable)" : "");
5033 if (info->relocatable)
5036 /* Initialize howto table if not already done. */
5037 if (!ppc_elf_howto_table[R_PPC_ADDR32])
5038 ppc_elf_howto_init ();
5040 htab = ppc_elf_hash_table (info);
5041 local_got_offsets = elf_local_got_offsets (input_bfd);
5042 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5043 sym_hashes = elf_sym_hashes (input_bfd);
5045 relend = relocs + input_section->reloc_count;
5046 for (; rel < relend; rel++)
5048 enum elf_ppc_reloc_type r_type;
5050 bfd_reloc_status_type r;
5051 Elf_Internal_Sym *sym;
5053 struct elf_link_hash_entry *h;
5054 const char *sym_name;
5055 reloc_howto_type *howto;
5056 unsigned long r_symndx;
5058 bfd_vma branch_bit, insn, from;
5059 bfd_boolean unresolved_reloc;
5061 unsigned int tls_type, tls_mask, tls_gd;
5063 r_type = ELF32_R_TYPE (rel->r_info);
5067 unresolved_reloc = FALSE;
5069 r_symndx = ELF32_R_SYM (rel->r_info);
5071 if (r_symndx < symtab_hdr->sh_info)
5073 sym = local_syms + r_symndx;
5074 sec = local_sections[r_symndx];
5075 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
5077 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5081 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5082 r_symndx, symtab_hdr, sym_hashes,
5084 unresolved_reloc, warned);
5086 sym_name = h->root.root.string;
5089 /* TLS optimizations. Replace instruction sequences and relocs
5090 based on information we collected in tls_optimize. We edit
5091 RELOCS so that --emit-relocs will output something sensible
5092 for the final instruction stream. */
5095 if (IS_PPC_TLS_RELOC (r_type))
5098 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
5099 else if (local_got_offsets != NULL)
5102 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
5103 tls_mask = lgot_masks[r_symndx];
5107 /* Ensure reloc mapping code below stays sane. */
5108 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
5109 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
5110 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
5111 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
5112 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
5113 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
5114 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
5115 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
5122 case R_PPC_GOT_TPREL16:
5123 case R_PPC_GOT_TPREL16_LO:
5125 && (tls_mask & TLS_TPREL) == 0)
5128 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
5130 insn |= 0x3c020000; /* addis 0,2,0 */
5131 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
5132 r_type = R_PPC_TPREL16_HA;
5133 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5139 && (tls_mask & TLS_TPREL) == 0)
5142 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5143 if ((insn & ((31 << 26) | (31 << 11)))
5144 == ((31 << 26) | (2 << 11)))
5145 rtra = insn & ((1 << 26) - (1 << 16));
5146 else if ((insn & ((31 << 26) | (31 << 16)))
5147 == ((31 << 26) | (2 << 16)))
5148 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
5151 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
5154 else if ((insn & (31 << 1)) == 23 << 1
5155 && ((insn & (31 << 6)) < 14 << 6
5156 || ((insn & (31 << 6)) >= 16 << 6
5157 && (insn & (31 << 6)) < 24 << 6)))
5158 /* load and store indexed -> dform. */
5159 insn = (32 | ((insn >> 6) & 31)) << 26;
5160 else if ((insn & (31 << 1)) == 21 << 1
5161 && (insn & (0x1a << 6)) == 0)
5162 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
5163 insn = (((58 | ((insn >> 6) & 4)) << 26)
5164 | ((insn >> 6) & 1));
5165 else if ((insn & (31 << 1)) == 21 << 1
5166 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
5168 insn = (58 << 26) | 2;
5172 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5173 r_type = R_PPC_TPREL16_LO;
5174 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5175 /* Was PPC_TLS which sits on insn boundary, now
5176 PPC_TPREL16_LO which is at insn+2. */
5181 case R_PPC_GOT_TLSGD16_HI:
5182 case R_PPC_GOT_TLSGD16_HA:
5183 tls_gd = TLS_TPRELGD;
5184 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5188 case R_PPC_GOT_TLSLD16_HI:
5189 case R_PPC_GOT_TLSLD16_HA:
5190 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5193 if ((tls_mask & tls_gd) != 0)
5194 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5195 + R_PPC_GOT_TPREL16);
5198 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
5200 r_type = R_PPC_NONE;
5202 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5206 case R_PPC_GOT_TLSGD16:
5207 case R_PPC_GOT_TLSGD16_LO:
5208 tls_gd = TLS_TPRELGD;
5209 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
5210 goto tls_get_addr_check;
5213 case R_PPC_GOT_TLSLD16:
5214 case R_PPC_GOT_TLSLD16_LO:
5215 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
5218 if (rel + 1 < relend)
5220 enum elf_ppc_reloc_type r_type2;
5221 unsigned long r_symndx2;
5222 struct elf_link_hash_entry *h2;
5223 bfd_vma insn1, insn2;
5226 /* The next instruction should be a call to
5227 __tls_get_addr. Peek at the reloc to be sure. */
5228 r_type2 = ELF32_R_TYPE (rel[1].r_info);
5229 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
5230 if (r_symndx2 < symtab_hdr->sh_info
5231 || (r_type2 != R_PPC_REL14
5232 && r_type2 != R_PPC_REL14_BRTAKEN
5233 && r_type2 != R_PPC_REL14_BRNTAKEN
5234 && r_type2 != R_PPC_REL24
5235 && r_type2 != R_PPC_PLTREL24))
5238 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
5239 while (h2->root.type == bfd_link_hash_indirect
5240 || h2->root.type == bfd_link_hash_warning)
5241 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
5242 if (h2 == NULL || h2 != htab->tls_get_addr)
5245 /* OK, it checks out. Replace the call. */
5246 offset = rel[1].r_offset;
5247 insn1 = bfd_get_32 (output_bfd,
5248 contents + rel->r_offset - 2);
5249 if ((tls_mask & tls_gd) != 0)
5252 insn1 &= (1 << 26) - 1;
5253 insn1 |= 32 << 26; /* lwz */
5254 insn2 = 0x7c631214; /* add 3,3,2 */
5255 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
5256 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
5257 + R_PPC_GOT_TPREL16);
5258 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5263 insn1 = 0x3c620000; /* addis 3,2,0 */
5264 insn2 = 0x38630000; /* addi 3,3,0 */
5267 /* Was an LD reloc. */
5269 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5270 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
5272 r_type = R_PPC_TPREL16_HA;
5273 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
5274 rel[1].r_info = ELF32_R_INFO (r_symndx,
5276 rel[1].r_offset += 2;
5278 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
5279 bfd_put_32 (output_bfd, insn2, contents + offset);
5282 /* We changed the symbol on an LD reloc. Start over
5283 in order to get h, sym, sec etc. right. */
5292 /* Handle other relocations that tweak non-addend part of insn. */
5299 /* Branch taken prediction relocations. */
5300 case R_PPC_ADDR14_BRTAKEN:
5301 case R_PPC_REL14_BRTAKEN:
5302 branch_bit = BRANCH_PREDICT_BIT;
5305 /* Branch not taken prediction relocations. */
5306 case R_PPC_ADDR14_BRNTAKEN:
5307 case R_PPC_REL14_BRNTAKEN:
5308 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5309 insn &= ~BRANCH_PREDICT_BIT;
5312 from = (rel->r_offset
5313 + input_section->output_offset
5314 + input_section->output_section->vma);
5316 /* Invert 'y' bit if not the default. */
5317 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
5318 insn ^= BRANCH_PREDICT_BIT;
5320 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5324 addend = rel->r_addend;
5327 if (r_type < R_PPC_max)
5328 howto = ppc_elf_howto_table[r_type];
5332 (*_bfd_error_handler)
5333 (_("%B: unknown relocation type %d for symbol %s"),
5334 input_bfd, (int) r_type, sym_name);
5336 bfd_set_error (bfd_error_bad_value);
5342 case R_PPC_EMB_MRKREF:
5343 case R_PPC_GNU_VTINHERIT:
5344 case R_PPC_GNU_VTENTRY:
5347 /* GOT16 relocations. Like an ADDR16 using the symbol's
5348 address in the GOT as relocation value instead of the
5349 symbol's value itself. Also, create a GOT entry for the
5350 symbol and put the symbol value there. */
5351 case R_PPC_GOT_TLSGD16:
5352 case R_PPC_GOT_TLSGD16_LO:
5353 case R_PPC_GOT_TLSGD16_HI:
5354 case R_PPC_GOT_TLSGD16_HA:
5355 tls_type = TLS_TLS | TLS_GD;
5358 case R_PPC_GOT_TLSLD16:
5359 case R_PPC_GOT_TLSLD16_LO:
5360 case R_PPC_GOT_TLSLD16_HI:
5361 case R_PPC_GOT_TLSLD16_HA:
5362 tls_type = TLS_TLS | TLS_LD;
5365 case R_PPC_GOT_TPREL16:
5366 case R_PPC_GOT_TPREL16_LO:
5367 case R_PPC_GOT_TPREL16_HI:
5368 case R_PPC_GOT_TPREL16_HA:
5369 tls_type = TLS_TLS | TLS_TPREL;
5372 case R_PPC_GOT_DTPREL16:
5373 case R_PPC_GOT_DTPREL16_LO:
5374 case R_PPC_GOT_DTPREL16_HI:
5375 case R_PPC_GOT_DTPREL16_HA:
5376 tls_type = TLS_TLS | TLS_DTPREL;
5380 case R_PPC_GOT16_LO:
5381 case R_PPC_GOT16_HI:
5382 case R_PPC_GOT16_HA:
5385 /* Relocation is to the entry for this symbol in the global
5391 if (htab->got == NULL)
5395 if (tls_type == (TLS_TLS | TLS_LD)
5397 || !h->def_dynamic))
5398 offp = &htab->tlsld_got.offset;
5402 dyn = htab->elf.dynamic_sections_created;
5403 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5405 && SYMBOL_REFERENCES_LOCAL (info, h)))
5406 /* This is actually a static link, or it is a
5407 -Bsymbolic link and the symbol is defined
5408 locally, or the symbol was forced to be local
5409 because of a version file. */
5414 unresolved_reloc = FALSE;
5416 offp = &h->got.offset;
5420 if (local_got_offsets == NULL)
5422 offp = &local_got_offsets[r_symndx];
5425 /* The offset must always be a multiple of 4. We use the
5426 least significant bit to record whether we have already
5427 processed this entry. */
5433 unsigned int tls_m = (tls_mask
5434 & (TLS_LD | TLS_GD | TLS_DTPREL
5435 | TLS_TPREL | TLS_TPRELGD));
5437 if (offp == &htab->tlsld_got.offset)
5443 /* We might have multiple got entries for this sym.
5444 Initialize them all. */
5449 if ((tls_m & TLS_LD) != 0)
5451 tls_ty = TLS_TLS | TLS_LD;
5454 else if ((tls_m & TLS_GD) != 0)
5456 tls_ty = TLS_TLS | TLS_GD;
5459 else if ((tls_m & TLS_DTPREL) != 0)
5461 tls_ty = TLS_TLS | TLS_DTPREL;
5462 tls_m &= ~TLS_DTPREL;
5464 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
5466 tls_ty = TLS_TLS | TLS_TPREL;
5470 /* Generate relocs for the dynamic linker. */
5471 if ((info->shared || indx != 0)
5473 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5474 || h->root.type != bfd_link_hash_undefweak))
5476 outrel.r_offset = (htab->got->output_section->vma
5477 + htab->got->output_offset
5479 outrel.r_addend = 0;
5480 if (tls_ty & (TLS_LD | TLS_GD))
5482 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
5483 if (tls_ty == (TLS_TLS | TLS_GD))
5485 loc = htab->relgot->contents;
5486 loc += (htab->relgot->reloc_count++
5487 * sizeof (Elf32_External_Rela));
5488 bfd_elf32_swap_reloca_out (output_bfd,
5490 outrel.r_offset += 4;
5492 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5495 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
5496 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
5497 else if (tls_ty == (TLS_TLS | TLS_TPREL))
5498 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
5500 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
5502 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
5505 outrel.r_addend += relocation;
5506 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
5507 outrel.r_addend -= htab->elf.tls_sec->vma;
5509 loc = htab->relgot->contents;
5510 loc += (htab->relgot->reloc_count++
5511 * sizeof (Elf32_External_Rela));
5512 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5515 /* Init the .got section contents if we're not
5516 emitting a reloc. */
5519 bfd_vma value = relocation;
5521 if (tls_ty == (TLS_TLS | TLS_LD))
5523 else if (tls_ty != 0)
5525 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
5526 if (tls_ty == (TLS_TLS | TLS_TPREL))
5527 value += DTP_OFFSET - TP_OFFSET;
5529 if (tls_ty == (TLS_TLS | TLS_GD))
5531 bfd_put_32 (output_bfd, value,
5532 htab->got->contents + off + 4);
5536 bfd_put_32 (output_bfd, value,
5537 htab->got->contents + off);
5541 if (tls_ty & (TLS_LD | TLS_GD))
5550 if (off >= (bfd_vma) -2)
5553 if ((tls_type & TLS_TLS) != 0)
5555 if (tls_type != (TLS_TLS | TLS_LD))
5557 if ((tls_mask & TLS_LD) != 0
5559 || !h->def_dynamic))
5561 if (tls_type != (TLS_TLS | TLS_GD))
5563 if ((tls_mask & TLS_GD) != 0)
5565 if (tls_type != (TLS_TLS | TLS_DTPREL))
5567 if ((tls_mask & TLS_DTPREL) != 0)
5574 relocation = htab->got->output_offset + off;
5575 relocation -= htab->elf.hgot->root.u.def.value;
5577 /* Addends on got relocations don't make much sense.
5578 x+off@got is actually x@got+off, and since the got is
5579 generated by a hash table traversal, the value in the
5580 got at entry m+n bears little relation to the entry m. */
5582 (*_bfd_error_handler)
5583 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5586 (long) rel->r_offset,
5592 /* Relocations that need no special processing. */
5593 case R_PPC_LOCAL24PC:
5594 /* It makes no sense to point a local relocation
5595 at a symbol not in this object. */
5596 if (unresolved_reloc)
5598 if (! (*info->callbacks->undefined_symbol) (info,
5599 h->root.root.string,
5609 case R_PPC_DTPREL16:
5610 case R_PPC_DTPREL16_LO:
5611 case R_PPC_DTPREL16_HI:
5612 case R_PPC_DTPREL16_HA:
5613 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5616 /* Relocations that may need to be propagated if this is a shared
5619 case R_PPC_TPREL16_LO:
5620 case R_PPC_TPREL16_HI:
5621 case R_PPC_TPREL16_HA:
5622 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5623 /* The TPREL16 relocs shouldn't really be used in shared
5624 libs as they will result in DT_TEXTREL being set, but
5625 support them anyway. */
5629 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
5632 case R_PPC_DTPREL32:
5633 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
5636 case R_PPC_DTPMOD32:
5642 case R_PPC_REL16_LO:
5643 case R_PPC_REL16_HI:
5644 case R_PPC_REL16_HA:
5650 case R_PPC_REL14_BRTAKEN:
5651 case R_PPC_REL14_BRNTAKEN:
5652 /* If these relocations are not to a named symbol, they can be
5653 handled right here, no need to bother the dynamic linker. */
5654 if (SYMBOL_REFERENCES_LOCAL (info, h)
5655 || h == htab->elf.hgot)
5659 /* Relocations that always need to be propagated if this is a shared
5664 case R_PPC_ADDR16_LO:
5665 case R_PPC_ADDR16_HI:
5666 case R_PPC_ADDR16_HA:
5668 case R_PPC_ADDR14_BRTAKEN:
5669 case R_PPC_ADDR14_BRNTAKEN:
5672 /* r_symndx will be zero only for relocs against symbols
5673 from removed linkonce sections, or sections discarded by
5680 if ((input_section->flags & SEC_ALLOC) == 0)
5686 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5687 || h->root.type != bfd_link_hash_undefweak)
5688 && (MUST_BE_DYN_RELOC (r_type)
5689 || !SYMBOL_CALLS_LOCAL (info, h)))
5690 || (ELIMINATE_COPY_RELOCS
5696 && !h->def_regular))
5701 fprintf (stderr, "ppc_elf_relocate_section needs to "
5702 "create relocation for %s\n",
5703 (h && h->root.root.string
5704 ? h->root.root.string : "<unknown>"));
5707 /* When generating a shared object, these relocations
5708 are copied into the output file to be resolved at run
5714 name = (bfd_elf_string_from_elf_section
5716 elf_elfheader (input_bfd)->e_shstrndx,
5717 elf_section_data (input_section)->rel_hdr.sh_name));
5721 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5722 && strcmp (bfd_get_section_name (input_bfd,
5726 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
5727 BFD_ASSERT (sreloc != NULL);
5733 _bfd_elf_section_offset (output_bfd, info, input_section,
5735 if (outrel.r_offset == (bfd_vma) -1
5736 || outrel.r_offset == (bfd_vma) -2)
5737 skip = (int) outrel.r_offset;
5738 outrel.r_offset += (input_section->output_section->vma
5739 + input_section->output_offset);
5742 memset (&outrel, 0, sizeof outrel);
5743 else if (!SYMBOL_REFERENCES_LOCAL (info, h))
5745 unresolved_reloc = FALSE;
5746 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5747 outrel.r_addend = rel->r_addend;
5751 outrel.r_addend = relocation + rel->r_addend;
5753 if (r_type == R_PPC_ADDR32)
5754 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
5759 if (bfd_is_abs_section (sec))
5761 else if (sec == NULL || sec->owner == NULL)
5763 bfd_set_error (bfd_error_bad_value);
5770 /* We are turning this relocation into one
5771 against a section symbol. It would be
5772 proper to subtract the symbol's value,
5773 osec->vma, from the emitted reloc addend,
5774 but ld.so expects buggy relocs. */
5775 osec = sec->output_section;
5776 indx = elf_section_data (osec)->dynindx;
5777 BFD_ASSERT (indx > 0);
5780 printf ("indx=%d section=%s flags=%08x name=%s\n",
5781 indx, osec->name, osec->flags,
5782 h->root.root.string);
5786 outrel.r_info = ELF32_R_INFO (indx, r_type);
5790 loc = sreloc->contents;
5791 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5792 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5797 /* This reloc will be computed at runtime. We clear the memory
5798 so that it contains predictable value. */
5800 && ((input_section->flags & SEC_ALLOC) != 0
5801 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
5803 relocation = howto->pc_relative ? outrel.r_offset : 0;
5810 case R_PPC_RELAX32PC_PLT:
5811 case R_PPC_RELAX32_PLT:
5812 BFD_ASSERT (h != NULL
5813 && h->plt.offset != (bfd_vma) -1
5814 && htab->plt != NULL);
5817 relocation = (htab->glink->output_section->vma
5818 + htab->glink->output_offset
5819 + h->plt.offset * (GLINK_ENTRY_SIZE / 4));
5821 relocation = (htab->plt->output_section->vma
5822 + htab->plt->output_offset
5824 if (r_type == R_PPC_RELAX32_PLT)
5828 case R_PPC_RELAX32PC:
5829 relocation -= (input_section->output_section->vma
5830 + input_section->output_offset
5831 + rel->r_offset - 4);
5840 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
5841 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
5843 /* We're clearing the bits for R_PPC_ADDR16_HA
5844 and R_PPC_ADDR16_LO here. */
5848 /* t0 is HA, t1 is LO */
5849 relocation += addend;
5850 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
5851 t1 |= relocation & 0xffff;
5853 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
5854 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
5858 /* Indirect .sdata relocation. */
5859 case R_PPC_EMB_SDAI16:
5860 BFD_ASSERT (htab->sdata[0].section != NULL);
5862 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
5863 h, relocation, rel);
5866 /* Indirect .sdata2 relocation. */
5867 case R_PPC_EMB_SDA2I16:
5868 BFD_ASSERT (htab->sdata[1].section != NULL);
5870 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
5871 h, relocation, rel);
5874 /* Handle the TOC16 reloc. We want to use the offset within the .got
5875 section, not the actual VMA. This is appropriate when generating
5876 an embedded ELF object, for which the .got section acts like the
5877 AIX .toc section. */
5878 case R_PPC_TOC16: /* phony GOT16 relocations */
5879 BFD_ASSERT (sec != NULL);
5880 BFD_ASSERT (bfd_is_und_section (sec)
5881 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
5882 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
5884 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
5887 case R_PPC_PLTREL24:
5888 /* Relocation is to the entry for this symbol in the
5889 procedure linkage table. */
5890 BFD_ASSERT (h != NULL);
5892 if (h->plt.offset == (bfd_vma) -1
5893 || htab->plt == NULL)
5895 /* We didn't make a PLT entry for this symbol. This
5896 happens when statically linking PIC code, or when
5897 using -Bsymbolic. */
5901 unresolved_reloc = FALSE;
5903 relocation = (htab->glink->output_section->vma
5904 + htab->glink->output_offset
5905 + h->plt.offset * (GLINK_ENTRY_SIZE / 4));
5907 relocation = (htab->plt->output_section->vma
5908 + htab->plt->output_offset
5912 /* Relocate against _SDA_BASE_. */
5913 case R_PPC_SDAREL16:
5917 BFD_ASSERT (sec != NULL);
5918 name = bfd_get_section_name (abfd, sec->output_section);
5919 if (! ((strncmp (name, ".sdata", 6) == 0
5920 && (name[6] == 0 || name[6] == '.'))
5921 || (strncmp (name, ".sbss", 5) == 0
5922 && (name[5] == 0 || name[5] == '.'))))
5924 (*_bfd_error_handler)
5925 (_("%B: the target (%s) of a %s relocation is "
5926 "in the wrong output section (%s)"),
5932 addend -= htab->sdata[0].sym_val;
5936 /* Relocate against _SDA2_BASE_. */
5937 case R_PPC_EMB_SDA2REL:
5941 BFD_ASSERT (sec != NULL);
5942 name = bfd_get_section_name (abfd, sec->output_section);
5943 if (! (strncmp (name, ".sdata2", 7) == 0
5944 || strncmp (name, ".sbss2", 6) == 0))
5946 (*_bfd_error_handler)
5947 (_("%B: the target (%s) of a %s relocation is "
5948 "in the wrong output section (%s)"),
5954 bfd_set_error (bfd_error_bad_value);
5958 addend -= htab->sdata[1].sym_val;
5962 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5963 case R_PPC_EMB_SDA21:
5964 case R_PPC_EMB_RELSDA:
5969 BFD_ASSERT (sec != NULL);
5970 name = bfd_get_section_name (abfd, sec->output_section);
5971 if (((strncmp (name, ".sdata", 6) == 0
5972 && (name[6] == 0 || name[6] == '.'))
5973 || (strncmp (name, ".sbss", 5) == 0
5974 && (name[5] == 0 || name[5] == '.'))))
5977 addend -= htab->sdata[0].sym_val;
5980 else if (strncmp (name, ".sdata2", 7) == 0
5981 || strncmp (name, ".sbss2", 6) == 0)
5984 addend -= htab->sdata[1].sym_val;
5987 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
5988 || strcmp (name, ".PPC.EMB.sbss0") == 0)
5995 (*_bfd_error_handler)
5996 (_("%B: the target (%s) of a %s relocation is "
5997 "in the wrong output section (%s)"),
6003 bfd_set_error (bfd_error_bad_value);
6008 if (r_type == R_PPC_EMB_SDA21)
6009 { /* fill in register field */
6010 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
6011 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
6012 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
6017 /* Relocate against the beginning of the section. */
6019 case R_PPC_SECTOFF_LO:
6020 case R_PPC_SECTOFF_HI:
6021 case R_PPC_SECTOFF_HA:
6022 BFD_ASSERT (sec != NULL);
6023 addend -= sec->output_section->vma;
6026 /* Negative relocations. */
6027 case R_PPC_EMB_NADDR32:
6028 case R_PPC_EMB_NADDR16:
6029 case R_PPC_EMB_NADDR16_LO:
6030 case R_PPC_EMB_NADDR16_HI:
6031 case R_PPC_EMB_NADDR16_HA:
6032 addend -= 2 * relocation;
6036 case R_PPC_GLOB_DAT:
6037 case R_PPC_JMP_SLOT:
6038 case R_PPC_RELATIVE:
6040 case R_PPC_PLTREL32:
6041 case R_PPC_PLT16_LO:
6042 case R_PPC_PLT16_HI:
6043 case R_PPC_PLT16_HA:
6045 case R_PPC_EMB_RELSEC16:
6046 case R_PPC_EMB_RELST_LO:
6047 case R_PPC_EMB_RELST_HI:
6048 case R_PPC_EMB_RELST_HA:
6049 case R_PPC_EMB_BIT_FLD:
6050 (*_bfd_error_handler)
6051 (_("%B: relocation %s is not yet supported for symbol %s."),
6056 bfd_set_error (bfd_error_invalid_operation);
6061 /* Do any further special processing. */
6067 case R_PPC_ADDR16_HA:
6068 case R_PPC_REL16_HA:
6069 case R_PPC_GOT16_HA:
6070 case R_PPC_PLT16_HA:
6071 case R_PPC_SECTOFF_HA:
6072 case R_PPC_TPREL16_HA:
6073 case R_PPC_DTPREL16_HA:
6074 case R_PPC_GOT_TLSGD16_HA:
6075 case R_PPC_GOT_TLSLD16_HA:
6076 case R_PPC_GOT_TPREL16_HA:
6077 case R_PPC_GOT_DTPREL16_HA:
6078 case R_PPC_EMB_NADDR16_HA:
6079 case R_PPC_EMB_RELST_HA:
6080 /* It's just possible that this symbol is a weak symbol
6081 that's not actually defined anywhere. In that case,
6082 'sec' would be NULL, and we should leave the symbol
6083 alone (it will be set to zero elsewhere in the link). */
6085 /* Add 0x10000 if sign bit in 0:15 is set.
6086 Bits 0:15 are not used. */
6092 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
6093 "offset = %ld, addend = %ld\n",
6098 (long) rel->r_offset,
6102 if (unresolved_reloc
6103 && !((input_section->flags & SEC_DEBUGGING) != 0
6106 (*_bfd_error_handler)
6107 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6110 (long) rel->r_offset,
6116 r = _bfd_final_link_relocate (howto,
6124 if (r != bfd_reloc_ok)
6126 if (r == bfd_reloc_overflow)
6131 && h->root.type == bfd_link_hash_undefweak
6132 && howto->pc_relative)
6134 /* Assume this is a call protected by other code that
6135 detect the symbol is undefined. If this is the case,
6136 we can safely ignore the overflow. If not, the
6137 program is hosed anyway, and a little warning isn't
6143 if (! (*info->callbacks->reloc_overflow) (info,
6144 (h ? &h->root : NULL),
6155 (*_bfd_error_handler)
6156 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
6157 input_bfd, input_section,
6158 (long) rel->r_offset, howto->name, sym_name, (int) r);
6165 fprintf (stderr, "\n");
6171 /* Finish up dynamic symbol handling. We set the contents of various
6172 dynamic sections here. */
6175 ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
6176 struct bfd_link_info *info,
6177 struct elf_link_hash_entry *h,
6178 Elf_Internal_Sym *sym)
6180 struct ppc_elf_link_hash_table *htab;
6183 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
6184 h->root.root.string);
6187 htab = ppc_elf_hash_table (info);
6188 BFD_ASSERT (htab->elf.dynobj != NULL);
6190 if (h->plt.offset != (bfd_vma) -1)
6192 Elf_Internal_Rela rela;
6194 bfd_vma reloc_index;
6197 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
6200 /* This symbol has an entry in the procedure linkage table. Set
6203 BFD_ASSERT (h->dynindx != -1);
6204 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
6208 /* We don't need to fill in the .plt. The ppc dynamic linker
6213 bfd_vma val = (htab->glink_pltresolve
6215 + htab->glink->output_section->vma
6216 + htab->glink->output_offset);
6217 bfd_put_32 (output_bfd, val, htab->plt->contents + h->plt.offset);
6220 /* Fill in the entry in the .rela.plt section. */
6221 rela.r_offset = (htab->plt->output_section->vma
6222 + htab->plt->output_offset
6224 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
6228 reloc_index = h->plt.offset / 4;
6231 reloc_index = ((h->plt.offset - PLT_INITIAL_ENTRY_SIZE)
6233 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
6234 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
6236 loc = (htab->relplt->contents
6237 + reloc_index * sizeof (Elf32_External_Rela));
6238 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6240 if (!h->def_regular)
6242 /* Mark the symbol as undefined, rather than as defined in
6243 the .plt section. Leave the value alone. */
6244 sym->st_shndx = SHN_UNDEF;
6245 /* If the symbol is weak, we do need to clear the value.
6246 Otherwise, the PLT entry would provide a definition for
6247 the symbol even if the symbol wasn't defined anywhere,
6248 and so the symbol would never be NULL. */
6249 if (!h->ref_regular_nonweak)
6257 Elf_Internal_Rela rela;
6260 /* This symbols needs a copy reloc. Set it up. */
6263 fprintf (stderr, ", copy");
6266 BFD_ASSERT (h->dynindx != -1);
6268 if (h->size <= elf_gp_size (htab->elf.dynobj))
6272 BFD_ASSERT (s != NULL);
6274 rela.r_offset = (h->root.u.def.value
6275 + h->root.u.def.section->output_section->vma
6276 + h->root.u.def.section->output_offset);
6277 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
6279 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6280 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
6284 fprintf (stderr, "\n");
6287 /* Mark some specially defined symbols as absolute. */
6288 if (h == htab->elf.hgot
6289 || strcmp (h->root.root.string, "_DYNAMIC") == 0
6290 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
6291 sym->st_shndx = SHN_ABS;
6296 static enum elf_reloc_type_class
6297 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
6299 switch (ELF32_R_TYPE (rela->r_info))
6301 case R_PPC_RELATIVE:
6302 return reloc_class_relative;
6305 case R_PPC_JMP_SLOT:
6306 return reloc_class_plt;
6308 return reloc_class_copy;
6310 return reloc_class_normal;
6314 /* Finish up the dynamic sections. */
6317 ppc_elf_finish_dynamic_sections (bfd *output_bfd,
6318 struct bfd_link_info *info)
6321 struct ppc_elf_link_hash_table *htab;
6325 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
6328 htab = ppc_elf_hash_table (info);
6329 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
6332 if (htab->elf.hgot != NULL)
6333 got = (htab->elf.hgot->root.u.def.value
6334 + htab->elf.hgot->root.u.def.section->output_section->vma
6335 + htab->elf.hgot->root.u.def.section->output_offset);
6337 if (htab->elf.dynamic_sections_created)
6339 Elf32_External_Dyn *dyncon, *dynconend;
6341 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
6343 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6344 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6345 for (; dyncon < dynconend; dyncon++)
6347 Elf_Internal_Dyn dyn;
6350 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
6356 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6360 dyn.d_un.d_val = htab->relplt->size;
6365 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
6369 dyn.d_un.d_ptr = got;
6376 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6380 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
6381 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
6382 if (htab->got != NULL)
6384 unsigned char *p = htab->got->contents;
6387 p += elf_hash_table (info)->hgot->root.u.def.value;
6389 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
6393 val = sdyn->output_section->vma + sdyn->output_offset;
6394 bfd_put_32 (output_bfd, val, p);
6396 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
6399 if (htab->glink != NULL && htab->glink->contents != NULL)
6402 unsigned char *endp;
6403 bfd_vma pltgot, res0;
6405 static const unsigned int plt_resolve[] =
6419 if (ARRAY_SIZE (plt_resolve) + 2 != GLINK_PLTRESOLVE / 4)
6422 #define PPC_LO(v) ((v) & 0xffff)
6423 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6424 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6426 pltgot = htab->plt->output_section->vma + htab->plt->output_offset;
6428 /* Write the plt call stubs. */
6429 p = htab->glink->contents;
6430 endp = p + htab->glink_pltresolve;
6431 if (info->shared || info->pie)
6437 if (pltgot < 0x8000)
6439 bfd_put_32 (output_bfd, LWZ_11_X_30 + pltgot, p);
6441 bfd_put_32 (output_bfd, MTCTR_11, p);
6443 bfd_put_32 (output_bfd, BCTR, p);
6445 bfd_put_32 (output_bfd, NOP, p);
6450 bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (pltgot), p);
6452 bfd_put_32 (output_bfd, LWZ_11_X_11 + PPC_LO (pltgot), p);
6454 bfd_put_32 (output_bfd, MTCTR_11, p);
6456 bfd_put_32 (output_bfd, BCTR, p);
6465 bfd_put_32 (output_bfd, LIS_11 + PPC_HA (pltgot), p);
6467 bfd_put_32 (output_bfd, LWZ_11_X_11 + PPC_LO (pltgot), p);
6469 bfd_put_32 (output_bfd, MTCTR_11, p);
6471 bfd_put_32 (output_bfd, BCTR, p);
6476 /* Now build the branch table, one for each plt entry (less one),
6477 and perhaps some padding. */
6478 endp = htab->glink->contents;
6479 endp += htab->glink->size - GLINK_PLTRESOLVE;
6480 while (p < endp - 8 * 4)
6482 bfd_put_32 (output_bfd, B + endp - p, p);
6487 bfd_put_32 (output_bfd, NOP, p);
6491 res0 = (htab->glink_pltresolve
6492 + htab->glink->output_section->vma
6493 + htab->glink->output_offset);
6495 /* Last comes the PLTresolve stub. */
6496 if (info->shared || info->pie)
6498 bfd_put_32 (output_bfd, ADDIS_11_11 + PPC_HA (got - res0), p);
6500 bfd_put_32 (output_bfd, ADDI_11_11 + PPC_LO (got - res0), p);
6503 for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
6505 bfd_put_32 (output_bfd, plt_resolve[i], p);
6511 bfd_put_32 (output_bfd, LIS_12 + PPC_HA (got + 4), p);
6513 bfd_put_32 (output_bfd, ADDIS_11_11 + PPC_HA (-res0), p);
6515 if (PPC_HA (got + 4) != PPC_HA (got + 8))
6516 bfd_put_32 (output_bfd, LWZU_0_X_12 + PPC_LO (got + 4), p);
6518 bfd_put_32 (output_bfd, LWZ_0_X_12 + PPC_LO (got + 4), p);
6520 bfd_put_32 (output_bfd, ADDI_11_11 + PPC_LO (-res0), p);
6522 bfd_put_32 (output_bfd, MTCTR_0, p);
6524 bfd_put_32 (output_bfd, ADD_0_11_11, p);
6526 if (PPC_HA (got + 4) != PPC_HA (got + 8))
6527 bfd_put_32 (output_bfd, LWZ_12_4_12, p);
6529 bfd_put_32 (output_bfd, LWZ_12_X_12 + PPC_LO (got + 8), p);
6532 for (i = 5; i < ARRAY_SIZE (plt_resolve); i++)
6534 bfd_put_32 (output_bfd, plt_resolve[i], p);
6543 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6544 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6545 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6546 #define TARGET_BIG_NAME "elf32-powerpc"
6547 #define ELF_ARCH bfd_arch_powerpc
6548 #define ELF_MACHINE_CODE EM_PPC
6549 #ifdef __QNXTARGET__
6550 #define ELF_MAXPAGESIZE 0x1000
6552 #define ELF_MAXPAGESIZE 0x10000
6554 #define ELF_MINPAGESIZE 0x1000
6555 #define elf_info_to_howto ppc_elf_info_to_howto
6557 #ifdef EM_CYGNUS_POWERPC
6558 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6562 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6565 #define elf_backend_plt_not_loaded 1
6566 #define elf_backend_can_gc_sections 1
6567 #define elf_backend_can_refcount 1
6568 #define elf_backend_rela_normal 1
6570 #define bfd_elf32_mkobject ppc_elf_mkobject
6571 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6572 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6573 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6574 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6575 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6577 #define elf_backend_object_p ppc_elf_object_p
6578 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6579 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6580 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6581 #define elf_backend_relocate_section ppc_elf_relocate_section
6582 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6583 #define elf_backend_check_relocs ppc_elf_check_relocs
6584 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6585 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6586 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6587 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6588 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6589 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6590 #define elf_backend_fake_sections ppc_elf_fake_sections
6591 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6592 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6593 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6594 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6595 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6596 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6597 #define elf_backend_write_section ppc_elf_write_section
6598 #define elf_backend_special_sections ppc_elf_special_sections
6599 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6601 #include "elf32-target.h"