1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 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 3 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. */
24 /* This file is based on a preliminary PowerPC ELF ABI. The
25 information may not match the final PowerPC ELF ABI. It includes
26 suggestions from the in-progress Embedded PowerPC ABI, and that
27 information may also not match. */
36 #include "elf32-ppc.h"
37 #include "elf-vxworks.h"
39 /* RELA relocations are used here. */
41 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
42 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 static bfd_reloc_status_type ppc_elf_unhandled_reloc
44 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 /* Branch prediction bit for branch taken relocs. */
47 #define BRANCH_PREDICT_BIT 0x200000
48 /* Mask to set RA in memory instructions. */
49 #define RA_REGISTER_MASK 0x001f0000
50 /* Value to shift register by to insert RA. */
51 #define RA_REGISTER_SHIFT 16
53 /* The name of the dynamic interpreter. This is put in the .interp
55 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
57 /* For old-style PLT. */
58 /* The number of single-slot PLT entries (the rest use two slots). */
59 #define PLT_NUM_SINGLE_ENTRIES 8192
61 /* For new-style .glink and .plt. */
62 #define GLINK_PLTRESOLVE 16*4
63 #define GLINK_ENTRY_SIZE 4*4
65 /* VxWorks uses its own plt layout, filled in by the static linker. */
67 /* The standard VxWorks PLT entry. */
68 #define VXWORKS_PLT_ENTRY_SIZE 32
69 static const bfd_vma ppc_elf_vxworks_plt_entry
70 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
72 0x3d800000, /* lis r12,0 */
73 0x818c0000, /* lwz r12,0(r12) */
74 0x7d8903a6, /* mtctr r12 */
75 0x4e800420, /* bctr */
76 0x39600000, /* li r11,0 */
77 0x48000000, /* b 14 <.PLT0resolve+0x4> */
81 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
82 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
84 0x3d9e0000, /* addis r12,r30,0 */
85 0x818c0000, /* lwz r12,0(r12) */
86 0x7d8903a6, /* mtctr r12 */
87 0x4e800420, /* bctr */
88 0x39600000, /* li r11,0 */
89 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
94 /* The initial VxWorks PLT entry. */
95 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
96 static const bfd_vma ppc_elf_vxworks_plt0_entry
97 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
99 0x3d800000, /* lis r12,0 */
100 0x398c0000, /* addi r12,r12,0 */
101 0x800c0008, /* lwz r0,8(r12) */
102 0x7c0903a6, /* mtctr r0 */
103 0x818c0004, /* lwz r12,4(r12) */
104 0x4e800420, /* bctr */
105 0x60000000, /* nop */
106 0x60000000, /* nop */
108 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
109 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
111 0x819e0008, /* lwz r12,8(r30) */
112 0x7d8903a6, /* mtctr r12 */
113 0x819e0004, /* lwz r12,4(r30) */
114 0x4e800420, /* bctr */
115 0x60000000, /* nop */
116 0x60000000, /* nop */
117 0x60000000, /* nop */
118 0x60000000, /* nop */
121 /* For executables, we have some additional relocations in
122 .rela.plt.unloaded, for the kernel loader. */
124 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
125 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
126 /* The number of relocations in the PLTResolve slot. */
127 #define VXWORKS_PLTRESOLVE_RELOCS 2
128 /* The number of relocations in the PLTResolve slot when when creating
130 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
132 /* Some instructions. */
133 #define ADDIS_11_11 0x3d6b0000
134 #define ADDIS_11_30 0x3d7e0000
135 #define ADDIS_12_12 0x3d8c0000
136 #define ADDI_11_11 0x396b0000
137 #define ADD_0_11_11 0x7c0b5a14
138 #define ADD_11_0_11 0x7d605a14
140 #define BCL_20_31 0x429f0005
141 #define BCTR 0x4e800420
142 #define LIS_11 0x3d600000
143 #define LIS_12 0x3d800000
144 #define LWZU_0_12 0x840c0000
145 #define LWZ_0_12 0x800c0000
146 #define LWZ_11_11 0x816b0000
147 #define LWZ_11_30 0x817e0000
148 #define LWZ_12_12 0x818c0000
149 #define MFLR_0 0x7c0802a6
150 #define MFLR_12 0x7d8802a6
151 #define MTCTR_0 0x7c0903a6
152 #define MTCTR_11 0x7d6903a6
153 #define MTLR_0 0x7c0803a6
154 #define NOP 0x60000000
155 #define SUB_11_11_12 0x7d6c5850
157 /* Offset of tp and dtp pointers from start of TLS block. */
158 #define TP_OFFSET 0x7000
159 #define DTP_OFFSET 0x8000
161 /* The value of a defined global symbol. */
162 #define SYM_VAL(SYM) \
163 ((SYM)->root.u.def.section->output_section->vma \
164 + (SYM)->root.u.def.section->output_offset \
165 + (SYM)->root.u.def.value)
167 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
169 static reloc_howto_type ppc_elf_howto_raw
[] = {
170 /* This reloc does nothing. */
171 HOWTO (R_PPC_NONE
, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 FALSE
, /* pc_relative */
177 complain_overflow_bitfield
, /* complain_on_overflow */
178 bfd_elf_generic_reloc
, /* special_function */
179 "R_PPC_NONE", /* name */
180 FALSE
, /* partial_inplace */
183 FALSE
), /* pcrel_offset */
185 /* A standard 32 bit relocation. */
186 HOWTO (R_PPC_ADDR32
, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 FALSE
, /* pc_relative */
192 complain_overflow_bitfield
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_PPC_ADDR32", /* name */
195 FALSE
, /* partial_inplace */
197 0xffffffff, /* dst_mask */
198 FALSE
), /* pcrel_offset */
200 /* An absolute 26 bit branch; the lower two bits must be zero.
201 FIXME: we don't check that, we just clear them. */
202 HOWTO (R_PPC_ADDR24
, /* type */
204 2, /* size (0 = byte, 1 = short, 2 = long) */
206 FALSE
, /* pc_relative */
208 complain_overflow_bitfield
, /* complain_on_overflow */
209 bfd_elf_generic_reloc
, /* special_function */
210 "R_PPC_ADDR24", /* name */
211 FALSE
, /* partial_inplace */
213 0x3fffffc, /* dst_mask */
214 FALSE
), /* pcrel_offset */
216 /* A standard 16 bit relocation. */
217 HOWTO (R_PPC_ADDR16
, /* type */
219 1, /* size (0 = byte, 1 = short, 2 = long) */
221 FALSE
, /* pc_relative */
223 complain_overflow_bitfield
, /* complain_on_overflow */
224 bfd_elf_generic_reloc
, /* special_function */
225 "R_PPC_ADDR16", /* name */
226 FALSE
, /* partial_inplace */
228 0xffff, /* dst_mask */
229 FALSE
), /* pcrel_offset */
231 /* A 16 bit relocation without overflow. */
232 HOWTO (R_PPC_ADDR16_LO
, /* type */
234 1, /* size (0 = byte, 1 = short, 2 = long) */
236 FALSE
, /* pc_relative */
238 complain_overflow_dont
,/* complain_on_overflow */
239 bfd_elf_generic_reloc
, /* special_function */
240 "R_PPC_ADDR16_LO", /* name */
241 FALSE
, /* partial_inplace */
243 0xffff, /* dst_mask */
244 FALSE
), /* pcrel_offset */
246 /* The high order 16 bits of an address. */
247 HOWTO (R_PPC_ADDR16_HI
, /* type */
249 1, /* size (0 = byte, 1 = short, 2 = long) */
251 FALSE
, /* pc_relative */
253 complain_overflow_dont
, /* complain_on_overflow */
254 bfd_elf_generic_reloc
, /* special_function */
255 "R_PPC_ADDR16_HI", /* name */
256 FALSE
, /* partial_inplace */
258 0xffff, /* dst_mask */
259 FALSE
), /* pcrel_offset */
261 /* The high order 16 bits of an address, plus 1 if the contents of
262 the low 16 bits, treated as a signed number, is negative. */
263 HOWTO (R_PPC_ADDR16_HA
, /* type */
265 1, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_dont
, /* complain_on_overflow */
270 ppc_elf_addr16_ha_reloc
, /* special_function */
271 "R_PPC_ADDR16_HA", /* name */
272 FALSE
, /* partial_inplace */
274 0xffff, /* dst_mask */
275 FALSE
), /* pcrel_offset */
277 /* An absolute 16 bit branch; the lower two bits must be zero.
278 FIXME: we don't check that, we just clear them. */
279 HOWTO (R_PPC_ADDR14
, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 FALSE
, /* pc_relative */
285 complain_overflow_bitfield
, /* complain_on_overflow */
286 bfd_elf_generic_reloc
, /* special_function */
287 "R_PPC_ADDR14", /* name */
288 FALSE
, /* partial_inplace */
290 0xfffc, /* dst_mask */
291 FALSE
), /* pcrel_offset */
293 /* An absolute 16 bit branch, for which bit 10 should be set to
294 indicate that the branch is expected to be taken. The lower two
295 bits must be zero. */
296 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_bitfield
, /* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* special_function */
304 "R_PPC_ADDR14_BRTAKEN",/* name */
305 FALSE
, /* partial_inplace */
307 0xfffc, /* dst_mask */
308 FALSE
), /* pcrel_offset */
310 /* An absolute 16 bit branch, for which bit 10 should be set to
311 indicate that the branch is not expected to be taken. The lower
312 two bits must be zero. */
313 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 FALSE
, /* pc_relative */
319 complain_overflow_bitfield
, /* complain_on_overflow */
320 bfd_elf_generic_reloc
, /* special_function */
321 "R_PPC_ADDR14_BRNTAKEN",/* name */
322 FALSE
, /* partial_inplace */
324 0xfffc, /* dst_mask */
325 FALSE
), /* pcrel_offset */
327 /* A relative 26 bit branch; the lower two bits must be zero. */
328 HOWTO (R_PPC_REL24
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 TRUE
, /* pc_relative */
334 complain_overflow_signed
, /* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_PPC_REL24", /* name */
337 FALSE
, /* partial_inplace */
339 0x3fffffc, /* dst_mask */
340 TRUE
), /* pcrel_offset */
342 /* A relative 16 bit branch; the lower two bits must be zero. */
343 HOWTO (R_PPC_REL14
, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 TRUE
, /* pc_relative */
349 complain_overflow_signed
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_PPC_REL14", /* name */
352 FALSE
, /* partial_inplace */
354 0xfffc, /* dst_mask */
355 TRUE
), /* pcrel_offset */
357 /* A relative 16 bit branch. Bit 10 should be set to indicate that
358 the branch is expected to be taken. The lower two bits must be
360 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 TRUE
, /* pc_relative */
366 complain_overflow_signed
, /* complain_on_overflow */
367 bfd_elf_generic_reloc
, /* special_function */
368 "R_PPC_REL14_BRTAKEN", /* name */
369 FALSE
, /* partial_inplace */
371 0xfffc, /* dst_mask */
372 TRUE
), /* pcrel_offset */
374 /* A relative 16 bit branch. Bit 10 should be set to indicate that
375 the branch is not expected to be taken. The lower two bits must
377 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 TRUE
, /* pc_relative */
383 complain_overflow_signed
, /* complain_on_overflow */
384 bfd_elf_generic_reloc
, /* special_function */
385 "R_PPC_REL14_BRNTAKEN",/* name */
386 FALSE
, /* partial_inplace */
388 0xfffc, /* dst_mask */
389 TRUE
), /* pcrel_offset */
391 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
393 HOWTO (R_PPC_GOT16
, /* type */
395 1, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_signed
, /* complain_on_overflow */
400 bfd_elf_generic_reloc
, /* special_function */
401 "R_PPC_GOT16", /* name */
402 FALSE
, /* partial_inplace */
404 0xffff, /* dst_mask */
405 FALSE
), /* pcrel_offset */
407 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
409 HOWTO (R_PPC_GOT16_LO
, /* type */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_PPC_GOT16_LO", /* name */
418 FALSE
, /* partial_inplace */
420 0xffff, /* dst_mask */
421 FALSE
), /* pcrel_offset */
423 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
425 HOWTO (R_PPC_GOT16_HI
, /* type */
427 1, /* size (0 = byte, 1 = short, 2 = long) */
429 FALSE
, /* pc_relative */
431 complain_overflow_bitfield
, /* complain_on_overflow */
432 bfd_elf_generic_reloc
, /* special_function */
433 "R_PPC_GOT16_HI", /* name */
434 FALSE
, /* partial_inplace */
436 0xffff, /* dst_mask */
437 FALSE
), /* pcrel_offset */
439 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
441 HOWTO (R_PPC_GOT16_HA
, /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 FALSE
, /* pc_relative */
447 complain_overflow_bitfield
, /* complain_on_overflow */
448 ppc_elf_addr16_ha_reloc
, /* special_function */
449 "R_PPC_GOT16_HA", /* name */
450 FALSE
, /* partial_inplace */
452 0xffff, /* dst_mask */
453 FALSE
), /* pcrel_offset */
455 /* Like R_PPC_REL24, but referring to the procedure linkage table
456 entry for the symbol. */
457 HOWTO (R_PPC_PLTREL24
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 TRUE
, /* pc_relative */
463 complain_overflow_signed
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_PPC_PLTREL24", /* name */
466 FALSE
, /* partial_inplace */
468 0x3fffffc, /* dst_mask */
469 TRUE
), /* pcrel_offset */
471 /* This is used only by the dynamic linker. The symbol should exist
472 both in the object being run and in some shared library. The
473 dynamic linker copies the data addressed by the symbol from the
474 shared library into the object, because the object being
475 run has to have the data at some particular address. */
476 HOWTO (R_PPC_COPY
, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE
, /* pc_relative */
482 complain_overflow_bitfield
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_PPC_COPY", /* name */
485 FALSE
, /* partial_inplace */
488 FALSE
), /* pcrel_offset */
490 /* Like R_PPC_ADDR32, but used when setting global offset table
492 HOWTO (R_PPC_GLOB_DAT
, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE
, /* pc_relative */
498 complain_overflow_bitfield
, /* complain_on_overflow */
499 bfd_elf_generic_reloc
, /* special_function */
500 "R_PPC_GLOB_DAT", /* name */
501 FALSE
, /* partial_inplace */
503 0xffffffff, /* dst_mask */
504 FALSE
), /* pcrel_offset */
506 /* Marks a procedure linkage table entry for a symbol. */
507 HOWTO (R_PPC_JMP_SLOT
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 FALSE
, /* pc_relative */
513 complain_overflow_bitfield
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_PPC_JMP_SLOT", /* name */
516 FALSE
, /* partial_inplace */
519 FALSE
), /* pcrel_offset */
521 /* Used only by the dynamic linker. When the object is run, this
522 longword is set to the load address of the object, plus the
524 HOWTO (R_PPC_RELATIVE
, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE
, /* pc_relative */
530 complain_overflow_bitfield
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_PPC_RELATIVE", /* name */
533 FALSE
, /* partial_inplace */
535 0xffffffff, /* dst_mask */
536 FALSE
), /* pcrel_offset */
538 /* Like R_PPC_REL24, but uses the value of the symbol within the
539 object rather than the final value. Normally used for
540 _GLOBAL_OFFSET_TABLE_. */
541 HOWTO (R_PPC_LOCAL24PC
, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 TRUE
, /* pc_relative */
547 complain_overflow_signed
, /* complain_on_overflow */
548 bfd_elf_generic_reloc
, /* special_function */
549 "R_PPC_LOCAL24PC", /* name */
550 FALSE
, /* partial_inplace */
552 0x3fffffc, /* dst_mask */
553 TRUE
), /* pcrel_offset */
555 /* Like R_PPC_ADDR32, but may be unaligned. */
556 HOWTO (R_PPC_UADDR32
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE
, /* pc_relative */
562 complain_overflow_bitfield
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_PPC_UADDR32", /* name */
565 FALSE
, /* partial_inplace */
567 0xffffffff, /* dst_mask */
568 FALSE
), /* pcrel_offset */
570 /* Like R_PPC_ADDR16, but may be unaligned. */
571 HOWTO (R_PPC_UADDR16
, /* type */
573 1, /* size (0 = byte, 1 = short, 2 = long) */
575 FALSE
, /* pc_relative */
577 complain_overflow_bitfield
, /* complain_on_overflow */
578 bfd_elf_generic_reloc
, /* special_function */
579 "R_PPC_UADDR16", /* name */
580 FALSE
, /* partial_inplace */
582 0xffff, /* dst_mask */
583 FALSE
), /* pcrel_offset */
585 /* 32-bit PC relative */
586 HOWTO (R_PPC_REL32
, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 TRUE
, /* pc_relative */
592 complain_overflow_bitfield
, /* complain_on_overflow */
593 bfd_elf_generic_reloc
, /* special_function */
594 "R_PPC_REL32", /* name */
595 FALSE
, /* partial_inplace */
597 0xffffffff, /* dst_mask */
598 TRUE
), /* pcrel_offset */
600 /* 32-bit relocation to the symbol's procedure linkage table.
601 FIXME: not supported. */
602 HOWTO (R_PPC_PLT32
, /* type */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE
, /* pc_relative */
608 complain_overflow_bitfield
, /* complain_on_overflow */
609 bfd_elf_generic_reloc
, /* special_function */
610 "R_PPC_PLT32", /* name */
611 FALSE
, /* partial_inplace */
614 FALSE
), /* pcrel_offset */
616 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
617 FIXME: not supported. */
618 HOWTO (R_PPC_PLTREL32
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 TRUE
, /* pc_relative */
624 complain_overflow_bitfield
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_PPC_PLTREL32", /* name */
627 FALSE
, /* partial_inplace */
630 TRUE
), /* pcrel_offset */
632 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
634 HOWTO (R_PPC_PLT16_LO
, /* type */
636 1, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE
, /* pc_relative */
640 complain_overflow_dont
, /* complain_on_overflow */
641 bfd_elf_generic_reloc
, /* special_function */
642 "R_PPC_PLT16_LO", /* name */
643 FALSE
, /* partial_inplace */
645 0xffff, /* dst_mask */
646 FALSE
), /* pcrel_offset */
648 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
650 HOWTO (R_PPC_PLT16_HI
, /* type */
652 1, /* size (0 = byte, 1 = short, 2 = long) */
654 FALSE
, /* pc_relative */
656 complain_overflow_bitfield
, /* complain_on_overflow */
657 bfd_elf_generic_reloc
, /* special_function */
658 "R_PPC_PLT16_HI", /* name */
659 FALSE
, /* partial_inplace */
661 0xffff, /* dst_mask */
662 FALSE
), /* pcrel_offset */
664 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
666 HOWTO (R_PPC_PLT16_HA
, /* type */
668 1, /* size (0 = byte, 1 = short, 2 = long) */
670 FALSE
, /* pc_relative */
672 complain_overflow_bitfield
, /* complain_on_overflow */
673 ppc_elf_addr16_ha_reloc
, /* special_function */
674 "R_PPC_PLT16_HA", /* name */
675 FALSE
, /* partial_inplace */
677 0xffff, /* dst_mask */
678 FALSE
), /* pcrel_offset */
680 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
682 HOWTO (R_PPC_SDAREL16
, /* type */
684 1, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE
, /* pc_relative */
688 complain_overflow_signed
, /* complain_on_overflow */
689 bfd_elf_generic_reloc
, /* special_function */
690 "R_PPC_SDAREL16", /* name */
691 FALSE
, /* partial_inplace */
693 0xffff, /* dst_mask */
694 FALSE
), /* pcrel_offset */
696 /* 16-bit section relative relocation. */
697 HOWTO (R_PPC_SECTOFF
, /* type */
699 1, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE
, /* pc_relative */
703 complain_overflow_bitfield
, /* complain_on_overflow */
704 bfd_elf_generic_reloc
, /* special_function */
705 "R_PPC_SECTOFF", /* name */
706 FALSE
, /* partial_inplace */
708 0xffff, /* dst_mask */
709 FALSE
), /* pcrel_offset */
711 /* 16-bit lower half section relative relocation. */
712 HOWTO (R_PPC_SECTOFF_LO
, /* type */
714 1, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE
, /* pc_relative */
718 complain_overflow_dont
, /* complain_on_overflow */
719 bfd_elf_generic_reloc
, /* special_function */
720 "R_PPC_SECTOFF_LO", /* name */
721 FALSE
, /* partial_inplace */
723 0xffff, /* dst_mask */
724 FALSE
), /* pcrel_offset */
726 /* 16-bit upper half section relative relocation. */
727 HOWTO (R_PPC_SECTOFF_HI
, /* type */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_bitfield
, /* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_PPC_SECTOFF_HI", /* name */
736 FALSE
, /* partial_inplace */
738 0xffff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 /* 16-bit upper half adjusted section relative relocation. */
742 HOWTO (R_PPC_SECTOFF_HA
, /* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE
, /* pc_relative */
748 complain_overflow_bitfield
, /* complain_on_overflow */
749 ppc_elf_addr16_ha_reloc
, /* special_function */
750 "R_PPC_SECTOFF_HA", /* name */
751 FALSE
, /* partial_inplace */
753 0xffff, /* dst_mask */
754 FALSE
), /* pcrel_offset */
756 /* Marker relocs for TLS. */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_dont
, /* complain_on_overflow */
764 bfd_elf_generic_reloc
, /* special_function */
765 "R_PPC_TLS", /* name */
766 FALSE
, /* partial_inplace */
769 FALSE
), /* pcrel_offset */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE
, /* pc_relative */
777 complain_overflow_dont
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* special_function */
779 "R_PPC_TLSGD", /* name */
780 FALSE
, /* partial_inplace */
783 FALSE
), /* pcrel_offset */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_dont
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 "R_PPC_TLSLD", /* name */
794 FALSE
, /* partial_inplace */
797 FALSE
), /* pcrel_offset */
799 /* Computes the load module index of the load module that contains the
800 definition of its TLS sym. */
801 HOWTO (R_PPC_DTPMOD32
,
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 FALSE
, /* pc_relative */
807 complain_overflow_dont
, /* complain_on_overflow */
808 ppc_elf_unhandled_reloc
, /* special_function */
809 "R_PPC_DTPMOD32", /* name */
810 FALSE
, /* partial_inplace */
812 0xffffffff, /* dst_mask */
813 FALSE
), /* pcrel_offset */
815 /* Computes a dtv-relative displacement, the difference between the value
816 of sym+add and the base address of the thread-local storage block that
817 contains the definition of sym, minus 0x8000. */
818 HOWTO (R_PPC_DTPREL32
,
820 2, /* size (0 = byte, 1 = short, 2 = long) */
822 FALSE
, /* pc_relative */
824 complain_overflow_dont
, /* complain_on_overflow */
825 ppc_elf_unhandled_reloc
, /* special_function */
826 "R_PPC_DTPREL32", /* name */
827 FALSE
, /* partial_inplace */
829 0xffffffff, /* dst_mask */
830 FALSE
), /* pcrel_offset */
832 /* A 16 bit dtprel reloc. */
833 HOWTO (R_PPC_DTPREL16
,
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 FALSE
, /* pc_relative */
839 complain_overflow_signed
, /* complain_on_overflow */
840 ppc_elf_unhandled_reloc
, /* special_function */
841 "R_PPC_DTPREL16", /* name */
842 FALSE
, /* partial_inplace */
844 0xffff, /* dst_mask */
845 FALSE
), /* pcrel_offset */
847 /* Like DTPREL16, but no overflow. */
848 HOWTO (R_PPC_DTPREL16_LO
,
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 FALSE
, /* pc_relative */
854 complain_overflow_dont
, /* complain_on_overflow */
855 ppc_elf_unhandled_reloc
, /* special_function */
856 "R_PPC_DTPREL16_LO", /* name */
857 FALSE
, /* partial_inplace */
859 0xffff, /* dst_mask */
860 FALSE
), /* pcrel_offset */
862 /* Like DTPREL16_LO, but next higher group of 16 bits. */
863 HOWTO (R_PPC_DTPREL16_HI
,
865 1, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_dont
, /* complain_on_overflow */
870 ppc_elf_unhandled_reloc
, /* special_function */
871 "R_PPC_DTPREL16_HI", /* name */
872 FALSE
, /* partial_inplace */
874 0xffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 /* Like DTPREL16_HI, but adjust for low 16 bits. */
878 HOWTO (R_PPC_DTPREL16_HA
,
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE
, /* pc_relative */
884 complain_overflow_dont
, /* complain_on_overflow */
885 ppc_elf_unhandled_reloc
, /* special_function */
886 "R_PPC_DTPREL16_HA", /* name */
887 FALSE
, /* partial_inplace */
889 0xffff, /* dst_mask */
890 FALSE
), /* pcrel_offset */
892 /* Computes a tp-relative displacement, the difference between the value of
893 sym+add and the value of the thread pointer (r13). */
894 HOWTO (R_PPC_TPREL32
,
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_dont
, /* complain_on_overflow */
901 ppc_elf_unhandled_reloc
, /* special_function */
902 "R_PPC_TPREL32", /* name */
903 FALSE
, /* partial_inplace */
905 0xffffffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 /* A 16 bit tprel reloc. */
909 HOWTO (R_PPC_TPREL16
,
911 1, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE
, /* pc_relative */
915 complain_overflow_signed
, /* complain_on_overflow */
916 ppc_elf_unhandled_reloc
, /* special_function */
917 "R_PPC_TPREL16", /* name */
918 FALSE
, /* partial_inplace */
920 0xffff, /* dst_mask */
921 FALSE
), /* pcrel_offset */
923 /* Like TPREL16, but no overflow. */
924 HOWTO (R_PPC_TPREL16_LO
,
926 1, /* size (0 = byte, 1 = short, 2 = long) */
928 FALSE
, /* pc_relative */
930 complain_overflow_dont
, /* complain_on_overflow */
931 ppc_elf_unhandled_reloc
, /* special_function */
932 "R_PPC_TPREL16_LO", /* name */
933 FALSE
, /* partial_inplace */
935 0xffff, /* dst_mask */
936 FALSE
), /* pcrel_offset */
938 /* Like TPREL16_LO, but next higher group of 16 bits. */
939 HOWTO (R_PPC_TPREL16_HI
,
941 1, /* size (0 = byte, 1 = short, 2 = long) */
943 FALSE
, /* pc_relative */
945 complain_overflow_dont
, /* complain_on_overflow */
946 ppc_elf_unhandled_reloc
, /* special_function */
947 "R_PPC_TPREL16_HI", /* name */
948 FALSE
, /* partial_inplace */
950 0xffff, /* dst_mask */
951 FALSE
), /* pcrel_offset */
953 /* Like TPREL16_HI, but adjust for low 16 bits. */
954 HOWTO (R_PPC_TPREL16_HA
,
956 1, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE
, /* pc_relative */
960 complain_overflow_dont
, /* complain_on_overflow */
961 ppc_elf_unhandled_reloc
, /* special_function */
962 "R_PPC_TPREL16_HA", /* name */
963 FALSE
, /* partial_inplace */
965 0xffff, /* dst_mask */
966 FALSE
), /* pcrel_offset */
968 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
969 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
970 to the first entry. */
971 HOWTO (R_PPC_GOT_TLSGD16
,
973 1, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_signed
, /* complain_on_overflow */
978 ppc_elf_unhandled_reloc
, /* special_function */
979 "R_PPC_GOT_TLSGD16", /* name */
980 FALSE
, /* partial_inplace */
982 0xffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 /* Like GOT_TLSGD16, but no overflow. */
986 HOWTO (R_PPC_GOT_TLSGD16_LO
,
988 1, /* size (0 = byte, 1 = short, 2 = long) */
990 FALSE
, /* pc_relative */
992 complain_overflow_dont
, /* complain_on_overflow */
993 ppc_elf_unhandled_reloc
, /* special_function */
994 "R_PPC_GOT_TLSGD16_LO", /* name */
995 FALSE
, /* partial_inplace */
997 0xffff, /* dst_mask */
998 FALSE
), /* pcrel_offset */
1000 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1001 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1002 16, /* rightshift */
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_dont
, /* complain_on_overflow */
1008 ppc_elf_unhandled_reloc
, /* special_function */
1009 "R_PPC_GOT_TLSGD16_HI", /* name */
1010 FALSE
, /* partial_inplace */
1012 0xffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1016 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1017 16, /* rightshift */
1018 1, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE
, /* pc_relative */
1022 complain_overflow_dont
, /* complain_on_overflow */
1023 ppc_elf_unhandled_reloc
, /* special_function */
1024 "R_PPC_GOT_TLSGD16_HA", /* name */
1025 FALSE
, /* partial_inplace */
1027 0xffff, /* dst_mask */
1028 FALSE
), /* pcrel_offset */
1030 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1031 with values (sym+add)@dtpmod and zero, and computes the offset to the
1033 HOWTO (R_PPC_GOT_TLSLD16
,
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE
, /* pc_relative */
1039 complain_overflow_signed
, /* complain_on_overflow */
1040 ppc_elf_unhandled_reloc
, /* special_function */
1041 "R_PPC_GOT_TLSLD16", /* name */
1042 FALSE
, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE
), /* pcrel_offset */
1047 /* Like GOT_TLSLD16, but no overflow. */
1048 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1050 1, /* size (0 = byte, 1 = short, 2 = long) */
1052 FALSE
, /* pc_relative */
1054 complain_overflow_dont
, /* complain_on_overflow */
1055 ppc_elf_unhandled_reloc
, /* special_function */
1056 "R_PPC_GOT_TLSLD16_LO", /* name */
1057 FALSE
, /* partial_inplace */
1059 0xffff, /* dst_mask */
1060 FALSE
), /* pcrel_offset */
1062 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1063 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1064 16, /* rightshift */
1065 1, /* size (0 = byte, 1 = short, 2 = long) */
1067 FALSE
, /* pc_relative */
1069 complain_overflow_dont
, /* complain_on_overflow */
1070 ppc_elf_unhandled_reloc
, /* special_function */
1071 "R_PPC_GOT_TLSLD16_HI", /* name */
1072 FALSE
, /* partial_inplace */
1074 0xffff, /* dst_mask */
1075 FALSE
), /* pcrel_offset */
1077 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1078 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1079 16, /* rightshift */
1080 1, /* size (0 = byte, 1 = short, 2 = long) */
1082 FALSE
, /* pc_relative */
1084 complain_overflow_dont
, /* complain_on_overflow */
1085 ppc_elf_unhandled_reloc
, /* special_function */
1086 "R_PPC_GOT_TLSLD16_HA", /* name */
1087 FALSE
, /* partial_inplace */
1089 0xffff, /* dst_mask */
1090 FALSE
), /* pcrel_offset */
1092 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1093 the offset to the entry. */
1094 HOWTO (R_PPC_GOT_DTPREL16
,
1096 1, /* size (0 = byte, 1 = short, 2 = long) */
1098 FALSE
, /* pc_relative */
1100 complain_overflow_signed
, /* complain_on_overflow */
1101 ppc_elf_unhandled_reloc
, /* special_function */
1102 "R_PPC_GOT_DTPREL16", /* name */
1103 FALSE
, /* partial_inplace */
1105 0xffff, /* dst_mask */
1106 FALSE
), /* pcrel_offset */
1108 /* Like GOT_DTPREL16, but no overflow. */
1109 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1111 1, /* size (0 = byte, 1 = short, 2 = long) */
1113 FALSE
, /* pc_relative */
1115 complain_overflow_dont
, /* complain_on_overflow */
1116 ppc_elf_unhandled_reloc
, /* special_function */
1117 "R_PPC_GOT_DTPREL16_LO", /* name */
1118 FALSE
, /* partial_inplace */
1120 0xffff, /* dst_mask */
1121 FALSE
), /* pcrel_offset */
1123 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1124 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1125 16, /* rightshift */
1126 1, /* size (0 = byte, 1 = short, 2 = long) */
1128 FALSE
, /* pc_relative */
1130 complain_overflow_dont
, /* complain_on_overflow */
1131 ppc_elf_unhandled_reloc
, /* special_function */
1132 "R_PPC_GOT_DTPREL16_HI", /* name */
1133 FALSE
, /* partial_inplace */
1135 0xffff, /* dst_mask */
1136 FALSE
), /* pcrel_offset */
1138 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1139 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1140 16, /* rightshift */
1141 1, /* size (0 = byte, 1 = short, 2 = long) */
1143 FALSE
, /* pc_relative */
1145 complain_overflow_dont
, /* complain_on_overflow */
1146 ppc_elf_unhandled_reloc
, /* special_function */
1147 "R_PPC_GOT_DTPREL16_HA", /* name */
1148 FALSE
, /* partial_inplace */
1150 0xffff, /* dst_mask */
1151 FALSE
), /* pcrel_offset */
1153 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1154 offset to the entry. */
1155 HOWTO (R_PPC_GOT_TPREL16
,
1157 1, /* size (0 = byte, 1 = short, 2 = long) */
1159 FALSE
, /* pc_relative */
1161 complain_overflow_signed
, /* complain_on_overflow */
1162 ppc_elf_unhandled_reloc
, /* special_function */
1163 "R_PPC_GOT_TPREL16", /* name */
1164 FALSE
, /* partial_inplace */
1166 0xffff, /* dst_mask */
1167 FALSE
), /* pcrel_offset */
1169 /* Like GOT_TPREL16, but no overflow. */
1170 HOWTO (R_PPC_GOT_TPREL16_LO
,
1172 1, /* size (0 = byte, 1 = short, 2 = long) */
1174 FALSE
, /* pc_relative */
1176 complain_overflow_dont
, /* complain_on_overflow */
1177 ppc_elf_unhandled_reloc
, /* special_function */
1178 "R_PPC_GOT_TPREL16_LO", /* name */
1179 FALSE
, /* partial_inplace */
1181 0xffff, /* dst_mask */
1182 FALSE
), /* pcrel_offset */
1184 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1185 HOWTO (R_PPC_GOT_TPREL16_HI
,
1186 16, /* rightshift */
1187 1, /* size (0 = byte, 1 = short, 2 = long) */
1189 FALSE
, /* pc_relative */
1191 complain_overflow_dont
, /* complain_on_overflow */
1192 ppc_elf_unhandled_reloc
, /* special_function */
1193 "R_PPC_GOT_TPREL16_HI", /* name */
1194 FALSE
, /* partial_inplace */
1196 0xffff, /* dst_mask */
1197 FALSE
), /* pcrel_offset */
1199 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1200 HOWTO (R_PPC_GOT_TPREL16_HA
,
1201 16, /* rightshift */
1202 1, /* size (0 = byte, 1 = short, 2 = long) */
1204 FALSE
, /* pc_relative */
1206 complain_overflow_dont
, /* complain_on_overflow */
1207 ppc_elf_unhandled_reloc
, /* special_function */
1208 "R_PPC_GOT_TPREL16_HA", /* name */
1209 FALSE
, /* partial_inplace */
1211 0xffff, /* dst_mask */
1212 FALSE
), /* pcrel_offset */
1214 /* The remaining relocs are from the Embedded ELF ABI, and are not
1215 in the SVR4 ELF ABI. */
1217 /* 32 bit value resulting from the addend minus the symbol. */
1218 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1220 2, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE
, /* pc_relative */
1224 complain_overflow_bitfield
, /* complain_on_overflow */
1225 bfd_elf_generic_reloc
, /* special_function */
1226 "R_PPC_EMB_NADDR32", /* name */
1227 FALSE
, /* partial_inplace */
1229 0xffffffff, /* dst_mask */
1230 FALSE
), /* pcrel_offset */
1232 /* 16 bit value resulting from the addend minus the symbol. */
1233 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1235 1, /* size (0 = byte, 1 = short, 2 = long) */
1237 FALSE
, /* pc_relative */
1239 complain_overflow_bitfield
, /* complain_on_overflow */
1240 bfd_elf_generic_reloc
, /* special_function */
1241 "R_PPC_EMB_NADDR16", /* name */
1242 FALSE
, /* partial_inplace */
1244 0xffff, /* dst_mask */
1245 FALSE
), /* pcrel_offset */
1247 /* 16 bit value resulting from the addend minus the symbol. */
1248 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1250 1, /* size (0 = byte, 1 = short, 2 = long) */
1252 FALSE
, /* pc_relative */
1254 complain_overflow_dont
,/* complain_on_overflow */
1255 bfd_elf_generic_reloc
, /* special_function */
1256 "R_PPC_EMB_ADDR16_LO", /* name */
1257 FALSE
, /* partial_inplace */
1259 0xffff, /* dst_mask */
1260 FALSE
), /* pcrel_offset */
1262 /* The high order 16 bits of the addend minus the symbol. */
1263 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1264 16, /* rightshift */
1265 1, /* size (0 = byte, 1 = short, 2 = long) */
1267 FALSE
, /* pc_relative */
1269 complain_overflow_dont
, /* complain_on_overflow */
1270 bfd_elf_generic_reloc
, /* special_function */
1271 "R_PPC_EMB_NADDR16_HI", /* name */
1272 FALSE
, /* partial_inplace */
1274 0xffff, /* dst_mask */
1275 FALSE
), /* pcrel_offset */
1277 /* The high order 16 bits of the result of the addend minus the address,
1278 plus 1 if the contents of the low 16 bits, treated as a signed number,
1280 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1281 16, /* rightshift */
1282 1, /* size (0 = byte, 1 = short, 2 = long) */
1284 FALSE
, /* pc_relative */
1286 complain_overflow_dont
, /* complain_on_overflow */
1287 ppc_elf_addr16_ha_reloc
, /* special_function */
1288 "R_PPC_EMB_NADDR16_HA", /* name */
1289 FALSE
, /* partial_inplace */
1291 0xffff, /* dst_mask */
1292 FALSE
), /* pcrel_offset */
1294 /* 16 bit value resulting from allocating a 4 byte word to hold an
1295 address in the .sdata section, and returning the offset from
1296 _SDA_BASE_ for that relocation. */
1297 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1299 1, /* size (0 = byte, 1 = short, 2 = long) */
1301 FALSE
, /* pc_relative */
1303 complain_overflow_bitfield
, /* complain_on_overflow */
1304 bfd_elf_generic_reloc
, /* special_function */
1305 "R_PPC_EMB_SDAI16", /* name */
1306 FALSE
, /* partial_inplace */
1308 0xffff, /* dst_mask */
1309 FALSE
), /* pcrel_offset */
1311 /* 16 bit value resulting from allocating a 4 byte word to hold an
1312 address in the .sdata2 section, and returning the offset from
1313 _SDA2_BASE_ for that relocation. */
1314 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1316 1, /* size (0 = byte, 1 = short, 2 = long) */
1318 FALSE
, /* pc_relative */
1320 complain_overflow_bitfield
, /* complain_on_overflow */
1321 bfd_elf_generic_reloc
, /* special_function */
1322 "R_PPC_EMB_SDA2I16", /* name */
1323 FALSE
, /* partial_inplace */
1325 0xffff, /* dst_mask */
1326 FALSE
), /* pcrel_offset */
1328 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1329 small data items. */
1330 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1332 1, /* size (0 = byte, 1 = short, 2 = long) */
1334 FALSE
, /* pc_relative */
1336 complain_overflow_signed
, /* complain_on_overflow */
1337 bfd_elf_generic_reloc
, /* special_function */
1338 "R_PPC_EMB_SDA2REL", /* name */
1339 FALSE
, /* partial_inplace */
1341 0xffff, /* dst_mask */
1342 FALSE
), /* pcrel_offset */
1344 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1345 signed offset from the appropriate base, and filling in the register
1346 field with the appropriate register (0, 2, or 13). */
1347 HOWTO (R_PPC_EMB_SDA21
, /* type */
1349 2, /* size (0 = byte, 1 = short, 2 = long) */
1351 FALSE
, /* pc_relative */
1353 complain_overflow_signed
, /* complain_on_overflow */
1354 bfd_elf_generic_reloc
, /* special_function */
1355 "R_PPC_EMB_SDA21", /* name */
1356 FALSE
, /* partial_inplace */
1358 0xffff, /* dst_mask */
1359 FALSE
), /* pcrel_offset */
1361 /* Relocation not handled: R_PPC_EMB_MRKREF */
1362 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1363 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1364 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1365 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1366 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1368 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1369 in the 16 bit signed offset from the appropriate base, and filling in the
1370 register field with the appropriate register (0, 2, or 13). */
1371 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1373 1, /* size (0 = byte, 1 = short, 2 = long) */
1375 TRUE
, /* pc_relative */
1377 complain_overflow_signed
, /* complain_on_overflow */
1378 bfd_elf_generic_reloc
, /* special_function */
1379 "R_PPC_EMB_RELSDA", /* name */
1380 FALSE
, /* partial_inplace */
1382 0xffff, /* dst_mask */
1383 FALSE
), /* pcrel_offset */
1385 HOWTO (R_PPC_IRELATIVE
, /* type */
1387 2, /* size (0 = byte, 1 = short, 2 = long) */
1389 FALSE
, /* pc_relative */
1391 complain_overflow_bitfield
, /* complain_on_overflow */
1392 bfd_elf_generic_reloc
, /* special_function */
1393 "R_PPC_IRELATIVE", /* name */
1394 FALSE
, /* partial_inplace */
1396 0xffffffff, /* dst_mask */
1397 FALSE
), /* pcrel_offset */
1399 /* A 16 bit relative relocation. */
1400 HOWTO (R_PPC_REL16
, /* type */
1402 1, /* size (0 = byte, 1 = short, 2 = long) */
1404 TRUE
, /* pc_relative */
1406 complain_overflow_bitfield
, /* complain_on_overflow */
1407 bfd_elf_generic_reloc
, /* special_function */
1408 "R_PPC_REL16", /* name */
1409 FALSE
, /* partial_inplace */
1411 0xffff, /* dst_mask */
1412 TRUE
), /* pcrel_offset */
1414 /* A 16 bit relative relocation without overflow. */
1415 HOWTO (R_PPC_REL16_LO
, /* type */
1417 1, /* size (0 = byte, 1 = short, 2 = long) */
1419 TRUE
, /* pc_relative */
1421 complain_overflow_dont
,/* complain_on_overflow */
1422 bfd_elf_generic_reloc
, /* special_function */
1423 "R_PPC_REL16_LO", /* name */
1424 FALSE
, /* partial_inplace */
1426 0xffff, /* dst_mask */
1427 TRUE
), /* pcrel_offset */
1429 /* The high order 16 bits of a relative address. */
1430 HOWTO (R_PPC_REL16_HI
, /* type */
1431 16, /* rightshift */
1432 1, /* size (0 = byte, 1 = short, 2 = long) */
1434 TRUE
, /* pc_relative */
1436 complain_overflow_dont
, /* complain_on_overflow */
1437 bfd_elf_generic_reloc
, /* special_function */
1438 "R_PPC_REL16_HI", /* name */
1439 FALSE
, /* partial_inplace */
1441 0xffff, /* dst_mask */
1442 TRUE
), /* pcrel_offset */
1444 /* The high order 16 bits of a relative address, plus 1 if the contents of
1445 the low 16 bits, treated as a signed number, is negative. */
1446 HOWTO (R_PPC_REL16_HA
, /* type */
1447 16, /* rightshift */
1448 1, /* size (0 = byte, 1 = short, 2 = long) */
1450 TRUE
, /* pc_relative */
1452 complain_overflow_dont
, /* complain_on_overflow */
1453 ppc_elf_addr16_ha_reloc
, /* special_function */
1454 "R_PPC_REL16_HA", /* name */
1455 FALSE
, /* partial_inplace */
1457 0xffff, /* dst_mask */
1458 TRUE
), /* pcrel_offset */
1460 /* GNU extension to record C++ vtable hierarchy. */
1461 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1463 0, /* size (0 = byte, 1 = short, 2 = long) */
1465 FALSE
, /* pc_relative */
1467 complain_overflow_dont
, /* complain_on_overflow */
1468 NULL
, /* special_function */
1469 "R_PPC_GNU_VTINHERIT", /* name */
1470 FALSE
, /* partial_inplace */
1473 FALSE
), /* pcrel_offset */
1475 /* GNU extension to record C++ vtable member usage. */
1476 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1478 0, /* size (0 = byte, 1 = short, 2 = long) */
1480 FALSE
, /* pc_relative */
1482 complain_overflow_dont
, /* complain_on_overflow */
1483 NULL
, /* special_function */
1484 "R_PPC_GNU_VTENTRY", /* name */
1485 FALSE
, /* partial_inplace */
1488 FALSE
), /* pcrel_offset */
1490 /* Phony reloc to handle AIX style TOC entries. */
1491 HOWTO (R_PPC_TOC16
, /* type */
1493 1, /* size (0 = byte, 1 = short, 2 = long) */
1495 FALSE
, /* pc_relative */
1497 complain_overflow_signed
, /* complain_on_overflow */
1498 bfd_elf_generic_reloc
, /* special_function */
1499 "R_PPC_TOC16", /* name */
1500 FALSE
, /* partial_inplace */
1502 0xffff, /* dst_mask */
1503 FALSE
), /* pcrel_offset */
1506 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1509 ppc_elf_howto_init (void)
1511 unsigned int i
, type
;
1514 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1517 type
= ppc_elf_howto_raw
[i
].type
;
1518 if (type
>= (sizeof (ppc_elf_howto_table
)
1519 / sizeof (ppc_elf_howto_table
[0])))
1521 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1525 static reloc_howto_type
*
1526 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1527 bfd_reloc_code_real_type code
)
1529 enum elf_ppc_reloc_type r
;
1531 /* Initialize howto table if not already done. */
1532 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1533 ppc_elf_howto_init ();
1540 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1541 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1542 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1543 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1544 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1545 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1546 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1547 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1548 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1549 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1550 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1551 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1552 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1553 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1554 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1555 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1556 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1557 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1558 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1559 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1560 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1561 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1562 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1563 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1564 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1565 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1566 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1567 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1568 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1569 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1570 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1571 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1572 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1573 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1574 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1575 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1576 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC_TLSGD
; break;
1577 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC_TLSLD
; break;
1578 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1579 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1580 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1581 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1582 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1583 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1584 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1585 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1586 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1587 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1588 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1589 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1590 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1591 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1592 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1593 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1594 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1595 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1596 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1597 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1598 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1599 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1600 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1601 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1602 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1603 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1604 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1605 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1606 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1607 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1608 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1609 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1610 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1611 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1612 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1613 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1614 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1615 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1616 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1617 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1618 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1619 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1620 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1621 case BFD_RELOC_16_PCREL
: r
= R_PPC_REL16
; break;
1622 case BFD_RELOC_LO16_PCREL
: r
= R_PPC_REL16_LO
; break;
1623 case BFD_RELOC_HI16_PCREL
: r
= R_PPC_REL16_HI
; break;
1624 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC_REL16_HA
; break;
1625 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1626 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1629 return ppc_elf_howto_table
[r
];
1632 static reloc_howto_type
*
1633 ppc_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1639 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1641 if (ppc_elf_howto_raw
[i
].name
!= NULL
1642 && strcasecmp (ppc_elf_howto_raw
[i
].name
, r_name
) == 0)
1643 return &ppc_elf_howto_raw
[i
];
1648 /* Set the howto pointer for a PowerPC ELF reloc. */
1651 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1653 Elf_Internal_Rela
*dst
)
1655 /* Initialize howto table if not already done. */
1656 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1657 ppc_elf_howto_init ();
1659 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1660 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1662 /* Just because the above assert didn't trigger doesn't mean that
1663 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1664 if (!cache_ptr
->howto
)
1666 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
1667 abfd
, ELF32_R_TYPE (dst
->r_info
));
1668 bfd_set_error (bfd_error_bad_value
);
1670 cache_ptr
->howto
= ppc_elf_howto_table
[R_PPC_NONE
];
1674 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1676 static bfd_reloc_status_type
1677 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1678 arelent
*reloc_entry
,
1680 void *data ATTRIBUTE_UNUSED
,
1681 asection
*input_section
,
1683 char **error_message ATTRIBUTE_UNUSED
)
1687 if (output_bfd
!= NULL
)
1689 reloc_entry
->address
+= input_section
->output_offset
;
1690 return bfd_reloc_ok
;
1693 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1694 return bfd_reloc_outofrange
;
1696 if (bfd_is_com_section (symbol
->section
))
1699 relocation
= symbol
->value
;
1701 relocation
+= symbol
->section
->output_section
->vma
;
1702 relocation
+= symbol
->section
->output_offset
;
1703 relocation
+= reloc_entry
->addend
;
1704 if (reloc_entry
->howto
->pc_relative
)
1705 relocation
-= reloc_entry
->address
;
1707 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1709 return bfd_reloc_continue
;
1712 static bfd_reloc_status_type
1713 ppc_elf_unhandled_reloc (bfd
*abfd
,
1714 arelent
*reloc_entry
,
1717 asection
*input_section
,
1719 char **error_message
)
1721 /* If this is a relocatable link (output_bfd test tells us), just
1722 call the generic function. Any adjustment will be done at final
1724 if (output_bfd
!= NULL
)
1725 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1726 input_section
, output_bfd
, error_message
);
1728 if (error_message
!= NULL
)
1730 static char buf
[60];
1731 sprintf (buf
, _("generic linker can't handle %s"),
1732 reloc_entry
->howto
->name
);
1733 *error_message
= buf
;
1735 return bfd_reloc_dangerous
;
1738 /* Sections created by the linker. */
1740 typedef struct elf_linker_section
1742 /* Pointer to the bfd section. */
1746 /* Associated bss section name. */
1747 const char *bss_name
;
1748 /* Associated symbol name. */
1749 const char *sym_name
;
1750 /* Associated symbol. */
1751 struct elf_link_hash_entry
*sym
;
1752 } elf_linker_section_t
;
1754 /* Linked list of allocated pointer entries. This hangs off of the
1755 symbol lists, and provides allows us to return different pointers,
1756 based on different addend's. */
1758 typedef struct elf_linker_section_pointers
1760 /* next allocated pointer for this symbol */
1761 struct elf_linker_section_pointers
*next
;
1762 /* offset of pointer from beginning of section */
1766 /* which linker section this is */
1767 elf_linker_section_t
*lsect
;
1768 } elf_linker_section_pointers_t
;
1770 struct ppc_elf_obj_tdata
1772 struct elf_obj_tdata elf
;
1774 /* A mapping from local symbols to offsets into the various linker
1775 sections added. This is index by the symbol index. */
1776 elf_linker_section_pointers_t
**linker_section_pointers
;
1778 /* Flags used to auto-detect plt type. */
1779 unsigned int makes_plt_call
: 1;
1780 unsigned int has_rel16
: 1;
1783 #define ppc_elf_tdata(bfd) \
1784 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1786 #define elf_local_ptr_offsets(bfd) \
1787 (ppc_elf_tdata (bfd)->linker_section_pointers)
1789 #define is_ppc_elf(bfd) \
1790 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1791 && elf_object_id (bfd) == PPC32_ELF_TDATA)
1793 /* Override the generic function because we store some extras. */
1796 ppc_elf_mkobject (bfd
*abfd
)
1798 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc_elf_obj_tdata
),
1802 /* Fix bad default arch selected for a 32 bit input bfd when the
1803 default is 64 bit. */
1806 ppc_elf_object_p (bfd
*abfd
)
1808 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1810 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1812 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1814 /* Relies on arch after 64 bit default being 32 bit default. */
1815 abfd
->arch_info
= abfd
->arch_info
->next
;
1816 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1822 /* Function to set whether a module needs the -mrelocatable bit set. */
1825 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1827 BFD_ASSERT (!elf_flags_init (abfd
)
1828 || elf_elfheader (abfd
)->e_flags
== flags
);
1830 elf_elfheader (abfd
)->e_flags
= flags
;
1831 elf_flags_init (abfd
) = TRUE
;
1835 /* Support for core dump NOTE sections. */
1838 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1843 switch (note
->descsz
)
1848 case 268: /* Linux/PPC. */
1850 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1853 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1862 /* Make a ".reg/999" section. */
1863 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1864 size
, note
->descpos
+ offset
);
1868 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1870 switch (note
->descsz
)
1875 case 128: /* Linux/PPC elf_prpsinfo. */
1876 elf_tdata (abfd
)->core_program
1877 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1878 elf_tdata (abfd
)->core_command
1879 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1882 /* Note that for some reason, a spurious space is tacked
1883 onto the end of the args in some (at least one anyway)
1884 implementations, so strip it off if it exists. */
1887 char *command
= elf_tdata (abfd
)->core_command
;
1888 int n
= strlen (command
);
1890 if (0 < n
&& command
[n
- 1] == ' ')
1891 command
[n
- 1] = '\0';
1898 ppc_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
, ...)
1910 va_start (ap
, note_type
);
1911 memset (data
, 0, 32);
1912 strncpy (data
+ 32, va_arg (ap
, const char *), 16);
1913 strncpy (data
+ 48, va_arg (ap
, const char *), 80);
1915 return elfcore_write_note (abfd
, buf
, bufsiz
,
1916 "CORE", note_type
, data
, sizeof (data
));
1927 va_start (ap
, note_type
);
1928 memset (data
, 0, 72);
1929 pid
= va_arg (ap
, long);
1930 bfd_put_32 (abfd
, pid
, data
+ 24);
1931 cursig
= va_arg (ap
, int);
1932 bfd_put_16 (abfd
, cursig
, data
+ 12);
1933 greg
= va_arg (ap
, const void *);
1934 memcpy (data
+ 72, greg
, 192);
1935 memset (data
+ 264, 0, 4);
1937 return elfcore_write_note (abfd
, buf
, bufsiz
,
1938 "CORE", note_type
, data
, sizeof (data
));
1943 /* Return address for Ith PLT stub in section PLT, for relocation REL
1944 or (bfd_vma) -1 if it should not be included. */
1947 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1948 const asection
*plt ATTRIBUTE_UNUSED
,
1951 return rel
->address
;
1954 /* Handle a PowerPC specific section when reading an object file. This
1955 is called when bfd_section_from_shdr finds a section with an unknown
1959 ppc_elf_section_from_shdr (bfd
*abfd
,
1960 Elf_Internal_Shdr
*hdr
,
1967 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1970 newsect
= hdr
->bfd_section
;
1971 flags
= bfd_get_section_flags (abfd
, newsect
);
1972 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1973 flags
|= SEC_EXCLUDE
;
1975 if (hdr
->sh_type
== SHT_ORDERED
)
1976 flags
|= SEC_SORT_ENTRIES
;
1978 bfd_set_section_flags (abfd
, newsect
, flags
);
1982 /* Set up any other section flags and such that may be necessary. */
1985 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1986 Elf_Internal_Shdr
*shdr
,
1989 if ((asect
->flags
& (SEC_GROUP
| SEC_EXCLUDE
)) == SEC_EXCLUDE
)
1990 shdr
->sh_flags
|= SHF_EXCLUDE
;
1992 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1993 shdr
->sh_type
= SHT_ORDERED
;
1998 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1999 need to bump up the number of section headers. */
2002 ppc_elf_additional_program_headers (bfd
*abfd
,
2003 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2008 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2009 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2012 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2013 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2019 /* Add extra PPC sections -- Note, for now, make .sbss2 and
2020 .PPC.EMB.sbss0 a normal section, and not a bss section so
2021 that the linker doesn't crater when trying to make more than
2024 static const struct bfd_elf_special_section ppc_elf_special_sections
[] =
2026 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
2027 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2028 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2029 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2030 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2031 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED
, SHF_ALLOC
},
2032 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE
, 0 },
2033 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2034 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2035 { NULL
, 0, 0, 0, 0 }
2038 /* This is what we want for new plt/got. */
2039 static struct bfd_elf_special_section ppc_alt_plt
=
2040 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
};
2042 static const struct bfd_elf_special_section
*
2043 ppc_elf_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
2045 const struct bfd_elf_special_section
*ssect
;
2047 /* See if this is one of the special sections. */
2048 if (sec
->name
== NULL
)
2051 ssect
= _bfd_elf_get_special_section (sec
->name
, ppc_elf_special_sections
,
2055 if (ssect
== ppc_elf_special_sections
&& (sec
->flags
& SEC_LOAD
) != 0)
2056 ssect
= &ppc_alt_plt
;
2060 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
2063 /* Very simple linked list structure for recording apuinfo values. */
2064 typedef struct apuinfo_list
2066 struct apuinfo_list
*next
;
2067 unsigned long value
;
2071 static apuinfo_list
*head
;
2075 apuinfo_list_init (void)
2081 apuinfo_list_add (unsigned long value
)
2083 apuinfo_list
*entry
= head
;
2085 while (entry
!= NULL
)
2087 if (entry
->value
== value
)
2089 entry
= entry
->next
;
2092 entry
= bfd_malloc (sizeof (* entry
));
2096 entry
->value
= value
;
2102 apuinfo_list_length (void)
2104 apuinfo_list
*entry
;
2105 unsigned long count
;
2107 for (entry
= head
, count
= 0;
2109 entry
= entry
->next
)
2115 static inline unsigned long
2116 apuinfo_list_element (unsigned long number
)
2118 apuinfo_list
* entry
;
2122 entry
= entry
->next
)
2125 return entry
? entry
->value
: 0;
2129 apuinfo_list_finish (void)
2131 apuinfo_list
*entry
;
2133 for (entry
= head
; entry
;)
2135 apuinfo_list
*next
= entry
->next
;
2143 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2144 #define APUINFO_LABEL "APUinfo"
2146 /* Scan the input BFDs and create a linked list of
2147 the APUinfo values that will need to be emitted. */
2150 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
2155 unsigned num_input_sections
;
2156 bfd_size_type output_section_size
;
2158 unsigned num_entries
;
2159 unsigned long offset
;
2160 unsigned long length
;
2161 const char *error_message
= NULL
;
2163 if (link_info
== NULL
)
2166 /* Scan the input bfds, looking for apuinfo sections. */
2167 num_input_sections
= 0;
2168 output_section_size
= 0;
2170 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2172 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2175 ++ num_input_sections
;
2176 output_section_size
+= asec
->size
;
2180 /* We need at least one input sections
2181 in order to make merging worthwhile. */
2182 if (num_input_sections
< 1)
2185 /* Just make sure that the output section exists as well. */
2186 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2190 /* Allocate a buffer for the contents of the input sections. */
2191 buffer
= bfd_malloc (output_section_size
);
2196 apuinfo_list_init ();
2198 /* Read in the input sections contents. */
2199 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2201 unsigned long datum
;
2204 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2208 length
= asec
->size
;
2211 error_message
= _("corrupt or empty %s section in %B");
2215 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
2216 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
2218 error_message
= _("unable to read in %s section from %B");
2222 /* Process the contents of the section. */
2223 ptr
= buffer
+ offset
;
2224 error_message
= _("corrupt %s section in %B");
2226 /* Verify the contents of the header. Note - we have to
2227 extract the values this way in order to allow for a
2228 host whose endian-ness is different from the target. */
2229 datum
= bfd_get_32 (ibfd
, ptr
);
2230 if (datum
!= sizeof APUINFO_LABEL
)
2233 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
2237 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
2240 /* Get the number of bytes used for apuinfo entries. */
2241 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
2242 if (datum
+ 20 != length
)
2245 /* Make sure that we do not run off the end of the section. */
2246 if (offset
+ length
> output_section_size
)
2249 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2250 for (i
= 0; i
< datum
; i
+= 4)
2251 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
2253 /* Update the offset. */
2257 error_message
= NULL
;
2259 /* Compute the size of the output section. */
2260 num_entries
= apuinfo_list_length ();
2261 output_section_size
= 20 + num_entries
* 4;
2263 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2265 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
2267 error_message
= _("warning: unable to set size of %s section in %B");
2273 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
2276 /* Prevent the output section from accumulating the input sections'
2277 contents. We have already stored this in our linked list structure. */
2280 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2281 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
2283 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2285 return (apuinfo_list_length ()
2286 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
2289 /* Finally we can generate the output section. */
2292 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
2297 unsigned num_entries
;
2298 bfd_size_type length
;
2300 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2304 if (apuinfo_list_length () == 0)
2307 length
= asec
->size
;
2311 buffer
= bfd_malloc (length
);
2314 (*_bfd_error_handler
)
2315 (_("failed to allocate space for new APUinfo section."));
2319 /* Create the apuinfo header. */
2320 num_entries
= apuinfo_list_length ();
2321 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
2322 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
2323 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
2324 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
2327 for (i
= 0; i
< num_entries
; i
++)
2329 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
2333 if (length
!= asec
->size
)
2334 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
2336 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
2337 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
2341 apuinfo_list_finish ();
2345 is_nonpic_glink_stub (bfd
*abfd
, asection
*glink
, bfd_vma off
)
2347 bfd_byte buf
[GLINK_ENTRY_SIZE
];
2349 if (!bfd_get_section_contents (abfd
, glink
, buf
, off
, GLINK_ENTRY_SIZE
))
2352 return ((bfd_get_32 (abfd
, buf
+ 0) & 0xffff0000) == LIS_11
2353 && (bfd_get_32 (abfd
, buf
+ 4) & 0xffff0000) == LWZ_11_11
2354 && bfd_get_32 (abfd
, buf
+ 8) == MTCTR_11
2355 && bfd_get_32 (abfd
, buf
+ 12) == BCTR
);
2359 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2361 bfd_vma vma
= *(bfd_vma
*) ptr
;
2362 return ((section
->flags
& SEC_ALLOC
) != 0
2363 && section
->vma
<= vma
2364 && vma
< section
->vma
+ section
->size
);
2368 ppc_elf_get_synthetic_symtab (bfd
*abfd
, long symcount
, asymbol
**syms
,
2369 long dynsymcount
, asymbol
**dynsyms
,
2372 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2373 asection
*plt
, *relplt
, *dynamic
, *glink
;
2374 bfd_vma glink_vma
= 0;
2375 bfd_vma resolv_vma
= 0;
2386 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
2389 if (dynsymcount
<= 0)
2392 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2396 plt
= bfd_get_section_by_name (abfd
, ".plt");
2400 /* Call common code to handle old-style executable PLTs. */
2401 if (elf_section_flags (plt
) & SHF_EXECINSTR
)
2402 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
2403 dynsymcount
, dynsyms
, ret
);
2405 /* If this object was prelinked, the prelinker stored the address
2406 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
2407 dynamic
= bfd_get_section_by_name (abfd
, ".dynamic");
2408 if (dynamic
!= NULL
)
2410 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2412 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2414 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2417 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2418 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2421 extdynend
= extdyn
+ dynamic
->size
;
2422 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2424 Elf_Internal_Dyn dyn
;
2425 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2427 if (dyn
.d_tag
== DT_NULL
)
2430 if (dyn
.d_tag
== DT_PPC_GOT
)
2432 unsigned int g_o_t
= dyn
.d_un
.d_val
;
2433 asection
*got
= bfd_get_section_by_name (abfd
, ".got");
2435 && bfd_get_section_contents (abfd
, got
, buf
,
2436 g_o_t
- got
->vma
+ 4, 4))
2437 glink_vma
= bfd_get_32 (abfd
, buf
);
2444 /* Otherwise we read the first plt entry. */
2447 if (bfd_get_section_contents (abfd
, plt
, buf
, 0, 4))
2448 glink_vma
= bfd_get_32 (abfd
, buf
);
2454 /* The .glink section usually does not survive the final
2455 link; search for the section (usually .text) where the
2456 glink stubs now reside. */
2457 glink
= bfd_sections_find_if (abfd
, section_covers_vma
, &glink_vma
);
2461 /* Determine glink PLT resolver by reading the relative branch
2462 from the first glink stub. */
2463 if (bfd_get_section_contents (abfd
, glink
, buf
,
2464 glink_vma
- glink
->vma
, 4))
2466 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2468 /* The first glink stub may either branch to the resolver ... */
2470 if ((insn
& ~0x3fffffc) == 0)
2471 resolv_vma
= glink_vma
+ (insn
^ 0x2000000) - 0x2000000;
2473 /* ... or fall through a bunch of NOPs. */
2474 else if ((insn
^ B
^ NOP
) == 0)
2476 bfd_get_section_contents (abfd
, glink
, buf
,
2477 glink_vma
- glink
->vma
+ i
, 4);
2479 if (bfd_get_32 (abfd
, buf
) != NOP
)
2481 resolv_vma
= glink_vma
+ i
;
2486 count
= relplt
->size
/ sizeof (Elf32_External_Rela
);
2487 stub_vma
= glink_vma
- (bfd_vma
) count
* 16;
2488 /* If the stubs are those for -shared/-pie then we might have
2489 multiple stubs for each plt entry. If that is the case then
2490 there is no way to associate stubs with their plt entries short
2491 of figuring out the GOT pointer value used in the stub. */
2492 if (!is_nonpic_glink_stub (abfd
, glink
,
2493 glink_vma
- GLINK_ENTRY_SIZE
- glink
->vma
))
2496 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2497 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
2500 size
= count
* sizeof (asymbol
);
2501 p
= relplt
->relocation
;
2502 for (i
= 0; i
< count
; i
++, p
++)
2504 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2506 size
+= sizeof ("+0x") - 1 + 8;
2509 size
+= sizeof (asymbol
) + sizeof ("__glink");
2512 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2514 s
= *ret
= bfd_malloc (size
);
2518 names
= (char *) (s
+ count
+ 1 + (resolv_vma
!= 0));
2519 p
= relplt
->relocation
;
2520 for (i
= 0; i
< count
; i
++, p
++)
2524 *s
= **p
->sym_ptr_ptr
;
2525 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2526 we are defining a symbol, ensure one of them is set. */
2527 if ((s
->flags
& BSF_LOCAL
) == 0)
2528 s
->flags
|= BSF_GLOBAL
;
2529 s
->flags
|= BSF_SYNTHETIC
;
2531 s
->value
= stub_vma
- glink
->vma
;
2534 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2535 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2539 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2540 names
+= sizeof ("+0x") - 1;
2541 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2542 names
+= strlen (names
);
2544 memcpy (names
, "@plt", sizeof ("@plt"));
2545 names
+= sizeof ("@plt");
2550 /* Add a symbol at the start of the glink branch table. */
2551 memset (s
, 0, sizeof *s
);
2553 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2555 s
->value
= glink_vma
- glink
->vma
;
2557 memcpy (names
, "__glink", sizeof ("__glink"));
2558 names
+= sizeof ("__glink");
2564 /* Add a symbol for the glink PLT resolver. */
2565 memset (s
, 0, sizeof *s
);
2567 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2569 s
->value
= resolv_vma
- glink
->vma
;
2571 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2572 names
+= sizeof ("__glink_PLTresolve");
2580 /* The following functions are specific to the ELF linker, while
2581 functions above are used generally. They appear in this file more
2582 or less in the order in which they are called. eg.
2583 ppc_elf_check_relocs is called early in the link process,
2584 ppc_elf_finish_dynamic_sections is one of the last functions
2587 /* The PPC linker needs to keep track of the number of relocs that it
2588 decides to copy as dynamic relocs in check_relocs for each symbol.
2589 This is so that it can later discard them if they are found to be
2590 unnecessary. We store the information in a field extending the
2591 regular ELF linker hash table. */
2593 struct ppc_elf_dyn_relocs
2595 struct ppc_elf_dyn_relocs
*next
;
2597 /* The input section of the reloc. */
2600 /* Total number of relocs copied for the input section. */
2601 bfd_size_type count
;
2603 /* Number of pc-relative relocs copied for the input section. */
2604 bfd_size_type pc_count
;
2607 /* Track PLT entries needed for a given symbol. We might need more
2608 than one glink entry per symbol. */
2611 struct plt_entry
*next
;
2613 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2614 This field stores the offset into .got2 used to initialise the
2615 GOT pointer reg. It will always be at least 32768 (and for
2616 current gcc this is the only offset used). */
2619 /* The .got2 section. */
2622 /* PLT refcount or offset. */
2625 bfd_signed_vma refcount
;
2629 /* .glink stub offset. */
2630 bfd_vma glink_offset
;
2633 /* Of those relocs that might be copied as dynamic relocs, this function
2634 selects those that must be copied when linking a shared library,
2635 even when the symbol is local. */
2638 must_be_dyn_reloc (struct bfd_link_info
*info
,
2639 enum elf_ppc_reloc_type r_type
)
2648 case R_PPC_REL14_BRTAKEN
:
2649 case R_PPC_REL14_BRNTAKEN
:
2655 case R_PPC_TPREL16_LO
:
2656 case R_PPC_TPREL16_HI
:
2657 case R_PPC_TPREL16_HA
:
2658 return !info
->executable
;
2662 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2663 copying dynamic variables from a shared lib into an app's dynbss
2664 section, and instead use a dynamic relocation to point into the
2666 #define ELIMINATE_COPY_RELOCS 1
2668 /* PPC ELF linker hash entry. */
2670 struct ppc_elf_link_hash_entry
2672 struct elf_link_hash_entry elf
;
2674 /* If this symbol is used in the linker created sections, the processor
2675 specific backend uses this field to map the field into the offset
2676 from the beginning of the section. */
2677 elf_linker_section_pointers_t
*linker_section_pointer
;
2679 /* Track dynamic relocs copied for this symbol. */
2680 struct ppc_elf_dyn_relocs
*dyn_relocs
;
2682 /* Contexts in which symbol is used in the GOT (or TOC).
2683 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2684 corresponding relocs are encountered during check_relocs.
2685 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2686 indicate the corresponding GOT entry type is not needed. */
2687 #define TLS_GD 1 /* GD reloc. */
2688 #define TLS_LD 2 /* LD reloc. */
2689 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2690 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2691 #define TLS_TLS 16 /* Any TLS reloc. */
2692 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2693 #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
2696 /* Nonzero if we have seen a small data relocation referring to this
2698 unsigned char has_sda_refs
;
2701 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2703 /* PPC ELF linker hash table. */
2705 struct ppc_elf_link_hash_table
2707 struct elf_link_hash_table elf
;
2709 /* Short-cuts to get to dynamic linker sections. */
2721 elf_linker_section_t sdata
[2];
2724 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2727 /* The .got.plt section (VxWorks only)*/
2730 /* Shortcut to __tls_get_addr. */
2731 struct elf_link_hash_entry
*tls_get_addr
;
2733 /* The bfd that forced an old-style PLT. */
2736 /* TLS local dynamic got entry handling. */
2738 bfd_signed_vma refcount
;
2742 /* Offset of branch table to PltResolve function in glink. */
2743 bfd_vma glink_pltresolve
;
2745 /* Size of reserved GOT entries. */
2746 unsigned int got_header_size
;
2747 /* Non-zero if allocating the header left a gap. */
2748 unsigned int got_gap
;
2750 /* The type of PLT we have chosen to use. */
2751 enum ppc_elf_plt_type plt_type
;
2753 /* Set if we should emit symbols for stubs. */
2754 unsigned int emit_stub_syms
:1;
2756 /* True if the target system is VxWorks. */
2757 unsigned int is_vxworks
:1;
2759 /* The size of PLT entries. */
2761 /* The distance between adjacent PLT slots. */
2763 /* The size of the first PLT entry. */
2764 int plt_initial_entry_size
;
2766 /* Small local sym cache. */
2767 struct sym_cache sym_cache
;
2770 /* Get the PPC ELF linker hash table from a link_info structure. */
2772 #define ppc_elf_hash_table(p) \
2773 ((struct ppc_elf_link_hash_table *) (p)->hash)
2775 /* Create an entry in a PPC ELF linker hash table. */
2777 static struct bfd_hash_entry
*
2778 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2779 struct bfd_hash_table
*table
,
2782 /* Allocate the structure if it has not already been allocated by a
2786 entry
= bfd_hash_allocate (table
,
2787 sizeof (struct ppc_elf_link_hash_entry
));
2792 /* Call the allocation method of the superclass. */
2793 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2796 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2797 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
2798 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2804 /* Create a PPC ELF linker hash table. */
2806 static struct bfd_link_hash_table
*
2807 ppc_elf_link_hash_table_create (bfd
*abfd
)
2809 struct ppc_elf_link_hash_table
*ret
;
2811 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2815 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2816 ppc_elf_link_hash_newfunc
,
2817 sizeof (struct ppc_elf_link_hash_entry
)))
2823 ret
->elf
.init_plt_refcount
.refcount
= 0;
2824 ret
->elf
.init_plt_refcount
.glist
= NULL
;
2825 ret
->elf
.init_plt_offset
.offset
= 0;
2826 ret
->elf
.init_plt_offset
.glist
= NULL
;
2828 ret
->sdata
[0].name
= ".sdata";
2829 ret
->sdata
[0].sym_name
= "_SDA_BASE_";
2830 ret
->sdata
[0].bss_name
= ".sbss";
2832 ret
->sdata
[1].name
= ".sdata2";
2833 ret
->sdata
[1].sym_name
= "_SDA2_BASE_";
2834 ret
->sdata
[1].bss_name
= ".sbss2";
2836 ret
->plt_entry_size
= 12;
2837 ret
->plt_slot_size
= 8;
2838 ret
->plt_initial_entry_size
= 72;
2840 return &ret
->elf
.root
;
2843 /* Create .got and the related sections. */
2846 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2848 struct ppc_elf_link_hash_table
*htab
;
2852 if (!_bfd_elf_create_got_section (abfd
, info
))
2855 htab
= ppc_elf_hash_table (info
);
2856 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2860 if (htab
->is_vxworks
)
2862 htab
->sgotplt
= bfd_get_section_by_name (abfd
, ".got.plt");
2868 /* The powerpc .got has a blrl instruction in it. Mark it
2870 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
2871 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2872 if (!bfd_set_section_flags (abfd
, s
, flags
))
2876 htab
->relgot
= bfd_get_section_by_name (abfd
, ".rela.got");
2884 ppc_elf_create_glink (bfd
*abfd
, struct bfd_link_info
*info
)
2886 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2890 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
| SEC_HAS_CONTENTS
2891 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2892 s
= bfd_make_section_anyway_with_flags (abfd
, ".glink", flags
);
2895 || !bfd_set_section_alignment (abfd
, s
, 4))
2898 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
2899 s
= bfd_make_section_anyway_with_flags (abfd
, ".iplt", flags
);
2902 || !bfd_set_section_alignment (abfd
, s
, 4))
2905 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2906 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2907 s
= bfd_make_section_with_flags (abfd
, ".rela.iplt", flags
);
2910 || ! bfd_set_section_alignment (abfd
, s
, 2))
2915 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2916 to output sections (just like _bfd_elf_create_dynamic_sections has
2917 to create .dynbss and .rela.bss). */
2920 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2922 struct ppc_elf_link_hash_table
*htab
;
2926 htab
= ppc_elf_hash_table (info
);
2928 if (htab
->got
== NULL
2929 && !ppc_elf_create_got (abfd
, info
))
2932 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2935 if (htab
->glink
== NULL
2936 && !ppc_elf_create_glink (abfd
, info
))
2939 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2940 s
= bfd_make_section_with_flags (abfd
, ".dynsbss",
2941 SEC_ALLOC
| SEC_LINKER_CREATED
);
2948 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2949 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2950 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2951 s
= bfd_make_section_with_flags (abfd
, ".rela.sbss", flags
);
2954 || ! bfd_set_section_alignment (abfd
, s
, 2))
2958 if (htab
->is_vxworks
2959 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
2962 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2963 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2967 flags
= SEC_ALLOC
| SEC_CODE
| SEC_LINKER_CREATED
;
2968 if (htab
->plt_type
== PLT_VXWORKS
)
2969 /* The VxWorks PLT is a loaded section with contents. */
2970 flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_READONLY
;
2971 return bfd_set_section_flags (abfd
, s
, flags
);
2974 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2977 ppc_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2978 struct elf_link_hash_entry
*dir
,
2979 struct elf_link_hash_entry
*ind
)
2981 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2983 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2984 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
2986 if (eind
->dyn_relocs
!= NULL
)
2988 if (edir
->dyn_relocs
!= NULL
)
2990 struct ppc_elf_dyn_relocs
**pp
;
2991 struct ppc_elf_dyn_relocs
*p
;
2993 /* Add reloc counts against the indirect sym to the direct sym
2994 list. Merge any entries against the same section. */
2995 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2997 struct ppc_elf_dyn_relocs
*q
;
2999 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3000 if (q
->sec
== p
->sec
)
3002 q
->pc_count
+= p
->pc_count
;
3003 q
->count
+= p
->count
;
3010 *pp
= edir
->dyn_relocs
;
3013 edir
->dyn_relocs
= eind
->dyn_relocs
;
3014 eind
->dyn_relocs
= NULL
;
3017 edir
->tls_mask
|= eind
->tls_mask
;
3018 edir
->has_sda_refs
|= eind
->has_sda_refs
;
3020 /* If called to transfer flags for a weakdef during processing
3021 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3022 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3023 if (!(ELIMINATE_COPY_RELOCS
3024 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3025 && edir
->elf
.dynamic_adjusted
))
3026 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3028 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3029 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3030 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3031 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3032 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3034 /* If we were called to copy over info for a weak sym, that's all. */
3035 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3038 /* Copy over the GOT refcount entries that we may have already seen to
3039 the symbol which just became indirect. */
3040 edir
->elf
.got
.refcount
+= eind
->elf
.got
.refcount
;
3041 eind
->elf
.got
.refcount
= 0;
3043 /* And plt entries. */
3044 if (eind
->elf
.plt
.plist
!= NULL
)
3046 if (edir
->elf
.plt
.plist
!= NULL
)
3048 struct plt_entry
**entp
;
3049 struct plt_entry
*ent
;
3051 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3053 struct plt_entry
*dent
;
3055 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3056 if (dent
->sec
== ent
->sec
&& dent
->addend
== ent
->addend
)
3058 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3065 *entp
= edir
->elf
.plt
.plist
;
3068 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3069 eind
->elf
.plt
.plist
= NULL
;
3072 if (eind
->elf
.dynindx
!= -1)
3074 if (edir
->elf
.dynindx
!= -1)
3075 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3076 edir
->elf
.dynstr_index
);
3077 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3078 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3079 eind
->elf
.dynindx
= -1;
3080 eind
->elf
.dynstr_index
= 0;
3084 /* Hook called by the linker routine which adds symbols from an object
3085 file. We use it to put .comm items in .sbss, and not .bss. */
3088 ppc_elf_add_symbol_hook (bfd
*abfd
,
3089 struct bfd_link_info
*info
,
3090 Elf_Internal_Sym
*sym
,
3091 const char **namep ATTRIBUTE_UNUSED
,
3092 flagword
*flagsp ATTRIBUTE_UNUSED
,
3096 if (sym
->st_shndx
== SHN_COMMON
3097 && !info
->relocatable
3098 && is_ppc_elf (info
->output_bfd
)
3099 && sym
->st_size
<= elf_gp_size (abfd
))
3101 /* Common symbols less than or equal to -G nn bytes are automatically
3103 struct ppc_elf_link_hash_table
*htab
;
3105 htab
= ppc_elf_hash_table (info
);
3106 if (htab
->sbss
== NULL
)
3108 flagword flags
= SEC_IS_COMMON
| SEC_LINKER_CREATED
;
3110 if (!htab
->elf
.dynobj
)
3111 htab
->elf
.dynobj
= abfd
;
3113 htab
->sbss
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3116 if (htab
->sbss
== NULL
)
3121 *valp
= sym
->st_size
;
3124 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3125 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
3131 create_sdata_sym (struct ppc_elf_link_hash_table
*htab
,
3132 elf_linker_section_t
*lsect
)
3134 lsect
->sym
= elf_link_hash_lookup (&htab
->elf
, lsect
->sym_name
,
3136 if (lsect
->sym
== NULL
)
3138 if (lsect
->sym
->root
.type
== bfd_link_hash_new
)
3139 lsect
->sym
->non_elf
= 0;
3140 lsect
->sym
->ref_regular
= 1;
3144 /* Create a special linker section. */
3147 ppc_elf_create_linker_section (bfd
*abfd
,
3148 struct bfd_link_info
*info
,
3150 elf_linker_section_t
*lsect
)
3152 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
3155 flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3156 | SEC_LINKER_CREATED
);
3158 /* Record the first bfd that needs the special sections. */
3159 if (!htab
->elf
.dynobj
)
3160 htab
->elf
.dynobj
= abfd
;
3162 s
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3166 || !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
3170 return create_sdata_sym (htab
, lsect
);
3173 /* Find a linker generated pointer with a given addend and type. */
3175 static elf_linker_section_pointers_t
*
3176 elf_find_pointer_linker_section
3177 (elf_linker_section_pointers_t
*linker_pointers
,
3179 elf_linker_section_t
*lsect
)
3181 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
3182 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
3183 return linker_pointers
;
3188 /* Allocate a pointer to live in a linker created section. */
3191 elf_create_pointer_linker_section (bfd
*abfd
,
3192 elf_linker_section_t
*lsect
,
3193 struct elf_link_hash_entry
*h
,
3194 const Elf_Internal_Rela
*rel
)
3196 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
3197 elf_linker_section_pointers_t
*linker_section_ptr
;
3198 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
3201 BFD_ASSERT (lsect
!= NULL
);
3203 /* Is this a global symbol? */
3206 struct ppc_elf_link_hash_entry
*eh
;
3208 /* Has this symbol already been allocated? If so, our work is done. */
3209 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3210 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
3215 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
3219 BFD_ASSERT (is_ppc_elf (abfd
));
3221 /* Allocation of a pointer to a local symbol. */
3222 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
3224 /* Allocate a table to hold the local symbols if first time. */
3227 unsigned int num_symbols
= elf_symtab_hdr (abfd
).sh_info
;
3230 amt
*= sizeof (elf_linker_section_pointers_t
*);
3231 ptr
= bfd_zalloc (abfd
, amt
);
3236 elf_local_ptr_offsets (abfd
) = ptr
;
3239 /* Has this symbol already been allocated? If so, our work is done. */
3240 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
3245 ptr_linker_section_ptr
= &ptr
[r_symndx
];
3248 /* Allocate space for a pointer in the linker section, and allocate
3249 a new pointer record from internal memory. */
3250 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
3251 amt
= sizeof (elf_linker_section_pointers_t
);
3252 linker_section_ptr
= bfd_alloc (abfd
, amt
);
3254 if (!linker_section_ptr
)
3257 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
3258 linker_section_ptr
->addend
= rel
->r_addend
;
3259 linker_section_ptr
->lsect
= lsect
;
3260 *ptr_linker_section_ptr
= linker_section_ptr
;
3262 linker_section_ptr
->offset
= lsect
->section
->size
;
3263 lsect
->section
->size
+= 4;
3267 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
3268 lsect
->name
, (long) linker_section_ptr
->offset
,
3269 (long) lsect
->section
->size
);
3275 static struct plt_entry
**
3276 update_local_sym_info (bfd
*abfd
,
3277 Elf_Internal_Shdr
*symtab_hdr
,
3278 unsigned long r_symndx
,
3281 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3282 struct plt_entry
**local_plt
;
3283 char *local_got_tls_masks
;
3285 if (local_got_refcounts
== NULL
)
3287 bfd_size_type size
= symtab_hdr
->sh_info
;
3289 size
*= (sizeof (*local_got_refcounts
)
3290 + sizeof (*local_plt
)
3291 + sizeof (*local_got_tls_masks
));
3292 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3293 if (local_got_refcounts
== NULL
)
3295 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3298 local_plt
= (struct plt_entry
**) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3299 local_got_tls_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
3300 local_got_tls_masks
[r_symndx
] |= tls_type
;
3301 if (tls_type
!= PLT_IFUNC
)
3302 local_got_refcounts
[r_symndx
] += 1;
3303 return local_plt
+ r_symndx
;
3307 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
,
3308 asection
*sec
, bfd_vma addend
)
3310 struct plt_entry
*ent
;
3312 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3313 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3317 bfd_size_type amt
= sizeof (*ent
);
3318 ent
= bfd_alloc (abfd
, amt
);
3323 ent
->addend
= addend
;
3324 ent
->plt
.refcount
= 0;
3327 ent
->plt
.refcount
+= 1;
3331 static struct plt_entry
*
3332 find_plt_ent (struct plt_entry
**plist
, asection
*sec
, bfd_vma addend
)
3334 struct plt_entry
*ent
;
3338 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3339 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3345 is_branch_reloc (enum elf_ppc_reloc_type r_type
)
3347 return (r_type
== R_PPC_PLTREL24
3348 || r_type
== R_PPC_LOCAL24PC
3349 || r_type
== R_PPC_REL24
3350 || r_type
== R_PPC_REL14
3351 || r_type
== R_PPC_REL14_BRTAKEN
3352 || r_type
== R_PPC_REL14_BRNTAKEN
3353 || r_type
== R_PPC_ADDR24
3354 || r_type
== R_PPC_ADDR14
3355 || r_type
== R_PPC_ADDR14_BRTAKEN
3356 || r_type
== R_PPC_ADDR14_BRNTAKEN
);
3360 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3362 (*_bfd_error_handler
)
3363 (_("%B: relocation %s cannot be used when making a shared object"),
3365 ppc_elf_howto_table
[r_type
]->name
);
3366 bfd_set_error (bfd_error_bad_value
);
3369 /* Look through the relocs for a section during the first phase, and
3370 allocate space in the global offset table or procedure linkage
3374 ppc_elf_check_relocs (bfd
*abfd
,
3375 struct bfd_link_info
*info
,
3377 const Elf_Internal_Rela
*relocs
)
3379 struct ppc_elf_link_hash_table
*htab
;
3380 Elf_Internal_Shdr
*symtab_hdr
;
3381 struct elf_link_hash_entry
**sym_hashes
;
3382 const Elf_Internal_Rela
*rel
;
3383 const Elf_Internal_Rela
*rel_end
;
3384 asection
*got2
, *sreloc
;
3385 struct elf_link_hash_entry
*tga
;
3387 if (info
->relocatable
)
3390 /* Don't do anything special with non-loaded, non-alloced sections.
3391 In particular, any relocs in such sections should not affect GOT
3392 and PLT reference counting (ie. we don't allow them to create GOT
3393 or PLT entries), there's no possibility or desire to optimize TLS
3394 relocs, and there's not much point in propagating relocs to shared
3395 libs that the dynamic linker won't relocate. */
3396 if ((sec
->flags
& SEC_ALLOC
) == 0)
3400 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3404 BFD_ASSERT (is_ppc_elf (abfd
));
3406 /* Initialize howto table if not already done. */
3407 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3408 ppc_elf_howto_init ();
3410 htab
= ppc_elf_hash_table (info
);
3411 if (htab
->glink
== NULL
)
3413 if (htab
->elf
.dynobj
== NULL
)
3414 htab
->elf
.dynobj
= abfd
;
3415 if (!ppc_elf_create_glink (htab
->elf
.dynobj
, info
))
3418 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3419 FALSE
, FALSE
, TRUE
);
3420 symtab_hdr
= &elf_symtab_hdr (abfd
);
3421 sym_hashes
= elf_sym_hashes (abfd
);
3422 got2
= bfd_get_section_by_name (abfd
, ".got2");
3425 rel_end
= relocs
+ sec
->reloc_count
;
3426 for (rel
= relocs
; rel
< rel_end
; rel
++)
3428 unsigned long r_symndx
;
3429 enum elf_ppc_reloc_type r_type
;
3430 struct elf_link_hash_entry
*h
;
3432 struct plt_entry
**ifunc
;
3434 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3435 if (r_symndx
< symtab_hdr
->sh_info
)
3439 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3440 while (h
->root
.type
== bfd_link_hash_indirect
3441 || h
->root
.type
== bfd_link_hash_warning
)
3442 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3445 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3446 This shows up in particular in an R_PPC_ADDR32 in the eabi
3449 && htab
->got
== NULL
3450 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3452 if (htab
->elf
.dynobj
== NULL
)
3453 htab
->elf
.dynobj
= abfd
;
3454 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3456 BFD_ASSERT (h
== htab
->elf
.hgot
);
3461 if (!htab
->is_vxworks
)
3465 if (h
->type
== STT_GNU_IFUNC
)
3468 ifunc
= &h
->plt
.plist
;
3473 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3478 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
3480 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3488 r_type
= ELF32_R_TYPE (rel
->r_info
);
3489 if (!htab
->is_vxworks
&& is_branch_reloc (r_type
))
3491 if (h
!= NULL
&& h
== tga
)
3494 && (ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSGD
3495 || ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSLD
))
3496 /* We have a new-style __tls_get_addr call with a marker
3500 /* Mark this section as having an old-style call. */
3501 sec
->has_tls_get_addr_call
= 1;
3504 /* STT_GNU_IFUNC symbols must have a PLT entry. */
3509 if (r_type
== R_PPC_PLTREL24
)
3511 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3512 addend
= rel
->r_addend
;
3514 if (!update_plt_info (abfd
, ifunc
,
3515 addend
< 32768 ? NULL
: got2
, addend
))
3524 /* These special tls relocs tie a call to __tls_get_addr with
3525 its parameter symbol. */
3528 case R_PPC_GOT_TLSLD16
:
3529 case R_PPC_GOT_TLSLD16_LO
:
3530 case R_PPC_GOT_TLSLD16_HI
:
3531 case R_PPC_GOT_TLSLD16_HA
:
3532 tls_type
= TLS_TLS
| TLS_LD
;
3535 case R_PPC_GOT_TLSGD16
:
3536 case R_PPC_GOT_TLSGD16_LO
:
3537 case R_PPC_GOT_TLSGD16_HI
:
3538 case R_PPC_GOT_TLSGD16_HA
:
3539 tls_type
= TLS_TLS
| TLS_GD
;
3542 case R_PPC_GOT_TPREL16
:
3543 case R_PPC_GOT_TPREL16_LO
:
3544 case R_PPC_GOT_TPREL16_HI
:
3545 case R_PPC_GOT_TPREL16_HA
:
3546 if (!info
->executable
)
3547 info
->flags
|= DF_STATIC_TLS
;
3548 tls_type
= TLS_TLS
| TLS_TPREL
;
3551 case R_PPC_GOT_DTPREL16
:
3552 case R_PPC_GOT_DTPREL16_LO
:
3553 case R_PPC_GOT_DTPREL16_HI
:
3554 case R_PPC_GOT_DTPREL16_HA
:
3555 tls_type
= TLS_TLS
| TLS_DTPREL
;
3557 sec
->has_tls_reloc
= 1;
3560 /* GOT16 relocations */
3562 case R_PPC_GOT16_LO
:
3563 case R_PPC_GOT16_HI
:
3564 case R_PPC_GOT16_HA
:
3565 /* This symbol requires a global offset table entry. */
3566 if (htab
->got
== NULL
)
3568 if (htab
->elf
.dynobj
== NULL
)
3569 htab
->elf
.dynobj
= abfd
;
3570 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3575 h
->got
.refcount
+= 1;
3576 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3579 /* This is a global offset table entry for a local symbol. */
3580 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3584 /* Indirect .sdata relocation. */
3585 case R_PPC_EMB_SDAI16
:
3588 bad_shared_reloc (abfd
, r_type
);
3591 if (htab
->sdata
[0].section
== NULL
3592 && !ppc_elf_create_linker_section (abfd
, info
, 0,
3595 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[0],
3600 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3601 h
->non_got_ref
= TRUE
;
3605 /* Indirect .sdata2 relocation. */
3606 case R_PPC_EMB_SDA2I16
:
3609 bad_shared_reloc (abfd
, r_type
);
3612 if (htab
->sdata
[1].section
== NULL
3613 && !ppc_elf_create_linker_section (abfd
, info
, SEC_READONLY
,
3616 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[1],
3621 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3622 h
->non_got_ref
= TRUE
;
3626 case R_PPC_SDAREL16
:
3629 bad_shared_reloc (abfd
, r_type
);
3632 if (htab
->sdata
[0].sym
== NULL
3633 && !create_sdata_sym (htab
, &htab
->sdata
[0]))
3637 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3638 h
->non_got_ref
= TRUE
;
3642 case R_PPC_EMB_SDA2REL
:
3645 bad_shared_reloc (abfd
, r_type
);
3648 if (htab
->sdata
[1].sym
== NULL
3649 && !create_sdata_sym (htab
, &htab
->sdata
[1]))
3653 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3654 h
->non_got_ref
= TRUE
;
3658 case R_PPC_EMB_SDA21
:
3659 case R_PPC_EMB_RELSDA
:
3662 bad_shared_reloc (abfd
, r_type
);
3665 if (htab
->sdata
[0].sym
== NULL
3666 && !create_sdata_sym (htab
, &htab
->sdata
[0]))
3668 if (htab
->sdata
[1].sym
== NULL
3669 && !create_sdata_sym (htab
, &htab
->sdata
[1]))
3673 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3674 h
->non_got_ref
= TRUE
;
3678 case R_PPC_EMB_NADDR32
:
3679 case R_PPC_EMB_NADDR16
:
3680 case R_PPC_EMB_NADDR16_LO
:
3681 case R_PPC_EMB_NADDR16_HI
:
3682 case R_PPC_EMB_NADDR16_HA
:
3685 bad_shared_reloc (abfd
, r_type
);
3689 h
->non_got_ref
= TRUE
;
3692 case R_PPC_PLTREL24
:
3693 if (h
== NULL
|| ifunc
!= NULL
)
3697 case R_PPC_PLTREL32
:
3698 case R_PPC_PLT16_LO
:
3699 case R_PPC_PLT16_HI
:
3700 case R_PPC_PLT16_HA
:
3702 fprintf (stderr
, "Reloc requires a PLT entry\n");
3704 /* This symbol requires a procedure linkage table entry. We
3705 actually build the entry in finish_dynamic_symbol,
3706 because this might be a case of linking PIC code without
3707 linking in any dynamic objects, in which case we don't
3708 need to generate a procedure linkage table after all. */
3712 /* It does not make sense to have a procedure linkage
3713 table entry for a local symbol. */
3714 (*_bfd_error_handler
) (_("%B(%A+0x%lx): %s reloc against "
3718 (long) rel
->r_offset
,
3719 ppc_elf_howto_table
[r_type
]->name
);
3720 bfd_set_error (bfd_error_bad_value
);
3727 if (r_type
== R_PPC_PLTREL24
)
3729 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3730 addend
= rel
->r_addend
;
3733 if (!update_plt_info (abfd
, &h
->plt
.plist
,
3734 addend
< 32768 ? NULL
: got2
, addend
))
3739 /* The following relocations don't need to propagate the
3740 relocation if linking a shared object since they are
3741 section relative. */
3743 case R_PPC_SECTOFF_LO
:
3744 case R_PPC_SECTOFF_HI
:
3745 case R_PPC_SECTOFF_HA
:
3746 case R_PPC_DTPREL16
:
3747 case R_PPC_DTPREL16_LO
:
3748 case R_PPC_DTPREL16_HI
:
3749 case R_PPC_DTPREL16_HA
:
3754 case R_PPC_REL16_LO
:
3755 case R_PPC_REL16_HI
:
3756 case R_PPC_REL16_HA
:
3757 ppc_elf_tdata (abfd
)->has_rel16
= 1;
3760 /* These are just markers. */
3762 case R_PPC_EMB_MRKREF
:
3766 case R_PPC_RELAX32PC
:
3767 case R_PPC_RELAX32_PLT
:
3768 case R_PPC_RELAX32PC_PLT
:
3771 /* These should only appear in dynamic objects. */
3773 case R_PPC_GLOB_DAT
:
3774 case R_PPC_JMP_SLOT
:
3775 case R_PPC_RELATIVE
:
3776 case R_PPC_IRELATIVE
:
3779 /* These aren't handled yet. We'll report an error later. */
3781 case R_PPC_EMB_RELSEC16
:
3782 case R_PPC_EMB_RELST_LO
:
3783 case R_PPC_EMB_RELST_HI
:
3784 case R_PPC_EMB_RELST_HA
:
3785 case R_PPC_EMB_BIT_FLD
:
3788 /* This refers only to functions defined in the shared library. */
3789 case R_PPC_LOCAL24PC
:
3790 if (h
!= NULL
&& h
== htab
->elf
.hgot
&& htab
->plt_type
== PLT_UNSET
)
3792 htab
->plt_type
= PLT_OLD
;
3793 htab
->old_bfd
= abfd
;
3797 /* This relocation describes the C++ object vtable hierarchy.
3798 Reconstruct it for later use during GC. */
3799 case R_PPC_GNU_VTINHERIT
:
3800 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3804 /* This relocation describes which C++ vtable entries are actually
3805 used. Record for later use during GC. */
3806 case R_PPC_GNU_VTENTRY
:
3807 BFD_ASSERT (h
!= NULL
);
3809 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3813 /* We shouldn't really be seeing these. */
3816 case R_PPC_TPREL16_LO
:
3817 case R_PPC_TPREL16_HI
:
3818 case R_PPC_TPREL16_HA
:
3819 if (!info
->executable
)
3820 info
->flags
|= DF_STATIC_TLS
;
3824 case R_PPC_DTPMOD32
:
3825 case R_PPC_DTPREL32
:
3831 && (sec
->flags
& SEC_CODE
) != 0
3832 && (info
->shared
|| info
->pie
)
3833 && htab
->plt_type
== PLT_UNSET
)
3835 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3836 the start of a function, which assembles to a REL32
3837 reference to .got2. If we detect one of these, then
3838 force the old PLT layout because the linker cannot
3839 reliably deduce the GOT pointer value needed for
3842 Elf_Internal_Sym
*isym
;
3844 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3849 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3852 htab
->plt_type
= PLT_OLD
;
3853 htab
->old_bfd
= abfd
;
3856 if (h
== NULL
|| h
== htab
->elf
.hgot
)
3862 case R_PPC_ADDR16_LO
:
3863 case R_PPC_ADDR16_HI
:
3864 case R_PPC_ADDR16_HA
:
3867 if (h
!= NULL
&& !info
->shared
)
3869 /* We may need a plt entry if the symbol turns out to be
3870 a function defined in a dynamic object. */
3871 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3874 /* We may need a copy reloc too. */
3876 h
->pointer_equality_needed
= 1;
3882 case R_PPC_REL14_BRTAKEN
:
3883 case R_PPC_REL14_BRNTAKEN
:
3886 if (h
== htab
->elf
.hgot
)
3888 if (htab
->plt_type
== PLT_UNSET
)
3890 htab
->plt_type
= PLT_OLD
;
3891 htab
->old_bfd
= abfd
;
3899 case R_PPC_ADDR14_BRTAKEN
:
3900 case R_PPC_ADDR14_BRNTAKEN
:
3901 if (h
!= NULL
&& !info
->shared
)
3903 /* We may need a plt entry if the symbol turns out to be
3904 a function defined in a dynamic object. */
3907 && !update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3913 /* If we are creating a shared library, and this is a reloc
3914 against a global symbol, or a non PC relative reloc
3915 against a local symbol, then we need to copy the reloc
3916 into the shared library. However, if we are linking with
3917 -Bsymbolic, we do not need to copy a reloc against a
3918 global symbol which is defined in an object we are
3919 including in the link (i.e., DEF_REGULAR is set). At
3920 this point we have not seen all the input files, so it is
3921 possible that DEF_REGULAR is not set now but will be set
3922 later (it is never cleared). In case of a weak definition,
3923 DEF_REGULAR may be cleared later by a strong definition in
3924 a shared library. We account for that possibility below by
3925 storing information in the dyn_relocs field of the hash
3926 table entry. A similar situation occurs when creating
3927 shared libraries and symbol visibility changes render the
3930 If on the other hand, we are creating an executable, we
3931 may need to keep relocations for symbols satisfied by a
3932 dynamic library if we manage to avoid copy relocs for the
3935 && (must_be_dyn_reloc (info
, r_type
)
3937 && (! info
->symbolic
3938 || h
->root
.type
== bfd_link_hash_defweak
3939 || !h
->def_regular
))))
3940 || (ELIMINATE_COPY_RELOCS
3943 && (h
->root
.type
== bfd_link_hash_defweak
3944 || !h
->def_regular
))
3948 struct ppc_elf_dyn_relocs
*p
;
3949 struct ppc_elf_dyn_relocs
**head
;
3953 "ppc_elf_check_relocs needs to "
3954 "create relocation for %s\n",
3955 (h
&& h
->root
.root
.string
3956 ? h
->root
.root
.string
: "<unknown>"));
3960 if (htab
->elf
.dynobj
== NULL
)
3961 htab
->elf
.dynobj
= abfd
;
3963 sreloc
= _bfd_elf_make_dynamic_reloc_section
3964 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3970 /* If this is a global symbol, we count the number of
3971 relocations we need for this symbol. */
3974 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3978 /* Track dynamic relocs needed for local syms too.
3979 We really need local syms available to do this
3983 Elf_Internal_Sym
*isym
;
3985 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3990 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3994 vpp
= &elf_section_data (s
)->local_dynrel
;
3995 head
= (struct ppc_elf_dyn_relocs
**) vpp
;
3999 if (p
== NULL
|| p
->sec
!= sec
)
4001 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4012 if (!must_be_dyn_reloc (info
, r_type
))
4024 /* Merge object attributes from IBFD into OBFD. Raise an error if
4025 there are conflicting attributes. */
4027 ppc_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
4029 obj_attribute
*in_attr
, *in_attrs
;
4030 obj_attribute
*out_attr
, *out_attrs
;
4032 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
4034 /* This is the first object. Copy the attributes. */
4035 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
4037 /* Use the Tag_null value to indicate the attributes have been
4039 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
4044 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
4045 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
4047 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
4048 non-conflicting ones. */
4049 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_FP
];
4050 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_FP
];
4051 if (in_attr
->i
!= out_attr
->i
)
4054 if (out_attr
->i
== 0)
4055 out_attr
->i
= in_attr
->i
;
4056 else if (in_attr
->i
== 0)
4058 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4060 (_("Warning: %B uses hard float, %B uses soft float"), obfd
, ibfd
);
4061 else if (out_attr
->i
== 1 && in_attr
->i
== 3)
4063 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4065 else if (out_attr
->i
== 3 && in_attr
->i
== 1)
4067 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4069 else if (out_attr
->i
== 3 && in_attr
->i
== 2)
4071 (_("Warning: %B uses soft float, %B uses single-precision hard float"),
4073 else if (out_attr
->i
== 2 && (in_attr
->i
== 1 || in_attr
->i
== 3))
4075 (_("Warning: %B uses hard float, %B uses soft float"), ibfd
, obfd
);
4076 else if (in_attr
->i
> 3)
4078 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
4082 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
4086 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
4087 merge non-conflicting ones. */
4088 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Vector
];
4089 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Vector
];
4090 if (in_attr
->i
!= out_attr
->i
)
4092 const char *in_abi
= NULL
, *out_abi
= NULL
;
4096 case 1: in_abi
= "generic"; break;
4097 case 2: in_abi
= "AltiVec"; break;
4098 case 3: in_abi
= "SPE"; break;
4101 switch (out_attr
->i
)
4103 case 1: out_abi
= "generic"; break;
4104 case 2: out_abi
= "AltiVec"; break;
4105 case 3: out_abi
= "SPE"; break;
4109 if (out_attr
->i
== 0)
4110 out_attr
->i
= in_attr
->i
;
4111 else if (in_attr
->i
== 0)
4113 /* For now, allow generic to transition to AltiVec or SPE
4114 without a warning. If GCC marked files with their stack
4115 alignment and used don't-care markings for files which are
4116 not affected by the vector ABI, we could warn about this
4118 else if (out_attr
->i
== 1)
4119 out_attr
->i
= in_attr
->i
;
4120 else if (in_attr
->i
== 1)
4122 else if (in_abi
== NULL
)
4124 (_("Warning: %B uses unknown vector ABI %d"), ibfd
,
4126 else if (out_abi
== NULL
)
4128 (_("Warning: %B uses unknown vector ABI %d"), obfd
,
4132 (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
4133 ibfd
, obfd
, in_abi
, out_abi
);
4136 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
4137 and merge non-conflicting ones. */
4138 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4139 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4140 if (in_attr
->i
!= out_attr
->i
)
4143 if (out_attr
->i
== 0)
4144 out_attr
->i
= in_attr
->i
;
4145 else if (in_attr
->i
== 0)
4147 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4149 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd
, ibfd
);
4150 else if (out_attr
->i
== 2 && in_attr
->i
== 1)
4152 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd
, obfd
);
4153 else if (in_attr
->i
> 2)
4155 (_("Warning: %B uses unknown small structure return convention %d"), ibfd
,
4159 (_("Warning: %B uses unknown small structure return convention %d"), obfd
,
4163 /* Merge Tag_compatibility attributes and any common GNU ones. */
4164 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
4169 /* Merge backend specific data from an object file to the output
4170 object file when linking. */
4173 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4179 if (!is_ppc_elf (ibfd
) || !is_ppc_elf (obfd
))
4182 /* Check if we have the same endianess. */
4183 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
4186 if (!ppc_elf_merge_obj_attributes (ibfd
, obfd
))
4189 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4190 old_flags
= elf_elfheader (obfd
)->e_flags
;
4191 if (!elf_flags_init (obfd
))
4193 /* First call, no flags set. */
4194 elf_flags_init (obfd
) = TRUE
;
4195 elf_elfheader (obfd
)->e_flags
= new_flags
;
4198 /* Compatible flags are ok. */
4199 else if (new_flags
== old_flags
)
4202 /* Incompatible flags. */
4205 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
4206 to be linked with either. */
4208 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
4209 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
4212 (*_bfd_error_handler
)
4213 (_("%B: compiled with -mrelocatable and linked with "
4214 "modules compiled normally"), ibfd
);
4216 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
4217 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
4220 (*_bfd_error_handler
)
4221 (_("%B: compiled normally and linked with "
4222 "modules compiled with -mrelocatable"), ibfd
);
4225 /* The output is -mrelocatable-lib iff both the input files are. */
4226 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
4227 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
4229 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
4230 but each input file is either -mrelocatable or -mrelocatable-lib. */
4231 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
4232 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
4233 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
4234 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
4236 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
4237 any module uses it. */
4238 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
4240 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4241 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4243 /* Warn about any other mismatches. */
4244 if (new_flags
!= old_flags
)
4247 (*_bfd_error_handler
)
4248 (_("%B: uses different e_flags (0x%lx) fields "
4249 "than previous modules (0x%lx)"),
4250 ibfd
, (long) new_flags
, (long) old_flags
);
4255 bfd_set_error (bfd_error_bad_value
);
4263 /* Choose which PLT scheme to use, and set .plt flags appropriately.
4264 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
4266 ppc_elf_select_plt_layout (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4267 struct bfd_link_info
*info
,
4268 enum ppc_elf_plt_type plt_style
,
4271 struct ppc_elf_link_hash_table
*htab
;
4274 htab
= ppc_elf_hash_table (info
);
4276 if (htab
->plt_type
== PLT_UNSET
)
4278 if (plt_style
== PLT_OLD
)
4279 htab
->plt_type
= PLT_OLD
;
4283 enum ppc_elf_plt_type plt_type
= plt_style
;
4285 /* Look through the reloc flags left by ppc_elf_check_relocs.
4286 Use the old style bss plt if a file makes plt calls
4287 without using the new relocs, and if ld isn't given
4288 --secure-plt and we never see REL16 relocs. */
4289 if (plt_type
== PLT_UNSET
)
4291 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
4292 if (is_ppc_elf (ibfd
))
4294 if (ppc_elf_tdata (ibfd
)->has_rel16
)
4296 else if (ppc_elf_tdata (ibfd
)->makes_plt_call
)
4299 htab
->old_bfd
= ibfd
;
4303 htab
->plt_type
= plt_type
;
4306 if (htab
->plt_type
== PLT_OLD
&& plt_style
== PLT_NEW
)
4307 info
->callbacks
->info (_("Using bss-plt due to %B"), htab
->old_bfd
);
4309 htab
->emit_stub_syms
= emit_stub_syms
;
4311 BFD_ASSERT (htab
->plt_type
!= PLT_VXWORKS
);
4313 if (htab
->plt_type
== PLT_NEW
)
4315 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4316 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4318 /* The new PLT is a loaded section. */
4319 if (htab
->plt
!= NULL
4320 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->plt
, flags
))
4323 /* The new GOT is not executable. */
4324 if (htab
->got
!= NULL
4325 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->got
, flags
))
4330 /* Stop an unused .glink section from affecting .text alignment. */
4331 if (htab
->glink
!= NULL
4332 && !bfd_set_section_alignment (htab
->elf
.dynobj
, htab
->glink
, 0))
4335 return htab
->plt_type
== PLT_NEW
;
4338 /* Return the section that should be marked against GC for a given
4342 ppc_elf_gc_mark_hook (asection
*sec
,
4343 struct bfd_link_info
*info
,
4344 Elf_Internal_Rela
*rel
,
4345 struct elf_link_hash_entry
*h
,
4346 Elf_Internal_Sym
*sym
)
4349 switch (ELF32_R_TYPE (rel
->r_info
))
4351 case R_PPC_GNU_VTINHERIT
:
4352 case R_PPC_GNU_VTENTRY
:
4356 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4359 /* Update the got, plt and dynamic reloc reference counts for the
4360 section being removed. */
4363 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4364 struct bfd_link_info
*info
,
4366 const Elf_Internal_Rela
*relocs
)
4368 struct ppc_elf_link_hash_table
*htab
;
4369 Elf_Internal_Shdr
*symtab_hdr
;
4370 struct elf_link_hash_entry
**sym_hashes
;
4371 bfd_signed_vma
*local_got_refcounts
;
4372 const Elf_Internal_Rela
*rel
, *relend
;
4375 if (info
->relocatable
)
4378 if ((sec
->flags
& SEC_ALLOC
) == 0)
4381 elf_section_data (sec
)->local_dynrel
= NULL
;
4383 htab
= ppc_elf_hash_table (info
);
4384 symtab_hdr
= &elf_symtab_hdr (abfd
);
4385 sym_hashes
= elf_sym_hashes (abfd
);
4386 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4387 got2
= bfd_get_section_by_name (abfd
, ".got2");
4389 relend
= relocs
+ sec
->reloc_count
;
4390 for (rel
= relocs
; rel
< relend
; rel
++)
4392 unsigned long r_symndx
;
4393 enum elf_ppc_reloc_type r_type
;
4394 struct elf_link_hash_entry
*h
= NULL
;
4396 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4397 if (r_symndx
>= symtab_hdr
->sh_info
)
4399 struct ppc_elf_dyn_relocs
**pp
, *p
;
4400 struct ppc_elf_link_hash_entry
*eh
;
4402 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4403 while (h
->root
.type
== bfd_link_hash_indirect
4404 || h
->root
.type
== bfd_link_hash_warning
)
4405 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4406 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4408 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4411 /* Everything must go for SEC. */
4417 r_type
= ELF32_R_TYPE (rel
->r_info
);
4418 if (!htab
->is_vxworks
&& is_branch_reloc (r_type
))
4420 struct plt_entry
**ifunc
= NULL
;
4423 if (h
->type
== STT_GNU_IFUNC
)
4424 ifunc
= &h
->plt
.plist
;
4426 else if (local_got_refcounts
!= NULL
)
4428 struct plt_entry
**local_plt
= (struct plt_entry
**)
4429 (local_got_refcounts
+ symtab_hdr
->sh_info
);
4430 char *local_got_tls_masks
= (char *)
4431 (local_plt
+ symtab_hdr
->sh_info
);
4432 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
4433 ifunc
= local_plt
+ r_symndx
;
4437 bfd_vma addend
= r_type
== R_PPC_PLTREL24
? rel
->r_addend
: 0;
4438 struct plt_entry
*ent
= find_plt_ent (ifunc
, got2
, addend
);
4439 if (ent
->plt
.refcount
> 0)
4440 ent
->plt
.refcount
-= 1;
4447 case R_PPC_GOT_TLSLD16
:
4448 case R_PPC_GOT_TLSLD16_LO
:
4449 case R_PPC_GOT_TLSLD16_HI
:
4450 case R_PPC_GOT_TLSLD16_HA
:
4451 case R_PPC_GOT_TLSGD16
:
4452 case R_PPC_GOT_TLSGD16_LO
:
4453 case R_PPC_GOT_TLSGD16_HI
:
4454 case R_PPC_GOT_TLSGD16_HA
:
4455 case R_PPC_GOT_TPREL16
:
4456 case R_PPC_GOT_TPREL16_LO
:
4457 case R_PPC_GOT_TPREL16_HI
:
4458 case R_PPC_GOT_TPREL16_HA
:
4459 case R_PPC_GOT_DTPREL16
:
4460 case R_PPC_GOT_DTPREL16_LO
:
4461 case R_PPC_GOT_DTPREL16_HI
:
4462 case R_PPC_GOT_DTPREL16_HA
:
4464 case R_PPC_GOT16_LO
:
4465 case R_PPC_GOT16_HI
:
4466 case R_PPC_GOT16_HA
:
4469 if (h
->got
.refcount
> 0)
4472 else if (local_got_refcounts
!= NULL
)
4474 if (local_got_refcounts
[r_symndx
] > 0)
4475 local_got_refcounts
[r_symndx
]--;
4481 case R_PPC_REL14_BRTAKEN
:
4482 case R_PPC_REL14_BRNTAKEN
:
4484 if (h
== NULL
|| h
== htab
->elf
.hgot
)
4491 case R_PPC_ADDR16_LO
:
4492 case R_PPC_ADDR16_HI
:
4493 case R_PPC_ADDR16_HA
:
4495 case R_PPC_ADDR14_BRTAKEN
:
4496 case R_PPC_ADDR14_BRNTAKEN
:
4503 case R_PPC_PLTREL24
:
4504 case R_PPC_PLTREL32
:
4505 case R_PPC_PLT16_LO
:
4506 case R_PPC_PLT16_HI
:
4507 case R_PPC_PLT16_HA
:
4510 bfd_vma addend
= r_type
== R_PPC_PLTREL24
? rel
->r_addend
: 0;
4511 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
,
4513 if (ent
->plt
.refcount
> 0)
4514 ent
->plt
.refcount
-= 1;
4525 /* Set plt output section type, htab->tls_get_addr, and call the
4526 generic ELF tls_setup function. */
4529 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4531 struct ppc_elf_link_hash_table
*htab
;
4533 htab
= ppc_elf_hash_table (info
);
4534 if (htab
->plt_type
== PLT_NEW
4535 && htab
->plt
!= NULL
4536 && htab
->plt
->output_section
!= NULL
)
4538 elf_section_type (htab
->plt
->output_section
) = SHT_PROGBITS
;
4539 elf_section_flags (htab
->plt
->output_section
) = SHF_ALLOC
+ SHF_WRITE
;
4542 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4543 FALSE
, FALSE
, TRUE
);
4544 return _bfd_elf_tls_setup (obfd
, info
);
4547 /* Return TRUE iff REL is a branch reloc with a global symbol matching
4551 branch_reloc_hash_match (const bfd
*ibfd
,
4552 const Elf_Internal_Rela
*rel
,
4553 const struct elf_link_hash_entry
*hash
)
4555 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4556 enum elf_ppc_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
4557 unsigned int r_symndx
= ELF32_R_SYM (rel
->r_info
);
4559 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
4561 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4562 struct elf_link_hash_entry
*h
;
4564 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4565 while (h
->root
.type
== bfd_link_hash_indirect
4566 || h
->root
.type
== bfd_link_hash_warning
)
4567 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4574 /* Run through all the TLS relocs looking for optimization
4578 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4579 struct bfd_link_info
*info
)
4583 struct ppc_elf_link_hash_table
*htab
;
4586 if (info
->relocatable
|| !info
->executable
)
4589 htab
= ppc_elf_hash_table (info
);
4590 /* Make two passes through the relocs. First time check that tls
4591 relocs involved in setting up a tls_get_addr call are indeed
4592 followed by such a call. If they are not, exclude them from
4593 the optimizations done on the second pass. */
4594 for (pass
= 0; pass
< 2; ++pass
)
4595 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4597 Elf_Internal_Sym
*locsyms
= NULL
;
4598 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4600 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4601 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4603 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4605 /* Read the relocations. */
4606 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4608 if (relstart
== NULL
)
4611 relend
= relstart
+ sec
->reloc_count
;
4612 for (rel
= relstart
; rel
< relend
; rel
++)
4614 enum elf_ppc_reloc_type r_type
;
4615 unsigned long r_symndx
;
4616 struct elf_link_hash_entry
*h
= NULL
;
4618 char tls_set
, tls_clear
;
4619 bfd_boolean is_local
;
4620 int expecting_tls_get_addr
;
4621 bfd_signed_vma
*got_count
;
4623 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4624 if (r_symndx
>= symtab_hdr
->sh_info
)
4626 struct elf_link_hash_entry
**sym_hashes
;
4628 sym_hashes
= elf_sym_hashes (ibfd
);
4629 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4630 while (h
->root
.type
== bfd_link_hash_indirect
4631 || h
->root
.type
== bfd_link_hash_warning
)
4632 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4635 expecting_tls_get_addr
= 0;
4641 r_type
= ELF32_R_TYPE (rel
->r_info
);
4644 case R_PPC_GOT_TLSLD16
:
4645 case R_PPC_GOT_TLSLD16_LO
:
4646 expecting_tls_get_addr
= 1;
4649 case R_PPC_GOT_TLSLD16_HI
:
4650 case R_PPC_GOT_TLSLD16_HA
:
4651 /* These relocs should never be against a symbol
4652 defined in a shared lib. Leave them alone if
4653 that turns out to be the case. */
4662 case R_PPC_GOT_TLSGD16
:
4663 case R_PPC_GOT_TLSGD16_LO
:
4664 expecting_tls_get_addr
= 1;
4667 case R_PPC_GOT_TLSGD16_HI
:
4668 case R_PPC_GOT_TLSGD16_HA
:
4674 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4678 case R_PPC_GOT_TPREL16
:
4679 case R_PPC_GOT_TPREL16_LO
:
4680 case R_PPC_GOT_TPREL16_HI
:
4681 case R_PPC_GOT_TPREL16_HA
:
4686 tls_clear
= TLS_TPREL
;
4698 if (!expecting_tls_get_addr
4699 || !sec
->has_tls_get_addr_call
)
4702 if (rel
+ 1 < relend
4703 && branch_reloc_hash_match (ibfd
, rel
+ 1,
4704 htab
->tls_get_addr
))
4707 /* Uh oh, we didn't find the expected call. We
4708 could just mark this symbol to exclude it
4709 from tls optimization but it's safer to skip
4710 the entire section. */
4711 sec
->has_tls_reloc
= 0;
4717 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4718 got_count
= &h
->got
.refcount
;
4722 Elf_Internal_Sym
*sym
;
4723 bfd_signed_vma
*lgot_refs
;
4724 struct plt_entry
**local_plt
;
4727 if (locsyms
== NULL
)
4729 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4730 if (locsyms
== NULL
)
4731 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4732 symtab_hdr
->sh_info
,
4733 0, NULL
, NULL
, NULL
);
4734 if (locsyms
== NULL
)
4736 if (elf_section_data (sec
)->relocs
!= relstart
)
4741 sym
= locsyms
+ r_symndx
;
4742 lgot_refs
= elf_local_got_refcounts (ibfd
);
4743 if (lgot_refs
== NULL
)
4745 local_plt
= (struct plt_entry
**)
4746 (lgot_refs
+ symtab_hdr
->sh_info
);
4747 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
4748 tls_mask
= &lgot_masks
[r_symndx
];
4749 got_count
= &lgot_refs
[r_symndx
];
4754 /* We managed to get rid of a got entry. */
4759 if (expecting_tls_get_addr
)
4761 struct plt_entry
*ent
;
4763 ent
= find_plt_ent (&htab
->tls_get_addr
->plt
.plist
,
4765 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4766 ent
->plt
.refcount
-= 1;
4769 *tls_mask
|= tls_set
;
4770 *tls_mask
&= ~tls_clear
;
4773 if (elf_section_data (sec
)->relocs
!= relstart
)
4778 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4780 if (!info
->keep_memory
)
4783 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4789 /* Return true if we have dynamic relocs that apply to read-only sections. */
4792 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
4794 struct ppc_elf_dyn_relocs
*p
;
4796 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4798 asection
*s
= p
->sec
->output_section
;
4801 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
4802 == (SEC_READONLY
| SEC_ALLOC
)))
4808 /* Adjust a symbol defined by a dynamic object and referenced by a
4809 regular object. The current definition is in some section of the
4810 dynamic object, but we're not including those sections. We have to
4811 change the definition to something the rest of the link can
4815 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4816 struct elf_link_hash_entry
*h
)
4818 struct ppc_elf_link_hash_table
*htab
;
4822 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4823 h
->root
.root
.string
);
4826 /* Make sure we know what is going on here. */
4827 htab
= ppc_elf_hash_table (info
);
4828 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
4830 || h
->u
.weakdef
!= NULL
4833 && !h
->def_regular
)));
4835 /* Deal with function syms. */
4836 if (h
->type
== STT_FUNC
4837 || h
->type
== STT_GNU_IFUNC
4840 /* Clear procedure linkage table information for any symbol that
4841 won't need a .plt entry. */
4842 struct plt_entry
*ent
;
4843 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4844 if (ent
->plt
.refcount
> 0)
4847 || (h
->type
!= STT_GNU_IFUNC
4848 && (SYMBOL_CALLS_LOCAL (info
, h
)
4849 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4850 && h
->root
.type
== bfd_link_hash_undefweak
))))
4852 /* A PLT entry is not required/allowed when:
4854 1. We are not using ld.so; because then the PLT entry
4855 can't be set up, so we can't use one. In this case,
4856 ppc_elf_adjust_dynamic_symbol won't even be called.
4858 2. GC has rendered the entry unused.
4860 3. We know for certain that a call to this symbol
4861 will go to this object, or will remain undefined. */
4862 h
->plt
.plist
= NULL
;
4867 /* After adjust_dynamic_symbol, non_got_ref set in the
4868 non-shared case means that we have allocated space in
4869 .dynbss for the symbol and thus dyn_relocs for this
4870 symbol should be discarded.
4871 If we get here we know we are making a PLT entry for this
4872 symbol, and in an executable we'd normally resolve
4873 relocations against this symbol to the PLT entry. Allow
4874 dynamic relocs if the reference is weak, and the dynamic
4875 relocs will not cause text relocation. */
4876 if (!h
->ref_regular_nonweak
4878 && h
->type
!= STT_GNU_IFUNC
4879 && !htab
->is_vxworks
4880 && !ppc_elf_hash_entry (h
)->has_sda_refs
4881 && !readonly_dynrelocs (h
))
4887 h
->plt
.plist
= NULL
;
4889 /* If this is a weak symbol, and there is a real definition, the
4890 processor independent code will have arranged for us to see the
4891 real definition first, and we can just use the same value. */
4892 if (h
->u
.weakdef
!= NULL
)
4894 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
4895 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
4896 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
4897 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
4898 if (ELIMINATE_COPY_RELOCS
)
4899 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
4903 /* This is a reference to a symbol defined by a dynamic object which
4904 is not a function. */
4906 /* If we are creating a shared library, we must presume that the
4907 only references to the symbol are via the global offset table.
4908 For such cases we need not do anything here; the relocations will
4909 be handled correctly by relocate_section. */
4913 /* If there are no references to this symbol that do not use the
4914 GOT, we don't need to generate a copy reloc. */
4915 if (!h
->non_got_ref
)
4918 /* If we didn't find any dynamic relocs in read-only sections, then
4919 we'll be keeping the dynamic relocs and avoiding the copy reloc.
4920 We can't do this if there are any small data relocations. This
4921 doesn't work on VxWorks, where we can not have dynamic
4922 relocations (other than copy and jump slot relocations) in an
4924 if (ELIMINATE_COPY_RELOCS
4925 && !ppc_elf_hash_entry (h
)->has_sda_refs
4926 && !htab
->is_vxworks
4928 && !readonly_dynrelocs (h
))
4936 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
4937 h
->root
.root
.string
);
4941 /* We must allocate the symbol in our .dynbss section, which will
4942 become part of the .bss section of the executable. There will be
4943 an entry for this symbol in the .dynsym section. The dynamic
4944 object will contain position independent code, so all references
4945 from the dynamic object to this symbol will go through the global
4946 offset table. The dynamic linker will use the .dynsym entry to
4947 determine the address it must put in the global offset table, so
4948 both the dynamic object and the regular object will refer to the
4949 same memory location for the variable.
4951 Of course, if the symbol is referenced using SDAREL relocs, we
4952 must instead allocate it in .sbss. */
4954 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
4958 BFD_ASSERT (s
!= NULL
);
4960 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
4961 copy the initial value out of the dynamic object and into the
4962 runtime process image. We need to remember the offset into the
4963 .rela.bss section we are going to use. */
4964 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4968 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
4969 srel
= htab
->relsbss
;
4971 srel
= htab
->relbss
;
4972 BFD_ASSERT (srel
!= NULL
);
4973 srel
->size
+= sizeof (Elf32_External_Rela
);
4977 return _bfd_elf_adjust_dynamic_copy (h
, s
);
4980 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
4981 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
4982 specifying the addend on the plt relocation. For -fpic code, the sym
4983 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
4984 xxxxxxxx.got2.plt_pic32.<callee>. */
4987 add_stub_sym (struct plt_entry
*ent
,
4988 struct elf_link_hash_entry
*h
,
4989 struct bfd_link_info
*info
)
4991 struct elf_link_hash_entry
*sh
;
4992 size_t len1
, len2
, len3
;
4995 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
4997 if (info
->shared
|| info
->pie
)
4998 stub
= ".plt_pic32.";
5000 stub
= ".plt_call32.";
5002 len1
= strlen (h
->root
.root
.string
);
5003 len2
= strlen (stub
);
5006 len3
= strlen (ent
->sec
->name
);
5007 name
= bfd_malloc (len1
+ len2
+ len3
+ 9);
5010 sprintf (name
, "%08x", (unsigned) ent
->addend
& 0xffffffff);
5012 memcpy (name
+ 8, ent
->sec
->name
, len3
);
5013 memcpy (name
+ 8 + len3
, stub
, len2
);
5014 memcpy (name
+ 8 + len3
+ len2
, h
->root
.root
.string
, len1
+ 1);
5015 sh
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
5018 if (sh
->root
.type
== bfd_link_hash_new
)
5020 sh
->root
.type
= bfd_link_hash_defined
;
5021 sh
->root
.u
.def
.section
= htab
->glink
;
5022 sh
->root
.u
.def
.value
= ent
->glink_offset
;
5023 sh
->ref_regular
= 1;
5024 sh
->def_regular
= 1;
5025 sh
->ref_regular_nonweak
= 1;
5026 sh
->forced_local
= 1;
5032 /* Allocate NEED contiguous space in .got, and return the offset.
5033 Handles allocation of the got header when crossing 32k. */
5036 allocate_got (struct ppc_elf_link_hash_table
*htab
, unsigned int need
)
5039 unsigned int max_before_header
;
5041 if (htab
->plt_type
== PLT_VXWORKS
)
5043 where
= htab
->got
->size
;
5044 htab
->got
->size
+= need
;
5048 max_before_header
= htab
->plt_type
== PLT_NEW
? 32768 : 32764;
5049 if (need
<= htab
->got_gap
)
5051 where
= max_before_header
- htab
->got_gap
;
5052 htab
->got_gap
-= need
;
5056 if (htab
->got
->size
+ need
> max_before_header
5057 && htab
->got
->size
<= max_before_header
)
5059 htab
->got_gap
= max_before_header
- htab
->got
->size
;
5060 htab
->got
->size
= max_before_header
+ htab
->got_header_size
;
5062 where
= htab
->got
->size
;
5063 htab
->got
->size
+= need
;
5069 /* Allocate space in associated reloc sections for dynamic relocs. */
5072 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5074 struct bfd_link_info
*info
= inf
;
5075 struct ppc_elf_link_hash_entry
*eh
;
5076 struct ppc_elf_link_hash_table
*htab
;
5077 struct ppc_elf_dyn_relocs
*p
;
5079 if (h
->root
.type
== bfd_link_hash_indirect
)
5082 if (h
->root
.type
== bfd_link_hash_warning
)
5083 /* When warning symbols are created, they **replace** the "real"
5084 entry in the hash table, thus we never get to see the real
5085 symbol in a hash traversal. So look at it now. */
5086 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5088 htab
= ppc_elf_hash_table (info
);
5089 if (htab
->elf
.dynamic_sections_created
5090 || h
->type
== STT_GNU_IFUNC
)
5092 struct plt_entry
*ent
;
5093 bfd_boolean doneone
= FALSE
;
5094 bfd_vma plt_offset
= 0, glink_offset
= 0;
5097 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5098 if (ent
->plt
.refcount
> 0)
5100 /* Make sure this symbol is output as a dynamic symbol. */
5101 if (h
->dynindx
== -1
5104 && htab
->elf
.dynamic_sections_created
)
5106 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5110 dyn
= htab
->elf
.dynamic_sections_created
;
5112 || h
->type
== STT_GNU_IFUNC
5113 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5115 asection
*s
= htab
->plt
;
5116 if (!dyn
|| h
->dynindx
== -1)
5119 if (htab
->plt_type
== PLT_NEW
|| !dyn
|| h
->dynindx
== -1)
5123 plt_offset
= s
->size
;
5126 ent
->plt
.offset
= plt_offset
;
5129 if (!doneone
|| info
->shared
|| info
->pie
)
5131 glink_offset
= s
->size
;
5132 s
->size
+= GLINK_ENTRY_SIZE
;
5139 h
->root
.u
.def
.section
= s
;
5140 h
->root
.u
.def
.value
= glink_offset
;
5142 ent
->glink_offset
= glink_offset
;
5144 if (htab
->emit_stub_syms
5145 && !add_stub_sym (ent
, h
, info
))
5152 /* If this is the first .plt entry, make room
5153 for the special first entry. */
5155 s
->size
+= htab
->plt_initial_entry_size
;
5157 /* The PowerPC PLT is actually composed of two
5158 parts, the first part is 2 words (for a load
5159 and a jump), and then there is a remaining
5160 word available at the end. */
5161 plt_offset
= (htab
->plt_initial_entry_size
5162 + (htab
->plt_slot_size
5164 - htab
->plt_initial_entry_size
)
5165 / htab
->plt_entry_size
)));
5167 /* If this symbol is not defined in a regular
5168 file, and we are not generating a shared
5169 library, then set the symbol to this location
5170 in the .plt. This is required to make
5171 function pointers compare as equal between
5172 the normal executable and the shared library. */
5177 h
->root
.u
.def
.section
= s
;
5178 h
->root
.u
.def
.value
= plt_offset
;
5181 /* Make room for this entry. */
5182 s
->size
+= htab
->plt_entry_size
;
5183 /* After the 8192nd entry, room for two entries
5185 if (htab
->plt_type
== PLT_OLD
5186 && (s
->size
- htab
->plt_initial_entry_size
)
5187 / htab
->plt_entry_size
5188 > PLT_NUM_SINGLE_ENTRIES
)
5189 s
->size
+= htab
->plt_entry_size
;
5191 ent
->plt
.offset
= plt_offset
;
5194 /* We also need to make an entry in the .rela.plt section. */
5197 if (!htab
->elf
.dynamic_sections_created
5198 || h
->dynindx
== -1)
5199 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5202 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
5204 if (htab
->plt_type
== PLT_VXWORKS
)
5206 /* Allocate space for the unloaded relocations. */
5208 && htab
->elf
.dynamic_sections_created
)
5211 == (bfd_vma
) htab
->plt_initial_entry_size
)
5213 htab
->srelplt2
->size
5214 += (sizeof (Elf32_External_Rela
)
5215 * VXWORKS_PLTRESOLVE_RELOCS
);
5218 htab
->srelplt2
->size
5219 += (sizeof (Elf32_External_Rela
)
5220 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
);
5223 /* Every PLT entry has an associated GOT entry in
5225 htab
->sgotplt
->size
+= 4;
5232 ent
->plt
.offset
= (bfd_vma
) -1;
5235 ent
->plt
.offset
= (bfd_vma
) -1;
5239 h
->plt
.plist
= NULL
;
5245 h
->plt
.plist
= NULL
;
5249 eh
= (struct ppc_elf_link_hash_entry
*) h
;
5250 if (eh
->elf
.got
.refcount
> 0)
5255 /* Make sure this symbol is output as a dynamic symbol. */
5256 if (eh
->elf
.dynindx
== -1
5257 && !eh
->elf
.forced_local
5258 && eh
->elf
.type
!= STT_GNU_IFUNC
5259 && htab
->elf
.dynamic_sections_created
)
5261 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
5266 if ((eh
->tls_mask
& TLS_TLS
) != 0)
5268 if ((eh
->tls_mask
& TLS_LD
) != 0)
5270 if (!eh
->elf
.def_dynamic
)
5271 /* We'll just use htab->tlsld_got.offset. This should
5272 always be the case. It's a little odd if we have
5273 a local dynamic reloc against a non-local symbol. */
5274 htab
->tlsld_got
.refcount
+= 1;
5278 if ((eh
->tls_mask
& TLS_GD
) != 0)
5280 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5282 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
5288 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5291 asection
*rsec
= NULL
;
5292 eh
->elf
.got
.offset
= allocate_got (htab
, need
);
5293 dyn
= htab
->elf
.dynamic_sections_created
;
5295 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
5296 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
5297 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
5298 rsec
= htab
->relgot
;
5299 else if (h
->type
== STT_GNU_IFUNC
)
5300 rsec
= htab
->reliplt
;
5303 /* All the entries we allocated need relocs.
5304 Except LD only needs one. */
5305 if ((eh
->tls_mask
& TLS_LD
) != 0
5306 && eh
->elf
.def_dynamic
)
5308 rsec
->size
+= need
* (sizeof (Elf32_External_Rela
) / 4);
5313 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5315 if (eh
->dyn_relocs
== NULL
5316 || (!htab
->elf
.dynamic_sections_created
5317 && h
->type
!= STT_GNU_IFUNC
))
5320 /* In the shared -Bsymbolic case, discard space allocated for
5321 dynamic pc-relative relocs against symbols which turn out to be
5322 defined in regular objects. For the normal shared case, discard
5323 space for relocs that have become local due to symbol visibility
5328 /* Relocs that use pc_count are those that appear on a call insn,
5329 or certain REL relocs (see must_be_dyn_reloc) that can be
5330 generated via assembly. We want calls to protected symbols to
5331 resolve directly to the function rather than going via the plt.
5332 If people want function pointer comparisons to work as expected
5333 then they should avoid writing weird assembly. */
5334 if (SYMBOL_CALLS_LOCAL (info
, h
))
5336 struct ppc_elf_dyn_relocs
**pp
;
5338 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5340 p
->count
-= p
->pc_count
;
5349 if (htab
->is_vxworks
)
5351 struct ppc_elf_dyn_relocs
**pp
;
5353 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5355 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
5362 /* Discard relocs on undefined symbols that must be local. */
5363 if (eh
->dyn_relocs
!= NULL
5364 && h
->root
.type
== bfd_link_hash_undefined
5365 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
5366 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
5367 eh
->dyn_relocs
= NULL
;
5369 /* Also discard relocs on undefined weak syms with non-default
5371 if (eh
->dyn_relocs
!= NULL
5372 && h
->root
.type
== bfd_link_hash_undefweak
)
5374 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5375 eh
->dyn_relocs
= NULL
;
5377 /* Make sure undefined weak symbols are output as a dynamic
5379 else if (h
->dynindx
== -1
5383 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5388 else if (h
->type
== STT_GNU_IFUNC
)
5390 if (!h
->non_got_ref
)
5391 eh
->dyn_relocs
= NULL
;
5393 else if (ELIMINATE_COPY_RELOCS
)
5395 /* For the non-shared case, discard space for relocs against
5396 symbols which turn out to need copy relocs or are not
5402 /* Make sure this symbol is output as a dynamic symbol.
5403 Undefined weak syms won't yet be marked as dynamic. */
5404 if (h
->dynindx
== -1
5405 && !h
->forced_local
)
5407 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5411 /* If that succeeded, we know we'll be keeping all the
5413 if (h
->dynindx
!= -1)
5417 eh
->dyn_relocs
= NULL
;
5422 /* Finally, allocate space. */
5423 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5425 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5426 if (!htab
->elf
.dynamic_sections_created
)
5427 sreloc
= htab
->reliplt
;
5428 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5434 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
5435 read-only sections. */
5438 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info
)
5440 if (h
->root
.type
== bfd_link_hash_indirect
)
5443 if (h
->root
.type
== bfd_link_hash_warning
)
5444 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5446 if (readonly_dynrelocs (h
))
5448 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
5450 /* Not an error, just cut short the traversal. */
5456 /* Set the sizes of the dynamic sections. */
5459 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5460 struct bfd_link_info
*info
)
5462 struct ppc_elf_link_hash_table
*htab
;
5468 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
5471 htab
= ppc_elf_hash_table (info
);
5472 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
5474 if (elf_hash_table (info
)->dynamic_sections_created
)
5476 /* Set the contents of the .interp section to the interpreter. */
5477 if (info
->executable
)
5479 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
5480 BFD_ASSERT (s
!= NULL
);
5481 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5482 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5486 if (htab
->plt_type
== PLT_OLD
)
5487 htab
->got_header_size
= 16;
5488 else if (htab
->plt_type
== PLT_NEW
)
5489 htab
->got_header_size
= 12;
5491 /* Set up .got offsets for local syms, and space for local dynamic
5493 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5495 bfd_signed_vma
*local_got
;
5496 bfd_signed_vma
*end_local_got
;
5497 struct plt_entry
**local_plt
;
5498 struct plt_entry
**end_local_plt
;
5500 bfd_size_type locsymcount
;
5501 Elf_Internal_Shdr
*symtab_hdr
;
5503 if (!is_ppc_elf (ibfd
))
5506 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5508 struct ppc_elf_dyn_relocs
*p
;
5510 for (p
= ((struct ppc_elf_dyn_relocs
*)
5511 elf_section_data (s
)->local_dynrel
);
5515 if (!bfd_is_abs_section (p
->sec
)
5516 && bfd_is_abs_section (p
->sec
->output_section
))
5518 /* Input section has been discarded, either because
5519 it is a copy of a linkonce section or due to
5520 linker script /DISCARD/, so we'll be discarding
5523 else if (htab
->is_vxworks
5524 && strcmp (p
->sec
->output_section
->name
,
5527 /* Relocations in vxworks .tls_vars sections are
5528 handled specially by the loader. */
5530 else if (p
->count
!= 0)
5532 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5533 if (!htab
->elf
.dynamic_sections_created
)
5534 sreloc
= htab
->reliplt
;
5535 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5536 if ((p
->sec
->output_section
->flags
5537 & (SEC_READONLY
| SEC_ALLOC
))
5538 == (SEC_READONLY
| SEC_ALLOC
))
5539 info
->flags
|= DF_TEXTREL
;
5544 local_got
= elf_local_got_refcounts (ibfd
);
5548 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5549 locsymcount
= symtab_hdr
->sh_info
;
5550 end_local_got
= local_got
+ locsymcount
;
5551 local_plt
= (struct plt_entry
**) end_local_got
;
5552 end_local_plt
= local_plt
+ locsymcount
;
5553 lgot_masks
= (char *) end_local_plt
;
5554 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
5557 unsigned int need
= 0;
5558 if ((*lgot_masks
& TLS_TLS
) != 0)
5560 if ((*lgot_masks
& TLS_GD
) != 0)
5562 if ((*lgot_masks
& TLS_LD
) != 0)
5563 htab
->tlsld_got
.refcount
+= 1;
5564 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5566 if ((*lgot_masks
& TLS_DTPREL
) != 0)
5572 *local_got
= (bfd_vma
) -1;
5575 *local_got
= allocate_got (htab
, need
);
5577 htab
->relgot
->size
+= (need
5578 * (sizeof (Elf32_External_Rela
) / 4));
5579 else if ((*lgot_masks
& PLT_IFUNC
) != 0)
5580 htab
->reliplt
->size
+= (need
5581 * (sizeof (Elf32_External_Rela
) / 4));
5585 *local_got
= (bfd_vma
) -1;
5587 if (htab
->is_vxworks
)
5590 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
5591 for (; local_plt
< end_local_plt
; ++local_plt
)
5593 struct plt_entry
*ent
;
5594 bfd_boolean doneone
= FALSE
;
5595 bfd_vma plt_offset
= 0, glink_offset
= 0;
5597 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
5598 if (ent
->plt
.refcount
> 0)
5600 asection
*s
= htab
->iplt
;
5604 plt_offset
= s
->size
;
5607 ent
->plt
.offset
= plt_offset
;
5610 if (!doneone
|| info
->shared
|| info
->pie
)
5612 glink_offset
= s
->size
;
5613 s
->size
+= GLINK_ENTRY_SIZE
;
5615 ent
->glink_offset
= glink_offset
;
5619 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5624 ent
->plt
.offset
= (bfd_vma
) -1;
5628 /* Allocate space for global sym dynamic relocs. */
5629 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
5631 if (htab
->tlsld_got
.refcount
> 0)
5633 htab
->tlsld_got
.offset
= allocate_got (htab
, 8);
5635 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
5638 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
5640 if (htab
->got
!= NULL
&& htab
->plt_type
!= PLT_VXWORKS
)
5642 unsigned int g_o_t
= 32768;
5644 /* If we haven't allocated the header, do so now. When we get here,
5645 for old plt/got the got size will be 0 to 32764 (not allocated),
5646 or 32780 to 65536 (header allocated). For new plt/got, the
5647 corresponding ranges are 0 to 32768 and 32780 to 65536. */
5648 if (htab
->got
->size
<= 32768)
5650 g_o_t
= htab
->got
->size
;
5651 if (htab
->plt_type
== PLT_OLD
)
5653 htab
->got
->size
+= htab
->got_header_size
;
5656 htab
->elf
.hgot
->root
.u
.def
.value
= g_o_t
;
5659 if (htab
->glink
!= NULL
5660 && htab
->glink
->size
!= 0
5661 && htab
->elf
.dynamic_sections_created
)
5663 htab
->glink_pltresolve
= htab
->glink
->size
;
5664 /* Space for the branch table. */
5665 htab
->glink
->size
+= htab
->glink
->size
/ (GLINK_ENTRY_SIZE
/ 4) - 4;
5666 /* Pad out to align the start of PLTresolve. */
5667 htab
->glink
->size
+= -htab
->glink
->size
& 15;
5668 htab
->glink
->size
+= GLINK_PLTRESOLVE
;
5670 if (htab
->emit_stub_syms
)
5672 struct elf_link_hash_entry
*sh
;
5673 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink",
5674 TRUE
, FALSE
, FALSE
);
5677 if (sh
->root
.type
== bfd_link_hash_new
)
5679 sh
->root
.type
= bfd_link_hash_defined
;
5680 sh
->root
.u
.def
.section
= htab
->glink
;
5681 sh
->root
.u
.def
.value
= htab
->glink_pltresolve
;
5682 sh
->ref_regular
= 1;
5683 sh
->def_regular
= 1;
5684 sh
->ref_regular_nonweak
= 1;
5685 sh
->forced_local
= 1;
5688 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
5689 TRUE
, FALSE
, FALSE
);
5692 if (sh
->root
.type
== bfd_link_hash_new
)
5694 sh
->root
.type
= bfd_link_hash_defined
;
5695 sh
->root
.u
.def
.section
= htab
->glink
;
5696 sh
->root
.u
.def
.value
= htab
->glink
->size
- GLINK_PLTRESOLVE
;
5697 sh
->ref_regular
= 1;
5698 sh
->def_regular
= 1;
5699 sh
->ref_regular_nonweak
= 1;
5700 sh
->forced_local
= 1;
5706 /* We've now determined the sizes of the various dynamic sections.
5707 Allocate memory for them. */
5709 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5711 bfd_boolean strip_section
= TRUE
;
5713 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5719 /* We'd like to strip these sections if they aren't needed, but if
5720 we've exported dynamic symbols from them we must leave them.
5721 It's too late to tell BFD to get rid of the symbols. */
5722 if (htab
->elf
.hplt
!= NULL
)
5723 strip_section
= FALSE
;
5724 /* Strip this section if we don't need it; see the
5727 else if (s
== htab
->iplt
5729 || s
== htab
->sgotplt
5731 || s
== htab
->dynbss
5732 || s
== htab
->dynsbss
5733 || s
== htab
->sdata
[0].section
5734 || s
== htab
->sdata
[1].section
)
5736 /* Strip these too. */
5738 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
5742 /* Remember whether there are any relocation sections. */
5745 /* We use the reloc_count field as a counter if we need
5746 to copy relocs into the output file. */
5752 /* It's not one of our sections, so don't allocate space. */
5756 if (s
->size
== 0 && strip_section
)
5758 /* If we don't need this section, strip it from the
5759 output file. This is mostly to handle .rela.bss and
5760 .rela.plt. We must create both sections in
5761 create_dynamic_sections, because they must be created
5762 before the linker maps input sections to output
5763 sections. The linker does that before
5764 adjust_dynamic_symbol is called, and it is that
5765 function which decides whether anything needs to go
5766 into these sections. */
5767 s
->flags
|= SEC_EXCLUDE
;
5771 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
5774 /* Allocate memory for the section contents. */
5775 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
5776 if (s
->contents
== NULL
)
5780 if (htab
->elf
.dynamic_sections_created
)
5782 /* Add some entries to the .dynamic section. We fill in the
5783 values later, in ppc_elf_finish_dynamic_sections, but we
5784 must add the entries now so that we get the correct size for
5785 the .dynamic section. The DT_DEBUG entry is filled in by the
5786 dynamic linker and used by the debugger. */
5787 #define add_dynamic_entry(TAG, VAL) \
5788 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5790 if (info
->executable
)
5792 if (!add_dynamic_entry (DT_DEBUG
, 0))
5796 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
5798 if (!add_dynamic_entry (DT_PLTGOT
, 0)
5799 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
5800 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
5801 || !add_dynamic_entry (DT_JMPREL
, 0))
5805 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
5807 if (!add_dynamic_entry (DT_PPC_GOT
, 0))
5813 if (!add_dynamic_entry (DT_RELA
, 0)
5814 || !add_dynamic_entry (DT_RELASZ
, 0)
5815 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
5819 /* If any dynamic relocs apply to a read-only section, then we
5820 need a DT_TEXTREL entry. */
5821 if ((info
->flags
& DF_TEXTREL
) == 0)
5822 elf_link_hash_traverse (elf_hash_table (info
), maybe_set_textrel
,
5825 if ((info
->flags
& DF_TEXTREL
) != 0)
5827 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5830 if (htab
->is_vxworks
5831 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
5834 #undef add_dynamic_entry
5839 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5842 ppc_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5844 if (h
->plt
.plist
!= NULL
5846 && (!h
->pointer_equality_needed
5847 || !h
->ref_regular_nonweak
))
5850 return _bfd_elf_hash_symbol (h
);
5853 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5855 static const int shared_stub_entry
[] =
5857 0x7c0802a6, /* mflr 0 */
5858 0x429f0005, /* bcl 20, 31, .Lxxx */
5859 0x7d6802a6, /* mflr 11 */
5860 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
5861 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
5862 0x7c0803a6, /* mtlr 0 */
5863 0x7d6903a6, /* mtctr 11 */
5864 0x4e800420, /* bctr */
5867 static const int stub_entry
[] =
5869 0x3d600000, /* lis 11,xxx@ha */
5870 0x396b0000, /* addi 11,11,xxx@l */
5871 0x7d6903a6, /* mtctr 11 */
5872 0x4e800420, /* bctr */
5876 ppc_elf_relax_section (bfd
*abfd
,
5878 struct bfd_link_info
*link_info
,
5883 struct one_fixup
*next
;
5889 Elf_Internal_Shdr
*symtab_hdr
;
5890 bfd_byte
*contents
= NULL
;
5891 Elf_Internal_Sym
*isymbuf
= NULL
;
5892 Elf_Internal_Rela
*internal_relocs
= NULL
;
5893 Elf_Internal_Rela
*irel
, *irelend
;
5894 struct one_fixup
*fixups
= NULL
;
5895 unsigned changes
= 0;
5896 struct ppc_elf_link_hash_table
*htab
;
5897 bfd_size_type trampoff
;
5902 /* Nothing to do if there are no relocations, and no need to do
5903 anything with non-alloc sections. */
5904 if ((isec
->flags
& SEC_ALLOC
) == 0
5905 || (isec
->flags
& SEC_RELOC
) == 0
5906 || isec
->reloc_count
== 0)
5909 /* We cannot represent the required PIC relocs in the output, so don't
5910 do anything. The linker doesn't support mixing -shared and -r
5912 if (link_info
->relocatable
&& link_info
->shared
)
5915 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
5916 /* Space for a branch around any trampolines. */
5919 symtab_hdr
= &elf_symtab_hdr (abfd
);
5921 /* Get a copy of the native relocations. */
5922 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
5923 link_info
->keep_memory
);
5924 if (internal_relocs
== NULL
)
5927 htab
= ppc_elf_hash_table (link_info
);
5928 got2
= bfd_get_section_by_name (abfd
, ".got2");
5930 irelend
= internal_relocs
+ isec
->reloc_count
;
5931 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
5933 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
5934 bfd_vma symaddr
, reladdr
, toff
, roff
;
5936 struct one_fixup
*f
;
5937 size_t insn_offset
= 0;
5938 bfd_vma max_branch_offset
, val
;
5941 unsigned char sym_type
;
5946 case R_PPC_LOCAL24PC
:
5947 case R_PPC_PLTREL24
:
5948 max_branch_offset
= 1 << 25;
5952 case R_PPC_REL14_BRTAKEN
:
5953 case R_PPC_REL14_BRNTAKEN
:
5954 max_branch_offset
= 1 << 15;
5961 /* Get the value of the symbol referred to by the reloc. */
5962 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
5964 /* A local symbol. */
5965 Elf_Internal_Sym
*isym
;
5967 /* Read this BFD's local symbols. */
5968 if (isymbuf
== NULL
)
5970 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5971 if (isymbuf
== NULL
)
5972 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
5973 symtab_hdr
->sh_info
, 0,
5978 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
5979 if (isym
->st_shndx
== SHN_UNDEF
)
5980 tsec
= bfd_und_section_ptr
;
5981 else if (isym
->st_shndx
== SHN_ABS
)
5982 tsec
= bfd_abs_section_ptr
;
5983 else if (isym
->st_shndx
== SHN_COMMON
)
5984 tsec
= bfd_com_section_ptr
;
5986 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5988 toff
= isym
->st_value
;
5989 sym_type
= ELF_ST_TYPE (isym
->st_info
);
5993 /* Global symbol handling. */
5995 struct elf_link_hash_entry
*h
;
5997 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
5998 h
= elf_sym_hashes (abfd
)[indx
];
6000 while (h
->root
.type
== bfd_link_hash_indirect
6001 || h
->root
.type
== bfd_link_hash_warning
)
6002 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6006 if (r_type
== R_PPC_PLTREL24
6007 && htab
->plt
!= NULL
)
6009 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
,
6010 got2
, irel
->r_addend
);
6014 if (htab
->plt_type
== PLT_NEW
)
6017 toff
= ent
->glink_offset
;
6022 toff
= ent
->plt
.offset
;
6028 else if (h
->root
.type
== bfd_link_hash_defined
6029 || h
->root
.type
== bfd_link_hash_defweak
)
6031 tsec
= h
->root
.u
.def
.section
;
6032 toff
= h
->root
.u
.def
.value
;
6034 else if (h
->root
.type
== bfd_link_hash_undefined
6035 || h
->root
.type
== bfd_link_hash_undefweak
)
6037 tsec
= bfd_und_section_ptr
;
6046 /* If the branch and target are in the same section, you have
6047 no hope of adding stubs. We'll error out later should the
6052 /* There probably isn't any reason to handle symbols in
6053 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6054 attribute for a code section, and we are only looking at
6055 branches. However, implement it correctly here as a
6056 reference for other target relax_section functions. */
6057 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
6059 /* At this stage in linking, no SEC_MERGE symbol has been
6060 adjusted, so all references to such symbols need to be
6061 passed through _bfd_merged_section_offset. (Later, in
6062 relocate_section, all SEC_MERGE symbols *except* for
6063 section symbols have been adjusted.)
6065 gas may reduce relocations against symbols in SEC_MERGE
6066 sections to a relocation against the section symbol when
6067 the original addend was zero. When the reloc is against
6068 a section symbol we should include the addend in the
6069 offset passed to _bfd_merged_section_offset, since the
6070 location of interest is the original symbol. On the
6071 other hand, an access to "sym+addend" where "sym" is not
6072 a section symbol should not include the addend; Such an
6073 access is presumed to be an offset from "sym"; The
6074 location of interest is just "sym". */
6075 if (sym_type
== STT_SECTION
)
6076 toff
+= irel
->r_addend
;
6078 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
6079 elf_section_data (tsec
)->sec_info
,
6082 if (sym_type
!= STT_SECTION
)
6083 toff
+= irel
->r_addend
;
6085 /* PLTREL24 addends are special. */
6086 else if (r_type
!= R_PPC_PLTREL24
)
6087 toff
+= irel
->r_addend
;
6089 /* Attempted -shared link of non-pic code loses. */
6090 if (tsec
->output_section
== NULL
)
6093 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
6095 roff
= irel
->r_offset
;
6096 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
6098 /* If the branch is in range, no need to do anything. */
6099 if (tsec
!= bfd_und_section_ptr
6100 && (!link_info
->relocatable
6101 /* A relocatable link may have sections moved during
6102 final link, so do not presume they remain in range. */
6103 || tsec
->output_section
== isec
->output_section
)
6104 && symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
6107 /* Look for an existing fixup to this address. */
6108 for (f
= fixups
; f
; f
= f
->next
)
6109 if (f
->tsec
== tsec
&& f
->toff
== toff
)
6115 unsigned long stub_rtype
;
6117 val
= trampoff
- roff
;
6118 if (val
>= max_branch_offset
)
6119 /* Oh dear, we can't reach a trampoline. Don't try to add
6120 one. We'll report an error later. */
6123 if (link_info
->shared
)
6125 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
6127 stub_rtype
= R_PPC_RELAX32PC
;
6131 size
= 4 * ARRAY_SIZE (stub_entry
);
6133 stub_rtype
= R_PPC_RELAX32
;
6136 if (R_PPC_RELAX32_PLT
- R_PPC_RELAX32
6137 != R_PPC_RELAX32PC_PLT
- R_PPC_RELAX32PC
)
6139 if (tsec
== htab
->plt
6140 || tsec
== htab
->glink
)
6141 stub_rtype
+= R_PPC_RELAX32_PLT
- R_PPC_RELAX32
;
6143 /* Hijack the old relocation. Since we need two
6144 relocations for this use a "composite" reloc. */
6145 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
6147 irel
->r_offset
= trampoff
+ insn_offset
;
6148 if (r_type
== R_PPC_PLTREL24
)
6151 /* Record the fixup so we don't do it again this section. */
6152 f
= bfd_malloc (sizeof (*f
));
6156 f
->trampoff
= trampoff
;
6164 val
= f
->trampoff
- roff
;
6165 if (val
>= max_branch_offset
)
6168 /* Nop out the reloc, since we're finalizing things here. */
6169 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6172 /* Get the section contents. */
6173 if (contents
== NULL
)
6175 /* Get cached copy if it exists. */
6176 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
6177 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6180 /* Go get them off disk. */
6181 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
6186 /* Fix up the existing branch to hit the trampoline. */
6187 hit_addr
= contents
+ roff
;
6191 case R_PPC_LOCAL24PC
:
6192 case R_PPC_PLTREL24
:
6193 t0
= bfd_get_32 (abfd
, hit_addr
);
6195 t0
|= val
& 0x3fffffc;
6196 bfd_put_32 (abfd
, t0
, hit_addr
);
6200 case R_PPC_REL14_BRTAKEN
:
6201 case R_PPC_REL14_BRNTAKEN
:
6202 t0
= bfd_get_32 (abfd
, hit_addr
);
6205 bfd_put_32 (abfd
, t0
, hit_addr
);
6210 /* Write out the trampolines. */
6220 struct one_fixup
*f
= fixups
;
6221 fixups
= fixups
->next
;
6226 contents
= bfd_realloc_or_free (contents
, trampoff
);
6227 if (contents
== NULL
)
6230 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
6231 /* Branch around the trampolines. */
6232 val
= B
+ trampoff
- isec
->size
;
6233 dest
= contents
+ isec
->size
;
6234 isec
->size
= trampoff
;
6235 bfd_put_32 (abfd
, val
, dest
);
6238 if (link_info
->shared
)
6240 stub
= shared_stub_entry
;
6241 size
= ARRAY_SIZE (shared_stub_entry
);
6246 size
= ARRAY_SIZE (stub_entry
);
6250 while (dest
< contents
+ trampoff
)
6252 bfd_put_32 (abfd
, stub
[i
], dest
);
6258 BFD_ASSERT (i
== 0);
6262 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
6264 if (! link_info
->keep_memory
)
6268 /* Cache the symbols for elf_link_input_bfd. */
6269 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
6273 if (contents
!= NULL
6274 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6276 if (!changes
&& !link_info
->keep_memory
)
6280 /* Cache the section contents for elf_link_input_bfd. */
6281 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6287 /* Append sufficient NOP relocs so we can write out relocation
6288 information for the trampolines. */
6289 Elf_Internal_Rela
*new_relocs
= bfd_malloc ((changes
+ isec
->reloc_count
)
6290 * sizeof (*new_relocs
));
6295 memcpy (new_relocs
, internal_relocs
,
6296 isec
->reloc_count
* sizeof (*new_relocs
));
6297 for (ix
= changes
; ix
--;)
6299 irel
= new_relocs
+ ix
+ isec
->reloc_count
;
6301 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6303 if (internal_relocs
!= elf_section_data (isec
)->relocs
)
6304 free (internal_relocs
);
6305 elf_section_data (isec
)->relocs
= new_relocs
;
6306 isec
->reloc_count
+= changes
;
6307 elf_section_data (isec
)->rel_hdr
.sh_size
6308 += changes
* elf_section_data (isec
)->rel_hdr
.sh_entsize
;
6310 else if (elf_section_data (isec
)->relocs
!= internal_relocs
)
6311 free (internal_relocs
);
6313 *again
= changes
!= 0;
6314 if (!*again
&& link_info
->relocatable
)
6316 /* Convert the internal relax relocs to external form. */
6317 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6318 if (ELF32_R_TYPE (irel
->r_info
) == R_PPC_RELAX32
)
6320 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
6322 /* Rewrite the reloc and convert one of the trailing nop
6323 relocs to describe this relocation. */
6324 BFD_ASSERT (ELF32_R_TYPE (irelend
[-1].r_info
) == R_PPC_NONE
);
6325 /* The relocs are at the bottom 2 bytes */
6326 irel
[0].r_offset
+= 2;
6327 memmove (irel
+ 1, irel
, (irelend
- irel
- 1) * sizeof (*irel
));
6328 irel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
6329 irel
[1].r_offset
+= 4;
6330 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
6338 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
6340 if (contents
!= NULL
6341 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6343 if (internal_relocs
!= NULL
6344 && elf_section_data (isec
)->relocs
!= internal_relocs
)
6345 free (internal_relocs
);
6349 /* What to do when ld finds relocations against symbols defined in
6350 discarded sections. */
6353 ppc_elf_action_discarded (asection
*sec
)
6355 if (strcmp (".fixup", sec
->name
) == 0)
6358 if (strcmp (".got2", sec
->name
) == 0)
6361 return _bfd_elf_default_action_discarded (sec
);
6364 /* Fill in the address for a pointer generated in a linker section. */
6367 elf_finish_pointer_linker_section (bfd
*input_bfd
,
6368 elf_linker_section_t
*lsect
,
6369 struct elf_link_hash_entry
*h
,
6371 const Elf_Internal_Rela
*rel
)
6373 elf_linker_section_pointers_t
*linker_section_ptr
;
6375 BFD_ASSERT (lsect
!= NULL
);
6379 /* Handle global symbol. */
6380 struct ppc_elf_link_hash_entry
*eh
;
6382 eh
= (struct ppc_elf_link_hash_entry
*) h
;
6383 BFD_ASSERT (eh
->elf
.def_regular
);
6384 linker_section_ptr
= eh
->linker_section_pointer
;
6388 /* Handle local symbol. */
6389 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
6391 BFD_ASSERT (is_ppc_elf (input_bfd
));
6392 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6393 linker_section_ptr
= elf_local_ptr_offsets (input_bfd
)[r_symndx
];
6396 linker_section_ptr
= elf_find_pointer_linker_section (linker_section_ptr
,
6399 BFD_ASSERT (linker_section_ptr
!= NULL
);
6401 /* Offset will always be a multiple of four, so use the bottom bit
6402 as a "written" flag. */
6403 if ((linker_section_ptr
->offset
& 1) == 0)
6405 bfd_put_32 (lsect
->section
->owner
,
6406 relocation
+ linker_section_ptr
->addend
,
6407 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6408 linker_section_ptr
->offset
+= 1;
6411 relocation
= (lsect
->section
->output_offset
6412 + linker_section_ptr
->offset
- 1
6417 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6418 lsect
->name
, (long) relocation
, (long) relocation
);
6421 /* Subtract out the addend, because it will get added back in by the normal
6423 return relocation
- linker_section_ptr
->addend
;
6426 #define PPC_LO(v) ((v) & 0xffff)
6427 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6428 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6431 write_glink_stub (struct plt_entry
*ent
, asection
*plt_sec
,
6432 struct bfd_link_info
*info
)
6434 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
6435 bfd
*output_bfd
= info
->output_bfd
;
6439 plt
= ((ent
->plt
.offset
& ~1)
6440 + plt_sec
->output_section
->vma
6441 + plt_sec
->output_offset
);
6442 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
6444 if (info
->shared
|| info
->pie
)
6448 if (ent
->addend
>= 32768)
6450 + ent
->sec
->output_section
->vma
6451 + ent
->sec
->output_offset
);
6452 else if (htab
->elf
.hgot
!= NULL
)
6453 got
= SYM_VAL (htab
->elf
.hgot
);
6457 if (plt
+ 0x8000 < 0x10000)
6459 bfd_put_32 (output_bfd
, LWZ_11_30
+ PPC_LO (plt
), p
);
6461 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6463 bfd_put_32 (output_bfd
, BCTR
, p
);
6465 bfd_put_32 (output_bfd
, NOP
, p
);
6470 bfd_put_32 (output_bfd
, ADDIS_11_30
+ PPC_HA (plt
), p
);
6472 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6474 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6476 bfd_put_32 (output_bfd
, BCTR
, p
);
6482 bfd_put_32 (output_bfd
, LIS_11
+ PPC_HA (plt
), p
);
6484 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6486 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6488 bfd_put_32 (output_bfd
, BCTR
, p
);
6493 /* The RELOCATE_SECTION function is called by the ELF backend linker
6494 to handle the relocations for a section.
6496 The relocs are always passed as Rela structures; if the section
6497 actually uses Rel structures, the r_addend field will always be
6500 This function is responsible for adjust the section contents as
6501 necessary, and (if using Rela relocs and generating a
6502 relocatable output file) adjusting the reloc addend as
6505 This function does not have to worry about setting the reloc
6506 address or the reloc symbol index.
6508 LOCAL_SYMS is a pointer to the swapped in local symbols.
6510 LOCAL_SECTIONS is an array giving the section in the input file
6511 corresponding to the st_shndx field of each local symbol.
6513 The global hash table entry for the global symbols can be found
6514 via elf_sym_hashes (input_bfd).
6516 When generating relocatable output, this function must handle
6517 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6518 going to be the section symbol corresponding to the output
6519 section, which means that the addend must be adjusted
6523 ppc_elf_relocate_section (bfd
*output_bfd
,
6524 struct bfd_link_info
*info
,
6526 asection
*input_section
,
6528 Elf_Internal_Rela
*relocs
,
6529 Elf_Internal_Sym
*local_syms
,
6530 asection
**local_sections
)
6532 Elf_Internal_Shdr
*symtab_hdr
;
6533 struct elf_link_hash_entry
**sym_hashes
;
6534 struct ppc_elf_link_hash_table
*htab
;
6535 Elf_Internal_Rela
*rel
;
6536 Elf_Internal_Rela
*relend
;
6537 Elf_Internal_Rela outrel
;
6539 asection
*got2
, *sreloc
= NULL
;
6540 bfd_vma
*local_got_offsets
;
6541 bfd_boolean ret
= TRUE
;
6542 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
6543 bfd_boolean is_vxworks_tls
;
6546 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
6547 "%ld relocations%s",
6548 input_bfd
, input_section
,
6549 (long) input_section
->reloc_count
,
6550 (info
->relocatable
) ? " (relocatable)" : "");
6553 got2
= bfd_get_section_by_name (input_bfd
, ".got2");
6555 /* Initialize howto table if not already done. */
6556 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
6557 ppc_elf_howto_init ();
6559 htab
= ppc_elf_hash_table (info
);
6560 local_got_offsets
= elf_local_got_offsets (input_bfd
);
6561 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6562 sym_hashes
= elf_sym_hashes (input_bfd
);
6563 /* We have to handle relocations in vxworks .tls_vars sections
6564 specially, because the dynamic loader is 'weird'. */
6565 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
6566 && !strcmp (input_section
->output_section
->name
,
6569 relend
= relocs
+ input_section
->reloc_count
;
6570 for (; rel
< relend
; rel
++)
6572 enum elf_ppc_reloc_type r_type
;
6574 bfd_reloc_status_type r
;
6575 Elf_Internal_Sym
*sym
;
6577 struct elf_link_hash_entry
*h
;
6578 const char *sym_name
;
6579 reloc_howto_type
*howto
;
6580 unsigned long r_symndx
;
6582 bfd_vma branch_bit
, insn
, from
;
6583 bfd_boolean unresolved_reloc
;
6585 unsigned int tls_type
, tls_mask
, tls_gd
;
6586 struct plt_entry
**ifunc
;
6588 r_type
= ELF32_R_TYPE (rel
->r_info
);
6592 unresolved_reloc
= FALSE
;
6594 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6596 if (r_symndx
< symtab_hdr
->sh_info
)
6598 sym
= local_syms
+ r_symndx
;
6599 sec
= local_sections
[r_symndx
];
6600 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
6602 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6606 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6607 r_symndx
, symtab_hdr
, sym_hashes
,
6609 unresolved_reloc
, warned
);
6611 sym_name
= h
->root
.root
.string
;
6614 if (sec
!= NULL
&& elf_discarded_section (sec
))
6616 /* For relocs against symbols from removed linkonce sections,
6617 or sections discarded by a linker script, we just want the
6618 section contents zeroed. Avoid any special processing. */
6620 if (r_type
< R_PPC_max
)
6621 howto
= ppc_elf_howto_table
[r_type
];
6622 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
6628 if (info
->relocatable
)
6631 && r_type
== R_PPC_PLTREL24
6632 && rel
->r_addend
>= 32768)
6634 /* R_PPC_PLTREL24 is rather special. If non-zero, the
6635 addend specifies the GOT pointer offset within .got2. */
6636 rel
->r_addend
+= got2
->output_offset
;
6641 /* TLS optimizations. Replace instruction sequences and relocs
6642 based on information we collected in tls_optimize. We edit
6643 RELOCS so that --emit-relocs will output something sensible
6644 for the final instruction stream. */
6648 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
6649 else if (local_got_offsets
!= NULL
)
6651 struct plt_entry
**local_plt
;
6654 = (struct plt_entry
**) (local_got_offsets
+ symtab_hdr
->sh_info
);
6655 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
6656 tls_mask
= lgot_masks
[r_symndx
];
6659 /* Ensure reloc mapping code below stays sane. */
6660 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
6661 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
6662 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
6663 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
6664 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
6665 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
6666 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
6667 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
6674 case R_PPC_GOT_TPREL16
:
6675 case R_PPC_GOT_TPREL16_LO
:
6676 if ((tls_mask
& TLS_TLS
) != 0
6677 && (tls_mask
& TLS_TPREL
) == 0)
6680 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
6682 insn
|= 0x3c020000; /* addis 0,2,0 */
6683 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
6684 r_type
= R_PPC_TPREL16_HA
;
6685 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6690 if ((tls_mask
& TLS_TLS
) != 0
6691 && (tls_mask
& TLS_TPREL
) == 0)
6694 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6695 if ((insn
& ((31 << 26) | (31 << 11)))
6696 == ((31 << 26) | (2 << 11)))
6697 rtra
= insn
& ((1 << 26) - (1 << 16));
6698 else if ((insn
& ((31 << 26) | (31 << 16)))
6699 == ((31 << 26) | (2 << 16)))
6700 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
6703 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
6706 else if ((insn
& (31 << 1)) == 23 << 1
6707 && ((insn
& (31 << 6)) < 14 << 6
6708 || ((insn
& (31 << 6)) >= 16 << 6
6709 && (insn
& (31 << 6)) < 24 << 6)))
6710 /* load and store indexed -> dform. */
6711 insn
= (32 | ((insn
>> 6) & 31)) << 26;
6712 else if ((insn
& (31 << 1)) == 21 << 1
6713 && (insn
& (0x1a << 6)) == 0)
6714 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
6715 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
6716 | ((insn
>> 6) & 1));
6717 else if ((insn
& (31 << 1)) == 21 << 1
6718 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
6720 insn
= (58 << 26) | 2;
6724 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
6725 r_type
= R_PPC_TPREL16_LO
;
6726 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6728 /* Was PPC_TLS which sits on insn boundary, now
6729 PPC_TPREL16_LO which is at low-order half-word. */
6730 rel
->r_offset
+= d_offset
;
6734 case R_PPC_GOT_TLSGD16_HI
:
6735 case R_PPC_GOT_TLSGD16_HA
:
6736 tls_gd
= TLS_TPRELGD
;
6737 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6741 case R_PPC_GOT_TLSLD16_HI
:
6742 case R_PPC_GOT_TLSLD16_HA
:
6743 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6746 if ((tls_mask
& tls_gd
) != 0)
6747 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
6748 + R_PPC_GOT_TPREL16
);
6751 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
6752 rel
->r_offset
-= d_offset
;
6753 r_type
= R_PPC_NONE
;
6755 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6759 case R_PPC_GOT_TLSGD16
:
6760 case R_PPC_GOT_TLSGD16_LO
:
6761 tls_gd
= TLS_TPRELGD
;
6762 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6766 case R_PPC_GOT_TLSLD16
:
6767 case R_PPC_GOT_TLSLD16_LO
:
6768 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6770 unsigned int insn1
, insn2
;
6774 offset
= (bfd_vma
) -1;
6775 /* If not using the newer R_PPC_TLSGD/LD to mark
6776 __tls_get_addr calls, we must trust that the call
6777 stays with its arg setup insns, ie. that the next
6778 reloc is the __tls_get_addr call associated with
6779 the current reloc. Edit both insns. */
6780 if (input_section
->has_tls_get_addr_call
6782 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
6783 htab
->tls_get_addr
))
6784 offset
= rel
[1].r_offset
;
6785 if ((tls_mask
& tls_gd
) != 0)
6788 insn1
= bfd_get_32 (output_bfd
,
6789 contents
+ rel
->r_offset
- d_offset
);
6790 insn1
&= (1 << 26) - 1;
6791 insn1
|= 32 << 26; /* lwz */
6792 if (offset
!= (bfd_vma
) -1)
6795 = ELF32_R_INFO (ELF32_R_SYM (rel
[1].r_info
),
6797 insn2
= 0x7c631214; /* add 3,3,2 */
6798 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
6800 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
6801 + R_PPC_GOT_TPREL16
);
6802 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6807 insn1
= 0x3c620000; /* addis 3,2,0 */
6810 /* Was an LD reloc. */
6812 r_symndx
< symtab_hdr
->sh_info
;
6814 if (local_sections
[r_symndx
] == sec
)
6816 if (r_symndx
>= symtab_hdr
->sh_info
)
6818 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
6820 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
6821 + sec
->output_offset
6822 + sec
->output_section
->vma
);
6824 r_type
= R_PPC_TPREL16_HA
;
6825 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6826 if (offset
!= (bfd_vma
) -1)
6828 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
6829 rel
[1].r_offset
= offset
+ d_offset
;
6830 rel
[1].r_addend
= rel
->r_addend
;
6831 insn2
= 0x38630000; /* addi 3,3,0 */
6832 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
6835 bfd_put_32 (output_bfd
, insn1
,
6836 contents
+ rel
->r_offset
- d_offset
);
6839 /* We changed the symbol on an LD reloc. Start over
6840 in order to get h, sym, sec etc. right. */
6848 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6851 bfd_vma offset
= rel
->r_offset
;
6853 if ((tls_mask
& TLS_TPRELGD
) != 0)
6856 r_type
= R_PPC_NONE
;
6857 insn2
= 0x7c631214; /* add 3,3,2 */
6862 r_type
= R_PPC_TPREL16_LO
;
6863 rel
->r_offset
+= d_offset
;
6864 insn2
= 0x38630000; /* addi 3,3,0 */
6866 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6867 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
6868 /* Zap the reloc on the _tls_get_addr call too. */
6869 BFD_ASSERT (offset
== rel
[1].r_offset
);
6870 rel
[1].r_info
= ELF32_R_INFO (ELF32_R_SYM (rel
[1].r_info
),
6876 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6881 r_symndx
< symtab_hdr
->sh_info
;
6883 if (local_sections
[r_symndx
] == sec
)
6885 if (r_symndx
>= symtab_hdr
->sh_info
)
6887 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
6889 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
6890 + sec
->output_offset
6891 + sec
->output_section
->vma
);
6893 rel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
6894 rel
->r_offset
+= d_offset
;
6895 insn2
= 0x38630000; /* addi 3,3,0 */
6896 bfd_put_32 (output_bfd
, insn2
,
6897 contents
+ rel
->r_offset
- d_offset
);
6898 /* Zap the reloc on the _tls_get_addr call too. */
6899 BFD_ASSERT (rel
->r_offset
- d_offset
== rel
[1].r_offset
);
6900 rel
[1].r_info
= ELF32_R_INFO (ELF32_R_SYM (rel
[1].r_info
),
6908 /* Handle other relocations that tweak non-addend part of insn. */
6915 /* Branch taken prediction relocations. */
6916 case R_PPC_ADDR14_BRTAKEN
:
6917 case R_PPC_REL14_BRTAKEN
:
6918 branch_bit
= BRANCH_PREDICT_BIT
;
6921 /* Branch not taken prediction relocations. */
6922 case R_PPC_ADDR14_BRNTAKEN
:
6923 case R_PPC_REL14_BRNTAKEN
:
6924 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6925 insn
&= ~BRANCH_PREDICT_BIT
;
6928 from
= (rel
->r_offset
6929 + input_section
->output_offset
6930 + input_section
->output_section
->vma
);
6932 /* Invert 'y' bit if not the default. */
6933 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
6934 insn
^= BRANCH_PREDICT_BIT
;
6936 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
6941 if (!htab
->is_vxworks
)
6945 if (h
->type
== STT_GNU_IFUNC
)
6946 ifunc
= &h
->plt
.plist
;
6948 else if (local_got_offsets
!= NULL
)
6950 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
6952 struct plt_entry
**local_plt
= (struct plt_entry
**)
6953 (local_got_offsets
+ symtab_hdr
->sh_info
);
6955 ifunc
= local_plt
+ r_symndx
;
6958 if (ifunc
!= NULL
&& is_branch_reloc (r_type
))
6960 struct plt_entry
*ent
= find_plt_ent (ifunc
, got2
, rel
->r_addend
);
6962 if (h
== NULL
&& (ent
->plt
.offset
& 1) == 0)
6964 Elf_Internal_Rela rela
;
6967 rela
.r_offset
= (htab
->iplt
->output_section
->vma
6968 + htab
->iplt
->output_offset
6970 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
6971 rela
.r_addend
= relocation
;
6972 loc
= htab
->reliplt
->contents
;
6973 loc
+= (htab
->reliplt
->reloc_count
++
6974 * sizeof (Elf32_External_Rela
));
6975 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
6977 ent
->plt
.offset
|= 1;
6979 if (h
== NULL
&& (ent
->glink_offset
& 1) == 0)
6981 write_glink_stub (ent
, htab
->iplt
, info
);
6982 ent
->glink_offset
|= 1;
6985 unresolved_reloc
= FALSE
;
6986 if (htab
->plt_type
== PLT_NEW
6987 || !htab
->elf
.dynamic_sections_created
6989 relocation
= (htab
->glink
->output_section
->vma
6990 + htab
->glink
->output_offset
6991 + (ent
->glink_offset
& ~1));
6993 relocation
= (htab
->plt
->output_section
->vma
6994 + htab
->plt
->output_offset
6999 addend
= rel
->r_addend
;
7002 if (r_type
< R_PPC_max
)
7003 howto
= ppc_elf_howto_table
[r_type
];
7007 (*_bfd_error_handler
)
7008 (_("%B: unknown relocation type %d for symbol %s"),
7009 input_bfd
, (int) r_type
, sym_name
);
7011 bfd_set_error (bfd_error_bad_value
);
7019 case R_PPC_EMB_MRKREF
:
7020 case R_PPC_GNU_VTINHERIT
:
7021 case R_PPC_GNU_VTENTRY
:
7024 /* GOT16 relocations. Like an ADDR16 using the symbol's
7025 address in the GOT as relocation value instead of the
7026 symbol's value itself. Also, create a GOT entry for the
7027 symbol and put the symbol value there. */
7028 case R_PPC_GOT_TLSGD16
:
7029 case R_PPC_GOT_TLSGD16_LO
:
7030 case R_PPC_GOT_TLSGD16_HI
:
7031 case R_PPC_GOT_TLSGD16_HA
:
7032 tls_type
= TLS_TLS
| TLS_GD
;
7035 case R_PPC_GOT_TLSLD16
:
7036 case R_PPC_GOT_TLSLD16_LO
:
7037 case R_PPC_GOT_TLSLD16_HI
:
7038 case R_PPC_GOT_TLSLD16_HA
:
7039 tls_type
= TLS_TLS
| TLS_LD
;
7042 case R_PPC_GOT_TPREL16
:
7043 case R_PPC_GOT_TPREL16_LO
:
7044 case R_PPC_GOT_TPREL16_HI
:
7045 case R_PPC_GOT_TPREL16_HA
:
7046 tls_type
= TLS_TLS
| TLS_TPREL
;
7049 case R_PPC_GOT_DTPREL16
:
7050 case R_PPC_GOT_DTPREL16_LO
:
7051 case R_PPC_GOT_DTPREL16_HI
:
7052 case R_PPC_GOT_DTPREL16_HA
:
7053 tls_type
= TLS_TLS
| TLS_DTPREL
;
7057 case R_PPC_GOT16_LO
:
7058 case R_PPC_GOT16_HI
:
7059 case R_PPC_GOT16_HA
:
7063 /* Relocation is to the entry for this symbol in the global
7069 if (htab
->got
== NULL
)
7073 if (tls_type
== (TLS_TLS
| TLS_LD
)
7075 || !h
->def_dynamic
))
7076 offp
= &htab
->tlsld_got
.offset
;
7080 dyn
= htab
->elf
.dynamic_sections_created
;
7081 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7083 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
7084 /* This is actually a static link, or it is a
7085 -Bsymbolic link and the symbol is defined
7086 locally, or the symbol was forced to be local
7087 because of a version file. */
7092 unresolved_reloc
= FALSE
;
7094 offp
= &h
->got
.offset
;
7098 if (local_got_offsets
== NULL
)
7100 offp
= &local_got_offsets
[r_symndx
];
7103 /* The offset must always be a multiple of 4. We use the
7104 least significant bit to record whether we have already
7105 processed this entry. */
7112 unsigned int tls_m
= (tls_mask
7113 & (TLS_LD
| TLS_GD
| TLS_DTPREL
7114 | TLS_TPREL
| TLS_TPRELGD
));
7116 if (offp
== &htab
->tlsld_got
.offset
)
7122 /* We might have multiple got entries for this sym.
7123 Initialize them all. */
7128 if ((tls_m
& TLS_LD
) != 0)
7130 tls_ty
= TLS_TLS
| TLS_LD
;
7133 else if ((tls_m
& TLS_GD
) != 0)
7135 tls_ty
= TLS_TLS
| TLS_GD
;
7138 else if ((tls_m
& TLS_DTPREL
) != 0)
7140 tls_ty
= TLS_TLS
| TLS_DTPREL
;
7141 tls_m
&= ~TLS_DTPREL
;
7143 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
7145 tls_ty
= TLS_TLS
| TLS_TPREL
;
7149 /* Generate relocs for the dynamic linker. */
7151 if ((info
->shared
|| indx
!= 0)
7152 && (offp
== &htab
->tlsld_got
.offset
7154 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7155 || h
->root
.type
!= bfd_link_hash_undefweak
))
7156 rsec
= htab
->relgot
;
7157 else if (ifunc
!= NULL
)
7158 rsec
= htab
->reliplt
;
7161 outrel
.r_offset
= (htab
->got
->output_section
->vma
7162 + htab
->got
->output_offset
7164 outrel
.r_addend
= 0;
7165 if (tls_ty
& (TLS_LD
| TLS_GD
))
7167 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
7168 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7170 loc
= rsec
->contents
;
7171 loc
+= (rsec
->reloc_count
++
7172 * sizeof (Elf32_External_Rela
));
7173 bfd_elf32_swap_reloca_out (output_bfd
,
7175 outrel
.r_offset
+= 4;
7177 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7180 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
7181 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7182 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7183 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
7185 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
7186 else if (ifunc
!= NULL
)
7187 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7189 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7190 if (indx
== 0 && tls_ty
!= (TLS_TLS
| TLS_LD
))
7192 outrel
.r_addend
+= relocation
;
7193 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
7194 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
7196 loc
= rsec
->contents
;
7197 loc
+= (rsec
->reloc_count
++
7198 * sizeof (Elf32_External_Rela
));
7199 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7202 /* Init the .got section contents if we're not
7203 emitting a reloc. */
7206 bfd_vma value
= relocation
;
7208 if (tls_ty
== (TLS_TLS
| TLS_LD
))
7210 else if (tls_ty
!= 0)
7212 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7213 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7214 value
+= DTP_OFFSET
- TP_OFFSET
;
7216 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7218 bfd_put_32 (output_bfd
, value
,
7219 htab
->got
->contents
+ off
+ 4);
7223 bfd_put_32 (output_bfd
, value
,
7224 htab
->got
->contents
+ off
);
7228 if (tls_ty
& (TLS_LD
| TLS_GD
))
7237 if (off
>= (bfd_vma
) -2)
7240 if ((tls_type
& TLS_TLS
) != 0)
7242 if (tls_type
!= (TLS_TLS
| TLS_LD
))
7244 if ((tls_mask
& TLS_LD
) != 0
7246 || !h
->def_dynamic
))
7248 if (tls_type
!= (TLS_TLS
| TLS_GD
))
7250 if ((tls_mask
& TLS_GD
) != 0)
7252 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
7254 if ((tls_mask
& TLS_DTPREL
) != 0)
7261 relocation
= (htab
->got
->output_section
->vma
7262 + htab
->got
->output_offset
7264 - SYM_VAL (htab
->elf
.hgot
));
7266 /* Addends on got relocations don't make much sense.
7267 x+off@got is actually x@got+off, and since the got is
7268 generated by a hash table traversal, the value in the
7269 got at entry m+n bears little relation to the entry m. */
7271 (*_bfd_error_handler
)
7272 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
7275 (long) rel
->r_offset
,
7281 /* Relocations that need no special processing. */
7282 case R_PPC_LOCAL24PC
:
7283 /* It makes no sense to point a local relocation
7284 at a symbol not in this object. */
7285 if (unresolved_reloc
)
7287 if (! (*info
->callbacks
->undefined_symbol
) (info
,
7288 h
->root
.root
.string
,
7298 case R_PPC_DTPREL16
:
7299 case R_PPC_DTPREL16_LO
:
7300 case R_PPC_DTPREL16_HI
:
7301 case R_PPC_DTPREL16_HA
:
7302 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7305 /* Relocations that may need to be propagated if this is a shared
7308 case R_PPC_TPREL16_LO
:
7309 case R_PPC_TPREL16_HI
:
7310 case R_PPC_TPREL16_HA
:
7311 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7312 /* The TPREL16 relocs shouldn't really be used in shared
7313 libs as they will result in DT_TEXTREL being set, but
7314 support them anyway. */
7318 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7321 case R_PPC_DTPREL32
:
7322 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7325 case R_PPC_DTPMOD32
:
7331 case R_PPC_REL16_LO
:
7332 case R_PPC_REL16_HI
:
7333 case R_PPC_REL16_HA
:
7337 if (h
== NULL
|| h
== htab
->elf
.hgot
)
7343 case R_PPC_ADDR16_LO
:
7344 case R_PPC_ADDR16_HI
:
7345 case R_PPC_ADDR16_HA
:
7352 case R_PPC_REL14_BRTAKEN
:
7353 case R_PPC_REL14_BRNTAKEN
:
7354 /* If these relocations are not to a named symbol, they can be
7355 handled right here, no need to bother the dynamic linker. */
7356 if (SYMBOL_CALLS_LOCAL (info
, h
)
7357 || h
== htab
->elf
.hgot
)
7363 case R_PPC_ADDR14_BRTAKEN
:
7364 case R_PPC_ADDR14_BRNTAKEN
:
7365 if (h
!= NULL
&& !info
->shared
)
7370 if ((input_section
->flags
& SEC_ALLOC
) == 0
7376 && ((h
->root
.type
== bfd_link_hash_undefined
7377 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
7378 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
7379 || (h
->root
.type
== bfd_link_hash_undefweak
7380 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)))
7381 && (must_be_dyn_reloc (info
, r_type
)
7382 || !SYMBOL_CALLS_LOCAL (info
, h
)))
7383 || (ELIMINATE_COPY_RELOCS
7395 fprintf (stderr
, "ppc_elf_relocate_section needs to "
7396 "create relocation for %s\n",
7397 (h
&& h
->root
.root
.string
7398 ? h
->root
.root
.string
: "<unknown>"));
7401 /* When generating a shared object, these relocations
7402 are copied into the output file to be resolved at run
7406 sreloc
= elf_section_data (input_section
)->sreloc
;
7407 if (!htab
->elf
.dynamic_sections_created
)
7408 sreloc
= htab
->reliplt
;
7415 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
7417 if (outrel
.r_offset
== (bfd_vma
) -1
7418 || outrel
.r_offset
== (bfd_vma
) -2)
7419 skip
= (int) outrel
.r_offset
;
7420 outrel
.r_offset
+= (input_section
->output_section
->vma
7421 + input_section
->output_offset
);
7424 memset (&outrel
, 0, sizeof outrel
);
7426 && (h
->root
.type
== bfd_link_hash_undefined
7427 || h
->root
.type
== bfd_link_hash_undefweak
))
7428 || !SYMBOL_REFERENCES_LOCAL (info
, h
))
7430 unresolved_reloc
= FALSE
;
7431 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
7432 outrel
.r_addend
= rel
->r_addend
;
7436 outrel
.r_addend
= relocation
+ rel
->r_addend
;
7438 if (r_type
!= R_PPC_ADDR32
)
7444 /* If we get here when building a static
7445 executable, then the libc startup function
7446 responsible for applying indirect function
7447 relocations is going to complain about
7449 If we get here when building a dynamic
7450 executable, it will be because we have
7451 a text relocation. The dynamic loader
7452 will set the text segment writable and
7453 non-executable to apply text relocations.
7454 So we'll segfault when trying to run the
7455 indirection function to resolve the reloc. */
7456 (*_bfd_error_handler
)
7457 (_("%B(%A+0x%lx): relocation %s for indirect "
7458 "function %s unsupported"),
7461 (long) rel
->r_offset
,
7466 else if (r_symndx
== 0 || bfd_is_abs_section (sec
))
7468 else if (sec
== NULL
|| sec
->owner
== NULL
)
7470 bfd_set_error (bfd_error_bad_value
);
7477 /* We are turning this relocation into one
7478 against a section symbol. It would be
7479 proper to subtract the symbol's value,
7480 osec->vma, from the emitted reloc addend,
7481 but ld.so expects buggy relocs.
7482 FIXME: Why not always use a zero index? */
7483 osec
= sec
->output_section
;
7484 indx
= elf_section_data (osec
)->dynindx
;
7487 osec
= htab
->elf
.text_index_section
;
7488 indx
= elf_section_data (osec
)->dynindx
;
7490 BFD_ASSERT (indx
!= 0);
7493 printf ("indx=%ld section=%s flags=%08x name=%s\n",
7494 indx
, osec
->name
, osec
->flags
,
7495 h
->root
.root
.string
);
7499 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
7501 else if (ifunc
!= NULL
)
7502 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7504 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7507 loc
= sreloc
->contents
;
7508 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7509 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7514 /* This reloc will be computed at runtime. We clear the memory
7515 so that it contains predictable value. */
7517 && ((input_section
->flags
& SEC_ALLOC
) != 0
7518 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
7520 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
7527 case R_PPC_RELAX32PC_PLT
:
7528 case R_PPC_RELAX32_PLT
:
7530 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
, got2
, addend
);
7532 if (htab
->plt_type
== PLT_NEW
)
7533 relocation
= (htab
->glink
->output_section
->vma
7534 + htab
->glink
->output_offset
7535 + ent
->glink_offset
);
7537 relocation
= (htab
->plt
->output_section
->vma
7538 + htab
->plt
->output_offset
7541 if (r_type
== R_PPC_RELAX32_PLT
)
7545 case R_PPC_RELAX32PC
:
7546 relocation
-= (input_section
->output_section
->vma
7547 + input_section
->output_offset
7548 + rel
->r_offset
- 4);
7557 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7558 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
7560 /* We're clearing the bits for R_PPC_ADDR16_HA
7561 and R_PPC_ADDR16_LO here. */
7565 /* t0 is HA, t1 is LO */
7566 relocation
+= addend
;
7567 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
7568 t1
|= relocation
& 0xffff;
7570 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
7571 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
7573 /* Rewrite the reloc and convert one of the trailing nop
7574 relocs to describe this relocation. */
7575 BFD_ASSERT (ELF32_R_TYPE (relend
[-1].r_info
) == R_PPC_NONE
);
7576 /* The relocs are at the bottom 2 bytes */
7577 rel
[0].r_offset
+= 2;
7578 memmove (rel
+ 1, rel
, (relend
- rel
- 1) * sizeof (*rel
));
7579 rel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
7580 rel
[1].r_offset
+= 4;
7581 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
7586 /* Indirect .sdata relocation. */
7587 case R_PPC_EMB_SDAI16
:
7588 BFD_ASSERT (htab
->sdata
[0].section
!= NULL
);
7590 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[0],
7591 h
, relocation
, rel
);
7594 /* Indirect .sdata2 relocation. */
7595 case R_PPC_EMB_SDA2I16
:
7596 BFD_ASSERT (htab
->sdata
[1].section
!= NULL
);
7598 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[1],
7599 h
, relocation
, rel
);
7602 /* Handle the TOC16 reloc. We want to use the offset within the .got
7603 section, not the actual VMA. This is appropriate when generating
7604 an embedded ELF object, for which the .got section acts like the
7605 AIX .toc section. */
7606 case R_PPC_TOC16
: /* phony GOT16 relocations */
7607 if (sec
== NULL
|| sec
->output_section
== NULL
)
7609 unresolved_reloc
= TRUE
;
7612 BFD_ASSERT (strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
7613 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
7615 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
7618 case R_PPC_PLTREL24
:
7619 if (h
== NULL
|| ifunc
!= NULL
)
7621 /* Relocation is to the entry for this symbol in the
7622 procedure linkage table. */
7624 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
, got2
, addend
);
7628 || htab
->plt
== NULL
)
7630 /* We didn't make a PLT entry for this symbol. This
7631 happens when statically linking PIC code, or when
7632 using -Bsymbolic. */
7636 unresolved_reloc
= FALSE
;
7637 if (htab
->plt_type
== PLT_NEW
)
7638 relocation
= (htab
->glink
->output_section
->vma
7639 + htab
->glink
->output_offset
7640 + ent
->glink_offset
);
7642 relocation
= (htab
->plt
->output_section
->vma
7643 + htab
->plt
->output_offset
7648 /* Relocate against _SDA_BASE_. */
7649 case R_PPC_SDAREL16
:
7653 if (sec
== NULL
|| sec
->output_section
== NULL
)
7655 unresolved_reloc
= TRUE
;
7659 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7660 if (! ((CONST_STRNEQ (name
, ".sdata")
7661 && (name
[6] == 0 || name
[6] == '.'))
7662 || (CONST_STRNEQ (name
, ".sbss")
7663 && (name
[5] == 0 || name
[5] == '.'))))
7665 (*_bfd_error_handler
)
7666 (_("%B: the target (%s) of a %s relocation is "
7667 "in the wrong output section (%s)"),
7673 addend
-= SYM_VAL (htab
->sdata
[0].sym
);
7677 /* Relocate against _SDA2_BASE_. */
7678 case R_PPC_EMB_SDA2REL
:
7682 if (sec
== NULL
|| sec
->output_section
== NULL
)
7684 unresolved_reloc
= TRUE
;
7688 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7689 if (! (CONST_STRNEQ (name
, ".sdata2")
7690 || CONST_STRNEQ (name
, ".sbss2")))
7692 (*_bfd_error_handler
)
7693 (_("%B: the target (%s) of a %s relocation is "
7694 "in the wrong output section (%s)"),
7700 bfd_set_error (bfd_error_bad_value
);
7704 addend
-= SYM_VAL (htab
->sdata
[1].sym
);
7708 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
7709 case R_PPC_EMB_SDA21
:
7710 case R_PPC_EMB_RELSDA
:
7715 if (sec
== NULL
|| sec
->output_section
== NULL
)
7717 unresolved_reloc
= TRUE
;
7721 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7722 if (((CONST_STRNEQ (name
, ".sdata")
7723 && (name
[6] == 0 || name
[6] == '.'))
7724 || (CONST_STRNEQ (name
, ".sbss")
7725 && (name
[5] == 0 || name
[5] == '.'))))
7728 addend
-= SYM_VAL (htab
->sdata
[0].sym
);
7730 else if (CONST_STRNEQ (name
, ".sdata2")
7731 || CONST_STRNEQ (name
, ".sbss2"))
7734 addend
-= SYM_VAL (htab
->sdata
[1].sym
);
7736 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
7737 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
7743 (*_bfd_error_handler
)
7744 (_("%B: the target (%s) of a %s relocation is "
7745 "in the wrong output section (%s)"),
7751 bfd_set_error (bfd_error_bad_value
);
7756 if (r_type
== R_PPC_EMB_SDA21
)
7757 { /* fill in register field */
7758 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7759 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
7760 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7765 /* Relocate against the beginning of the section. */
7767 case R_PPC_SECTOFF_LO
:
7768 case R_PPC_SECTOFF_HI
:
7769 case R_PPC_SECTOFF_HA
:
7770 if (sec
== NULL
|| sec
->output_section
== NULL
)
7772 unresolved_reloc
= TRUE
;
7775 addend
-= sec
->output_section
->vma
;
7778 /* Negative relocations. */
7779 case R_PPC_EMB_NADDR32
:
7780 case R_PPC_EMB_NADDR16
:
7781 case R_PPC_EMB_NADDR16_LO
:
7782 case R_PPC_EMB_NADDR16_HI
:
7783 case R_PPC_EMB_NADDR16_HA
:
7784 addend
-= 2 * relocation
;
7788 case R_PPC_GLOB_DAT
:
7789 case R_PPC_JMP_SLOT
:
7790 case R_PPC_RELATIVE
:
7791 case R_PPC_IRELATIVE
:
7793 case R_PPC_PLTREL32
:
7794 case R_PPC_PLT16_LO
:
7795 case R_PPC_PLT16_HI
:
7796 case R_PPC_PLT16_HA
:
7798 case R_PPC_EMB_RELSEC16
:
7799 case R_PPC_EMB_RELST_LO
:
7800 case R_PPC_EMB_RELST_HI
:
7801 case R_PPC_EMB_RELST_HA
:
7802 case R_PPC_EMB_BIT_FLD
:
7803 (*_bfd_error_handler
)
7804 (_("%B: relocation %s is not yet supported for symbol %s."),
7809 bfd_set_error (bfd_error_invalid_operation
);
7814 /* Do any further special processing. */
7820 case R_PPC_ADDR16_HA
:
7821 case R_PPC_REL16_HA
:
7822 case R_PPC_SECTOFF_HA
:
7823 case R_PPC_TPREL16_HA
:
7824 case R_PPC_DTPREL16_HA
:
7825 case R_PPC_EMB_NADDR16_HA
:
7826 case R_PPC_EMB_RELST_HA
:
7827 /* It's just possible that this symbol is a weak symbol
7828 that's not actually defined anywhere. In that case,
7829 'sec' would be NULL, and we should leave the symbol
7830 alone (it will be set to zero elsewhere in the link). */
7835 case R_PPC_PLT16_HA
:
7836 case R_PPC_GOT16_HA
:
7837 case R_PPC_GOT_TLSGD16_HA
:
7838 case R_PPC_GOT_TLSLD16_HA
:
7839 case R_PPC_GOT_TPREL16_HA
:
7840 case R_PPC_GOT_DTPREL16_HA
:
7841 /* Add 0x10000 if sign bit in 0:15 is set.
7842 Bits 0:15 are not used. */
7848 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
7849 "offset = %ld, addend = %ld\n",
7854 (long) rel
->r_offset
,
7858 if (unresolved_reloc
7859 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
7862 (*_bfd_error_handler
)
7863 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
7866 (long) rel
->r_offset
,
7872 r
= _bfd_final_link_relocate (howto
,
7880 if (r
!= bfd_reloc_ok
)
7882 if (r
== bfd_reloc_overflow
)
7887 && h
->root
.type
== bfd_link_hash_undefweak
7888 && howto
->pc_relative
)
7890 /* Assume this is a call protected by other code that
7891 detect the symbol is undefined. If this is the case,
7892 we can safely ignore the overflow. If not, the
7893 program is hosed anyway, and a little warning isn't
7899 if (! (*info
->callbacks
->reloc_overflow
) (info
,
7900 (h
? &h
->root
: NULL
),
7911 (*_bfd_error_handler
)
7912 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
7913 input_bfd
, input_section
,
7914 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
7921 fprintf (stderr
, "\n");
7927 /* Finish up dynamic symbol handling. We set the contents of various
7928 dynamic sections here. */
7931 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
7932 struct bfd_link_info
*info
,
7933 struct elf_link_hash_entry
*h
,
7934 Elf_Internal_Sym
*sym
)
7936 struct ppc_elf_link_hash_table
*htab
;
7937 struct plt_entry
*ent
;
7938 bfd_boolean doneone
;
7941 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
7942 h
->root
.root
.string
);
7945 htab
= ppc_elf_hash_table (info
);
7946 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
7949 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7950 if (ent
->plt
.offset
!= (bfd_vma
) -1)
7954 Elf_Internal_Rela rela
;
7956 bfd_vma reloc_index
;
7958 if (htab
->plt_type
== PLT_NEW
7959 || !htab
->elf
.dynamic_sections_created
7960 || h
->dynindx
== -1)
7961 reloc_index
= ent
->plt
.offset
/ 4;
7964 reloc_index
= ((ent
->plt
.offset
- htab
->plt_initial_entry_size
)
7965 / htab
->plt_slot_size
);
7966 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
7967 && htab
->plt_type
== PLT_OLD
)
7968 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
7971 /* This symbol has an entry in the procedure linkage table.
7973 if (htab
->plt_type
== PLT_VXWORKS
7974 && htab
->elf
.dynamic_sections_created
7975 && h
->dynindx
!= -1)
7978 const bfd_vma
*plt_entry
;
7980 /* The first three entries in .got.plt are reserved. */
7981 got_offset
= (reloc_index
+ 3) * 4;
7983 /* Use the right PLT. */
7984 plt_entry
= info
->shared
? ppc_elf_vxworks_pic_plt_entry
7985 : ppc_elf_vxworks_plt_entry
;
7987 /* Fill in the .plt on VxWorks. */
7990 bfd_put_32 (output_bfd
,
7991 plt_entry
[0] | PPC_HA (got_offset
),
7992 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
7993 bfd_put_32 (output_bfd
,
7994 plt_entry
[1] | PPC_LO (got_offset
),
7995 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
7999 bfd_vma got_loc
= got_offset
+ SYM_VAL (htab
->elf
.hgot
);
8001 bfd_put_32 (output_bfd
,
8002 plt_entry
[0] | PPC_HA (got_loc
),
8003 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
8004 bfd_put_32 (output_bfd
,
8005 plt_entry
[1] | PPC_LO (got_loc
),
8006 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
8009 bfd_put_32 (output_bfd
, plt_entry
[2],
8010 htab
->plt
->contents
+ ent
->plt
.offset
+ 8);
8011 bfd_put_32 (output_bfd
, plt_entry
[3],
8012 htab
->plt
->contents
+ ent
->plt
.offset
+ 12);
8014 /* This instruction is an immediate load. The value loaded is
8015 the byte offset of the R_PPC_JMP_SLOT relocation from the
8016 start of the .rela.plt section. The value is stored in the
8017 low-order 16 bits of the load instruction. */
8018 /* NOTE: It appears that this is now an index rather than a
8019 prescaled offset. */
8020 bfd_put_32 (output_bfd
,
8021 plt_entry
[4] | reloc_index
,
8022 htab
->plt
->contents
+ ent
->plt
.offset
+ 16);
8023 /* This instruction is a PC-relative branch whose target is
8024 the start of the PLT section. The address of this branch
8025 instruction is 20 bytes beyond the start of this PLT entry.
8026 The address is encoded in bits 6-29, inclusive. The value
8027 stored is right-shifted by two bits, permitting a 26-bit
8029 bfd_put_32 (output_bfd
,
8031 | (-(ent
->plt
.offset
+ 20) & 0x03fffffc)),
8032 htab
->plt
->contents
+ ent
->plt
.offset
+ 20);
8033 bfd_put_32 (output_bfd
, plt_entry
[6],
8034 htab
->plt
->contents
+ ent
->plt
.offset
+ 24);
8035 bfd_put_32 (output_bfd
, plt_entry
[7],
8036 htab
->plt
->contents
+ ent
->plt
.offset
+ 28);
8038 /* Fill in the GOT entry corresponding to this PLT slot with
8039 the address immediately after the the "bctr" instruction
8040 in this PLT entry. */
8041 bfd_put_32 (output_bfd
, (htab
->plt
->output_section
->vma
8042 + htab
->plt
->output_offset
8043 + ent
->plt
.offset
+ 16),
8044 htab
->sgotplt
->contents
+ got_offset
);
8048 /* Fill in a couple of entries in .rela.plt.unloaded. */
8049 loc
= htab
->srelplt2
->contents
8050 + ((VXWORKS_PLTRESOLVE_RELOCS
+ reloc_index
8051 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
)
8052 * sizeof (Elf32_External_Rela
));
8054 /* Provide the @ha relocation for the first instruction. */
8055 rela
.r_offset
= (htab
->plt
->output_section
->vma
8056 + htab
->plt
->output_offset
8057 + ent
->plt
.offset
+ 2);
8058 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8060 rela
.r_addend
= got_offset
;
8061 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8062 loc
+= sizeof (Elf32_External_Rela
);
8064 /* Provide the @l relocation for the second instruction. */
8065 rela
.r_offset
= (htab
->plt
->output_section
->vma
8066 + htab
->plt
->output_offset
8067 + ent
->plt
.offset
+ 6);
8068 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8070 rela
.r_addend
= got_offset
;
8071 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8072 loc
+= sizeof (Elf32_External_Rela
);
8074 /* Provide a relocation for the GOT entry corresponding to this
8075 PLT slot. Point it at the middle of the .plt entry. */
8076 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8077 + htab
->sgotplt
->output_offset
8079 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
8081 rela
.r_addend
= ent
->plt
.offset
+ 16;
8082 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8085 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
8086 In particular, the offset for the relocation is not the
8087 address of the PLT entry for this function, as specified
8088 by the ABI. Instead, the offset is set to the address of
8089 the GOT slot for this function. See EABI 4.4.4.1. */
8090 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8091 + htab
->sgotplt
->output_offset
8097 asection
*splt
= htab
->plt
;
8098 if (!htab
->elf
.dynamic_sections_created
8099 || h
->dynindx
== -1)
8102 rela
.r_offset
= (splt
->output_section
->vma
8103 + splt
->output_offset
8105 if (htab
->plt_type
== PLT_OLD
8106 || !htab
->elf
.dynamic_sections_created
8107 || h
->dynindx
== -1)
8109 /* We don't need to fill in the .plt. The ppc dynamic
8110 linker will fill it in. */
8114 bfd_vma val
= (htab
->glink_pltresolve
+ ent
->plt
.offset
8115 + htab
->glink
->output_section
->vma
8116 + htab
->glink
->output_offset
);
8117 bfd_put_32 (output_bfd
, val
,
8118 splt
->contents
+ ent
->plt
.offset
);
8122 /* Fill in the entry in the .rela.plt section. */
8124 if (!htab
->elf
.dynamic_sections_created
8125 || h
->dynindx
== -1)
8127 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
8129 && (h
->root
.type
== bfd_link_hash_defined
8130 || h
->root
.type
== bfd_link_hash_defweak
));
8131 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
8132 rela
.r_addend
= SYM_VAL (h
);
8135 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
8137 if (!htab
->elf
.dynamic_sections_created
8138 || h
->dynindx
== -1)
8139 loc
= (htab
->reliplt
->contents
8140 + (htab
->reliplt
->reloc_count
++
8141 * sizeof (Elf32_External_Rela
)));
8143 loc
= (htab
->relplt
->contents
8144 + reloc_index
* sizeof (Elf32_External_Rela
));
8145 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8147 if (!h
->def_regular
)
8149 /* Mark the symbol as undefined, rather than as
8150 defined in the .plt section. Leave the value if
8151 there were any relocations where pointer equality
8152 matters (this is a clue for the dynamic linker, to
8153 make function pointer comparisons work between an
8154 application and shared library), otherwise set it
8156 sym
->st_shndx
= SHN_UNDEF
;
8157 if (!h
->pointer_equality_needed
)
8159 else if (!h
->ref_regular_nonweak
)
8161 /* This breaks function pointer comparisons, but
8162 that is better than breaking tests for a NULL
8163 function pointer. */
8170 if (htab
->plt_type
== PLT_NEW
8171 || !htab
->elf
.dynamic_sections_created
8172 || h
->dynindx
== -1)
8174 asection
*splt
= htab
->plt
;
8175 if (!htab
->elf
.dynamic_sections_created
8176 || h
->dynindx
== -1)
8179 write_glink_stub (ent
, splt
, info
);
8181 if (!info
->shared
&& !info
->pie
)
8182 /* We only need one non-PIC glink stub. */
8192 Elf_Internal_Rela rela
;
8195 /* This symbols needs a copy reloc. Set it up. */
8198 fprintf (stderr
, ", copy");
8201 BFD_ASSERT (h
->dynindx
!= -1);
8203 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
8207 BFD_ASSERT (s
!= NULL
);
8209 rela
.r_offset
= SYM_VAL (h
);
8210 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
8212 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
8213 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8217 fprintf (stderr
, "\n");
8220 /* Mark some specially defined symbols as absolute. */
8221 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
8222 || (!htab
->is_vxworks
8223 && (h
== htab
->elf
.hgot
8224 || strcmp (h
->root
.root
.string
,
8225 "_PROCEDURE_LINKAGE_TABLE_") == 0)))
8226 sym
->st_shndx
= SHN_ABS
;
8231 static enum elf_reloc_type_class
8232 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
8234 switch (ELF32_R_TYPE (rela
->r_info
))
8236 case R_PPC_RELATIVE
:
8237 return reloc_class_relative
;
8240 case R_PPC_JMP_SLOT
:
8241 return reloc_class_plt
;
8243 return reloc_class_copy
;
8245 return reloc_class_normal
;
8249 /* Finish up the dynamic sections. */
8252 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
8253 struct bfd_link_info
*info
)
8257 struct ppc_elf_link_hash_table
*htab
;
8260 bfd_boolean ret
= TRUE
;
8263 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
8266 htab
= ppc_elf_hash_table (info
);
8267 dynobj
= elf_hash_table (info
)->dynobj
;
8268 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8269 if (htab
->is_vxworks
)
8270 splt
= bfd_get_section_by_name (dynobj
, ".plt");
8275 if (htab
->elf
.hgot
!= NULL
)
8276 got
= SYM_VAL (htab
->elf
.hgot
);
8278 if (htab
->elf
.dynamic_sections_created
)
8280 Elf32_External_Dyn
*dyncon
, *dynconend
;
8282 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
8284 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
8285 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8286 for (; dyncon
< dynconend
; dyncon
++)
8288 Elf_Internal_Dyn dyn
;
8291 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8296 if (htab
->is_vxworks
)
8300 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8304 dyn
.d_un
.d_val
= htab
->relplt
->size
;
8309 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8313 dyn
.d_un
.d_ptr
= got
;
8317 if (htab
->is_vxworks
)
8320 dyn
.d_un
.d_ptr
-= htab
->relplt
->size
;
8326 if (htab
->is_vxworks
8327 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
8332 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8336 if (htab
->got
!= NULL
)
8338 if (htab
->elf
.hgot
->root
.u
.def
.section
== htab
->got
8339 || htab
->elf
.hgot
->root
.u
.def
.section
== htab
->sgotplt
)
8341 unsigned char *p
= htab
->elf
.hgot
->root
.u
.def
.section
->contents
;
8343 p
+= htab
->elf
.hgot
->root
.u
.def
.value
;
8344 if (htab
->plt_type
== PLT_OLD
)
8346 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
8347 so that a function can easily find the address of
8348 _GLOBAL_OFFSET_TABLE_. */
8349 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
- 4
8350 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8351 bfd_put_32 (output_bfd
, 0x4e800021, p
- 4);
8356 bfd_vma val
= sdyn
->output_section
->vma
+ sdyn
->output_offset
;
8357 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
8358 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8359 bfd_put_32 (output_bfd
, val
, p
);
8364 (*_bfd_error_handler
) (_("%s not defined in linker created %s"),
8365 htab
->elf
.hgot
->root
.root
.string
,
8366 (htab
->sgotplt
!= NULL
8367 ? htab
->sgotplt
->name
: htab
->got
->name
));
8368 bfd_set_error (bfd_error_bad_value
);
8372 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
8375 /* Fill in the first entry in the VxWorks procedure linkage table. */
8376 if (splt
&& splt
->size
> 0)
8378 /* Use the right PLT. */
8379 static const bfd_vma
*plt_entry
= NULL
;
8380 plt_entry
= info
->shared
?
8381 ppc_elf_vxworks_pic_plt0_entry
: ppc_elf_vxworks_plt0_entry
;
8385 bfd_vma got_value
= SYM_VAL (htab
->elf
.hgot
);
8387 bfd_put_32 (output_bfd
, plt_entry
[0] | PPC_HA (got_value
),
8388 splt
->contents
+ 0);
8389 bfd_put_32 (output_bfd
, plt_entry
[1] | PPC_LO (got_value
),
8390 splt
->contents
+ 4);
8394 bfd_put_32 (output_bfd
, plt_entry
[0], splt
->contents
+ 0);
8395 bfd_put_32 (output_bfd
, plt_entry
[1], splt
->contents
+ 4);
8397 bfd_put_32 (output_bfd
, plt_entry
[2], splt
->contents
+ 8);
8398 bfd_put_32 (output_bfd
, plt_entry
[3], splt
->contents
+ 12);
8399 bfd_put_32 (output_bfd
, plt_entry
[4], splt
->contents
+ 16);
8400 bfd_put_32 (output_bfd
, plt_entry
[5], splt
->contents
+ 20);
8401 bfd_put_32 (output_bfd
, plt_entry
[6], splt
->contents
+ 24);
8402 bfd_put_32 (output_bfd
, plt_entry
[7], splt
->contents
+ 28);
8406 Elf_Internal_Rela rela
;
8409 loc
= htab
->srelplt2
->contents
;
8411 /* Output the @ha relocation for the first instruction. */
8412 rela
.r_offset
= (htab
->plt
->output_section
->vma
8413 + htab
->plt
->output_offset
8415 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8417 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8418 loc
+= sizeof (Elf32_External_Rela
);
8420 /* Output the @l relocation for the second instruction. */
8421 rela
.r_offset
= (htab
->plt
->output_section
->vma
8422 + htab
->plt
->output_offset
8424 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8426 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8427 loc
+= sizeof (Elf32_External_Rela
);
8429 /* Fix up the remaining relocations. They may have the wrong
8430 symbol index for _G_O_T_ or _P_L_T_ depending on the order
8431 in which symbols were output. */
8432 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
8434 Elf_Internal_Rela rel
;
8436 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8437 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8438 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8439 loc
+= sizeof (Elf32_External_Rela
);
8441 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8442 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8443 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8444 loc
+= sizeof (Elf32_External_Rela
);
8446 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8447 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_PPC_ADDR32
);
8448 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8449 loc
+= sizeof (Elf32_External_Rela
);
8454 if (htab
->glink
!= NULL
8455 && htab
->glink
->contents
!= NULL
8456 && htab
->elf
.dynamic_sections_created
)
8459 unsigned char *endp
;
8464 * PIC glink code is the following:
8466 * # ith PLT code stub.
8467 * addis 11,30,(plt+(i-1)*4-got)@ha
8468 * lwz 11,(plt+(i-1)*4-got)@l(11)
8472 * # A table of branches, one for each plt entry.
8473 * # The idea is that the plt call stub loads ctr and r11 with these
8474 * # addresses, so (r11 - res_0) gives the plt index * 4.
8475 * res_0: b PLTresolve
8476 * res_1: b PLTresolve
8478 * # Some number of entries towards the end can be nops
8484 * addis 11,11,(1f-res_0)@ha
8487 * 1: addi 11,11,(1b-res_0)@l
8490 * sub 11,11,12 # r11 = index * 4
8491 * addis 12,12,(got+4-1b)@ha
8492 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
8493 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
8496 * add 11,0,11 # r11 = index * 12 = reloc offset.
8499 static const unsigned int pic_plt_resolve
[] =
8520 * Non-PIC glink code is a little simpler.
8522 * # ith PLT code stub.
8523 * lis 11,(plt+(i-1)*4)@ha
8524 * lwz 11,(plt+(i-1)*4)@l(11)
8528 * The branch table is the same, then comes
8532 * addis 11,11,(-res_0)@ha
8533 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
8534 * addi 11,11,(-res_0)@l # r11 = index * 4
8537 * lwz 12,(got+8)@l(12) # got[2] contains the map address
8538 * add 11,0,11 # r11 = index * 12 = reloc offset.
8541 static const unsigned int plt_resolve
[] =
8561 if (ARRAY_SIZE (pic_plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8563 if (ARRAY_SIZE (plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8566 /* Build the branch table, one for each plt entry (less one),
8567 and perhaps some padding. */
8568 p
= htab
->glink
->contents
;
8569 p
+= htab
->glink_pltresolve
;
8570 endp
= htab
->glink
->contents
;
8571 endp
+= htab
->glink
->size
- GLINK_PLTRESOLVE
;
8572 while (p
< endp
- 8 * 4)
8574 bfd_put_32 (output_bfd
, B
+ endp
- p
, p
);
8579 bfd_put_32 (output_bfd
, NOP
, p
);
8583 res0
= (htab
->glink_pltresolve
8584 + htab
->glink
->output_section
->vma
8585 + htab
->glink
->output_offset
);
8587 /* Last comes the PLTresolve stub. */
8588 if (info
->shared
|| info
->pie
)
8592 for (i
= 0; i
< ARRAY_SIZE (pic_plt_resolve
); i
++)
8594 bfd_put_32 (output_bfd
, pic_plt_resolve
[i
], p
);
8597 p
-= 4 * ARRAY_SIZE (pic_plt_resolve
);
8599 bcl
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 3*4
8600 + htab
->glink
->output_section
->vma
8601 + htab
->glink
->output_offset
);
8603 bfd_put_32 (output_bfd
,
8604 ADDIS_11_11
+ PPC_HA (bcl
- res0
), p
+ 0*4);
8605 bfd_put_32 (output_bfd
,
8606 ADDI_11_11
+ PPC_LO (bcl
- res0
), p
+ 3*4);
8607 bfd_put_32 (output_bfd
,
8608 ADDIS_12_12
+ PPC_HA (got
+ 4 - bcl
), p
+ 7*4);
8609 if (PPC_HA (got
+ 4 - bcl
) == PPC_HA (got
+ 8 - bcl
))
8611 bfd_put_32 (output_bfd
,
8612 LWZ_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8613 bfd_put_32 (output_bfd
,
8614 LWZ_12_12
+ PPC_LO (got
+ 8 - bcl
), p
+ 9*4);
8618 bfd_put_32 (output_bfd
,
8619 LWZU_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8620 bfd_put_32 (output_bfd
,
8621 LWZ_12_12
+ 4, p
+ 9*4);
8626 for (i
= 0; i
< ARRAY_SIZE (plt_resolve
); i
++)
8628 bfd_put_32 (output_bfd
, plt_resolve
[i
], p
);
8631 p
-= 4 * ARRAY_SIZE (plt_resolve
);
8633 bfd_put_32 (output_bfd
,
8634 LIS_12
+ PPC_HA (got
+ 4), p
+ 0*4);
8635 bfd_put_32 (output_bfd
,
8636 ADDIS_11_11
+ PPC_HA (-res0
), p
+ 1*4);
8637 bfd_put_32 (output_bfd
,
8638 ADDI_11_11
+ PPC_LO (-res0
), p
+ 3*4);
8639 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
8641 bfd_put_32 (output_bfd
,
8642 LWZ_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8643 bfd_put_32 (output_bfd
,
8644 LWZ_12_12
+ PPC_LO (got
+ 8), p
+ 6*4);
8648 bfd_put_32 (output_bfd
,
8649 LWZU_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8650 bfd_put_32 (output_bfd
,
8651 LWZ_12_12
+ 4, p
+ 6*4);
8659 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
8660 #define TARGET_LITTLE_NAME "elf32-powerpcle"
8661 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
8662 #define TARGET_BIG_NAME "elf32-powerpc"
8663 #define ELF_ARCH bfd_arch_powerpc
8664 #define ELF_MACHINE_CODE EM_PPC
8665 #ifdef __QNXTARGET__
8666 #define ELF_MAXPAGESIZE 0x1000
8668 #define ELF_MAXPAGESIZE 0x10000
8670 #define ELF_MINPAGESIZE 0x1000
8671 #define ELF_COMMONPAGESIZE 0x1000
8672 #define elf_info_to_howto ppc_elf_info_to_howto
8674 #ifdef EM_CYGNUS_POWERPC
8675 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
8679 #define ELF_MACHINE_ALT2 EM_PPC_OLD
8682 #define elf_backend_plt_not_loaded 1
8683 #define elf_backend_can_gc_sections 1
8684 #define elf_backend_can_refcount 1
8685 #define elf_backend_rela_normal 1
8687 #define bfd_elf32_mkobject ppc_elf_mkobject
8688 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
8689 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
8690 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
8691 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
8692 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
8693 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
8694 #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
8696 #define elf_backend_object_p ppc_elf_object_p
8697 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
8698 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
8699 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
8700 #define elf_backend_relocate_section ppc_elf_relocate_section
8701 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
8702 #define elf_backend_check_relocs ppc_elf_check_relocs
8703 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
8704 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
8705 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
8706 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
8707 #define elf_backend_hash_symbol ppc_elf_hash_symbol
8708 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
8709 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
8710 #define elf_backend_fake_sections ppc_elf_fake_sections
8711 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
8712 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
8713 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
8714 #define elf_backend_write_core_note ppc_elf_write_core_note
8715 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
8716 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
8717 #define elf_backend_final_write_processing ppc_elf_final_write_processing
8718 #define elf_backend_write_section ppc_elf_write_section
8719 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
8720 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
8721 #define elf_backend_action_discarded ppc_elf_action_discarded
8722 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
8723 #define elf_backend_post_process_headers _bfd_elf_set_osabi
8725 #include "elf32-target.h"
8727 /* VxWorks Target */
8729 #undef TARGET_LITTLE_SYM
8730 #undef TARGET_LITTLE_NAME
8732 #undef TARGET_BIG_SYM
8733 #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
8734 #undef TARGET_BIG_NAME
8735 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
8737 /* VxWorks uses the elf default section flags for .plt. */
8738 static const struct bfd_elf_special_section
*
8739 ppc_elf_vxworks_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
8741 if (sec
->name
== NULL
)
8744 if (strcmp (sec
->name
, ".plt") == 0)
8745 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
8747 return ppc_elf_get_sec_type_attr (abfd
, sec
);
8750 /* Like ppc_elf_link_hash_table_create, but overrides
8751 appropriately for VxWorks. */
8752 static struct bfd_link_hash_table
*
8753 ppc_elf_vxworks_link_hash_table_create (bfd
*abfd
)
8755 struct bfd_link_hash_table
*ret
;
8757 ret
= ppc_elf_link_hash_table_create (abfd
);
8760 struct ppc_elf_link_hash_table
*htab
8761 = (struct ppc_elf_link_hash_table
*)ret
;
8762 htab
->is_vxworks
= 1;
8763 htab
->plt_type
= PLT_VXWORKS
;
8764 htab
->plt_entry_size
= VXWORKS_PLT_ENTRY_SIZE
;
8765 htab
->plt_slot_size
= VXWORKS_PLT_ENTRY_SIZE
;
8766 htab
->plt_initial_entry_size
= VXWORKS_PLT_INITIAL_ENTRY_SIZE
;
8771 /* Tweak magic VxWorks symbols as they are loaded. */
8773 ppc_elf_vxworks_add_symbol_hook (bfd
*abfd
,
8774 struct bfd_link_info
*info
,
8775 Elf_Internal_Sym
*sym
,
8776 const char **namep ATTRIBUTE_UNUSED
,
8777 flagword
*flagsp ATTRIBUTE_UNUSED
,
8781 if (!elf_vxworks_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
,
8785 return ppc_elf_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
, valp
);
8789 ppc_elf_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
8791 ppc_elf_final_write_processing(abfd
, linker
);
8792 elf_vxworks_final_write_processing(abfd
, linker
);
8795 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
8797 #undef elf_backend_want_plt_sym
8798 #define elf_backend_want_plt_sym 1
8799 #undef elf_backend_want_got_plt
8800 #define elf_backend_want_got_plt 1
8801 #undef elf_backend_got_symbol_offset
8802 #define elf_backend_got_symbol_offset 0
8803 #undef elf_backend_plt_not_loaded
8804 #define elf_backend_plt_not_loaded 0
8805 #undef elf_backend_plt_readonly
8806 #define elf_backend_plt_readonly 1
8807 #undef elf_backend_got_header_size
8808 #define elf_backend_got_header_size 12
8810 #undef bfd_elf32_get_synthetic_symtab
8812 #undef bfd_elf32_bfd_link_hash_table_create
8813 #define bfd_elf32_bfd_link_hash_table_create \
8814 ppc_elf_vxworks_link_hash_table_create
8815 #undef elf_backend_add_symbol_hook
8816 #define elf_backend_add_symbol_hook \
8817 ppc_elf_vxworks_add_symbol_hook
8818 #undef elf_backend_link_output_symbol_hook
8819 #define elf_backend_link_output_symbol_hook \
8820 elf_vxworks_link_output_symbol_hook
8821 #undef elf_backend_final_write_processing
8822 #define elf_backend_final_write_processing \
8823 ppc_elf_vxworks_final_write_processing
8824 #undef elf_backend_get_sec_type_attr
8825 #define elf_backend_get_sec_type_attr \
8826 ppc_elf_vxworks_get_sec_type_attr
8827 #undef elf_backend_emit_relocs
8828 #define elf_backend_emit_relocs \
8829 elf_vxworks_emit_relocs
8832 #define elf32_bed ppc_elf_vxworks_bed
8833 #undef elf_backend_post_process_headers
8835 #include "elf32-target.h"