1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* This file is based on a preliminary PowerPC ELF ABI. The
24 information may not match the final PowerPC ELF ABI. It includes
25 suggestions from the in-progress Embedded PowerPC ABI, and that
26 information may also not match. */
34 #include "elf32-ppc.h"
36 /* RELA relocations are used here. */
38 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc_elf_unhandled_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 /* Branch prediction bit for branch taken relocs. */
44 #define BRANCH_PREDICT_BIT 0x200000
45 /* Mask to set RA in memory instructions. */
46 #define RA_REGISTER_MASK 0x001f0000
47 /* Value to shift register by to insert RA. */
48 #define RA_REGISTER_SHIFT 16
50 /* The name of the dynamic interpreter. This is put in the .interp
52 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
54 /* For old-style PLT. */
55 /* The size in bytes of an entry in the procedure linkage table. */
56 #define PLT_ENTRY_SIZE 12
57 /* The initial size of the plt reserved for the dynamic linker. */
58 #define PLT_INITIAL_ENTRY_SIZE 72
59 /* The size of the gap between entries in the PLT. */
60 #define PLT_SLOT_SIZE 8
61 /* The number of single-slot PLT entries (the rest use two slots). */
62 #define PLT_NUM_SINGLE_ENTRIES 8192
64 /* For new-style .glink and .plt. */
65 #define GLINK_PLTRESOLVE 16*4
66 #define GLINK_ENTRY_SIZE 4*4
68 /* Some instructions. */
69 #define ADDIS_11_11 0x3d6b0000
70 #define ADDIS_11_30 0x3d7e0000
71 #define ADDIS_12_12 0x3d8c0000
72 #define ADDI_11_11 0x396b0000
73 #define ADD_0_11_11 0x7c0b5a14
74 #define ADD_11_0_11 0x7d605a14
76 #define BCL_20_31 0x429f0005
77 #define BCTR 0x4e800420
78 #define LIS_11 0x3d600000
79 #define LIS_12 0x3d800000
80 #define LWZU_0_12 0x840c0000
81 #define LWZ_0_12 0x800c0000
82 #define LWZ_11_11 0x816b0000
83 #define LWZ_11_30 0x817e0000
84 #define LWZ_12_12 0x818c0000
85 #define MFLR_0 0x7c0802a6
86 #define MFLR_12 0x7d8802a6
87 #define MTCTR_0 0x7c0903a6
88 #define MTCTR_11 0x7d6903a6
89 #define MTLR_0 0x7c0803a6
90 #define NOP 0x60000000
91 #define SUB_11_11_12 0x7d6c5850
93 /* Offset of tp and dtp pointers from start of TLS block. */
94 #define TP_OFFSET 0x7000
95 #define DTP_OFFSET 0x8000
97 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
99 static reloc_howto_type ppc_elf_howto_raw
[] = {
100 /* This reloc does nothing. */
101 HOWTO (R_PPC_NONE
, /* type */
103 2, /* size (0 = byte, 1 = short, 2 = long) */
105 FALSE
, /* pc_relative */
107 complain_overflow_bitfield
, /* complain_on_overflow */
108 bfd_elf_generic_reloc
, /* special_function */
109 "R_PPC_NONE", /* name */
110 FALSE
, /* partial_inplace */
113 FALSE
), /* pcrel_offset */
115 /* A standard 32 bit relocation. */
116 HOWTO (R_PPC_ADDR32
, /* type */
118 2, /* size (0 = byte, 1 = short, 2 = long) */
120 FALSE
, /* pc_relative */
122 complain_overflow_bitfield
, /* complain_on_overflow */
123 bfd_elf_generic_reloc
, /* special_function */
124 "R_PPC_ADDR32", /* name */
125 FALSE
, /* partial_inplace */
127 0xffffffff, /* dst_mask */
128 FALSE
), /* pcrel_offset */
130 /* An absolute 26 bit branch; the lower two bits must be zero.
131 FIXME: we don't check that, we just clear them. */
132 HOWTO (R_PPC_ADDR24
, /* type */
134 2, /* size (0 = byte, 1 = short, 2 = long) */
136 FALSE
, /* pc_relative */
138 complain_overflow_bitfield
, /* complain_on_overflow */
139 bfd_elf_generic_reloc
, /* special_function */
140 "R_PPC_ADDR24", /* name */
141 FALSE
, /* partial_inplace */
143 0x3fffffc, /* dst_mask */
144 FALSE
), /* pcrel_offset */
146 /* A standard 16 bit relocation. */
147 HOWTO (R_PPC_ADDR16
, /* type */
149 1, /* size (0 = byte, 1 = short, 2 = long) */
151 FALSE
, /* pc_relative */
153 complain_overflow_bitfield
, /* complain_on_overflow */
154 bfd_elf_generic_reloc
, /* special_function */
155 "R_PPC_ADDR16", /* name */
156 FALSE
, /* partial_inplace */
158 0xffff, /* dst_mask */
159 FALSE
), /* pcrel_offset */
161 /* A 16 bit relocation without overflow. */
162 HOWTO (R_PPC_ADDR16_LO
, /* type */
164 1, /* size (0 = byte, 1 = short, 2 = long) */
166 FALSE
, /* pc_relative */
168 complain_overflow_dont
,/* complain_on_overflow */
169 bfd_elf_generic_reloc
, /* special_function */
170 "R_PPC_ADDR16_LO", /* name */
171 FALSE
, /* partial_inplace */
173 0xffff, /* dst_mask */
174 FALSE
), /* pcrel_offset */
176 /* The high order 16 bits of an address. */
177 HOWTO (R_PPC_ADDR16_HI
, /* type */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
181 FALSE
, /* pc_relative */
183 complain_overflow_dont
, /* complain_on_overflow */
184 bfd_elf_generic_reloc
, /* special_function */
185 "R_PPC_ADDR16_HI", /* name */
186 FALSE
, /* partial_inplace */
188 0xffff, /* dst_mask */
189 FALSE
), /* pcrel_offset */
191 /* The high order 16 bits of an address, plus 1 if the contents of
192 the low 16 bits, treated as a signed number, is negative. */
193 HOWTO (R_PPC_ADDR16_HA
, /* type */
195 1, /* size (0 = byte, 1 = short, 2 = long) */
197 FALSE
, /* pc_relative */
199 complain_overflow_dont
, /* complain_on_overflow */
200 ppc_elf_addr16_ha_reloc
, /* special_function */
201 "R_PPC_ADDR16_HA", /* name */
202 FALSE
, /* partial_inplace */
204 0xffff, /* dst_mask */
205 FALSE
), /* pcrel_offset */
207 /* An absolute 16 bit branch; the lower two bits must be zero.
208 FIXME: we don't check that, we just clear them. */
209 HOWTO (R_PPC_ADDR14
, /* type */
211 2, /* size (0 = byte, 1 = short, 2 = long) */
213 FALSE
, /* pc_relative */
215 complain_overflow_bitfield
, /* complain_on_overflow */
216 bfd_elf_generic_reloc
, /* special_function */
217 "R_PPC_ADDR14", /* name */
218 FALSE
, /* partial_inplace */
220 0xfffc, /* dst_mask */
221 FALSE
), /* pcrel_offset */
223 /* An absolute 16 bit branch, for which bit 10 should be set to
224 indicate that the branch is expected to be taken. The lower two
225 bits must be zero. */
226 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_bitfield
, /* complain_on_overflow */
233 bfd_elf_generic_reloc
, /* special_function */
234 "R_PPC_ADDR14_BRTAKEN",/* name */
235 FALSE
, /* partial_inplace */
237 0xfffc, /* dst_mask */
238 FALSE
), /* pcrel_offset */
240 /* An absolute 16 bit branch, for which bit 10 should be set to
241 indicate that the branch is not expected to be taken. The lower
242 two bits must be zero. */
243 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 FALSE
, /* pc_relative */
249 complain_overflow_bitfield
, /* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_PPC_ADDR14_BRNTAKEN",/* name */
252 FALSE
, /* partial_inplace */
254 0xfffc, /* dst_mask */
255 FALSE
), /* pcrel_offset */
257 /* A relative 26 bit branch; the lower two bits must be zero. */
258 HOWTO (R_PPC_REL24
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 TRUE
, /* pc_relative */
264 complain_overflow_signed
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_PPC_REL24", /* name */
267 FALSE
, /* partial_inplace */
269 0x3fffffc, /* dst_mask */
270 TRUE
), /* pcrel_offset */
272 /* A relative 16 bit branch; the lower two bits must be zero. */
273 HOWTO (R_PPC_REL14
, /* type */
275 2, /* size (0 = byte, 1 = short, 2 = long) */
277 TRUE
, /* pc_relative */
279 complain_overflow_signed
, /* complain_on_overflow */
280 bfd_elf_generic_reloc
, /* special_function */
281 "R_PPC_REL14", /* name */
282 FALSE
, /* partial_inplace */
284 0xfffc, /* dst_mask */
285 TRUE
), /* pcrel_offset */
287 /* A relative 16 bit branch. Bit 10 should be set to indicate that
288 the branch is expected to be taken. The lower two bits must be
290 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 TRUE
, /* pc_relative */
296 complain_overflow_signed
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_PPC_REL14_BRTAKEN", /* name */
299 FALSE
, /* partial_inplace */
301 0xfffc, /* dst_mask */
302 TRUE
), /* pcrel_offset */
304 /* A relative 16 bit branch. Bit 10 should be set to indicate that
305 the branch is not expected to be taken. The lower two bits must
307 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 TRUE
, /* pc_relative */
313 complain_overflow_signed
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_PPC_REL14_BRNTAKEN",/* name */
316 FALSE
, /* partial_inplace */
318 0xfffc, /* dst_mask */
319 TRUE
), /* pcrel_offset */
321 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
323 HOWTO (R_PPC_GOT16
, /* type */
325 1, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_signed
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_PPC_GOT16", /* name */
332 FALSE
, /* partial_inplace */
334 0xffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
339 HOWTO (R_PPC_GOT16_LO
, /* type */
341 1, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_dont
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_PPC_GOT16_LO", /* name */
348 FALSE
, /* partial_inplace */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
355 HOWTO (R_PPC_GOT16_HI
, /* type */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
359 FALSE
, /* pc_relative */
361 complain_overflow_bitfield
, /* complain_on_overflow */
362 bfd_elf_generic_reloc
, /* special_function */
363 "R_PPC_GOT16_HI", /* name */
364 FALSE
, /* partial_inplace */
366 0xffff, /* dst_mask */
367 FALSE
), /* pcrel_offset */
369 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
371 HOWTO (R_PPC_GOT16_HA
, /* type */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
375 FALSE
, /* pc_relative */
377 complain_overflow_bitfield
, /* complain_on_overflow */
378 ppc_elf_addr16_ha_reloc
, /* special_function */
379 "R_PPC_GOT16_HA", /* name */
380 FALSE
, /* partial_inplace */
382 0xffff, /* dst_mask */
383 FALSE
), /* pcrel_offset */
385 /* Like R_PPC_REL24, but referring to the procedure linkage table
386 entry for the symbol. */
387 HOWTO (R_PPC_PLTREL24
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 TRUE
, /* pc_relative */
393 complain_overflow_signed
, /* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_PPC_PLTREL24", /* name */
396 FALSE
, /* partial_inplace */
398 0x3fffffc, /* dst_mask */
399 TRUE
), /* pcrel_offset */
401 /* This is used only by the dynamic linker. The symbol should exist
402 both in the object being run and in some shared library. The
403 dynamic linker copies the data addressed by the symbol from the
404 shared library into the object, because the object being
405 run has to have the data at some particular address. */
406 HOWTO (R_PPC_COPY
, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE
, /* pc_relative */
412 complain_overflow_bitfield
, /* complain_on_overflow */
413 bfd_elf_generic_reloc
, /* special_function */
414 "R_PPC_COPY", /* name */
415 FALSE
, /* partial_inplace */
418 FALSE
), /* pcrel_offset */
420 /* Like R_PPC_ADDR32, but used when setting global offset table
422 HOWTO (R_PPC_GLOB_DAT
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE
, /* pc_relative */
428 complain_overflow_bitfield
, /* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* special_function */
430 "R_PPC_GLOB_DAT", /* name */
431 FALSE
, /* partial_inplace */
433 0xffffffff, /* dst_mask */
434 FALSE
), /* pcrel_offset */
436 /* Marks a procedure linkage table entry for a symbol. */
437 HOWTO (R_PPC_JMP_SLOT
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 FALSE
, /* pc_relative */
443 complain_overflow_bitfield
, /* complain_on_overflow */
444 bfd_elf_generic_reloc
, /* special_function */
445 "R_PPC_JMP_SLOT", /* name */
446 FALSE
, /* partial_inplace */
449 FALSE
), /* pcrel_offset */
451 /* Used only by the dynamic linker. When the object is run, this
452 longword is set to the load address of the object, plus the
454 HOWTO (R_PPC_RELATIVE
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_bitfield
, /* complain_on_overflow */
461 bfd_elf_generic_reloc
, /* special_function */
462 "R_PPC_RELATIVE", /* name */
463 FALSE
, /* partial_inplace */
465 0xffffffff, /* dst_mask */
466 FALSE
), /* pcrel_offset */
468 /* Like R_PPC_REL24, but uses the value of the symbol within the
469 object rather than the final value. Normally used for
470 _GLOBAL_OFFSET_TABLE_. */
471 HOWTO (R_PPC_LOCAL24PC
, /* type */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
475 TRUE
, /* pc_relative */
477 complain_overflow_signed
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_PPC_LOCAL24PC", /* name */
480 FALSE
, /* partial_inplace */
482 0x3fffffc, /* dst_mask */
483 TRUE
), /* pcrel_offset */
485 /* Like R_PPC_ADDR32, but may be unaligned. */
486 HOWTO (R_PPC_UADDR32
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 FALSE
, /* pc_relative */
492 complain_overflow_bitfield
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_PPC_UADDR32", /* name */
495 FALSE
, /* partial_inplace */
497 0xffffffff, /* dst_mask */
498 FALSE
), /* pcrel_offset */
500 /* Like R_PPC_ADDR16, but may be unaligned. */
501 HOWTO (R_PPC_UADDR16
, /* type */
503 1, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE
, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_PPC_UADDR16", /* name */
510 FALSE
, /* partial_inplace */
512 0xffff, /* dst_mask */
513 FALSE
), /* pcrel_offset */
515 /* 32-bit PC relative */
516 HOWTO (R_PPC_REL32
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 TRUE
, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_PPC_REL32", /* name */
525 FALSE
, /* partial_inplace */
527 0xffffffff, /* dst_mask */
528 TRUE
), /* pcrel_offset */
530 /* 32-bit relocation to the symbol's procedure linkage table.
531 FIXME: not supported. */
532 HOWTO (R_PPC_PLT32
, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 FALSE
, /* pc_relative */
538 complain_overflow_bitfield
, /* complain_on_overflow */
539 bfd_elf_generic_reloc
, /* special_function */
540 "R_PPC_PLT32", /* name */
541 FALSE
, /* partial_inplace */
544 FALSE
), /* pcrel_offset */
546 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
547 FIXME: not supported. */
548 HOWTO (R_PPC_PLTREL32
, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 TRUE
, /* pc_relative */
554 complain_overflow_bitfield
, /* complain_on_overflow */
555 bfd_elf_generic_reloc
, /* special_function */
556 "R_PPC_PLTREL32", /* name */
557 FALSE
, /* partial_inplace */
560 TRUE
), /* pcrel_offset */
562 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
564 HOWTO (R_PPC_PLT16_LO
, /* type */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE
, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 bfd_elf_generic_reloc
, /* special_function */
572 "R_PPC_PLT16_LO", /* name */
573 FALSE
, /* partial_inplace */
575 0xffff, /* dst_mask */
576 FALSE
), /* pcrel_offset */
578 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
580 HOWTO (R_PPC_PLT16_HI
, /* type */
582 1, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE
, /* pc_relative */
586 complain_overflow_bitfield
, /* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_PPC_PLT16_HI", /* name */
589 FALSE
, /* partial_inplace */
591 0xffff, /* dst_mask */
592 FALSE
), /* pcrel_offset */
594 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
596 HOWTO (R_PPC_PLT16_HA
, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE
, /* pc_relative */
602 complain_overflow_bitfield
, /* complain_on_overflow */
603 ppc_elf_addr16_ha_reloc
, /* special_function */
604 "R_PPC_PLT16_HA", /* name */
605 FALSE
, /* partial_inplace */
607 0xffff, /* dst_mask */
608 FALSE
), /* pcrel_offset */
610 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
612 HOWTO (R_PPC_SDAREL16
, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_signed
, /* complain_on_overflow */
619 bfd_elf_generic_reloc
, /* special_function */
620 "R_PPC_SDAREL16", /* name */
621 FALSE
, /* partial_inplace */
623 0xffff, /* dst_mask */
624 FALSE
), /* pcrel_offset */
626 /* 16-bit section relative relocation. */
627 HOWTO (R_PPC_SECTOFF
, /* type */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
631 FALSE
, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_PPC_SECTOFF", /* name */
636 FALSE
, /* partial_inplace */
638 0xffff, /* dst_mask */
639 FALSE
), /* pcrel_offset */
641 /* 16-bit lower half section relative relocation. */
642 HOWTO (R_PPC_SECTOFF_LO
, /* type */
644 1, /* size (0 = byte, 1 = short, 2 = long) */
646 FALSE
, /* pc_relative */
648 complain_overflow_dont
, /* complain_on_overflow */
649 bfd_elf_generic_reloc
, /* special_function */
650 "R_PPC_SECTOFF_LO", /* name */
651 FALSE
, /* partial_inplace */
653 0xffff, /* dst_mask */
654 FALSE
), /* pcrel_offset */
656 /* 16-bit upper half section relative relocation. */
657 HOWTO (R_PPC_SECTOFF_HI
, /* type */
659 1, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE
, /* pc_relative */
663 complain_overflow_bitfield
, /* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_PPC_SECTOFF_HI", /* name */
666 FALSE
, /* partial_inplace */
668 0xffff, /* dst_mask */
669 FALSE
), /* pcrel_offset */
671 /* 16-bit upper half adjusted section relative relocation. */
672 HOWTO (R_PPC_SECTOFF_HA
, /* type */
674 1, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE
, /* pc_relative */
678 complain_overflow_bitfield
, /* complain_on_overflow */
679 ppc_elf_addr16_ha_reloc
, /* special_function */
680 "R_PPC_SECTOFF_HA", /* name */
681 FALSE
, /* partial_inplace */
683 0xffff, /* dst_mask */
684 FALSE
), /* pcrel_offset */
686 /* Marker reloc for TLS. */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 FALSE
, /* pc_relative */
693 complain_overflow_dont
, /* complain_on_overflow */
694 bfd_elf_generic_reloc
, /* special_function */
695 "R_PPC_TLS", /* name */
696 FALSE
, /* partial_inplace */
699 FALSE
), /* pcrel_offset */
701 /* Computes the load module index of the load module that contains the
702 definition of its TLS sym. */
703 HOWTO (R_PPC_DTPMOD32
,
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE
, /* pc_relative */
709 complain_overflow_dont
, /* complain_on_overflow */
710 ppc_elf_unhandled_reloc
, /* special_function */
711 "R_PPC_DTPMOD32", /* name */
712 FALSE
, /* partial_inplace */
714 0xffffffff, /* dst_mask */
715 FALSE
), /* pcrel_offset */
717 /* Computes a dtv-relative displacement, the difference between the value
718 of sym+add and the base address of the thread-local storage block that
719 contains the definition of sym, minus 0x8000. */
720 HOWTO (R_PPC_DTPREL32
,
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE
, /* pc_relative */
726 complain_overflow_dont
, /* complain_on_overflow */
727 ppc_elf_unhandled_reloc
, /* special_function */
728 "R_PPC_DTPREL32", /* name */
729 FALSE
, /* partial_inplace */
731 0xffffffff, /* dst_mask */
732 FALSE
), /* pcrel_offset */
734 /* A 16 bit dtprel reloc. */
735 HOWTO (R_PPC_DTPREL16
,
737 1, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE
, /* pc_relative */
741 complain_overflow_signed
, /* complain_on_overflow */
742 ppc_elf_unhandled_reloc
, /* special_function */
743 "R_PPC_DTPREL16", /* name */
744 FALSE
, /* partial_inplace */
746 0xffff, /* dst_mask */
747 FALSE
), /* pcrel_offset */
749 /* Like DTPREL16, but no overflow. */
750 HOWTO (R_PPC_DTPREL16_LO
,
752 1, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_dont
, /* complain_on_overflow */
757 ppc_elf_unhandled_reloc
, /* special_function */
758 "R_PPC_DTPREL16_LO", /* name */
759 FALSE
, /* partial_inplace */
761 0xffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* Like DTPREL16_LO, but next higher group of 16 bits. */
765 HOWTO (R_PPC_DTPREL16_HI
,
767 1, /* size (0 = byte, 1 = short, 2 = long) */
769 FALSE
, /* pc_relative */
771 complain_overflow_dont
, /* complain_on_overflow */
772 ppc_elf_unhandled_reloc
, /* special_function */
773 "R_PPC_DTPREL16_HI", /* name */
774 FALSE
, /* partial_inplace */
776 0xffff, /* dst_mask */
777 FALSE
), /* pcrel_offset */
779 /* Like DTPREL16_HI, but adjust for low 16 bits. */
780 HOWTO (R_PPC_DTPREL16_HA
,
782 1, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_dont
, /* complain_on_overflow */
787 ppc_elf_unhandled_reloc
, /* special_function */
788 "R_PPC_DTPREL16_HA", /* name */
789 FALSE
, /* partial_inplace */
791 0xffff, /* dst_mask */
792 FALSE
), /* pcrel_offset */
794 /* Computes a tp-relative displacement, the difference between the value of
795 sym+add and the value of the thread pointer (r13). */
796 HOWTO (R_PPC_TPREL32
,
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE
, /* pc_relative */
802 complain_overflow_dont
, /* complain_on_overflow */
803 ppc_elf_unhandled_reloc
, /* special_function */
804 "R_PPC_TPREL32", /* name */
805 FALSE
, /* partial_inplace */
807 0xffffffff, /* dst_mask */
808 FALSE
), /* pcrel_offset */
810 /* A 16 bit tprel reloc. */
811 HOWTO (R_PPC_TPREL16
,
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE
, /* pc_relative */
817 complain_overflow_signed
, /* complain_on_overflow */
818 ppc_elf_unhandled_reloc
, /* special_function */
819 "R_PPC_TPREL16", /* name */
820 FALSE
, /* partial_inplace */
822 0xffff, /* dst_mask */
823 FALSE
), /* pcrel_offset */
825 /* Like TPREL16, but no overflow. */
826 HOWTO (R_PPC_TPREL16_LO
,
828 1, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE
, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 ppc_elf_unhandled_reloc
, /* special_function */
834 "R_PPC_TPREL16_LO", /* name */
835 FALSE
, /* partial_inplace */
837 0xffff, /* dst_mask */
838 FALSE
), /* pcrel_offset */
840 /* Like TPREL16_LO, but next higher group of 16 bits. */
841 HOWTO (R_PPC_TPREL16_HI
,
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 ppc_elf_unhandled_reloc
, /* special_function */
849 "R_PPC_TPREL16_HI", /* name */
850 FALSE
, /* partial_inplace */
852 0xffff, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* Like TPREL16_HI, but adjust for low 16 bits. */
856 HOWTO (R_PPC_TPREL16_HA
,
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
, /* complain_on_overflow */
863 ppc_elf_unhandled_reloc
, /* special_function */
864 "R_PPC_TPREL16_HA", /* name */
865 FALSE
, /* partial_inplace */
867 0xffff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
871 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
872 to the first entry. */
873 HOWTO (R_PPC_GOT_TLSGD16
,
875 1, /* size (0 = byte, 1 = short, 2 = long) */
877 FALSE
, /* pc_relative */
879 complain_overflow_signed
, /* complain_on_overflow */
880 ppc_elf_unhandled_reloc
, /* special_function */
881 "R_PPC_GOT_TLSGD16", /* name */
882 FALSE
, /* partial_inplace */
884 0xffff, /* dst_mask */
885 FALSE
), /* pcrel_offset */
887 /* Like GOT_TLSGD16, but no overflow. */
888 HOWTO (R_PPC_GOT_TLSGD16_LO
,
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 ppc_elf_unhandled_reloc
, /* special_function */
896 "R_PPC_GOT_TLSGD16_LO", /* name */
897 FALSE
, /* partial_inplace */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
903 HOWTO (R_PPC_GOT_TLSGD16_HI
,
905 1, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE
, /* pc_relative */
909 complain_overflow_dont
, /* complain_on_overflow */
910 ppc_elf_unhandled_reloc
, /* special_function */
911 "R_PPC_GOT_TLSGD16_HI", /* name */
912 FALSE
, /* partial_inplace */
914 0xffff, /* dst_mask */
915 FALSE
), /* pcrel_offset */
917 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
918 HOWTO (R_PPC_GOT_TLSGD16_HA
,
920 1, /* size (0 = byte, 1 = short, 2 = long) */
922 FALSE
, /* pc_relative */
924 complain_overflow_dont
, /* complain_on_overflow */
925 ppc_elf_unhandled_reloc
, /* special_function */
926 "R_PPC_GOT_TLSGD16_HA", /* name */
927 FALSE
, /* partial_inplace */
929 0xffff, /* dst_mask */
930 FALSE
), /* pcrel_offset */
932 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
933 with values (sym+add)@dtpmod and zero, and computes the offset to the
935 HOWTO (R_PPC_GOT_TLSLD16
,
937 1, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_signed
, /* complain_on_overflow */
942 ppc_elf_unhandled_reloc
, /* special_function */
943 "R_PPC_GOT_TLSLD16", /* name */
944 FALSE
, /* partial_inplace */
946 0xffff, /* dst_mask */
947 FALSE
), /* pcrel_offset */
949 /* Like GOT_TLSLD16, but no overflow. */
950 HOWTO (R_PPC_GOT_TLSLD16_LO
,
952 1, /* size (0 = byte, 1 = short, 2 = long) */
954 FALSE
, /* pc_relative */
956 complain_overflow_dont
, /* complain_on_overflow */
957 ppc_elf_unhandled_reloc
, /* special_function */
958 "R_PPC_GOT_TLSLD16_LO", /* name */
959 FALSE
, /* partial_inplace */
961 0xffff, /* dst_mask */
962 FALSE
), /* pcrel_offset */
964 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
965 HOWTO (R_PPC_GOT_TLSLD16_HI
,
967 1, /* size (0 = byte, 1 = short, 2 = long) */
969 FALSE
, /* pc_relative */
971 complain_overflow_dont
, /* complain_on_overflow */
972 ppc_elf_unhandled_reloc
, /* special_function */
973 "R_PPC_GOT_TLSLD16_HI", /* name */
974 FALSE
, /* partial_inplace */
976 0xffff, /* dst_mask */
977 FALSE
), /* pcrel_offset */
979 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
980 HOWTO (R_PPC_GOT_TLSLD16_HA
,
982 1, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_dont
, /* complain_on_overflow */
987 ppc_elf_unhandled_reloc
, /* special_function */
988 "R_PPC_GOT_TLSLD16_HA", /* name */
989 FALSE
, /* partial_inplace */
991 0xffff, /* dst_mask */
992 FALSE
), /* pcrel_offset */
994 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
995 the offset to the entry. */
996 HOWTO (R_PPC_GOT_DTPREL16
,
998 1, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE
, /* pc_relative */
1002 complain_overflow_signed
, /* complain_on_overflow */
1003 ppc_elf_unhandled_reloc
, /* special_function */
1004 "R_PPC_GOT_DTPREL16", /* name */
1005 FALSE
, /* partial_inplace */
1007 0xffff, /* dst_mask */
1008 FALSE
), /* pcrel_offset */
1010 /* Like GOT_DTPREL16, but no overflow. */
1011 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1013 1, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE
, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 ppc_elf_unhandled_reloc
, /* special_function */
1019 "R_PPC_GOT_DTPREL16_LO", /* name */
1020 FALSE
, /* partial_inplace */
1022 0xffff, /* dst_mask */
1023 FALSE
), /* pcrel_offset */
1025 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1026 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1027 16, /* rightshift */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_dont
, /* complain_on_overflow */
1033 ppc_elf_unhandled_reloc
, /* special_function */
1034 "R_PPC_GOT_DTPREL16_HI", /* name */
1035 FALSE
, /* partial_inplace */
1037 0xffff, /* dst_mask */
1038 FALSE
), /* pcrel_offset */
1040 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1041 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1042 16, /* rightshift */
1043 1, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE
, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 ppc_elf_unhandled_reloc
, /* special_function */
1049 "R_PPC_GOT_DTPREL16_HA", /* name */
1050 FALSE
, /* partial_inplace */
1052 0xffff, /* dst_mask */
1053 FALSE
), /* pcrel_offset */
1055 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1056 offset to the entry. */
1057 HOWTO (R_PPC_GOT_TPREL16
,
1059 1, /* size (0 = byte, 1 = short, 2 = long) */
1061 FALSE
, /* pc_relative */
1063 complain_overflow_signed
, /* complain_on_overflow */
1064 ppc_elf_unhandled_reloc
, /* special_function */
1065 "R_PPC_GOT_TPREL16", /* name */
1066 FALSE
, /* partial_inplace */
1068 0xffff, /* dst_mask */
1069 FALSE
), /* pcrel_offset */
1071 /* Like GOT_TPREL16, but no overflow. */
1072 HOWTO (R_PPC_GOT_TPREL16_LO
,
1074 1, /* size (0 = byte, 1 = short, 2 = long) */
1076 FALSE
, /* pc_relative */
1078 complain_overflow_dont
, /* complain_on_overflow */
1079 ppc_elf_unhandled_reloc
, /* special_function */
1080 "R_PPC_GOT_TPREL16_LO", /* name */
1081 FALSE
, /* partial_inplace */
1083 0xffff, /* dst_mask */
1084 FALSE
), /* pcrel_offset */
1086 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1087 HOWTO (R_PPC_GOT_TPREL16_HI
,
1088 16, /* rightshift */
1089 1, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE
, /* pc_relative */
1093 complain_overflow_dont
, /* complain_on_overflow */
1094 ppc_elf_unhandled_reloc
, /* special_function */
1095 "R_PPC_GOT_TPREL16_HI", /* name */
1096 FALSE
, /* partial_inplace */
1098 0xffff, /* dst_mask */
1099 FALSE
), /* pcrel_offset */
1101 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1102 HOWTO (R_PPC_GOT_TPREL16_HA
,
1103 16, /* rightshift */
1104 1, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE
, /* pc_relative */
1108 complain_overflow_dont
, /* complain_on_overflow */
1109 ppc_elf_unhandled_reloc
, /* special_function */
1110 "R_PPC_GOT_TPREL16_HA", /* name */
1111 FALSE
, /* partial_inplace */
1113 0xffff, /* dst_mask */
1114 FALSE
), /* pcrel_offset */
1116 /* The remaining relocs are from the Embedded ELF ABI, and are not
1117 in the SVR4 ELF ABI. */
1119 /* 32 bit value resulting from the addend minus the symbol. */
1120 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_bitfield
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* special_function */
1128 "R_PPC_EMB_NADDR32", /* name */
1129 FALSE
, /* partial_inplace */
1131 0xffffffff, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 /* 16 bit value resulting from the addend minus the symbol. */
1135 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1137 1, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_bitfield
, /* complain_on_overflow */
1142 bfd_elf_generic_reloc
, /* special_function */
1143 "R_PPC_EMB_NADDR16", /* name */
1144 FALSE
, /* partial_inplace */
1146 0xffff, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* 16 bit value resulting from the addend minus the symbol. */
1150 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_dont
,/* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 "R_PPC_EMB_ADDR16_LO", /* name */
1159 FALSE
, /* partial_inplace */
1161 0xffff, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 /* The high order 16 bits of the addend minus the symbol. */
1165 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1166 16, /* rightshift */
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 bfd_elf_generic_reloc
, /* special_function */
1173 "R_PPC_EMB_NADDR16_HI", /* name */
1174 FALSE
, /* partial_inplace */
1176 0xffff, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* The high order 16 bits of the result of the addend minus the address,
1180 plus 1 if the contents of the low 16 bits, treated as a signed number,
1182 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1183 16, /* rightshift */
1184 1, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE
, /* pc_relative */
1188 complain_overflow_dont
, /* complain_on_overflow */
1189 ppc_elf_addr16_ha_reloc
, /* special_function */
1190 "R_PPC_EMB_NADDR16_HA", /* name */
1191 FALSE
, /* partial_inplace */
1193 0xffff, /* dst_mask */
1194 FALSE
), /* pcrel_offset */
1196 /* 16 bit value resulting from allocating a 4 byte word to hold an
1197 address in the .sdata section, and returning the offset from
1198 _SDA_BASE_ for that relocation. */
1199 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1201 1, /* size (0 = byte, 1 = short, 2 = long) */
1203 FALSE
, /* pc_relative */
1205 complain_overflow_bitfield
, /* complain_on_overflow */
1206 bfd_elf_generic_reloc
, /* special_function */
1207 "R_PPC_EMB_SDAI16", /* name */
1208 FALSE
, /* partial_inplace */
1210 0xffff, /* dst_mask */
1211 FALSE
), /* pcrel_offset */
1213 /* 16 bit value resulting from allocating a 4 byte word to hold an
1214 address in the .sdata2 section, and returning the offset from
1215 _SDA2_BASE_ for that relocation. */
1216 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1218 1, /* size (0 = byte, 1 = short, 2 = long) */
1220 FALSE
, /* pc_relative */
1222 complain_overflow_bitfield
, /* complain_on_overflow */
1223 bfd_elf_generic_reloc
, /* special_function */
1224 "R_PPC_EMB_SDA2I16", /* name */
1225 FALSE
, /* partial_inplace */
1227 0xffff, /* dst_mask */
1228 FALSE
), /* pcrel_offset */
1230 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1231 small data items. */
1232 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1234 1, /* size (0 = byte, 1 = short, 2 = long) */
1236 FALSE
, /* pc_relative */
1238 complain_overflow_signed
, /* complain_on_overflow */
1239 bfd_elf_generic_reloc
, /* special_function */
1240 "R_PPC_EMB_SDA2REL", /* name */
1241 FALSE
, /* partial_inplace */
1243 0xffff, /* dst_mask */
1244 FALSE
), /* pcrel_offset */
1246 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1247 signed offset from the appropriate base, and filling in the register
1248 field with the appropriate register (0, 2, or 13). */
1249 HOWTO (R_PPC_EMB_SDA21
, /* type */
1251 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_signed
, /* complain_on_overflow */
1256 bfd_elf_generic_reloc
, /* special_function */
1257 "R_PPC_EMB_SDA21", /* name */
1258 FALSE
, /* partial_inplace */
1260 0xffff, /* dst_mask */
1261 FALSE
), /* pcrel_offset */
1263 /* Relocation not handled: R_PPC_EMB_MRKREF */
1264 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1265 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1266 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1267 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1268 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1270 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1271 in the 16 bit signed offset from the appropriate base, and filling in the
1272 register field with the appropriate register (0, 2, or 13). */
1273 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1275 1, /* size (0 = byte, 1 = short, 2 = long) */
1277 TRUE
, /* pc_relative */
1279 complain_overflow_signed
, /* complain_on_overflow */
1280 bfd_elf_generic_reloc
, /* special_function */
1281 "R_PPC_EMB_RELSDA", /* name */
1282 FALSE
, /* partial_inplace */
1284 0xffff, /* dst_mask */
1285 FALSE
), /* pcrel_offset */
1287 /* A 16 bit relative relocation. */
1288 HOWTO (R_PPC_REL16
, /* type */
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1292 TRUE
, /* pc_relative */
1294 complain_overflow_bitfield
, /* complain_on_overflow */
1295 bfd_elf_generic_reloc
, /* special_function */
1296 "R_PPC_REL16", /* name */
1297 FALSE
, /* partial_inplace */
1299 0xffff, /* dst_mask */
1300 TRUE
), /* pcrel_offset */
1302 /* A 16 bit relative relocation without overflow. */
1303 HOWTO (R_PPC_REL16_LO
, /* type */
1305 1, /* size (0 = byte, 1 = short, 2 = long) */
1307 TRUE
, /* pc_relative */
1309 complain_overflow_dont
,/* complain_on_overflow */
1310 bfd_elf_generic_reloc
, /* special_function */
1311 "R_PPC_REL16_LO", /* name */
1312 FALSE
, /* partial_inplace */
1314 0xffff, /* dst_mask */
1315 TRUE
), /* pcrel_offset */
1317 /* The high order 16 bits of a relative address. */
1318 HOWTO (R_PPC_REL16_HI
, /* type */
1319 16, /* rightshift */
1320 1, /* size (0 = byte, 1 = short, 2 = long) */
1322 TRUE
, /* pc_relative */
1324 complain_overflow_dont
, /* complain_on_overflow */
1325 bfd_elf_generic_reloc
, /* special_function */
1326 "R_PPC_REL16_HI", /* name */
1327 FALSE
, /* partial_inplace */
1329 0xffff, /* dst_mask */
1330 TRUE
), /* pcrel_offset */
1332 /* The high order 16 bits of a relative address, plus 1 if the contents of
1333 the low 16 bits, treated as a signed number, is negative. */
1334 HOWTO (R_PPC_REL16_HA
, /* type */
1335 16, /* rightshift */
1336 1, /* size (0 = byte, 1 = short, 2 = long) */
1338 TRUE
, /* pc_relative */
1340 complain_overflow_dont
, /* complain_on_overflow */
1341 ppc_elf_addr16_ha_reloc
, /* special_function */
1342 "R_PPC_REL16_HA", /* name */
1343 FALSE
, /* partial_inplace */
1345 0xffff, /* dst_mask */
1346 TRUE
), /* pcrel_offset */
1348 /* GNU extension to record C++ vtable hierarchy. */
1349 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1351 0, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE
, /* pc_relative */
1355 complain_overflow_dont
, /* complain_on_overflow */
1356 NULL
, /* special_function */
1357 "R_PPC_GNU_VTINHERIT", /* name */
1358 FALSE
, /* partial_inplace */
1361 FALSE
), /* pcrel_offset */
1363 /* GNU extension to record C++ vtable member usage. */
1364 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1366 0, /* size (0 = byte, 1 = short, 2 = long) */
1368 FALSE
, /* pc_relative */
1370 complain_overflow_dont
, /* complain_on_overflow */
1371 NULL
, /* special_function */
1372 "R_PPC_GNU_VTENTRY", /* name */
1373 FALSE
, /* partial_inplace */
1376 FALSE
), /* pcrel_offset */
1378 /* Phony reloc to handle AIX style TOC entries. */
1379 HOWTO (R_PPC_TOC16
, /* type */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 FALSE
, /* pc_relative */
1385 complain_overflow_signed
, /* complain_on_overflow */
1386 bfd_elf_generic_reloc
, /* special_function */
1387 "R_PPC_TOC16", /* name */
1388 FALSE
, /* partial_inplace */
1390 0xffff, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1394 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1397 ppc_elf_howto_init (void)
1399 unsigned int i
, type
;
1402 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1405 type
= ppc_elf_howto_raw
[i
].type
;
1406 if (type
>= (sizeof (ppc_elf_howto_table
)
1407 / sizeof (ppc_elf_howto_table
[0])))
1409 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1413 static reloc_howto_type
*
1414 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1415 bfd_reloc_code_real_type code
)
1417 enum elf_ppc_reloc_type r
;
1419 /* Initialize howto table if not already done. */
1420 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1421 ppc_elf_howto_init ();
1428 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1429 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1430 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1431 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1432 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1433 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1434 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1435 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1436 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1437 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1438 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1439 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1440 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1441 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1442 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1443 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1444 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1445 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1446 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1447 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1448 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1449 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1450 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1451 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1452 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1453 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1454 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1455 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1456 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1457 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1458 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1459 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1460 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1461 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1462 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1463 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1464 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1465 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1466 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1467 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1468 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1469 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1470 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1471 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1472 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1473 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1474 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1475 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1476 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1477 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1478 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1479 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1480 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1481 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1482 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1483 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1484 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1485 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1486 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1487 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1488 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1489 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1490 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1491 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1492 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1493 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1494 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1495 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1496 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1497 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1498 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1499 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1500 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1501 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1502 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1503 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1504 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1505 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1506 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1507 case BFD_RELOC_16_PCREL
: r
= R_PPC_REL16
; break;
1508 case BFD_RELOC_LO16_PCREL
: r
= R_PPC_REL16_LO
; break;
1509 case BFD_RELOC_HI16_PCREL
: r
= R_PPC_REL16_HI
; break;
1510 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC_REL16_HA
; break;
1511 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1512 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1515 return ppc_elf_howto_table
[r
];
1518 /* Set the howto pointer for a PowerPC ELF reloc. */
1521 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1523 Elf_Internal_Rela
*dst
)
1525 /* Initialize howto table if not already done. */
1526 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1527 ppc_elf_howto_init ();
1529 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1530 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1533 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1535 static bfd_reloc_status_type
1536 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1537 arelent
*reloc_entry
,
1539 void *data ATTRIBUTE_UNUSED
,
1540 asection
*input_section
,
1542 char **error_message ATTRIBUTE_UNUSED
)
1546 if (output_bfd
!= NULL
)
1548 reloc_entry
->address
+= input_section
->output_offset
;
1549 return bfd_reloc_ok
;
1552 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1553 return bfd_reloc_outofrange
;
1555 if (bfd_is_com_section (symbol
->section
))
1558 relocation
= symbol
->value
;
1560 relocation
+= symbol
->section
->output_section
->vma
;
1561 relocation
+= symbol
->section
->output_offset
;
1562 relocation
+= reloc_entry
->addend
;
1563 if (reloc_entry
->howto
->pc_relative
)
1564 relocation
-= reloc_entry
->address
;
1566 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1568 return bfd_reloc_continue
;
1571 static bfd_reloc_status_type
1572 ppc_elf_unhandled_reloc (bfd
*abfd
,
1573 arelent
*reloc_entry
,
1576 asection
*input_section
,
1578 char **error_message
)
1580 /* If this is a relocatable link (output_bfd test tells us), just
1581 call the generic function. Any adjustment will be done at final
1583 if (output_bfd
!= NULL
)
1584 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1585 input_section
, output_bfd
, error_message
);
1587 if (error_message
!= NULL
)
1589 static char buf
[60];
1590 sprintf (buf
, _("generic linker can't handle %s"),
1591 reloc_entry
->howto
->name
);
1592 *error_message
= buf
;
1594 return bfd_reloc_dangerous
;
1597 /* Sections created by the linker. */
1599 typedef struct elf_linker_section
1601 /* Pointer to the bfd section. */
1605 /* Associated bss section name. */
1606 const char *bss_name
;
1607 /* Associated symbol name. */
1608 const char *sym_name
;
1609 /* Value of symbol. */
1611 } elf_linker_section_t
;
1613 /* Linked list of allocated pointer entries. This hangs off of the
1614 symbol lists, and provides allows us to return different pointers,
1615 based on different addend's. */
1617 typedef struct elf_linker_section_pointers
1619 /* next allocated pointer for this symbol */
1620 struct elf_linker_section_pointers
*next
;
1621 /* offset of pointer from beginning of section */
1625 /* which linker section this is */
1626 elf_linker_section_t
*lsect
;
1627 } elf_linker_section_pointers_t
;
1629 struct ppc_elf_obj_tdata
1631 struct elf_obj_tdata elf
;
1633 /* A mapping from local symbols to offsets into the various linker
1634 sections added. This is index by the symbol index. */
1635 elf_linker_section_pointers_t
**linker_section_pointers
;
1638 #define ppc_elf_tdata(bfd) \
1639 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1641 #define elf_local_ptr_offsets(bfd) \
1642 (ppc_elf_tdata (bfd)->linker_section_pointers)
1644 /* Override the generic function because we store some extras. */
1647 ppc_elf_mkobject (bfd
*abfd
)
1649 bfd_size_type amt
= sizeof (struct ppc_elf_obj_tdata
);
1650 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
1651 if (abfd
->tdata
.any
== NULL
)
1656 /* Fix bad default arch selected for a 32 bit input bfd when the
1657 default is 64 bit. */
1660 ppc_elf_object_p (bfd
*abfd
)
1662 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1664 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1666 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1668 /* Relies on arch after 64 bit default being 32 bit default. */
1669 abfd
->arch_info
= abfd
->arch_info
->next
;
1670 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1676 /* Function to set whether a module needs the -mrelocatable bit set. */
1679 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1681 BFD_ASSERT (!elf_flags_init (abfd
)
1682 || elf_elfheader (abfd
)->e_flags
== flags
);
1684 elf_elfheader (abfd
)->e_flags
= flags
;
1685 elf_flags_init (abfd
) = TRUE
;
1689 /* Support for core dump NOTE sections. */
1692 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1697 switch (note
->descsz
)
1702 case 268: /* Linux/PPC. */
1704 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1707 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1716 /* Make a ".reg/999" section. */
1717 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1718 size
, note
->descpos
+ offset
);
1722 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1724 switch (note
->descsz
)
1729 case 128: /* Linux/PPC elf_prpsinfo. */
1730 elf_tdata (abfd
)->core_program
1731 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1732 elf_tdata (abfd
)->core_command
1733 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1736 /* Note that for some reason, a spurious space is tacked
1737 onto the end of the args in some (at least one anyway)
1738 implementations, so strip it off if it exists. */
1741 char *command
= elf_tdata (abfd
)->core_command
;
1742 int n
= strlen (command
);
1744 if (0 < n
&& command
[n
- 1] == ' ')
1745 command
[n
- 1] = '\0';
1751 /* Return address for Ith PLT stub in section PLT, for relocation REL
1752 or (bfd_vma) -1 if it should not be included. */
1755 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1756 const asection
*plt ATTRIBUTE_UNUSED
,
1759 return rel
->address
;
1762 /* Handle a PowerPC specific section when reading an object file. This
1763 is called when bfd_section_from_shdr finds a section with an unknown
1767 ppc_elf_section_from_shdr (bfd
*abfd
,
1768 Elf_Internal_Shdr
*hdr
,
1775 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1778 newsect
= hdr
->bfd_section
;
1779 flags
= bfd_get_section_flags (abfd
, newsect
);
1780 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1781 flags
|= SEC_EXCLUDE
;
1783 if (hdr
->sh_type
== SHT_ORDERED
)
1784 flags
|= SEC_SORT_ENTRIES
;
1786 bfd_set_section_flags (abfd
, newsect
, flags
);
1790 /* Set up any other section flags and such that may be necessary. */
1793 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1794 Elf_Internal_Shdr
*shdr
,
1797 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1798 shdr
->sh_flags
|= SHF_EXCLUDE
;
1800 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1801 shdr
->sh_type
= SHT_ORDERED
;
1806 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1807 need to bump up the number of section headers. */
1810 ppc_elf_additional_program_headers (bfd
*abfd
)
1815 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1816 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1819 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1820 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1826 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1827 .PPC.EMB.sbss0 a normal section, and not a bss section so
1828 that the linker doesn't crater when trying to make more than
1831 static const struct bfd_elf_special_section ppc_elf_special_sections
[] =
1833 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
1834 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1835 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
1836 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1837 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
1838 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
1839 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
1840 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
1841 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
1842 { NULL
, 0, 0, 0, 0 }
1845 /* This is what we want for new plt/got. */
1846 static struct bfd_elf_special_section ppc_alt_plt
=
1847 { ".plt", 4, 0, SHT_PROGBITS
, SHF_ALLOC
};
1849 static const struct bfd_elf_special_section
*
1850 ppc_elf_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
1852 const struct bfd_elf_special_section
*ssect
;
1854 /* See if this is one of the special sections. */
1855 if (sec
->name
== NULL
)
1858 ssect
= _bfd_elf_get_special_section (sec
->name
, ppc_elf_special_sections
,
1862 if (ssect
== ppc_elf_special_sections
&& (sec
->flags
& SEC_LOAD
) != 0)
1863 ssect
= &ppc_alt_plt
;
1867 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
1870 /* Very simple linked list structure for recording apuinfo values. */
1871 typedef struct apuinfo_list
1873 struct apuinfo_list
*next
;
1874 unsigned long value
;
1878 static apuinfo_list
*head
;
1882 apuinfo_list_init (void)
1888 apuinfo_list_add (unsigned long value
)
1890 apuinfo_list
*entry
= head
;
1892 while (entry
!= NULL
)
1894 if (entry
->value
== value
)
1896 entry
= entry
->next
;
1899 entry
= bfd_malloc (sizeof (* entry
));
1903 entry
->value
= value
;
1909 apuinfo_list_length (void)
1911 apuinfo_list
*entry
;
1912 unsigned long count
;
1914 for (entry
= head
, count
= 0;
1916 entry
= entry
->next
)
1922 static inline unsigned long
1923 apuinfo_list_element (unsigned long number
)
1925 apuinfo_list
* entry
;
1929 entry
= entry
->next
)
1932 return entry
? entry
->value
: 0;
1936 apuinfo_list_finish (void)
1938 apuinfo_list
*entry
;
1940 for (entry
= head
; entry
;)
1942 apuinfo_list
*next
= entry
->next
;
1950 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
1951 #define APUINFO_LABEL "APUinfo"
1953 /* Scan the input BFDs and create a linked list of
1954 the APUinfo values that will need to be emitted. */
1957 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
1962 unsigned num_input_sections
;
1963 bfd_size_type output_section_size
;
1965 unsigned num_entries
;
1966 unsigned long offset
;
1967 unsigned long length
;
1968 const char *error_message
= NULL
;
1970 if (link_info
== NULL
)
1973 /* Scan the input bfds, looking for apuinfo sections. */
1974 num_input_sections
= 0;
1975 output_section_size
= 0;
1977 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
1979 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
1982 ++ num_input_sections
;
1983 output_section_size
+= asec
->size
;
1987 /* We need at least one input sections
1988 in order to make merging worthwhile. */
1989 if (num_input_sections
< 1)
1992 /* Just make sure that the output section exists as well. */
1993 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
1997 /* Allocate a buffer for the contents of the input sections. */
1998 buffer
= bfd_malloc (output_section_size
);
2003 apuinfo_list_init ();
2005 /* Read in the input sections contents. */
2006 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2008 unsigned long datum
;
2011 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2015 length
= asec
->size
;
2018 error_message
= _("corrupt or empty %s section in %B");
2022 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
2023 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
2025 error_message
= _("unable to read in %s section from %B");
2029 /* Process the contents of the section. */
2030 ptr
= buffer
+ offset
;
2031 error_message
= _("corrupt %s section in %B");
2033 /* Verify the contents of the header. Note - we have to
2034 extract the values this way in order to allow for a
2035 host whose endian-ness is different from the target. */
2036 datum
= bfd_get_32 (ibfd
, ptr
);
2037 if (datum
!= sizeof APUINFO_LABEL
)
2040 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
2044 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
2047 /* Get the number of bytes used for apuinfo entries. */
2048 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
2049 if (datum
+ 20 != length
)
2052 /* Make sure that we do not run off the end of the section. */
2053 if (offset
+ length
> output_section_size
)
2056 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2057 for (i
= 0; i
< datum
; i
+= 4)
2058 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
2060 /* Update the offset. */
2064 error_message
= NULL
;
2066 /* Compute the size of the output section. */
2067 num_entries
= apuinfo_list_length ();
2068 output_section_size
= 20 + num_entries
* 4;
2070 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2072 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
2074 error_message
= _("warning: unable to set size of %s section in %B");
2080 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
2083 /* Prevent the output section from accumulating the input sections'
2084 contents. We have already stored this in our linked list structure. */
2087 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2089 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2091 return (apuinfo_list_length ()
2092 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
2095 /* Finally we can generate the output section. */
2098 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
2103 unsigned num_entries
;
2104 bfd_size_type length
;
2106 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2110 if (apuinfo_list_length () == 0)
2113 length
= asec
->size
;
2117 buffer
= bfd_malloc (length
);
2120 (*_bfd_error_handler
)
2121 (_("failed to allocate space for new APUinfo section."));
2125 /* Create the apuinfo header. */
2126 num_entries
= apuinfo_list_length ();
2127 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
2128 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
2129 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
2130 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
2133 for (i
= 0; i
< num_entries
; i
++)
2135 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
2139 if (length
!= asec
->size
)
2140 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
2142 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
2143 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
2147 apuinfo_list_finish ();
2150 /* The following functions are specific to the ELF linker, while
2151 functions above are used generally. They appear in this file more
2152 or less in the order in which they are called. eg.
2153 ppc_elf_check_relocs is called early in the link process,
2154 ppc_elf_finish_dynamic_sections is one of the last functions
2157 /* The PPC linker needs to keep track of the number of relocs that it
2158 decides to copy as dynamic relocs in check_relocs for each symbol.
2159 This is so that it can later discard them if they are found to be
2160 unnecessary. We store the information in a field extending the
2161 regular ELF linker hash table. */
2163 struct ppc_elf_dyn_relocs
2165 struct ppc_elf_dyn_relocs
*next
;
2167 /* The input section of the reloc. */
2170 /* Total number of relocs copied for the input section. */
2171 bfd_size_type count
;
2173 /* Number of pc-relative relocs copied for the input section. */
2174 bfd_size_type pc_count
;
2177 /* Track PLT entries needed for a given symbol. We might need more
2178 than one glink entry per symbol. */
2181 struct plt_entry
*next
;
2183 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2184 This field stores the offset into .got2 used to initialise the
2185 GOT pointer reg. It will always be at least 32768 (and for
2186 current gcc this is the only offset used). */
2189 /* The .got2 section. */
2192 /* PLT refcount or offset. */
2195 bfd_signed_vma refcount
;
2199 /* .glink stub offset. */
2200 bfd_vma glink_offset
;
2203 /* Of those relocs that might be copied as dynamic relocs, this macro
2204 selects those that must be copied when linking a shared library,
2205 even when the symbol is local. */
2207 #define MUST_BE_DYN_RELOC(RTYPE) \
2208 ((RTYPE) != R_PPC_REL24 \
2209 && (RTYPE) != R_PPC_REL14 \
2210 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2211 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2212 && (RTYPE) != R_PPC_REL32)
2214 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2215 copying dynamic variables from a shared lib into an app's dynbss
2216 section, and instead use a dynamic relocation to point into the
2218 #define ELIMINATE_COPY_RELOCS 1
2220 /* PPC ELF linker hash entry. */
2222 struct ppc_elf_link_hash_entry
2224 struct elf_link_hash_entry elf
;
2226 /* If this symbol is used in the linker created sections, the processor
2227 specific backend uses this field to map the field into the offset
2228 from the beginning of the section. */
2229 elf_linker_section_pointers_t
*linker_section_pointer
;
2231 /* Track dynamic relocs copied for this symbol. */
2232 struct ppc_elf_dyn_relocs
*dyn_relocs
;
2234 /* Contexts in which symbol is used in the GOT (or TOC).
2235 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2236 corresponding relocs are encountered during check_relocs.
2237 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2238 indicate the corresponding GOT entry type is not needed. */
2239 #define TLS_GD 1 /* GD reloc. */
2240 #define TLS_LD 2 /* LD reloc. */
2241 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2242 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2243 #define TLS_TLS 16 /* Any TLS reloc. */
2244 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2247 /* Nonzero if we have seen a small data relocation referring to this
2249 unsigned char has_sda_refs
;
2252 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2254 /* PPC ELF linker hash table. */
2256 struct ppc_elf_link_hash_table
2258 struct elf_link_hash_table elf
;
2260 /* Short-cuts to get to dynamic linker sections. */
2270 elf_linker_section_t sdata
[2];
2273 /* Shortcut to .__tls_get_addr. */
2274 struct elf_link_hash_entry
*tls_get_addr
;
2276 /* TLS local dynamic got entry handling. */
2278 bfd_signed_vma refcount
;
2282 /* Offset of PltResolve function in glink. */
2283 bfd_vma glink_pltresolve
;
2285 /* Size of reserved GOT entries. */
2286 unsigned int got_header_size
;
2287 /* Non-zero if allocating the header left a gap. */
2288 unsigned int got_gap
;
2290 /* Whether to use new plt/got layout or not. */
2291 unsigned int new_plt
:1;
2292 unsigned int old_plt
:1;
2294 /* Small local sym to section mapping cache. */
2295 struct sym_sec_cache sym_sec
;
2298 /* Get the PPC ELF linker hash table from a link_info structure. */
2300 #define ppc_elf_hash_table(p) \
2301 ((struct ppc_elf_link_hash_table *) (p)->hash)
2303 /* Create an entry in a PPC ELF linker hash table. */
2305 static struct bfd_hash_entry
*
2306 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2307 struct bfd_hash_table
*table
,
2310 /* Allocate the structure if it has not already been allocated by a
2314 entry
= bfd_hash_allocate (table
,
2315 sizeof (struct ppc_elf_link_hash_entry
));
2320 /* Call the allocation method of the superclass. */
2321 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2324 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2325 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
2326 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2332 /* Create a PPC ELF linker hash table. */
2334 static struct bfd_link_hash_table
*
2335 ppc_elf_link_hash_table_create (bfd
*abfd
)
2337 struct ppc_elf_link_hash_table
*ret
;
2339 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2343 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2344 ppc_elf_link_hash_newfunc
))
2350 ret
->elf
.init_plt_refcount
.refcount
= 0;
2351 ret
->elf
.init_plt_refcount
.glist
= NULL
;
2352 ret
->elf
.init_plt_offset
.offset
= 0;
2353 ret
->elf
.init_plt_offset
.glist
= NULL
;
2355 ret
->sdata
[0].name
= ".sdata";
2356 ret
->sdata
[0].sym_name
= "_SDA_BASE_";
2357 ret
->sdata
[0].bss_name
= ".sbss";
2359 ret
->sdata
[1].name
= ".sdata2";
2360 ret
->sdata
[1].sym_name
= "_SDA2_BASE_";
2361 ret
->sdata
[1].bss_name
= ".sbss2";
2363 return &ret
->elf
.root
;
2366 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2369 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2371 struct ppc_elf_link_hash_table
*htab
;
2375 if (!_bfd_elf_create_got_section (abfd
, info
))
2378 htab
= ppc_elf_hash_table (info
);
2379 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2383 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2384 | SEC_LINKER_CREATED
);
2385 if (!bfd_set_section_flags (abfd
, s
, flags
))
2388 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2389 | SEC_LINKER_CREATED
| SEC_READONLY
);
2390 htab
->relgot
= bfd_make_section_with_flags (abfd
, ".rela.got", flags
);
2392 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2398 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2399 to output sections (just like _bfd_elf_create_dynamic_sections has
2400 to create .dynbss and .rela.bss). */
2403 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2405 struct ppc_elf_link_hash_table
*htab
;
2409 htab
= ppc_elf_hash_table (info
);
2411 if (htab
->got
== NULL
2412 && !ppc_elf_create_got (abfd
, info
))
2415 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2418 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2419 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2421 s
= bfd_make_section_anyway_with_flags (abfd
, ".glink", flags
| SEC_CODE
);
2424 || !bfd_set_section_alignment (abfd
, s
, 4))
2427 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2428 s
= bfd_make_section_with_flags (abfd
, ".dynsbss",
2429 SEC_ALLOC
| SEC_LINKER_CREATED
);
2436 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2437 s
= bfd_make_section_with_flags (abfd
, ".rela.sbss", flags
);
2440 || ! bfd_set_section_alignment (abfd
, s
, 2))
2444 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2445 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2449 flags
= SEC_ALLOC
| SEC_CODE
| SEC_LINKER_CREATED
;
2450 return bfd_set_section_flags (abfd
, s
, flags
);
2453 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2456 ppc_elf_copy_indirect_symbol (const struct elf_backend_data
*bed ATTRIBUTE_UNUSED
,
2457 struct elf_link_hash_entry
*dir
,
2458 struct elf_link_hash_entry
*ind
)
2460 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2463 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2464 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
2466 if (eind
->dyn_relocs
!= NULL
)
2468 if (edir
->dyn_relocs
!= NULL
)
2470 struct ppc_elf_dyn_relocs
**pp
;
2471 struct ppc_elf_dyn_relocs
*p
;
2473 if (ind
->root
.type
== bfd_link_hash_indirect
)
2476 /* Add reloc counts against the weak sym to the strong sym
2477 list. Merge any entries against the same section. */
2478 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2480 struct ppc_elf_dyn_relocs
*q
;
2482 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2483 if (q
->sec
== p
->sec
)
2485 q
->pc_count
+= p
->pc_count
;
2486 q
->count
+= p
->count
;
2493 *pp
= edir
->dyn_relocs
;
2496 edir
->dyn_relocs
= eind
->dyn_relocs
;
2497 eind
->dyn_relocs
= NULL
;
2500 edir
->tls_mask
|= eind
->tls_mask
;
2501 edir
->has_sda_refs
|= eind
->has_sda_refs
;
2503 /* If called to transfer flags for a weakdef during processing
2504 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2505 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2506 if (!(ELIMINATE_COPY_RELOCS
2507 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
2508 && edir
->elf
.dynamic_adjusted
))
2509 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
2511 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
2512 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
2513 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
2514 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
2516 /* If we were called to copy over info for a weak sym, that's all. */
2517 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
2520 /* Copy over the GOT refcount entries that we may have already seen to
2521 the symbol which just became indirect. */
2522 tmp
= edir
->elf
.got
.refcount
;
2525 edir
->elf
.got
.refcount
= eind
->elf
.got
.refcount
;
2526 eind
->elf
.got
.refcount
= tmp
;
2529 BFD_ASSERT (eind
->elf
.got
.refcount
< 1);
2531 /* And plt entries. */
2532 if (eind
->elf
.plt
.plist
!= NULL
)
2534 if (edir
->elf
.plt
.plist
!= NULL
)
2536 struct plt_entry
**entp
;
2537 struct plt_entry
*ent
;
2539 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
2541 struct plt_entry
*dent
;
2543 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
2544 if (dent
->sec
== ent
->sec
&& dent
->addend
== ent
->addend
)
2546 dent
->plt
.refcount
+= ent
->plt
.refcount
;
2553 *entp
= edir
->elf
.plt
.plist
;
2556 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
2557 eind
->elf
.plt
.plist
= NULL
;
2560 if (edir
->elf
.dynindx
== -1)
2562 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
2563 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
2564 eind
->elf
.dynindx
= -1;
2565 eind
->elf
.dynstr_index
= 0;
2568 BFD_ASSERT (eind
->elf
.dynindx
== -1);
2571 /* Return 1 if target is one of ours. */
2574 is_ppc_elf_target (const struct bfd_target
*targ
)
2576 extern const bfd_target bfd_elf32_powerpc_vec
;
2577 extern const bfd_target bfd_elf32_powerpcle_vec
;
2579 return targ
== &bfd_elf32_powerpc_vec
|| targ
== &bfd_elf32_powerpcle_vec
;
2582 /* Hook called by the linker routine which adds symbols from an object
2583 file. We use it to put .comm items in .sbss, and not .bss. */
2586 ppc_elf_add_symbol_hook (bfd
*abfd
,
2587 struct bfd_link_info
*info
,
2588 Elf_Internal_Sym
*sym
,
2589 const char **namep ATTRIBUTE_UNUSED
,
2590 flagword
*flagsp ATTRIBUTE_UNUSED
,
2594 if (sym
->st_shndx
== SHN_COMMON
2595 && !info
->relocatable
2596 && sym
->st_size
<= elf_gp_size (abfd
)
2597 && is_ppc_elf_target (info
->hash
->creator
))
2599 /* Common symbols less than or equal to -G nn bytes are automatically
2601 struct ppc_elf_link_hash_table
*htab
;
2603 htab
= ppc_elf_hash_table (info
);
2604 if (htab
->sbss
== NULL
)
2606 flagword flags
= SEC_IS_COMMON
| SEC_LINKER_CREATED
;
2608 if (!htab
->elf
.dynobj
)
2609 htab
->elf
.dynobj
= abfd
;
2611 htab
->sbss
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2614 if (htab
->sbss
== NULL
)
2619 *valp
= sym
->st_size
;
2625 /* Create a special linker section. */
2628 ppc_elf_create_linker_section (bfd
*abfd
,
2629 struct bfd_link_info
*info
,
2631 elf_linker_section_t
*lsect
)
2633 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2636 flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2637 | SEC_LINKER_CREATED
);
2639 /* Record the first bfd that needs the special sections. */
2640 if (!htab
->elf
.dynobj
)
2641 htab
->elf
.dynobj
= abfd
;
2643 s
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2647 || !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2654 /* Find a linker generated pointer with a given addend and type. */
2656 static elf_linker_section_pointers_t
*
2657 elf_find_pointer_linker_section
2658 (elf_linker_section_pointers_t
*linker_pointers
,
2660 elf_linker_section_t
*lsect
)
2662 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2663 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2664 return linker_pointers
;
2669 /* Allocate a pointer to live in a linker created section. */
2672 elf_create_pointer_linker_section (bfd
*abfd
,
2673 elf_linker_section_t
*lsect
,
2674 struct elf_link_hash_entry
*h
,
2675 const Elf_Internal_Rela
*rel
)
2677 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2678 elf_linker_section_pointers_t
*linker_section_ptr
;
2679 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2682 BFD_ASSERT (lsect
!= NULL
);
2684 /* Is this a global symbol? */
2687 struct ppc_elf_link_hash_entry
*eh
;
2689 /* Has this symbol already been allocated? If so, our work is done. */
2690 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2691 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2696 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2700 /* Allocation of a pointer to a local symbol. */
2701 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2703 /* Allocate a table to hold the local symbols if first time. */
2706 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2709 amt
*= sizeof (elf_linker_section_pointers_t
*);
2710 ptr
= bfd_zalloc (abfd
, amt
);
2715 elf_local_ptr_offsets (abfd
) = ptr
;
2718 /* Has this symbol already been allocated? If so, our work is done. */
2719 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2724 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2727 /* Allocate space for a pointer in the linker section, and allocate
2728 a new pointer record from internal memory. */
2729 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2730 amt
= sizeof (elf_linker_section_pointers_t
);
2731 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2733 if (!linker_section_ptr
)
2736 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2737 linker_section_ptr
->addend
= rel
->r_addend
;
2738 linker_section_ptr
->lsect
= lsect
;
2739 *ptr_linker_section_ptr
= linker_section_ptr
;
2741 linker_section_ptr
->offset
= lsect
->section
->size
;
2742 lsect
->section
->size
+= 4;
2746 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2747 lsect
->name
, (long) linker_section_ptr
->offset
,
2748 (long) lsect
->section
->size
);
2755 update_local_sym_info (bfd
*abfd
,
2756 Elf_Internal_Shdr
*symtab_hdr
,
2757 unsigned long r_symndx
,
2760 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
2761 char *local_got_tls_masks
;
2763 if (local_got_refcounts
== NULL
)
2765 bfd_size_type size
= symtab_hdr
->sh_info
;
2767 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
2768 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2769 if (local_got_refcounts
== NULL
)
2771 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2774 local_got_refcounts
[r_symndx
] += 1;
2775 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2776 local_got_tls_masks
[r_symndx
] |= tls_type
;
2781 update_plt_info (bfd
*abfd
, struct elf_link_hash_entry
*h
,
2782 asection
*sec
, bfd_vma addend
)
2784 struct plt_entry
*ent
;
2788 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
2789 if (ent
->sec
== sec
&& ent
->addend
== addend
)
2793 bfd_size_type amt
= sizeof (*ent
);
2794 ent
= bfd_alloc (abfd
, amt
);
2797 ent
->next
= h
->plt
.plist
;
2799 ent
->addend
= addend
;
2800 ent
->plt
.refcount
= 0;
2803 ent
->plt
.refcount
+= 1;
2807 static struct plt_entry
*
2808 find_plt_ent (struct elf_link_hash_entry
*h
, asection
*sec
, bfd_vma addend
)
2810 struct plt_entry
*ent
;
2814 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
2815 if (ent
->sec
== sec
&& ent
->addend
== addend
)
2821 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
2823 (*_bfd_error_handler
)
2824 (_("%B: relocation %s cannot be used when making a shared object"),
2826 ppc_elf_howto_table
[r_type
]->name
);
2827 bfd_set_error (bfd_error_bad_value
);
2830 /* Look through the relocs for a section during the first phase, and
2831 allocate space in the global offset table or procedure linkage
2835 ppc_elf_check_relocs (bfd
*abfd
,
2836 struct bfd_link_info
*info
,
2838 const Elf_Internal_Rela
*relocs
)
2840 struct ppc_elf_link_hash_table
*htab
;
2841 Elf_Internal_Shdr
*symtab_hdr
;
2842 struct elf_link_hash_entry
**sym_hashes
;
2843 const Elf_Internal_Rela
*rel
;
2844 const Elf_Internal_Rela
*rel_end
;
2845 asection
*got2
, *sreloc
;
2847 if (info
->relocatable
)
2850 /* Don't do anything special with non-loaded, non-alloced sections.
2851 In particular, any relocs in such sections should not affect GOT
2852 and PLT reference counting (ie. we don't allow them to create GOT
2853 or PLT entries), there's no possibility or desire to optimize TLS
2854 relocs, and there's not much point in propagating relocs to shared
2855 libs that the dynamic linker won't relocate. */
2856 if ((sec
->flags
& SEC_ALLOC
) == 0)
2860 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
2864 /* Initialize howto table if not already done. */
2865 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2866 ppc_elf_howto_init ();
2868 htab
= ppc_elf_hash_table (info
);
2869 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2870 sym_hashes
= elf_sym_hashes (abfd
);
2871 got2
= bfd_get_section_by_name (abfd
, ".got2");
2874 rel_end
= relocs
+ sec
->reloc_count
;
2875 for (rel
= relocs
; rel
< rel_end
; rel
++)
2877 unsigned long r_symndx
;
2878 enum elf_ppc_reloc_type r_type
;
2879 struct elf_link_hash_entry
*h
;
2882 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2883 if (r_symndx
< symtab_hdr
->sh_info
)
2887 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2888 while (h
->root
.type
== bfd_link_hash_indirect
2889 || h
->root
.type
== bfd_link_hash_warning
)
2890 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2893 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2894 This shows up in particular in an R_PPC_ADDR32 in the eabi
2897 && htab
->got
== NULL
2898 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2900 if (htab
->elf
.dynobj
== NULL
)
2901 htab
->elf
.dynobj
= abfd
;
2902 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
2904 BFD_ASSERT (h
== htab
->elf
.hgot
);
2907 r_type
= ELF32_R_TYPE (rel
->r_info
);
2910 case R_PPC_GOT_TLSLD16
:
2911 case R_PPC_GOT_TLSLD16_LO
:
2912 case R_PPC_GOT_TLSLD16_HI
:
2913 case R_PPC_GOT_TLSLD16_HA
:
2914 htab
->tlsld_got
.refcount
+= 1;
2915 tls_type
= TLS_TLS
| TLS_LD
;
2918 case R_PPC_GOT_TLSGD16
:
2919 case R_PPC_GOT_TLSGD16_LO
:
2920 case R_PPC_GOT_TLSGD16_HI
:
2921 case R_PPC_GOT_TLSGD16_HA
:
2922 tls_type
= TLS_TLS
| TLS_GD
;
2925 case R_PPC_GOT_TPREL16
:
2926 case R_PPC_GOT_TPREL16_LO
:
2927 case R_PPC_GOT_TPREL16_HI
:
2928 case R_PPC_GOT_TPREL16_HA
:
2930 info
->flags
|= DF_STATIC_TLS
;
2931 tls_type
= TLS_TLS
| TLS_TPREL
;
2934 case R_PPC_GOT_DTPREL16
:
2935 case R_PPC_GOT_DTPREL16_LO
:
2936 case R_PPC_GOT_DTPREL16_HI
:
2937 case R_PPC_GOT_DTPREL16_HA
:
2938 tls_type
= TLS_TLS
| TLS_DTPREL
;
2940 sec
->has_tls_reloc
= 1;
2943 /* GOT16 relocations */
2945 case R_PPC_GOT16_LO
:
2946 case R_PPC_GOT16_HI
:
2947 case R_PPC_GOT16_HA
:
2948 /* This symbol requires a global offset table entry. */
2949 if (htab
->got
== NULL
)
2951 if (htab
->elf
.dynobj
== NULL
)
2952 htab
->elf
.dynobj
= abfd
;
2953 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
2958 h
->got
.refcount
+= 1;
2959 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
2962 /* This is a global offset table entry for a local symbol. */
2963 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
2967 /* Indirect .sdata relocation. */
2968 case R_PPC_EMB_SDAI16
:
2971 bad_shared_reloc (abfd
, r_type
);
2974 if (htab
->sdata
[0].section
== NULL
2975 && !ppc_elf_create_linker_section (abfd
, info
, 0,
2978 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[0],
2983 /* Indirect .sdata2 relocation. */
2984 case R_PPC_EMB_SDA2I16
:
2987 bad_shared_reloc (abfd
, r_type
);
2990 if (htab
->sdata
[1].section
== NULL
2991 && !ppc_elf_create_linker_section (abfd
, info
, SEC_READONLY
,
2994 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[1],
2999 case R_PPC_SDAREL16
:
3000 case R_PPC_EMB_SDA2REL
:
3001 case R_PPC_EMB_SDA21
:
3002 case R_PPC_EMB_RELSDA
:
3003 case R_PPC_EMB_NADDR32
:
3004 case R_PPC_EMB_NADDR16
:
3005 case R_PPC_EMB_NADDR16_LO
:
3006 case R_PPC_EMB_NADDR16_HI
:
3007 case R_PPC_EMB_NADDR16_HA
:
3010 bad_shared_reloc (abfd
, r_type
);
3015 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3016 /* We may need a copy reloc. */
3017 h
->non_got_ref
= TRUE
;
3022 case R_PPC_PLTREL24
:
3023 case R_PPC_PLTREL32
:
3024 case R_PPC_PLT16_LO
:
3025 case R_PPC_PLT16_HI
:
3026 case R_PPC_PLT16_HA
:
3028 fprintf (stderr
, "Reloc requires a PLT entry\n");
3030 /* This symbol requires a procedure linkage table entry. We
3031 actually build the entry in finish_dynamic_symbol,
3032 because this might be a case of linking PIC code without
3033 linking in any dynamic objects, in which case we don't
3034 need to generate a procedure linkage table after all. */
3038 /* It does not make sense to have a procedure linkage
3039 table entry for a local symbol. */
3040 (*_bfd_error_handler
) (_("%B(%A+0x%lx): %s reloc against "
3044 (long) rel
->r_offset
,
3045 ppc_elf_howto_table
[r_type
]->name
);
3046 bfd_set_error (bfd_error_bad_value
);
3051 bfd_vma addend
= r_type
== R_PPC_PLTREL24
? rel
->r_addend
: 0;
3054 if (!update_plt_info (abfd
, h
, got2
, addend
))
3059 /* The following relocations don't need to propagate the
3060 relocation if linking a shared object since they are
3061 section relative. */
3063 case R_PPC_SECTOFF_LO
:
3064 case R_PPC_SECTOFF_HI
:
3065 case R_PPC_SECTOFF_HA
:
3066 case R_PPC_DTPREL16
:
3067 case R_PPC_DTPREL16_LO
:
3068 case R_PPC_DTPREL16_HI
:
3069 case R_PPC_DTPREL16_HA
:
3074 case R_PPC_REL16_LO
:
3075 case R_PPC_REL16_HI
:
3076 case R_PPC_REL16_HA
:
3080 /* These are just markers. */
3082 case R_PPC_EMB_MRKREF
:
3087 /* These should only appear in dynamic objects. */
3089 case R_PPC_GLOB_DAT
:
3090 case R_PPC_JMP_SLOT
:
3091 case R_PPC_RELATIVE
:
3094 /* These aren't handled yet. We'll report an error later. */
3096 case R_PPC_EMB_RELSEC16
:
3097 case R_PPC_EMB_RELST_LO
:
3098 case R_PPC_EMB_RELST_HI
:
3099 case R_PPC_EMB_RELST_HA
:
3100 case R_PPC_EMB_BIT_FLD
:
3103 /* This refers only to functions defined in the shared library. */
3104 case R_PPC_LOCAL24PC
:
3105 if (h
&& h
== htab
->elf
.hgot
)
3109 /* This relocation describes the C++ object vtable hierarchy.
3110 Reconstruct it for later use during GC. */
3111 case R_PPC_GNU_VTINHERIT
:
3112 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3116 /* This relocation describes which C++ vtable entries are actually
3117 used. Record for later use during GC. */
3118 case R_PPC_GNU_VTENTRY
:
3119 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3123 /* We shouldn't really be seeing these. */
3126 info
->flags
|= DF_STATIC_TLS
;
3130 case R_PPC_DTPMOD32
:
3131 case R_PPC_DTPREL32
:
3135 case R_PPC_TPREL16_LO
:
3136 case R_PPC_TPREL16_HI
:
3137 case R_PPC_TPREL16_HA
:
3139 info
->flags
|= DF_STATIC_TLS
;
3145 && (sec
->flags
& SEC_CODE
) != 0
3146 && (info
->shared
|| info
->pie
)
3149 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3150 the start of a function, which assembles to a REL32
3151 reference to .got2. If we detect one of these, then
3152 force the old PLT layout because the linker cannot
3153 reliably deduce the GOT pointer value needed for
3157 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
3166 case R_PPC_REL14_BRTAKEN
:
3167 case R_PPC_REL14_BRNTAKEN
:
3170 if (h
== htab
->elf
.hgot
)
3180 case R_PPC_ADDR16_LO
:
3181 case R_PPC_ADDR16_HI
:
3182 case R_PPC_ADDR16_HA
:
3184 case R_PPC_ADDR14_BRTAKEN
:
3185 case R_PPC_ADDR14_BRNTAKEN
:
3188 if (h
!= NULL
&& !info
->shared
)
3190 /* We may need a plt entry if the symbol turns out to be
3191 a function defined in a dynamic object. */
3192 if (!update_plt_info (abfd
, h
, NULL
, 0))
3195 /* We may need a copy reloc too. */
3200 /* If we are creating a shared library, and this is a reloc
3201 against a global symbol, or a non PC relative reloc
3202 against a local symbol, then we need to copy the reloc
3203 into the shared library. However, if we are linking with
3204 -Bsymbolic, we do not need to copy a reloc against a
3205 global symbol which is defined in an object we are
3206 including in the link (i.e., DEF_REGULAR is set). At
3207 this point we have not seen all the input files, so it is
3208 possible that DEF_REGULAR is not set now but will be set
3209 later (it is never cleared). In case of a weak definition,
3210 DEF_REGULAR may be cleared later by a strong definition in
3211 a shared library. We account for that possibility below by
3212 storing information in the dyn_relocs field of the hash
3213 table entry. A similar situation occurs when creating
3214 shared libraries and symbol visibility changes render the
3217 If on the other hand, we are creating an executable, we
3218 may need to keep relocations for symbols satisfied by a
3219 dynamic library if we manage to avoid copy relocs for the
3222 && (MUST_BE_DYN_RELOC (r_type
)
3224 && (! info
->symbolic
3225 || h
->root
.type
== bfd_link_hash_defweak
3226 || !h
->def_regular
))))
3227 || (ELIMINATE_COPY_RELOCS
3230 && (h
->root
.type
== bfd_link_hash_defweak
3231 || !h
->def_regular
)))
3233 struct ppc_elf_dyn_relocs
*p
;
3234 struct ppc_elf_dyn_relocs
**head
;
3238 "ppc_elf_check_relocs needs to "
3239 "create relocation for %s\n",
3240 (h
&& h
->root
.root
.string
3241 ? h
->root
.root
.string
: "<unknown>"));
3247 name
= (bfd_elf_string_from_elf_section
3249 elf_elfheader (abfd
)->e_shstrndx
,
3250 elf_section_data (sec
)->rel_hdr
.sh_name
));
3254 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3255 && strcmp (bfd_get_section_name (abfd
, sec
),
3258 if (htab
->elf
.dynobj
== NULL
)
3259 htab
->elf
.dynobj
= abfd
;
3260 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3265 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3266 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
3267 | SEC_ALLOC
| SEC_LOAD
);
3268 sreloc
= bfd_make_section_with_flags (htab
->elf
.dynobj
,
3272 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3276 elf_section_data (sec
)->sreloc
= sreloc
;
3279 /* If this is a global symbol, we count the number of
3280 relocations we need for this symbol. */
3283 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3287 /* Track dynamic relocs needed for local syms too.
3288 We really need local syms available to do this
3292 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3297 head
= ((struct ppc_elf_dyn_relocs
**)
3298 &elf_section_data (s
)->local_dynrel
);
3302 if (p
== NULL
|| p
->sec
!= sec
)
3304 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3315 if (!MUST_BE_DYN_RELOC (r_type
))
3326 /* Merge backend specific data from an object file to the output
3327 object file when linking. */
3330 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3336 if (!is_ppc_elf_target (ibfd
->xvec
)
3337 || !is_ppc_elf_target (obfd
->xvec
))
3340 /* Check if we have the same endianess. */
3341 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
3344 new_flags
= elf_elfheader (ibfd
)->e_flags
;
3345 old_flags
= elf_elfheader (obfd
)->e_flags
;
3346 if (!elf_flags_init (obfd
))
3348 /* First call, no flags set. */
3349 elf_flags_init (obfd
) = TRUE
;
3350 elf_elfheader (obfd
)->e_flags
= new_flags
;
3353 /* Compatible flags are ok. */
3354 else if (new_flags
== old_flags
)
3357 /* Incompatible flags. */
3360 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
3361 to be linked with either. */
3363 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
3364 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
3367 (*_bfd_error_handler
)
3368 (_("%B: compiled with -mrelocatable and linked with "
3369 "modules compiled normally"), ibfd
);
3371 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
3372 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
3375 (*_bfd_error_handler
)
3376 (_("%B: compiled normally and linked with "
3377 "modules compiled with -mrelocatable"), ibfd
);
3380 /* The output is -mrelocatable-lib iff both the input files are. */
3381 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
3382 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
3384 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
3385 but each input file is either -mrelocatable or -mrelocatable-lib. */
3386 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
3387 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
3388 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
3389 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
3391 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
3392 any module uses it. */
3393 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
3395 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
3396 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
3398 /* Warn about any other mismatches. */
3399 if (new_flags
!= old_flags
)
3402 (*_bfd_error_handler
)
3403 (_("%B: uses different e_flags (0x%lx) fields "
3404 "than previous modules (0x%lx)"),
3405 ibfd
, (long) new_flags
, (long) old_flags
);
3410 bfd_set_error (bfd_error_bad_value
);
3418 /* Choose which PLT scheme to use, and set .plt flags appropriately.
3419 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
3421 ppc_elf_select_plt_layout (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3422 struct bfd_link_info
*info
,
3425 struct ppc_elf_link_hash_table
*htab
;
3427 htab
= ppc_elf_hash_table (info
);
3428 if (force_old_plt
|| !htab
->new_plt
)
3433 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3434 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3436 /* The new PLT is a loaded section. */
3437 if (htab
->plt
!= NULL
3438 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->plt
, flags
))
3441 /* The new GOT is not executable. */
3442 if (htab
->got
!= NULL
3443 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->got
, flags
))
3448 /* Stop an unused .glink section from affecting .text alignment. */
3449 if (htab
->glink
!= NULL
3450 && !bfd_set_section_alignment (htab
->elf
.dynobj
, htab
->glink
, 0))
3453 return !htab
->old_plt
;
3456 /* Return the section that should be marked against GC for a given
3460 ppc_elf_gc_mark_hook (asection
*sec
,
3461 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3462 Elf_Internal_Rela
*rel
,
3463 struct elf_link_hash_entry
*h
,
3464 Elf_Internal_Sym
*sym
)
3468 switch (ELF32_R_TYPE (rel
->r_info
))
3470 case R_PPC_GNU_VTINHERIT
:
3471 case R_PPC_GNU_VTENTRY
:
3475 switch (h
->root
.type
)
3477 case bfd_link_hash_defined
:
3478 case bfd_link_hash_defweak
:
3479 return h
->root
.u
.def
.section
;
3481 case bfd_link_hash_common
:
3482 return h
->root
.u
.c
.p
->section
;
3490 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3495 /* Update the got, plt and dynamic reloc reference counts for the
3496 section being removed. */
3499 ppc_elf_gc_sweep_hook (bfd
*abfd
,
3500 struct bfd_link_info
*info
,
3502 const Elf_Internal_Rela
*relocs
)
3504 struct ppc_elf_link_hash_table
*htab
;
3505 Elf_Internal_Shdr
*symtab_hdr
;
3506 struct elf_link_hash_entry
**sym_hashes
;
3507 bfd_signed_vma
*local_got_refcounts
;
3508 const Elf_Internal_Rela
*rel
, *relend
;
3511 if ((sec
->flags
& SEC_ALLOC
) == 0)
3514 elf_section_data (sec
)->local_dynrel
= NULL
;
3516 htab
= ppc_elf_hash_table (info
);
3517 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3518 sym_hashes
= elf_sym_hashes (abfd
);
3519 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3520 got2
= bfd_get_section_by_name (abfd
, ".got2");
3522 relend
= relocs
+ sec
->reloc_count
;
3523 for (rel
= relocs
; rel
< relend
; rel
++)
3525 unsigned long r_symndx
;
3526 enum elf_ppc_reloc_type r_type
;
3527 struct elf_link_hash_entry
*h
= NULL
;
3529 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3530 if (r_symndx
>= symtab_hdr
->sh_info
)
3532 struct ppc_elf_dyn_relocs
**pp
, *p
;
3533 struct ppc_elf_link_hash_entry
*eh
;
3535 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3536 while (h
->root
.type
== bfd_link_hash_indirect
3537 || h
->root
.type
== bfd_link_hash_warning
)
3538 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3539 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3541 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3544 /* Everything must go for SEC. */
3550 r_type
= ELF32_R_TYPE (rel
->r_info
);
3553 case R_PPC_GOT_TLSLD16
:
3554 case R_PPC_GOT_TLSLD16_LO
:
3555 case R_PPC_GOT_TLSLD16_HI
:
3556 case R_PPC_GOT_TLSLD16_HA
:
3557 htab
->tlsld_got
.refcount
-= 1;
3560 case R_PPC_GOT_TLSGD16
:
3561 case R_PPC_GOT_TLSGD16_LO
:
3562 case R_PPC_GOT_TLSGD16_HI
:
3563 case R_PPC_GOT_TLSGD16_HA
:
3564 case R_PPC_GOT_TPREL16
:
3565 case R_PPC_GOT_TPREL16_LO
:
3566 case R_PPC_GOT_TPREL16_HI
:
3567 case R_PPC_GOT_TPREL16_HA
:
3568 case R_PPC_GOT_DTPREL16
:
3569 case R_PPC_GOT_DTPREL16_LO
:
3570 case R_PPC_GOT_DTPREL16_HI
:
3571 case R_PPC_GOT_DTPREL16_HA
:
3573 case R_PPC_GOT16_LO
:
3574 case R_PPC_GOT16_HI
:
3575 case R_PPC_GOT16_HA
:
3578 if (h
->got
.refcount
> 0)
3581 else if (local_got_refcounts
!= NULL
)
3583 if (local_got_refcounts
[r_symndx
] > 0)
3584 local_got_refcounts
[r_symndx
]--;
3590 case R_PPC_REL14_BRTAKEN
:
3591 case R_PPC_REL14_BRNTAKEN
:
3593 if (h
== NULL
|| h
== htab
->elf
.hgot
)
3600 case R_PPC_ADDR16_LO
:
3601 case R_PPC_ADDR16_HI
:
3602 case R_PPC_ADDR16_HA
:
3604 case R_PPC_ADDR14_BRTAKEN
:
3605 case R_PPC_ADDR14_BRNTAKEN
:
3609 case R_PPC_PLTREL24
:
3610 case R_PPC_PLT16_LO
:
3611 case R_PPC_PLT16_HI
:
3612 case R_PPC_PLT16_HA
:
3615 bfd_vma addend
= r_type
== R_PPC_PLTREL24
? rel
->r_addend
: 0;
3616 struct plt_entry
*ent
= find_plt_ent (h
, got2
, addend
);
3617 if (ent
->plt
.refcount
> 0)
3618 ent
->plt
.refcount
-= 1;
3629 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
3632 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
3634 struct ppc_elf_link_hash_table
*htab
;
3636 htab
= ppc_elf_hash_table (info
);
3638 && htab
->plt
!= NULL
3639 && htab
->plt
->output_section
!= NULL
)
3641 elf_section_type (htab
->plt
->output_section
) = SHT_PROGBITS
;
3642 elf_section_flags (htab
->plt
->output_section
) = SHF_ALLOC
+ SHF_WRITE
;
3645 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3646 FALSE
, FALSE
, TRUE
);
3647 return _bfd_elf_tls_setup (obfd
, info
);
3650 /* Run through all the TLS relocs looking for optimization
3654 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
3655 struct bfd_link_info
*info
)
3659 struct ppc_elf_link_hash_table
*htab
;
3661 if (info
->relocatable
|| info
->shared
)
3664 htab
= ppc_elf_hash_table (info
);
3665 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3667 Elf_Internal_Sym
*locsyms
= NULL
;
3668 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3670 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3671 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
3673 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3674 int expecting_tls_get_addr
;
3676 /* Read the relocations. */
3677 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
3679 if (relstart
== NULL
)
3682 expecting_tls_get_addr
= 0;
3683 relend
= relstart
+ sec
->reloc_count
;
3684 for (rel
= relstart
; rel
< relend
; rel
++)
3686 enum elf_ppc_reloc_type r_type
;
3687 unsigned long r_symndx
;
3688 struct elf_link_hash_entry
*h
= NULL
;
3690 char tls_set
, tls_clear
;
3691 bfd_boolean is_local
;
3693 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3694 if (r_symndx
>= symtab_hdr
->sh_info
)
3696 struct elf_link_hash_entry
**sym_hashes
;
3698 sym_hashes
= elf_sym_hashes (ibfd
);
3699 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3700 while (h
->root
.type
== bfd_link_hash_indirect
3701 || h
->root
.type
== bfd_link_hash_warning
)
3702 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3710 r_type
= ELF32_R_TYPE (rel
->r_info
);
3713 case R_PPC_GOT_TLSLD16
:
3714 case R_PPC_GOT_TLSLD16_LO
:
3715 case R_PPC_GOT_TLSLD16_HI
:
3716 case R_PPC_GOT_TLSLD16_HA
:
3717 /* These relocs should never be against a symbol
3718 defined in a shared lib. Leave them alone if
3719 that turns out to be the case. */
3720 expecting_tls_get_addr
= 0;
3721 htab
->tlsld_got
.refcount
-= 1;
3728 expecting_tls_get_addr
= 1;
3731 case R_PPC_GOT_TLSGD16
:
3732 case R_PPC_GOT_TLSGD16_LO
:
3733 case R_PPC_GOT_TLSGD16_HI
:
3734 case R_PPC_GOT_TLSGD16_HA
:
3740 tls_set
= TLS_TLS
| TLS_TPRELGD
;
3742 expecting_tls_get_addr
= 1;
3745 case R_PPC_GOT_TPREL16
:
3746 case R_PPC_GOT_TPREL16_LO
:
3747 case R_PPC_GOT_TPREL16_HI
:
3748 case R_PPC_GOT_TPREL16_HA
:
3749 expecting_tls_get_addr
= 0;
3754 tls_clear
= TLS_TPREL
;
3761 case R_PPC_REL14_BRTAKEN
:
3762 case R_PPC_REL14_BRNTAKEN
:
3764 if (expecting_tls_get_addr
3766 && h
== htab
->tls_get_addr
)
3768 struct plt_entry
*ent
= find_plt_ent (h
, NULL
, 0);
3769 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
3770 ent
->plt
.refcount
-= 1;
3772 expecting_tls_get_addr
= 0;
3776 expecting_tls_get_addr
= 0;
3784 /* We managed to get rid of a got entry. */
3785 if (h
->got
.refcount
> 0)
3786 h
->got
.refcount
-= 1;
3788 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
3792 Elf_Internal_Sym
*sym
;
3793 bfd_signed_vma
*lgot_refs
;
3796 if (locsyms
== NULL
)
3798 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3799 if (locsyms
== NULL
)
3800 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3801 symtab_hdr
->sh_info
,
3802 0, NULL
, NULL
, NULL
);
3803 if (locsyms
== NULL
)
3805 if (elf_section_data (sec
)->relocs
!= relstart
)
3810 sym
= locsyms
+ r_symndx
;
3811 lgot_refs
= elf_local_got_refcounts (ibfd
);
3812 if (lgot_refs
== NULL
)
3816 /* We managed to get rid of a got entry. */
3817 if (lgot_refs
[r_symndx
] > 0)
3818 lgot_refs
[r_symndx
] -= 1;
3820 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
3821 tls_mask
= &lgot_masks
[r_symndx
];
3824 *tls_mask
|= tls_set
;
3825 *tls_mask
&= ~tls_clear
;
3828 if (elf_section_data (sec
)->relocs
!= relstart
)
3833 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
3835 if (!info
->keep_memory
)
3838 symtab_hdr
->contents
= (unsigned char *) locsyms
;
3844 /* Adjust a symbol defined by a dynamic object and referenced by a
3845 regular object. The current definition is in some section of the
3846 dynamic object, but we're not including those sections. We have to
3847 change the definition to something the rest of the link can
3851 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3852 struct elf_link_hash_entry
*h
)
3854 struct ppc_elf_link_hash_table
*htab
;
3856 unsigned int power_of_two
;
3859 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
3860 h
->root
.root
.string
);
3863 /* Make sure we know what is going on here. */
3864 htab
= ppc_elf_hash_table (info
);
3865 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
3867 || h
->u
.weakdef
!= NULL
3870 && !h
->def_regular
)));
3872 /* Deal with function syms. */
3873 if (h
->type
== STT_FUNC
3876 /* Clear procedure linkage table information for any symbol that
3877 won't need a .plt entry. */
3878 struct plt_entry
*ent
;
3879 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
3880 if (ent
->plt
.refcount
> 0)
3883 || SYMBOL_CALLS_LOCAL (info
, h
)
3884 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3885 && h
->root
.type
== bfd_link_hash_undefweak
))
3887 /* A PLT entry is not required/allowed when:
3889 1. We are not using ld.so; because then the PLT entry
3890 can't be set up, so we can't use one. In this case,
3891 ppc_elf_adjust_dynamic_symbol won't even be called.
3893 2. GC has rendered the entry unused.
3895 3. We know for certain that a call to this symbol
3896 will go to this object, or will remain undefined. */
3897 h
->plt
.plist
= NULL
;
3903 h
->plt
.plist
= NULL
;
3905 /* If this is a weak symbol, and there is a real definition, the
3906 processor independent code will have arranged for us to see the
3907 real definition first, and we can just use the same value. */
3908 if (h
->u
.weakdef
!= NULL
)
3910 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3911 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3912 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3913 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3914 if (ELIMINATE_COPY_RELOCS
)
3915 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3919 /* This is a reference to a symbol defined by a dynamic object which
3920 is not a function. */
3922 /* First, a fudge for old shared libs that export some symbols they
3925 && (strcmp (h
->root
.root
.string
, "_SDA_BASE_") == 0
3926 || strcmp (h
->root
.root
.string
, "_SDA2_BASE_") == 0))
3928 /* These symbols will be defined later, as if they were defined in
3929 a linker script. We don't want to use a definition in a shared
3931 const struct elf_backend_data
*bed
;
3933 bed
= get_elf_backend_data (htab
->elf
.dynobj
);
3934 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
3935 h
->root
.type
= bfd_link_hash_undefined
;
3936 h
->root
.u
.undef
.abfd
= htab
->elf
.dynobj
;
3940 /* If we are creating a shared library, we must presume that the
3941 only references to the symbol are via the global offset table.
3942 For such cases we need not do anything here; the relocations will
3943 be handled correctly by relocate_section. */
3947 /* If there are no references to this symbol that do not use the
3948 GOT, we don't need to generate a copy reloc. */
3949 if (!h
->non_got_ref
)
3952 /* If we didn't find any dynamic relocs in read-only sections, then we'll
3953 be keeping the dynamic relocs and avoiding the copy reloc. We can't
3954 do this if there are any small data relocations. */
3955 if (ELIMINATE_COPY_RELOCS
3956 && !ppc_elf_hash_entry (h
)->has_sda_refs
)
3958 struct ppc_elf_dyn_relocs
*p
;
3959 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3961 s
= p
->sec
->output_section
;
3962 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3973 /* We must allocate the symbol in our .dynbss section, which will
3974 become part of the .bss section of the executable. There will be
3975 an entry for this symbol in the .dynsym section. The dynamic
3976 object will contain position independent code, so all references
3977 from the dynamic object to this symbol will go through the global
3978 offset table. The dynamic linker will use the .dynsym entry to
3979 determine the address it must put in the global offset table, so
3980 both the dynamic object and the regular object will refer to the
3981 same memory location for the variable.
3983 Of course, if the symbol is referenced using SDAREL relocs, we
3984 must instead allocate it in .sbss. */
3986 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
3990 BFD_ASSERT (s
!= NULL
);
3992 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3993 copy the initial value out of the dynamic object and into the
3994 runtime process image. We need to remember the offset into the
3995 .rela.bss section we are going to use. */
3996 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4000 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
4001 srel
= htab
->relsbss
;
4003 srel
= htab
->relbss
;
4004 BFD_ASSERT (srel
!= NULL
);
4005 srel
->size
+= sizeof (Elf32_External_Rela
);
4009 /* We need to figure out the alignment required for this symbol. I
4010 have no idea how ELF linkers handle this. */
4011 power_of_two
= bfd_log2 (h
->size
);
4012 if (power_of_two
> 4)
4015 /* Apply the required alignment. */
4016 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
4017 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
4019 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
4023 /* Define the symbol as being at this point in the section. */
4024 h
->root
.u
.def
.section
= s
;
4025 h
->root
.u
.def
.value
= s
->size
;
4027 /* Increment the section size to make room for the symbol. */
4033 /* Allocate NEED contiguous space in .got, and return the offset.
4034 Handles allocation of the got header when crossing 32k. */
4037 allocate_got (struct ppc_elf_link_hash_table
*htab
, unsigned int need
)
4040 unsigned int max_before_header
= 32768;
4043 max_before_header
= 32764;
4045 if (need
<= htab
->got_gap
)
4047 where
= max_before_header
- htab
->got_gap
;
4048 htab
->got_gap
-= need
;
4052 if (htab
->got
->size
+ need
> max_before_header
4053 && htab
->got
->size
<= max_before_header
)
4055 htab
->got_gap
= max_before_header
- htab
->got
->size
;
4056 htab
->got
->size
= max_before_header
+ htab
->got_header_size
;
4058 where
= htab
->got
->size
;
4059 htab
->got
->size
+= need
;
4064 /* Allocate space in associated reloc sections for dynamic relocs. */
4067 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4069 struct bfd_link_info
*info
= inf
;
4070 struct ppc_elf_link_hash_entry
*eh
;
4071 struct ppc_elf_link_hash_table
*htab
;
4072 struct ppc_elf_dyn_relocs
*p
;
4074 if (h
->root
.type
== bfd_link_hash_indirect
)
4077 if (h
->root
.type
== bfd_link_hash_warning
)
4078 /* When warning symbols are created, they **replace** the "real"
4079 entry in the hash table, thus we never get to see the real
4080 symbol in a hash traversal. So look at it now. */
4081 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4083 htab
= ppc_elf_hash_table (info
);
4084 if (htab
->elf
.dynamic_sections_created
)
4086 struct plt_entry
*ent
;
4087 bfd_boolean doneone
= FALSE
;
4088 bfd_vma plt_offset
= 0, glink_offset
= 0;
4090 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4091 if (ent
->plt
.refcount
> 0)
4093 /* Make sure this symbol is output as a dynamic symbol. */
4094 if (h
->dynindx
== -1
4095 && !h
->forced_local
)
4097 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4102 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
4104 asection
*s
= htab
->plt
;
4110 plt_offset
= s
->size
;
4113 ent
->plt
.offset
= plt_offset
;
4116 if (!doneone
|| info
->shared
|| info
->pie
)
4118 glink_offset
= s
->size
;
4119 s
->size
+= GLINK_ENTRY_SIZE
;
4125 h
->root
.u
.def
.section
= s
;
4126 h
->root
.u
.def
.value
= glink_offset
;
4128 ent
->glink_offset
= glink_offset
;
4134 /* If this is the first .plt entry, make room
4135 for the special first entry. */
4137 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
4139 /* The PowerPC PLT is actually composed of two
4140 parts, the first part is 2 words (for a load
4141 and a jump), and then there is a remaining
4142 word available at the end. */
4143 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
4145 * ((s
->size
- PLT_INITIAL_ENTRY_SIZE
)
4146 / PLT_ENTRY_SIZE
)));
4148 /* If this symbol is not defined in a regular
4149 file, and we are not generating a shared
4150 library, then set the symbol to this location
4151 in the .plt. This is required to make
4152 function pointers compare as equal between
4153 the normal executable and the shared library. */
4157 h
->root
.u
.def
.section
= s
;
4158 h
->root
.u
.def
.value
= plt_offset
;
4161 /* Make room for this entry. After the 8192nd
4162 entry, room for two entries is allocated. */
4163 s
->size
+= PLT_ENTRY_SIZE
;
4164 if ((s
->size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
4165 > PLT_NUM_SINGLE_ENTRIES
)
4166 s
->size
+= PLT_ENTRY_SIZE
;
4168 ent
->plt
.offset
= plt_offset
;
4171 /* We also need to make an entry in the .rela.plt section. */
4174 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
4179 ent
->plt
.offset
= (bfd_vma
) -1;
4183 h
->plt
.plist
= NULL
;
4190 h
->plt
.plist
= NULL
;
4194 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4195 if (eh
->elf
.got
.refcount
> 0)
4197 /* Make sure this symbol is output as a dynamic symbol. */
4198 if (eh
->elf
.dynindx
== -1
4199 && !eh
->elf
.forced_local
)
4201 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
4205 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
4206 && !eh
->elf
.def_dynamic
)
4207 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
4208 eh
->elf
.got
.offset
= (bfd_vma
) -1;
4212 unsigned int need
= 0;
4213 if ((eh
->tls_mask
& TLS_TLS
) != 0)
4215 if ((eh
->tls_mask
& TLS_LD
) != 0)
4217 if ((eh
->tls_mask
& TLS_GD
) != 0)
4219 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4221 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
4226 eh
->elf
.got
.offset
= allocate_got (htab
, need
);
4227 dyn
= htab
->elf
.dynamic_sections_created
;
4229 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
4230 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
4231 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
4233 /* All the entries we allocated need relocs.
4234 Except LD only needs one. */
4235 if ((eh
->tls_mask
& TLS_LD
) != 0)
4237 htab
->relgot
->size
+= need
* (sizeof (Elf32_External_Rela
) / 4);
4242 eh
->elf
.got
.offset
= (bfd_vma
) -1;
4244 if (eh
->dyn_relocs
== NULL
)
4247 /* In the shared -Bsymbolic case, discard space allocated for
4248 dynamic pc-relative relocs against symbols which turn out to be
4249 defined in regular objects. For the normal shared case, discard
4250 space for relocs that have become local due to symbol visibility
4255 /* Relocs that use pc_count are those that appear on a call insn,
4256 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
4257 generated via assembly. We want calls to protected symbols to
4258 resolve directly to the function rather than going via the plt.
4259 If people want function pointer comparisons to work as expected
4260 then they should avoid writing weird assembly. */
4261 if (SYMBOL_CALLS_LOCAL (info
, h
))
4263 struct ppc_elf_dyn_relocs
**pp
;
4265 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4267 p
->count
-= p
->pc_count
;
4276 /* Also discard relocs on undefined weak syms with non-default
4278 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4279 && h
->root
.type
== bfd_link_hash_undefweak
)
4280 eh
->dyn_relocs
= NULL
;
4282 /* Make sure undefined weak symbols are output as a dynamic symbol
4285 && eh
->dyn_relocs
!= NULL
4287 && h
->root
.type
== bfd_link_hash_undefweak
4288 && !h
->forced_local
)
4290 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4294 else if (ELIMINATE_COPY_RELOCS
)
4296 /* For the non-shared case, discard space for relocs against
4297 symbols which turn out to need copy relocs or are not
4304 /* Make sure this symbol is output as a dynamic symbol.
4305 Undefined weak syms won't yet be marked as dynamic. */
4306 if (h
->dynindx
== -1
4307 && !h
->forced_local
)
4309 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4313 /* If that succeeded, we know we'll be keeping all the
4315 if (h
->dynindx
!= -1)
4319 eh
->dyn_relocs
= NULL
;
4324 /* Finally, allocate space. */
4325 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4327 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4328 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
4334 /* Find any dynamic relocs that apply to read-only sections. */
4337 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
4339 struct ppc_elf_dyn_relocs
*p
;
4341 if (h
->root
.type
== bfd_link_hash_indirect
)
4344 if (h
->root
.type
== bfd_link_hash_warning
)
4345 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4347 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4349 asection
*s
= p
->sec
->output_section
;
4352 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
4353 == (SEC_READONLY
| SEC_ALLOC
)))
4355 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
4357 /* Not an error, just cut short the traversal. */
4364 /* Set the sizes of the dynamic sections. */
4367 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4368 struct bfd_link_info
*info
)
4370 struct ppc_elf_link_hash_table
*htab
;
4376 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
4379 htab
= ppc_elf_hash_table (info
);
4380 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4382 if (elf_hash_table (info
)->dynamic_sections_created
)
4384 /* Set the contents of the .interp section to the interpreter. */
4385 if (info
->executable
)
4387 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
4388 BFD_ASSERT (s
!= NULL
);
4389 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4390 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4395 htab
->got_header_size
= 16;
4397 htab
->got_header_size
= 12;
4399 /* Set up .got offsets for local syms, and space for local dynamic
4401 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4403 bfd_signed_vma
*local_got
;
4404 bfd_signed_vma
*end_local_got
;
4406 bfd_size_type locsymcount
;
4407 Elf_Internal_Shdr
*symtab_hdr
;
4409 if (!is_ppc_elf_target (ibfd
->xvec
))
4412 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4414 struct ppc_elf_dyn_relocs
*p
;
4416 for (p
= ((struct ppc_elf_dyn_relocs
*)
4417 elf_section_data (s
)->local_dynrel
);
4421 if (!bfd_is_abs_section (p
->sec
)
4422 && bfd_is_abs_section (p
->sec
->output_section
))
4424 /* Input section has been discarded, either because
4425 it is a copy of a linkonce section or due to
4426 linker script /DISCARD/, so we'll be discarding
4429 else if (p
->count
!= 0)
4431 elf_section_data (p
->sec
)->sreloc
->size
4432 += p
->count
* sizeof (Elf32_External_Rela
);
4433 if ((p
->sec
->output_section
->flags
4434 & (SEC_READONLY
| SEC_ALLOC
))
4435 == (SEC_READONLY
| SEC_ALLOC
))
4436 info
->flags
|= DF_TEXTREL
;
4441 local_got
= elf_local_got_refcounts (ibfd
);
4445 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4446 locsymcount
= symtab_hdr
->sh_info
;
4447 end_local_got
= local_got
+ locsymcount
;
4448 lgot_masks
= (char *) end_local_got
;
4449 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
4452 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
4454 /* If just an LD reloc, we'll just use
4455 htab->tlsld_got.offset. */
4456 htab
->tlsld_got
.refcount
+= 1;
4457 *local_got
= (bfd_vma
) -1;
4461 unsigned int need
= 0;
4462 if ((*lgot_masks
& TLS_TLS
) != 0)
4464 if ((*lgot_masks
& TLS_GD
) != 0)
4466 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4468 if ((*lgot_masks
& TLS_DTPREL
) != 0)
4473 *local_got
= allocate_got (htab
, need
);
4475 htab
->relgot
->size
+= (need
4476 * (sizeof (Elf32_External_Rela
) / 4));
4480 *local_got
= (bfd_vma
) -1;
4483 if (htab
->tlsld_got
.refcount
> 0)
4485 htab
->tlsld_got
.offset
= allocate_got (htab
, 8);
4487 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
4490 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
4492 /* Allocate space for global sym dynamic relocs. */
4493 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
4495 if (htab
->got
!= NULL
)
4497 unsigned int g_o_t
= 32768;
4499 /* If we haven't allocated the header, do so now. */
4500 if (htab
->got
->size
<= 32768)
4502 g_o_t
= htab
->got
->size
;
4503 htab
->got
->size
+= htab
->got_header_size
;
4508 htab
->elf
.hgot
->root
.u
.def
.value
= g_o_t
;
4511 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
4513 htab
->glink_pltresolve
= htab
->glink
->size
;
4514 /* Space for the branch table. */
4515 htab
->glink
->size
+= htab
->glink
->size
/ (GLINK_ENTRY_SIZE
/ 4) - 4;
4516 /* Pad out to align the start of PLTresolve. */
4517 htab
->glink
->size
+= -htab
->glink
->size
& 15;
4518 htab
->glink
->size
+= GLINK_PLTRESOLVE
;
4521 /* We've now determined the sizes of the various dynamic sections.
4522 Allocate memory for them. */
4524 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4526 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4534 /* Strip this section if we don't need it; see the
4537 else if (s
== htab
->sdata
[0].section
4538 || s
== htab
->sdata
[1].section
)
4540 /* Strip these too. */
4542 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4546 /* If we don't need this section, strip it from the
4547 output file. This is mostly to handle .rela.bss and
4548 .rela.plt. We must create both sections in
4549 create_dynamic_sections, because they must be created
4550 before the linker maps input sections to output
4551 sections. The linker does that before
4552 adjust_dynamic_symbol is called, and it is that
4553 function which decides whether anything needs to go
4554 into these sections. */
4558 /* Remember whether there are any relocation sections. */
4561 /* We use the reloc_count field as a counter if we need
4562 to copy relocs into the output file. */
4568 /* It's not one of our sections, so don't allocate space. */
4574 s
->flags
|= SEC_EXCLUDE
;
4578 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
4581 /* Allocate memory for the section contents. */
4582 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
4583 if (s
->contents
== NULL
)
4587 if (htab
->elf
.dynamic_sections_created
)
4589 /* Add some entries to the .dynamic section. We fill in the
4590 values later, in ppc_elf_finish_dynamic_sections, but we
4591 must add the entries now so that we get the correct size for
4592 the .dynamic section. The DT_DEBUG entry is filled in by the
4593 dynamic linker and used by the debugger. */
4594 #define add_dynamic_entry(TAG, VAL) \
4595 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4597 if (info
->executable
)
4599 if (!add_dynamic_entry (DT_DEBUG
, 0))
4603 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
4605 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4606 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4607 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4608 || !add_dynamic_entry (DT_JMPREL
, 0))
4612 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
4614 if (!add_dynamic_entry (DT_PPC_GOT
, 0))
4620 if (!add_dynamic_entry (DT_RELA
, 0)
4621 || !add_dynamic_entry (DT_RELASZ
, 0)
4622 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4626 /* If any dynamic relocs apply to a read-only section, then we
4627 need a DT_TEXTREL entry. */
4628 if ((info
->flags
& DF_TEXTREL
) == 0)
4629 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
4632 if ((info
->flags
& DF_TEXTREL
) != 0)
4634 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4638 #undef add_dynamic_entry
4643 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
4645 static const int shared_stub_entry
[] =
4647 0x7c0802a6, /* mflr 0 */
4648 0x429f0005, /* bcl 20, 31, .Lxxx */
4649 0x7d6802a6, /* mflr 11 */
4650 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
4651 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
4652 0x7c0803a6, /* mtlr 0 */
4653 0x7d6903a6, /* mtctr 11 */
4654 0x4e800420, /* bctr */
4657 static const int stub_entry
[] =
4659 0x3d600000, /* lis 11,xxx@ha */
4660 0x396b0000, /* addi 11,11,xxx@l */
4661 0x7d6903a6, /* mtctr 11 */
4662 0x4e800420, /* bctr */
4666 ppc_elf_relax_section (bfd
*abfd
,
4668 struct bfd_link_info
*link_info
,
4673 struct one_fixup
*next
;
4679 Elf_Internal_Shdr
*symtab_hdr
;
4680 bfd_byte
*contents
= NULL
;
4681 Elf_Internal_Sym
*isymbuf
= NULL
;
4682 Elf_Internal_Rela
*internal_relocs
= NULL
;
4683 Elf_Internal_Rela
*irel
, *irelend
;
4684 struct one_fixup
*fixups
= NULL
;
4685 bfd_boolean changed
;
4686 struct ppc_elf_link_hash_table
*htab
;
4687 bfd_size_type trampoff
;
4692 /* Nothing to do if there are no relocations, and no need to do
4693 anything with non-alloc sections. */
4694 if ((isec
->flags
& SEC_ALLOC
) == 0
4695 || (isec
->flags
& SEC_RELOC
) == 0
4696 || isec
->reloc_count
== 0)
4699 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
4700 /* Space for a branch around any trampolines. */
4703 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4705 /* Get a copy of the native relocations. */
4706 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
4707 link_info
->keep_memory
);
4708 if (internal_relocs
== NULL
)
4711 htab
= ppc_elf_hash_table (link_info
);
4712 got2
= bfd_get_section_by_name (abfd
, ".got2");
4714 irelend
= internal_relocs
+ isec
->reloc_count
;
4715 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
4717 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
4718 bfd_vma symaddr
, reladdr
, toff
, roff
;
4720 struct one_fixup
*f
;
4721 size_t insn_offset
= 0;
4722 bfd_vma max_branch_offset
, val
;
4725 unsigned char sym_type
;
4730 case R_PPC_LOCAL24PC
:
4731 case R_PPC_PLTREL24
:
4732 max_branch_offset
= 1 << 25;
4736 case R_PPC_REL14_BRTAKEN
:
4737 case R_PPC_REL14_BRNTAKEN
:
4738 max_branch_offset
= 1 << 15;
4745 /* Get the value of the symbol referred to by the reloc. */
4746 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
4748 /* A local symbol. */
4749 Elf_Internal_Sym
*isym
;
4751 /* Read this BFD's local symbols. */
4752 if (isymbuf
== NULL
)
4754 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4755 if (isymbuf
== NULL
)
4756 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
4757 symtab_hdr
->sh_info
, 0,
4762 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
4763 if (isym
->st_shndx
== SHN_UNDEF
)
4764 continue; /* We can't do anything with undefined symbols. */
4765 else if (isym
->st_shndx
== SHN_ABS
)
4766 tsec
= bfd_abs_section_ptr
;
4767 else if (isym
->st_shndx
== SHN_COMMON
)
4768 tsec
= bfd_com_section_ptr
;
4770 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4772 toff
= isym
->st_value
;
4773 sym_type
= ELF_ST_TYPE (isym
->st_info
);
4777 /* Global symbol handling. */
4779 struct elf_link_hash_entry
*h
;
4781 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
4782 h
= elf_sym_hashes (abfd
)[indx
];
4784 while (h
->root
.type
== bfd_link_hash_indirect
4785 || h
->root
.type
== bfd_link_hash_warning
)
4786 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4790 if (r_type
== R_PPC_PLTREL24
4791 && htab
->plt
!= NULL
)
4793 struct plt_entry
*ent
= find_plt_ent (h
, got2
, irel
->r_addend
);
4800 toff
= ent
->glink_offset
;
4805 toff
= ent
->plt
.offset
;
4811 else if (h
->root
.type
== bfd_link_hash_defined
4812 || h
->root
.type
== bfd_link_hash_defweak
)
4814 tsec
= h
->root
.u
.def
.section
;
4815 toff
= h
->root
.u
.def
.value
;
4823 /* If the branch and target are in the same section, you have
4824 no hope of adding stubs. We'll error out later should the
4829 /* There probably isn't any reason to handle symbols in
4830 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
4831 attribute for a code section, and we are only looking at
4832 branches. However, implement it correctly here as a
4833 reference for other target relax_section functions. */
4834 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
4836 /* At this stage in linking, no SEC_MERGE symbol has been
4837 adjusted, so all references to such symbols need to be
4838 passed through _bfd_merged_section_offset. (Later, in
4839 relocate_section, all SEC_MERGE symbols *except* for
4840 section symbols have been adjusted.)
4842 gas may reduce relocations against symbols in SEC_MERGE
4843 sections to a relocation against the section symbol when
4844 the original addend was zero. When the reloc is against
4845 a section symbol we should include the addend in the
4846 offset passed to _bfd_merged_section_offset, since the
4847 location of interest is the original symbol. On the
4848 other hand, an access to "sym+addend" where "sym" is not
4849 a section symbol should not include the addend; Such an
4850 access is presumed to be an offset from "sym"; The
4851 location of interest is just "sym". */
4852 if (sym_type
== STT_SECTION
)
4853 toff
+= irel
->r_addend
;
4855 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
4856 elf_section_data (tsec
)->sec_info
,
4859 if (sym_type
!= STT_SECTION
)
4860 toff
+= irel
->r_addend
;
4862 /* PLTREL24 addends are special. */
4863 else if (r_type
!= R_PPC_PLTREL24
)
4864 toff
+= irel
->r_addend
;
4866 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
4868 roff
= irel
->r_offset
;
4869 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
4871 /* If the branch is in range, no need to do anything. */
4872 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
4875 /* Look for an existing fixup to this address. */
4876 for (f
= fixups
; f
; f
= f
->next
)
4877 if (f
->tsec
== tsec
&& f
->toff
== toff
)
4883 unsigned long stub_rtype
;
4885 val
= trampoff
- roff
;
4886 if (val
>= max_branch_offset
)
4887 /* Oh dear, we can't reach a trampoline. Don't try to add
4888 one. We'll report an error later. */
4891 if (link_info
->shared
)
4893 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
4895 stub_rtype
= R_PPC_RELAX32PC
;
4899 size
= 4 * ARRAY_SIZE (stub_entry
);
4901 stub_rtype
= R_PPC_RELAX32
;
4904 if (R_PPC_RELAX32_PLT
- R_PPC_RELAX32
4905 != R_PPC_RELAX32PC_PLT
- R_PPC_RELAX32PC
)
4907 if (tsec
== htab
->plt
4908 || tsec
== htab
->glink
)
4909 stub_rtype
+= R_PPC_RELAX32_PLT
- R_PPC_RELAX32
;
4911 /* Hijack the old relocation. Since we need two
4912 relocations for this use a "composite" reloc. */
4913 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
4915 irel
->r_offset
= trampoff
+ insn_offset
;
4917 /* Record the fixup so we don't do it again this section. */
4918 f
= bfd_malloc (sizeof (*f
));
4922 f
->trampoff
= trampoff
;
4929 val
= f
->trampoff
- roff
;
4930 if (val
>= max_branch_offset
)
4933 /* Nop out the reloc, since we're finalizing things here. */
4934 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
4937 /* Get the section contents. */
4938 if (contents
== NULL
)
4940 /* Get cached copy if it exists. */
4941 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
4942 contents
= elf_section_data (isec
)->this_hdr
.contents
;
4945 /* Go get them off disk. */
4946 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
4951 /* Fix up the existing branch to hit the trampoline. */
4952 hit_addr
= contents
+ roff
;
4956 case R_PPC_LOCAL24PC
:
4957 case R_PPC_PLTREL24
:
4958 t0
= bfd_get_32 (abfd
, hit_addr
);
4960 t0
|= val
& 0x3fffffc;
4961 bfd_put_32 (abfd
, t0
, hit_addr
);
4965 case R_PPC_REL14_BRTAKEN
:
4966 case R_PPC_REL14_BRNTAKEN
:
4967 t0
= bfd_get_32 (abfd
, hit_addr
);
4970 bfd_put_32 (abfd
, t0
, hit_addr
);
4975 /* Write out the trampolines. */
4976 changed
= fixups
!= NULL
;
4986 struct one_fixup
*f
= fixups
;
4987 fixups
= fixups
->next
;
4992 contents
= bfd_realloc (contents
, trampoff
);
4993 if (contents
== NULL
)
4996 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
4997 /* Branch around the trampolines. */
4998 val
= trampoff
- isec
->size
+ 0x48000000;
4999 dest
= contents
+ isec
->size
;
5000 isec
->size
= trampoff
;
5001 bfd_put_32 (abfd
, val
, dest
);
5004 if (link_info
->shared
)
5006 stub
= shared_stub_entry
;
5007 size
= ARRAY_SIZE (shared_stub_entry
);
5012 size
= ARRAY_SIZE (stub_entry
);
5016 while (dest
< contents
+ trampoff
)
5018 bfd_put_32 (abfd
, stub
[i
], dest
);
5024 BFD_ASSERT (i
== 0);
5028 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5030 if (! link_info
->keep_memory
)
5034 /* Cache the symbols for elf_link_input_bfd. */
5035 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
5039 if (contents
!= NULL
5040 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
5042 if (!changed
&& !link_info
->keep_memory
)
5046 /* Cache the section contents for elf_link_input_bfd. */
5047 elf_section_data (isec
)->this_hdr
.contents
= contents
;
5051 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
5054 free (internal_relocs
);
5056 elf_section_data (isec
)->relocs
= internal_relocs
;
5063 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
5065 if (contents
!= NULL
5066 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
5068 if (internal_relocs
!= NULL
5069 && elf_section_data (isec
)->relocs
!= internal_relocs
)
5070 free (internal_relocs
);
5074 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms. They are
5075 set here rather than via PROVIDE in the default linker script,
5076 because using PROVIDE inside an output section statement results in
5077 unnecessary output sections. Using PROVIDE outside an output section
5078 statement runs the risk of section alignment affecting where the
5082 ppc_elf_set_sdata_syms (bfd
*obfd
, struct bfd_link_info
*info
)
5084 struct ppc_elf_link_hash_table
*htab
;
5089 htab
= ppc_elf_hash_table (info
);
5091 for (i
= 0; i
< 2; i
++)
5093 elf_linker_section_t
*lsect
= &htab
->sdata
[i
];
5097 s
= s
->output_section
;
5099 s
= bfd_get_section_by_name (obfd
, lsect
->name
);
5101 s
= bfd_get_section_by_name (obfd
, lsect
->bss_name
);
5105 /* VxWorks executables are relocatable, so the sdata base symbols
5106 must be section-relative. If the section is zero sized leave
5107 them as absolute symbols to avoid creationg an unused
5110 lsect
->sym_val
= val
+ s
->vma
;
5123 _bfd_elf_provide_symbol (info
, lsect
->sym_name
, val
, s
);
5126 s
= bfd_get_section_by_name (obfd
, ".sbss");
5127 _bfd_elf_provide_symbol (info
, "__sbss_start", 0, NULL
);
5128 _bfd_elf_provide_symbol (info
, "___sbss_start", 0, NULL
);
5133 _bfd_elf_provide_symbol (info
, "__sbss_end", val
, s
);
5134 _bfd_elf_provide_symbol (info
, "___sbss_end", val
, s
);
5138 /* Fill in the address for a pointer generated in a linker section. */
5141 elf_finish_pointer_linker_section (bfd
*input_bfd
,
5142 elf_linker_section_t
*lsect
,
5143 struct elf_link_hash_entry
*h
,
5145 const Elf_Internal_Rela
*rel
)
5147 elf_linker_section_pointers_t
*linker_section_ptr
;
5149 BFD_ASSERT (lsect
!= NULL
);
5153 /* Handle global symbol. */
5154 struct ppc_elf_link_hash_entry
*eh
;
5156 eh
= (struct ppc_elf_link_hash_entry
*) h
;
5157 BFD_ASSERT (eh
->elf
.def_regular
);
5158 linker_section_ptr
= eh
->linker_section_pointer
;
5162 /* Handle local symbol. */
5163 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
5165 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
5166 linker_section_ptr
= elf_local_ptr_offsets (input_bfd
)[r_symndx
];
5169 linker_section_ptr
= elf_find_pointer_linker_section (linker_section_ptr
,
5172 BFD_ASSERT (linker_section_ptr
!= NULL
);
5174 /* Offset will always be a multiple of four, so use the bottom bit
5175 as a "written" flag. */
5176 if ((linker_section_ptr
->offset
& 1) == 0)
5178 bfd_put_32 (lsect
->section
->owner
,
5179 relocation
+ linker_section_ptr
->addend
,
5180 lsect
->section
->contents
+ linker_section_ptr
->offset
);
5181 linker_section_ptr
->offset
+= 1;
5184 relocation
= (lsect
->section
->output_offset
5185 + linker_section_ptr
->offset
- 1
5190 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
5191 lsect
->name
, (long) relocation
, (long) relocation
);
5194 /* Subtract out the addend, because it will get added back in by the normal
5196 return relocation
- linker_section_ptr
->addend
;
5199 /* The RELOCATE_SECTION function is called by the ELF backend linker
5200 to handle the relocations for a section.
5202 The relocs are always passed as Rela structures; if the section
5203 actually uses Rel structures, the r_addend field will always be
5206 This function is responsible for adjust the section contents as
5207 necessary, and (if using Rela relocs and generating a
5208 relocatable output file) adjusting the reloc addend as
5211 This function does not have to worry about setting the reloc
5212 address or the reloc symbol index.
5214 LOCAL_SYMS is a pointer to the swapped in local symbols.
5216 LOCAL_SECTIONS is an array giving the section in the input file
5217 corresponding to the st_shndx field of each local symbol.
5219 The global hash table entry for the global symbols can be found
5220 via elf_sym_hashes (input_bfd).
5222 When generating relocatable output, this function must handle
5223 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5224 going to be the section symbol corresponding to the output
5225 section, which means that the addend must be adjusted
5229 ppc_elf_relocate_section (bfd
*output_bfd
,
5230 struct bfd_link_info
*info
,
5232 asection
*input_section
,
5234 Elf_Internal_Rela
*relocs
,
5235 Elf_Internal_Sym
*local_syms
,
5236 asection
**local_sections
)
5238 Elf_Internal_Shdr
*symtab_hdr
;
5239 struct elf_link_hash_entry
**sym_hashes
;
5240 struct ppc_elf_link_hash_table
*htab
;
5241 Elf_Internal_Rela
*rel
;
5242 Elf_Internal_Rela
*relend
;
5243 Elf_Internal_Rela outrel
;
5245 asection
*got2
, *sreloc
= NULL
;
5246 bfd_vma
*local_got_offsets
;
5247 bfd_boolean ret
= TRUE
;
5250 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
5251 "%ld relocations%s",
5252 input_bfd
, input_section
,
5253 (long) input_section
->reloc_count
,
5254 (info
->relocatable
) ? " (relocatable)" : "");
5257 got2
= bfd_get_section_by_name (input_bfd
, ".got2");
5259 if (info
->relocatable
)
5265 relend
= relocs
+ input_section
->reloc_count
;
5266 for (; rel
< relend
; rel
++)
5268 enum elf_ppc_reloc_type r_type
;
5270 r_type
= ELF32_R_TYPE (rel
->r_info
);
5271 if (r_type
== R_PPC_PLTREL24
5272 && rel
->r_addend
>= 32768)
5274 /* R_PPC_PLTREL24 is rather special. If non-zero, the
5275 addend specifies the GOT pointer offset within .got2. */
5276 rel
->r_addend
+= got2
->output_offset
;
5282 /* Initialize howto table if not already done. */
5283 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
5284 ppc_elf_howto_init ();
5286 htab
= ppc_elf_hash_table (info
);
5287 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5288 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5289 sym_hashes
= elf_sym_hashes (input_bfd
);
5291 relend
= relocs
+ input_section
->reloc_count
;
5292 for (; rel
< relend
; rel
++)
5294 enum elf_ppc_reloc_type r_type
;
5296 bfd_reloc_status_type r
;
5297 Elf_Internal_Sym
*sym
;
5299 struct elf_link_hash_entry
*h
;
5300 const char *sym_name
;
5301 reloc_howto_type
*howto
;
5302 unsigned long r_symndx
;
5304 bfd_vma branch_bit
, insn
, from
;
5305 bfd_boolean unresolved_reloc
;
5307 unsigned int tls_type
, tls_mask
, tls_gd
;
5309 r_type
= ELF32_R_TYPE (rel
->r_info
);
5313 unresolved_reloc
= FALSE
;
5315 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5317 if (r_symndx
< symtab_hdr
->sh_info
)
5319 sym
= local_syms
+ r_symndx
;
5320 sec
= local_sections
[r_symndx
];
5321 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
5323 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5327 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5328 r_symndx
, symtab_hdr
, sym_hashes
,
5330 unresolved_reloc
, warned
);
5332 sym_name
= h
->root
.root
.string
;
5335 /* TLS optimizations. Replace instruction sequences and relocs
5336 based on information we collected in tls_optimize. We edit
5337 RELOCS so that --emit-relocs will output something sensible
5338 for the final instruction stream. */
5341 if (IS_PPC_TLS_RELOC (r_type
))
5344 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
5345 else if (local_got_offsets
!= NULL
)
5348 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
5349 tls_mask
= lgot_masks
[r_symndx
];
5353 /* Ensure reloc mapping code below stays sane. */
5354 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
5355 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
5356 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
5357 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
5358 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
5359 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
5360 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
5361 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
5368 case R_PPC_GOT_TPREL16
:
5369 case R_PPC_GOT_TPREL16_LO
:
5371 && (tls_mask
& TLS_TPREL
) == 0)
5374 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
5376 insn
|= 0x3c020000; /* addis 0,2,0 */
5377 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
5378 r_type
= R_PPC_TPREL16_HA
;
5379 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5385 && (tls_mask
& TLS_TPREL
) == 0)
5388 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5389 if ((insn
& ((31 << 26) | (31 << 11)))
5390 == ((31 << 26) | (2 << 11)))
5391 rtra
= insn
& ((1 << 26) - (1 << 16));
5392 else if ((insn
& ((31 << 26) | (31 << 16)))
5393 == ((31 << 26) | (2 << 16)))
5394 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
5397 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
5400 else if ((insn
& (31 << 1)) == 23 << 1
5401 && ((insn
& (31 << 6)) < 14 << 6
5402 || ((insn
& (31 << 6)) >= 16 << 6
5403 && (insn
& (31 << 6)) < 24 << 6)))
5404 /* load and store indexed -> dform. */
5405 insn
= (32 | ((insn
>> 6) & 31)) << 26;
5406 else if ((insn
& (31 << 1)) == 21 << 1
5407 && (insn
& (0x1a << 6)) == 0)
5408 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
5409 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
5410 | ((insn
>> 6) & 1));
5411 else if ((insn
& (31 << 1)) == 21 << 1
5412 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
5414 insn
= (58 << 26) | 2;
5418 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5419 r_type
= R_PPC_TPREL16_LO
;
5420 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5421 /* Was PPC_TLS which sits on insn boundary, now
5422 PPC_TPREL16_LO which is at insn+2. */
5427 case R_PPC_GOT_TLSGD16_HI
:
5428 case R_PPC_GOT_TLSGD16_HA
:
5429 tls_gd
= TLS_TPRELGD
;
5430 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
5434 case R_PPC_GOT_TLSLD16_HI
:
5435 case R_PPC_GOT_TLSLD16_HA
:
5436 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
5439 if ((tls_mask
& tls_gd
) != 0)
5440 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
5441 + R_PPC_GOT_TPREL16
);
5444 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
5446 r_type
= R_PPC_NONE
;
5448 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5452 case R_PPC_GOT_TLSGD16
:
5453 case R_PPC_GOT_TLSGD16_LO
:
5454 tls_gd
= TLS_TPRELGD
;
5455 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
5456 goto tls_get_addr_check
;
5459 case R_PPC_GOT_TLSLD16
:
5460 case R_PPC_GOT_TLSLD16_LO
:
5461 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
5464 if (rel
+ 1 < relend
)
5466 enum elf_ppc_reloc_type r_type2
;
5467 unsigned long r_symndx2
;
5468 struct elf_link_hash_entry
*h2
;
5469 bfd_vma insn1
, insn2
;
5472 /* The next instruction should be a call to
5473 __tls_get_addr. Peek at the reloc to be sure. */
5474 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
5475 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
5476 if (r_symndx2
< symtab_hdr
->sh_info
5477 || (r_type2
!= R_PPC_REL14
5478 && r_type2
!= R_PPC_REL14_BRTAKEN
5479 && r_type2
!= R_PPC_REL14_BRNTAKEN
5480 && r_type2
!= R_PPC_REL24
5481 && r_type2
!= R_PPC_PLTREL24
))
5484 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
5485 while (h2
->root
.type
== bfd_link_hash_indirect
5486 || h2
->root
.type
== bfd_link_hash_warning
)
5487 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
5488 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
5491 /* OK, it checks out. Replace the call. */
5492 offset
= rel
[1].r_offset
;
5493 insn1
= bfd_get_32 (output_bfd
,
5494 contents
+ rel
->r_offset
- 2);
5495 if ((tls_mask
& tls_gd
) != 0)
5498 insn1
&= (1 << 26) - 1;
5499 insn1
|= 32 << 26; /* lwz */
5500 insn2
= 0x7c631214; /* add 3,3,2 */
5501 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
5502 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
5503 + R_PPC_GOT_TPREL16
);
5504 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5509 insn1
= 0x3c620000; /* addis 3,2,0 */
5510 insn2
= 0x38630000; /* addi 3,3,0 */
5513 /* Was an LD reloc. */
5515 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5516 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5518 r_type
= R_PPC_TPREL16_HA
;
5519 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
5520 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
5522 rel
[1].r_offset
+= 2;
5524 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
5525 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
5528 /* We changed the symbol on an LD reloc. Start over
5529 in order to get h, sym, sec etc. right. */
5538 /* Handle other relocations that tweak non-addend part of insn. */
5545 /* Branch taken prediction relocations. */
5546 case R_PPC_ADDR14_BRTAKEN
:
5547 case R_PPC_REL14_BRTAKEN
:
5548 branch_bit
= BRANCH_PREDICT_BIT
;
5551 /* Branch not taken prediction relocations. */
5552 case R_PPC_ADDR14_BRNTAKEN
:
5553 case R_PPC_REL14_BRNTAKEN
:
5554 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5555 insn
&= ~BRANCH_PREDICT_BIT
;
5558 from
= (rel
->r_offset
5559 + input_section
->output_offset
5560 + input_section
->output_section
->vma
);
5562 /* Invert 'y' bit if not the default. */
5563 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
5564 insn
^= BRANCH_PREDICT_BIT
;
5566 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5570 addend
= rel
->r_addend
;
5573 if (r_type
< R_PPC_max
)
5574 howto
= ppc_elf_howto_table
[r_type
];
5578 (*_bfd_error_handler
)
5579 (_("%B: unknown relocation type %d for symbol %s"),
5580 input_bfd
, (int) r_type
, sym_name
);
5582 bfd_set_error (bfd_error_bad_value
);
5588 case R_PPC_EMB_MRKREF
:
5589 case R_PPC_GNU_VTINHERIT
:
5590 case R_PPC_GNU_VTENTRY
:
5593 /* GOT16 relocations. Like an ADDR16 using the symbol's
5594 address in the GOT as relocation value instead of the
5595 symbol's value itself. Also, create a GOT entry for the
5596 symbol and put the symbol value there. */
5597 case R_PPC_GOT_TLSGD16
:
5598 case R_PPC_GOT_TLSGD16_LO
:
5599 case R_PPC_GOT_TLSGD16_HI
:
5600 case R_PPC_GOT_TLSGD16_HA
:
5601 tls_type
= TLS_TLS
| TLS_GD
;
5604 case R_PPC_GOT_TLSLD16
:
5605 case R_PPC_GOT_TLSLD16_LO
:
5606 case R_PPC_GOT_TLSLD16_HI
:
5607 case R_PPC_GOT_TLSLD16_HA
:
5608 tls_type
= TLS_TLS
| TLS_LD
;
5611 case R_PPC_GOT_TPREL16
:
5612 case R_PPC_GOT_TPREL16_LO
:
5613 case R_PPC_GOT_TPREL16_HI
:
5614 case R_PPC_GOT_TPREL16_HA
:
5615 tls_type
= TLS_TLS
| TLS_TPREL
;
5618 case R_PPC_GOT_DTPREL16
:
5619 case R_PPC_GOT_DTPREL16_LO
:
5620 case R_PPC_GOT_DTPREL16_HI
:
5621 case R_PPC_GOT_DTPREL16_HA
:
5622 tls_type
= TLS_TLS
| TLS_DTPREL
;
5626 case R_PPC_GOT16_LO
:
5627 case R_PPC_GOT16_HI
:
5628 case R_PPC_GOT16_HA
:
5631 /* Relocation is to the entry for this symbol in the global
5637 if (htab
->got
== NULL
)
5641 if (tls_type
== (TLS_TLS
| TLS_LD
)
5643 || !h
->def_dynamic
))
5644 offp
= &htab
->tlsld_got
.offset
;
5648 dyn
= htab
->elf
.dynamic_sections_created
;
5649 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5651 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5652 /* This is actually a static link, or it is a
5653 -Bsymbolic link and the symbol is defined
5654 locally, or the symbol was forced to be local
5655 because of a version file. */
5660 unresolved_reloc
= FALSE
;
5662 offp
= &h
->got
.offset
;
5666 if (local_got_offsets
== NULL
)
5668 offp
= &local_got_offsets
[r_symndx
];
5671 /* The offset must always be a multiple of 4. We use the
5672 least significant bit to record whether we have already
5673 processed this entry. */
5679 unsigned int tls_m
= (tls_mask
5680 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5681 | TLS_TPREL
| TLS_TPRELGD
));
5683 if (offp
== &htab
->tlsld_got
.offset
)
5689 /* We might have multiple got entries for this sym.
5690 Initialize them all. */
5695 if ((tls_m
& TLS_LD
) != 0)
5697 tls_ty
= TLS_TLS
| TLS_LD
;
5700 else if ((tls_m
& TLS_GD
) != 0)
5702 tls_ty
= TLS_TLS
| TLS_GD
;
5705 else if ((tls_m
& TLS_DTPREL
) != 0)
5707 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5708 tls_m
&= ~TLS_DTPREL
;
5710 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5712 tls_ty
= TLS_TLS
| TLS_TPREL
;
5716 /* Generate relocs for the dynamic linker. */
5717 if ((info
->shared
|| indx
!= 0)
5719 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5720 || h
->root
.type
!= bfd_link_hash_undefweak
))
5722 outrel
.r_offset
= (htab
->got
->output_section
->vma
5723 + htab
->got
->output_offset
5725 outrel
.r_addend
= 0;
5726 if (tls_ty
& (TLS_LD
| TLS_GD
))
5728 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5729 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5731 loc
= htab
->relgot
->contents
;
5732 loc
+= (htab
->relgot
->reloc_count
++
5733 * sizeof (Elf32_External_Rela
));
5734 bfd_elf32_swap_reloca_out (output_bfd
,
5736 outrel
.r_offset
+= 4;
5738 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5741 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5742 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5743 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5744 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5746 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5748 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5751 outrel
.r_addend
+= relocation
;
5752 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5753 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5755 loc
= htab
->relgot
->contents
;
5756 loc
+= (htab
->relgot
->reloc_count
++
5757 * sizeof (Elf32_External_Rela
));
5758 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5761 /* Init the .got section contents if we're not
5762 emitting a reloc. */
5765 bfd_vma value
= relocation
;
5767 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5769 else if (tls_ty
!= 0)
5771 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5772 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5773 value
+= DTP_OFFSET
- TP_OFFSET
;
5775 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5777 bfd_put_32 (output_bfd
, value
,
5778 htab
->got
->contents
+ off
+ 4);
5782 bfd_put_32 (output_bfd
, value
,
5783 htab
->got
->contents
+ off
);
5787 if (tls_ty
& (TLS_LD
| TLS_GD
))
5796 if (off
>= (bfd_vma
) -2)
5799 if ((tls_type
& TLS_TLS
) != 0)
5801 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5803 if ((tls_mask
& TLS_LD
) != 0
5805 || !h
->def_dynamic
))
5807 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5809 if ((tls_mask
& TLS_GD
) != 0)
5811 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5813 if ((tls_mask
& TLS_DTPREL
) != 0)
5820 relocation
= htab
->got
->output_offset
+ off
;
5821 relocation
-= htab
->elf
.hgot
->root
.u
.def
.value
;
5823 /* Addends on got relocations don't make much sense.
5824 x+off@got is actually x@got+off, and since the got is
5825 generated by a hash table traversal, the value in the
5826 got at entry m+n bears little relation to the entry m. */
5828 (*_bfd_error_handler
)
5829 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5832 (long) rel
->r_offset
,
5838 /* Relocations that need no special processing. */
5839 case R_PPC_LOCAL24PC
:
5840 /* It makes no sense to point a local relocation
5841 at a symbol not in this object. */
5842 if (unresolved_reloc
)
5844 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5845 h
->root
.root
.string
,
5855 case R_PPC_DTPREL16
:
5856 case R_PPC_DTPREL16_LO
:
5857 case R_PPC_DTPREL16_HI
:
5858 case R_PPC_DTPREL16_HA
:
5859 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5862 /* Relocations that may need to be propagated if this is a shared
5865 case R_PPC_TPREL16_LO
:
5866 case R_PPC_TPREL16_HI
:
5867 case R_PPC_TPREL16_HA
:
5868 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5869 /* The TPREL16 relocs shouldn't really be used in shared
5870 libs as they will result in DT_TEXTREL being set, but
5871 support them anyway. */
5875 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5878 case R_PPC_DTPREL32
:
5879 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5882 case R_PPC_DTPMOD32
:
5888 case R_PPC_REL16_LO
:
5889 case R_PPC_REL16_HI
:
5890 case R_PPC_REL16_HA
:
5896 case R_PPC_REL14_BRTAKEN
:
5897 case R_PPC_REL14_BRNTAKEN
:
5898 /* If these relocations are not to a named symbol, they can be
5899 handled right here, no need to bother the dynamic linker. */
5900 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5901 || h
== htab
->elf
.hgot
)
5905 /* Relocations that always need to be propagated if this is a shared
5910 case R_PPC_ADDR16_LO
:
5911 case R_PPC_ADDR16_HI
:
5912 case R_PPC_ADDR16_HA
:
5914 case R_PPC_ADDR14_BRTAKEN
:
5915 case R_PPC_ADDR14_BRNTAKEN
:
5918 /* r_symndx will be zero only for relocs against symbols
5919 from removed linkonce sections, or sections discarded by
5926 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5932 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5933 || h
->root
.type
!= bfd_link_hash_undefweak
)
5934 && (MUST_BE_DYN_RELOC (r_type
)
5935 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5936 || (ELIMINATE_COPY_RELOCS
5942 && !h
->def_regular
))
5947 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5948 "create relocation for %s\n",
5949 (h
&& h
->root
.root
.string
5950 ? h
->root
.root
.string
: "<unknown>"));
5953 /* When generating a shared object, these relocations
5954 are copied into the output file to be resolved at run
5960 name
= (bfd_elf_string_from_elf_section
5962 elf_elfheader (input_bfd
)->e_shstrndx
,
5963 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5967 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5968 && strcmp (bfd_get_section_name (input_bfd
,
5972 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5973 BFD_ASSERT (sreloc
!= NULL
);
5979 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5981 if (outrel
.r_offset
== (bfd_vma
) -1
5982 || outrel
.r_offset
== (bfd_vma
) -2)
5983 skip
= (int) outrel
.r_offset
;
5984 outrel
.r_offset
+= (input_section
->output_section
->vma
5985 + input_section
->output_offset
);
5988 memset (&outrel
, 0, sizeof outrel
);
5989 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5991 unresolved_reloc
= FALSE
;
5992 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5993 outrel
.r_addend
= rel
->r_addend
;
5997 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5999 if (r_type
== R_PPC_ADDR32
)
6000 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
6005 if (bfd_is_abs_section (sec
))
6007 else if (sec
== NULL
|| sec
->owner
== NULL
)
6009 bfd_set_error (bfd_error_bad_value
);
6016 /* We are turning this relocation into one
6017 against a section symbol. It would be
6018 proper to subtract the symbol's value,
6019 osec->vma, from the emitted reloc addend,
6020 but ld.so expects buggy relocs. */
6021 osec
= sec
->output_section
;
6022 indx
= elf_section_data (osec
)->dynindx
;
6023 BFD_ASSERT (indx
> 0);
6026 printf ("indx=%d section=%s flags=%08x name=%s\n",
6027 indx
, osec
->name
, osec
->flags
,
6028 h
->root
.root
.string
);
6032 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
6036 loc
= sreloc
->contents
;
6037 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
6038 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
6043 /* This reloc will be computed at runtime. We clear the memory
6044 so that it contains predictable value. */
6046 && ((input_section
->flags
& SEC_ALLOC
) != 0
6047 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
6049 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
6056 case R_PPC_RELAX32PC_PLT
:
6057 case R_PPC_RELAX32_PLT
:
6059 struct plt_entry
*ent
= find_plt_ent (h
, got2
, addend
);
6062 relocation
= (htab
->glink
->output_section
->vma
6063 + htab
->glink
->output_offset
6064 + ent
->glink_offset
);
6066 relocation
= (htab
->plt
->output_section
->vma
6067 + htab
->plt
->output_offset
6071 if (r_type
== R_PPC_RELAX32_PLT
)
6075 case R_PPC_RELAX32PC
:
6076 relocation
-= (input_section
->output_section
->vma
6077 + input_section
->output_offset
6078 + rel
->r_offset
- 4);
6087 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6088 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
6090 /* We're clearing the bits for R_PPC_ADDR16_HA
6091 and R_PPC_ADDR16_LO here. */
6095 /* t0 is HA, t1 is LO */
6096 relocation
+= addend
;
6097 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
6098 t1
|= relocation
& 0xffff;
6100 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
6101 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
6105 /* Indirect .sdata relocation. */
6106 case R_PPC_EMB_SDAI16
:
6107 BFD_ASSERT (htab
->sdata
[0].section
!= NULL
);
6109 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[0],
6110 h
, relocation
, rel
);
6113 /* Indirect .sdata2 relocation. */
6114 case R_PPC_EMB_SDA2I16
:
6115 BFD_ASSERT (htab
->sdata
[1].section
!= NULL
);
6117 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[1],
6118 h
, relocation
, rel
);
6121 /* Handle the TOC16 reloc. We want to use the offset within the .got
6122 section, not the actual VMA. This is appropriate when generating
6123 an embedded ELF object, for which the .got section acts like the
6124 AIX .toc section. */
6125 case R_PPC_TOC16
: /* phony GOT16 relocations */
6126 BFD_ASSERT (sec
!= NULL
);
6127 BFD_ASSERT (bfd_is_und_section (sec
)
6128 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
6129 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
6131 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
6134 case R_PPC_PLTREL24
:
6135 /* Relocation is to the entry for this symbol in the
6136 procedure linkage table. */
6138 struct plt_entry
*ent
= find_plt_ent (h
, got2
, addend
);
6142 || htab
->plt
== NULL
)
6144 /* We didn't make a PLT entry for this symbol. This
6145 happens when statically linking PIC code, or when
6146 using -Bsymbolic. */
6150 unresolved_reloc
= FALSE
;
6152 relocation
= (htab
->glink
->output_section
->vma
6153 + htab
->glink
->output_offset
6154 + ent
->glink_offset
);
6156 relocation
= (htab
->plt
->output_section
->vma
6157 + htab
->plt
->output_offset
6162 /* Relocate against _SDA_BASE_. */
6163 case R_PPC_SDAREL16
:
6167 BFD_ASSERT (sec
!= NULL
);
6168 name
= bfd_get_section_name (abfd
, sec
->output_section
);
6169 if (! ((strncmp (name
, ".sdata", 6) == 0
6170 && (name
[6] == 0 || name
[6] == '.'))
6171 || (strncmp (name
, ".sbss", 5) == 0
6172 && (name
[5] == 0 || name
[5] == '.'))))
6174 (*_bfd_error_handler
)
6175 (_("%B: the target (%s) of a %s relocation is "
6176 "in the wrong output section (%s)"),
6182 addend
-= htab
->sdata
[0].sym_val
;
6186 /* Relocate against _SDA2_BASE_. */
6187 case R_PPC_EMB_SDA2REL
:
6191 BFD_ASSERT (sec
!= NULL
);
6192 name
= bfd_get_section_name (abfd
, sec
->output_section
);
6193 if (! (strncmp (name
, ".sdata2", 7) == 0
6194 || strncmp (name
, ".sbss2", 6) == 0))
6196 (*_bfd_error_handler
)
6197 (_("%B: the target (%s) of a %s relocation is "
6198 "in the wrong output section (%s)"),
6204 bfd_set_error (bfd_error_bad_value
);
6208 addend
-= htab
->sdata
[1].sym_val
;
6212 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
6213 case R_PPC_EMB_SDA21
:
6214 case R_PPC_EMB_RELSDA
:
6219 BFD_ASSERT (sec
!= NULL
);
6220 name
= bfd_get_section_name (abfd
, sec
->output_section
);
6221 if (((strncmp (name
, ".sdata", 6) == 0
6222 && (name
[6] == 0 || name
[6] == '.'))
6223 || (strncmp (name
, ".sbss", 5) == 0
6224 && (name
[5] == 0 || name
[5] == '.'))))
6227 addend
-= htab
->sdata
[0].sym_val
;
6230 else if (strncmp (name
, ".sdata2", 7) == 0
6231 || strncmp (name
, ".sbss2", 6) == 0)
6234 addend
-= htab
->sdata
[1].sym_val
;
6237 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
6238 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
6245 (*_bfd_error_handler
)
6246 (_("%B: the target (%s) of a %s relocation is "
6247 "in the wrong output section (%s)"),
6253 bfd_set_error (bfd_error_bad_value
);
6258 if (r_type
== R_PPC_EMB_SDA21
)
6259 { /* fill in register field */
6260 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6261 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
6262 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
6267 /* Relocate against the beginning of the section. */
6269 case R_PPC_SECTOFF_LO
:
6270 case R_PPC_SECTOFF_HI
:
6271 case R_PPC_SECTOFF_HA
:
6272 BFD_ASSERT (sec
!= NULL
);
6273 addend
-= sec
->output_section
->vma
;
6276 /* Negative relocations. */
6277 case R_PPC_EMB_NADDR32
:
6278 case R_PPC_EMB_NADDR16
:
6279 case R_PPC_EMB_NADDR16_LO
:
6280 case R_PPC_EMB_NADDR16_HI
:
6281 case R_PPC_EMB_NADDR16_HA
:
6282 addend
-= 2 * relocation
;
6286 case R_PPC_GLOB_DAT
:
6287 case R_PPC_JMP_SLOT
:
6288 case R_PPC_RELATIVE
:
6290 case R_PPC_PLTREL32
:
6291 case R_PPC_PLT16_LO
:
6292 case R_PPC_PLT16_HI
:
6293 case R_PPC_PLT16_HA
:
6295 case R_PPC_EMB_RELSEC16
:
6296 case R_PPC_EMB_RELST_LO
:
6297 case R_PPC_EMB_RELST_HI
:
6298 case R_PPC_EMB_RELST_HA
:
6299 case R_PPC_EMB_BIT_FLD
:
6300 (*_bfd_error_handler
)
6301 (_("%B: relocation %s is not yet supported for symbol %s."),
6306 bfd_set_error (bfd_error_invalid_operation
);
6311 /* Do any further special processing. */
6317 case R_PPC_ADDR16_HA
:
6318 case R_PPC_REL16_HA
:
6319 case R_PPC_GOT16_HA
:
6320 case R_PPC_PLT16_HA
:
6321 case R_PPC_SECTOFF_HA
:
6322 case R_PPC_TPREL16_HA
:
6323 case R_PPC_DTPREL16_HA
:
6324 case R_PPC_GOT_TLSGD16_HA
:
6325 case R_PPC_GOT_TLSLD16_HA
:
6326 case R_PPC_GOT_TPREL16_HA
:
6327 case R_PPC_GOT_DTPREL16_HA
:
6328 case R_PPC_EMB_NADDR16_HA
:
6329 case R_PPC_EMB_RELST_HA
:
6330 /* It's just possible that this symbol is a weak symbol
6331 that's not actually defined anywhere. In that case,
6332 'sec' would be NULL, and we should leave the symbol
6333 alone (it will be set to zero elsewhere in the link). */
6335 /* Add 0x10000 if sign bit in 0:15 is set.
6336 Bits 0:15 are not used. */
6342 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
6343 "offset = %ld, addend = %ld\n",
6348 (long) rel
->r_offset
,
6352 if (unresolved_reloc
6353 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
6356 (*_bfd_error_handler
)
6357 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6360 (long) rel
->r_offset
,
6366 r
= _bfd_final_link_relocate (howto
,
6374 if (r
!= bfd_reloc_ok
)
6376 if (r
== bfd_reloc_overflow
)
6381 && h
->root
.type
== bfd_link_hash_undefweak
6382 && howto
->pc_relative
)
6384 /* Assume this is a call protected by other code that
6385 detect the symbol is undefined. If this is the case,
6386 we can safely ignore the overflow. If not, the
6387 program is hosed anyway, and a little warning isn't
6393 if (! (*info
->callbacks
->reloc_overflow
) (info
,
6394 (h
? &h
->root
: NULL
),
6405 (*_bfd_error_handler
)
6406 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
6407 input_bfd
, input_section
,
6408 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
6415 fprintf (stderr
, "\n");
6421 #define PPC_LO(v) ((v) & 0xffff)
6422 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6423 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6425 /* Finish up dynamic symbol handling. We set the contents of various
6426 dynamic sections here. */
6429 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
6430 struct bfd_link_info
*info
,
6431 struct elf_link_hash_entry
*h
,
6432 Elf_Internal_Sym
*sym
)
6434 struct ppc_elf_link_hash_table
*htab
;
6435 struct plt_entry
*ent
;
6436 bfd_boolean doneone
;
6439 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
6440 h
->root
.root
.string
);
6443 htab
= ppc_elf_hash_table (info
);
6444 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
6447 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6448 if (ent
->plt
.offset
!= (bfd_vma
) -1)
6452 Elf_Internal_Rela rela
;
6454 bfd_vma reloc_index
;
6456 /* This symbol has an entry in the procedure linkage table.
6460 /* We don't need to fill in the .plt. The ppc dynamic
6461 linker will fill it in. */
6465 bfd_vma val
= (htab
->glink_pltresolve
+ ent
->plt
.offset
6466 + htab
->glink
->output_section
->vma
6467 + htab
->glink
->output_offset
);
6468 bfd_put_32 (output_bfd
, val
,
6469 htab
->plt
->contents
+ ent
->plt
.offset
);
6472 /* Fill in the entry in the .rela.plt section. */
6473 rela
.r_offset
= (htab
->plt
->output_section
->vma
6474 + htab
->plt
->output_offset
6476 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
6480 reloc_index
= ent
->plt
.offset
/ 4;
6483 reloc_index
= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
)
6485 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
6486 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
6488 loc
= (htab
->relplt
->contents
6489 + reloc_index
* sizeof (Elf32_External_Rela
));
6490 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6492 if (!h
->def_regular
)
6494 /* Mark the symbol as undefined, rather than as defined in
6495 the .plt section. Leave the value alone. */
6496 sym
->st_shndx
= SHN_UNDEF
;
6497 /* If the symbol is weak, we do need to clear the value.
6498 Otherwise, the PLT entry would provide a definition for
6499 the symbol even if the symbol wasn't defined anywhere,
6500 and so the symbol would never be NULL. */
6501 if (!h
->ref_regular_nonweak
)
6512 plt
= (ent
->plt
.offset
6513 + htab
->plt
->output_section
->vma
6514 + htab
->plt
->output_offset
);
6515 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
6517 if (info
->shared
|| info
->pie
)
6521 if (ent
->addend
>= 32768)
6523 + ent
->sec
->output_section
->vma
6524 + ent
->sec
->output_offset
);
6525 else if (htab
->elf
.hgot
!= NULL
)
6526 got
= (htab
->elf
.hgot
->root
.u
.def
.value
6527 + htab
->elf
.hgot
->root
.u
.def
.section
->output_section
->vma
6528 + htab
->elf
.hgot
->root
.u
.def
.section
->output_offset
);
6532 if (plt
+ 0x8000 < 0x10000)
6534 bfd_put_32 (output_bfd
, LWZ_11_30
+ PPC_LO (plt
), p
);
6536 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6538 bfd_put_32 (output_bfd
, BCTR
, p
);
6540 bfd_put_32 (output_bfd
, NOP
, p
);
6545 bfd_put_32 (output_bfd
, ADDIS_11_30
+ PPC_HA (plt
), p
);
6547 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6549 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6551 bfd_put_32 (output_bfd
, BCTR
, p
);
6557 bfd_put_32 (output_bfd
, LIS_11
+ PPC_HA (plt
), p
);
6559 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6561 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6563 bfd_put_32 (output_bfd
, BCTR
, p
);
6566 /* We only need one non-PIC glink stub. */
6577 Elf_Internal_Rela rela
;
6580 /* This symbols needs a copy reloc. Set it up. */
6583 fprintf (stderr
, ", copy");
6586 BFD_ASSERT (h
->dynindx
!= -1);
6588 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
6592 BFD_ASSERT (s
!= NULL
);
6594 rela
.r_offset
= (h
->root
.u
.def
.value
6595 + h
->root
.u
.def
.section
->output_section
->vma
6596 + h
->root
.u
.def
.section
->output_offset
);
6597 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
6599 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
6600 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6604 fprintf (stderr
, "\n");
6607 /* Mark some specially defined symbols as absolute. */
6608 if (h
== htab
->elf
.hgot
6609 || strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6610 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
6611 sym
->st_shndx
= SHN_ABS
;
6616 static enum elf_reloc_type_class
6617 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
6619 switch (ELF32_R_TYPE (rela
->r_info
))
6621 case R_PPC_RELATIVE
:
6622 return reloc_class_relative
;
6625 case R_PPC_JMP_SLOT
:
6626 return reloc_class_plt
;
6628 return reloc_class_copy
;
6630 return reloc_class_normal
;
6634 /* Finish up the dynamic sections. */
6637 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
6638 struct bfd_link_info
*info
)
6641 struct ppc_elf_link_hash_table
*htab
;
6645 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
6648 htab
= ppc_elf_hash_table (info
);
6649 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
6652 if (htab
->elf
.hgot
!= NULL
)
6653 got
= (htab
->elf
.hgot
->root
.u
.def
.value
6654 + htab
->elf
.hgot
->root
.u
.def
.section
->output_section
->vma
6655 + htab
->elf
.hgot
->root
.u
.def
.section
->output_offset
);
6657 if (htab
->elf
.dynamic_sections_created
)
6659 Elf32_External_Dyn
*dyncon
, *dynconend
;
6661 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
6663 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6664 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6665 for (; dyncon
< dynconend
; dyncon
++)
6667 Elf_Internal_Dyn dyn
;
6670 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
6676 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6680 dyn
.d_un
.d_val
= htab
->relplt
->size
;
6685 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6689 dyn
.d_un
.d_ptr
= got
;
6696 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6700 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
6701 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
6702 if (htab
->got
!= NULL
)
6704 unsigned char *p
= htab
->got
->contents
;
6707 p
+= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
6709 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, p
- 4);
6713 val
= sdyn
->output_section
->vma
+ sdyn
->output_offset
;
6714 bfd_put_32 (output_bfd
, val
, p
);
6716 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
6719 if (htab
->glink
!= NULL
&& htab
->glink
->contents
!= NULL
)
6722 unsigned char *endp
;
6727 * PIC glink code is the following:
6729 * # ith PLT code stub.
6730 * addis 11,30,(plt+(i-1)*4-got)@ha
6731 * lwz 11,(plt+(i-1)*4-got)@l(11)
6735 * # A table of branches, one for each plt entry.
6736 * # The idea is that the plt call stub loads ctr (and r11) with these
6737 * # addresses, so (r11 - res_0) gives the plt index * 4.
6738 * res_0: b PLTresolve
6739 * res_1: b PLTresolve
6741 * # Some number of entries towards the end can be nops
6747 * addis 11,11,(1f-res_0)@ha
6750 * 1: addi 11,11,(1b-res_0)@l
6753 * sub 11,11,12 # r11 = index * 4
6754 * addis 12,12,(got+4-1b)@ha
6755 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
6756 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
6759 * add 11,0,11 # r11 = index * 12 = reloc offset.
6762 static const unsigned int pic_plt_resolve
[] =
6782 static const unsigned int plt_resolve
[] =
6802 if (ARRAY_SIZE (pic_plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
6804 if (ARRAY_SIZE (plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
6807 /* Build the branch table, one for each plt entry (less one),
6808 and perhaps some padding. */
6809 p
= htab
->glink
->contents
;
6810 p
+= htab
->glink_pltresolve
;
6811 endp
= htab
->glink
->contents
;
6812 endp
+= htab
->glink
->size
- GLINK_PLTRESOLVE
;
6813 while (p
< endp
- 8 * 4)
6815 bfd_put_32 (output_bfd
, B
+ endp
- p
, p
);
6820 bfd_put_32 (output_bfd
, NOP
, p
);
6824 res0
= (htab
->glink_pltresolve
6825 + htab
->glink
->output_section
->vma
6826 + htab
->glink
->output_offset
);
6828 /* Last comes the PLTresolve stub. */
6829 if (info
->shared
|| info
->pie
)
6833 for (i
= 0; i
< ARRAY_SIZE (pic_plt_resolve
); i
++)
6835 bfd_put_32 (output_bfd
, pic_plt_resolve
[i
], p
);
6838 p
-= 4 * ARRAY_SIZE (pic_plt_resolve
);
6840 bcl
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 3*4
6841 + htab
->glink
->output_section
->vma
6842 + htab
->glink
->output_offset
);
6844 bfd_put_32 (output_bfd
,
6845 ADDIS_11_11
+ PPC_HA (bcl
- res0
), p
+ 0*4);
6846 bfd_put_32 (output_bfd
,
6847 ADDI_11_11
+ PPC_LO (bcl
- res0
), p
+ 3*4);
6848 bfd_put_32 (output_bfd
,
6849 ADDIS_12_12
+ PPC_HA (got
+ 4 - bcl
), p
+ 7*4);
6850 if (PPC_HA (got
+ 4 - bcl
) == PPC_HA (got
+ 8 - bcl
))
6852 bfd_put_32 (output_bfd
,
6853 LWZ_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
6854 bfd_put_32 (output_bfd
,
6855 LWZ_12_12
+ PPC_LO (got
+ 8 - bcl
), p
+ 9*4);
6859 bfd_put_32 (output_bfd
,
6860 LWZU_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
6861 bfd_put_32 (output_bfd
,
6862 LWZ_12_12
+ 4, p
+ 9*4);
6867 for (i
= 0; i
< ARRAY_SIZE (plt_resolve
); i
++)
6869 bfd_put_32 (output_bfd
, plt_resolve
[i
], p
);
6872 p
-= 4 * ARRAY_SIZE (plt_resolve
);
6874 bfd_put_32 (output_bfd
,
6875 LIS_12
+ PPC_HA (got
+ 4), p
+ 0*4);
6876 bfd_put_32 (output_bfd
,
6877 ADDIS_11_11
+ PPC_HA (-res0
), p
+ 1*4);
6878 bfd_put_32 (output_bfd
,
6879 ADDI_11_11
+ PPC_LO (-res0
), p
+ 3*4);
6880 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
6882 bfd_put_32 (output_bfd
,
6883 LWZ_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
6884 bfd_put_32 (output_bfd
,
6885 LWZ_12_12
+ PPC_LO (got
+ 8), p
+ 6*4);
6889 bfd_put_32 (output_bfd
,
6890 LWZU_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
6891 bfd_put_32 (output_bfd
,
6892 LWZ_12_12
+ 4, p
+ 6*4);
6900 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6901 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6902 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6903 #define TARGET_BIG_NAME "elf32-powerpc"
6904 #define ELF_ARCH bfd_arch_powerpc
6905 #define ELF_MACHINE_CODE EM_PPC
6906 #ifdef __QNXTARGET__
6907 #define ELF_MAXPAGESIZE 0x1000
6909 #define ELF_MAXPAGESIZE 0x10000
6911 #define ELF_MINPAGESIZE 0x1000
6912 #define elf_info_to_howto ppc_elf_info_to_howto
6914 #ifdef EM_CYGNUS_POWERPC
6915 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6919 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6922 #define elf_backend_plt_not_loaded 1
6923 #define elf_backend_can_gc_sections 1
6924 #define elf_backend_can_refcount 1
6925 #define elf_backend_rela_normal 1
6927 #define bfd_elf32_mkobject ppc_elf_mkobject
6928 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6929 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6930 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6931 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6932 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6934 #define elf_backend_object_p ppc_elf_object_p
6935 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6936 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6937 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6938 #define elf_backend_relocate_section ppc_elf_relocate_section
6939 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6940 #define elf_backend_check_relocs ppc_elf_check_relocs
6941 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6942 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6943 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6944 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6945 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6946 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6947 #define elf_backend_fake_sections ppc_elf_fake_sections
6948 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6949 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6950 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6951 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6952 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6953 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6954 #define elf_backend_write_section ppc_elf_write_section
6955 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
6956 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6958 #include "elf32-target.h"