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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, 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 /* The size in bytes of an entry in the procedure linkage table. */
55 #define PLT_ENTRY_SIZE 12
56 /* The initial size of the plt reserved for the dynamic linker. */
57 #define PLT_INITIAL_ENTRY_SIZE 72
58 /* The size of the gap between entries in the PLT. */
59 #define PLT_SLOT_SIZE 8
60 /* The number of single-slot PLT entries (the rest use two slots). */
61 #define PLT_NUM_SINGLE_ENTRIES 8192
63 /* Some nop instructions. */
64 #define NOP 0x60000000
65 #define CROR_151515 0x4def7b82
66 #define CROR_313131 0x4ffffb82
68 /* Offset of tp and dtp pointers from start of TLS block. */
69 #define TP_OFFSET 0x7000
70 #define DTP_OFFSET 0x8000
72 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
74 static reloc_howto_type ppc_elf_howto_raw
[] = {
75 /* This reloc does nothing. */
76 HOWTO (R_PPC_NONE
, /* type */
78 2, /* size (0 = byte, 1 = short, 2 = long) */
80 FALSE
, /* pc_relative */
82 complain_overflow_bitfield
, /* complain_on_overflow */
83 bfd_elf_generic_reloc
, /* special_function */
84 "R_PPC_NONE", /* name */
85 FALSE
, /* partial_inplace */
88 FALSE
), /* pcrel_offset */
90 /* A standard 32 bit relocation. */
91 HOWTO (R_PPC_ADDR32
, /* type */
93 2, /* size (0 = byte, 1 = short, 2 = long) */
95 FALSE
, /* pc_relative */
97 complain_overflow_bitfield
, /* complain_on_overflow */
98 bfd_elf_generic_reloc
, /* special_function */
99 "R_PPC_ADDR32", /* name */
100 FALSE
, /* partial_inplace */
102 0xffffffff, /* dst_mask */
103 FALSE
), /* pcrel_offset */
105 /* An absolute 26 bit branch; the lower two bits must be zero.
106 FIXME: we don't check that, we just clear them. */
107 HOWTO (R_PPC_ADDR24
, /* type */
109 2, /* size (0 = byte, 1 = short, 2 = long) */
111 FALSE
, /* pc_relative */
113 complain_overflow_bitfield
, /* complain_on_overflow */
114 bfd_elf_generic_reloc
, /* special_function */
115 "R_PPC_ADDR24", /* name */
116 FALSE
, /* partial_inplace */
118 0x3fffffc, /* dst_mask */
119 FALSE
), /* pcrel_offset */
121 /* A standard 16 bit relocation. */
122 HOWTO (R_PPC_ADDR16
, /* type */
124 1, /* size (0 = byte, 1 = short, 2 = long) */
126 FALSE
, /* pc_relative */
128 complain_overflow_bitfield
, /* complain_on_overflow */
129 bfd_elf_generic_reloc
, /* special_function */
130 "R_PPC_ADDR16", /* name */
131 FALSE
, /* partial_inplace */
133 0xffff, /* dst_mask */
134 FALSE
), /* pcrel_offset */
136 /* A 16 bit relocation without overflow. */
137 HOWTO (R_PPC_ADDR16_LO
, /* type */
139 1, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE
, /* pc_relative */
143 complain_overflow_dont
,/* complain_on_overflow */
144 bfd_elf_generic_reloc
, /* special_function */
145 "R_PPC_ADDR16_LO", /* name */
146 FALSE
, /* partial_inplace */
148 0xffff, /* dst_mask */
149 FALSE
), /* pcrel_offset */
151 /* The high order 16 bits of an address. */
152 HOWTO (R_PPC_ADDR16_HI
, /* type */
154 1, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_dont
, /* complain_on_overflow */
159 bfd_elf_generic_reloc
, /* special_function */
160 "R_PPC_ADDR16_HI", /* name */
161 FALSE
, /* partial_inplace */
163 0xffff, /* dst_mask */
164 FALSE
), /* pcrel_offset */
166 /* The high order 16 bits of an address, plus 1 if the contents of
167 the low 16 bits, treated as a signed number, is negative. */
168 HOWTO (R_PPC_ADDR16_HA
, /* type */
170 1, /* size (0 = byte, 1 = short, 2 = long) */
172 FALSE
, /* pc_relative */
174 complain_overflow_dont
, /* complain_on_overflow */
175 ppc_elf_addr16_ha_reloc
, /* special_function */
176 "R_PPC_ADDR16_HA", /* name */
177 FALSE
, /* partial_inplace */
179 0xffff, /* dst_mask */
180 FALSE
), /* pcrel_offset */
182 /* An absolute 16 bit branch; the lower two bits must be zero.
183 FIXME: we don't check that, we just clear them. */
184 HOWTO (R_PPC_ADDR14
, /* type */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
188 FALSE
, /* pc_relative */
190 complain_overflow_bitfield
, /* complain_on_overflow */
191 bfd_elf_generic_reloc
, /* special_function */
192 "R_PPC_ADDR14", /* name */
193 FALSE
, /* partial_inplace */
195 0xfffc, /* dst_mask */
196 FALSE
), /* pcrel_offset */
198 /* An absolute 16 bit branch, for which bit 10 should be set to
199 indicate that the branch is expected to be taken. The lower two
200 bits must be zero. */
201 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
205 FALSE
, /* pc_relative */
207 complain_overflow_bitfield
, /* complain_on_overflow */
208 bfd_elf_generic_reloc
, /* special_function */
209 "R_PPC_ADDR14_BRTAKEN",/* name */
210 FALSE
, /* partial_inplace */
212 0xfffc, /* dst_mask */
213 FALSE
), /* pcrel_offset */
215 /* An absolute 16 bit branch, for which bit 10 should be set to
216 indicate that the branch is not expected to be taken. The lower
217 two bits must be zero. */
218 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 FALSE
, /* pc_relative */
224 complain_overflow_bitfield
, /* complain_on_overflow */
225 bfd_elf_generic_reloc
, /* special_function */
226 "R_PPC_ADDR14_BRNTAKEN",/* name */
227 FALSE
, /* partial_inplace */
229 0xfffc, /* dst_mask */
230 FALSE
), /* pcrel_offset */
232 /* A relative 26 bit branch; the lower two bits must be zero. */
233 HOWTO (R_PPC_REL24
, /* type */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 TRUE
, /* pc_relative */
239 complain_overflow_signed
, /* complain_on_overflow */
240 bfd_elf_generic_reloc
, /* special_function */
241 "R_PPC_REL24", /* name */
242 FALSE
, /* partial_inplace */
244 0x3fffffc, /* dst_mask */
245 TRUE
), /* pcrel_offset */
247 /* A relative 16 bit branch; the lower two bits must be zero. */
248 HOWTO (R_PPC_REL14
, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 TRUE
, /* pc_relative */
254 complain_overflow_signed
, /* complain_on_overflow */
255 bfd_elf_generic_reloc
, /* special_function */
256 "R_PPC_REL14", /* name */
257 FALSE
, /* partial_inplace */
259 0xfffc, /* dst_mask */
260 TRUE
), /* pcrel_offset */
262 /* A relative 16 bit branch. Bit 10 should be set to indicate that
263 the branch is expected to be taken. The lower two bits must be
265 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
269 TRUE
, /* pc_relative */
271 complain_overflow_signed
, /* complain_on_overflow */
272 bfd_elf_generic_reloc
, /* special_function */
273 "R_PPC_REL14_BRTAKEN", /* name */
274 FALSE
, /* partial_inplace */
276 0xfffc, /* dst_mask */
277 TRUE
), /* pcrel_offset */
279 /* A relative 16 bit branch. Bit 10 should be set to indicate that
280 the branch is not expected to be taken. The lower two bits must
282 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 TRUE
, /* pc_relative */
288 complain_overflow_signed
, /* complain_on_overflow */
289 bfd_elf_generic_reloc
, /* special_function */
290 "R_PPC_REL14_BRNTAKEN",/* name */
291 FALSE
, /* partial_inplace */
293 0xfffc, /* dst_mask */
294 TRUE
), /* pcrel_offset */
296 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
298 HOWTO (R_PPC_GOT16
, /* type */
300 1, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE
, /* pc_relative */
304 complain_overflow_signed
, /* complain_on_overflow */
305 bfd_elf_generic_reloc
, /* special_function */
306 "R_PPC_GOT16", /* name */
307 FALSE
, /* partial_inplace */
309 0xffff, /* dst_mask */
310 FALSE
), /* pcrel_offset */
312 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
314 HOWTO (R_PPC_GOT16_LO
, /* type */
316 1, /* size (0 = byte, 1 = short, 2 = long) */
318 FALSE
, /* pc_relative */
320 complain_overflow_dont
, /* complain_on_overflow */
321 bfd_elf_generic_reloc
, /* special_function */
322 "R_PPC_GOT16_LO", /* name */
323 FALSE
, /* partial_inplace */
325 0xffff, /* dst_mask */
326 FALSE
), /* pcrel_offset */
328 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
330 HOWTO (R_PPC_GOT16_HI
, /* type */
332 1, /* size (0 = byte, 1 = short, 2 = long) */
334 FALSE
, /* pc_relative */
336 complain_overflow_bitfield
, /* complain_on_overflow */
337 bfd_elf_generic_reloc
, /* special_function */
338 "R_PPC_GOT16_HI", /* name */
339 FALSE
, /* partial_inplace */
341 0xffff, /* dst_mask */
342 FALSE
), /* pcrel_offset */
344 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
346 HOWTO (R_PPC_GOT16_HA
, /* type */
348 1, /* size (0 = byte, 1 = short, 2 = long) */
350 FALSE
, /* pc_relative */
352 complain_overflow_bitfield
, /* complain_on_overflow */
353 ppc_elf_addr16_ha_reloc
, /* special_function */
354 "R_PPC_GOT16_HA", /* name */
355 FALSE
, /* partial_inplace */
357 0xffff, /* dst_mask */
358 FALSE
), /* pcrel_offset */
360 /* Like R_PPC_REL24, but referring to the procedure linkage table
361 entry for the symbol. */
362 HOWTO (R_PPC_PLTREL24
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 TRUE
, /* pc_relative */
368 complain_overflow_signed
, /* complain_on_overflow */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_PPC_PLTREL24", /* name */
371 FALSE
, /* partial_inplace */
373 0x3fffffc, /* dst_mask */
374 TRUE
), /* pcrel_offset */
376 /* This is used only by the dynamic linker. The symbol should exist
377 both in the object being run and in some shared library. The
378 dynamic linker copies the data addressed by the symbol from the
379 shared library into the object, because the object being
380 run has to have the data at some particular address. */
381 HOWTO (R_PPC_COPY
, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 FALSE
, /* pc_relative */
387 complain_overflow_bitfield
, /* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 "R_PPC_COPY", /* name */
390 FALSE
, /* partial_inplace */
393 FALSE
), /* pcrel_offset */
395 /* Like R_PPC_ADDR32, but used when setting global offset table
397 HOWTO (R_PPC_GLOB_DAT
, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 FALSE
, /* pc_relative */
403 complain_overflow_bitfield
, /* complain_on_overflow */
404 bfd_elf_generic_reloc
, /* special_function */
405 "R_PPC_GLOB_DAT", /* name */
406 FALSE
, /* partial_inplace */
408 0xffffffff, /* dst_mask */
409 FALSE
), /* pcrel_offset */
411 /* Marks a procedure linkage table entry for a symbol. */
412 HOWTO (R_PPC_JMP_SLOT
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE
, /* pc_relative */
418 complain_overflow_bitfield
, /* complain_on_overflow */
419 bfd_elf_generic_reloc
, /* special_function */
420 "R_PPC_JMP_SLOT", /* name */
421 FALSE
, /* partial_inplace */
424 FALSE
), /* pcrel_offset */
426 /* Used only by the dynamic linker. When the object is run, this
427 longword is set to the load address of the object, plus the
429 HOWTO (R_PPC_RELATIVE
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 FALSE
, /* pc_relative */
435 complain_overflow_bitfield
, /* complain_on_overflow */
436 bfd_elf_generic_reloc
, /* special_function */
437 "R_PPC_RELATIVE", /* name */
438 FALSE
, /* partial_inplace */
440 0xffffffff, /* dst_mask */
441 FALSE
), /* pcrel_offset */
443 /* Like R_PPC_REL24, but uses the value of the symbol within the
444 object rather than the final value. Normally used for
445 _GLOBAL_OFFSET_TABLE_. */
446 HOWTO (R_PPC_LOCAL24PC
, /* type */
448 2, /* size (0 = byte, 1 = short, 2 = long) */
450 TRUE
, /* pc_relative */
452 complain_overflow_signed
, /* complain_on_overflow */
453 bfd_elf_generic_reloc
, /* special_function */
454 "R_PPC_LOCAL24PC", /* name */
455 FALSE
, /* partial_inplace */
457 0x3fffffc, /* dst_mask */
458 TRUE
), /* pcrel_offset */
460 /* Like R_PPC_ADDR32, but may be unaligned. */
461 HOWTO (R_PPC_UADDR32
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE
, /* pc_relative */
467 complain_overflow_bitfield
, /* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_PPC_UADDR32", /* name */
470 FALSE
, /* partial_inplace */
472 0xffffffff, /* dst_mask */
473 FALSE
), /* pcrel_offset */
475 /* Like R_PPC_ADDR16, but may be unaligned. */
476 HOWTO (R_PPC_UADDR16
, /* type */
478 1, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE
, /* pc_relative */
482 complain_overflow_bitfield
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_PPC_UADDR16", /* name */
485 FALSE
, /* partial_inplace */
487 0xffff, /* dst_mask */
488 FALSE
), /* pcrel_offset */
490 /* 32-bit PC relative */
491 HOWTO (R_PPC_REL32
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 TRUE
, /* pc_relative */
497 complain_overflow_bitfield
, /* complain_on_overflow */
498 bfd_elf_generic_reloc
, /* special_function */
499 "R_PPC_REL32", /* name */
500 FALSE
, /* partial_inplace */
502 0xffffffff, /* dst_mask */
503 TRUE
), /* pcrel_offset */
505 /* 32-bit relocation to the symbol's procedure linkage table.
506 FIXME: not supported. */
507 HOWTO (R_PPC_PLT32
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 FALSE
, /* pc_relative */
513 complain_overflow_bitfield
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_PPC_PLT32", /* name */
516 FALSE
, /* partial_inplace */
519 FALSE
), /* pcrel_offset */
521 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
522 FIXME: not supported. */
523 HOWTO (R_PPC_PLTREL32
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 TRUE
, /* pc_relative */
529 complain_overflow_bitfield
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_PPC_PLTREL32", /* name */
532 FALSE
, /* partial_inplace */
535 TRUE
), /* pcrel_offset */
537 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
539 HOWTO (R_PPC_PLT16_LO
, /* type */
541 1, /* size (0 = byte, 1 = short, 2 = long) */
543 FALSE
, /* pc_relative */
545 complain_overflow_dont
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_PPC_PLT16_LO", /* name */
548 FALSE
, /* partial_inplace */
550 0xffff, /* dst_mask */
551 FALSE
), /* pcrel_offset */
553 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
555 HOWTO (R_PPC_PLT16_HI
, /* type */
557 1, /* size (0 = byte, 1 = short, 2 = long) */
559 FALSE
, /* pc_relative */
561 complain_overflow_bitfield
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_PPC_PLT16_HI", /* name */
564 FALSE
, /* partial_inplace */
566 0xffff, /* dst_mask */
567 FALSE
), /* pcrel_offset */
569 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
571 HOWTO (R_PPC_PLT16_HA
, /* type */
573 1, /* size (0 = byte, 1 = short, 2 = long) */
575 FALSE
, /* pc_relative */
577 complain_overflow_bitfield
, /* complain_on_overflow */
578 ppc_elf_addr16_ha_reloc
, /* special_function */
579 "R_PPC_PLT16_HA", /* name */
580 FALSE
, /* partial_inplace */
582 0xffff, /* dst_mask */
583 FALSE
), /* pcrel_offset */
585 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
587 HOWTO (R_PPC_SDAREL16
, /* type */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
591 FALSE
, /* pc_relative */
593 complain_overflow_signed
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_PPC_SDAREL16", /* name */
596 FALSE
, /* partial_inplace */
598 0xffff, /* dst_mask */
599 FALSE
), /* pcrel_offset */
601 /* 16-bit section relative relocation. */
602 HOWTO (R_PPC_SECTOFF
, /* type */
604 1, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE
, /* pc_relative */
608 complain_overflow_bitfield
, /* complain_on_overflow */
609 bfd_elf_generic_reloc
, /* special_function */
610 "R_PPC_SECTOFF", /* name */
611 FALSE
, /* partial_inplace */
613 0xffff, /* dst_mask */
614 FALSE
), /* pcrel_offset */
616 /* 16-bit lower half section relative relocation. */
617 HOWTO (R_PPC_SECTOFF_LO
, /* type */
619 1, /* size (0 = byte, 1 = short, 2 = long) */
621 FALSE
, /* pc_relative */
623 complain_overflow_dont
, /* complain_on_overflow */
624 bfd_elf_generic_reloc
, /* special_function */
625 "R_PPC_SECTOFF_LO", /* name */
626 FALSE
, /* partial_inplace */
628 0xffff, /* dst_mask */
629 FALSE
), /* pcrel_offset */
631 /* 16-bit upper half section relative relocation. */
632 HOWTO (R_PPC_SECTOFF_HI
, /* type */
634 1, /* size (0 = byte, 1 = short, 2 = long) */
636 FALSE
, /* pc_relative */
638 complain_overflow_bitfield
, /* complain_on_overflow */
639 bfd_elf_generic_reloc
, /* special_function */
640 "R_PPC_SECTOFF_HI", /* name */
641 FALSE
, /* partial_inplace */
643 0xffff, /* dst_mask */
644 FALSE
), /* pcrel_offset */
646 /* 16-bit upper half adjusted section relative relocation. */
647 HOWTO (R_PPC_SECTOFF_HA
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 FALSE
, /* pc_relative */
653 complain_overflow_bitfield
, /* complain_on_overflow */
654 ppc_elf_addr16_ha_reloc
, /* special_function */
655 "R_PPC_SECTOFF_HA", /* name */
656 FALSE
, /* partial_inplace */
658 0xffff, /* dst_mask */
659 FALSE
), /* pcrel_offset */
661 /* Marker reloc for TLS. */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 FALSE
, /* pc_relative */
668 complain_overflow_dont
, /* complain_on_overflow */
669 bfd_elf_generic_reloc
, /* special_function */
670 "R_PPC_TLS", /* name */
671 FALSE
, /* partial_inplace */
674 FALSE
), /* pcrel_offset */
676 /* Computes the load module index of the load module that contains the
677 definition of its TLS sym. */
678 HOWTO (R_PPC_DTPMOD32
,
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE
, /* pc_relative */
684 complain_overflow_dont
, /* complain_on_overflow */
685 ppc_elf_unhandled_reloc
, /* special_function */
686 "R_PPC_DTPMOD32", /* name */
687 FALSE
, /* partial_inplace */
689 0xffffffff, /* dst_mask */
690 FALSE
), /* pcrel_offset */
692 /* Computes a dtv-relative displacement, the difference between the value
693 of sym+add and the base address of the thread-local storage block that
694 contains the definition of sym, minus 0x8000. */
695 HOWTO (R_PPC_DTPREL32
,
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE
, /* pc_relative */
701 complain_overflow_dont
, /* complain_on_overflow */
702 ppc_elf_unhandled_reloc
, /* special_function */
703 "R_PPC_DTPREL32", /* name */
704 FALSE
, /* partial_inplace */
706 0xffffffff, /* dst_mask */
707 FALSE
), /* pcrel_offset */
709 /* A 16 bit dtprel reloc. */
710 HOWTO (R_PPC_DTPREL16
,
712 1, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE
, /* pc_relative */
716 complain_overflow_signed
, /* complain_on_overflow */
717 ppc_elf_unhandled_reloc
, /* special_function */
718 "R_PPC_DTPREL16", /* name */
719 FALSE
, /* partial_inplace */
721 0xffff, /* dst_mask */
722 FALSE
), /* pcrel_offset */
724 /* Like DTPREL16, but no overflow. */
725 HOWTO (R_PPC_DTPREL16_LO
,
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_dont
, /* complain_on_overflow */
732 ppc_elf_unhandled_reloc
, /* special_function */
733 "R_PPC_DTPREL16_LO", /* name */
734 FALSE
, /* partial_inplace */
736 0xffff, /* dst_mask */
737 FALSE
), /* pcrel_offset */
739 /* Like DTPREL16_LO, but next higher group of 16 bits. */
740 HOWTO (R_PPC_DTPREL16_HI
,
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_dont
, /* complain_on_overflow */
747 ppc_elf_unhandled_reloc
, /* special_function */
748 "R_PPC_DTPREL16_HI", /* name */
749 FALSE
, /* partial_inplace */
751 0xffff, /* dst_mask */
752 FALSE
), /* pcrel_offset */
754 /* Like DTPREL16_HI, but adjust for low 16 bits. */
755 HOWTO (R_PPC_DTPREL16_HA
,
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_dont
, /* complain_on_overflow */
762 ppc_elf_unhandled_reloc
, /* special_function */
763 "R_PPC_DTPREL16_HA", /* name */
764 FALSE
, /* partial_inplace */
766 0xffff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 /* Computes a tp-relative displacement, the difference between the value of
770 sym+add and the value of the thread pointer (r13). */
771 HOWTO (R_PPC_TPREL32
,
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE
, /* pc_relative */
777 complain_overflow_dont
, /* complain_on_overflow */
778 ppc_elf_unhandled_reloc
, /* special_function */
779 "R_PPC_TPREL32", /* name */
780 FALSE
, /* partial_inplace */
782 0xffffffff, /* dst_mask */
783 FALSE
), /* pcrel_offset */
785 /* A 16 bit tprel reloc. */
786 HOWTO (R_PPC_TPREL16
,
788 1, /* size (0 = byte, 1 = short, 2 = long) */
790 FALSE
, /* pc_relative */
792 complain_overflow_signed
, /* complain_on_overflow */
793 ppc_elf_unhandled_reloc
, /* special_function */
794 "R_PPC_TPREL16", /* name */
795 FALSE
, /* partial_inplace */
797 0xffff, /* dst_mask */
798 FALSE
), /* pcrel_offset */
800 /* Like TPREL16, but no overflow. */
801 HOWTO (R_PPC_TPREL16_LO
,
803 1, /* size (0 = byte, 1 = short, 2 = long) */
805 FALSE
, /* pc_relative */
807 complain_overflow_dont
, /* complain_on_overflow */
808 ppc_elf_unhandled_reloc
, /* special_function */
809 "R_PPC_TPREL16_LO", /* name */
810 FALSE
, /* partial_inplace */
812 0xffff, /* dst_mask */
813 FALSE
), /* pcrel_offset */
815 /* Like TPREL16_LO, but next higher group of 16 bits. */
816 HOWTO (R_PPC_TPREL16_HI
,
818 1, /* size (0 = byte, 1 = short, 2 = long) */
820 FALSE
, /* pc_relative */
822 complain_overflow_dont
, /* complain_on_overflow */
823 ppc_elf_unhandled_reloc
, /* special_function */
824 "R_PPC_TPREL16_HI", /* name */
825 FALSE
, /* partial_inplace */
827 0xffff, /* dst_mask */
828 FALSE
), /* pcrel_offset */
830 /* Like TPREL16_HI, but adjust for low 16 bits. */
831 HOWTO (R_PPC_TPREL16_HA
,
833 1, /* size (0 = byte, 1 = short, 2 = long) */
835 FALSE
, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 ppc_elf_unhandled_reloc
, /* special_function */
839 "R_PPC_TPREL16_HA", /* name */
840 FALSE
, /* partial_inplace */
842 0xffff, /* dst_mask */
843 FALSE
), /* pcrel_offset */
845 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
846 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
847 to the first entry. */
848 HOWTO (R_PPC_GOT_TLSGD16
,
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 FALSE
, /* pc_relative */
854 complain_overflow_signed
, /* complain_on_overflow */
855 ppc_elf_unhandled_reloc
, /* special_function */
856 "R_PPC_GOT_TLSGD16", /* name */
857 FALSE
, /* partial_inplace */
859 0xffff, /* dst_mask */
860 FALSE
), /* pcrel_offset */
862 /* Like GOT_TLSGD16, but no overflow. */
863 HOWTO (R_PPC_GOT_TLSGD16_LO
,
865 1, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_dont
, /* complain_on_overflow */
870 ppc_elf_unhandled_reloc
, /* special_function */
871 "R_PPC_GOT_TLSGD16_LO", /* name */
872 FALSE
, /* partial_inplace */
874 0xffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
878 HOWTO (R_PPC_GOT_TLSGD16_HI
,
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE
, /* pc_relative */
884 complain_overflow_dont
, /* complain_on_overflow */
885 ppc_elf_unhandled_reloc
, /* special_function */
886 "R_PPC_GOT_TLSGD16_HI", /* name */
887 FALSE
, /* partial_inplace */
889 0xffff, /* dst_mask */
890 FALSE
), /* pcrel_offset */
892 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
893 HOWTO (R_PPC_GOT_TLSGD16_HA
,
895 1, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE
, /* pc_relative */
899 complain_overflow_dont
, /* complain_on_overflow */
900 ppc_elf_unhandled_reloc
, /* special_function */
901 "R_PPC_GOT_TLSGD16_HA", /* name */
902 FALSE
, /* partial_inplace */
904 0xffff, /* dst_mask */
905 FALSE
), /* pcrel_offset */
907 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
908 with values (sym+add)@dtpmod and zero, and computes the offset to the
910 HOWTO (R_PPC_GOT_TLSLD16
,
912 1, /* size (0 = byte, 1 = short, 2 = long) */
914 FALSE
, /* pc_relative */
916 complain_overflow_signed
, /* complain_on_overflow */
917 ppc_elf_unhandled_reloc
, /* special_function */
918 "R_PPC_GOT_TLSLD16", /* name */
919 FALSE
, /* partial_inplace */
921 0xffff, /* dst_mask */
922 FALSE
), /* pcrel_offset */
924 /* Like GOT_TLSLD16, but no overflow. */
925 HOWTO (R_PPC_GOT_TLSLD16_LO
,
927 1, /* size (0 = byte, 1 = short, 2 = long) */
929 FALSE
, /* pc_relative */
931 complain_overflow_dont
, /* complain_on_overflow */
932 ppc_elf_unhandled_reloc
, /* special_function */
933 "R_PPC_GOT_TLSLD16_LO", /* name */
934 FALSE
, /* partial_inplace */
936 0xffff, /* dst_mask */
937 FALSE
), /* pcrel_offset */
939 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
940 HOWTO (R_PPC_GOT_TLSLD16_HI
,
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE
, /* pc_relative */
946 complain_overflow_dont
, /* complain_on_overflow */
947 ppc_elf_unhandled_reloc
, /* special_function */
948 "R_PPC_GOT_TLSLD16_HI", /* name */
949 FALSE
, /* partial_inplace */
951 0xffff, /* dst_mask */
952 FALSE
), /* pcrel_offset */
954 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
955 HOWTO (R_PPC_GOT_TLSLD16_HA
,
957 1, /* size (0 = byte, 1 = short, 2 = long) */
959 FALSE
, /* pc_relative */
961 complain_overflow_dont
, /* complain_on_overflow */
962 ppc_elf_unhandled_reloc
, /* special_function */
963 "R_PPC_GOT_TLSLD16_HA", /* name */
964 FALSE
, /* partial_inplace */
966 0xffff, /* dst_mask */
967 FALSE
), /* pcrel_offset */
969 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
970 the offset to the entry. */
971 HOWTO (R_PPC_GOT_DTPREL16
,
973 1, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_signed
, /* complain_on_overflow */
978 ppc_elf_unhandled_reloc
, /* special_function */
979 "R_PPC_GOT_DTPREL16", /* name */
980 FALSE
, /* partial_inplace */
982 0xffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 /* Like GOT_DTPREL16, but no overflow. */
986 HOWTO (R_PPC_GOT_DTPREL16_LO
,
988 1, /* size (0 = byte, 1 = short, 2 = long) */
990 FALSE
, /* pc_relative */
992 complain_overflow_dont
, /* complain_on_overflow */
993 ppc_elf_unhandled_reloc
, /* special_function */
994 "R_PPC_GOT_DTPREL16_LO", /* name */
995 FALSE
, /* partial_inplace */
997 0xffff, /* dst_mask */
998 FALSE
), /* pcrel_offset */
1000 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1001 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1002 16, /* rightshift */
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_dont
, /* complain_on_overflow */
1008 ppc_elf_unhandled_reloc
, /* special_function */
1009 "R_PPC_GOT_DTPREL16_HI", /* name */
1010 FALSE
, /* partial_inplace */
1012 0xffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1016 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1017 16, /* rightshift */
1018 1, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE
, /* pc_relative */
1022 complain_overflow_dont
, /* complain_on_overflow */
1023 ppc_elf_unhandled_reloc
, /* special_function */
1024 "R_PPC_GOT_DTPREL16_HA", /* name */
1025 FALSE
, /* partial_inplace */
1027 0xffff, /* dst_mask */
1028 FALSE
), /* pcrel_offset */
1030 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1031 offset to the entry. */
1032 HOWTO (R_PPC_GOT_TPREL16
,
1034 1, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE
, /* pc_relative */
1038 complain_overflow_signed
, /* complain_on_overflow */
1039 ppc_elf_unhandled_reloc
, /* special_function */
1040 "R_PPC_GOT_TPREL16", /* name */
1041 FALSE
, /* partial_inplace */
1043 0xffff, /* dst_mask */
1044 FALSE
), /* pcrel_offset */
1046 /* Like GOT_TPREL16, but no overflow. */
1047 HOWTO (R_PPC_GOT_TPREL16_LO
,
1049 1, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE
, /* pc_relative */
1053 complain_overflow_dont
, /* complain_on_overflow */
1054 ppc_elf_unhandled_reloc
, /* special_function */
1055 "R_PPC_GOT_TPREL16_LO", /* name */
1056 FALSE
, /* partial_inplace */
1058 0xffff, /* dst_mask */
1059 FALSE
), /* pcrel_offset */
1061 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1062 HOWTO (R_PPC_GOT_TPREL16_HI
,
1063 16, /* rightshift */
1064 1, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE
, /* pc_relative */
1068 complain_overflow_dont
, /* complain_on_overflow */
1069 ppc_elf_unhandled_reloc
, /* special_function */
1070 "R_PPC_GOT_TPREL16_HI", /* name */
1071 FALSE
, /* partial_inplace */
1073 0xffff, /* dst_mask */
1074 FALSE
), /* pcrel_offset */
1076 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1077 HOWTO (R_PPC_GOT_TPREL16_HA
,
1078 16, /* rightshift */
1079 1, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE
, /* pc_relative */
1083 complain_overflow_dont
, /* complain_on_overflow */
1084 ppc_elf_unhandled_reloc
, /* special_function */
1085 "R_PPC_GOT_TPREL16_HA", /* name */
1086 FALSE
, /* partial_inplace */
1088 0xffff, /* dst_mask */
1089 FALSE
), /* pcrel_offset */
1091 /* The remaining relocs are from the Embedded ELF ABI, and are not
1092 in the SVR4 ELF ABI. */
1094 /* 32 bit value resulting from the addend minus the symbol. */
1095 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1097 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 FALSE
, /* pc_relative */
1101 complain_overflow_bitfield
, /* complain_on_overflow */
1102 bfd_elf_generic_reloc
, /* special_function */
1103 "R_PPC_EMB_NADDR32", /* name */
1104 FALSE
, /* partial_inplace */
1106 0xffffffff, /* dst_mask */
1107 FALSE
), /* pcrel_offset */
1109 /* 16 bit value resulting from the addend minus the symbol. */
1110 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1112 1, /* size (0 = byte, 1 = short, 2 = long) */
1114 FALSE
, /* pc_relative */
1116 complain_overflow_bitfield
, /* complain_on_overflow */
1117 bfd_elf_generic_reloc
, /* special_function */
1118 "R_PPC_EMB_NADDR16", /* name */
1119 FALSE
, /* partial_inplace */
1121 0xffff, /* dst_mask */
1122 FALSE
), /* pcrel_offset */
1124 /* 16 bit value resulting from the addend minus the symbol. */
1125 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1127 1, /* size (0 = byte, 1 = short, 2 = long) */
1129 FALSE
, /* pc_relative */
1131 complain_overflow_dont
,/* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 "R_PPC_EMB_ADDR16_LO", /* name */
1134 FALSE
, /* partial_inplace */
1136 0xffff, /* dst_mask */
1137 FALSE
), /* pcrel_offset */
1139 /* The high order 16 bits of the addend minus the symbol. */
1140 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1141 16, /* rightshift */
1142 1, /* size (0 = byte, 1 = short, 2 = long) */
1144 FALSE
, /* pc_relative */
1146 complain_overflow_dont
, /* complain_on_overflow */
1147 bfd_elf_generic_reloc
, /* special_function */
1148 "R_PPC_EMB_NADDR16_HI", /* name */
1149 FALSE
, /* partial_inplace */
1151 0xffff, /* dst_mask */
1152 FALSE
), /* pcrel_offset */
1154 /* The high order 16 bits of the result of the addend minus the address,
1155 plus 1 if the contents of the low 16 bits, treated as a signed number,
1157 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1158 16, /* rightshift */
1159 1, /* size (0 = byte, 1 = short, 2 = long) */
1161 FALSE
, /* pc_relative */
1163 complain_overflow_dont
, /* complain_on_overflow */
1164 ppc_elf_addr16_ha_reloc
, /* special_function */
1165 "R_PPC_EMB_NADDR16_HA", /* name */
1166 FALSE
, /* partial_inplace */
1168 0xffff, /* dst_mask */
1169 FALSE
), /* pcrel_offset */
1171 /* 16 bit value resulting from allocating a 4 byte word to hold an
1172 address in the .sdata section, and returning the offset from
1173 _SDA_BASE_ for that relocation. */
1174 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1176 1, /* size (0 = byte, 1 = short, 2 = long) */
1178 FALSE
, /* pc_relative */
1180 complain_overflow_bitfield
, /* complain_on_overflow */
1181 bfd_elf_generic_reloc
, /* special_function */
1182 "R_PPC_EMB_SDAI16", /* name */
1183 FALSE
, /* partial_inplace */
1185 0xffff, /* dst_mask */
1186 FALSE
), /* pcrel_offset */
1188 /* 16 bit value resulting from allocating a 4 byte word to hold an
1189 address in the .sdata2 section, and returning the offset from
1190 _SDA2_BASE_ for that relocation. */
1191 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1193 1, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE
, /* pc_relative */
1197 complain_overflow_bitfield
, /* complain_on_overflow */
1198 bfd_elf_generic_reloc
, /* special_function */
1199 "R_PPC_EMB_SDA2I16", /* name */
1200 FALSE
, /* partial_inplace */
1202 0xffff, /* dst_mask */
1203 FALSE
), /* pcrel_offset */
1205 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1206 small data items. */
1207 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1209 1, /* size (0 = byte, 1 = short, 2 = long) */
1211 FALSE
, /* pc_relative */
1213 complain_overflow_signed
, /* complain_on_overflow */
1214 bfd_elf_generic_reloc
, /* special_function */
1215 "R_PPC_EMB_SDA2REL", /* name */
1216 FALSE
, /* partial_inplace */
1218 0xffff, /* dst_mask */
1219 FALSE
), /* pcrel_offset */
1221 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1222 signed offset from the appropriate base, and filling in the register
1223 field with the appropriate register (0, 2, or 13). */
1224 HOWTO (R_PPC_EMB_SDA21
, /* type */
1226 2, /* size (0 = byte, 1 = short, 2 = long) */
1228 FALSE
, /* pc_relative */
1230 complain_overflow_signed
, /* complain_on_overflow */
1231 bfd_elf_generic_reloc
, /* special_function */
1232 "R_PPC_EMB_SDA21", /* name */
1233 FALSE
, /* partial_inplace */
1235 0xffff, /* dst_mask */
1236 FALSE
), /* pcrel_offset */
1238 /* Relocation not handled: R_PPC_EMB_MRKREF */
1239 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1240 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1241 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1242 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1243 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1245 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1246 in the 16 bit signed offset from the appropriate base, and filling in the
1247 register field with the appropriate register (0, 2, or 13). */
1248 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1250 1, /* size (0 = byte, 1 = short, 2 = long) */
1252 TRUE
, /* pc_relative */
1254 complain_overflow_signed
, /* complain_on_overflow */
1255 bfd_elf_generic_reloc
, /* special_function */
1256 "R_PPC_EMB_RELSDA", /* name */
1257 FALSE
, /* partial_inplace */
1259 0xffff, /* dst_mask */
1260 FALSE
), /* pcrel_offset */
1262 /* GNU extension to record C++ vtable hierarchy. */
1263 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1265 0, /* size (0 = byte, 1 = short, 2 = long) */
1267 FALSE
, /* pc_relative */
1269 complain_overflow_dont
, /* complain_on_overflow */
1270 NULL
, /* special_function */
1271 "R_PPC_GNU_VTINHERIT", /* name */
1272 FALSE
, /* partial_inplace */
1275 FALSE
), /* pcrel_offset */
1277 /* GNU extension to record C++ vtable member usage. */
1278 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1280 0, /* size (0 = byte, 1 = short, 2 = long) */
1282 FALSE
, /* pc_relative */
1284 complain_overflow_dont
, /* complain_on_overflow */
1285 NULL
, /* special_function */
1286 "R_PPC_GNU_VTENTRY", /* name */
1287 FALSE
, /* partial_inplace */
1290 FALSE
), /* pcrel_offset */
1292 /* Phony reloc to handle AIX style TOC entries. */
1293 HOWTO (R_PPC_TOC16
, /* type */
1295 1, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE
, /* pc_relative */
1299 complain_overflow_signed
, /* complain_on_overflow */
1300 bfd_elf_generic_reloc
, /* special_function */
1301 "R_PPC_TOC16", /* name */
1302 FALSE
, /* partial_inplace */
1304 0xffff, /* dst_mask */
1305 FALSE
), /* pcrel_offset */
1308 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1311 ppc_elf_howto_init (void)
1313 unsigned int i
, type
;
1316 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1319 type
= ppc_elf_howto_raw
[i
].type
;
1320 if (type
>= (sizeof (ppc_elf_howto_table
)
1321 / sizeof (ppc_elf_howto_table
[0])))
1323 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1327 static reloc_howto_type
*
1328 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1329 bfd_reloc_code_real_type code
)
1331 enum elf_ppc_reloc_type r
;
1333 /* Initialize howto table if not already done. */
1334 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1335 ppc_elf_howto_init ();
1342 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1343 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1344 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1345 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1346 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1347 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1348 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1349 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1350 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1351 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1352 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1353 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1354 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1355 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1356 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1357 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1358 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1359 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1360 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1361 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1362 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1363 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1364 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1365 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1366 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1367 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1368 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1369 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1370 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1371 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1372 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1373 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1374 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1375 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1376 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1377 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1378 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1379 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1380 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1381 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1382 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1383 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1384 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1385 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1386 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1387 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1388 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1389 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1390 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1391 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1392 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1393 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1394 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1395 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1396 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1397 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1398 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1399 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1400 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1401 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1402 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1403 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1404 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1405 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1406 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1407 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1408 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1409 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1410 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1411 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1412 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1413 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1414 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1415 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1416 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1417 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1418 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1419 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1420 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1421 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1422 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1425 return ppc_elf_howto_table
[r
];
1428 /* Set the howto pointer for a PowerPC ELF reloc. */
1431 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1433 Elf_Internal_Rela
*dst
)
1435 /* Initialize howto table if not already done. */
1436 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1437 ppc_elf_howto_init ();
1439 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1440 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1443 /* Handle the R_PPC_ADDR16_HA reloc. */
1445 static bfd_reloc_status_type
1446 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1447 arelent
*reloc_entry
,
1449 void *data ATTRIBUTE_UNUSED
,
1450 asection
*input_section
,
1452 char **error_message ATTRIBUTE_UNUSED
)
1456 if (output_bfd
!= NULL
)
1458 reloc_entry
->address
+= input_section
->output_offset
;
1459 return bfd_reloc_ok
;
1462 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1463 return bfd_reloc_outofrange
;
1465 if (bfd_is_com_section (symbol
->section
))
1468 relocation
= symbol
->value
;
1470 relocation
+= symbol
->section
->output_section
->vma
;
1471 relocation
+= symbol
->section
->output_offset
;
1472 relocation
+= reloc_entry
->addend
;
1474 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1476 return bfd_reloc_continue
;
1479 static bfd_reloc_status_type
1480 ppc_elf_unhandled_reloc (bfd
*abfd
,
1481 arelent
*reloc_entry
,
1484 asection
*input_section
,
1486 char **error_message
)
1488 /* If this is a relocatable link (output_bfd test tells us), just
1489 call the generic function. Any adjustment will be done at final
1491 if (output_bfd
!= NULL
)
1492 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1493 input_section
, output_bfd
, error_message
);
1495 if (error_message
!= NULL
)
1497 static char buf
[60];
1498 sprintf (buf
, _("generic linker can't handle %s"),
1499 reloc_entry
->howto
->name
);
1500 *error_message
= buf
;
1502 return bfd_reloc_dangerous
;
1505 /* Sections created by the linker. */
1507 typedef struct elf_linker_section
1509 /* pointer to the section */
1511 /* pointer to the created symbol hash value */
1512 struct elf_link_hash_entry
*sym_hash
;
1513 /* offset of symbol from beginning of section */
1515 } elf_linker_section_t
;
1517 /* Linked list of allocated pointer entries. This hangs off of the
1518 symbol lists, and provides allows us to return different pointers,
1519 based on different addend's. */
1521 typedef struct elf_linker_section_pointers
1523 /* next allocated pointer for this symbol */
1524 struct elf_linker_section_pointers
*next
;
1525 /* offset of pointer from beginning of section */
1529 /* which linker section this is */
1530 elf_linker_section_t
*lsect
;
1531 /* whether address was written yet */
1532 bfd_boolean written_address_p
;
1533 } elf_linker_section_pointers_t
;
1535 struct ppc_elf_obj_tdata
1537 struct elf_obj_tdata elf
;
1539 /* A mapping from local symbols to offsets into the various linker
1540 sections added. This is index by the symbol index. */
1541 elf_linker_section_pointers_t
**linker_section_pointers
;
1544 #define ppc_elf_tdata(bfd) \
1545 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1547 #define elf_local_ptr_offsets(bfd) \
1548 (ppc_elf_tdata (bfd)->linker_section_pointers)
1550 /* Override the generic function because we store some extras. */
1553 ppc_elf_mkobject (bfd
*abfd
)
1555 bfd_size_type amt
= sizeof (struct ppc_elf_obj_tdata
);
1556 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
1557 if (abfd
->tdata
.any
== NULL
)
1562 /* Fix bad default arch selected for a 32 bit input bfd when the
1563 default is 64 bit. */
1566 ppc_elf_object_p (bfd
*abfd
)
1568 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1570 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1572 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1574 /* Relies on arch after 64 bit default being 32 bit default. */
1575 abfd
->arch_info
= abfd
->arch_info
->next
;
1576 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1582 /* Function to set whether a module needs the -mrelocatable bit set. */
1585 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1587 BFD_ASSERT (!elf_flags_init (abfd
)
1588 || elf_elfheader (abfd
)->e_flags
== flags
);
1590 elf_elfheader (abfd
)->e_flags
= flags
;
1591 elf_flags_init (abfd
) = TRUE
;
1595 /* Return 1 if target is one of ours. */
1598 is_ppc_elf_target (const struct bfd_target
*targ
)
1600 extern const bfd_target bfd_elf32_powerpc_vec
;
1601 extern const bfd_target bfd_elf32_powerpcle_vec
;
1603 return targ
== &bfd_elf32_powerpc_vec
|| targ
== &bfd_elf32_powerpcle_vec
;
1606 /* Merge backend specific data from an object file to the output
1607 object file when linking. */
1610 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
1616 if (!is_ppc_elf_target (ibfd
->xvec
)
1617 || !is_ppc_elf_target (obfd
->xvec
))
1620 /* Check if we have the same endianess. */
1621 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
1624 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1625 old_flags
= elf_elfheader (obfd
)->e_flags
;
1626 if (!elf_flags_init (obfd
))
1628 /* First call, no flags set. */
1629 elf_flags_init (obfd
) = TRUE
;
1630 elf_elfheader (obfd
)->e_flags
= new_flags
;
1633 /* Compatible flags are ok. */
1634 else if (new_flags
== old_flags
)
1637 /* Incompatible flags. */
1640 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
1641 to be linked with either. */
1643 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1644 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1647 (*_bfd_error_handler
)
1648 (_("%B: compiled with -mrelocatable and linked with "
1649 "modules compiled normally"), ibfd
);
1651 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1652 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1655 (*_bfd_error_handler
)
1656 (_("%B: compiled normally and linked with "
1657 "modules compiled with -mrelocatable"), ibfd
);
1660 /* The output is -mrelocatable-lib iff both the input files are. */
1661 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1662 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1664 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1665 but each input file is either -mrelocatable or -mrelocatable-lib. */
1666 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1667 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1668 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1669 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1671 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
1672 any module uses it. */
1673 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1675 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1676 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1678 /* Warn about any other mismatches. */
1679 if (new_flags
!= old_flags
)
1682 (*_bfd_error_handler
)
1683 (_("%B: uses different e_flags (0x%lx) fields "
1684 "than previous modules (0x%lx)"),
1685 ibfd
, (long) new_flags
, (long) old_flags
);
1690 bfd_set_error (bfd_error_bad_value
);
1698 /* Support for core dump NOTE sections. */
1701 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1706 switch (note
->descsz
)
1711 case 268: /* Linux/PPC. */
1713 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1716 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1725 /* Make a ".reg/999" section. */
1726 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1727 size
, note
->descpos
+ offset
);
1731 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1733 switch (note
->descsz
)
1738 case 128: /* Linux/PPC elf_prpsinfo. */
1739 elf_tdata (abfd
)->core_program
1740 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1741 elf_tdata (abfd
)->core_command
1742 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1745 /* Note that for some reason, a spurious space is tacked
1746 onto the end of the args in some (at least one anyway)
1747 implementations, so strip it off if it exists. */
1750 char *command
= elf_tdata (abfd
)->core_command
;
1751 int n
= strlen (command
);
1753 if (0 < n
&& command
[n
- 1] == ' ')
1754 command
[n
- 1] = '\0';
1760 /* Return address for Ith PLT stub in section PLT, for relocation REL
1761 or (bfd_vma) -1 if it should not be included. */
1764 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1765 const asection
*plt ATTRIBUTE_UNUSED
,
1768 return rel
->address
;
1771 /* Handle a PowerPC specific section when reading an object file. This
1772 is called when bfd_section_from_shdr finds a section with an unknown
1776 ppc_elf_section_from_shdr (bfd
*abfd
,
1777 Elf_Internal_Shdr
*hdr
,
1784 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1787 newsect
= hdr
->bfd_section
;
1788 flags
= bfd_get_section_flags (abfd
, newsect
);
1789 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1790 flags
|= SEC_EXCLUDE
;
1792 if (hdr
->sh_type
== SHT_ORDERED
)
1793 flags
|= SEC_SORT_ENTRIES
;
1795 bfd_set_section_flags (abfd
, newsect
, flags
);
1799 /* Set up any other section flags and such that may be necessary. */
1802 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1803 Elf_Internal_Shdr
*shdr
,
1806 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1807 shdr
->sh_flags
|= SHF_EXCLUDE
;
1809 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1810 shdr
->sh_type
= SHT_ORDERED
;
1815 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1816 need to bump up the number of section headers. */
1819 ppc_elf_additional_program_headers (bfd
*abfd
)
1824 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1825 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1828 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1829 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1835 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1836 .PPC.EMB.sbss0 a normal section, and not a bss section so
1837 that the linker doesn't crater when trying to make more than
1840 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
1842 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
1843 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1844 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1845 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
1846 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
1847 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
1848 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
1849 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
1850 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
1851 { NULL
, 0, 0, 0, 0 }
1854 /* Very simple linked list structure for recording apuinfo values. */
1855 typedef struct apuinfo_list
1857 struct apuinfo_list
*next
;
1858 unsigned long value
;
1862 static apuinfo_list
*head
;
1866 apuinfo_list_init (void)
1872 apuinfo_list_add (unsigned long value
)
1874 apuinfo_list
*entry
= head
;
1876 while (entry
!= NULL
)
1878 if (entry
->value
== value
)
1880 entry
= entry
->next
;
1883 entry
= bfd_malloc (sizeof (* entry
));
1887 entry
->value
= value
;
1893 apuinfo_list_length (void)
1895 apuinfo_list
*entry
;
1896 unsigned long count
;
1898 for (entry
= head
, count
= 0;
1900 entry
= entry
->next
)
1906 static inline unsigned long
1907 apuinfo_list_element (unsigned long number
)
1909 apuinfo_list
* entry
;
1913 entry
= entry
->next
)
1916 return entry
? entry
->value
: 0;
1920 apuinfo_list_finish (void)
1922 apuinfo_list
*entry
;
1924 for (entry
= head
; entry
;)
1926 apuinfo_list
*next
= entry
->next
;
1934 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
1935 #define APUINFO_LABEL "APUinfo"
1937 /* Scan the input BFDs and create a linked list of
1938 the APUinfo values that will need to be emitted. */
1941 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
1946 unsigned num_input_sections
;
1947 bfd_size_type output_section_size
;
1949 unsigned num_entries
;
1950 unsigned long offset
;
1951 unsigned long length
;
1952 const char *error_message
= NULL
;
1954 if (link_info
== NULL
)
1957 /* Scan the input bfds, looking for apuinfo sections. */
1958 num_input_sections
= 0;
1959 output_section_size
= 0;
1961 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
1963 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
1966 ++ num_input_sections
;
1967 output_section_size
+= asec
->size
;
1971 /* We need at least one input sections
1972 in order to make merging worthwhile. */
1973 if (num_input_sections
< 1)
1976 /* Just make sure that the output section exists as well. */
1977 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
1981 /* Allocate a buffer for the contents of the input sections. */
1982 buffer
= bfd_malloc (output_section_size
);
1987 apuinfo_list_init ();
1989 /* Read in the input sections contents. */
1990 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
1992 unsigned long datum
;
1995 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
1999 length
= asec
->size
;
2002 error_message
= _("corrupt or empty %s section in %B");
2006 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
2007 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
2009 error_message
= _("unable to read in %s section from %B");
2013 /* Process the contents of the section. */
2014 ptr
= buffer
+ offset
;
2015 error_message
= _("corrupt %s section in %B");
2017 /* Verify the contents of the header. Note - we have to
2018 extract the values this way in order to allow for a
2019 host whose endian-ness is different from the target. */
2020 datum
= bfd_get_32 (ibfd
, ptr
);
2021 if (datum
!= sizeof APUINFO_LABEL
)
2024 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
2028 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
2031 /* Get the number of bytes used for apuinfo entries. */
2032 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
2033 if (datum
+ 20 != length
)
2036 /* Make sure that we do not run off the end of the section. */
2037 if (offset
+ length
> output_section_size
)
2040 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2041 for (i
= 0; i
< datum
; i
+= 4)
2042 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
2044 /* Update the offset. */
2048 error_message
= NULL
;
2050 /* Compute the size of the output section. */
2051 num_entries
= apuinfo_list_length ();
2052 output_section_size
= 20 + num_entries
* 4;
2054 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2056 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
2058 error_message
= _("warning: unable to set size of %s section in %B");
2064 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
2067 /* Prevent the output section from accumulating the input sections'
2068 contents. We have already stored this in our linked list structure. */
2071 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2073 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2075 return (apuinfo_list_length ()
2076 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
2079 /* Finally we can generate the output section. */
2082 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
2087 unsigned num_entries
;
2088 bfd_size_type length
;
2090 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2094 if (apuinfo_list_length () == 0)
2097 length
= asec
->size
;
2101 buffer
= bfd_malloc (length
);
2104 (*_bfd_error_handler
)
2105 (_("failed to allocate space for new APUinfo section."));
2109 /* Create the apuinfo header. */
2110 num_entries
= apuinfo_list_length ();
2111 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
2112 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
2113 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
2114 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
2117 for (i
= 0; i
< num_entries
; i
++)
2119 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
2123 if (length
!= asec
->size
)
2124 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
2126 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
2127 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
2131 apuinfo_list_finish ();
2134 /* The following functions are specific to the ELF linker, while
2135 functions above are used generally. They appear in this file more
2136 or less in the order in which they are called. eg.
2137 ppc_elf_check_relocs is called early in the link process,
2138 ppc_elf_finish_dynamic_sections is one of the last functions
2141 /* The PPC linker needs to keep track of the number of relocs that it
2142 decides to copy as dynamic relocs in check_relocs for each symbol.
2143 This is so that it can later discard them if they are found to be
2144 unnecessary. We store the information in a field extending the
2145 regular ELF linker hash table. */
2147 struct ppc_elf_dyn_relocs
2149 struct ppc_elf_dyn_relocs
*next
;
2151 /* The input section of the reloc. */
2154 /* Total number of relocs copied for the input section. */
2155 bfd_size_type count
;
2157 /* Number of pc-relative relocs copied for the input section. */
2158 bfd_size_type pc_count
;
2161 /* Of those relocs that might be copied as dynamic relocs, this macro
2162 selects those that must be copied when linking a shared library,
2163 even when the symbol is local. */
2165 #define MUST_BE_DYN_RELOC(RTYPE) \
2166 ((RTYPE) != R_PPC_REL24 \
2167 && (RTYPE) != R_PPC_REL14 \
2168 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2169 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2170 && (RTYPE) != R_PPC_REL32)
2172 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2173 copying dynamic variables from a shared lib into an app's dynbss
2174 section, and instead use a dynamic relocation to point into the
2176 #define ELIMINATE_COPY_RELOCS 1
2178 /* PPC ELF linker hash entry. */
2180 struct ppc_elf_link_hash_entry
2182 struct elf_link_hash_entry elf
;
2184 /* If this symbol is used in the linker created sections, the processor
2185 specific backend uses this field to map the field into the offset
2186 from the beginning of the section. */
2187 elf_linker_section_pointers_t
*linker_section_pointer
;
2189 /* Track dynamic relocs copied for this symbol. */
2190 struct ppc_elf_dyn_relocs
*dyn_relocs
;
2192 /* Contexts in which symbol is used in the GOT (or TOC).
2193 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2194 corresponding relocs are encountered during check_relocs.
2195 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2196 indicate the corresponding GOT entry type is not needed. */
2197 #define TLS_GD 1 /* GD reloc. */
2198 #define TLS_LD 2 /* LD reloc. */
2199 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2200 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2201 #define TLS_TLS 16 /* Any TLS reloc. */
2202 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2206 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2208 /* PPC ELF linker hash table. */
2210 struct ppc_elf_link_hash_table
2212 struct elf_link_hash_table elf
;
2214 /* Short-cuts to get to dynamic linker sections. */
2223 elf_linker_section_t
*sdata
;
2224 elf_linker_section_t
*sdata2
;
2227 /* Shortcut to .__tls_get_addr. */
2228 struct elf_link_hash_entry
*tls_get_addr
;
2230 /* TLS local dynamic got entry handling. */
2232 bfd_signed_vma refcount
;
2236 /* Small local sym to section mapping cache. */
2237 struct sym_sec_cache sym_sec
;
2240 /* Get the PPC ELF linker hash table from a link_info structure. */
2242 #define ppc_elf_hash_table(p) \
2243 ((struct ppc_elf_link_hash_table *) (p)->hash)
2245 /* Create an entry in a PPC ELF linker hash table. */
2247 static struct bfd_hash_entry
*
2248 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2249 struct bfd_hash_table
*table
,
2252 /* Allocate the structure if it has not already been allocated by a
2256 entry
= bfd_hash_allocate (table
,
2257 sizeof (struct ppc_elf_link_hash_entry
));
2262 /* Call the allocation method of the superclass. */
2263 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2266 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2267 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
2268 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2274 /* Create a PPC ELF linker hash table. */
2276 static struct bfd_link_hash_table
*
2277 ppc_elf_link_hash_table_create (bfd
*abfd
)
2279 struct ppc_elf_link_hash_table
*ret
;
2281 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2285 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2286 ppc_elf_link_hash_newfunc
))
2292 return &ret
->elf
.root
;
2295 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2298 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2300 struct ppc_elf_link_hash_table
*htab
;
2304 if (!_bfd_elf_create_got_section (abfd
, info
))
2307 htab
= ppc_elf_hash_table (info
);
2308 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2312 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2313 | SEC_LINKER_CREATED
);
2314 if (!bfd_set_section_flags (abfd
, s
, flags
))
2317 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2319 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2320 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2321 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2323 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2329 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2330 to output sections (just like _bfd_elf_create_dynamic_sections has
2331 to create .dynbss and .rela.bss). */
2334 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2336 struct ppc_elf_link_hash_table
*htab
;
2340 htab
= ppc_elf_hash_table (info
);
2342 if (htab
->got
== NULL
2343 && !ppc_elf_create_got (abfd
, info
))
2346 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2349 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2350 | SEC_LINKER_CREATED
);
2352 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2353 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2355 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
2360 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2361 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2363 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2364 || ! bfd_set_section_alignment (abfd
, s
, 2))
2368 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2369 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2373 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2374 return bfd_set_section_flags (abfd
, s
, flags
);
2377 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2380 ppc_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
2381 struct elf_link_hash_entry
*dir
,
2382 struct elf_link_hash_entry
*ind
)
2384 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2386 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2387 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
2389 if (eind
->dyn_relocs
!= NULL
)
2391 if (edir
->dyn_relocs
!= NULL
)
2393 struct ppc_elf_dyn_relocs
**pp
;
2394 struct ppc_elf_dyn_relocs
*p
;
2396 if (ind
->root
.type
== bfd_link_hash_indirect
)
2399 /* Add reloc counts against the weak sym to the strong sym
2400 list. Merge any entries against the same section. */
2401 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2403 struct ppc_elf_dyn_relocs
*q
;
2405 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2406 if (q
->sec
== p
->sec
)
2408 q
->pc_count
+= p
->pc_count
;
2409 q
->count
+= p
->count
;
2416 *pp
= edir
->dyn_relocs
;
2419 edir
->dyn_relocs
= eind
->dyn_relocs
;
2420 eind
->dyn_relocs
= NULL
;
2423 edir
->tls_mask
|= eind
->tls_mask
;
2425 if (ELIMINATE_COPY_RELOCS
2426 && ind
->root
.type
!= bfd_link_hash_indirect
2427 && dir
->dynamic_adjusted
)
2429 /* If called to transfer flags for a weakdef during processing
2430 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2431 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2432 dir
->ref_dynamic
|= ind
->ref_dynamic
;
2433 dir
->ref_regular
|= ind
->ref_regular
;
2434 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
2435 dir
->needs_plt
|= ind
->needs_plt
;
2438 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
2441 /* Hook called by the linker routine which adds symbols from an object
2442 file. We use it to put .comm items in .sbss, and not .bss. */
2445 ppc_elf_add_symbol_hook (bfd
*abfd
,
2446 struct bfd_link_info
*info
,
2447 Elf_Internal_Sym
*sym
,
2448 const char **namep ATTRIBUTE_UNUSED
,
2449 flagword
*flagsp ATTRIBUTE_UNUSED
,
2453 if (sym
->st_shndx
== SHN_COMMON
2454 && !info
->relocatable
2455 && sym
->st_size
<= elf_gp_size (abfd
)
2456 && is_ppc_elf_target (info
->hash
->creator
))
2458 /* Common symbols less than or equal to -G nn bytes are automatically
2460 struct ppc_elf_link_hash_table
*htab
;
2462 htab
= ppc_elf_hash_table (info
);
2463 if (htab
->sbss
== NULL
)
2465 flagword flags
= SEC_IS_COMMON
;
2467 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
2468 if (htab
->sbss
== NULL
2469 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
2474 *valp
= sym
->st_size
;
2480 /* Enumeration to specify the special section. */
2481 enum elf_linker_section_enum
2483 LINKER_SECTION_SDATA
,
2484 LINKER_SECTION_SDATA2
2487 /* Create a special linker section */
2488 static elf_linker_section_t
*
2489 ppc_elf_create_linker_section (bfd
*abfd
,
2490 struct bfd_link_info
*info
,
2491 enum elf_linker_section_enum which
)
2493 elf_linker_section_t
*lsect
;
2494 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2495 asection
*s
, *sym_sec
;
2499 const char *rel_name
;
2500 const char *sym_name
;
2503 /* The linker creates these sections so it has somewhere to attach
2504 their respective symbols. Startup code (crt1.o) uses these symbols
2505 to initialize a register pointing to the section. If the output
2506 sections corresponding to these input sections were empty it would
2507 be OK to set the symbol to 0 (or any random number), because the
2508 associated register should never be used.
2509 FIXME: Setting a symbol this way is silly. The symbols ought to
2510 be set the same way other backends set gp. */
2511 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2512 | SEC_LINKER_CREATED
);
2521 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2523 rel_name
= ".rela.sdata";
2524 sym_name
= "_SDA_BASE_";
2527 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2529 rel_name
= ".rela.sdata2";
2530 sym_name
= "_SDA2_BASE_";
2531 flags
|= SEC_READONLY
;
2535 /* Record the first bfd that needs the special sections. */
2536 if (!htab
->elf
.dynobj
)
2537 htab
->elf
.dynobj
= abfd
;
2539 amt
= sizeof (elf_linker_section_t
);
2540 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2542 lsect
->sym_offset
= sym_offset
;
2544 /* See if the sections already exist. */
2545 sym_sec
= s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2546 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2548 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2550 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2552 if (sym_sec
== NULL
)
2557 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2558 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2561 s
->size
= align_power (s
->size
, 2);
2564 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2565 name
, (long) s
->size
);
2570 struct elf_link_hash_entry
*h
;
2571 struct bfd_link_hash_entry
*bh
;
2574 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2576 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2577 FALSE
, FALSE
, FALSE
);
2579 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2580 && !(_bfd_generic_link_add_one_symbol
2581 (info
, abfd
, sym_name
, BSF_GLOBAL
, sym_sec
, sym_offset
, NULL
,
2582 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2584 h
= (struct elf_link_hash_entry
*) bh
;
2586 h
->type
= STT_OBJECT
;
2587 lsect
->sym_hash
= h
;
2590 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2597 /* Find a linker generated pointer with a given addend and type. */
2599 static elf_linker_section_pointers_t
*
2600 elf_find_pointer_linker_section
2601 (elf_linker_section_pointers_t
*linker_pointers
,
2603 elf_linker_section_t
*lsect
)
2605 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2606 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2607 return linker_pointers
;
2612 /* Allocate a pointer to live in a linker created section. */
2615 elf_create_pointer_linker_section (bfd
*abfd
,
2616 struct bfd_link_info
*info
,
2617 elf_linker_section_t
*lsect
,
2618 struct elf_link_hash_entry
*h
,
2619 const Elf_Internal_Rela
*rel
)
2621 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2622 elf_linker_section_pointers_t
*linker_section_ptr
;
2623 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2626 BFD_ASSERT (lsect
!= NULL
);
2628 /* Is this a global symbol? */
2631 struct ppc_elf_link_hash_entry
*eh
;
2633 /* Has this symbol already been allocated? If so, our work is done. */
2634 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2635 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2640 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2641 /* Make sure this symbol is output as a dynamic symbol. */
2642 if (h
->dynindx
== -1)
2644 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2650 /* Allocation of a pointer to a local symbol. */
2651 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2653 /* Allocate a table to hold the local symbols if first time. */
2656 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2659 amt
*= sizeof (elf_linker_section_pointers_t
*);
2660 ptr
= bfd_zalloc (abfd
, amt
);
2665 elf_local_ptr_offsets (abfd
) = ptr
;
2668 /* Has this symbol already been allocated? If so, our work is done. */
2669 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2674 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2677 /* Allocate space for a pointer in the linker section, and allocate
2678 a new pointer record from internal memory. */
2679 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2680 amt
= sizeof (elf_linker_section_pointers_t
);
2681 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2683 if (!linker_section_ptr
)
2686 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2687 linker_section_ptr
->addend
= rel
->r_addend
;
2688 linker_section_ptr
->lsect
= lsect
;
2689 linker_section_ptr
->written_address_p
= FALSE
;
2690 *ptr_linker_section_ptr
= linker_section_ptr
;
2692 linker_section_ptr
->offset
= lsect
->section
->size
;
2693 lsect
->section
->size
+= 4;
2697 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2698 lsect
->name
, (long) linker_section_ptr
->offset
,
2699 (long) lsect
->section
->size
);
2706 update_local_sym_info (bfd
*abfd
,
2707 Elf_Internal_Shdr
*symtab_hdr
,
2708 unsigned long r_symndx
,
2711 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
2712 char *local_got_tls_masks
;
2714 if (local_got_refcounts
== NULL
)
2716 bfd_size_type size
= symtab_hdr
->sh_info
;
2718 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
2719 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2720 if (local_got_refcounts
== NULL
)
2722 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2725 local_got_refcounts
[r_symndx
] += 1;
2726 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2727 local_got_tls_masks
[r_symndx
] |= tls_type
;
2732 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
2734 (*_bfd_error_handler
)
2735 (_("%B: relocation %s cannot be used when making a shared object"),
2737 ppc_elf_howto_table
[r_type
]->name
);
2738 bfd_set_error (bfd_error_bad_value
);
2741 /* Look through the relocs for a section during the first phase, and
2742 allocate space in the global offset table or procedure linkage
2746 ppc_elf_check_relocs (bfd
*abfd
,
2747 struct bfd_link_info
*info
,
2749 const Elf_Internal_Rela
*relocs
)
2751 struct ppc_elf_link_hash_table
*htab
;
2752 Elf_Internal_Shdr
*symtab_hdr
;
2753 struct elf_link_hash_entry
**sym_hashes
;
2754 const Elf_Internal_Rela
*rel
;
2755 const Elf_Internal_Rela
*rel_end
;
2758 if (info
->relocatable
)
2762 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
2766 /* Initialize howto table if not already done. */
2767 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2768 ppc_elf_howto_init ();
2770 /* Create the linker generated sections all the time so that the
2771 special symbols are created. */
2772 htab
= ppc_elf_hash_table (info
);
2773 if (htab
->sdata
== NULL
)
2775 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
2776 LINKER_SECTION_SDATA
);
2777 if (htab
->sdata
== NULL
)
2781 if (htab
->sdata2
== NULL
)
2783 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
2784 LINKER_SECTION_SDATA2
);
2785 if (htab
->sdata2
== NULL
)
2789 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2790 sym_hashes
= elf_sym_hashes (abfd
);
2793 rel_end
= relocs
+ sec
->reloc_count
;
2794 for (rel
= relocs
; rel
< rel_end
; rel
++)
2796 unsigned long r_symndx
;
2797 enum elf_ppc_reloc_type r_type
;
2798 struct elf_link_hash_entry
*h
;
2801 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2802 if (r_symndx
< symtab_hdr
->sh_info
)
2805 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2807 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2808 This shows up in particular in an R_PPC_ADDR32 in the eabi
2810 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2812 if (htab
->got
== NULL
)
2814 if (htab
->elf
.dynobj
== NULL
)
2815 htab
->elf
.dynobj
= abfd
;
2816 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
2821 r_type
= ELF32_R_TYPE (rel
->r_info
);
2824 case R_PPC_GOT_TLSLD16
:
2825 case R_PPC_GOT_TLSLD16_LO
:
2826 case R_PPC_GOT_TLSLD16_HI
:
2827 case R_PPC_GOT_TLSLD16_HA
:
2828 htab
->tlsld_got
.refcount
+= 1;
2829 tls_type
= TLS_TLS
| TLS_LD
;
2832 case R_PPC_GOT_TLSGD16
:
2833 case R_PPC_GOT_TLSGD16_LO
:
2834 case R_PPC_GOT_TLSGD16_HI
:
2835 case R_PPC_GOT_TLSGD16_HA
:
2836 tls_type
= TLS_TLS
| TLS_GD
;
2839 case R_PPC_GOT_TPREL16
:
2840 case R_PPC_GOT_TPREL16_LO
:
2841 case R_PPC_GOT_TPREL16_HI
:
2842 case R_PPC_GOT_TPREL16_HA
:
2844 info
->flags
|= DF_STATIC_TLS
;
2845 tls_type
= TLS_TLS
| TLS_TPREL
;
2848 case R_PPC_GOT_DTPREL16
:
2849 case R_PPC_GOT_DTPREL16_LO
:
2850 case R_PPC_GOT_DTPREL16_HI
:
2851 case R_PPC_GOT_DTPREL16_HA
:
2852 tls_type
= TLS_TLS
| TLS_DTPREL
;
2854 sec
->has_tls_reloc
= 1;
2857 /* GOT16 relocations */
2859 case R_PPC_GOT16_LO
:
2860 case R_PPC_GOT16_HI
:
2861 case R_PPC_GOT16_HA
:
2862 /* This symbol requires a global offset table entry. */
2863 if (htab
->got
== NULL
)
2865 if (htab
->elf
.dynobj
== NULL
)
2866 htab
->elf
.dynobj
= abfd
;
2867 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
2872 h
->got
.refcount
+= 1;
2873 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
2876 /* This is a global offset table entry for a local symbol. */
2877 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
2881 /* Indirect .sdata relocation. */
2882 case R_PPC_EMB_SDAI16
:
2885 bad_shared_reloc (abfd
, r_type
);
2888 if (!elf_create_pointer_linker_section (abfd
, info
,
2889 htab
->sdata
, h
, rel
))
2893 /* Indirect .sdata2 relocation. */
2894 case R_PPC_EMB_SDA2I16
:
2897 bad_shared_reloc (abfd
, r_type
);
2900 if (!elf_create_pointer_linker_section (abfd
, info
,
2901 htab
->sdata2
, h
, rel
))
2905 case R_PPC_SDAREL16
:
2906 case R_PPC_EMB_SDA2REL
:
2907 case R_PPC_EMB_SDA21
:
2908 case R_PPC_EMB_RELSDA
:
2909 case R_PPC_EMB_NADDR32
:
2910 case R_PPC_EMB_NADDR16
:
2911 case R_PPC_EMB_NADDR16_LO
:
2912 case R_PPC_EMB_NADDR16_HI
:
2913 case R_PPC_EMB_NADDR16_HA
:
2916 bad_shared_reloc (abfd
, r_type
);
2922 case R_PPC_PLTREL24
:
2923 case R_PPC_PLTREL32
:
2924 case R_PPC_PLT16_LO
:
2925 case R_PPC_PLT16_HI
:
2926 case R_PPC_PLT16_HA
:
2928 fprintf (stderr
, "Reloc requires a PLT entry\n");
2930 /* This symbol requires a procedure linkage table entry. We
2931 actually build the entry in finish_dynamic_symbol,
2932 because this might be a case of linking PIC code without
2933 linking in any dynamic objects, in which case we don't
2934 need to generate a procedure linkage table after all. */
2938 /* It does not make sense to have a procedure linkage
2939 table entry for a local symbol. */
2940 (*_bfd_error_handler
) (_("%B(%A+0x%lx): %s reloc against "
2944 (long) rel
->r_offset
,
2945 ppc_elf_howto_table
[r_type
]->name
);
2946 bfd_set_error (bfd_error_bad_value
);
2954 /* The following relocations don't need to propagate the
2955 relocation if linking a shared object since they are
2956 section relative. */
2958 case R_PPC_SECTOFF_LO
:
2959 case R_PPC_SECTOFF_HI
:
2960 case R_PPC_SECTOFF_HA
:
2961 case R_PPC_DTPREL16
:
2962 case R_PPC_DTPREL16_LO
:
2963 case R_PPC_DTPREL16_HI
:
2964 case R_PPC_DTPREL16_HA
:
2968 /* This are just markers. */
2970 case R_PPC_EMB_MRKREF
:
2975 /* These should only appear in dynamic objects. */
2977 case R_PPC_GLOB_DAT
:
2978 case R_PPC_JMP_SLOT
:
2979 case R_PPC_RELATIVE
:
2982 /* These aren't handled yet. We'll report an error later. */
2984 case R_PPC_EMB_RELSEC16
:
2985 case R_PPC_EMB_RELST_LO
:
2986 case R_PPC_EMB_RELST_HI
:
2987 case R_PPC_EMB_RELST_HA
:
2988 case R_PPC_EMB_BIT_FLD
:
2991 /* This refers only to functions defined in the shared library. */
2992 case R_PPC_LOCAL24PC
:
2995 /* This relocation describes the C++ object vtable hierarchy.
2996 Reconstruct it for later use during GC. */
2997 case R_PPC_GNU_VTINHERIT
:
2998 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3002 /* This relocation describes which C++ vtable entries are actually
3003 used. Record for later use during GC. */
3004 case R_PPC_GNU_VTENTRY
:
3005 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3009 /* We shouldn't really be seeing these. */
3012 info
->flags
|= DF_STATIC_TLS
;
3016 case R_PPC_DTPMOD32
:
3017 case R_PPC_DTPREL32
:
3021 case R_PPC_TPREL16_LO
:
3022 case R_PPC_TPREL16_HI
:
3023 case R_PPC_TPREL16_HA
:
3025 info
->flags
|= DF_STATIC_TLS
;
3028 /* When creating a shared object, we must copy these
3029 relocs into the output file. We create a reloc
3030 section in dynobj and make room for the reloc. */
3033 case R_PPC_REL14_BRTAKEN
:
3034 case R_PPC_REL14_BRNTAKEN
:
3037 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3044 case R_PPC_ADDR16_LO
:
3045 case R_PPC_ADDR16_HI
:
3046 case R_PPC_ADDR16_HA
:
3048 case R_PPC_ADDR14_BRTAKEN
:
3049 case R_PPC_ADDR14_BRNTAKEN
:
3052 if (h
!= NULL
&& !info
->shared
)
3054 /* We may need a plt entry if the symbol turns out to be
3055 a function defined in a dynamic object. */
3058 /* We may need a copy reloc too. */
3063 /* If we are creating a shared library, and this is a reloc
3064 against a global symbol, or a non PC relative reloc
3065 against a local symbol, then we need to copy the reloc
3066 into the shared library. However, if we are linking with
3067 -Bsymbolic, we do not need to copy a reloc against a
3068 global symbol which is defined in an object we are
3069 including in the link (i.e., DEF_REGULAR is set). At
3070 this point we have not seen all the input files, so it is
3071 possible that DEF_REGULAR is not set now but will be set
3072 later (it is never cleared). In case of a weak definition,
3073 DEF_REGULAR may be cleared later by a strong definition in
3074 a shared library. We account for that possibility below by
3075 storing information in the dyn_relocs field of the hash
3076 table entry. A similar situation occurs when creating
3077 shared libraries and symbol visibility changes render the
3080 If on the other hand, we are creating an executable, we
3081 may need to keep relocations for symbols satisfied by a
3082 dynamic library if we manage to avoid copy relocs for the
3085 && (MUST_BE_DYN_RELOC (r_type
)
3087 && (! info
->symbolic
3088 || h
->root
.type
== bfd_link_hash_defweak
3089 || !h
->def_regular
))))
3090 || (ELIMINATE_COPY_RELOCS
3092 && (sec
->flags
& SEC_ALLOC
) != 0
3094 && (h
->root
.type
== bfd_link_hash_defweak
3095 || !h
->def_regular
)))
3097 struct ppc_elf_dyn_relocs
*p
;
3098 struct ppc_elf_dyn_relocs
**head
;
3102 "ppc_elf_check_relocs needs to "
3103 "create relocation for %s\n",
3104 (h
&& h
->root
.root
.string
3105 ? h
->root
.root
.string
: "<unknown>"));
3111 name
= (bfd_elf_string_from_elf_section
3113 elf_elfheader (abfd
)->e_shstrndx
,
3114 elf_section_data (sec
)->rel_hdr
.sh_name
));
3118 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3119 && strcmp (bfd_get_section_name (abfd
, sec
),
3122 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3127 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3128 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3129 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3130 if ((sec
->flags
& SEC_ALLOC
) != 0)
3131 flags
|= SEC_ALLOC
| SEC_LOAD
;
3133 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3135 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3139 elf_section_data (sec
)->sreloc
= sreloc
;
3142 /* If this is a global symbol, we count the number of
3143 relocations we need for this symbol. */
3146 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3150 /* Track dynamic relocs needed for local syms too.
3151 We really need local syms available to do this
3155 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3160 head
= ((struct ppc_elf_dyn_relocs
**)
3161 &elf_section_data (s
)->local_dynrel
);
3165 if (p
== NULL
|| p
->sec
!= sec
)
3167 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3178 if (!MUST_BE_DYN_RELOC (r_type
))
3189 /* Return the section that should be marked against GC for a given
3193 ppc_elf_gc_mark_hook (asection
*sec
,
3194 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3195 Elf_Internal_Rela
*rel
,
3196 struct elf_link_hash_entry
*h
,
3197 Elf_Internal_Sym
*sym
)
3201 switch (ELF32_R_TYPE (rel
->r_info
))
3203 case R_PPC_GNU_VTINHERIT
:
3204 case R_PPC_GNU_VTENTRY
:
3208 switch (h
->root
.type
)
3210 case bfd_link_hash_defined
:
3211 case bfd_link_hash_defweak
:
3212 return h
->root
.u
.def
.section
;
3214 case bfd_link_hash_common
:
3215 return h
->root
.u
.c
.p
->section
;
3223 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3228 /* Update the got, plt and dynamic reloc reference counts for the
3229 section being removed. */
3232 ppc_elf_gc_sweep_hook (bfd
*abfd
,
3233 struct bfd_link_info
*info
,
3235 const Elf_Internal_Rela
*relocs
)
3237 struct ppc_elf_link_hash_table
*htab
;
3238 Elf_Internal_Shdr
*symtab_hdr
;
3239 struct elf_link_hash_entry
**sym_hashes
;
3240 bfd_signed_vma
*local_got_refcounts
;
3241 const Elf_Internal_Rela
*rel
, *relend
;
3243 elf_section_data (sec
)->local_dynrel
= NULL
;
3245 htab
= ppc_elf_hash_table (info
);
3246 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3247 sym_hashes
= elf_sym_hashes (abfd
);
3248 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3250 relend
= relocs
+ sec
->reloc_count
;
3251 for (rel
= relocs
; rel
< relend
; rel
++)
3253 unsigned long r_symndx
;
3254 enum elf_ppc_reloc_type r_type
;
3255 struct elf_link_hash_entry
*h
= NULL
;
3257 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3258 if (r_symndx
>= symtab_hdr
->sh_info
)
3260 struct ppc_elf_dyn_relocs
**pp
, *p
;
3261 struct ppc_elf_link_hash_entry
*eh
;
3263 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3264 while (h
->root
.type
== bfd_link_hash_indirect
3265 || h
->root
.type
== bfd_link_hash_warning
)
3266 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3267 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3269 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3272 /* Everything must go for SEC. */
3278 r_type
= ELF32_R_TYPE (rel
->r_info
);
3281 case R_PPC_GOT_TLSLD16
:
3282 case R_PPC_GOT_TLSLD16_LO
:
3283 case R_PPC_GOT_TLSLD16_HI
:
3284 case R_PPC_GOT_TLSLD16_HA
:
3285 htab
->tlsld_got
.refcount
-= 1;
3288 case R_PPC_GOT_TLSGD16
:
3289 case R_PPC_GOT_TLSGD16_LO
:
3290 case R_PPC_GOT_TLSGD16_HI
:
3291 case R_PPC_GOT_TLSGD16_HA
:
3292 case R_PPC_GOT_TPREL16
:
3293 case R_PPC_GOT_TPREL16_LO
:
3294 case R_PPC_GOT_TPREL16_HI
:
3295 case R_PPC_GOT_TPREL16_HA
:
3296 case R_PPC_GOT_DTPREL16
:
3297 case R_PPC_GOT_DTPREL16_LO
:
3298 case R_PPC_GOT_DTPREL16_HI
:
3299 case R_PPC_GOT_DTPREL16_HA
:
3301 case R_PPC_GOT16_LO
:
3302 case R_PPC_GOT16_HI
:
3303 case R_PPC_GOT16_HA
:
3306 if (h
->got
.refcount
> 0)
3309 else if (local_got_refcounts
!= NULL
)
3311 if (local_got_refcounts
[r_symndx
] > 0)
3312 local_got_refcounts
[r_symndx
]--;
3318 case R_PPC_REL14_BRTAKEN
:
3319 case R_PPC_REL14_BRNTAKEN
:
3322 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3329 case R_PPC_ADDR16_LO
:
3330 case R_PPC_ADDR16_HI
:
3331 case R_PPC_ADDR16_HA
:
3333 case R_PPC_ADDR14_BRTAKEN
:
3334 case R_PPC_ADDR14_BRNTAKEN
:
3338 case R_PPC_PLTREL24
:
3339 case R_PPC_PLT16_LO
:
3340 case R_PPC_PLT16_HI
:
3341 case R_PPC_PLT16_HA
:
3344 if (h
->plt
.refcount
> 0)
3356 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
3359 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
3361 struct ppc_elf_link_hash_table
*htab
;
3363 htab
= ppc_elf_hash_table (info
);
3364 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3365 FALSE
, FALSE
, TRUE
);
3367 return _bfd_elf_tls_setup (obfd
, info
);
3370 /* Run through all the TLS relocs looking for optimization
3374 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
3375 struct bfd_link_info
*info
)
3379 struct ppc_elf_link_hash_table
*htab
;
3381 if (info
->relocatable
|| info
->shared
)
3384 htab
= ppc_elf_hash_table (info
);
3385 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3387 Elf_Internal_Sym
*locsyms
= NULL
;
3388 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3390 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3391 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
3393 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3394 int expecting_tls_get_addr
;
3396 /* Read the relocations. */
3397 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
3399 if (relstart
== NULL
)
3402 expecting_tls_get_addr
= 0;
3403 relend
= relstart
+ sec
->reloc_count
;
3404 for (rel
= relstart
; rel
< relend
; rel
++)
3406 enum elf_ppc_reloc_type r_type
;
3407 unsigned long r_symndx
;
3408 struct elf_link_hash_entry
*h
= NULL
;
3410 char tls_set
, tls_clear
;
3411 bfd_boolean is_local
;
3413 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3414 if (r_symndx
>= symtab_hdr
->sh_info
)
3416 struct elf_link_hash_entry
**sym_hashes
;
3418 sym_hashes
= elf_sym_hashes (ibfd
);
3419 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3420 while (h
->root
.type
== bfd_link_hash_indirect
3421 || h
->root
.type
== bfd_link_hash_warning
)
3422 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3430 r_type
= ELF32_R_TYPE (rel
->r_info
);
3433 case R_PPC_GOT_TLSLD16
:
3434 case R_PPC_GOT_TLSLD16_LO
:
3435 case R_PPC_GOT_TLSLD16_HI
:
3436 case R_PPC_GOT_TLSLD16_HA
:
3437 /* These relocs should never be against a symbol
3438 defined in a shared lib. Leave them alone if
3439 that turns out to be the case. */
3440 expecting_tls_get_addr
= 0;
3441 htab
->tlsld_got
.refcount
-= 1;
3448 expecting_tls_get_addr
= 1;
3451 case R_PPC_GOT_TLSGD16
:
3452 case R_PPC_GOT_TLSGD16_LO
:
3453 case R_PPC_GOT_TLSGD16_HI
:
3454 case R_PPC_GOT_TLSGD16_HA
:
3460 tls_set
= TLS_TLS
| TLS_TPRELGD
;
3462 expecting_tls_get_addr
= 1;
3465 case R_PPC_GOT_TPREL16
:
3466 case R_PPC_GOT_TPREL16_LO
:
3467 case R_PPC_GOT_TPREL16_HI
:
3468 case R_PPC_GOT_TPREL16_HA
:
3469 expecting_tls_get_addr
= 0;
3474 tls_clear
= TLS_TPREL
;
3481 case R_PPC_REL14_BRTAKEN
:
3482 case R_PPC_REL14_BRNTAKEN
:
3484 if (expecting_tls_get_addr
3486 && h
== htab
->tls_get_addr
)
3488 if (h
->plt
.refcount
> 0)
3489 h
->plt
.refcount
-= 1;
3491 expecting_tls_get_addr
= 0;
3495 expecting_tls_get_addr
= 0;
3503 /* We managed to get rid of a got entry. */
3504 if (h
->got
.refcount
> 0)
3505 h
->got
.refcount
-= 1;
3507 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
3511 Elf_Internal_Sym
*sym
;
3512 bfd_signed_vma
*lgot_refs
;
3515 if (locsyms
== NULL
)
3517 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3518 if (locsyms
== NULL
)
3519 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3520 symtab_hdr
->sh_info
,
3521 0, NULL
, NULL
, NULL
);
3522 if (locsyms
== NULL
)
3524 if (elf_section_data (sec
)->relocs
!= relstart
)
3529 sym
= locsyms
+ r_symndx
;
3530 lgot_refs
= elf_local_got_refcounts (ibfd
);
3531 if (lgot_refs
== NULL
)
3535 /* We managed to get rid of a got entry. */
3536 if (lgot_refs
[r_symndx
] > 0)
3537 lgot_refs
[r_symndx
] -= 1;
3539 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
3540 tls_mask
= &lgot_masks
[r_symndx
];
3543 *tls_mask
|= tls_set
;
3544 *tls_mask
&= ~tls_clear
;
3547 if (elf_section_data (sec
)->relocs
!= relstart
)
3552 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
3554 if (!info
->keep_memory
)
3557 symtab_hdr
->contents
= (unsigned char *) locsyms
;
3563 /* Adjust a symbol defined by a dynamic object and referenced by a
3564 regular object. The current definition is in some section of the
3565 dynamic object, but we're not including those sections. We have to
3566 change the definition to something the rest of the link can
3570 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3571 struct elf_link_hash_entry
*h
)
3573 struct ppc_elf_link_hash_table
*htab
;
3575 unsigned int power_of_two
;
3578 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
3579 h
->root
.root
.string
);
3582 /* Make sure we know what is going on here. */
3583 htab
= ppc_elf_hash_table (info
);
3584 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
3586 || h
->u
.weakdef
!= NULL
3589 && !h
->def_regular
)));
3591 /* Deal with function syms. */
3592 if (h
->type
== STT_FUNC
3595 /* Clear procedure linkage table information for any symbol that
3596 won't need a .plt entry. */
3597 if (h
->plt
.refcount
<= 0
3598 || SYMBOL_CALLS_LOCAL (info
, h
)
3599 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3600 && h
->root
.type
== bfd_link_hash_undefweak
))
3602 /* A PLT entry is not required/allowed when:
3604 1. We are not using ld.so; because then the PLT entry
3605 can't be set up, so we can't use one. In this case,
3606 ppc_elf_adjust_dynamic_symbol won't even be called.
3608 2. GC has rendered the entry unused.
3610 3. We know for certain that a call to this symbol
3611 will go to this object, or will remain undefined. */
3612 h
->plt
.offset
= (bfd_vma
) -1;
3618 h
->plt
.offset
= (bfd_vma
) -1;
3620 /* If this is a weak symbol, and there is a real definition, the
3621 processor independent code will have arranged for us to see the
3622 real definition first, and we can just use the same value. */
3623 if (h
->u
.weakdef
!= NULL
)
3625 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3626 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3627 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3628 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3629 if (ELIMINATE_COPY_RELOCS
)
3630 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3634 /* This is a reference to a symbol defined by a dynamic object which
3635 is not a function. */
3637 /* If we are creating a shared library, we must presume that the
3638 only references to the symbol are via the global offset table.
3639 For such cases we need not do anything here; the relocations will
3640 be handled correctly by relocate_section. */
3644 /* If there are no references to this symbol that do not use the
3645 GOT, we don't need to generate a copy reloc. */
3646 if (!h
->non_got_ref
)
3649 if (ELIMINATE_COPY_RELOCS
)
3651 struct ppc_elf_dyn_relocs
*p
;
3652 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3654 s
= p
->sec
->output_section
;
3655 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3659 /* If we didn't find any dynamic relocs in read-only sections, then
3660 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3668 /* We must allocate the symbol in our .dynbss section, which will
3669 become part of the .bss section of the executable. There will be
3670 an entry for this symbol in the .dynsym section. The dynamic
3671 object will contain position independent code, so all references
3672 from the dynamic object to this symbol will go through the global
3673 offset table. The dynamic linker will use the .dynsym entry to
3674 determine the address it must put in the global offset table, so
3675 both the dynamic object and the regular object will refer to the
3676 same memory location for the variable.
3678 Of course, if the symbol is sufficiently small, we must instead
3679 allocate it in .sbss. FIXME: It would be better to do this if and
3680 only if there were actually SDAREL relocs for that symbol. */
3682 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
3686 BFD_ASSERT (s
!= NULL
);
3688 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3689 copy the initial value out of the dynamic object and into the
3690 runtime process image. We need to remember the offset into the
3691 .rela.bss section we are going to use. */
3692 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3696 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
3697 srel
= htab
->relsbss
;
3699 srel
= htab
->relbss
;
3700 BFD_ASSERT (srel
!= NULL
);
3701 srel
->size
+= sizeof (Elf32_External_Rela
);
3705 /* We need to figure out the alignment required for this symbol. I
3706 have no idea how ELF linkers handle this. */
3707 power_of_two
= bfd_log2 (h
->size
);
3708 if (power_of_two
> 4)
3711 /* Apply the required alignment. */
3712 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3713 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3715 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3719 /* Define the symbol as being at this point in the section. */
3720 h
->root
.u
.def
.section
= s
;
3721 h
->root
.u
.def
.value
= s
->size
;
3723 /* Increment the section size to make room for the symbol. */
3729 /* Allocate space in associated reloc sections for dynamic relocs. */
3732 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3734 struct bfd_link_info
*info
= inf
;
3735 struct ppc_elf_link_hash_entry
*eh
;
3736 struct ppc_elf_link_hash_table
*htab
;
3737 struct ppc_elf_dyn_relocs
*p
;
3739 if (h
->root
.type
== bfd_link_hash_indirect
)
3742 if (h
->root
.type
== bfd_link_hash_warning
)
3743 /* When warning symbols are created, they **replace** the "real"
3744 entry in the hash table, thus we never get to see the real
3745 symbol in a hash traversal. So look at it now. */
3746 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3748 htab
= ppc_elf_hash_table (info
);
3749 if (htab
->elf
.dynamic_sections_created
3750 && h
->plt
.refcount
> 0)
3752 /* Make sure this symbol is output as a dynamic symbol. */
3753 if (h
->dynindx
== -1
3754 && !h
->forced_local
)
3756 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3761 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3763 asection
*s
= htab
->plt
;
3765 /* If this is the first .plt entry, make room for the special
3768 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
3770 /* The PowerPC PLT is actually composed of two parts, the
3771 first part is 2 words (for a load and a jump), and then
3772 there is a remaining word available at the end. */
3773 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3775 * ((s
->size
- PLT_INITIAL_ENTRY_SIZE
)
3776 / PLT_ENTRY_SIZE
)));
3778 /* If this symbol is not defined in a regular file, and we
3779 are not generating a shared library, then set the symbol
3780 to this location in the .plt. This is required to make
3781 function pointers compare as equal between the normal
3782 executable and the shared library. */
3786 h
->root
.u
.def
.section
= s
;
3787 h
->root
.u
.def
.value
= h
->plt
.offset
;
3790 /* Make room for this entry. After the 8192nd entry, room
3791 for two entries is allocated. */
3792 s
->size
+= PLT_ENTRY_SIZE
;
3793 if ((s
->size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3794 > PLT_NUM_SINGLE_ENTRIES
)
3795 s
->size
+= PLT_ENTRY_SIZE
;
3797 /* We also need to make an entry in the .rela.plt section. */
3798 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
3802 h
->plt
.offset
= (bfd_vma
) -1;
3808 h
->plt
.offset
= (bfd_vma
) -1;
3812 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3813 if (eh
->elf
.got
.refcount
> 0)
3815 /* Make sure this symbol is output as a dynamic symbol. */
3816 if (eh
->elf
.dynindx
== -1
3817 && !eh
->elf
.forced_local
)
3819 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
3823 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3824 && !eh
->elf
.def_dynamic
)
3825 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3826 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3830 eh
->elf
.got
.offset
= htab
->got
->size
;
3831 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3833 if ((eh
->tls_mask
& TLS_LD
) != 0)
3834 htab
->got
->size
+= 8;
3835 if ((eh
->tls_mask
& TLS_GD
) != 0)
3836 htab
->got
->size
+= 8;
3837 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3838 htab
->got
->size
+= 4;
3839 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3840 htab
->got
->size
+= 4;
3843 htab
->got
->size
+= 4;
3844 dyn
= htab
->elf
.dynamic_sections_created
;
3846 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3847 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3848 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3850 /* All the entries we allocated need relocs. */
3852 += ((htab
->got
->size
- eh
->elf
.got
.offset
) / 4
3853 * sizeof (Elf32_External_Rela
));
3854 /* Except LD only needs one. */
3855 if ((eh
->tls_mask
& TLS_LD
) != 0)
3856 htab
->relgot
->size
-= sizeof (Elf32_External_Rela
);
3861 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3863 if (eh
->dyn_relocs
== NULL
)
3866 /* In the shared -Bsymbolic case, discard space allocated for
3867 dynamic pc-relative relocs against symbols which turn out to be
3868 defined in regular objects. For the normal shared case, discard
3869 space for relocs that have become local due to symbol visibility
3874 /* Relocs that use pc_count are those that appear on a call insn,
3875 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3876 generated via assembly. We want calls to protected symbols to
3877 resolve directly to the function rather than going via the plt.
3878 If people want function pointer comparisons to work as expected
3879 then they should avoid writing weird assembly. */
3880 if (SYMBOL_CALLS_LOCAL (info
, h
))
3882 struct ppc_elf_dyn_relocs
**pp
;
3884 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3886 p
->count
-= p
->pc_count
;
3895 /* Also discard relocs on undefined weak syms with non-default
3897 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3898 && h
->root
.type
== bfd_link_hash_undefweak
)
3899 eh
->dyn_relocs
= NULL
;
3901 /* Make sure undefined weak symbols are output as a dynamic symbol
3904 && eh
->dyn_relocs
!= NULL
3906 && h
->root
.type
== bfd_link_hash_undefweak
3907 && !h
->forced_local
)
3909 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3913 else if (ELIMINATE_COPY_RELOCS
)
3915 /* For the non-shared case, discard space for relocs against
3916 symbols which turn out to need copy relocs or are not
3923 /* Make sure this symbol is output as a dynamic symbol.
3924 Undefined weak syms won't yet be marked as dynamic. */
3925 if (h
->dynindx
== -1
3926 && !h
->forced_local
)
3928 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3932 /* If that succeeded, we know we'll be keeping all the
3934 if (h
->dynindx
!= -1)
3938 eh
->dyn_relocs
= NULL
;
3943 /* Finally, allocate space. */
3944 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3946 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3947 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3953 /* Find any dynamic relocs that apply to read-only sections. */
3956 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3958 struct ppc_elf_dyn_relocs
*p
;
3960 if (h
->root
.type
== bfd_link_hash_indirect
)
3963 if (h
->root
.type
== bfd_link_hash_warning
)
3964 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3966 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3968 asection
*s
= p
->sec
->output_section
;
3971 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3972 == (SEC_READONLY
| SEC_ALLOC
)))
3974 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3976 /* Not an error, just cut short the traversal. */
3983 /* Set the sizes of the dynamic sections. */
3986 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3987 struct bfd_link_info
*info
)
3989 struct ppc_elf_link_hash_table
*htab
;
3995 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3998 htab
= ppc_elf_hash_table (info
);
3999 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4001 if (elf_hash_table (info
)->dynamic_sections_created
)
4003 /* Set the contents of the .interp section to the interpreter. */
4004 if (info
->executable
)
4006 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
4007 BFD_ASSERT (s
!= NULL
);
4008 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4009 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4013 if (htab
->tlsld_got
.refcount
> 0)
4015 htab
->tlsld_got
.offset
= htab
->got
->size
;
4016 htab
->got
->size
+= 8;
4018 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
4021 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
4023 /* Set up .got offsets for local syms, and space for local dynamic
4025 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4027 bfd_signed_vma
*local_got
;
4028 bfd_signed_vma
*end_local_got
;
4030 bfd_size_type locsymcount
;
4031 Elf_Internal_Shdr
*symtab_hdr
;
4034 if (!is_ppc_elf_target (ibfd
->xvec
))
4037 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4039 struct ppc_elf_dyn_relocs
*p
;
4041 for (p
= ((struct ppc_elf_dyn_relocs
*)
4042 elf_section_data (s
)->local_dynrel
);
4046 if (!bfd_is_abs_section (p
->sec
)
4047 && bfd_is_abs_section (p
->sec
->output_section
))
4049 /* Input section has been discarded, either because
4050 it is a copy of a linkonce section or due to
4051 linker script /DISCARD/, so we'll be discarding
4054 else if (p
->count
!= 0)
4056 elf_section_data (p
->sec
)->sreloc
->size
4057 += p
->count
* sizeof (Elf32_External_Rela
);
4058 if ((p
->sec
->output_section
->flags
4059 & (SEC_READONLY
| SEC_ALLOC
))
4060 == (SEC_READONLY
| SEC_ALLOC
))
4061 info
->flags
|= DF_TEXTREL
;
4066 local_got
= elf_local_got_refcounts (ibfd
);
4070 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4071 locsymcount
= symtab_hdr
->sh_info
;
4072 end_local_got
= local_got
+ locsymcount
;
4073 lgot_masks
= (char *) end_local_got
;
4075 srel
= htab
->relgot
;
4076 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
4079 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
4081 /* If just an LD reloc, we'll just use
4082 htab->tlsld_got.offset. */
4083 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
4085 htab
->tlsld_got
.offset
= s
->size
;
4088 srel
->size
+= sizeof (Elf32_External_Rela
);
4090 *local_got
= (bfd_vma
) -1;
4094 *local_got
= s
->size
;
4095 if ((*lgot_masks
& TLS_TLS
) != 0)
4097 if ((*lgot_masks
& TLS_GD
) != 0)
4099 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4101 if ((*lgot_masks
& TLS_DTPREL
) != 0)
4107 srel
->size
+= ((s
->size
- *local_got
) / 4
4108 * sizeof (Elf32_External_Rela
));
4112 *local_got
= (bfd_vma
) -1;
4115 /* Allocate space for global sym dynamic relocs. */
4116 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
4118 /* We've now determined the sizes of the various dynamic sections.
4119 Allocate memory for them. */
4121 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4123 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4129 /* Strip this section if we don't need it; see the
4132 else if ((htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
4133 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
4136 /* Don't strip these sections. We need them because they
4137 define _SDA_BASE_ and _SDA2_BASE_. crt1.o makes a
4138 reference to _SDA_BASE_ to set up r13. */
4141 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4145 /* If we don't need this section, strip it from the
4146 output file. This is mostly to handle .rela.bss and
4147 .rela.plt. We must create both sections in
4148 create_dynamic_sections, because they must be created
4149 before the linker maps input sections to output
4150 sections. The linker does that before
4151 adjust_dynamic_symbol is called, and it is that
4152 function which decides whether anything needs to go
4153 into these sections. */
4157 /* Remember whether there are any relocation sections. */
4160 /* We use the reloc_count field as a counter if we need
4161 to copy relocs into the output file. */
4167 /* It's not one of our sections, so don't allocate space. */
4173 _bfd_strip_section_from_output (info
, s
);
4177 /* Allocate memory for the section contents. */
4178 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
4179 if (s
->contents
== NULL
)
4183 if (htab
->elf
.dynamic_sections_created
)
4185 /* Add some entries to the .dynamic section. We fill in the
4186 values later, in ppc_elf_finish_dynamic_sections, but we
4187 must add the entries now so that we get the correct size for
4188 the .dynamic section. The DT_DEBUG entry is filled in by the
4189 dynamic linker and used by the debugger. */
4190 #define add_dynamic_entry(TAG, VAL) \
4191 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4193 if (info
->executable
)
4195 if (!add_dynamic_entry (DT_DEBUG
, 0))
4199 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
4201 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4202 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4203 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4204 || !add_dynamic_entry (DT_JMPREL
, 0))
4210 if (!add_dynamic_entry (DT_RELA
, 0)
4211 || !add_dynamic_entry (DT_RELASZ
, 0)
4212 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4216 /* If any dynamic relocs apply to a read-only section, then we
4217 need a DT_TEXTREL entry. */
4218 if ((info
->flags
& DF_TEXTREL
) == 0)
4219 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
4222 if ((info
->flags
& DF_TEXTREL
) != 0)
4224 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4228 #undef add_dynamic_entry
4233 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
4235 static const int shared_stub_entry
[] =
4237 0x7c0802a6, /* mflr 0 */
4238 0x429f0005, /* bcl 20, 31, .Lxxx */
4239 0x7d6802a6, /* mflr 11 */
4240 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
4241 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
4242 0x7c0803a6, /* mtlr 0 */
4243 0x7d6903a6, /* mtctr 11 */
4244 0x4e800420, /* bctr */
4247 static const int stub_entry
[] =
4249 0x3d600000, /* lis 11,xxx@ha */
4250 0x396b0000, /* addi 11,11,xxx@l */
4251 0x7d6903a6, /* mtctr 11 */
4252 0x4e800420, /* bctr */
4256 ppc_elf_relax_section (bfd
*abfd
,
4258 struct bfd_link_info
*link_info
,
4263 struct one_fixup
*next
;
4269 Elf_Internal_Shdr
*symtab_hdr
;
4270 bfd_byte
*contents
= NULL
;
4271 Elf_Internal_Sym
*isymbuf
= NULL
;
4272 Elf_Internal_Rela
*internal_relocs
= NULL
;
4273 Elf_Internal_Rela
*irel
, *irelend
;
4274 struct one_fixup
*fixups
= NULL
;
4275 bfd_boolean changed
;
4276 struct ppc_elf_link_hash_table
*ppc_info
;
4277 bfd_size_type trampoff
;
4281 /* Nothing to do if there are no relocations. */
4282 if ((isec
->flags
& SEC_RELOC
) == 0 || isec
->reloc_count
== 0)
4285 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
4286 /* Space for a branch around any trampolines. */
4289 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4291 /* Get a copy of the native relocations. */
4292 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
4293 link_info
->keep_memory
);
4294 if (internal_relocs
== NULL
)
4297 ppc_info
= ppc_elf_hash_table (link_info
);
4298 irelend
= internal_relocs
+ isec
->reloc_count
;
4300 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
4302 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
4303 bfd_vma symaddr
, reladdr
, toff
, roff
;
4305 struct one_fixup
*f
;
4306 size_t insn_offset
= 0;
4307 bfd_vma max_branch_offset
, val
;
4310 unsigned char sym_type
;
4315 case R_PPC_LOCAL24PC
:
4316 case R_PPC_PLTREL24
:
4317 max_branch_offset
= 1 << 25;
4321 case R_PPC_REL14_BRTAKEN
:
4322 case R_PPC_REL14_BRNTAKEN
:
4323 max_branch_offset
= 1 << 15;
4330 /* Get the value of the symbol referred to by the reloc. */
4331 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
4333 /* A local symbol. */
4334 Elf_Internal_Sym
*isym
;
4336 /* Read this BFD's local symbols. */
4337 if (isymbuf
== NULL
)
4339 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4340 if (isymbuf
== NULL
)
4341 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
4342 symtab_hdr
->sh_info
, 0,
4347 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
4348 if (isym
->st_shndx
== SHN_UNDEF
)
4349 continue; /* We can't do anything with undefined symbols. */
4350 else if (isym
->st_shndx
== SHN_ABS
)
4351 tsec
= bfd_abs_section_ptr
;
4352 else if (isym
->st_shndx
== SHN_COMMON
)
4353 tsec
= bfd_com_section_ptr
;
4355 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4357 toff
= isym
->st_value
;
4358 sym_type
= ELF_ST_TYPE (isym
->st_info
);
4362 /* Global symbol handling. */
4364 struct elf_link_hash_entry
*h
;
4366 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
4367 h
= elf_sym_hashes (abfd
)[indx
];
4369 while (h
->root
.type
== bfd_link_hash_indirect
4370 || h
->root
.type
== bfd_link_hash_warning
)
4371 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4373 if (r_type
== R_PPC_PLTREL24
4374 && ppc_info
->plt
!= NULL
4375 && h
->plt
.offset
!= (bfd_vma
) -1)
4377 tsec
= ppc_info
->plt
;
4378 toff
= h
->plt
.offset
;
4380 else if (h
->root
.type
== bfd_link_hash_defined
4381 || h
->root
.type
== bfd_link_hash_defweak
)
4383 tsec
= h
->root
.u
.def
.section
;
4384 toff
= h
->root
.u
.def
.value
;
4392 /* If the branch and target are in the same section, you have
4393 no hope of adding stubs. We'll error out later should the
4398 /* There probably isn't any reason to handle symbols in
4399 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
4400 attribute for a code section, and we are only looking at
4401 branches. However, implement it correctly here as a
4402 reference for other target relax_section functions. */
4403 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
4405 /* At this stage in linking, no SEC_MERGE symbol has been
4406 adjusted, so all references to such symbols need to be
4407 passed through _bfd_merged_section_offset. (Later, in
4408 relocate_section, all SEC_MERGE symbols *except* for
4409 section symbols have been adjusted.)
4411 gas may reduce relocations against symbols in SEC_MERGE
4412 sections to a relocation against the section symbol when
4413 the original addend was zero. When the reloc is against
4414 a section symbol we should include the addend in the
4415 offset passed to _bfd_merged_section_offset, since the
4416 location of interest is the original symbol. On the
4417 other hand, an access to "sym+addend" where "sym" is not
4418 a section symbol should not include the addend; Such an
4419 access is presumed to be an offset from "sym"; The
4420 location of interest is just "sym". */
4421 if (sym_type
== STT_SECTION
)
4422 toff
+= irel
->r_addend
;
4424 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
4425 elf_section_data (tsec
)->sec_info
,
4428 if (sym_type
!= STT_SECTION
)
4429 toff
+= irel
->r_addend
;
4432 toff
+= irel
->r_addend
;
4434 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
4436 roff
= irel
->r_offset
;
4437 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
4439 /* If the branch is in range, no need to do anything. */
4440 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
4443 /* Look for an existing fixup to this address. */
4444 for (f
= fixups
; f
; f
= f
->next
)
4445 if (f
->tsec
== tsec
&& f
->toff
== toff
)
4451 unsigned long stub_rtype
;
4453 val
= trampoff
- roff
;
4454 if (val
>= max_branch_offset
)
4455 /* Oh dear, we can't reach a trampoline. Don't try to add
4456 one. We'll report an error later. */
4459 if (link_info
->shared
)
4461 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
4463 stub_rtype
= R_PPC_RELAX32PC
;
4467 size
= 4 * ARRAY_SIZE (stub_entry
);
4469 stub_rtype
= R_PPC_RELAX32
;
4472 if (R_PPC_RELAX32_PLT
- R_PPC_RELAX32
4473 != R_PPC_RELAX32PC_PLT
- R_PPC_RELAX32PC
)
4475 if (tsec
== ppc_info
->plt
)
4476 stub_rtype
+= R_PPC_RELAX32_PLT
- R_PPC_RELAX32
;
4478 /* Hijack the old relocation. Since we need two
4479 relocations for this use a "composite" reloc. */
4480 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
4482 irel
->r_offset
= trampoff
+ insn_offset
;
4484 /* Record the fixup so we don't do it again this section. */
4485 f
= bfd_malloc (sizeof (*f
));
4489 f
->trampoff
= trampoff
;
4496 val
= f
->trampoff
- roff
;
4497 if (val
>= max_branch_offset
)
4500 /* Nop out the reloc, since we're finalizing things here. */
4501 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
4504 /* Get the section contents. */
4505 if (contents
== NULL
)
4507 /* Get cached copy if it exists. */
4508 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
4509 contents
= elf_section_data (isec
)->this_hdr
.contents
;
4512 /* Go get them off disk. */
4513 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
4518 /* Fix up the existing branch to hit the trampoline. */
4519 hit_addr
= contents
+ roff
;
4523 case R_PPC_LOCAL24PC
:
4524 case R_PPC_PLTREL24
:
4525 t0
= bfd_get_32 (abfd
, hit_addr
);
4527 t0
|= val
& 0x3fffffc;
4528 bfd_put_32 (abfd
, t0
, hit_addr
);
4532 case R_PPC_REL14_BRTAKEN
:
4533 case R_PPC_REL14_BRNTAKEN
:
4534 t0
= bfd_get_32 (abfd
, hit_addr
);
4537 bfd_put_32 (abfd
, t0
, hit_addr
);
4542 /* Write out the trampolines. */
4543 changed
= fixups
!= NULL
;
4553 struct one_fixup
*f
= fixups
;
4554 fixups
= fixups
->next
;
4559 contents
= bfd_realloc (contents
, trampoff
);
4560 if (contents
== NULL
)
4563 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
4564 /* Branch around the trampolines. */
4565 val
= trampoff
- isec
->size
+ 0x48000000;
4566 dest
= contents
+ isec
->size
;
4567 isec
->size
= trampoff
;
4568 bfd_put_32 (abfd
, val
, dest
);
4571 if (link_info
->shared
)
4573 stub
= shared_stub_entry
;
4574 size
= ARRAY_SIZE (shared_stub_entry
);
4579 size
= ARRAY_SIZE (stub_entry
);
4583 while (dest
< contents
+ trampoff
)
4585 bfd_put_32 (abfd
, stub
[i
], dest
);
4591 BFD_ASSERT (i
== 0);
4595 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
4597 if (! link_info
->keep_memory
)
4601 /* Cache the symbols for elf_link_input_bfd. */
4602 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
4606 if (contents
!= NULL
4607 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
4609 if (!changed
&& !link_info
->keep_memory
)
4613 /* Cache the section contents for elf_link_input_bfd. */
4614 elf_section_data (isec
)->this_hdr
.contents
= contents
;
4618 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
4621 free (internal_relocs
);
4623 elf_section_data (isec
)->relocs
= internal_relocs
;
4630 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
4632 if (contents
!= NULL
4633 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
4635 if (internal_relocs
!= NULL
4636 && elf_section_data (isec
)->relocs
!= internal_relocs
)
4637 free (internal_relocs
);
4641 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
4643 /* Fill in the address for a pointer generated in a linker section. */
4646 elf_finish_pointer_linker_section (bfd
*output_bfd
,
4648 struct bfd_link_info
*info
,
4649 elf_linker_section_t
*lsect
,
4650 struct elf_link_hash_entry
*h
,
4652 const Elf_Internal_Rela
*rel
)
4654 elf_linker_section_pointers_t
*linker_section_ptr
;
4656 BFD_ASSERT (lsect
!= NULL
);
4660 /* Handle global symbol. */
4661 struct ppc_elf_link_hash_entry
*eh
;
4663 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4665 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
4669 BFD_ASSERT (linker_section_ptr
!= NULL
);
4671 if (! elf_hash_table (info
)->dynamic_sections_created
4676 /* This is actually a static link, or it is a
4677 -Bsymbolic link and the symbol is defined
4678 locally. We must initialize this entry in the
4681 When doing a dynamic link, we create a .rela.<xxx>
4682 relocation entry to initialize the value. This
4683 is done in the finish_dynamic_symbol routine. */
4684 if (!linker_section_ptr
->written_address_p
)
4686 linker_section_ptr
->written_address_p
= TRUE
;
4687 bfd_put_ptr (output_bfd
,
4688 relocation
+ linker_section_ptr
->addend
,
4689 (lsect
->section
->contents
4690 + linker_section_ptr
->offset
));
4696 /* Handle local symbol. */
4697 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
4698 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
4699 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
4700 linker_section_ptr
= (elf_find_pointer_linker_section
4701 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
4705 BFD_ASSERT (linker_section_ptr
!= NULL
);
4707 /* Write out pointer if it hasn't been rewritten out before. */
4708 if (!linker_section_ptr
->written_address_p
)
4710 linker_section_ptr
->written_address_p
= TRUE
;
4711 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
4712 lsect
->section
->contents
+ linker_section_ptr
->offset
);
4716 relocation
= (lsect
->section
->output_offset
4717 + linker_section_ptr
->offset
4718 - lsect
->sym_offset
);
4722 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
4723 lsect
->name
, (long) relocation
, (long) relocation
);
4726 /* Subtract out the addend, because it will get added back in by the normal
4728 return relocation
- linker_section_ptr
->addend
;
4731 /* The RELOCATE_SECTION function is called by the ELF backend linker
4732 to handle the relocations for a section.
4734 The relocs are always passed as Rela structures; if the section
4735 actually uses Rel structures, the r_addend field will always be
4738 This function is responsible for adjust the section contents as
4739 necessary, and (if using Rela relocs and generating a
4740 relocatable output file) adjusting the reloc addend as
4743 This function does not have to worry about setting the reloc
4744 address or the reloc symbol index.
4746 LOCAL_SYMS is a pointer to the swapped in local symbols.
4748 LOCAL_SECTIONS is an array giving the section in the input file
4749 corresponding to the st_shndx field of each local symbol.
4751 The global hash table entry for the global symbols can be found
4752 via elf_sym_hashes (input_bfd).
4754 When generating relocatable output, this function must handle
4755 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4756 going to be the section symbol corresponding to the output
4757 section, which means that the addend must be adjusted
4761 ppc_elf_relocate_section (bfd
*output_bfd
,
4762 struct bfd_link_info
*info
,
4764 asection
*input_section
,
4766 Elf_Internal_Rela
*relocs
,
4767 Elf_Internal_Sym
*local_syms
,
4768 asection
**local_sections
)
4770 Elf_Internal_Shdr
*symtab_hdr
;
4771 struct elf_link_hash_entry
**sym_hashes
;
4772 struct ppc_elf_link_hash_table
*htab
;
4773 Elf_Internal_Rela
*rel
;
4774 Elf_Internal_Rela
*relend
;
4775 Elf_Internal_Rela outrel
;
4777 asection
*sreloc
= NULL
;
4778 bfd_vma
*local_got_offsets
;
4779 bfd_boolean ret
= TRUE
;
4782 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
4783 "%ld relocations%s",
4784 input_bfd
, input_section
,
4785 (long) input_section
->reloc_count
,
4786 (info
->relocatable
) ? " (relocatable)" : "");
4789 if (info
->relocatable
)
4792 /* Initialize howto table if not already done. */
4793 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4794 ppc_elf_howto_init ();
4796 htab
= ppc_elf_hash_table (info
);
4797 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4798 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4799 sym_hashes
= elf_sym_hashes (input_bfd
);
4801 relend
= relocs
+ input_section
->reloc_count
;
4802 for (; rel
< relend
; rel
++)
4804 enum elf_ppc_reloc_type r_type
;
4806 bfd_reloc_status_type r
;
4807 Elf_Internal_Sym
*sym
;
4809 struct elf_link_hash_entry
*h
;
4810 const char *sym_name
;
4811 reloc_howto_type
*howto
;
4812 unsigned long r_symndx
;
4814 bfd_vma branch_bit
, insn
, from
;
4815 bfd_boolean unresolved_reloc
;
4817 unsigned int tls_type
, tls_mask
, tls_gd
;
4819 r_type
= ELF32_R_TYPE (rel
->r_info
);
4823 unresolved_reloc
= FALSE
;
4825 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4827 if (r_symndx
< symtab_hdr
->sh_info
)
4829 sym
= local_syms
+ r_symndx
;
4830 sec
= local_sections
[r_symndx
];
4831 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
);
4833 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4837 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4838 r_symndx
, symtab_hdr
, sym_hashes
,
4840 unresolved_reloc
, warned
);
4842 sym_name
= h
->root
.root
.string
;
4845 /* TLS optimizations. Replace instruction sequences and relocs
4846 based on information we collected in tls_optimize. We edit
4847 RELOCS so that --emit-relocs will output something sensible
4848 for the final instruction stream. */
4851 if (IS_PPC_TLS_RELOC (r_type
))
4854 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4855 else if (local_got_offsets
!= NULL
)
4858 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4859 tls_mask
= lgot_masks
[r_symndx
];
4863 /* Ensure reloc mapping code below stays sane. */
4864 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4865 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4866 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4867 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4868 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4869 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4870 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4871 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4878 case R_PPC_GOT_TPREL16
:
4879 case R_PPC_GOT_TPREL16_LO
:
4881 && (tls_mask
& TLS_TPREL
) == 0)
4884 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4886 insn
|= 0x3c020000; /* addis 0,2,0 */
4887 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4888 r_type
= R_PPC_TPREL16_HA
;
4889 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4895 && (tls_mask
& TLS_TPREL
) == 0)
4898 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4899 if ((insn
& ((31 << 26) | (31 << 11)))
4900 == ((31 << 26) | (2 << 11)))
4901 rtra
= insn
& ((1 << 26) - (1 << 16));
4902 else if ((insn
& ((31 << 26) | (31 << 16)))
4903 == ((31 << 26) | (2 << 16)))
4904 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4907 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4910 else if ((insn
& (31 << 1)) == 23 << 1
4911 && ((insn
& (31 << 6)) < 14 << 6
4912 || ((insn
& (31 << 6)) >= 16 << 6
4913 && (insn
& (31 << 6)) < 24 << 6)))
4914 /* load and store indexed -> dform. */
4915 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4916 else if ((insn
& (31 << 1)) == 21 << 1
4917 && (insn
& (0x1a << 6)) == 0)
4918 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4919 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4920 | ((insn
>> 6) & 1));
4921 else if ((insn
& (31 << 1)) == 21 << 1
4922 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4924 insn
= (58 << 26) | 2;
4928 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4929 r_type
= R_PPC_TPREL16_LO
;
4930 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4931 /* Was PPC_TLS which sits on insn boundary, now
4932 PPC_TPREL16_LO which is at insn+2. */
4937 case R_PPC_GOT_TLSGD16_HI
:
4938 case R_PPC_GOT_TLSGD16_HA
:
4939 tls_gd
= TLS_TPRELGD
;
4940 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4944 case R_PPC_GOT_TLSLD16_HI
:
4945 case R_PPC_GOT_TLSLD16_HA
:
4946 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4949 if ((tls_mask
& tls_gd
) != 0)
4950 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4951 + R_PPC_GOT_TPREL16
);
4954 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4956 r_type
= R_PPC_NONE
;
4958 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4962 case R_PPC_GOT_TLSGD16
:
4963 case R_PPC_GOT_TLSGD16_LO
:
4964 tls_gd
= TLS_TPRELGD
;
4965 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4966 goto tls_get_addr_check
;
4969 case R_PPC_GOT_TLSLD16
:
4970 case R_PPC_GOT_TLSLD16_LO
:
4971 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4974 if (rel
+ 1 < relend
)
4976 enum elf_ppc_reloc_type r_type2
;
4977 unsigned long r_symndx2
;
4978 struct elf_link_hash_entry
*h2
;
4979 bfd_vma insn1
, insn2
;
4982 /* The next instruction should be a call to
4983 __tls_get_addr. Peek at the reloc to be sure. */
4984 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4985 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4986 if (r_symndx2
< symtab_hdr
->sh_info
4987 || (r_type2
!= R_PPC_REL14
4988 && r_type2
!= R_PPC_REL14_BRTAKEN
4989 && r_type2
!= R_PPC_REL14_BRNTAKEN
4990 && r_type2
!= R_PPC_REL24
4991 && r_type2
!= R_PPC_PLTREL24
))
4994 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4995 while (h2
->root
.type
== bfd_link_hash_indirect
4996 || h2
->root
.type
== bfd_link_hash_warning
)
4997 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4998 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
5001 /* OK, it checks out. Replace the call. */
5002 offset
= rel
[1].r_offset
;
5003 insn1
= bfd_get_32 (output_bfd
,
5004 contents
+ rel
->r_offset
- 2);
5005 if ((tls_mask
& tls_gd
) != 0)
5008 insn1
&= (1 << 26) - 1;
5009 insn1
|= 32 << 26; /* lwz */
5010 insn2
= 0x7c631214; /* add 3,3,2 */
5011 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
5012 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
5013 + R_PPC_GOT_TPREL16
);
5014 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5019 insn1
= 0x3c620000; /* addis 3,2,0 */
5020 insn2
= 0x38630000; /* addi 3,3,0 */
5023 /* Was an LD reloc. */
5025 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5026 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5028 r_type
= R_PPC_TPREL16_HA
;
5029 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5030 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
5032 rel
[1].r_offset
+= 2;
5034 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
5035 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
5038 /* We changed the symbol on an LD reloc. Start over
5039 in order to get h, sym, sec etc. right. */
5048 /* Handle other relocations that tweak non-addend part of insn. */
5055 /* Branch taken prediction relocations. */
5056 case R_PPC_ADDR14_BRTAKEN
:
5057 case R_PPC_REL14_BRTAKEN
:
5058 branch_bit
= BRANCH_PREDICT_BIT
;
5061 /* Branch not taken prediction relocations. */
5062 case R_PPC_ADDR14_BRNTAKEN
:
5063 case R_PPC_REL14_BRNTAKEN
:
5064 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5065 insn
&= ~BRANCH_PREDICT_BIT
;
5068 from
= (rel
->r_offset
5069 + input_section
->output_offset
5070 + input_section
->output_section
->vma
);
5072 /* Invert 'y' bit if not the default. */
5073 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
5074 insn
^= BRANCH_PREDICT_BIT
;
5076 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5080 addend
= rel
->r_addend
;
5083 if (r_type
< R_PPC_max
)
5084 howto
= ppc_elf_howto_table
[r_type
];
5088 (*_bfd_error_handler
)
5089 (_("%B: unknown relocation type %d for symbol %s"),
5090 input_bfd
, (int) r_type
, sym_name
);
5092 bfd_set_error (bfd_error_bad_value
);
5098 case R_PPC_EMB_MRKREF
:
5099 case R_PPC_GNU_VTINHERIT
:
5100 case R_PPC_GNU_VTENTRY
:
5103 /* GOT16 relocations. Like an ADDR16 using the symbol's
5104 address in the GOT as relocation value instead of the
5105 symbol's value itself. Also, create a GOT entry for the
5106 symbol and put the symbol value there. */
5107 case R_PPC_GOT_TLSGD16
:
5108 case R_PPC_GOT_TLSGD16_LO
:
5109 case R_PPC_GOT_TLSGD16_HI
:
5110 case R_PPC_GOT_TLSGD16_HA
:
5111 tls_type
= TLS_TLS
| TLS_GD
;
5114 case R_PPC_GOT_TLSLD16
:
5115 case R_PPC_GOT_TLSLD16_LO
:
5116 case R_PPC_GOT_TLSLD16_HI
:
5117 case R_PPC_GOT_TLSLD16_HA
:
5118 tls_type
= TLS_TLS
| TLS_LD
;
5121 case R_PPC_GOT_TPREL16
:
5122 case R_PPC_GOT_TPREL16_LO
:
5123 case R_PPC_GOT_TPREL16_HI
:
5124 case R_PPC_GOT_TPREL16_HA
:
5125 tls_type
= TLS_TLS
| TLS_TPREL
;
5128 case R_PPC_GOT_DTPREL16
:
5129 case R_PPC_GOT_DTPREL16_LO
:
5130 case R_PPC_GOT_DTPREL16_HI
:
5131 case R_PPC_GOT_DTPREL16_HA
:
5132 tls_type
= TLS_TLS
| TLS_DTPREL
;
5136 case R_PPC_GOT16_LO
:
5137 case R_PPC_GOT16_HI
:
5138 case R_PPC_GOT16_HA
:
5141 /* Relocation is to the entry for this symbol in the global
5147 if (htab
->got
== NULL
)
5151 if (tls_type
== (TLS_TLS
| TLS_LD
)
5153 || !h
->def_dynamic
))
5154 offp
= &htab
->tlsld_got
.offset
;
5158 dyn
= htab
->elf
.dynamic_sections_created
;
5159 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5161 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5162 /* This is actually a static link, or it is a
5163 -Bsymbolic link and the symbol is defined
5164 locally, or the symbol was forced to be local
5165 because of a version file. */
5170 unresolved_reloc
= FALSE
;
5172 offp
= &h
->got
.offset
;
5176 if (local_got_offsets
== NULL
)
5178 offp
= &local_got_offsets
[r_symndx
];
5181 /* The offset must always be a multiple of 4. We use the
5182 least significant bit to record whether we have already
5183 processed this entry. */
5189 unsigned int tls_m
= (tls_mask
5190 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5191 | TLS_TPREL
| TLS_TPRELGD
));
5193 if (offp
== &htab
->tlsld_got
.offset
)
5199 /* We might have multiple got entries for this sym.
5200 Initialize them all. */
5205 if ((tls_m
& TLS_LD
) != 0)
5207 tls_ty
= TLS_TLS
| TLS_LD
;
5210 else if ((tls_m
& TLS_GD
) != 0)
5212 tls_ty
= TLS_TLS
| TLS_GD
;
5215 else if ((tls_m
& TLS_DTPREL
) != 0)
5217 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5218 tls_m
&= ~TLS_DTPREL
;
5220 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5222 tls_ty
= TLS_TLS
| TLS_TPREL
;
5226 /* Generate relocs for the dynamic linker. */
5227 if ((info
->shared
|| indx
!= 0)
5229 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5230 || h
->root
.type
!= bfd_link_hash_undefweak
))
5232 outrel
.r_offset
= (htab
->got
->output_section
->vma
5233 + htab
->got
->output_offset
5235 outrel
.r_addend
= 0;
5236 if (tls_ty
& (TLS_LD
| TLS_GD
))
5238 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5239 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5241 loc
= htab
->relgot
->contents
;
5242 loc
+= (htab
->relgot
->reloc_count
++
5243 * sizeof (Elf32_External_Rela
));
5244 bfd_elf32_swap_reloca_out (output_bfd
,
5246 outrel
.r_offset
+= 4;
5248 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5251 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5252 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5253 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5254 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5256 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5258 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5261 outrel
.r_addend
+= relocation
;
5262 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5263 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5265 loc
= htab
->relgot
->contents
;
5266 loc
+= (htab
->relgot
->reloc_count
++
5267 * sizeof (Elf32_External_Rela
));
5268 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5271 /* Init the .got section contents if we're not
5272 emitting a reloc. */
5275 bfd_vma value
= relocation
;
5277 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5279 else if (tls_ty
!= 0)
5281 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5282 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5283 value
+= DTP_OFFSET
- TP_OFFSET
;
5285 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5287 bfd_put_32 (output_bfd
, value
,
5288 htab
->got
->contents
+ off
+ 4);
5292 bfd_put_32 (output_bfd
, value
,
5293 htab
->got
->contents
+ off
);
5297 if (tls_ty
& (TLS_LD
| TLS_GD
))
5306 if (off
>= (bfd_vma
) -2)
5309 if ((tls_type
& TLS_TLS
) != 0)
5311 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5313 if ((tls_mask
& TLS_LD
) != 0
5315 || !h
->def_dynamic
))
5317 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5319 if ((tls_mask
& TLS_GD
) != 0)
5321 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5323 if ((tls_mask
& TLS_DTPREL
) != 0)
5330 relocation
= htab
->got
->output_offset
+ off
- 4;
5332 /* Addends on got relocations don't make much sense.
5333 x+off@got is actually x@got+off, and since the got is
5334 generated by a hash table traversal, the value in the
5335 got at entry m+n bears little relation to the entry m. */
5337 (*_bfd_error_handler
)
5338 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5341 (long) rel
->r_offset
,
5347 /* Relocations that need no special processing. */
5348 case R_PPC_LOCAL24PC
:
5349 /* It makes no sense to point a local relocation
5350 at a symbol not in this object. */
5351 if (unresolved_reloc
)
5353 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5354 h
->root
.root
.string
,
5364 case R_PPC_DTPREL16
:
5365 case R_PPC_DTPREL16_LO
:
5366 case R_PPC_DTPREL16_HI
:
5367 case R_PPC_DTPREL16_HA
:
5368 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5371 /* Relocations that may need to be propagated if this is a shared
5374 case R_PPC_TPREL16_LO
:
5375 case R_PPC_TPREL16_HI
:
5376 case R_PPC_TPREL16_HA
:
5377 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5378 /* The TPREL16 relocs shouldn't really be used in shared
5379 libs as they will result in DT_TEXTREL being set, but
5380 support them anyway. */
5384 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5387 case R_PPC_DTPREL32
:
5388 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5391 case R_PPC_DTPMOD32
:
5399 case R_PPC_REL14_BRTAKEN
:
5400 case R_PPC_REL14_BRNTAKEN
:
5401 /* If these relocations are not to a named symbol, they can be
5402 handled right here, no need to bother the dynamic linker. */
5403 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5404 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5408 /* Relocations that always need to be propagated if this is a shared
5413 case R_PPC_ADDR16_LO
:
5414 case R_PPC_ADDR16_HI
:
5415 case R_PPC_ADDR16_HA
:
5417 case R_PPC_ADDR14_BRTAKEN
:
5418 case R_PPC_ADDR14_BRNTAKEN
:
5421 /* r_symndx will be zero only for relocs against symbols
5422 from removed linkonce sections, or sections discarded by
5431 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5432 || h
->root
.type
!= bfd_link_hash_undefweak
)
5433 && (MUST_BE_DYN_RELOC (r_type
)
5434 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5435 || (ELIMINATE_COPY_RELOCS
5437 && (input_section
->flags
& SEC_ALLOC
) != 0
5442 && !h
->def_regular
))
5447 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5448 "create relocation for %s\n",
5449 (h
&& h
->root
.root
.string
5450 ? h
->root
.root
.string
: "<unknown>"));
5453 /* When generating a shared object, these relocations
5454 are copied into the output file to be resolved at run
5460 name
= (bfd_elf_string_from_elf_section
5462 elf_elfheader (input_bfd
)->e_shstrndx
,
5463 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5467 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5468 && strcmp (bfd_get_section_name (input_bfd
,
5472 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5473 BFD_ASSERT (sreloc
!= NULL
);
5479 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5481 if (outrel
.r_offset
== (bfd_vma
) -1
5482 || outrel
.r_offset
== (bfd_vma
) -2)
5483 skip
= (int) outrel
.r_offset
;
5484 outrel
.r_offset
+= (input_section
->output_section
->vma
5485 + input_section
->output_offset
);
5488 memset (&outrel
, 0, sizeof outrel
);
5489 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5491 unresolved_reloc
= FALSE
;
5492 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5493 outrel
.r_addend
= rel
->r_addend
;
5497 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5499 if (r_type
== R_PPC_ADDR32
)
5500 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5505 if (bfd_is_abs_section (sec
))
5507 else if (sec
== NULL
|| sec
->owner
== NULL
)
5509 bfd_set_error (bfd_error_bad_value
);
5516 /* We are turning this relocation into one
5517 against a section symbol. It would be
5518 proper to subtract the symbol's value,
5519 osec->vma, from the emitted reloc addend,
5520 but ld.so expects buggy relocs. */
5521 osec
= sec
->output_section
;
5522 indx
= elf_section_data (osec
)->dynindx
;
5523 BFD_ASSERT (indx
> 0);
5526 printf ("indx=%d section=%s flags=%08x name=%s\n",
5527 indx
, osec
->name
, osec
->flags
,
5528 h
->root
.root
.string
);
5532 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5536 loc
= sreloc
->contents
;
5537 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5538 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5543 /* This reloc will be computed at runtime. We clear the memory
5544 so that it contains predictable value. */
5546 && ((input_section
->flags
& SEC_ALLOC
) != 0
5547 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5549 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5556 case R_PPC_RELAX32PC_PLT
:
5557 case R_PPC_RELAX32_PLT
:
5558 BFD_ASSERT (h
!= NULL
5559 && h
->plt
.offset
!= (bfd_vma
) -1
5560 && htab
->plt
!= NULL
);
5562 relocation
= (htab
->plt
->output_section
->vma
5563 + htab
->plt
->output_offset
5565 if (r_type
== R_PPC_RELAX32_PLT
)
5569 case R_PPC_RELAX32PC
:
5570 relocation
-= (input_section
->output_section
->vma
5571 + input_section
->output_offset
5572 + rel
->r_offset
- 4);
5581 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5582 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
5584 /* We're clearing the bits for R_PPC_ADDR16_HA
5585 and R_PPC_ADDR16_LO here. */
5589 /* t0 is HA, t1 is LO */
5590 relocation
+= addend
;
5591 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
5592 t1
|= relocation
& 0xffff;
5594 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
5595 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
5599 /* Indirect .sdata relocation. */
5600 case R_PPC_EMB_SDAI16
:
5601 BFD_ASSERT (htab
->sdata
!= NULL
);
5603 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5604 htab
->sdata
, h
, relocation
,
5608 /* Indirect .sdata2 relocation. */
5609 case R_PPC_EMB_SDA2I16
:
5610 BFD_ASSERT (htab
->sdata2
!= NULL
);
5612 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5613 htab
->sdata2
, h
, relocation
,
5617 /* Handle the TOC16 reloc. We want to use the offset within the .got
5618 section, not the actual VMA. This is appropriate when generating
5619 an embedded ELF object, for which the .got section acts like the
5620 AIX .toc section. */
5621 case R_PPC_TOC16
: /* phony GOT16 relocations */
5622 BFD_ASSERT (sec
!= NULL
);
5623 BFD_ASSERT (bfd_is_und_section (sec
)
5624 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5625 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
5627 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5630 case R_PPC_PLTREL24
:
5631 /* Relocation is to the entry for this symbol in the
5632 procedure linkage table. */
5633 BFD_ASSERT (h
!= NULL
);
5635 if (h
->plt
.offset
== (bfd_vma
) -1
5636 || htab
->plt
== NULL
)
5638 /* We didn't make a PLT entry for this symbol. This
5639 happens when statically linking PIC code, or when
5640 using -Bsymbolic. */
5644 unresolved_reloc
= FALSE
;
5645 relocation
= (htab
->plt
->output_section
->vma
5646 + htab
->plt
->output_offset
5650 /* Relocate against _SDA_BASE_. */
5651 case R_PPC_SDAREL16
:
5654 const struct elf_link_hash_entry
*sh
;
5656 BFD_ASSERT (sec
!= NULL
);
5657 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5658 if (! ((strncmp (name
, ".sdata", 6) == 0
5659 && (name
[6] == 0 || name
[6] == '.'))
5660 || (strncmp (name
, ".sbss", 5) == 0
5661 && (name
[5] == 0 || name
[5] == '.'))))
5663 (*_bfd_error_handler
)
5664 (_("%B: the target (%s) of a %s relocation is "
5665 "in the wrong output section (%s)"),
5671 sh
= htab
->sdata
->sym_hash
;
5672 addend
-= (sh
->root
.u
.def
.value
5673 + sh
->root
.u
.def
.section
->output_section
->vma
5674 + sh
->root
.u
.def
.section
->output_offset
);
5678 /* Relocate against _SDA2_BASE_. */
5679 case R_PPC_EMB_SDA2REL
:
5682 const struct elf_link_hash_entry
*sh
;
5684 BFD_ASSERT (sec
!= NULL
);
5685 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5686 if (! (strncmp (name
, ".sdata2", 7) == 0
5687 || strncmp (name
, ".sbss2", 6) == 0))
5689 (*_bfd_error_handler
)
5690 (_("%B: the target (%s) of a %s relocation is "
5691 "in the wrong output section (%s)"),
5697 bfd_set_error (bfd_error_bad_value
);
5701 sh
= htab
->sdata2
->sym_hash
;
5702 addend
-= (sh
->root
.u
.def
.value
5703 + sh
->root
.u
.def
.section
->output_section
->vma
5704 + sh
->root
.u
.def
.section
->output_offset
);
5708 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5709 case R_PPC_EMB_SDA21
:
5710 case R_PPC_EMB_RELSDA
:
5713 const struct elf_link_hash_entry
*sh
;
5716 BFD_ASSERT (sec
!= NULL
);
5717 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5718 if (((strncmp (name
, ".sdata", 6) == 0
5719 && (name
[6] == 0 || name
[6] == '.'))
5720 || (strncmp (name
, ".sbss", 5) == 0
5721 && (name
[5] == 0 || name
[5] == '.'))))
5724 sh
= htab
->sdata
->sym_hash
;
5725 addend
-= (sh
->root
.u
.def
.value
5726 + sh
->root
.u
.def
.section
->output_section
->vma
5727 + sh
->root
.u
.def
.section
->output_offset
);
5730 else if (strncmp (name
, ".sdata2", 7) == 0
5731 || strncmp (name
, ".sbss2", 6) == 0)
5734 sh
= htab
->sdata2
->sym_hash
;
5735 addend
-= (sh
->root
.u
.def
.value
5736 + sh
->root
.u
.def
.section
->output_section
->vma
5737 + sh
->root
.u
.def
.section
->output_offset
);
5740 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5741 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5748 (*_bfd_error_handler
)
5749 (_("%B: the target (%s) of a %s relocation is "
5750 "in the wrong output section (%s)"),
5756 bfd_set_error (bfd_error_bad_value
);
5761 if (r_type
== R_PPC_EMB_SDA21
)
5762 { /* fill in register field */
5763 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5764 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5765 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5770 /* Relocate against the beginning of the section. */
5772 case R_PPC_SECTOFF_LO
:
5773 case R_PPC_SECTOFF_HI
:
5774 case R_PPC_SECTOFF_HA
:
5775 BFD_ASSERT (sec
!= NULL
);
5776 addend
-= sec
->output_section
->vma
;
5779 /* Negative relocations. */
5780 case R_PPC_EMB_NADDR32
:
5781 case R_PPC_EMB_NADDR16
:
5782 case R_PPC_EMB_NADDR16_LO
:
5783 case R_PPC_EMB_NADDR16_HI
:
5784 case R_PPC_EMB_NADDR16_HA
:
5785 addend
-= 2 * relocation
;
5789 case R_PPC_GLOB_DAT
:
5790 case R_PPC_JMP_SLOT
:
5791 case R_PPC_RELATIVE
:
5793 case R_PPC_PLTREL32
:
5794 case R_PPC_PLT16_LO
:
5795 case R_PPC_PLT16_HI
:
5796 case R_PPC_PLT16_HA
:
5798 case R_PPC_EMB_RELSEC16
:
5799 case R_PPC_EMB_RELST_LO
:
5800 case R_PPC_EMB_RELST_HI
:
5801 case R_PPC_EMB_RELST_HA
:
5802 case R_PPC_EMB_BIT_FLD
:
5803 (*_bfd_error_handler
)
5804 (_("%B: relocation %s is not yet supported for symbol %s."),
5809 bfd_set_error (bfd_error_invalid_operation
);
5814 /* Do any further special processing. */
5820 case R_PPC_ADDR16_HA
:
5821 case R_PPC_GOT16_HA
:
5822 case R_PPC_PLT16_HA
:
5823 case R_PPC_SECTOFF_HA
:
5824 case R_PPC_TPREL16_HA
:
5825 case R_PPC_DTPREL16_HA
:
5826 case R_PPC_GOT_TLSGD16_HA
:
5827 case R_PPC_GOT_TLSLD16_HA
:
5828 case R_PPC_GOT_TPREL16_HA
:
5829 case R_PPC_GOT_DTPREL16_HA
:
5830 case R_PPC_EMB_NADDR16_HA
:
5831 case R_PPC_EMB_RELST_HA
:
5832 /* It's just possible that this symbol is a weak symbol
5833 that's not actually defined anywhere. In that case,
5834 'sec' would be NULL, and we should leave the symbol
5835 alone (it will be set to zero elsewhere in the link). */
5837 /* Add 0x10000 if sign bit in 0:15 is set.
5838 Bits 0:15 are not used. */
5844 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5845 "offset = %ld, addend = %ld\n",
5850 (long) rel
->r_offset
,
5854 if (unresolved_reloc
5855 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5858 (*_bfd_error_handler
)
5859 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5862 (long) rel
->r_offset
,
5868 r
= _bfd_final_link_relocate (howto
,
5876 if (r
!= bfd_reloc_ok
)
5878 if (sym_name
== NULL
)
5879 sym_name
= "(null)";
5880 if (r
== bfd_reloc_overflow
)
5885 && h
->root
.type
== bfd_link_hash_undefweak
5886 && howto
->pc_relative
)
5888 /* Assume this is a call protected by other code that
5889 detect the symbol is undefined. If this is the case,
5890 we can safely ignore the overflow. If not, the
5891 program is hosed anyway, and a little warning isn't
5897 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5898 (h
? &h
->root
: NULL
),
5909 (*_bfd_error_handler
)
5910 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
5911 input_bfd
, input_section
,
5912 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5919 fprintf (stderr
, "\n");
5925 /* Finish up dynamic symbol handling. We set the contents of various
5926 dynamic sections here. */
5929 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
5930 struct bfd_link_info
*info
,
5931 struct elf_link_hash_entry
*h
,
5932 Elf_Internal_Sym
*sym
)
5934 struct ppc_elf_link_hash_table
*htab
;
5937 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
5938 h
->root
.root
.string
);
5941 htab
= ppc_elf_hash_table (info
);
5942 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
5944 if (h
->plt
.offset
!= (bfd_vma
) -1)
5946 Elf_Internal_Rela rela
;
5948 bfd_vma reloc_index
;
5951 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
5954 /* This symbol has an entry in the procedure linkage table. Set
5957 BFD_ASSERT (h
->dynindx
!= -1);
5958 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
5960 /* We don't need to fill in the .plt. The ppc dynamic linker
5963 /* Fill in the entry in the .rela.plt section. */
5964 rela
.r_offset
= (htab
->plt
->output_section
->vma
5965 + htab
->plt
->output_offset
5967 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
5970 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
5971 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
5972 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
5973 loc
= (htab
->relplt
->contents
5974 + reloc_index
* sizeof (Elf32_External_Rela
));
5975 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
5977 if (!h
->def_regular
)
5979 /* Mark the symbol as undefined, rather than as defined in
5980 the .plt section. Leave the value alone. */
5981 sym
->st_shndx
= SHN_UNDEF
;
5982 /* If the symbol is weak, we do need to clear the value.
5983 Otherwise, the PLT entry would provide a definition for
5984 the symbol even if the symbol wasn't defined anywhere,
5985 and so the symbol would never be NULL. */
5986 if (!h
->ref_regular_nonweak
)
5994 Elf_Internal_Rela rela
;
5997 /* This symbols needs a copy reloc. Set it up. */
6000 fprintf (stderr
, ", copy");
6003 BFD_ASSERT (h
->dynindx
!= -1);
6005 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
6009 BFD_ASSERT (s
!= NULL
);
6011 rela
.r_offset
= (h
->root
.u
.def
.value
6012 + h
->root
.u
.def
.section
->output_section
->vma
6013 + h
->root
.u
.def
.section
->output_offset
);
6014 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
6016 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
6017 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6021 fprintf (stderr
, "\n");
6024 /* Mark some specially defined symbols as absolute. */
6025 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6026 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
6027 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
6028 sym
->st_shndx
= SHN_ABS
;
6033 static enum elf_reloc_type_class
6034 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
6036 switch (ELF32_R_TYPE (rela
->r_info
))
6038 case R_PPC_RELATIVE
:
6039 return reloc_class_relative
;
6042 case R_PPC_JMP_SLOT
:
6043 return reloc_class_plt
;
6045 return reloc_class_copy
;
6047 return reloc_class_normal
;
6051 /* Finish up the dynamic sections. */
6054 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
6055 struct bfd_link_info
*info
)
6058 struct ppc_elf_link_hash_table
*htab
;
6061 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
6064 htab
= ppc_elf_hash_table (info
);
6065 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
6067 if (htab
->elf
.dynamic_sections_created
)
6069 Elf32_External_Dyn
*dyncon
, *dynconend
;
6071 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
6073 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6074 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6075 for (; dyncon
< dynconend
; dyncon
++)
6077 Elf_Internal_Dyn dyn
;
6080 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
6086 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6090 dyn
.d_un
.d_val
= htab
->relplt
->size
;
6095 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6102 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6106 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
6107 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
6110 unsigned char *contents
= htab
->got
->contents
;
6111 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
6114 bfd_put_32 (output_bfd
, 0, contents
+ 4);
6116 bfd_put_32 (output_bfd
,
6117 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6120 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
6126 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6127 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6128 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6129 #define TARGET_BIG_NAME "elf32-powerpc"
6130 #define ELF_ARCH bfd_arch_powerpc
6131 #define ELF_MACHINE_CODE EM_PPC
6132 #ifdef __QNXTARGET__
6133 #define ELF_MAXPAGESIZE 0x1000
6135 #define ELF_MAXPAGESIZE 0x10000
6137 #define ELF_MINPAGESIZE 0x1000
6138 #define elf_info_to_howto ppc_elf_info_to_howto
6140 #ifdef EM_CYGNUS_POWERPC
6141 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6145 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6148 #define elf_backend_plt_not_loaded 1
6149 #define elf_backend_got_symbol_offset 4
6150 #define elf_backend_can_gc_sections 1
6151 #define elf_backend_can_refcount 1
6152 #define elf_backend_got_header_size 12
6153 #define elf_backend_rela_normal 1
6155 #define bfd_elf32_mkobject ppc_elf_mkobject
6156 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6157 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6158 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6159 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6160 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6162 #define elf_backend_object_p ppc_elf_object_p
6163 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6164 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6165 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6166 #define elf_backend_relocate_section ppc_elf_relocate_section
6167 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6168 #define elf_backend_check_relocs ppc_elf_check_relocs
6169 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6170 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6171 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6172 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6173 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6174 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6175 #define elf_backend_fake_sections ppc_elf_fake_sections
6176 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6177 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6178 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6179 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6180 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6181 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6182 #define elf_backend_write_section ppc_elf_write_section
6183 #define elf_backend_special_sections ppc_elf_special_sections
6184 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6186 #include "elf32-target.h"