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, 2010, 2011
4 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor, Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the
21 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 /* This file is based on a preliminary PowerPC ELF ABI. The
26 information may not match the final PowerPC ELF ABI. It includes
27 suggestions from the in-progress Embedded PowerPC ABI, and that
28 information may also not match. */
37 #include "elf32-ppc.h"
38 #include "elf-vxworks.h"
41 /* RELA relocations are used here. */
43 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
44 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
45 static bfd_reloc_status_type ppc_elf_unhandled_reloc
46 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 /* Branch prediction bit for branch taken relocs. */
49 #define BRANCH_PREDICT_BIT 0x200000
50 /* Mask to set RA in memory instructions. */
51 #define RA_REGISTER_MASK 0x001f0000
52 /* Value to shift register by to insert RA. */
53 #define RA_REGISTER_SHIFT 16
55 /* The name of the dynamic interpreter. This is put in the .interp
57 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
59 /* For old-style PLT. */
60 /* The number of single-slot PLT entries (the rest use two slots). */
61 #define PLT_NUM_SINGLE_ENTRIES 8192
63 /* For new-style .glink and .plt. */
64 #define GLINK_PLTRESOLVE 16*4
65 #define GLINK_ENTRY_SIZE 4*4
66 #define TLS_GET_ADDR_GLINK_SIZE 12*4
68 /* VxWorks uses its own plt layout, filled in by the static linker. */
70 /* The standard VxWorks PLT entry. */
71 #define VXWORKS_PLT_ENTRY_SIZE 32
72 static const bfd_vma ppc_elf_vxworks_plt_entry
73 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
75 0x3d800000, /* lis r12,0 */
76 0x818c0000, /* lwz r12,0(r12) */
77 0x7d8903a6, /* mtctr r12 */
78 0x4e800420, /* bctr */
79 0x39600000, /* li r11,0 */
80 0x48000000, /* b 14 <.PLT0resolve+0x4> */
84 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
85 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
87 0x3d9e0000, /* addis r12,r30,0 */
88 0x818c0000, /* lwz r12,0(r12) */
89 0x7d8903a6, /* mtctr r12 */
90 0x4e800420, /* bctr */
91 0x39600000, /* li r11,0 */
92 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
97 /* The initial VxWorks PLT entry. */
98 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
99 static const bfd_vma ppc_elf_vxworks_plt0_entry
100 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
102 0x3d800000, /* lis r12,0 */
103 0x398c0000, /* addi r12,r12,0 */
104 0x800c0008, /* lwz r0,8(r12) */
105 0x7c0903a6, /* mtctr r0 */
106 0x818c0004, /* lwz r12,4(r12) */
107 0x4e800420, /* bctr */
108 0x60000000, /* nop */
109 0x60000000, /* nop */
111 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
112 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
114 0x819e0008, /* lwz r12,8(r30) */
115 0x7d8903a6, /* mtctr r12 */
116 0x819e0004, /* lwz r12,4(r30) */
117 0x4e800420, /* bctr */
118 0x60000000, /* nop */
119 0x60000000, /* nop */
120 0x60000000, /* nop */
121 0x60000000, /* nop */
124 /* For executables, we have some additional relocations in
125 .rela.plt.unloaded, for the kernel loader. */
127 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
128 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
129 /* The number of relocations in the PLTResolve slot. */
130 #define VXWORKS_PLTRESOLVE_RELOCS 2
131 /* The number of relocations in the PLTResolve slot when when creating
133 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
135 /* Some instructions. */
136 #define ADDIS_11_11 0x3d6b0000
137 #define ADDIS_11_30 0x3d7e0000
138 #define ADDIS_12_12 0x3d8c0000
139 #define ADDI_11_11 0x396b0000
140 #define ADD_0_11_11 0x7c0b5a14
141 #define ADD_3_12_2 0x7c6c1214
142 #define ADD_11_0_11 0x7d605a14
144 #define BCL_20_31 0x429f0005
145 #define BCTR 0x4e800420
146 #define BEQLR 0x4d820020
147 #define CMPWI_11_0 0x2c0b0000
148 #define LIS_11 0x3d600000
149 #define LIS_12 0x3d800000
150 #define LWZU_0_12 0x840c0000
151 #define LWZ_0_12 0x800c0000
152 #define LWZ_11_3 0x81630000
153 #define LWZ_11_11 0x816b0000
154 #define LWZ_11_30 0x817e0000
155 #define LWZ_12_3 0x81830000
156 #define LWZ_12_12 0x818c0000
157 #define MR_0_3 0x7c601b78
158 #define MR_3_0 0x7c030378
159 #define MFLR_0 0x7c0802a6
160 #define MFLR_12 0x7d8802a6
161 #define MTCTR_0 0x7c0903a6
162 #define MTCTR_11 0x7d6903a6
163 #define MTLR_0 0x7c0803a6
164 #define NOP 0x60000000
165 #define SUB_11_11_12 0x7d6c5850
167 /* Offset of tp and dtp pointers from start of TLS block. */
168 #define TP_OFFSET 0x7000
169 #define DTP_OFFSET 0x8000
171 /* The value of a defined global symbol. */
172 #define SYM_VAL(SYM) \
173 ((SYM)->root.u.def.section->output_section->vma \
174 + (SYM)->root.u.def.section->output_offset \
175 + (SYM)->root.u.def.value)
177 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
179 static reloc_howto_type ppc_elf_howto_raw
[] = {
180 /* This reloc does nothing. */
181 HOWTO (R_PPC_NONE
, /* type */
183 2, /* size (0 = byte, 1 = short, 2 = long) */
185 FALSE
, /* pc_relative */
187 complain_overflow_bitfield
, /* complain_on_overflow */
188 bfd_elf_generic_reloc
, /* special_function */
189 "R_PPC_NONE", /* name */
190 FALSE
, /* partial_inplace */
193 FALSE
), /* pcrel_offset */
195 /* A standard 32 bit relocation. */
196 HOWTO (R_PPC_ADDR32
, /* type */
198 2, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE
, /* pc_relative */
202 complain_overflow_bitfield
, /* complain_on_overflow */
203 bfd_elf_generic_reloc
, /* special_function */
204 "R_PPC_ADDR32", /* name */
205 FALSE
, /* partial_inplace */
207 0xffffffff, /* dst_mask */
208 FALSE
), /* pcrel_offset */
210 /* An absolute 26 bit branch; the lower two bits must be zero.
211 FIXME: we don't check that, we just clear them. */
212 HOWTO (R_PPC_ADDR24
, /* type */
214 2, /* size (0 = byte, 1 = short, 2 = long) */
216 FALSE
, /* pc_relative */
218 complain_overflow_bitfield
, /* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_PPC_ADDR24", /* name */
221 FALSE
, /* partial_inplace */
223 0x3fffffc, /* dst_mask */
224 FALSE
), /* pcrel_offset */
226 /* A standard 16 bit relocation. */
227 HOWTO (R_PPC_ADDR16
, /* type */
229 1, /* size (0 = byte, 1 = short, 2 = long) */
231 FALSE
, /* pc_relative */
233 complain_overflow_bitfield
, /* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_PPC_ADDR16", /* name */
236 FALSE
, /* partial_inplace */
238 0xffff, /* dst_mask */
239 FALSE
), /* pcrel_offset */
241 /* A 16 bit relocation without overflow. */
242 HOWTO (R_PPC_ADDR16_LO
, /* type */
244 1, /* size (0 = byte, 1 = short, 2 = long) */
246 FALSE
, /* pc_relative */
248 complain_overflow_dont
,/* complain_on_overflow */
249 bfd_elf_generic_reloc
, /* special_function */
250 "R_PPC_ADDR16_LO", /* name */
251 FALSE
, /* partial_inplace */
253 0xffff, /* dst_mask */
254 FALSE
), /* pcrel_offset */
256 /* The high order 16 bits of an address. */
257 HOWTO (R_PPC_ADDR16_HI
, /* type */
259 1, /* size (0 = byte, 1 = short, 2 = long) */
261 FALSE
, /* pc_relative */
263 complain_overflow_dont
, /* complain_on_overflow */
264 bfd_elf_generic_reloc
, /* special_function */
265 "R_PPC_ADDR16_HI", /* name */
266 FALSE
, /* partial_inplace */
268 0xffff, /* dst_mask */
269 FALSE
), /* pcrel_offset */
271 /* The high order 16 bits of an address, plus 1 if the contents of
272 the low 16 bits, treated as a signed number, is negative. */
273 HOWTO (R_PPC_ADDR16_HA
, /* type */
275 1, /* size (0 = byte, 1 = short, 2 = long) */
277 FALSE
, /* pc_relative */
279 complain_overflow_dont
, /* complain_on_overflow */
280 ppc_elf_addr16_ha_reloc
, /* special_function */
281 "R_PPC_ADDR16_HA", /* name */
282 FALSE
, /* partial_inplace */
284 0xffff, /* dst_mask */
285 FALSE
), /* pcrel_offset */
287 /* An absolute 16 bit branch; the lower two bits must be zero.
288 FIXME: we don't check that, we just clear them. */
289 HOWTO (R_PPC_ADDR14
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_bitfield
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_PPC_ADDR14", /* name */
298 FALSE
, /* partial_inplace */
300 0xfffc, /* dst_mask */
301 FALSE
), /* pcrel_offset */
303 /* An absolute 16 bit branch, for which bit 10 should be set to
304 indicate that the branch is expected to be taken. The lower two
305 bits must be zero. */
306 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 FALSE
, /* pc_relative */
312 complain_overflow_bitfield
, /* complain_on_overflow */
313 bfd_elf_generic_reloc
, /* special_function */
314 "R_PPC_ADDR14_BRTAKEN",/* name */
315 FALSE
, /* partial_inplace */
317 0xfffc, /* dst_mask */
318 FALSE
), /* pcrel_offset */
320 /* An absolute 16 bit branch, for which bit 10 should be set to
321 indicate that the branch is not expected to be taken. The lower
322 two bits must be zero. */
323 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_bitfield
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_PPC_ADDR14_BRNTAKEN",/* name */
332 FALSE
, /* partial_inplace */
334 0xfffc, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* A relative 26 bit branch; the lower two bits must be zero. */
338 HOWTO (R_PPC_REL24
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 TRUE
, /* pc_relative */
344 complain_overflow_signed
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_PPC_REL24", /* name */
347 FALSE
, /* partial_inplace */
349 0x3fffffc, /* dst_mask */
350 TRUE
), /* pcrel_offset */
352 /* A relative 16 bit branch; the lower two bits must be zero. */
353 HOWTO (R_PPC_REL14
, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 TRUE
, /* pc_relative */
359 complain_overflow_signed
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_PPC_REL14", /* name */
362 FALSE
, /* partial_inplace */
364 0xfffc, /* dst_mask */
365 TRUE
), /* pcrel_offset */
367 /* A relative 16 bit branch. Bit 10 should be set to indicate that
368 the branch is expected to be taken. The lower two bits must be
370 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 TRUE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_PPC_REL14_BRTAKEN", /* name */
379 FALSE
, /* partial_inplace */
381 0xfffc, /* dst_mask */
382 TRUE
), /* pcrel_offset */
384 /* A relative 16 bit branch. Bit 10 should be set to indicate that
385 the branch is not expected to be taken. The lower two bits must
387 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 TRUE
, /* pc_relative */
393 complain_overflow_signed
, /* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_PPC_REL14_BRNTAKEN",/* name */
396 FALSE
, /* partial_inplace */
398 0xfffc, /* dst_mask */
399 TRUE
), /* pcrel_offset */
401 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
403 HOWTO (R_PPC_GOT16
, /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE
, /* pc_relative */
409 complain_overflow_signed
, /* complain_on_overflow */
410 bfd_elf_generic_reloc
, /* special_function */
411 "R_PPC_GOT16", /* name */
412 FALSE
, /* partial_inplace */
414 0xffff, /* dst_mask */
415 FALSE
), /* pcrel_offset */
417 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
419 HOWTO (R_PPC_GOT16_LO
, /* type */
421 1, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE
, /* pc_relative */
425 complain_overflow_dont
, /* complain_on_overflow */
426 bfd_elf_generic_reloc
, /* special_function */
427 "R_PPC_GOT16_LO", /* name */
428 FALSE
, /* partial_inplace */
430 0xffff, /* dst_mask */
431 FALSE
), /* pcrel_offset */
433 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
435 HOWTO (R_PPC_GOT16_HI
, /* type */
437 1, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE
, /* pc_relative */
441 complain_overflow_bitfield
, /* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_PPC_GOT16_HI", /* name */
444 FALSE
, /* partial_inplace */
446 0xffff, /* dst_mask */
447 FALSE
), /* pcrel_offset */
449 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
451 HOWTO (R_PPC_GOT16_HA
, /* type */
453 1, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_bitfield
, /* complain_on_overflow */
458 ppc_elf_addr16_ha_reloc
, /* special_function */
459 "R_PPC_GOT16_HA", /* name */
460 FALSE
, /* partial_inplace */
462 0xffff, /* dst_mask */
463 FALSE
), /* pcrel_offset */
465 /* Like R_PPC_REL24, but referring to the procedure linkage table
466 entry for the symbol. */
467 HOWTO (R_PPC_PLTREL24
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_PPC_PLTREL24", /* name */
476 FALSE
, /* partial_inplace */
478 0x3fffffc, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 /* This is used only by the dynamic linker. The symbol should exist
482 both in the object being run and in some shared library. The
483 dynamic linker copies the data addressed by the symbol from the
484 shared library into the object, because the object being
485 run has to have the data at some particular address. */
486 HOWTO (R_PPC_COPY
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 FALSE
, /* pc_relative */
492 complain_overflow_bitfield
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_PPC_COPY", /* name */
495 FALSE
, /* partial_inplace */
498 FALSE
), /* pcrel_offset */
500 /* Like R_PPC_ADDR32, but used when setting global offset table
502 HOWTO (R_PPC_GLOB_DAT
, /* type */
504 2, /* size (0 = byte, 1 = short, 2 = long) */
506 FALSE
, /* pc_relative */
508 complain_overflow_bitfield
, /* complain_on_overflow */
509 bfd_elf_generic_reloc
, /* special_function */
510 "R_PPC_GLOB_DAT", /* name */
511 FALSE
, /* partial_inplace */
513 0xffffffff, /* dst_mask */
514 FALSE
), /* pcrel_offset */
516 /* Marks a procedure linkage table entry for a symbol. */
517 HOWTO (R_PPC_JMP_SLOT
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 FALSE
, /* pc_relative */
523 complain_overflow_bitfield
, /* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_PPC_JMP_SLOT", /* name */
526 FALSE
, /* partial_inplace */
529 FALSE
), /* pcrel_offset */
531 /* Used only by the dynamic linker. When the object is run, this
532 longword is set to the load address of the object, plus the
534 HOWTO (R_PPC_RELATIVE
, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE
, /* pc_relative */
540 complain_overflow_bitfield
, /* complain_on_overflow */
541 bfd_elf_generic_reloc
, /* special_function */
542 "R_PPC_RELATIVE", /* name */
543 FALSE
, /* partial_inplace */
545 0xffffffff, /* dst_mask */
546 FALSE
), /* pcrel_offset */
548 /* Like R_PPC_REL24, but uses the value of the symbol within the
549 object rather than the final value. Normally used for
550 _GLOBAL_OFFSET_TABLE_. */
551 HOWTO (R_PPC_LOCAL24PC
, /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 TRUE
, /* pc_relative */
557 complain_overflow_signed
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 "R_PPC_LOCAL24PC", /* name */
560 FALSE
, /* partial_inplace */
562 0x3fffffc, /* dst_mask */
563 TRUE
), /* pcrel_offset */
565 /* Like R_PPC_ADDR32, but may be unaligned. */
566 HOWTO (R_PPC_UADDR32
, /* type */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
570 FALSE
, /* pc_relative */
572 complain_overflow_bitfield
, /* complain_on_overflow */
573 bfd_elf_generic_reloc
, /* special_function */
574 "R_PPC_UADDR32", /* name */
575 FALSE
, /* partial_inplace */
577 0xffffffff, /* dst_mask */
578 FALSE
), /* pcrel_offset */
580 /* Like R_PPC_ADDR16, but may be unaligned. */
581 HOWTO (R_PPC_UADDR16
, /* type */
583 1, /* size (0 = byte, 1 = short, 2 = long) */
585 FALSE
, /* pc_relative */
587 complain_overflow_bitfield
, /* complain_on_overflow */
588 bfd_elf_generic_reloc
, /* special_function */
589 "R_PPC_UADDR16", /* name */
590 FALSE
, /* partial_inplace */
592 0xffff, /* dst_mask */
593 FALSE
), /* pcrel_offset */
595 /* 32-bit PC relative */
596 HOWTO (R_PPC_REL32
, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 TRUE
, /* pc_relative */
602 complain_overflow_bitfield
, /* complain_on_overflow */
603 bfd_elf_generic_reloc
, /* special_function */
604 "R_PPC_REL32", /* name */
605 FALSE
, /* partial_inplace */
607 0xffffffff, /* dst_mask */
608 TRUE
), /* pcrel_offset */
610 /* 32-bit relocation to the symbol's procedure linkage table.
611 FIXME: not supported. */
612 HOWTO (R_PPC_PLT32
, /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_bitfield
, /* complain_on_overflow */
619 bfd_elf_generic_reloc
, /* special_function */
620 "R_PPC_PLT32", /* name */
621 FALSE
, /* partial_inplace */
624 FALSE
), /* pcrel_offset */
626 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
627 FIXME: not supported. */
628 HOWTO (R_PPC_PLTREL32
, /* type */
630 2, /* size (0 = byte, 1 = short, 2 = long) */
632 TRUE
, /* pc_relative */
634 complain_overflow_bitfield
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_PPC_PLTREL32", /* name */
637 FALSE
, /* partial_inplace */
640 TRUE
), /* pcrel_offset */
642 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
644 HOWTO (R_PPC_PLT16_LO
, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 FALSE
, /* pc_relative */
650 complain_overflow_dont
, /* complain_on_overflow */
651 bfd_elf_generic_reloc
, /* special_function */
652 "R_PPC_PLT16_LO", /* name */
653 FALSE
, /* partial_inplace */
655 0xffff, /* dst_mask */
656 FALSE
), /* pcrel_offset */
658 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
660 HOWTO (R_PPC_PLT16_HI
, /* type */
662 1, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_bitfield
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_PPC_PLT16_HI", /* name */
669 FALSE
, /* partial_inplace */
671 0xffff, /* dst_mask */
672 FALSE
), /* pcrel_offset */
674 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
676 HOWTO (R_PPC_PLT16_HA
, /* type */
678 1, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_bitfield
, /* complain_on_overflow */
683 ppc_elf_addr16_ha_reloc
, /* special_function */
684 "R_PPC_PLT16_HA", /* name */
685 FALSE
, /* partial_inplace */
687 0xffff, /* dst_mask */
688 FALSE
), /* pcrel_offset */
690 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
692 HOWTO (R_PPC_SDAREL16
, /* type */
694 1, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE
, /* pc_relative */
698 complain_overflow_signed
, /* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_PPC_SDAREL16", /* name */
701 FALSE
, /* partial_inplace */
703 0xffff, /* dst_mask */
704 FALSE
), /* pcrel_offset */
706 /* 16-bit section relative relocation. */
707 HOWTO (R_PPC_SECTOFF
, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE
, /* pc_relative */
713 complain_overflow_bitfield
, /* complain_on_overflow */
714 bfd_elf_generic_reloc
, /* special_function */
715 "R_PPC_SECTOFF", /* name */
716 FALSE
, /* partial_inplace */
718 0xffff, /* dst_mask */
719 FALSE
), /* pcrel_offset */
721 /* 16-bit lower half section relative relocation. */
722 HOWTO (R_PPC_SECTOFF_LO
, /* type */
724 1, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE
, /* pc_relative */
728 complain_overflow_dont
, /* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 "R_PPC_SECTOFF_LO", /* name */
731 FALSE
, /* partial_inplace */
733 0xffff, /* dst_mask */
734 FALSE
), /* pcrel_offset */
736 /* 16-bit upper half section relative relocation. */
737 HOWTO (R_PPC_SECTOFF_HI
, /* type */
739 1, /* size (0 = byte, 1 = short, 2 = long) */
741 FALSE
, /* pc_relative */
743 complain_overflow_bitfield
, /* complain_on_overflow */
744 bfd_elf_generic_reloc
, /* special_function */
745 "R_PPC_SECTOFF_HI", /* name */
746 FALSE
, /* partial_inplace */
748 0xffff, /* dst_mask */
749 FALSE
), /* pcrel_offset */
751 /* 16-bit upper half adjusted section relative relocation. */
752 HOWTO (R_PPC_SECTOFF_HA
, /* type */
754 1, /* size (0 = byte, 1 = short, 2 = long) */
756 FALSE
, /* pc_relative */
758 complain_overflow_bitfield
, /* complain_on_overflow */
759 ppc_elf_addr16_ha_reloc
, /* special_function */
760 "R_PPC_SECTOFF_HA", /* name */
761 FALSE
, /* partial_inplace */
763 0xffff, /* dst_mask */
764 FALSE
), /* pcrel_offset */
766 /* Marker relocs for TLS. */
769 2, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE
, /* pc_relative */
773 complain_overflow_dont
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_PPC_TLS", /* name */
776 FALSE
, /* partial_inplace */
779 FALSE
), /* pcrel_offset */
783 2, /* size (0 = byte, 1 = short, 2 = long) */
785 FALSE
, /* pc_relative */
787 complain_overflow_dont
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_PPC_TLSGD", /* name */
790 FALSE
, /* partial_inplace */
793 FALSE
), /* pcrel_offset */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 FALSE
, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_PPC_TLSLD", /* name */
804 FALSE
, /* partial_inplace */
807 FALSE
), /* pcrel_offset */
809 /* Computes the load module index of the load module that contains the
810 definition of its TLS sym. */
811 HOWTO (R_PPC_DTPMOD32
,
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE
, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 ppc_elf_unhandled_reloc
, /* special_function */
819 "R_PPC_DTPMOD32", /* name */
820 FALSE
, /* partial_inplace */
822 0xffffffff, /* dst_mask */
823 FALSE
), /* pcrel_offset */
825 /* Computes a dtv-relative displacement, the difference between the value
826 of sym+add and the base address of the thread-local storage block that
827 contains the definition of sym, minus 0x8000. */
828 HOWTO (R_PPC_DTPREL32
,
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 FALSE
, /* pc_relative */
834 complain_overflow_dont
, /* complain_on_overflow */
835 ppc_elf_unhandled_reloc
, /* special_function */
836 "R_PPC_DTPREL32", /* name */
837 FALSE
, /* partial_inplace */
839 0xffffffff, /* dst_mask */
840 FALSE
), /* pcrel_offset */
842 /* A 16 bit dtprel reloc. */
843 HOWTO (R_PPC_DTPREL16
,
845 1, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_signed
, /* complain_on_overflow */
850 ppc_elf_unhandled_reloc
, /* special_function */
851 "R_PPC_DTPREL16", /* name */
852 FALSE
, /* partial_inplace */
854 0xffff, /* dst_mask */
855 FALSE
), /* pcrel_offset */
857 /* Like DTPREL16, but no overflow. */
858 HOWTO (R_PPC_DTPREL16_LO
,
860 1, /* size (0 = byte, 1 = short, 2 = long) */
862 FALSE
, /* pc_relative */
864 complain_overflow_dont
, /* complain_on_overflow */
865 ppc_elf_unhandled_reloc
, /* special_function */
866 "R_PPC_DTPREL16_LO", /* name */
867 FALSE
, /* partial_inplace */
869 0xffff, /* dst_mask */
870 FALSE
), /* pcrel_offset */
872 /* Like DTPREL16_LO, but next higher group of 16 bits. */
873 HOWTO (R_PPC_DTPREL16_HI
,
875 1, /* size (0 = byte, 1 = short, 2 = long) */
877 FALSE
, /* pc_relative */
879 complain_overflow_dont
, /* complain_on_overflow */
880 ppc_elf_unhandled_reloc
, /* special_function */
881 "R_PPC_DTPREL16_HI", /* name */
882 FALSE
, /* partial_inplace */
884 0xffff, /* dst_mask */
885 FALSE
), /* pcrel_offset */
887 /* Like DTPREL16_HI, but adjust for low 16 bits. */
888 HOWTO (R_PPC_DTPREL16_HA
,
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 ppc_elf_unhandled_reloc
, /* special_function */
896 "R_PPC_DTPREL16_HA", /* name */
897 FALSE
, /* partial_inplace */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* Computes a tp-relative displacement, the difference between the value of
903 sym+add and the value of the thread pointer (r13). */
904 HOWTO (R_PPC_TPREL32
,
906 2, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_dont
, /* complain_on_overflow */
911 ppc_elf_unhandled_reloc
, /* special_function */
912 "R_PPC_TPREL32", /* name */
913 FALSE
, /* partial_inplace */
915 0xffffffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* A 16 bit tprel reloc. */
919 HOWTO (R_PPC_TPREL16
,
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_signed
, /* complain_on_overflow */
926 ppc_elf_unhandled_reloc
, /* special_function */
927 "R_PPC_TPREL16", /* name */
928 FALSE
, /* partial_inplace */
930 0xffff, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* Like TPREL16, but no overflow. */
934 HOWTO (R_PPC_TPREL16_LO
,
936 1, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
, /* complain_on_overflow */
941 ppc_elf_unhandled_reloc
, /* special_function */
942 "R_PPC_TPREL16_LO", /* name */
943 FALSE
, /* partial_inplace */
945 0xffff, /* dst_mask */
946 FALSE
), /* pcrel_offset */
948 /* Like TPREL16_LO, but next higher group of 16 bits. */
949 HOWTO (R_PPC_TPREL16_HI
,
951 1, /* size (0 = byte, 1 = short, 2 = long) */
953 FALSE
, /* pc_relative */
955 complain_overflow_dont
, /* complain_on_overflow */
956 ppc_elf_unhandled_reloc
, /* special_function */
957 "R_PPC_TPREL16_HI", /* name */
958 FALSE
, /* partial_inplace */
960 0xffff, /* dst_mask */
961 FALSE
), /* pcrel_offset */
963 /* Like TPREL16_HI, but adjust for low 16 bits. */
964 HOWTO (R_PPC_TPREL16_HA
,
966 1, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_dont
, /* complain_on_overflow */
971 ppc_elf_unhandled_reloc
, /* special_function */
972 "R_PPC_TPREL16_HA", /* name */
973 FALSE
, /* partial_inplace */
975 0xffff, /* dst_mask */
976 FALSE
), /* pcrel_offset */
978 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
979 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
980 to the first entry. */
981 HOWTO (R_PPC_GOT_TLSGD16
,
983 1, /* size (0 = byte, 1 = short, 2 = long) */
985 FALSE
, /* pc_relative */
987 complain_overflow_signed
, /* complain_on_overflow */
988 ppc_elf_unhandled_reloc
, /* special_function */
989 "R_PPC_GOT_TLSGD16", /* name */
990 FALSE
, /* partial_inplace */
992 0xffff, /* dst_mask */
993 FALSE
), /* pcrel_offset */
995 /* Like GOT_TLSGD16, but no overflow. */
996 HOWTO (R_PPC_GOT_TLSGD16_LO
,
998 1, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE
, /* pc_relative */
1002 complain_overflow_dont
, /* complain_on_overflow */
1003 ppc_elf_unhandled_reloc
, /* special_function */
1004 "R_PPC_GOT_TLSGD16_LO", /* name */
1005 FALSE
, /* partial_inplace */
1007 0xffff, /* dst_mask */
1008 FALSE
), /* pcrel_offset */
1010 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1011 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1012 16, /* rightshift */
1013 1, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE
, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 ppc_elf_unhandled_reloc
, /* special_function */
1019 "R_PPC_GOT_TLSGD16_HI", /* name */
1020 FALSE
, /* partial_inplace */
1022 0xffff, /* dst_mask */
1023 FALSE
), /* pcrel_offset */
1025 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1026 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1027 16, /* rightshift */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_dont
, /* complain_on_overflow */
1033 ppc_elf_unhandled_reloc
, /* special_function */
1034 "R_PPC_GOT_TLSGD16_HA", /* name */
1035 FALSE
, /* partial_inplace */
1037 0xffff, /* dst_mask */
1038 FALSE
), /* pcrel_offset */
1040 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1041 with values (sym+add)@dtpmod and zero, and computes the offset to the
1043 HOWTO (R_PPC_GOT_TLSLD16
,
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_signed
, /* complain_on_overflow */
1050 ppc_elf_unhandled_reloc
, /* special_function */
1051 "R_PPC_GOT_TLSLD16", /* name */
1052 FALSE
, /* partial_inplace */
1054 0xffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* Like GOT_TLSLD16, but no overflow. */
1058 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE
, /* pc_relative */
1064 complain_overflow_dont
, /* complain_on_overflow */
1065 ppc_elf_unhandled_reloc
, /* special_function */
1066 "R_PPC_GOT_TLSLD16_LO", /* name */
1067 FALSE
, /* partial_inplace */
1069 0xffff, /* dst_mask */
1070 FALSE
), /* pcrel_offset */
1072 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1073 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1074 16, /* rightshift */
1075 1, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_dont
, /* complain_on_overflow */
1080 ppc_elf_unhandled_reloc
, /* special_function */
1081 "R_PPC_GOT_TLSLD16_HI", /* name */
1082 FALSE
, /* partial_inplace */
1084 0xffff, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1087 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1088 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1089 16, /* rightshift */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 ppc_elf_unhandled_reloc
, /* special_function */
1096 "R_PPC_GOT_TLSLD16_HA", /* name */
1097 FALSE
, /* partial_inplace */
1099 0xffff, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1103 the offset to the entry. */
1104 HOWTO (R_PPC_GOT_DTPREL16
,
1106 1, /* size (0 = byte, 1 = short, 2 = long) */
1108 FALSE
, /* pc_relative */
1110 complain_overflow_signed
, /* complain_on_overflow */
1111 ppc_elf_unhandled_reloc
, /* special_function */
1112 "R_PPC_GOT_DTPREL16", /* name */
1113 FALSE
, /* partial_inplace */
1115 0xffff, /* dst_mask */
1116 FALSE
), /* pcrel_offset */
1118 /* Like GOT_DTPREL16, but no overflow. */
1119 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1121 1, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE
, /* pc_relative */
1125 complain_overflow_dont
, /* complain_on_overflow */
1126 ppc_elf_unhandled_reloc
, /* special_function */
1127 "R_PPC_GOT_DTPREL16_LO", /* name */
1128 FALSE
, /* partial_inplace */
1130 0xffff, /* dst_mask */
1131 FALSE
), /* pcrel_offset */
1133 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1134 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1135 16, /* rightshift */
1136 1, /* size (0 = byte, 1 = short, 2 = long) */
1138 FALSE
, /* pc_relative */
1140 complain_overflow_dont
, /* complain_on_overflow */
1141 ppc_elf_unhandled_reloc
, /* special_function */
1142 "R_PPC_GOT_DTPREL16_HI", /* name */
1143 FALSE
, /* partial_inplace */
1145 0xffff, /* dst_mask */
1146 FALSE
), /* pcrel_offset */
1148 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1149 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1150 16, /* rightshift */
1151 1, /* size (0 = byte, 1 = short, 2 = long) */
1153 FALSE
, /* pc_relative */
1155 complain_overflow_dont
, /* complain_on_overflow */
1156 ppc_elf_unhandled_reloc
, /* special_function */
1157 "R_PPC_GOT_DTPREL16_HA", /* name */
1158 FALSE
, /* partial_inplace */
1160 0xffff, /* dst_mask */
1161 FALSE
), /* pcrel_offset */
1163 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1164 offset to the entry. */
1165 HOWTO (R_PPC_GOT_TPREL16
,
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_signed
, /* complain_on_overflow */
1172 ppc_elf_unhandled_reloc
, /* special_function */
1173 "R_PPC_GOT_TPREL16", /* name */
1174 FALSE
, /* partial_inplace */
1176 0xffff, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Like GOT_TPREL16, but no overflow. */
1180 HOWTO (R_PPC_GOT_TPREL16_LO
,
1182 1, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE
, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 ppc_elf_unhandled_reloc
, /* special_function */
1188 "R_PPC_GOT_TPREL16_LO", /* name */
1189 FALSE
, /* partial_inplace */
1191 0xffff, /* dst_mask */
1192 FALSE
), /* pcrel_offset */
1194 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1195 HOWTO (R_PPC_GOT_TPREL16_HI
,
1196 16, /* rightshift */
1197 1, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 ppc_elf_unhandled_reloc
, /* special_function */
1203 "R_PPC_GOT_TPREL16_HI", /* name */
1204 FALSE
, /* partial_inplace */
1206 0xffff, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1210 HOWTO (R_PPC_GOT_TPREL16_HA
,
1211 16, /* rightshift */
1212 1, /* size (0 = byte, 1 = short, 2 = long) */
1214 FALSE
, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 ppc_elf_unhandled_reloc
, /* special_function */
1218 "R_PPC_GOT_TPREL16_HA", /* name */
1219 FALSE
, /* partial_inplace */
1221 0xffff, /* dst_mask */
1222 FALSE
), /* pcrel_offset */
1224 /* The remaining relocs are from the Embedded ELF ABI, and are not
1225 in the SVR4 ELF ABI. */
1227 /* 32 bit value resulting from the addend minus the symbol. */
1228 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1230 2, /* size (0 = byte, 1 = short, 2 = long) */
1232 FALSE
, /* pc_relative */
1234 complain_overflow_bitfield
, /* complain_on_overflow */
1235 bfd_elf_generic_reloc
, /* special_function */
1236 "R_PPC_EMB_NADDR32", /* name */
1237 FALSE
, /* partial_inplace */
1239 0xffffffff, /* dst_mask */
1240 FALSE
), /* pcrel_offset */
1242 /* 16 bit value resulting from the addend minus the symbol. */
1243 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1245 1, /* size (0 = byte, 1 = short, 2 = long) */
1247 FALSE
, /* pc_relative */
1249 complain_overflow_bitfield
, /* complain_on_overflow */
1250 bfd_elf_generic_reloc
, /* special_function */
1251 "R_PPC_EMB_NADDR16", /* name */
1252 FALSE
, /* partial_inplace */
1254 0xffff, /* dst_mask */
1255 FALSE
), /* pcrel_offset */
1257 /* 16 bit value resulting from the addend minus the symbol. */
1258 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1260 1, /* size (0 = byte, 1 = short, 2 = long) */
1262 FALSE
, /* pc_relative */
1264 complain_overflow_dont
,/* complain_on_overflow */
1265 bfd_elf_generic_reloc
, /* special_function */
1266 "R_PPC_EMB_ADDR16_LO", /* name */
1267 FALSE
, /* partial_inplace */
1269 0xffff, /* dst_mask */
1270 FALSE
), /* pcrel_offset */
1272 /* The high order 16 bits of the addend minus the symbol. */
1273 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1274 16, /* rightshift */
1275 1, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE
, /* pc_relative */
1279 complain_overflow_dont
, /* complain_on_overflow */
1280 bfd_elf_generic_reloc
, /* special_function */
1281 "R_PPC_EMB_NADDR16_HI", /* name */
1282 FALSE
, /* partial_inplace */
1284 0xffff, /* dst_mask */
1285 FALSE
), /* pcrel_offset */
1287 /* The high order 16 bits of the result of the addend minus the address,
1288 plus 1 if the contents of the low 16 bits, treated as a signed number,
1290 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1291 16, /* rightshift */
1292 1, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE
, /* pc_relative */
1296 complain_overflow_dont
, /* complain_on_overflow */
1297 ppc_elf_addr16_ha_reloc
, /* special_function */
1298 "R_PPC_EMB_NADDR16_HA", /* name */
1299 FALSE
, /* partial_inplace */
1301 0xffff, /* dst_mask */
1302 FALSE
), /* pcrel_offset */
1304 /* 16 bit value resulting from allocating a 4 byte word to hold an
1305 address in the .sdata section, and returning the offset from
1306 _SDA_BASE_ for that relocation. */
1307 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1309 1, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE
, /* pc_relative */
1313 complain_overflow_signed
, /* complain_on_overflow */
1314 bfd_elf_generic_reloc
, /* special_function */
1315 "R_PPC_EMB_SDAI16", /* name */
1316 FALSE
, /* partial_inplace */
1318 0xffff, /* dst_mask */
1319 FALSE
), /* pcrel_offset */
1321 /* 16 bit value resulting from allocating a 4 byte word to hold an
1322 address in the .sdata2 section, and returning the offset from
1323 _SDA2_BASE_ for that relocation. */
1324 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1326 1, /* size (0 = byte, 1 = short, 2 = long) */
1328 FALSE
, /* pc_relative */
1330 complain_overflow_signed
, /* complain_on_overflow */
1331 bfd_elf_generic_reloc
, /* special_function */
1332 "R_PPC_EMB_SDA2I16", /* name */
1333 FALSE
, /* partial_inplace */
1335 0xffff, /* dst_mask */
1336 FALSE
), /* pcrel_offset */
1338 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1339 small data items. */
1340 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1342 1, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE
, /* pc_relative */
1346 complain_overflow_signed
, /* complain_on_overflow */
1347 bfd_elf_generic_reloc
, /* special_function */
1348 "R_PPC_EMB_SDA2REL", /* name */
1349 FALSE
, /* partial_inplace */
1351 0xffff, /* dst_mask */
1352 FALSE
), /* pcrel_offset */
1354 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1355 signed offset from the appropriate base, and filling in the register
1356 field with the appropriate register (0, 2, or 13). */
1357 HOWTO (R_PPC_EMB_SDA21
, /* type */
1359 2, /* size (0 = byte, 1 = short, 2 = long) */
1361 FALSE
, /* pc_relative */
1363 complain_overflow_signed
, /* complain_on_overflow */
1364 bfd_elf_generic_reloc
, /* special_function */
1365 "R_PPC_EMB_SDA21", /* name */
1366 FALSE
, /* partial_inplace */
1368 0xffff, /* dst_mask */
1369 FALSE
), /* pcrel_offset */
1371 /* Relocation not handled: R_PPC_EMB_MRKREF */
1372 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1373 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1374 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1375 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1376 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1378 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1379 in the 16 bit signed offset from the appropriate base, and filling in the
1380 register field with the appropriate register (0, 2, or 13). */
1381 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1383 1, /* size (0 = byte, 1 = short, 2 = long) */
1385 FALSE
, /* pc_relative */
1387 complain_overflow_signed
, /* complain_on_overflow */
1388 bfd_elf_generic_reloc
, /* special_function */
1389 "R_PPC_EMB_RELSDA", /* name */
1390 FALSE
, /* partial_inplace */
1392 0xffff, /* dst_mask */
1393 FALSE
), /* pcrel_offset */
1395 HOWTO (R_PPC_IRELATIVE
, /* type */
1397 2, /* size (0 = byte, 1 = short, 2 = long) */
1399 FALSE
, /* pc_relative */
1401 complain_overflow_bitfield
, /* complain_on_overflow */
1402 bfd_elf_generic_reloc
, /* special_function */
1403 "R_PPC_IRELATIVE", /* name */
1404 FALSE
, /* partial_inplace */
1406 0xffffffff, /* dst_mask */
1407 FALSE
), /* pcrel_offset */
1409 /* A 16 bit relative relocation. */
1410 HOWTO (R_PPC_REL16
, /* type */
1412 1, /* size (0 = byte, 1 = short, 2 = long) */
1414 TRUE
, /* pc_relative */
1416 complain_overflow_bitfield
, /* complain_on_overflow */
1417 bfd_elf_generic_reloc
, /* special_function */
1418 "R_PPC_REL16", /* name */
1419 FALSE
, /* partial_inplace */
1421 0xffff, /* dst_mask */
1422 TRUE
), /* pcrel_offset */
1424 /* A 16 bit relative relocation without overflow. */
1425 HOWTO (R_PPC_REL16_LO
, /* type */
1427 1, /* size (0 = byte, 1 = short, 2 = long) */
1429 TRUE
, /* pc_relative */
1431 complain_overflow_dont
,/* complain_on_overflow */
1432 bfd_elf_generic_reloc
, /* special_function */
1433 "R_PPC_REL16_LO", /* name */
1434 FALSE
, /* partial_inplace */
1436 0xffff, /* dst_mask */
1437 TRUE
), /* pcrel_offset */
1439 /* The high order 16 bits of a relative address. */
1440 HOWTO (R_PPC_REL16_HI
, /* type */
1441 16, /* rightshift */
1442 1, /* size (0 = byte, 1 = short, 2 = long) */
1444 TRUE
, /* pc_relative */
1446 complain_overflow_dont
, /* complain_on_overflow */
1447 bfd_elf_generic_reloc
, /* special_function */
1448 "R_PPC_REL16_HI", /* name */
1449 FALSE
, /* partial_inplace */
1451 0xffff, /* dst_mask */
1452 TRUE
), /* pcrel_offset */
1454 /* The high order 16 bits of a relative address, plus 1 if the contents of
1455 the low 16 bits, treated as a signed number, is negative. */
1456 HOWTO (R_PPC_REL16_HA
, /* type */
1457 16, /* rightshift */
1458 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 TRUE
, /* pc_relative */
1462 complain_overflow_dont
, /* complain_on_overflow */
1463 ppc_elf_addr16_ha_reloc
, /* special_function */
1464 "R_PPC_REL16_HA", /* name */
1465 FALSE
, /* partial_inplace */
1467 0xffff, /* dst_mask */
1468 TRUE
), /* pcrel_offset */
1470 /* GNU extension to record C++ vtable hierarchy. */
1471 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1473 0, /* size (0 = byte, 1 = short, 2 = long) */
1475 FALSE
, /* pc_relative */
1477 complain_overflow_dont
, /* complain_on_overflow */
1478 NULL
, /* special_function */
1479 "R_PPC_GNU_VTINHERIT", /* name */
1480 FALSE
, /* partial_inplace */
1483 FALSE
), /* pcrel_offset */
1485 /* GNU extension to record C++ vtable member usage. */
1486 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1488 0, /* size (0 = byte, 1 = short, 2 = long) */
1490 FALSE
, /* pc_relative */
1492 complain_overflow_dont
, /* complain_on_overflow */
1493 NULL
, /* special_function */
1494 "R_PPC_GNU_VTENTRY", /* name */
1495 FALSE
, /* partial_inplace */
1498 FALSE
), /* pcrel_offset */
1500 /* Phony reloc to handle AIX style TOC entries. */
1501 HOWTO (R_PPC_TOC16
, /* type */
1503 1, /* size (0 = byte, 1 = short, 2 = long) */
1505 FALSE
, /* pc_relative */
1507 complain_overflow_signed
, /* complain_on_overflow */
1508 bfd_elf_generic_reloc
, /* special_function */
1509 "R_PPC_TOC16", /* name */
1510 FALSE
, /* partial_inplace */
1512 0xffff, /* dst_mask */
1513 FALSE
), /* pcrel_offset */
1516 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1519 ppc_elf_howto_init (void)
1521 unsigned int i
, type
;
1524 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1527 type
= ppc_elf_howto_raw
[i
].type
;
1528 if (type
>= (sizeof (ppc_elf_howto_table
)
1529 / sizeof (ppc_elf_howto_table
[0])))
1531 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1535 static reloc_howto_type
*
1536 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1537 bfd_reloc_code_real_type code
)
1539 enum elf_ppc_reloc_type r
;
1541 /* Initialize howto table if not already done. */
1542 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1543 ppc_elf_howto_init ();
1550 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1551 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1552 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1553 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1554 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1555 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1556 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1557 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1558 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1559 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1560 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1561 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1562 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1563 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1564 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1565 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1566 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1567 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1568 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1569 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1570 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1571 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1572 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1573 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1574 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1575 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1576 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1577 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1578 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1579 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1580 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1581 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1582 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1583 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1584 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1585 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1586 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC_TLSGD
; break;
1587 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC_TLSLD
; break;
1588 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1589 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1590 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1591 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1592 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1593 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1594 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1595 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1596 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1597 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1598 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1599 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1600 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1601 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1602 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1603 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1604 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1605 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1606 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1607 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1608 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1609 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1610 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1611 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1612 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1613 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1614 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1615 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1616 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1617 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1618 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1619 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1620 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1621 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1622 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1623 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1624 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1625 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1626 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1627 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1628 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1629 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1630 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1631 case BFD_RELOC_16_PCREL
: r
= R_PPC_REL16
; break;
1632 case BFD_RELOC_LO16_PCREL
: r
= R_PPC_REL16_LO
; break;
1633 case BFD_RELOC_HI16_PCREL
: r
= R_PPC_REL16_HI
; break;
1634 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC_REL16_HA
; break;
1635 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1636 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1639 return ppc_elf_howto_table
[r
];
1642 static reloc_howto_type
*
1643 ppc_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1649 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1651 if (ppc_elf_howto_raw
[i
].name
!= NULL
1652 && strcasecmp (ppc_elf_howto_raw
[i
].name
, r_name
) == 0)
1653 return &ppc_elf_howto_raw
[i
];
1658 /* Set the howto pointer for a PowerPC ELF reloc. */
1661 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1663 Elf_Internal_Rela
*dst
)
1665 /* Initialize howto table if not already done. */
1666 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1667 ppc_elf_howto_init ();
1669 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1670 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1672 /* Just because the above assert didn't trigger doesn't mean that
1673 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1674 if (!cache_ptr
->howto
)
1676 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
1677 abfd
, ELF32_R_TYPE (dst
->r_info
));
1678 bfd_set_error (bfd_error_bad_value
);
1680 cache_ptr
->howto
= ppc_elf_howto_table
[R_PPC_NONE
];
1684 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1686 static bfd_reloc_status_type
1687 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1688 arelent
*reloc_entry
,
1690 void *data ATTRIBUTE_UNUSED
,
1691 asection
*input_section
,
1693 char **error_message ATTRIBUTE_UNUSED
)
1697 if (output_bfd
!= NULL
)
1699 reloc_entry
->address
+= input_section
->output_offset
;
1700 return bfd_reloc_ok
;
1703 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1704 return bfd_reloc_outofrange
;
1706 if (bfd_is_com_section (symbol
->section
))
1709 relocation
= symbol
->value
;
1711 relocation
+= symbol
->section
->output_section
->vma
;
1712 relocation
+= symbol
->section
->output_offset
;
1713 relocation
+= reloc_entry
->addend
;
1714 if (reloc_entry
->howto
->pc_relative
)
1715 relocation
-= reloc_entry
->address
;
1717 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1719 return bfd_reloc_continue
;
1722 static bfd_reloc_status_type
1723 ppc_elf_unhandled_reloc (bfd
*abfd
,
1724 arelent
*reloc_entry
,
1727 asection
*input_section
,
1729 char **error_message
)
1731 /* If this is a relocatable link (output_bfd test tells us), just
1732 call the generic function. Any adjustment will be done at final
1734 if (output_bfd
!= NULL
)
1735 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1736 input_section
, output_bfd
, error_message
);
1738 if (error_message
!= NULL
)
1740 static char buf
[60];
1741 sprintf (buf
, _("generic linker can't handle %s"),
1742 reloc_entry
->howto
->name
);
1743 *error_message
= buf
;
1745 return bfd_reloc_dangerous
;
1748 /* Sections created by the linker. */
1750 typedef struct elf_linker_section
1752 /* Pointer to the bfd section. */
1756 /* Associated bss section name. */
1757 const char *bss_name
;
1758 /* Associated symbol name. */
1759 const char *sym_name
;
1760 /* Associated symbol. */
1761 struct elf_link_hash_entry
*sym
;
1762 } elf_linker_section_t
;
1764 /* Linked list of allocated pointer entries. This hangs off of the
1765 symbol lists, and provides allows us to return different pointers,
1766 based on different addend's. */
1768 typedef struct elf_linker_section_pointers
1770 /* next allocated pointer for this symbol */
1771 struct elf_linker_section_pointers
*next
;
1772 /* offset of pointer from beginning of section */
1776 /* which linker section this is */
1777 elf_linker_section_t
*lsect
;
1778 } elf_linker_section_pointers_t
;
1780 struct ppc_elf_obj_tdata
1782 struct elf_obj_tdata elf
;
1784 /* A mapping from local symbols to offsets into the various linker
1785 sections added. This is index by the symbol index. */
1786 elf_linker_section_pointers_t
**linker_section_pointers
;
1788 /* Flags used to auto-detect plt type. */
1789 unsigned int makes_plt_call
: 1;
1790 unsigned int has_rel16
: 1;
1793 #define ppc_elf_tdata(bfd) \
1794 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1796 #define elf_local_ptr_offsets(bfd) \
1797 (ppc_elf_tdata (bfd)->linker_section_pointers)
1799 #define is_ppc_elf(bfd) \
1800 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1801 && elf_object_id (bfd) == PPC32_ELF_DATA)
1803 /* Override the generic function because we store some extras. */
1806 ppc_elf_mkobject (bfd
*abfd
)
1808 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc_elf_obj_tdata
),
1812 /* Fix bad default arch selected for a 32 bit input bfd when the
1813 default is 64 bit. */
1816 ppc_elf_object_p (bfd
*abfd
)
1818 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1820 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1822 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1824 /* Relies on arch after 64 bit default being 32 bit default. */
1825 abfd
->arch_info
= abfd
->arch_info
->next
;
1826 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1832 /* Function to set whether a module needs the -mrelocatable bit set. */
1835 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1837 BFD_ASSERT (!elf_flags_init (abfd
)
1838 || elf_elfheader (abfd
)->e_flags
== flags
);
1840 elf_elfheader (abfd
)->e_flags
= flags
;
1841 elf_flags_init (abfd
) = TRUE
;
1845 /* Support for core dump NOTE sections. */
1848 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1853 switch (note
->descsz
)
1858 case 268: /* Linux/PPC. */
1860 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1863 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1872 /* Make a ".reg/999" section. */
1873 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1874 size
, note
->descpos
+ offset
);
1878 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1880 switch (note
->descsz
)
1885 case 128: /* Linux/PPC elf_prpsinfo. */
1886 elf_tdata (abfd
)->core_pid
1887 = bfd_get_32 (abfd
, note
->descdata
+ 16);
1888 elf_tdata (abfd
)->core_program
1889 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1890 elf_tdata (abfd
)->core_command
1891 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1894 /* Note that for some reason, a spurious space is tacked
1895 onto the end of the args in some (at least one anyway)
1896 implementations, so strip it off if it exists. */
1899 char *command
= elf_tdata (abfd
)->core_command
;
1900 int n
= strlen (command
);
1902 if (0 < n
&& command
[n
- 1] == ' ')
1903 command
[n
- 1] = '\0';
1910 ppc_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
, ...)
1922 va_start (ap
, note_type
);
1923 memset (data
, 0, 32);
1924 strncpy (data
+ 32, va_arg (ap
, const char *), 16);
1925 strncpy (data
+ 48, va_arg (ap
, const char *), 80);
1927 return elfcore_write_note (abfd
, buf
, bufsiz
,
1928 "CORE", note_type
, data
, sizeof (data
));
1939 va_start (ap
, note_type
);
1940 memset (data
, 0, 72);
1941 pid
= va_arg (ap
, long);
1942 bfd_put_32 (abfd
, pid
, data
+ 24);
1943 cursig
= va_arg (ap
, int);
1944 bfd_put_16 (abfd
, cursig
, data
+ 12);
1945 greg
= va_arg (ap
, const void *);
1946 memcpy (data
+ 72, greg
, 192);
1947 memset (data
+ 264, 0, 4);
1949 return elfcore_write_note (abfd
, buf
, bufsiz
,
1950 "CORE", note_type
, data
, sizeof (data
));
1955 /* Return address for Ith PLT stub in section PLT, for relocation REL
1956 or (bfd_vma) -1 if it should not be included. */
1959 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1960 const asection
*plt ATTRIBUTE_UNUSED
,
1963 return rel
->address
;
1966 /* Handle a PowerPC specific section when reading an object file. This
1967 is called when bfd_section_from_shdr finds a section with an unknown
1971 ppc_elf_section_from_shdr (bfd
*abfd
,
1972 Elf_Internal_Shdr
*hdr
,
1979 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1982 newsect
= hdr
->bfd_section
;
1983 flags
= bfd_get_section_flags (abfd
, newsect
);
1984 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1985 flags
|= SEC_EXCLUDE
;
1987 if (hdr
->sh_type
== SHT_ORDERED
)
1988 flags
|= SEC_SORT_ENTRIES
;
1990 bfd_set_section_flags (abfd
, newsect
, flags
);
1994 /* Set up any other section flags and such that may be necessary. */
1997 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1998 Elf_Internal_Shdr
*shdr
,
2001 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2002 shdr
->sh_type
= SHT_ORDERED
;
2007 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
2008 need to bump up the number of section headers. */
2011 ppc_elf_additional_program_headers (bfd
*abfd
,
2012 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2017 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2018 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2021 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2022 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2028 /* Add extra PPC sections -- Note, for now, make .sbss2 and
2029 .PPC.EMB.sbss0 a normal section, and not a bss section so
2030 that the linker doesn't crater when trying to make more than
2033 static const struct bfd_elf_special_section ppc_elf_special_sections
[] =
2035 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
2036 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2037 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2038 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2039 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2040 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED
, SHF_ALLOC
},
2041 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE
, 0 },
2042 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2043 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2044 { NULL
, 0, 0, 0, 0 }
2047 /* This is what we want for new plt/got. */
2048 static struct bfd_elf_special_section ppc_alt_plt
=
2049 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
};
2051 static const struct bfd_elf_special_section
*
2052 ppc_elf_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
2054 const struct bfd_elf_special_section
*ssect
;
2056 /* See if this is one of the special sections. */
2057 if (sec
->name
== NULL
)
2060 ssect
= _bfd_elf_get_special_section (sec
->name
, ppc_elf_special_sections
,
2064 if (ssect
== ppc_elf_special_sections
&& (sec
->flags
& SEC_LOAD
) != 0)
2065 ssect
= &ppc_alt_plt
;
2069 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
2072 /* Very simple linked list structure for recording apuinfo values. */
2073 typedef struct apuinfo_list
2075 struct apuinfo_list
*next
;
2076 unsigned long value
;
2080 static apuinfo_list
*head
;
2081 static bfd_boolean apuinfo_set
;
2084 apuinfo_list_init (void)
2087 apuinfo_set
= FALSE
;
2091 apuinfo_list_add (unsigned long value
)
2093 apuinfo_list
*entry
= head
;
2095 while (entry
!= NULL
)
2097 if (entry
->value
== value
)
2099 entry
= entry
->next
;
2102 entry
= bfd_malloc (sizeof (* entry
));
2106 entry
->value
= value
;
2112 apuinfo_list_length (void)
2114 apuinfo_list
*entry
;
2115 unsigned long count
;
2117 for (entry
= head
, count
= 0;
2119 entry
= entry
->next
)
2125 static inline unsigned long
2126 apuinfo_list_element (unsigned long number
)
2128 apuinfo_list
* entry
;
2132 entry
= entry
->next
)
2135 return entry
? entry
->value
: 0;
2139 apuinfo_list_finish (void)
2141 apuinfo_list
*entry
;
2143 for (entry
= head
; entry
;)
2145 apuinfo_list
*next
= entry
->next
;
2153 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2154 #define APUINFO_LABEL "APUinfo"
2156 /* Scan the input BFDs and create a linked list of
2157 the APUinfo values that will need to be emitted. */
2160 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
2164 char *buffer
= NULL
;
2165 bfd_size_type largest_input_size
= 0;
2167 unsigned long length
;
2168 const char *error_message
= NULL
;
2170 if (link_info
== NULL
)
2173 apuinfo_list_init ();
2175 /* Read in the input sections contents. */
2176 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2178 unsigned long datum
;
2180 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2184 error_message
= _("corrupt %s section in %B");
2185 length
= asec
->size
;
2190 if (largest_input_size
< asec
->size
)
2194 largest_input_size
= asec
->size
;
2195 buffer
= bfd_malloc (largest_input_size
);
2200 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
2201 || (bfd_bread (buffer
, length
, ibfd
) != length
))
2203 error_message
= _("unable to read in %s section from %B");
2207 /* Verify the contents of the header. Note - we have to
2208 extract the values this way in order to allow for a
2209 host whose endian-ness is different from the target. */
2210 datum
= bfd_get_32 (ibfd
, buffer
);
2211 if (datum
!= sizeof APUINFO_LABEL
)
2214 datum
= bfd_get_32 (ibfd
, buffer
+ 8);
2218 if (strcmp (buffer
+ 12, APUINFO_LABEL
) != 0)
2221 /* Get the number of bytes used for apuinfo entries. */
2222 datum
= bfd_get_32 (ibfd
, buffer
+ 4);
2223 if (datum
+ 20 != length
)
2226 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2227 for (i
= 0; i
< datum
; i
+= 4)
2228 apuinfo_list_add (bfd_get_32 (ibfd
, buffer
+ 20 + i
));
2231 error_message
= NULL
;
2235 /* Compute the size of the output section. */
2236 unsigned num_entries
= apuinfo_list_length ();
2238 /* Set the output section size, if it exists. */
2239 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2241 if (asec
&& ! bfd_set_section_size (abfd
, asec
, 20 + num_entries
* 4))
2244 error_message
= _("warning: unable to set size of %s section in %B");
2253 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
2256 /* Prevent the output section from accumulating the input sections'
2257 contents. We have already stored this in our linked list structure. */
2260 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2261 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
2263 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2265 return apuinfo_set
&& strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0;
2268 /* Finally we can generate the output section. */
2271 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
2276 unsigned num_entries
;
2277 bfd_size_type length
;
2279 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2286 length
= asec
->size
;
2290 buffer
= bfd_malloc (length
);
2293 (*_bfd_error_handler
)
2294 (_("failed to allocate space for new APUinfo section."));
2298 /* Create the apuinfo header. */
2299 num_entries
= apuinfo_list_length ();
2300 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
2301 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
2302 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
2303 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
2306 for (i
= 0; i
< num_entries
; i
++)
2308 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
2312 if (length
!= asec
->size
)
2313 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
2315 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
2316 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
2320 apuinfo_list_finish ();
2324 is_nonpic_glink_stub (bfd
*abfd
, asection
*glink
, bfd_vma off
)
2326 bfd_byte buf
[GLINK_ENTRY_SIZE
];
2328 if (!bfd_get_section_contents (abfd
, glink
, buf
, off
, GLINK_ENTRY_SIZE
))
2331 return ((bfd_get_32 (abfd
, buf
+ 0) & 0xffff0000) == LIS_11
2332 && (bfd_get_32 (abfd
, buf
+ 4) & 0xffff0000) == LWZ_11_11
2333 && bfd_get_32 (abfd
, buf
+ 8) == MTCTR_11
2334 && bfd_get_32 (abfd
, buf
+ 12) == BCTR
);
2338 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2340 bfd_vma vma
= *(bfd_vma
*) ptr
;
2341 return ((section
->flags
& SEC_ALLOC
) != 0
2342 && section
->vma
<= vma
2343 && vma
< section
->vma
+ section
->size
);
2347 ppc_elf_get_synthetic_symtab (bfd
*abfd
, long symcount
, asymbol
**syms
,
2348 long dynsymcount
, asymbol
**dynsyms
,
2351 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2352 asection
*plt
, *relplt
, *dynamic
, *glink
;
2353 bfd_vma glink_vma
= 0;
2354 bfd_vma resolv_vma
= 0;
2365 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
2368 if (dynsymcount
<= 0)
2371 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2375 plt
= bfd_get_section_by_name (abfd
, ".plt");
2379 /* Call common code to handle old-style executable PLTs. */
2380 if (elf_section_flags (plt
) & SHF_EXECINSTR
)
2381 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
2382 dynsymcount
, dynsyms
, ret
);
2384 /* If this object was prelinked, the prelinker stored the address
2385 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
2386 dynamic
= bfd_get_section_by_name (abfd
, ".dynamic");
2387 if (dynamic
!= NULL
)
2389 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2391 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2393 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2396 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2397 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2400 extdynend
= extdyn
+ dynamic
->size
;
2401 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2403 Elf_Internal_Dyn dyn
;
2404 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2406 if (dyn
.d_tag
== DT_NULL
)
2409 if (dyn
.d_tag
== DT_PPC_GOT
)
2411 unsigned int g_o_t
= dyn
.d_un
.d_val
;
2412 asection
*got
= bfd_get_section_by_name (abfd
, ".got");
2414 && bfd_get_section_contents (abfd
, got
, buf
,
2415 g_o_t
- got
->vma
+ 4, 4))
2416 glink_vma
= bfd_get_32 (abfd
, buf
);
2423 /* Otherwise we read the first plt entry. */
2426 if (bfd_get_section_contents (abfd
, plt
, buf
, 0, 4))
2427 glink_vma
= bfd_get_32 (abfd
, buf
);
2433 /* The .glink section usually does not survive the final
2434 link; search for the section (usually .text) where the
2435 glink stubs now reside. */
2436 glink
= bfd_sections_find_if (abfd
, section_covers_vma
, &glink_vma
);
2440 /* Determine glink PLT resolver by reading the relative branch
2441 from the first glink stub. */
2442 if (bfd_get_section_contents (abfd
, glink
, buf
,
2443 glink_vma
- glink
->vma
, 4))
2445 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2447 /* The first glink stub may either branch to the resolver ... */
2449 if ((insn
& ~0x3fffffc) == 0)
2450 resolv_vma
= glink_vma
+ (insn
^ 0x2000000) - 0x2000000;
2452 /* ... or fall through a bunch of NOPs. */
2453 else if ((insn
^ B
^ NOP
) == 0)
2455 bfd_get_section_contents (abfd
, glink
, buf
,
2456 glink_vma
- glink
->vma
+ i
, 4);
2458 if (bfd_get_32 (abfd
, buf
) != NOP
)
2460 resolv_vma
= glink_vma
+ i
;
2465 count
= relplt
->size
/ sizeof (Elf32_External_Rela
);
2466 stub_vma
= glink_vma
- (bfd_vma
) count
* 16;
2467 /* If the stubs are those for -shared/-pie then we might have
2468 multiple stubs for each plt entry. If that is the case then
2469 there is no way to associate stubs with their plt entries short
2470 of figuring out the GOT pointer value used in the stub. */
2471 if (!is_nonpic_glink_stub (abfd
, glink
,
2472 glink_vma
- GLINK_ENTRY_SIZE
- glink
->vma
))
2475 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2476 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
2479 size
= count
* sizeof (asymbol
);
2480 p
= relplt
->relocation
;
2481 for (i
= 0; i
< count
; i
++, p
++)
2483 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2485 size
+= sizeof ("+0x") - 1 + 8;
2488 size
+= sizeof (asymbol
) + sizeof ("__glink");
2491 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2493 s
= *ret
= bfd_malloc (size
);
2497 names
= (char *) (s
+ count
+ 1 + (resolv_vma
!= 0));
2498 p
= relplt
->relocation
;
2499 for (i
= 0; i
< count
; i
++, p
++)
2503 *s
= **p
->sym_ptr_ptr
;
2504 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2505 we are defining a symbol, ensure one of them is set. */
2506 if ((s
->flags
& BSF_LOCAL
) == 0)
2507 s
->flags
|= BSF_GLOBAL
;
2508 s
->flags
|= BSF_SYNTHETIC
;
2510 s
->value
= stub_vma
- glink
->vma
;
2513 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2514 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2518 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2519 names
+= sizeof ("+0x") - 1;
2520 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2521 names
+= strlen (names
);
2523 memcpy (names
, "@plt", sizeof ("@plt"));
2524 names
+= sizeof ("@plt");
2529 /* Add a symbol at the start of the glink branch table. */
2530 memset (s
, 0, sizeof *s
);
2532 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2534 s
->value
= glink_vma
- glink
->vma
;
2536 memcpy (names
, "__glink", sizeof ("__glink"));
2537 names
+= sizeof ("__glink");
2543 /* Add a symbol for the glink PLT resolver. */
2544 memset (s
, 0, sizeof *s
);
2546 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2548 s
->value
= resolv_vma
- glink
->vma
;
2550 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2551 names
+= sizeof ("__glink_PLTresolve");
2559 /* The following functions are specific to the ELF linker, while
2560 functions above are used generally. They appear in this file more
2561 or less in the order in which they are called. eg.
2562 ppc_elf_check_relocs is called early in the link process,
2563 ppc_elf_finish_dynamic_sections is one of the last functions
2566 /* Track PLT entries needed for a given symbol. We might need more
2567 than one glink entry per symbol when generating a pic binary. */
2570 struct plt_entry
*next
;
2572 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2573 This field stores the offset into .got2 used to initialise the
2574 GOT pointer reg. It will always be at least 32768. (Current
2575 gcc always uses an offset of 32768, but ld -r will pack .got2
2576 sections together resulting in larger offsets). */
2579 /* The .got2 section. */
2582 /* PLT refcount or offset. */
2585 bfd_signed_vma refcount
;
2589 /* .glink stub offset. */
2590 bfd_vma glink_offset
;
2593 /* Of those relocs that might be copied as dynamic relocs, this function
2594 selects those that must be copied when linking a shared library,
2595 even when the symbol is local. */
2598 must_be_dyn_reloc (struct bfd_link_info
*info
,
2599 enum elf_ppc_reloc_type r_type
)
2608 case R_PPC_REL14_BRTAKEN
:
2609 case R_PPC_REL14_BRNTAKEN
:
2615 case R_PPC_TPREL16_LO
:
2616 case R_PPC_TPREL16_HI
:
2617 case R_PPC_TPREL16_HA
:
2618 return !info
->executable
;
2622 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2623 copying dynamic variables from a shared lib into an app's dynbss
2624 section, and instead use a dynamic relocation to point into the
2626 #define ELIMINATE_COPY_RELOCS 1
2628 /* PPC ELF linker hash entry. */
2630 struct ppc_elf_link_hash_entry
2632 struct elf_link_hash_entry elf
;
2634 /* If this symbol is used in the linker created sections, the processor
2635 specific backend uses this field to map the field into the offset
2636 from the beginning of the section. */
2637 elf_linker_section_pointers_t
*linker_section_pointer
;
2639 /* Track dynamic relocs copied for this symbol. */
2640 struct elf_dyn_relocs
*dyn_relocs
;
2642 /* Contexts in which symbol is used in the GOT (or TOC).
2643 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2644 corresponding relocs are encountered during check_relocs.
2645 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2646 indicate the corresponding GOT entry type is not needed. */
2647 #define TLS_GD 1 /* GD reloc. */
2648 #define TLS_LD 2 /* LD reloc. */
2649 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2650 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2651 #define TLS_TLS 16 /* Any TLS reloc. */
2652 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2653 #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
2656 /* Nonzero if we have seen a small data relocation referring to this
2658 unsigned char has_sda_refs
;
2661 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2663 /* PPC ELF linker hash table. */
2665 struct ppc_elf_link_hash_table
2667 struct elf_link_hash_table elf
;
2669 /* Short-cuts to get to dynamic linker sections. */
2681 elf_linker_section_t sdata
[2];
2683 asection
*glink_eh_frame
;
2685 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2688 /* The .got.plt section (VxWorks only)*/
2691 /* Shortcut to __tls_get_addr. */
2692 struct elf_link_hash_entry
*tls_get_addr
;
2694 /* The bfd that forced an old-style PLT. */
2697 /* TLS local dynamic got entry handling. */
2699 bfd_signed_vma refcount
;
2703 /* Offset of branch table to PltResolve function in glink. */
2704 bfd_vma glink_pltresolve
;
2706 /* Size of reserved GOT entries. */
2707 unsigned int got_header_size
;
2708 /* Non-zero if allocating the header left a gap. */
2709 unsigned int got_gap
;
2711 /* The type of PLT we have chosen to use. */
2712 enum ppc_elf_plt_type plt_type
;
2714 /* Set if we should emit symbols for stubs. */
2715 unsigned int emit_stub_syms
:1;
2717 /* Set if __tls_get_addr optimization should not be done. */
2718 unsigned int no_tls_get_addr_opt
:1;
2720 /* True if the target system is VxWorks. */
2721 unsigned int is_vxworks
:1;
2723 /* The size of PLT entries. */
2725 /* The distance between adjacent PLT slots. */
2727 /* The size of the first PLT entry. */
2728 int plt_initial_entry_size
;
2730 /* Small local sym cache. */
2731 struct sym_cache sym_cache
;
2734 /* Rename some of the generic section flags to better document how they
2737 /* Nonzero if this section has TLS related relocations. */
2738 #define has_tls_reloc sec_flg0
2740 /* Nonzero if this section has a call to __tls_get_addr. */
2741 #define has_tls_get_addr_call sec_flg1
2743 /* Get the PPC ELF linker hash table from a link_info structure. */
2745 #define ppc_elf_hash_table(p) \
2746 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2747 == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
2749 /* Create an entry in a PPC ELF linker hash table. */
2751 static struct bfd_hash_entry
*
2752 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2753 struct bfd_hash_table
*table
,
2756 /* Allocate the structure if it has not already been allocated by a
2760 entry
= bfd_hash_allocate (table
,
2761 sizeof (struct ppc_elf_link_hash_entry
));
2766 /* Call the allocation method of the superclass. */
2767 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2770 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2771 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
2772 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2773 ppc_elf_hash_entry (entry
)->has_sda_refs
= 0;
2779 /* Create a PPC ELF linker hash table. */
2781 static struct bfd_link_hash_table
*
2782 ppc_elf_link_hash_table_create (bfd
*abfd
)
2784 struct ppc_elf_link_hash_table
*ret
;
2786 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2790 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2791 ppc_elf_link_hash_newfunc
,
2792 sizeof (struct ppc_elf_link_hash_entry
),
2799 ret
->elf
.init_plt_refcount
.refcount
= 0;
2800 ret
->elf
.init_plt_refcount
.glist
= NULL
;
2801 ret
->elf
.init_plt_offset
.offset
= 0;
2802 ret
->elf
.init_plt_offset
.glist
= NULL
;
2804 ret
->sdata
[0].name
= ".sdata";
2805 ret
->sdata
[0].sym_name
= "_SDA_BASE_";
2806 ret
->sdata
[0].bss_name
= ".sbss";
2808 ret
->sdata
[1].name
= ".sdata2";
2809 ret
->sdata
[1].sym_name
= "_SDA2_BASE_";
2810 ret
->sdata
[1].bss_name
= ".sbss2";
2812 ret
->plt_entry_size
= 12;
2813 ret
->plt_slot_size
= 8;
2814 ret
->plt_initial_entry_size
= 72;
2816 return &ret
->elf
.root
;
2819 /* Create .got and the related sections. */
2822 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2824 struct ppc_elf_link_hash_table
*htab
;
2828 if (!_bfd_elf_create_got_section (abfd
, info
))
2831 htab
= ppc_elf_hash_table (info
);
2832 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2836 if (htab
->is_vxworks
)
2838 htab
->sgotplt
= bfd_get_section_by_name (abfd
, ".got.plt");
2844 /* The powerpc .got has a blrl instruction in it. Mark it
2846 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
2847 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2848 if (!bfd_set_section_flags (abfd
, s
, flags
))
2852 htab
->relgot
= bfd_get_section_by_name (abfd
, ".rela.got");
2860 ppc_elf_create_glink (bfd
*abfd
, struct bfd_link_info
*info
)
2862 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2866 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
| SEC_HAS_CONTENTS
2867 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2868 s
= bfd_make_section_anyway_with_flags (abfd
, ".glink", flags
);
2871 || !bfd_set_section_alignment (abfd
, s
, 4))
2874 if (!info
->no_ld_generated_unwind_info
)
2876 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2877 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2878 s
= bfd_make_section_anyway_with_flags (abfd
, ".eh_frame", flags
);
2879 htab
->glink_eh_frame
= s
;
2881 || !bfd_set_section_alignment (abfd
, s
, 2))
2885 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
2886 s
= bfd_make_section_anyway_with_flags (abfd
, ".iplt", flags
);
2889 || !bfd_set_section_alignment (abfd
, s
, 4))
2892 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2893 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2894 s
= bfd_make_section_with_flags (abfd
, ".rela.iplt", flags
);
2897 || ! bfd_set_section_alignment (abfd
, s
, 2))
2902 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2903 to output sections (just like _bfd_elf_create_dynamic_sections has
2904 to create .dynbss and .rela.bss). */
2907 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2909 struct ppc_elf_link_hash_table
*htab
;
2913 htab
= ppc_elf_hash_table (info
);
2915 if (htab
->got
== NULL
2916 && !ppc_elf_create_got (abfd
, info
))
2919 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2922 if (htab
->glink
== NULL
2923 && !ppc_elf_create_glink (abfd
, info
))
2926 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2927 s
= bfd_make_section_with_flags (abfd
, ".dynsbss",
2928 SEC_ALLOC
| SEC_LINKER_CREATED
);
2935 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2936 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2937 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2938 s
= bfd_make_section_with_flags (abfd
, ".rela.sbss", flags
);
2941 || ! bfd_set_section_alignment (abfd
, s
, 2))
2945 if (htab
->is_vxworks
2946 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
2949 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2950 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2954 flags
= SEC_ALLOC
| SEC_CODE
| SEC_LINKER_CREATED
;
2955 if (htab
->plt_type
== PLT_VXWORKS
)
2956 /* The VxWorks PLT is a loaded section with contents. */
2957 flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_READONLY
;
2958 return bfd_set_section_flags (abfd
, s
, flags
);
2961 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2964 ppc_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2965 struct elf_link_hash_entry
*dir
,
2966 struct elf_link_hash_entry
*ind
)
2968 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2970 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2971 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
2973 edir
->tls_mask
|= eind
->tls_mask
;
2974 edir
->has_sda_refs
|= eind
->has_sda_refs
;
2976 /* If called to transfer flags for a weakdef during processing
2977 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
2978 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
2979 if (!(ELIMINATE_COPY_RELOCS
2980 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
2981 && edir
->elf
.dynamic_adjusted
))
2982 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
2984 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
2985 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
2986 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
2987 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
2988 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
2990 /* If we were called to copy over info for a weak sym, that's all. */
2991 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
2994 if (eind
->dyn_relocs
!= NULL
)
2996 if (edir
->dyn_relocs
!= NULL
)
2998 struct elf_dyn_relocs
**pp
;
2999 struct elf_dyn_relocs
*p
;
3001 /* Add reloc counts against the indirect sym to the direct sym
3002 list. Merge any entries against the same section. */
3003 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3005 struct elf_dyn_relocs
*q
;
3007 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3008 if (q
->sec
== p
->sec
)
3010 q
->pc_count
+= p
->pc_count
;
3011 q
->count
+= p
->count
;
3018 *pp
= edir
->dyn_relocs
;
3021 edir
->dyn_relocs
= eind
->dyn_relocs
;
3022 eind
->dyn_relocs
= NULL
;
3025 /* Copy over the GOT refcount entries that we may have already seen to
3026 the symbol which just became indirect. */
3027 edir
->elf
.got
.refcount
+= eind
->elf
.got
.refcount
;
3028 eind
->elf
.got
.refcount
= 0;
3030 /* And plt entries. */
3031 if (eind
->elf
.plt
.plist
!= NULL
)
3033 if (edir
->elf
.plt
.plist
!= NULL
)
3035 struct plt_entry
**entp
;
3036 struct plt_entry
*ent
;
3038 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3040 struct plt_entry
*dent
;
3042 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3043 if (dent
->sec
== ent
->sec
&& dent
->addend
== ent
->addend
)
3045 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3052 *entp
= edir
->elf
.plt
.plist
;
3055 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3056 eind
->elf
.plt
.plist
= NULL
;
3059 if (eind
->elf
.dynindx
!= -1)
3061 if (edir
->elf
.dynindx
!= -1)
3062 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3063 edir
->elf
.dynstr_index
);
3064 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3065 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3066 eind
->elf
.dynindx
= -1;
3067 eind
->elf
.dynstr_index
= 0;
3071 /* Hook called by the linker routine which adds symbols from an object
3072 file. We use it to put .comm items in .sbss, and not .bss. */
3075 ppc_elf_add_symbol_hook (bfd
*abfd
,
3076 struct bfd_link_info
*info
,
3077 Elf_Internal_Sym
*sym
,
3078 const char **namep ATTRIBUTE_UNUSED
,
3079 flagword
*flagsp ATTRIBUTE_UNUSED
,
3083 if (sym
->st_shndx
== SHN_COMMON
3084 && !info
->relocatable
3085 && is_ppc_elf (info
->output_bfd
)
3086 && sym
->st_size
<= elf_gp_size (abfd
))
3088 /* Common symbols less than or equal to -G nn bytes are automatically
3090 struct ppc_elf_link_hash_table
*htab
;
3092 htab
= ppc_elf_hash_table (info
);
3093 if (htab
->sbss
== NULL
)
3095 flagword flags
= SEC_IS_COMMON
| SEC_LINKER_CREATED
;
3097 if (!htab
->elf
.dynobj
)
3098 htab
->elf
.dynobj
= abfd
;
3100 htab
->sbss
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3103 if (htab
->sbss
== NULL
)
3108 *valp
= sym
->st_size
;
3111 if ((abfd
->flags
& DYNAMIC
) == 0
3112 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
3113 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
3114 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
3120 create_sdata_sym (struct bfd_link_info
*info
, elf_linker_section_t
*lsect
)
3122 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
3124 lsect
->sym
= elf_link_hash_lookup (&htab
->elf
, lsect
->sym_name
,
3126 if (lsect
->sym
== NULL
)
3128 if (lsect
->sym
->root
.type
== bfd_link_hash_new
)
3129 lsect
->sym
->non_elf
= 0;
3130 lsect
->sym
->ref_regular
= 1;
3131 _bfd_elf_link_hash_hide_symbol (info
, lsect
->sym
, TRUE
);
3135 /* Create a special linker section. */
3138 ppc_elf_create_linker_section (bfd
*abfd
,
3139 struct bfd_link_info
*info
,
3141 elf_linker_section_t
*lsect
)
3143 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
3146 flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3147 | SEC_LINKER_CREATED
);
3149 /* Record the first bfd that needs the special sections. */
3150 if (!htab
->elf
.dynobj
)
3151 htab
->elf
.dynobj
= abfd
;
3153 s
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3157 || !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
3161 return create_sdata_sym (info
, lsect
);
3164 /* Find a linker generated pointer with a given addend and type. */
3166 static elf_linker_section_pointers_t
*
3167 elf_find_pointer_linker_section
3168 (elf_linker_section_pointers_t
*linker_pointers
,
3170 elf_linker_section_t
*lsect
)
3172 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
3173 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
3174 return linker_pointers
;
3179 /* Allocate a pointer to live in a linker created section. */
3182 elf_create_pointer_linker_section (bfd
*abfd
,
3183 elf_linker_section_t
*lsect
,
3184 struct elf_link_hash_entry
*h
,
3185 const Elf_Internal_Rela
*rel
)
3187 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
3188 elf_linker_section_pointers_t
*linker_section_ptr
;
3189 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
3192 BFD_ASSERT (lsect
!= NULL
);
3194 /* Is this a global symbol? */
3197 struct ppc_elf_link_hash_entry
*eh
;
3199 /* Has this symbol already been allocated? If so, our work is done. */
3200 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3201 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
3206 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
3210 BFD_ASSERT (is_ppc_elf (abfd
));
3212 /* Allocation of a pointer to a local symbol. */
3213 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
3215 /* Allocate a table to hold the local symbols if first time. */
3218 unsigned int num_symbols
= elf_symtab_hdr (abfd
).sh_info
;
3221 amt
*= sizeof (elf_linker_section_pointers_t
*);
3222 ptr
= bfd_zalloc (abfd
, amt
);
3227 elf_local_ptr_offsets (abfd
) = ptr
;
3230 /* Has this symbol already been allocated? If so, our work is done. */
3231 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
3236 ptr_linker_section_ptr
= &ptr
[r_symndx
];
3239 /* Allocate space for a pointer in the linker section, and allocate
3240 a new pointer record from internal memory. */
3241 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
3242 amt
= sizeof (elf_linker_section_pointers_t
);
3243 linker_section_ptr
= bfd_alloc (abfd
, amt
);
3245 if (!linker_section_ptr
)
3248 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
3249 linker_section_ptr
->addend
= rel
->r_addend
;
3250 linker_section_ptr
->lsect
= lsect
;
3251 *ptr_linker_section_ptr
= linker_section_ptr
;
3253 linker_section_ptr
->offset
= lsect
->section
->size
;
3254 lsect
->section
->size
+= 4;
3258 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
3259 lsect
->name
, (long) linker_section_ptr
->offset
,
3260 (long) lsect
->section
->size
);
3266 static struct plt_entry
**
3267 update_local_sym_info (bfd
*abfd
,
3268 Elf_Internal_Shdr
*symtab_hdr
,
3269 unsigned long r_symndx
,
3272 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3273 struct plt_entry
**local_plt
;
3274 char *local_got_tls_masks
;
3276 if (local_got_refcounts
== NULL
)
3278 bfd_size_type size
= symtab_hdr
->sh_info
;
3280 size
*= (sizeof (*local_got_refcounts
)
3281 + sizeof (*local_plt
)
3282 + sizeof (*local_got_tls_masks
));
3283 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3284 if (local_got_refcounts
== NULL
)
3286 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3289 local_plt
= (struct plt_entry
**) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3290 local_got_tls_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
3291 local_got_tls_masks
[r_symndx
] |= tls_type
;
3292 if (tls_type
!= PLT_IFUNC
)
3293 local_got_refcounts
[r_symndx
] += 1;
3294 return local_plt
+ r_symndx
;
3298 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
,
3299 asection
*sec
, bfd_vma addend
)
3301 struct plt_entry
*ent
;
3305 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3306 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3310 bfd_size_type amt
= sizeof (*ent
);
3311 ent
= bfd_alloc (abfd
, amt
);
3316 ent
->addend
= addend
;
3317 ent
->plt
.refcount
= 0;
3320 ent
->plt
.refcount
+= 1;
3324 static struct plt_entry
*
3325 find_plt_ent (struct plt_entry
**plist
, asection
*sec
, bfd_vma addend
)
3327 struct plt_entry
*ent
;
3331 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3332 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3338 is_branch_reloc (enum elf_ppc_reloc_type r_type
)
3340 return (r_type
== R_PPC_PLTREL24
3341 || r_type
== R_PPC_LOCAL24PC
3342 || r_type
== R_PPC_REL24
3343 || r_type
== R_PPC_REL14
3344 || r_type
== R_PPC_REL14_BRTAKEN
3345 || r_type
== R_PPC_REL14_BRNTAKEN
3346 || r_type
== R_PPC_ADDR24
3347 || r_type
== R_PPC_ADDR14
3348 || r_type
== R_PPC_ADDR14_BRTAKEN
3349 || r_type
== R_PPC_ADDR14_BRNTAKEN
);
3353 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3355 (*_bfd_error_handler
)
3356 (_("%B: relocation %s cannot be used when making a shared object"),
3358 ppc_elf_howto_table
[r_type
]->name
);
3359 bfd_set_error (bfd_error_bad_value
);
3362 /* Look through the relocs for a section during the first phase, and
3363 allocate space in the global offset table or procedure linkage
3367 ppc_elf_check_relocs (bfd
*abfd
,
3368 struct bfd_link_info
*info
,
3370 const Elf_Internal_Rela
*relocs
)
3372 struct ppc_elf_link_hash_table
*htab
;
3373 Elf_Internal_Shdr
*symtab_hdr
;
3374 struct elf_link_hash_entry
**sym_hashes
;
3375 const Elf_Internal_Rela
*rel
;
3376 const Elf_Internal_Rela
*rel_end
;
3377 asection
*got2
, *sreloc
;
3378 struct elf_link_hash_entry
*tga
;
3380 if (info
->relocatable
)
3383 /* Don't do anything special with non-loaded, non-alloced sections.
3384 In particular, any relocs in such sections should not affect GOT
3385 and PLT reference counting (ie. we don't allow them to create GOT
3386 or PLT entries), there's no possibility or desire to optimize TLS
3387 relocs, and there's not much point in propagating relocs to shared
3388 libs that the dynamic linker won't relocate. */
3389 if ((sec
->flags
& SEC_ALLOC
) == 0)
3393 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3397 BFD_ASSERT (is_ppc_elf (abfd
));
3399 /* Initialize howto table if not already done. */
3400 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3401 ppc_elf_howto_init ();
3403 htab
= ppc_elf_hash_table (info
);
3404 if (htab
->glink
== NULL
)
3406 if (htab
->elf
.dynobj
== NULL
)
3407 htab
->elf
.dynobj
= abfd
;
3408 if (!ppc_elf_create_glink (htab
->elf
.dynobj
, info
))
3411 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3412 FALSE
, FALSE
, TRUE
);
3413 symtab_hdr
= &elf_symtab_hdr (abfd
);
3414 sym_hashes
= elf_sym_hashes (abfd
);
3415 got2
= bfd_get_section_by_name (abfd
, ".got2");
3418 rel_end
= relocs
+ sec
->reloc_count
;
3419 for (rel
= relocs
; rel
< rel_end
; rel
++)
3421 unsigned long r_symndx
;
3422 enum elf_ppc_reloc_type r_type
;
3423 struct elf_link_hash_entry
*h
;
3426 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3427 if (r_symndx
< symtab_hdr
->sh_info
)
3431 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3432 while (h
->root
.type
== bfd_link_hash_indirect
3433 || h
->root
.type
== bfd_link_hash_warning
)
3434 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3437 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3438 This shows up in particular in an R_PPC_ADDR32 in the eabi
3441 && htab
->got
== NULL
3442 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3444 if (htab
->elf
.dynobj
== NULL
)
3445 htab
->elf
.dynobj
= abfd
;
3446 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3448 BFD_ASSERT (h
== htab
->elf
.hgot
);
3452 r_type
= ELF32_R_TYPE (rel
->r_info
);
3453 if (h
== NULL
&& !htab
->is_vxworks
)
3455 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3460 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
3462 || is_branch_reloc (r_type
)))
3464 struct plt_entry
**ifunc
;
3467 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3472 /* STT_GNU_IFUNC symbols must have a PLT entry;
3473 In a non-pie executable even when there are
3476 if (r_type
== R_PPC_PLTREL24
)
3478 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3480 addend
= rel
->r_addend
;
3482 if (!update_plt_info (abfd
, ifunc
, got2
, addend
))
3487 if (!htab
->is_vxworks
3488 && is_branch_reloc (r_type
)
3493 && (ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSGD
3494 || ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSLD
))
3495 /* We have a new-style __tls_get_addr call with a marker
3499 /* Mark this section as having an old-style call. */
3500 sec
->has_tls_get_addr_call
= 1;
3507 /* These special tls relocs tie a call to __tls_get_addr with
3508 its parameter symbol. */
3511 case R_PPC_GOT_TLSLD16
:
3512 case R_PPC_GOT_TLSLD16_LO
:
3513 case R_PPC_GOT_TLSLD16_HI
:
3514 case R_PPC_GOT_TLSLD16_HA
:
3515 tls_type
= TLS_TLS
| TLS_LD
;
3518 case R_PPC_GOT_TLSGD16
:
3519 case R_PPC_GOT_TLSGD16_LO
:
3520 case R_PPC_GOT_TLSGD16_HI
:
3521 case R_PPC_GOT_TLSGD16_HA
:
3522 tls_type
= TLS_TLS
| TLS_GD
;
3525 case R_PPC_GOT_TPREL16
:
3526 case R_PPC_GOT_TPREL16_LO
:
3527 case R_PPC_GOT_TPREL16_HI
:
3528 case R_PPC_GOT_TPREL16_HA
:
3529 if (!info
->executable
)
3530 info
->flags
|= DF_STATIC_TLS
;
3531 tls_type
= TLS_TLS
| TLS_TPREL
;
3534 case R_PPC_GOT_DTPREL16
:
3535 case R_PPC_GOT_DTPREL16_LO
:
3536 case R_PPC_GOT_DTPREL16_HI
:
3537 case R_PPC_GOT_DTPREL16_HA
:
3538 tls_type
= TLS_TLS
| TLS_DTPREL
;
3540 sec
->has_tls_reloc
= 1;
3543 /* GOT16 relocations */
3545 case R_PPC_GOT16_LO
:
3546 case R_PPC_GOT16_HI
:
3547 case R_PPC_GOT16_HA
:
3548 /* This symbol requires a global offset table entry. */
3549 if (htab
->got
== NULL
)
3551 if (htab
->elf
.dynobj
== NULL
)
3552 htab
->elf
.dynobj
= abfd
;
3553 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3558 h
->got
.refcount
+= 1;
3559 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3562 /* This is a global offset table entry for a local symbol. */
3563 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3566 /* We may also need a plt entry if the symbol turns out to be
3568 if (h
!= NULL
&& !info
->shared
)
3570 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3575 /* Indirect .sdata relocation. */
3576 case R_PPC_EMB_SDAI16
:
3579 bad_shared_reloc (abfd
, r_type
);
3582 if (htab
->sdata
[0].section
== NULL
3583 && !ppc_elf_create_linker_section (abfd
, info
, 0,
3586 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[0],
3591 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3592 h
->non_got_ref
= TRUE
;
3596 /* Indirect .sdata2 relocation. */
3597 case R_PPC_EMB_SDA2I16
:
3600 bad_shared_reloc (abfd
, r_type
);
3603 if (htab
->sdata
[1].section
== NULL
3604 && !ppc_elf_create_linker_section (abfd
, info
, SEC_READONLY
,
3607 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[1],
3612 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3613 h
->non_got_ref
= TRUE
;
3617 case R_PPC_SDAREL16
:
3618 if (htab
->sdata
[0].sym
== NULL
3619 && !create_sdata_sym (info
, &htab
->sdata
[0]))
3623 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3624 h
->non_got_ref
= TRUE
;
3628 case R_PPC_EMB_SDA2REL
:
3631 bad_shared_reloc (abfd
, r_type
);
3634 if (htab
->sdata
[1].sym
== NULL
3635 && !create_sdata_sym (info
, &htab
->sdata
[1]))
3639 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3640 h
->non_got_ref
= TRUE
;
3644 case R_PPC_EMB_SDA21
:
3645 case R_PPC_EMB_RELSDA
:
3648 bad_shared_reloc (abfd
, r_type
);
3651 if (htab
->sdata
[0].sym
== NULL
3652 && !create_sdata_sym (info
, &htab
->sdata
[0]))
3654 if (htab
->sdata
[1].sym
== NULL
3655 && !create_sdata_sym (info
, &htab
->sdata
[1]))
3659 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3660 h
->non_got_ref
= TRUE
;
3664 case R_PPC_EMB_NADDR32
:
3665 case R_PPC_EMB_NADDR16
:
3666 case R_PPC_EMB_NADDR16_LO
:
3667 case R_PPC_EMB_NADDR16_HI
:
3668 case R_PPC_EMB_NADDR16_HA
:
3671 bad_shared_reloc (abfd
, r_type
);
3675 h
->non_got_ref
= TRUE
;
3678 case R_PPC_PLTREL24
:
3683 case R_PPC_PLTREL32
:
3684 case R_PPC_PLT16_LO
:
3685 case R_PPC_PLT16_HI
:
3686 case R_PPC_PLT16_HA
:
3688 fprintf (stderr
, "Reloc requires a PLT entry\n");
3690 /* This symbol requires a procedure linkage table entry. We
3691 actually build the entry in finish_dynamic_symbol,
3692 because this might be a case of linking PIC code without
3693 linking in any dynamic objects, in which case we don't
3694 need to generate a procedure linkage table after all. */
3698 /* It does not make sense to have a procedure linkage
3699 table entry for a local symbol. */
3700 info
->callbacks
->einfo (_("%P: %H: %s reloc against local symbol\n"),
3701 abfd
, sec
, rel
->r_offset
,
3702 ppc_elf_howto_table
[r_type
]->name
);
3703 bfd_set_error (bfd_error_bad_value
);
3710 if (r_type
== R_PPC_PLTREL24
)
3712 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3714 addend
= rel
->r_addend
;
3717 if (!update_plt_info (abfd
, &h
->plt
.plist
, got2
, addend
))
3722 /* The following relocations don't need to propagate the
3723 relocation if linking a shared object since they are
3724 section relative. */
3726 case R_PPC_SECTOFF_LO
:
3727 case R_PPC_SECTOFF_HI
:
3728 case R_PPC_SECTOFF_HA
:
3729 case R_PPC_DTPREL16
:
3730 case R_PPC_DTPREL16_LO
:
3731 case R_PPC_DTPREL16_HI
:
3732 case R_PPC_DTPREL16_HA
:
3737 case R_PPC_REL16_LO
:
3738 case R_PPC_REL16_HI
:
3739 case R_PPC_REL16_HA
:
3740 ppc_elf_tdata (abfd
)->has_rel16
= 1;
3743 /* These are just markers. */
3745 case R_PPC_EMB_MRKREF
:
3749 case R_PPC_RELAX_PLT
:
3750 case R_PPC_RELAX_PLTREL24
:
3753 /* These should only appear in dynamic objects. */
3755 case R_PPC_GLOB_DAT
:
3756 case R_PPC_JMP_SLOT
:
3757 case R_PPC_RELATIVE
:
3758 case R_PPC_IRELATIVE
:
3761 /* These aren't handled yet. We'll report an error later. */
3763 case R_PPC_EMB_RELSEC16
:
3764 case R_PPC_EMB_RELST_LO
:
3765 case R_PPC_EMB_RELST_HI
:
3766 case R_PPC_EMB_RELST_HA
:
3767 case R_PPC_EMB_BIT_FLD
:
3770 /* This refers only to functions defined in the shared library. */
3771 case R_PPC_LOCAL24PC
:
3772 if (h
!= NULL
&& h
== htab
->elf
.hgot
&& htab
->plt_type
== PLT_UNSET
)
3774 htab
->plt_type
= PLT_OLD
;
3775 htab
->old_bfd
= abfd
;
3779 /* This relocation describes the C++ object vtable hierarchy.
3780 Reconstruct it for later use during GC. */
3781 case R_PPC_GNU_VTINHERIT
:
3782 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3786 /* This relocation describes which C++ vtable entries are actually
3787 used. Record for later use during GC. */
3788 case R_PPC_GNU_VTENTRY
:
3789 BFD_ASSERT (h
!= NULL
);
3791 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3795 /* We shouldn't really be seeing these. */
3798 case R_PPC_TPREL16_LO
:
3799 case R_PPC_TPREL16_HI
:
3800 case R_PPC_TPREL16_HA
:
3801 if (!info
->executable
)
3802 info
->flags
|= DF_STATIC_TLS
;
3806 case R_PPC_DTPMOD32
:
3807 case R_PPC_DTPREL32
:
3813 && (sec
->flags
& SEC_CODE
) != 0
3815 && htab
->plt_type
== PLT_UNSET
)
3817 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3818 the start of a function, which assembles to a REL32
3819 reference to .got2. If we detect one of these, then
3820 force the old PLT layout because the linker cannot
3821 reliably deduce the GOT pointer value needed for
3824 Elf_Internal_Sym
*isym
;
3826 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3831 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3834 htab
->plt_type
= PLT_OLD
;
3835 htab
->old_bfd
= abfd
;
3838 if (h
== NULL
|| h
== htab
->elf
.hgot
)
3844 case R_PPC_ADDR16_LO
:
3845 case R_PPC_ADDR16_HI
:
3846 case R_PPC_ADDR16_HA
:
3849 if (h
!= NULL
&& !info
->shared
)
3851 /* We may need a plt entry if the symbol turns out to be
3852 a function defined in a dynamic object. */
3853 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3856 /* We may need a copy reloc too. */
3858 h
->pointer_equality_needed
= 1;
3864 case R_PPC_REL14_BRTAKEN
:
3865 case R_PPC_REL14_BRNTAKEN
:
3868 if (h
== htab
->elf
.hgot
)
3870 if (htab
->plt_type
== PLT_UNSET
)
3872 htab
->plt_type
= PLT_OLD
;
3873 htab
->old_bfd
= abfd
;
3881 case R_PPC_ADDR14_BRTAKEN
:
3882 case R_PPC_ADDR14_BRNTAKEN
:
3883 if (h
!= NULL
&& !info
->shared
)
3885 /* We may need a plt entry if the symbol turns out to be
3886 a function defined in a dynamic object. */
3888 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3894 /* If we are creating a shared library, and this is a reloc
3895 against a global symbol, or a non PC relative reloc
3896 against a local symbol, then we need to copy the reloc
3897 into the shared library. However, if we are linking with
3898 -Bsymbolic, we do not need to copy a reloc against a
3899 global symbol which is defined in an object we are
3900 including in the link (i.e., DEF_REGULAR is set). At
3901 this point we have not seen all the input files, so it is
3902 possible that DEF_REGULAR is not set now but will be set
3903 later (it is never cleared). In case of a weak definition,
3904 DEF_REGULAR may be cleared later by a strong definition in
3905 a shared library. We account for that possibility below by
3906 storing information in the dyn_relocs field of the hash
3907 table entry. A similar situation occurs when creating
3908 shared libraries and symbol visibility changes render the
3911 If on the other hand, we are creating an executable, we
3912 may need to keep relocations for symbols satisfied by a
3913 dynamic library if we manage to avoid copy relocs for the
3916 && (must_be_dyn_reloc (info
, r_type
)
3918 && (! info
->symbolic
3919 || h
->root
.type
== bfd_link_hash_defweak
3920 || !h
->def_regular
))))
3921 || (ELIMINATE_COPY_RELOCS
3924 && (h
->root
.type
== bfd_link_hash_defweak
3925 || !h
->def_regular
)))
3927 struct elf_dyn_relocs
*p
;
3928 struct elf_dyn_relocs
**rel_head
;
3932 "ppc_elf_check_relocs needs to "
3933 "create relocation for %s\n",
3934 (h
&& h
->root
.root
.string
3935 ? h
->root
.root
.string
: "<unknown>"));
3939 if (htab
->elf
.dynobj
== NULL
)
3940 htab
->elf
.dynobj
= abfd
;
3942 sreloc
= _bfd_elf_make_dynamic_reloc_section
3943 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3949 /* If this is a global symbol, we count the number of
3950 relocations we need for this symbol. */
3953 rel_head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3957 /* Track dynamic relocs needed for local syms too.
3958 We really need local syms available to do this
3962 Elf_Internal_Sym
*isym
;
3964 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3969 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3973 vpp
= &elf_section_data (s
)->local_dynrel
;
3974 rel_head
= (struct elf_dyn_relocs
**) vpp
;
3978 if (p
== NULL
|| p
->sec
!= sec
)
3980 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3983 p
->next
= *rel_head
;
3991 if (!must_be_dyn_reloc (info
, r_type
))
4003 /* Merge object attributes from IBFD into OBFD. Raise an error if
4004 there are conflicting attributes. */
4006 ppc_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
4008 obj_attribute
*in_attr
, *in_attrs
;
4009 obj_attribute
*out_attr
, *out_attrs
;
4011 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
4013 /* This is the first object. Copy the attributes. */
4014 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
4016 /* Use the Tag_null value to indicate the attributes have been
4018 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
4023 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
4024 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
4026 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
4027 non-conflicting ones. */
4028 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_FP
];
4029 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_FP
];
4030 if (in_attr
->i
!= out_attr
->i
)
4033 if (out_attr
->i
== 0)
4034 out_attr
->i
= in_attr
->i
;
4035 else if (in_attr
->i
== 0)
4037 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4039 (_("Warning: %B uses hard float, %B uses soft float"), obfd
, ibfd
);
4040 else if (out_attr
->i
== 1 && in_attr
->i
== 3)
4042 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4044 else if (out_attr
->i
== 3 && in_attr
->i
== 1)
4046 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4048 else if (out_attr
->i
== 3 && in_attr
->i
== 2)
4050 (_("Warning: %B uses soft float, %B uses single-precision hard float"),
4052 else if (out_attr
->i
== 2 && (in_attr
->i
== 1 || in_attr
->i
== 3))
4054 (_("Warning: %B uses hard float, %B uses soft float"), ibfd
, obfd
);
4055 else if (in_attr
->i
> 3)
4057 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
4061 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
4065 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
4066 merge non-conflicting ones. */
4067 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Vector
];
4068 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Vector
];
4069 if (in_attr
->i
!= out_attr
->i
)
4071 const char *in_abi
= NULL
, *out_abi
= NULL
;
4075 case 1: in_abi
= "generic"; break;
4076 case 2: in_abi
= "AltiVec"; break;
4077 case 3: in_abi
= "SPE"; break;
4080 switch (out_attr
->i
)
4082 case 1: out_abi
= "generic"; break;
4083 case 2: out_abi
= "AltiVec"; break;
4084 case 3: out_abi
= "SPE"; break;
4088 if (out_attr
->i
== 0)
4089 out_attr
->i
= in_attr
->i
;
4090 else if (in_attr
->i
== 0)
4092 /* For now, allow generic to transition to AltiVec or SPE
4093 without a warning. If GCC marked files with their stack
4094 alignment and used don't-care markings for files which are
4095 not affected by the vector ABI, we could warn about this
4097 else if (out_attr
->i
== 1)
4098 out_attr
->i
= in_attr
->i
;
4099 else if (in_attr
->i
== 1)
4101 else if (in_abi
== NULL
)
4103 (_("Warning: %B uses unknown vector ABI %d"), ibfd
,
4105 else if (out_abi
== NULL
)
4107 (_("Warning: %B uses unknown vector ABI %d"), obfd
,
4111 (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
4112 ibfd
, obfd
, in_abi
, out_abi
);
4115 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
4116 and merge non-conflicting ones. */
4117 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4118 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4119 if (in_attr
->i
!= out_attr
->i
)
4122 if (out_attr
->i
== 0)
4123 out_attr
->i
= in_attr
->i
;
4124 else if (in_attr
->i
== 0)
4126 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4128 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd
, ibfd
);
4129 else if (out_attr
->i
== 2 && in_attr
->i
== 1)
4131 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd
, obfd
);
4132 else if (in_attr
->i
> 2)
4134 (_("Warning: %B uses unknown small structure return convention %d"), ibfd
,
4138 (_("Warning: %B uses unknown small structure return convention %d"), obfd
,
4142 /* Merge Tag_compatibility attributes and any common GNU ones. */
4143 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
4148 /* Merge backend specific data from an object file to the output
4149 object file when linking. */
4152 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4158 if (!is_ppc_elf (ibfd
) || !is_ppc_elf (obfd
))
4161 /* Check if we have the same endianness. */
4162 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
4165 if (!ppc_elf_merge_obj_attributes (ibfd
, obfd
))
4168 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4169 old_flags
= elf_elfheader (obfd
)->e_flags
;
4170 if (!elf_flags_init (obfd
))
4172 /* First call, no flags set. */
4173 elf_flags_init (obfd
) = TRUE
;
4174 elf_elfheader (obfd
)->e_flags
= new_flags
;
4177 /* Compatible flags are ok. */
4178 else if (new_flags
== old_flags
)
4181 /* Incompatible flags. */
4184 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
4185 to be linked with either. */
4187 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
4188 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
4191 (*_bfd_error_handler
)
4192 (_("%B: compiled with -mrelocatable and linked with "
4193 "modules compiled normally"), ibfd
);
4195 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
4196 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
4199 (*_bfd_error_handler
)
4200 (_("%B: compiled normally and linked with "
4201 "modules compiled with -mrelocatable"), ibfd
);
4204 /* The output is -mrelocatable-lib iff both the input files are. */
4205 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
4206 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
4208 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
4209 but each input file is either -mrelocatable or -mrelocatable-lib. */
4210 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
4211 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
4212 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
4213 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
4215 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
4216 any module uses it. */
4217 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
4219 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4220 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4222 /* Warn about any other mismatches. */
4223 if (new_flags
!= old_flags
)
4226 (*_bfd_error_handler
)
4227 (_("%B: uses different e_flags (0x%lx) fields "
4228 "than previous modules (0x%lx)"),
4229 ibfd
, (long) new_flags
, (long) old_flags
);
4234 bfd_set_error (bfd_error_bad_value
);
4242 /* Choose which PLT scheme to use, and set .plt flags appropriately.
4243 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
4245 ppc_elf_select_plt_layout (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4246 struct bfd_link_info
*info
,
4247 enum ppc_elf_plt_type plt_style
,
4250 struct ppc_elf_link_hash_table
*htab
;
4253 htab
= ppc_elf_hash_table (info
);
4255 htab
->emit_stub_syms
= emit_stub_syms
;
4257 if (htab
->plt_type
== PLT_UNSET
)
4259 struct elf_link_hash_entry
*h
;
4261 if (plt_style
== PLT_OLD
)
4262 htab
->plt_type
= PLT_OLD
;
4263 else if (info
->shared
4264 && htab
->elf
.dynamic_sections_created
4265 && (h
= elf_link_hash_lookup (&htab
->elf
, "_mcount",
4266 FALSE
, FALSE
, TRUE
)) != NULL
4267 && (h
->type
== STT_FUNC
4270 && !(SYMBOL_CALLS_LOCAL (info
, h
)
4271 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4272 && h
->root
.type
== bfd_link_hash_undefweak
)))
4274 /* Profiling of shared libs (and pies) is not supported with
4275 secure plt, because ppc32 does profiling before a
4276 function prologue and a secure plt pic call stubs needs
4277 r30 to be set up. */
4278 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
)
4308 if (htab
->old_bfd
!= NULL
)
4309 info
->callbacks
->einfo (_("%P: bss-plt forced due to %B\n"),
4312 info
->callbacks
->einfo (_("%P: bss-plt forced by profiling\n"));
4315 BFD_ASSERT (htab
->plt_type
!= PLT_VXWORKS
);
4317 if (htab
->plt_type
== PLT_NEW
)
4319 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4320 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4322 /* The new PLT is a loaded section. */
4323 if (htab
->plt
!= NULL
4324 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->plt
, flags
))
4327 /* The new GOT is not executable. */
4328 if (htab
->got
!= NULL
4329 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->got
, flags
))
4334 /* Stop an unused .glink section from affecting .text alignment. */
4335 if (htab
->glink
!= NULL
4336 && !bfd_set_section_alignment (htab
->elf
.dynobj
, htab
->glink
, 0))
4339 return htab
->plt_type
== PLT_NEW
;
4342 /* Return the section that should be marked against GC for a given
4346 ppc_elf_gc_mark_hook (asection
*sec
,
4347 struct bfd_link_info
*info
,
4348 Elf_Internal_Rela
*rel
,
4349 struct elf_link_hash_entry
*h
,
4350 Elf_Internal_Sym
*sym
)
4353 switch (ELF32_R_TYPE (rel
->r_info
))
4355 case R_PPC_GNU_VTINHERIT
:
4356 case R_PPC_GNU_VTENTRY
:
4360 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4363 /* Update the got, plt and dynamic reloc reference counts for the
4364 section being removed. */
4367 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4368 struct bfd_link_info
*info
,
4370 const Elf_Internal_Rela
*relocs
)
4372 struct ppc_elf_link_hash_table
*htab
;
4373 Elf_Internal_Shdr
*symtab_hdr
;
4374 struct elf_link_hash_entry
**sym_hashes
;
4375 bfd_signed_vma
*local_got_refcounts
;
4376 const Elf_Internal_Rela
*rel
, *relend
;
4379 if (info
->relocatable
)
4382 if ((sec
->flags
& SEC_ALLOC
) == 0)
4385 elf_section_data (sec
)->local_dynrel
= NULL
;
4387 htab
= ppc_elf_hash_table (info
);
4388 symtab_hdr
= &elf_symtab_hdr (abfd
);
4389 sym_hashes
= elf_sym_hashes (abfd
);
4390 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4391 got2
= bfd_get_section_by_name (abfd
, ".got2");
4393 relend
= relocs
+ sec
->reloc_count
;
4394 for (rel
= relocs
; rel
< relend
; rel
++)
4396 unsigned long r_symndx
;
4397 enum elf_ppc_reloc_type r_type
;
4398 struct elf_link_hash_entry
*h
= NULL
;
4400 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4401 if (r_symndx
>= symtab_hdr
->sh_info
)
4403 struct elf_dyn_relocs
**pp
, *p
;
4404 struct ppc_elf_link_hash_entry
*eh
;
4406 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4407 while (h
->root
.type
== bfd_link_hash_indirect
4408 || h
->root
.type
== bfd_link_hash_warning
)
4409 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4410 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4412 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4415 /* Everything must go for SEC. */
4421 r_type
= ELF32_R_TYPE (rel
->r_info
);
4422 if (!htab
->is_vxworks
4424 && local_got_refcounts
!= NULL
4426 || is_branch_reloc (r_type
)))
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)
4434 struct plt_entry
**ifunc
= local_plt
+ r_symndx
;
4436 struct plt_entry
*ent
;
4438 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
4439 addend
= rel
->r_addend
;
4440 ent
= find_plt_ent (ifunc
, got2
, addend
);
4441 if (ent
->plt
.refcount
> 0)
4442 ent
->plt
.refcount
-= 1;
4449 case R_PPC_GOT_TLSLD16
:
4450 case R_PPC_GOT_TLSLD16_LO
:
4451 case R_PPC_GOT_TLSLD16_HI
:
4452 case R_PPC_GOT_TLSLD16_HA
:
4453 case R_PPC_GOT_TLSGD16
:
4454 case R_PPC_GOT_TLSGD16_LO
:
4455 case R_PPC_GOT_TLSGD16_HI
:
4456 case R_PPC_GOT_TLSGD16_HA
:
4457 case R_PPC_GOT_TPREL16
:
4458 case R_PPC_GOT_TPREL16_LO
:
4459 case R_PPC_GOT_TPREL16_HI
:
4460 case R_PPC_GOT_TPREL16_HA
:
4461 case R_PPC_GOT_DTPREL16
:
4462 case R_PPC_GOT_DTPREL16_LO
:
4463 case R_PPC_GOT_DTPREL16_HI
:
4464 case R_PPC_GOT_DTPREL16_HA
:
4466 case R_PPC_GOT16_LO
:
4467 case R_PPC_GOT16_HI
:
4468 case R_PPC_GOT16_HA
:
4471 if (h
->got
.refcount
> 0)
4475 struct plt_entry
*ent
;
4477 ent
= find_plt_ent (&h
->plt
.plist
, NULL
, 0);
4478 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4479 ent
->plt
.refcount
-= 1;
4482 else if (local_got_refcounts
!= NULL
)
4484 if (local_got_refcounts
[r_symndx
] > 0)
4485 local_got_refcounts
[r_symndx
]--;
4491 case R_PPC_REL14_BRTAKEN
:
4492 case R_PPC_REL14_BRNTAKEN
:
4494 if (h
== NULL
|| h
== htab
->elf
.hgot
)
4501 case R_PPC_ADDR16_LO
:
4502 case R_PPC_ADDR16_HI
:
4503 case R_PPC_ADDR16_HA
:
4505 case R_PPC_ADDR14_BRTAKEN
:
4506 case R_PPC_ADDR14_BRNTAKEN
:
4513 case R_PPC_PLTREL24
:
4514 case R_PPC_PLTREL32
:
4515 case R_PPC_PLT16_LO
:
4516 case R_PPC_PLT16_HI
:
4517 case R_PPC_PLT16_HA
:
4521 struct plt_entry
*ent
;
4523 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
4524 addend
= rel
->r_addend
;
4525 ent
= find_plt_ent (&h
->plt
.plist
, got2
, addend
);
4526 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4527 ent
->plt
.refcount
-= 1;
4538 /* Set plt output section type, htab->tls_get_addr, and call the
4539 generic ELF tls_setup function. */
4542 ppc_elf_tls_setup (bfd
*obfd
,
4543 struct bfd_link_info
*info
,
4544 int no_tls_get_addr_opt
)
4546 struct ppc_elf_link_hash_table
*htab
;
4548 htab
= ppc_elf_hash_table (info
);
4549 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4550 FALSE
, FALSE
, TRUE
);
4551 if (!no_tls_get_addr_opt
)
4553 struct elf_link_hash_entry
*opt
, *tga
;
4554 opt
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
4555 FALSE
, FALSE
, TRUE
);
4557 && (opt
->root
.type
== bfd_link_hash_defined
4558 || opt
->root
.type
== bfd_link_hash_defweak
))
4560 /* If glibc supports an optimized __tls_get_addr call stub,
4561 signalled by the presence of __tls_get_addr_opt, and we'll
4562 be calling __tls_get_addr via a plt call stub, then
4563 make __tls_get_addr point to __tls_get_addr_opt. */
4564 tga
= htab
->tls_get_addr
;
4565 if (htab
->elf
.dynamic_sections_created
4567 && (tga
->type
== STT_FUNC
4569 && !(SYMBOL_CALLS_LOCAL (info
, tga
)
4570 || (ELF_ST_VISIBILITY (tga
->other
) != STV_DEFAULT
4571 && tga
->root
.type
== bfd_link_hash_undefweak
)))
4573 struct plt_entry
*ent
;
4574 for (ent
= tga
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4575 if (ent
->plt
.refcount
> 0)
4579 tga
->root
.type
= bfd_link_hash_indirect
;
4580 tga
->root
.u
.i
.link
= &opt
->root
;
4581 ppc_elf_copy_indirect_symbol (info
, opt
, tga
);
4582 if (opt
->dynindx
!= -1)
4584 /* Use __tls_get_addr_opt in dynamic relocations. */
4586 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4588 if (!bfd_elf_link_record_dynamic_symbol (info
, opt
))
4591 htab
->tls_get_addr
= opt
;
4596 no_tls_get_addr_opt
= TRUE
;
4598 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
4599 if (htab
->plt_type
== PLT_NEW
4600 && htab
->plt
!= NULL
4601 && htab
->plt
->output_section
!= NULL
)
4603 elf_section_type (htab
->plt
->output_section
) = SHT_PROGBITS
;
4604 elf_section_flags (htab
->plt
->output_section
) = SHF_ALLOC
+ SHF_WRITE
;
4607 return _bfd_elf_tls_setup (obfd
, info
);
4610 /* Return TRUE iff REL is a branch reloc with a global symbol matching
4614 branch_reloc_hash_match (const bfd
*ibfd
,
4615 const Elf_Internal_Rela
*rel
,
4616 const struct elf_link_hash_entry
*hash
)
4618 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4619 enum elf_ppc_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
4620 unsigned int r_symndx
= ELF32_R_SYM (rel
->r_info
);
4622 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
4624 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4625 struct elf_link_hash_entry
*h
;
4627 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4628 while (h
->root
.type
== bfd_link_hash_indirect
4629 || h
->root
.type
== bfd_link_hash_warning
)
4630 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4637 /* Run through all the TLS relocs looking for optimization
4641 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4642 struct bfd_link_info
*info
)
4646 struct ppc_elf_link_hash_table
*htab
;
4649 if (info
->relocatable
|| !info
->executable
)
4652 htab
= ppc_elf_hash_table (info
);
4656 /* Make two passes through the relocs. First time check that tls
4657 relocs involved in setting up a tls_get_addr call are indeed
4658 followed by such a call. If they are not, don't do any tls
4659 optimization. On the second pass twiddle tls_mask flags to
4660 notify relocate_section that optimization can be done, and
4661 adjust got and plt refcounts. */
4662 for (pass
= 0; pass
< 2; ++pass
)
4663 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4665 Elf_Internal_Sym
*locsyms
= NULL
;
4666 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4667 asection
*got2
= bfd_get_section_by_name (ibfd
, ".got2");
4669 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4670 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4672 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4673 int expecting_tls_get_addr
= 0;
4675 /* Read the relocations. */
4676 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4678 if (relstart
== NULL
)
4681 relend
= relstart
+ sec
->reloc_count
;
4682 for (rel
= relstart
; rel
< relend
; rel
++)
4684 enum elf_ppc_reloc_type r_type
;
4685 unsigned long r_symndx
;
4686 struct elf_link_hash_entry
*h
= NULL
;
4688 char tls_set
, tls_clear
;
4689 bfd_boolean is_local
;
4690 bfd_signed_vma
*got_count
;
4692 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4693 if (r_symndx
>= symtab_hdr
->sh_info
)
4695 struct elf_link_hash_entry
**sym_hashes
;
4697 sym_hashes
= elf_sym_hashes (ibfd
);
4698 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4699 while (h
->root
.type
== bfd_link_hash_indirect
4700 || h
->root
.type
== bfd_link_hash_warning
)
4701 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4709 r_type
= ELF32_R_TYPE (rel
->r_info
);
4710 /* If this section has old-style __tls_get_addr calls
4711 without marker relocs, then check that each
4712 __tls_get_addr call reloc is preceded by a reloc
4713 that conceivably belongs to the __tls_get_addr arg
4714 setup insn. If we don't find matching arg setup
4715 relocs, don't do any tls optimization. */
4717 && sec
->has_tls_get_addr_call
4719 && h
== htab
->tls_get_addr
4720 && !expecting_tls_get_addr
4721 && is_branch_reloc (r_type
))
4723 info
->callbacks
->minfo ("%H __tls_get_addr lost arg, "
4724 "TLS optimization disabled\n",
4725 ibfd
, sec
, rel
->r_offset
);
4726 if (elf_section_data (sec
)->relocs
!= relstart
)
4731 expecting_tls_get_addr
= 0;
4734 case R_PPC_GOT_TLSLD16
:
4735 case R_PPC_GOT_TLSLD16_LO
:
4736 expecting_tls_get_addr
= 1;
4739 case R_PPC_GOT_TLSLD16_HI
:
4740 case R_PPC_GOT_TLSLD16_HA
:
4741 /* These relocs should never be against a symbol
4742 defined in a shared lib. Leave them alone if
4743 that turns out to be the case. */
4752 case R_PPC_GOT_TLSGD16
:
4753 case R_PPC_GOT_TLSGD16_LO
:
4754 expecting_tls_get_addr
= 1;
4757 case R_PPC_GOT_TLSGD16_HI
:
4758 case R_PPC_GOT_TLSGD16_HA
:
4764 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4768 case R_PPC_GOT_TPREL16
:
4769 case R_PPC_GOT_TPREL16_LO
:
4770 case R_PPC_GOT_TPREL16_HI
:
4771 case R_PPC_GOT_TPREL16_HA
:
4776 tls_clear
= TLS_TPREL
;
4784 expecting_tls_get_addr
= 2;
4795 if (!expecting_tls_get_addr
4796 || (expecting_tls_get_addr
== 1
4797 && !sec
->has_tls_get_addr_call
))
4800 if (rel
+ 1 < relend
4801 && branch_reloc_hash_match (ibfd
, rel
+ 1,
4802 htab
->tls_get_addr
))
4805 /* Uh oh, we didn't find the expected call. We
4806 could just mark this symbol to exclude it
4807 from tls optimization but it's safer to skip
4808 the entire optimization. */
4809 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
4810 "TLS optimization disabled\n"),
4811 ibfd
, sec
, rel
->r_offset
);
4812 if (elf_section_data (sec
)->relocs
!= relstart
)
4817 if (expecting_tls_get_addr
)
4819 struct plt_entry
*ent
;
4823 && ELF32_R_TYPE (rel
[1].r_info
) == R_PPC_PLTREL24
)
4824 addend
= rel
[1].r_addend
;
4825 ent
= find_plt_ent (&htab
->tls_get_addr
->plt
.plist
,
4827 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4828 ent
->plt
.refcount
-= 1;
4830 if (expecting_tls_get_addr
== 2)
4836 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4837 got_count
= &h
->got
.refcount
;
4841 bfd_signed_vma
*lgot_refs
;
4842 struct plt_entry
**local_plt
;
4845 if (locsyms
== NULL
)
4847 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4848 if (locsyms
== NULL
)
4849 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4850 symtab_hdr
->sh_info
,
4851 0, NULL
, NULL
, NULL
);
4852 if (locsyms
== NULL
)
4854 if (elf_section_data (sec
)->relocs
!= relstart
)
4859 lgot_refs
= elf_local_got_refcounts (ibfd
);
4860 if (lgot_refs
== NULL
)
4862 local_plt
= (struct plt_entry
**)
4863 (lgot_refs
+ symtab_hdr
->sh_info
);
4864 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
4865 tls_mask
= &lgot_masks
[r_symndx
];
4866 got_count
= &lgot_refs
[r_symndx
];
4871 /* We managed to get rid of a got entry. */
4876 *tls_mask
|= tls_set
;
4877 *tls_mask
&= ~tls_clear
;
4880 if (elf_section_data (sec
)->relocs
!= relstart
)
4885 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4887 if (!info
->keep_memory
)
4890 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4896 /* Return true if we have dynamic relocs that apply to read-only sections. */
4899 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
4901 struct elf_dyn_relocs
*p
;
4903 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4905 asection
*s
= p
->sec
->output_section
;
4908 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
4909 == (SEC_READONLY
| SEC_ALLOC
)))
4915 /* Adjust a symbol defined by a dynamic object and referenced by a
4916 regular object. The current definition is in some section of the
4917 dynamic object, but we're not including those sections. We have to
4918 change the definition to something the rest of the link can
4922 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4923 struct elf_link_hash_entry
*h
)
4925 struct ppc_elf_link_hash_table
*htab
;
4929 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4930 h
->root
.root
.string
);
4933 /* Make sure we know what is going on here. */
4934 htab
= ppc_elf_hash_table (info
);
4935 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
4937 || h
->type
== STT_GNU_IFUNC
4938 || h
->u
.weakdef
!= NULL
4941 && !h
->def_regular
)));
4943 /* Deal with function syms. */
4944 if (h
->type
== STT_FUNC
4945 || h
->type
== STT_GNU_IFUNC
4948 /* Clear procedure linkage table information for any symbol that
4949 won't need a .plt entry. */
4950 struct plt_entry
*ent
;
4951 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4952 if (ent
->plt
.refcount
> 0)
4955 || (h
->type
!= STT_GNU_IFUNC
4956 && (SYMBOL_CALLS_LOCAL (info
, h
)
4957 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4958 && h
->root
.type
== bfd_link_hash_undefweak
))))
4960 /* A PLT entry is not required/allowed when:
4962 1. We are not using ld.so; because then the PLT entry
4963 can't be set up, so we can't use one. In this case,
4964 ppc_elf_adjust_dynamic_symbol won't even be called.
4966 2. GC has rendered the entry unused.
4968 3. We know for certain that a call to this symbol
4969 will go to this object, or will remain undefined. */
4970 h
->plt
.plist
= NULL
;
4975 /* After adjust_dynamic_symbol, non_got_ref set in the
4976 non-shared case means that we have allocated space in
4977 .dynbss for the symbol and thus dyn_relocs for this
4978 symbol should be discarded.
4979 If we get here we know we are making a PLT entry for this
4980 symbol, and in an executable we'd normally resolve
4981 relocations against this symbol to the PLT entry. Allow
4982 dynamic relocs if the reference is weak, and the dynamic
4983 relocs will not cause text relocation. */
4984 if (!h
->ref_regular_nonweak
4986 && h
->type
!= STT_GNU_IFUNC
4987 && !htab
->is_vxworks
4988 && !ppc_elf_hash_entry (h
)->has_sda_refs
4989 && !readonly_dynrelocs (h
))
4995 h
->plt
.plist
= NULL
;
4997 /* If this is a weak symbol, and there is a real definition, the
4998 processor independent code will have arranged for us to see the
4999 real definition first, and we can just use the same value. */
5000 if (h
->u
.weakdef
!= NULL
)
5002 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5003 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5004 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5005 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5006 if (ELIMINATE_COPY_RELOCS
)
5007 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
5011 /* This is a reference to a symbol defined by a dynamic object which
5012 is not a function. */
5014 /* If we are creating a shared library, we must presume that the
5015 only references to the symbol are via the global offset table.
5016 For such cases we need not do anything here; the relocations will
5017 be handled correctly by relocate_section. */
5021 /* If there are no references to this symbol that do not use the
5022 GOT, we don't need to generate a copy reloc. */
5023 if (!h
->non_got_ref
)
5026 /* If we didn't find any dynamic relocs in read-only sections, then
5027 we'll be keeping the dynamic relocs and avoiding the copy reloc.
5028 We can't do this if there are any small data relocations. This
5029 doesn't work on VxWorks, where we can not have dynamic
5030 relocations (other than copy and jump slot relocations) in an
5032 if (ELIMINATE_COPY_RELOCS
5033 && !ppc_elf_hash_entry (h
)->has_sda_refs
5034 && !htab
->is_vxworks
5036 && !readonly_dynrelocs (h
))
5044 info
->callbacks
->einfo (_("%P: dynamic variable `%s' is zero size\n"),
5045 h
->root
.root
.string
);
5049 /* We must allocate the symbol in our .dynbss section, which will
5050 become part of the .bss section of the executable. There will be
5051 an entry for this symbol in the .dynsym section. The dynamic
5052 object will contain position independent code, so all references
5053 from the dynamic object to this symbol will go through the global
5054 offset table. The dynamic linker will use the .dynsym entry to
5055 determine the address it must put in the global offset table, so
5056 both the dynamic object and the regular object will refer to the
5057 same memory location for the variable.
5059 Of course, if the symbol is referenced using SDAREL relocs, we
5060 must instead allocate it in .sbss. */
5062 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
5066 BFD_ASSERT (s
!= NULL
);
5068 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
5069 copy the initial value out of the dynamic object and into the
5070 runtime process image. We need to remember the offset into the
5071 .rela.bss section we are going to use. */
5072 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5076 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
5077 srel
= htab
->relsbss
;
5079 srel
= htab
->relbss
;
5080 BFD_ASSERT (srel
!= NULL
);
5081 srel
->size
+= sizeof (Elf32_External_Rela
);
5085 return _bfd_elf_adjust_dynamic_copy (h
, s
);
5088 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
5089 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
5090 specifying the addend on the plt relocation. For -fpic code, the sym
5091 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
5092 xxxxxxxx.got2.plt_pic32.<callee>. */
5095 add_stub_sym (struct plt_entry
*ent
,
5096 struct elf_link_hash_entry
*h
,
5097 struct bfd_link_info
*info
)
5099 struct elf_link_hash_entry
*sh
;
5100 size_t len1
, len2
, len3
;
5103 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
5106 stub
= ".plt_pic32.";
5108 stub
= ".plt_call32.";
5110 len1
= strlen (h
->root
.root
.string
);
5111 len2
= strlen (stub
);
5114 len3
= strlen (ent
->sec
->name
);
5115 name
= bfd_malloc (len1
+ len2
+ len3
+ 9);
5118 sprintf (name
, "%08x", (unsigned) ent
->addend
& 0xffffffff);
5120 memcpy (name
+ 8, ent
->sec
->name
, len3
);
5121 memcpy (name
+ 8 + len3
, stub
, len2
);
5122 memcpy (name
+ 8 + len3
+ len2
, h
->root
.root
.string
, len1
+ 1);
5123 sh
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
5126 if (sh
->root
.type
== bfd_link_hash_new
)
5128 sh
->root
.type
= bfd_link_hash_defined
;
5129 sh
->root
.u
.def
.section
= htab
->glink
;
5130 sh
->root
.u
.def
.value
= ent
->glink_offset
;
5131 sh
->ref_regular
= 1;
5132 sh
->def_regular
= 1;
5133 sh
->ref_regular_nonweak
= 1;
5134 sh
->forced_local
= 1;
5140 /* Allocate NEED contiguous space in .got, and return the offset.
5141 Handles allocation of the got header when crossing 32k. */
5144 allocate_got (struct ppc_elf_link_hash_table
*htab
, unsigned int need
)
5147 unsigned int max_before_header
;
5149 if (htab
->plt_type
== PLT_VXWORKS
)
5151 where
= htab
->got
->size
;
5152 htab
->got
->size
+= need
;
5156 max_before_header
= htab
->plt_type
== PLT_NEW
? 32768 : 32764;
5157 if (need
<= htab
->got_gap
)
5159 where
= max_before_header
- htab
->got_gap
;
5160 htab
->got_gap
-= need
;
5164 if (htab
->got
->size
+ need
> max_before_header
5165 && htab
->got
->size
<= max_before_header
)
5167 htab
->got_gap
= max_before_header
- htab
->got
->size
;
5168 htab
->got
->size
= max_before_header
+ htab
->got_header_size
;
5170 where
= htab
->got
->size
;
5171 htab
->got
->size
+= need
;
5177 /* Allocate space in associated reloc sections for dynamic relocs. */
5180 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5182 struct bfd_link_info
*info
= inf
;
5183 struct ppc_elf_link_hash_entry
*eh
;
5184 struct ppc_elf_link_hash_table
*htab
;
5185 struct elf_dyn_relocs
*p
;
5187 if (h
->root
.type
== bfd_link_hash_indirect
)
5190 htab
= ppc_elf_hash_table (info
);
5191 if (htab
->elf
.dynamic_sections_created
5192 || h
->type
== STT_GNU_IFUNC
)
5194 struct plt_entry
*ent
;
5195 bfd_boolean doneone
= FALSE
;
5196 bfd_vma plt_offset
= 0, glink_offset
= 0;
5199 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5200 if (ent
->plt
.refcount
> 0)
5202 /* Make sure this symbol is output as a dynamic symbol. */
5203 if (h
->dynindx
== -1
5206 && htab
->elf
.dynamic_sections_created
)
5208 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5212 dyn
= htab
->elf
.dynamic_sections_created
;
5214 || h
->type
== STT_GNU_IFUNC
5215 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5217 asection
*s
= htab
->plt
;
5218 if (!dyn
|| h
->dynindx
== -1)
5221 if (htab
->plt_type
== PLT_NEW
|| !dyn
|| h
->dynindx
== -1)
5225 plt_offset
= s
->size
;
5228 ent
->plt
.offset
= plt_offset
;
5231 if (!doneone
|| info
->shared
)
5233 glink_offset
= s
->size
;
5234 s
->size
+= GLINK_ENTRY_SIZE
;
5235 if (h
== htab
->tls_get_addr
5236 && !htab
->no_tls_get_addr_opt
)
5237 s
->size
+= TLS_GET_ADDR_GLINK_SIZE
- GLINK_ENTRY_SIZE
;
5244 h
->root
.u
.def
.section
= s
;
5245 h
->root
.u
.def
.value
= glink_offset
;
5247 ent
->glink_offset
= glink_offset
;
5249 if (htab
->emit_stub_syms
5250 && !add_stub_sym (ent
, h
, info
))
5257 /* If this is the first .plt entry, make room
5258 for the special first entry. */
5260 s
->size
+= htab
->plt_initial_entry_size
;
5262 /* The PowerPC PLT is actually composed of two
5263 parts, the first part is 2 words (for a load
5264 and a jump), and then there is a remaining
5265 word available at the end. */
5266 plt_offset
= (htab
->plt_initial_entry_size
5267 + (htab
->plt_slot_size
5269 - htab
->plt_initial_entry_size
)
5270 / htab
->plt_entry_size
)));
5272 /* If this symbol is not defined in a regular
5273 file, and we are not generating a shared
5274 library, then set the symbol to this location
5275 in the .plt. This is to avoid text
5276 relocations, and is required to make
5277 function pointers compare as equal between
5278 the normal executable and the shared library. */
5283 h
->root
.u
.def
.section
= s
;
5284 h
->root
.u
.def
.value
= plt_offset
;
5287 /* Make room for this entry. */
5288 s
->size
+= htab
->plt_entry_size
;
5289 /* After the 8192nd entry, room for two entries
5291 if (htab
->plt_type
== PLT_OLD
5292 && (s
->size
- htab
->plt_initial_entry_size
)
5293 / htab
->plt_entry_size
5294 > PLT_NUM_SINGLE_ENTRIES
)
5295 s
->size
+= htab
->plt_entry_size
;
5297 ent
->plt
.offset
= plt_offset
;
5300 /* We also need to make an entry in the .rela.plt section. */
5303 if (!htab
->elf
.dynamic_sections_created
5304 || h
->dynindx
== -1)
5305 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5308 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
5310 if (htab
->plt_type
== PLT_VXWORKS
)
5312 /* Allocate space for the unloaded relocations. */
5314 && htab
->elf
.dynamic_sections_created
)
5317 == (bfd_vma
) htab
->plt_initial_entry_size
)
5319 htab
->srelplt2
->size
5320 += (sizeof (Elf32_External_Rela
)
5321 * VXWORKS_PLTRESOLVE_RELOCS
);
5324 htab
->srelplt2
->size
5325 += (sizeof (Elf32_External_Rela
)
5326 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
);
5329 /* Every PLT entry has an associated GOT entry in
5331 htab
->sgotplt
->size
+= 4;
5338 ent
->plt
.offset
= (bfd_vma
) -1;
5341 ent
->plt
.offset
= (bfd_vma
) -1;
5345 h
->plt
.plist
= NULL
;
5351 h
->plt
.plist
= NULL
;
5355 eh
= (struct ppc_elf_link_hash_entry
*) h
;
5356 if (eh
->elf
.got
.refcount
> 0)
5361 /* Make sure this symbol is output as a dynamic symbol. */
5362 if (eh
->elf
.dynindx
== -1
5363 && !eh
->elf
.forced_local
5364 && eh
->elf
.type
!= STT_GNU_IFUNC
5365 && htab
->elf
.dynamic_sections_created
)
5367 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
5372 if ((eh
->tls_mask
& TLS_TLS
) != 0)
5374 if ((eh
->tls_mask
& TLS_LD
) != 0)
5376 if (!eh
->elf
.def_dynamic
)
5377 /* We'll just use htab->tlsld_got.offset. This should
5378 always be the case. It's a little odd if we have
5379 a local dynamic reloc against a non-local symbol. */
5380 htab
->tlsld_got
.refcount
+= 1;
5384 if ((eh
->tls_mask
& TLS_GD
) != 0)
5386 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5388 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
5394 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5397 eh
->elf
.got
.offset
= allocate_got (htab
, need
);
5398 dyn
= htab
->elf
.dynamic_sections_created
;
5400 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
5401 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
5402 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
5404 asection
*rsec
= htab
->relgot
;
5405 /* All the entries we allocated need relocs.
5406 Except LD only needs one. */
5407 if ((eh
->tls_mask
& TLS_LD
) != 0
5408 && eh
->elf
.def_dynamic
)
5410 rsec
->size
+= need
* (sizeof (Elf32_External_Rela
) / 4);
5415 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5417 if (eh
->dyn_relocs
== NULL
5418 || !htab
->elf
.dynamic_sections_created
)
5421 /* In the shared -Bsymbolic case, discard space allocated for
5422 dynamic pc-relative relocs against symbols which turn out to be
5423 defined in regular objects. For the normal shared case, discard
5424 space for relocs that have become local due to symbol visibility
5429 /* Relocs that use pc_count are those that appear on a call insn,
5430 or certain REL relocs (see must_be_dyn_reloc) that can be
5431 generated via assembly. We want calls to protected symbols to
5432 resolve directly to the function rather than going via the plt.
5433 If people want function pointer comparisons to work as expected
5434 then they should avoid writing weird assembly. */
5435 if (SYMBOL_CALLS_LOCAL (info
, h
))
5437 struct elf_dyn_relocs
**pp
;
5439 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5441 p
->count
-= p
->pc_count
;
5450 if (htab
->is_vxworks
)
5452 struct elf_dyn_relocs
**pp
;
5454 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5456 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
5463 /* Discard relocs on undefined symbols that must be local. */
5464 if (eh
->dyn_relocs
!= NULL
5465 && h
->root
.type
== bfd_link_hash_undefined
5466 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
5467 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
5468 eh
->dyn_relocs
= NULL
;
5470 /* Also discard relocs on undefined weak syms with non-default
5472 if (eh
->dyn_relocs
!= NULL
5473 && h
->root
.type
== bfd_link_hash_undefweak
)
5475 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5476 eh
->dyn_relocs
= NULL
;
5478 /* Make sure undefined weak symbols are output as a dynamic
5480 else if (h
->dynindx
== -1
5484 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5489 else if (ELIMINATE_COPY_RELOCS
)
5491 /* For the non-shared case, discard space for relocs against
5492 symbols which turn out to need copy relocs or are not
5498 /* Make sure this symbol is output as a dynamic symbol.
5499 Undefined weak syms won't yet be marked as dynamic. */
5500 if (h
->dynindx
== -1
5501 && !h
->forced_local
)
5503 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5507 /* If that succeeded, we know we'll be keeping all the
5509 if (h
->dynindx
!= -1)
5513 eh
->dyn_relocs
= NULL
;
5518 /* Finally, allocate space. */
5519 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5521 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5522 if (!htab
->elf
.dynamic_sections_created
)
5523 sreloc
= htab
->reliplt
;
5524 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5530 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
5531 read-only sections. */
5534 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info
)
5536 if (h
->root
.type
== bfd_link_hash_indirect
)
5539 if (readonly_dynrelocs (h
))
5541 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
5543 /* Not an error, just cut short the traversal. */
5549 static const unsigned char glink_eh_frame_cie
[] =
5551 0, 0, 0, 16, /* length. */
5552 0, 0, 0, 0, /* id. */
5553 1, /* CIE version. */
5554 'z', 'R', 0, /* Augmentation string. */
5555 4, /* Code alignment. */
5556 0x7c, /* Data alignment. */
5558 1, /* Augmentation size. */
5559 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
5560 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
5563 /* Set the sizes of the dynamic sections. */
5566 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5567 struct bfd_link_info
*info
)
5569 struct ppc_elf_link_hash_table
*htab
;
5575 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
5578 htab
= ppc_elf_hash_table (info
);
5579 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
5581 if (elf_hash_table (info
)->dynamic_sections_created
)
5583 /* Set the contents of the .interp section to the interpreter. */
5584 if (info
->executable
)
5586 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
5587 BFD_ASSERT (s
!= NULL
);
5588 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5589 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5593 if (htab
->plt_type
== PLT_OLD
)
5594 htab
->got_header_size
= 16;
5595 else if (htab
->plt_type
== PLT_NEW
)
5596 htab
->got_header_size
= 12;
5598 /* Set up .got offsets for local syms, and space for local dynamic
5600 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5602 bfd_signed_vma
*local_got
;
5603 bfd_signed_vma
*end_local_got
;
5604 struct plt_entry
**local_plt
;
5605 struct plt_entry
**end_local_plt
;
5607 bfd_size_type locsymcount
;
5608 Elf_Internal_Shdr
*symtab_hdr
;
5610 if (!is_ppc_elf (ibfd
))
5613 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5615 struct elf_dyn_relocs
*p
;
5617 for (p
= ((struct elf_dyn_relocs
*)
5618 elf_section_data (s
)->local_dynrel
);
5622 if (!bfd_is_abs_section (p
->sec
)
5623 && bfd_is_abs_section (p
->sec
->output_section
))
5625 /* Input section has been discarded, either because
5626 it is a copy of a linkonce section or due to
5627 linker script /DISCARD/, so we'll be discarding
5630 else if (htab
->is_vxworks
5631 && strcmp (p
->sec
->output_section
->name
,
5634 /* Relocations in vxworks .tls_vars sections are
5635 handled specially by the loader. */
5637 else if (p
->count
!= 0)
5639 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5640 if (!htab
->elf
.dynamic_sections_created
)
5641 sreloc
= htab
->reliplt
;
5642 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5643 if ((p
->sec
->output_section
->flags
5644 & (SEC_READONLY
| SEC_ALLOC
))
5645 == (SEC_READONLY
| SEC_ALLOC
))
5646 info
->flags
|= DF_TEXTREL
;
5651 local_got
= elf_local_got_refcounts (ibfd
);
5655 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5656 locsymcount
= symtab_hdr
->sh_info
;
5657 end_local_got
= local_got
+ locsymcount
;
5658 local_plt
= (struct plt_entry
**) end_local_got
;
5659 end_local_plt
= local_plt
+ locsymcount
;
5660 lgot_masks
= (char *) end_local_plt
;
5662 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
5665 unsigned int need
= 0;
5666 if ((*lgot_masks
& TLS_TLS
) != 0)
5668 if ((*lgot_masks
& TLS_GD
) != 0)
5670 if ((*lgot_masks
& TLS_LD
) != 0)
5671 htab
->tlsld_got
.refcount
+= 1;
5672 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5674 if ((*lgot_masks
& TLS_DTPREL
) != 0)
5680 *local_got
= (bfd_vma
) -1;
5683 *local_got
= allocate_got (htab
, need
);
5685 htab
->relgot
->size
+= (need
5686 * (sizeof (Elf32_External_Rela
) / 4));
5690 *local_got
= (bfd_vma
) -1;
5692 if (htab
->is_vxworks
)
5695 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
5696 for (; local_plt
< end_local_plt
; ++local_plt
)
5698 struct plt_entry
*ent
;
5699 bfd_boolean doneone
= FALSE
;
5700 bfd_vma plt_offset
= 0, glink_offset
= 0;
5702 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
5703 if (ent
->plt
.refcount
> 0)
5709 plt_offset
= s
->size
;
5712 ent
->plt
.offset
= plt_offset
;
5715 if (!doneone
|| info
->shared
)
5717 glink_offset
= s
->size
;
5718 s
->size
+= GLINK_ENTRY_SIZE
;
5720 ent
->glink_offset
= glink_offset
;
5724 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5729 ent
->plt
.offset
= (bfd_vma
) -1;
5733 /* Allocate space for global sym dynamic relocs. */
5734 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
5736 if (htab
->tlsld_got
.refcount
> 0)
5738 htab
->tlsld_got
.offset
= allocate_got (htab
, 8);
5740 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
5743 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
5745 if (htab
->got
!= NULL
&& htab
->plt_type
!= PLT_VXWORKS
)
5747 unsigned int g_o_t
= 32768;
5749 /* If we haven't allocated the header, do so now. When we get here,
5750 for old plt/got the got size will be 0 to 32764 (not allocated),
5751 or 32780 to 65536 (header allocated). For new plt/got, the
5752 corresponding ranges are 0 to 32768 and 32780 to 65536. */
5753 if (htab
->got
->size
<= 32768)
5755 g_o_t
= htab
->got
->size
;
5756 if (htab
->plt_type
== PLT_OLD
)
5758 htab
->got
->size
+= htab
->got_header_size
;
5761 htab
->elf
.hgot
->root
.u
.def
.value
= g_o_t
;
5765 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
5767 && !(sda
->root
.type
== bfd_link_hash_defined
5768 || sda
->root
.type
== bfd_link_hash_defweak
))
5770 sda
->root
.type
= bfd_link_hash_defined
;
5771 sda
->root
.u
.def
.section
= htab
->elf
.hgot
->root
.u
.def
.section
;
5772 sda
->root
.u
.def
.value
= htab
->elf
.hgot
->root
.u
.def
.value
;
5776 if (htab
->glink
!= NULL
5777 && htab
->glink
->size
!= 0
5778 && htab
->elf
.dynamic_sections_created
)
5780 htab
->glink_pltresolve
= htab
->glink
->size
;
5781 /* Space for the branch table. */
5782 htab
->glink
->size
+= htab
->glink
->size
/ (GLINK_ENTRY_SIZE
/ 4) - 4;
5783 /* Pad out to align the start of PLTresolve. */
5784 htab
->glink
->size
+= -htab
->glink
->size
& 15;
5785 htab
->glink
->size
+= GLINK_PLTRESOLVE
;
5787 if (htab
->emit_stub_syms
)
5789 struct elf_link_hash_entry
*sh
;
5790 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink",
5791 TRUE
, FALSE
, FALSE
);
5794 if (sh
->root
.type
== bfd_link_hash_new
)
5796 sh
->root
.type
= bfd_link_hash_defined
;
5797 sh
->root
.u
.def
.section
= htab
->glink
;
5798 sh
->root
.u
.def
.value
= htab
->glink_pltresolve
;
5799 sh
->ref_regular
= 1;
5800 sh
->def_regular
= 1;
5801 sh
->ref_regular_nonweak
= 1;
5802 sh
->forced_local
= 1;
5805 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
5806 TRUE
, FALSE
, FALSE
);
5809 if (sh
->root
.type
== bfd_link_hash_new
)
5811 sh
->root
.type
= bfd_link_hash_defined
;
5812 sh
->root
.u
.def
.section
= htab
->glink
;
5813 sh
->root
.u
.def
.value
= htab
->glink
->size
- GLINK_PLTRESOLVE
;
5814 sh
->ref_regular
= 1;
5815 sh
->def_regular
= 1;
5816 sh
->ref_regular_nonweak
= 1;
5817 sh
->forced_local
= 1;
5823 if (htab
->glink
!= NULL
5824 && htab
->glink
->size
!= 0
5825 && htab
->glink_eh_frame
!= NULL
5826 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
))
5828 s
= htab
->glink_eh_frame
;
5829 s
->size
= sizeof (glink_eh_frame_cie
) + 20;
5833 if (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 8 >= 256)
5838 /* We've now determined the sizes of the various dynamic sections.
5839 Allocate memory for them. */
5841 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5843 bfd_boolean strip_section
= TRUE
;
5845 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5851 /* We'd like to strip these sections if they aren't needed, but if
5852 we've exported dynamic symbols from them we must leave them.
5853 It's too late to tell BFD to get rid of the symbols. */
5854 if (htab
->elf
.hplt
!= NULL
)
5855 strip_section
= FALSE
;
5856 /* Strip this section if we don't need it; see the
5859 else if (s
== htab
->iplt
5861 || s
== htab
->glink_eh_frame
5862 || s
== htab
->sgotplt
5864 || s
== htab
->dynbss
5865 || s
== htab
->dynsbss
5866 || s
== htab
->sdata
[0].section
5867 || s
== htab
->sdata
[1].section
)
5869 /* Strip these too. */
5871 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
5875 /* Remember whether there are any relocation sections. */
5878 /* We use the reloc_count field as a counter if we need
5879 to copy relocs into the output file. */
5885 /* It's not one of our sections, so don't allocate space. */
5889 if (s
->size
== 0 && strip_section
)
5891 /* If we don't need this section, strip it from the
5892 output file. This is mostly to handle .rela.bss and
5893 .rela.plt. We must create both sections in
5894 create_dynamic_sections, because they must be created
5895 before the linker maps input sections to output
5896 sections. The linker does that before
5897 adjust_dynamic_symbol is called, and it is that
5898 function which decides whether anything needs to go
5899 into these sections. */
5900 s
->flags
|= SEC_EXCLUDE
;
5904 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
5907 /* Allocate memory for the section contents. */
5908 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
5909 if (s
->contents
== NULL
)
5913 if (htab
->elf
.dynamic_sections_created
)
5915 /* Add some entries to the .dynamic section. We fill in the
5916 values later, in ppc_elf_finish_dynamic_sections, but we
5917 must add the entries now so that we get the correct size for
5918 the .dynamic section. The DT_DEBUG entry is filled in by the
5919 dynamic linker and used by the debugger. */
5920 #define add_dynamic_entry(TAG, VAL) \
5921 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5923 if (info
->executable
)
5925 if (!add_dynamic_entry (DT_DEBUG
, 0))
5929 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
5931 if (!add_dynamic_entry (DT_PLTGOT
, 0)
5932 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
5933 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
5934 || !add_dynamic_entry (DT_JMPREL
, 0))
5938 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
5940 if (!add_dynamic_entry (DT_PPC_GOT
, 0))
5942 if (!htab
->no_tls_get_addr_opt
5943 && htab
->tls_get_addr
!= NULL
5944 && htab
->tls_get_addr
->plt
.plist
!= NULL
5945 && !add_dynamic_entry (DT_PPC_TLSOPT
, 0))
5951 if (!add_dynamic_entry (DT_RELA
, 0)
5952 || !add_dynamic_entry (DT_RELASZ
, 0)
5953 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
5957 /* If any dynamic relocs apply to a read-only section, then we
5958 need a DT_TEXTREL entry. */
5959 if ((info
->flags
& DF_TEXTREL
) == 0)
5960 elf_link_hash_traverse (elf_hash_table (info
), maybe_set_textrel
,
5963 if ((info
->flags
& DF_TEXTREL
) != 0)
5965 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5968 if (htab
->is_vxworks
5969 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
5972 #undef add_dynamic_entry
5977 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5980 ppc_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5982 if (h
->plt
.plist
!= NULL
5984 && (!h
->pointer_equality_needed
5985 || !h
->ref_regular_nonweak
))
5988 return _bfd_elf_hash_symbol (h
);
5991 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5993 /* Relaxation trampolines. r12 is available for clobbering (r11, is
5994 used for some functions that are allowed to break the ABI). */
5995 static const int shared_stub_entry
[] =
5997 0x7c0802a6, /* mflr 0 */
5998 0x429f0005, /* bcl 20, 31, .Lxxx */
5999 0x7d8802a6, /* mflr 12 */
6000 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
6001 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */
6002 0x7c0803a6, /* mtlr 0 */
6003 0x7d8903a6, /* mtctr 12 */
6004 0x4e800420, /* bctr */
6007 static const int stub_entry
[] =
6009 0x3d800000, /* lis 12,xxx@ha */
6010 0x398c0000, /* addi 12,12,xxx@l */
6011 0x7d8903a6, /* mtctr 12 */
6012 0x4e800420, /* bctr */
6016 ppc_elf_relax_section (bfd
*abfd
,
6018 struct bfd_link_info
*link_info
,
6023 struct one_fixup
*next
;
6025 /* Final link, can use the symbol offset. For a
6026 relocatable link we use the symbol's index. */
6031 Elf_Internal_Shdr
*symtab_hdr
;
6032 bfd_byte
*contents
= NULL
;
6033 Elf_Internal_Sym
*isymbuf
= NULL
;
6034 Elf_Internal_Rela
*internal_relocs
= NULL
;
6035 Elf_Internal_Rela
*irel
, *irelend
;
6036 struct one_fixup
*fixups
= NULL
;
6037 unsigned changes
= 0;
6038 struct ppc_elf_link_hash_table
*htab
;
6039 bfd_size_type trampoff
;
6041 bfd_boolean maybe_pasted
;
6045 /* Nothing to do if there are no relocations, and no need to do
6046 anything with non-alloc or non-code sections. */
6047 if ((isec
->flags
& SEC_ALLOC
) == 0
6048 || (isec
->flags
& SEC_CODE
) == 0
6049 || (isec
->flags
& SEC_RELOC
) == 0
6050 || isec
->reloc_count
== 0)
6053 /* We cannot represent the required PIC relocs in the output, so don't
6054 do anything. The linker doesn't support mixing -shared and -r
6056 if (link_info
->relocatable
&& link_info
->shared
)
6059 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
6060 maybe_pasted
= (strcmp (isec
->output_section
->name
, ".init") == 0
6061 || strcmp (isec
->output_section
->name
, ".fini") == 0);
6062 /* Space for a branch around any trampolines. */
6066 symtab_hdr
= &elf_symtab_hdr (abfd
);
6068 /* Get a copy of the native relocations. */
6069 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
6070 link_info
->keep_memory
);
6071 if (internal_relocs
== NULL
)
6074 htab
= ppc_elf_hash_table (link_info
);
6075 got2
= bfd_get_section_by_name (abfd
, ".got2");
6077 irelend
= internal_relocs
+ isec
->reloc_count
;
6078 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6080 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
6083 struct one_fixup
*f
;
6084 size_t insn_offset
= 0;
6085 bfd_vma max_branch_offset
, val
;
6088 struct elf_link_hash_entry
*h
;
6089 struct plt_entry
**plist
;
6090 unsigned char sym_type
;
6095 case R_PPC_LOCAL24PC
:
6096 case R_PPC_PLTREL24
:
6097 max_branch_offset
= 1 << 25;
6101 case R_PPC_REL14_BRTAKEN
:
6102 case R_PPC_REL14_BRNTAKEN
:
6103 max_branch_offset
= 1 << 15;
6110 /* Get the value of the symbol referred to by the reloc. */
6112 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6114 /* A local symbol. */
6115 Elf_Internal_Sym
*isym
;
6117 /* Read this BFD's local symbols. */
6118 if (isymbuf
== NULL
)
6120 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6121 if (isymbuf
== NULL
)
6122 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
6123 symtab_hdr
->sh_info
, 0,
6128 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6129 if (isym
->st_shndx
== SHN_UNDEF
)
6130 tsec
= bfd_und_section_ptr
;
6131 else if (isym
->st_shndx
== SHN_ABS
)
6132 tsec
= bfd_abs_section_ptr
;
6133 else if (isym
->st_shndx
== SHN_COMMON
)
6134 tsec
= bfd_com_section_ptr
;
6136 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6138 toff
= isym
->st_value
;
6139 sym_type
= ELF_ST_TYPE (isym
->st_info
);
6143 /* Global symbol handling. */
6146 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6147 h
= elf_sym_hashes (abfd
)[indx
];
6149 while (h
->root
.type
== bfd_link_hash_indirect
6150 || h
->root
.type
== bfd_link_hash_warning
)
6151 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6153 if (h
->root
.type
== bfd_link_hash_defined
6154 || h
->root
.type
== bfd_link_hash_defweak
)
6156 tsec
= h
->root
.u
.def
.section
;
6157 toff
= h
->root
.u
.def
.value
;
6159 else if (h
->root
.type
== bfd_link_hash_undefined
6160 || h
->root
.type
== bfd_link_hash_undefweak
)
6162 tsec
= bfd_und_section_ptr
;
6163 toff
= link_info
->relocatable
? indx
: 0;
6171 /* The condition here under which we call find_plt_ent must
6172 match that in relocate_section. If we call find_plt_ent here
6173 but not in relocate_section, or vice versa, then the branch
6174 destination used here may be incorrect. */
6178 /* We know is_branch_reloc (r_type) is true. */
6179 if (h
->type
== STT_GNU_IFUNC
6180 || r_type
== R_PPC_PLTREL24
)
6181 plist
= &h
->plt
.plist
;
6183 else if (sym_type
== STT_GNU_IFUNC
6184 && elf_local_got_offsets (abfd
) != NULL
)
6186 bfd_vma
*local_got_offsets
= elf_local_got_offsets (abfd
);
6187 struct plt_entry
**local_plt
= (struct plt_entry
**)
6188 (local_got_offsets
+ symtab_hdr
->sh_info
);
6189 plist
= local_plt
+ ELF32_R_SYM (irel
->r_info
);
6194 struct plt_entry
*ent
;
6196 if (r_type
== R_PPC_PLTREL24
&& link_info
->shared
)
6197 addend
= irel
->r_addend
;
6198 ent
= find_plt_ent (plist
, got2
, addend
);
6201 if (htab
->plt_type
== PLT_NEW
6203 || !htab
->elf
.dynamic_sections_created
6204 || h
->dynindx
== -1)
6207 toff
= ent
->glink_offset
;
6212 toff
= ent
->plt
.offset
;
6217 /* If the branch and target are in the same section, you have
6218 no hope of adding stubs. We'll error out later should the
6223 /* There probably isn't any reason to handle symbols in
6224 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6225 attribute for a code section, and we are only looking at
6226 branches. However, implement it correctly here as a
6227 reference for other target relax_section functions. */
6228 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
6230 /* At this stage in linking, no SEC_MERGE symbol has been
6231 adjusted, so all references to such symbols need to be
6232 passed through _bfd_merged_section_offset. (Later, in
6233 relocate_section, all SEC_MERGE symbols *except* for
6234 section symbols have been adjusted.)
6236 gas may reduce relocations against symbols in SEC_MERGE
6237 sections to a relocation against the section symbol when
6238 the original addend was zero. When the reloc is against
6239 a section symbol we should include the addend in the
6240 offset passed to _bfd_merged_section_offset, since the
6241 location of interest is the original symbol. On the
6242 other hand, an access to "sym+addend" where "sym" is not
6243 a section symbol should not include the addend; Such an
6244 access is presumed to be an offset from "sym"; The
6245 location of interest is just "sym". */
6246 if (sym_type
== STT_SECTION
)
6247 toff
+= irel
->r_addend
;
6249 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
6250 elf_section_data (tsec
)->sec_info
,
6253 if (sym_type
!= STT_SECTION
)
6254 toff
+= irel
->r_addend
;
6256 /* PLTREL24 addends are special. */
6257 else if (r_type
!= R_PPC_PLTREL24
)
6258 toff
+= irel
->r_addend
;
6260 /* Attempted -shared link of non-pic code loses. */
6261 if (tsec
->output_section
== NULL
)
6264 roff
= irel
->r_offset
;
6266 /* If the branch is in range, no need to do anything. */
6267 if (tsec
!= bfd_und_section_ptr
6268 && (!link_info
->relocatable
6269 /* A relocatable link may have sections moved during
6270 final link, so do not presume they remain in range. */
6271 || tsec
->output_section
== isec
->output_section
))
6273 bfd_vma symaddr
, reladdr
;
6275 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
6276 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
6277 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
6281 /* Look for an existing fixup to this address. */
6282 for (f
= fixups
; f
; f
= f
->next
)
6283 if (f
->tsec
== tsec
&& f
->toff
== toff
)
6289 unsigned long stub_rtype
;
6291 val
= trampoff
- roff
;
6292 if (val
>= max_branch_offset
)
6293 /* Oh dear, we can't reach a trampoline. Don't try to add
6294 one. We'll report an error later. */
6297 if (link_info
->shared
)
6299 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
6304 size
= 4 * ARRAY_SIZE (stub_entry
);
6307 stub_rtype
= R_PPC_RELAX
;
6308 if (tsec
== htab
->plt
6309 || tsec
== htab
->glink
)
6311 stub_rtype
= R_PPC_RELAX_PLT
;
6312 if (r_type
== R_PPC_PLTREL24
)
6313 stub_rtype
= R_PPC_RELAX_PLTREL24
;
6316 /* Hijack the old relocation. Since we need two
6317 relocations for this use a "composite" reloc. */
6318 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
6320 irel
->r_offset
= trampoff
+ insn_offset
;
6321 if (r_type
== R_PPC_PLTREL24
6322 && stub_rtype
!= R_PPC_RELAX_PLTREL24
)
6325 /* Record the fixup so we don't do it again this section. */
6326 f
= bfd_malloc (sizeof (*f
));
6330 f
->trampoff
= trampoff
;
6338 val
= f
->trampoff
- roff
;
6339 if (val
>= max_branch_offset
)
6342 /* Nop out the reloc, since we're finalizing things here. */
6343 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6346 /* Get the section contents. */
6347 if (contents
== NULL
)
6349 /* Get cached copy if it exists. */
6350 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
6351 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6354 /* Go get them off disk. */
6355 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
6360 /* Fix up the existing branch to hit the trampoline. */
6361 hit_addr
= contents
+ roff
;
6365 case R_PPC_LOCAL24PC
:
6366 case R_PPC_PLTREL24
:
6367 t0
= bfd_get_32 (abfd
, hit_addr
);
6369 t0
|= val
& 0x3fffffc;
6370 bfd_put_32 (abfd
, t0
, hit_addr
);
6374 case R_PPC_REL14_BRTAKEN
:
6375 case R_PPC_REL14_BRNTAKEN
:
6376 t0
= bfd_get_32 (abfd
, hit_addr
);
6379 bfd_put_32 (abfd
, t0
, hit_addr
);
6384 /* Write out the trampolines. */
6393 struct one_fixup
*f
= fixups
;
6394 fixups
= fixups
->next
;
6399 contents
= bfd_realloc_or_free (contents
, trampoff
);
6400 if (contents
== NULL
)
6403 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
6404 dest
= contents
+ isec
->size
;
6405 /* Branch around the trampolines. */
6408 bfd_vma val
= B
+ trampoff
- isec
->size
;
6409 bfd_put_32 (abfd
, val
, dest
);
6412 isec
->size
= trampoff
;
6414 if (link_info
->shared
)
6416 stub
= shared_stub_entry
;
6417 size
= ARRAY_SIZE (shared_stub_entry
);
6422 size
= ARRAY_SIZE (stub_entry
);
6426 while (dest
< contents
+ trampoff
)
6428 bfd_put_32 (abfd
, stub
[i
], dest
);
6434 BFD_ASSERT (i
== 0);
6438 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
6440 if (! link_info
->keep_memory
)
6444 /* Cache the symbols for elf_link_input_bfd. */
6445 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
6449 if (contents
!= NULL
6450 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6452 if (!changes
&& !link_info
->keep_memory
)
6456 /* Cache the section contents for elf_link_input_bfd. */
6457 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6463 /* Append sufficient NOP relocs so we can write out relocation
6464 information for the trampolines. */
6465 Elf_Internal_Shdr
*rel_hdr
;
6466 Elf_Internal_Rela
*new_relocs
= bfd_malloc ((changes
+ isec
->reloc_count
)
6467 * sizeof (*new_relocs
));
6472 memcpy (new_relocs
, internal_relocs
,
6473 isec
->reloc_count
* sizeof (*new_relocs
));
6474 for (ix
= changes
; ix
--;)
6476 irel
= new_relocs
+ ix
+ isec
->reloc_count
;
6478 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6480 if (internal_relocs
!= elf_section_data (isec
)->relocs
)
6481 free (internal_relocs
);
6482 elf_section_data (isec
)->relocs
= new_relocs
;
6483 isec
->reloc_count
+= changes
;
6484 rel_hdr
= _bfd_elf_single_rel_hdr (isec
);
6485 rel_hdr
->sh_size
+= changes
* rel_hdr
->sh_entsize
;
6487 else if (elf_section_data (isec
)->relocs
!= internal_relocs
)
6488 free (internal_relocs
);
6490 *again
= changes
!= 0;
6491 if (!*again
&& link_info
->relocatable
)
6493 /* Convert the internal relax relocs to external form. */
6494 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6495 if (ELF32_R_TYPE (irel
->r_info
) == R_PPC_RELAX
)
6497 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
6499 /* Rewrite the reloc and convert one of the trailing nop
6500 relocs to describe this relocation. */
6501 BFD_ASSERT (ELF32_R_TYPE (irelend
[-1].r_info
) == R_PPC_NONE
);
6502 /* The relocs are at the bottom 2 bytes */
6503 irel
[0].r_offset
+= 2;
6504 memmove (irel
+ 1, irel
, (irelend
- irel
- 1) * sizeof (*irel
));
6505 irel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
6506 irel
[1].r_offset
+= 4;
6507 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
6515 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
6517 if (contents
!= NULL
6518 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6520 if (internal_relocs
!= NULL
6521 && elf_section_data (isec
)->relocs
!= internal_relocs
)
6522 free (internal_relocs
);
6526 /* What to do when ld finds relocations against symbols defined in
6527 discarded sections. */
6530 ppc_elf_action_discarded (asection
*sec
)
6532 if (strcmp (".fixup", sec
->name
) == 0)
6535 if (strcmp (".got2", sec
->name
) == 0)
6538 return _bfd_elf_default_action_discarded (sec
);
6541 /* Fill in the address for a pointer generated in a linker section. */
6544 elf_finish_pointer_linker_section (bfd
*input_bfd
,
6545 elf_linker_section_t
*lsect
,
6546 struct elf_link_hash_entry
*h
,
6548 const Elf_Internal_Rela
*rel
)
6550 elf_linker_section_pointers_t
*linker_section_ptr
;
6552 BFD_ASSERT (lsect
!= NULL
);
6556 /* Handle global symbol. */
6557 struct ppc_elf_link_hash_entry
*eh
;
6559 eh
= (struct ppc_elf_link_hash_entry
*) h
;
6560 BFD_ASSERT (eh
->elf
.def_regular
);
6561 linker_section_ptr
= eh
->linker_section_pointer
;
6565 /* Handle local symbol. */
6566 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
6568 BFD_ASSERT (is_ppc_elf (input_bfd
));
6569 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6570 linker_section_ptr
= elf_local_ptr_offsets (input_bfd
)[r_symndx
];
6573 linker_section_ptr
= elf_find_pointer_linker_section (linker_section_ptr
,
6576 BFD_ASSERT (linker_section_ptr
!= NULL
);
6578 /* Offset will always be a multiple of four, so use the bottom bit
6579 as a "written" flag. */
6580 if ((linker_section_ptr
->offset
& 1) == 0)
6582 bfd_put_32 (lsect
->section
->owner
,
6583 relocation
+ linker_section_ptr
->addend
,
6584 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6585 linker_section_ptr
->offset
+= 1;
6588 relocation
= (lsect
->section
->output_section
->vma
6589 + lsect
->section
->output_offset
6590 + linker_section_ptr
->offset
- 1
6591 - SYM_VAL (lsect
->sym
));
6595 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6596 lsect
->name
, (long) relocation
, (long) relocation
);
6602 #define PPC_LO(v) ((v) & 0xffff)
6603 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6604 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6607 write_glink_stub (struct plt_entry
*ent
, asection
*plt_sec
, unsigned char *p
,
6608 struct bfd_link_info
*info
)
6610 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
6611 bfd
*output_bfd
= info
->output_bfd
;
6614 plt
= ((ent
->plt
.offset
& ~1)
6615 + plt_sec
->output_section
->vma
6616 + plt_sec
->output_offset
);
6622 if (ent
->addend
>= 32768)
6624 + ent
->sec
->output_section
->vma
6625 + ent
->sec
->output_offset
);
6626 else if (htab
->elf
.hgot
!= NULL
)
6627 got
= SYM_VAL (htab
->elf
.hgot
);
6631 if (plt
+ 0x8000 < 0x10000)
6633 bfd_put_32 (output_bfd
, LWZ_11_30
+ PPC_LO (plt
), p
);
6635 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6637 bfd_put_32 (output_bfd
, BCTR
, p
);
6639 bfd_put_32 (output_bfd
, NOP
, p
);
6644 bfd_put_32 (output_bfd
, ADDIS_11_30
+ PPC_HA (plt
), p
);
6646 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6648 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6650 bfd_put_32 (output_bfd
, BCTR
, p
);
6656 bfd_put_32 (output_bfd
, LIS_11
+ PPC_HA (plt
), p
);
6658 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6660 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6662 bfd_put_32 (output_bfd
, BCTR
, p
);
6667 /* Return true if symbol is defined statically. */
6670 is_static_defined (struct elf_link_hash_entry
*h
)
6672 return ((h
->root
.type
== bfd_link_hash_defined
6673 || h
->root
.type
== bfd_link_hash_defweak
)
6674 && h
->root
.u
.def
.section
!= NULL
6675 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6678 /* If INSN is an opcode that may be used with an @tls operand, return
6679 the transformed insn for TLS optimisation, otherwise return 0. If
6680 REG is non-zero only match an insn with RB or RA equal to REG. */
6683 _bfd_elf_ppc_at_tls_transform (unsigned int insn
, unsigned int reg
)
6687 if ((insn
& (0x3f << 26)) != 31 << 26)
6690 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
6691 rtra
= insn
& ((1 << 26) - (1 << 16));
6692 else if (((insn
>> 16) & 0x1f) == reg
)
6693 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
6697 if ((insn
& (0x3ff << 1)) == 266 << 1)
6700 else if ((insn
& (0x1f << 1)) == 23 << 1
6701 && ((insn
& (0x1f << 6)) < 14 << 6
6702 || ((insn
& (0x1f << 6)) >= 16 << 6
6703 && (insn
& (0x1f << 6)) < 24 << 6)))
6704 /* load and store indexed -> dform. */
6705 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
6706 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
6707 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
6708 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
6709 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
6711 insn
= (58 << 26) | 2;
6718 /* If INSN is an opcode that may be used with an @tprel operand, return
6719 the transformed insn for an undefined weak symbol, ie. with the
6720 thread pointer REG operand removed. Otherwise return 0. */
6723 _bfd_elf_ppc_at_tprel_transform (unsigned int insn
, unsigned int reg
)
6725 if ((insn
& (0x1f << 16)) == reg
<< 16
6726 && ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6727 || (insn
& (0x3f << 26)) == 15u << 26 /* addis */
6728 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6729 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6730 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6731 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6732 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6733 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6734 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6735 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6736 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6737 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6738 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6739 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6740 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6741 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6743 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6744 && ((insn
& 3) == 0 || (insn
& 3) == 3))))
6746 insn
&= ~(0x1f << 16);
6748 else if ((insn
& (0x1f << 21)) == reg
<< 21
6749 && ((insn
& (0x3e << 26)) == 24u << 26 /* ori, oris */
6750 || (insn
& (0x3e << 26)) == 26u << 26 /* xori,xoris */
6751 || (insn
& (0x3e << 26)) == 28u << 26 /* andi,andis */))
6753 insn
&= ~(0x1f << 21);
6754 insn
|= (insn
& (0x1f << 16)) << 5;
6755 if ((insn
& (0x3e << 26)) == 26 << 26 /* xori,xoris */)
6756 insn
-= 2 >> 26; /* convert to ori,oris */
6763 /* The RELOCATE_SECTION function is called by the ELF backend linker
6764 to handle the relocations for a section.
6766 The relocs are always passed as Rela structures; if the section
6767 actually uses Rel structures, the r_addend field will always be
6770 This function is responsible for adjust the section contents as
6771 necessary, and (if using Rela relocs and generating a
6772 relocatable output file) adjusting the reloc addend as
6775 This function does not have to worry about setting the reloc
6776 address or the reloc symbol index.
6778 LOCAL_SYMS is a pointer to the swapped in local symbols.
6780 LOCAL_SECTIONS is an array giving the section in the input file
6781 corresponding to the st_shndx field of each local symbol.
6783 The global hash table entry for the global symbols can be found
6784 via elf_sym_hashes (input_bfd).
6786 When generating relocatable output, this function must handle
6787 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6788 going to be the section symbol corresponding to the output
6789 section, which means that the addend must be adjusted
6793 ppc_elf_relocate_section (bfd
*output_bfd
,
6794 struct bfd_link_info
*info
,
6796 asection
*input_section
,
6798 Elf_Internal_Rela
*relocs
,
6799 Elf_Internal_Sym
*local_syms
,
6800 asection
**local_sections
)
6802 Elf_Internal_Shdr
*symtab_hdr
;
6803 struct elf_link_hash_entry
**sym_hashes
;
6804 struct ppc_elf_link_hash_table
*htab
;
6805 Elf_Internal_Rela
*rel
;
6806 Elf_Internal_Rela
*relend
;
6807 Elf_Internal_Rela outrel
;
6808 asection
*got2
, *sreloc
= NULL
;
6809 bfd_vma
*local_got_offsets
;
6810 bfd_boolean ret
= TRUE
;
6811 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
6812 bfd_boolean is_vxworks_tls
;
6815 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
6816 "%ld relocations%s",
6817 input_bfd
, input_section
,
6818 (long) input_section
->reloc_count
,
6819 (info
->relocatable
) ? " (relocatable)" : "");
6822 got2
= bfd_get_section_by_name (input_bfd
, ".got2");
6824 /* Initialize howto table if not already done. */
6825 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
6826 ppc_elf_howto_init ();
6828 htab
= ppc_elf_hash_table (info
);
6829 local_got_offsets
= elf_local_got_offsets (input_bfd
);
6830 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6831 sym_hashes
= elf_sym_hashes (input_bfd
);
6832 /* We have to handle relocations in vxworks .tls_vars sections
6833 specially, because the dynamic loader is 'weird'. */
6834 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
6835 && !strcmp (input_section
->output_section
->name
,
6838 relend
= relocs
+ input_section
->reloc_count
;
6839 for (; rel
< relend
; rel
++)
6841 enum elf_ppc_reloc_type r_type
;
6843 bfd_reloc_status_type r
;
6844 Elf_Internal_Sym
*sym
;
6846 struct elf_link_hash_entry
*h
;
6847 const char *sym_name
;
6848 reloc_howto_type
*howto
;
6849 unsigned long r_symndx
;
6851 bfd_vma branch_bit
, from
;
6852 bfd_boolean unresolved_reloc
;
6854 unsigned int tls_type
, tls_mask
, tls_gd
;
6855 struct plt_entry
**ifunc
;
6857 r_type
= ELF32_R_TYPE (rel
->r_info
);
6861 unresolved_reloc
= FALSE
;
6863 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6865 if (r_symndx
< symtab_hdr
->sh_info
)
6867 sym
= local_syms
+ r_symndx
;
6868 sec
= local_sections
[r_symndx
];
6869 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
6871 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6875 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6876 r_symndx
, symtab_hdr
, sym_hashes
,
6878 unresolved_reloc
, warned
);
6880 sym_name
= h
->root
.root
.string
;
6883 if (sec
!= NULL
&& elf_discarded_section (sec
))
6885 /* For relocs against symbols from removed linkonce sections,
6886 or sections discarded by a linker script, we just want the
6887 section contents zeroed. Avoid any special processing. */
6889 if (r_type
< R_PPC_max
)
6890 howto
= ppc_elf_howto_table
[r_type
];
6891 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
6892 rel
, relend
, howto
, contents
);
6895 if (info
->relocatable
)
6898 && r_type
== R_PPC_PLTREL24
6899 && rel
->r_addend
>= 32768)
6901 /* R_PPC_PLTREL24 is rather special. If non-zero, the
6902 addend specifies the GOT pointer offset within .got2. */
6903 rel
->r_addend
+= got2
->output_offset
;
6908 /* TLS optimizations. Replace instruction sequences and relocs
6909 based on information we collected in tls_optimize. We edit
6910 RELOCS so that --emit-relocs will output something sensible
6911 for the final instruction stream. */
6915 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
6916 else if (local_got_offsets
!= NULL
)
6918 struct plt_entry
**local_plt
;
6921 = (struct plt_entry
**) (local_got_offsets
+ symtab_hdr
->sh_info
);
6922 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
6923 tls_mask
= lgot_masks
[r_symndx
];
6926 /* Ensure reloc mapping code below stays sane. */
6927 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
6928 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
6929 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
6930 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
6931 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
6932 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
6933 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
6934 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
6941 case R_PPC_GOT_TPREL16
:
6942 case R_PPC_GOT_TPREL16_LO
:
6943 if ((tls_mask
& TLS_TLS
) != 0
6944 && (tls_mask
& TLS_TPREL
) == 0)
6948 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
6950 insn
|= 0x3c020000; /* addis 0,2,0 */
6951 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
6952 r_type
= R_PPC_TPREL16_HA
;
6953 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6958 if ((tls_mask
& TLS_TLS
) != 0
6959 && (tls_mask
& TLS_TPREL
) == 0)
6963 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6964 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 2);
6967 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
6968 r_type
= R_PPC_TPREL16_LO
;
6969 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6971 /* Was PPC_TLS which sits on insn boundary, now
6972 PPC_TPREL16_LO which is at low-order half-word. */
6973 rel
->r_offset
+= d_offset
;
6977 case R_PPC_GOT_TLSGD16_HI
:
6978 case R_PPC_GOT_TLSGD16_HA
:
6979 tls_gd
= TLS_TPRELGD
;
6980 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6984 case R_PPC_GOT_TLSLD16_HI
:
6985 case R_PPC_GOT_TLSLD16_HA
:
6986 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6989 if ((tls_mask
& tls_gd
) != 0)
6990 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
6991 + R_PPC_GOT_TPREL16
);
6994 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
6995 rel
->r_offset
-= d_offset
;
6996 r_type
= R_PPC_NONE
;
6998 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7002 case R_PPC_GOT_TLSGD16
:
7003 case R_PPC_GOT_TLSGD16_LO
:
7004 tls_gd
= TLS_TPRELGD
;
7005 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
7009 case R_PPC_GOT_TLSLD16
:
7010 case R_PPC_GOT_TLSLD16_LO
:
7011 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
7013 unsigned int insn1
, insn2
;
7017 offset
= (bfd_vma
) -1;
7018 /* If not using the newer R_PPC_TLSGD/LD to mark
7019 __tls_get_addr calls, we must trust that the call
7020 stays with its arg setup insns, ie. that the next
7021 reloc is the __tls_get_addr call associated with
7022 the current reloc. Edit both insns. */
7023 if (input_section
->has_tls_get_addr_call
7025 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
7026 htab
->tls_get_addr
))
7027 offset
= rel
[1].r_offset
;
7028 if ((tls_mask
& tls_gd
) != 0)
7031 insn1
= bfd_get_32 (output_bfd
,
7032 contents
+ rel
->r_offset
- d_offset
);
7033 insn1
&= (1 << 26) - 1;
7034 insn1
|= 32 << 26; /* lwz */
7035 if (offset
!= (bfd_vma
) -1)
7037 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7038 insn2
= 0x7c631214; /* add 3,3,2 */
7039 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7041 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
7042 + R_PPC_GOT_TPREL16
);
7043 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7048 insn1
= 0x3c620000; /* addis 3,2,0 */
7051 /* Was an LD reloc. */
7053 r_symndx
< symtab_hdr
->sh_info
;
7055 if (local_sections
[r_symndx
] == sec
)
7057 if (r_symndx
>= symtab_hdr
->sh_info
)
7058 r_symndx
= STN_UNDEF
;
7059 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7060 if (r_symndx
!= STN_UNDEF
)
7061 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7062 + sec
->output_offset
7063 + sec
->output_section
->vma
);
7065 r_type
= R_PPC_TPREL16_HA
;
7066 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7067 if (offset
!= (bfd_vma
) -1)
7069 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7070 rel
[1].r_offset
= offset
+ d_offset
;
7071 rel
[1].r_addend
= rel
->r_addend
;
7072 insn2
= 0x38630000; /* addi 3,3,0 */
7073 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7076 bfd_put_32 (output_bfd
, insn1
,
7077 contents
+ rel
->r_offset
- d_offset
);
7080 /* We changed the symbol on an LD reloc. Start over
7081 in order to get h, sym, sec etc. right. */
7089 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
7092 bfd_vma offset
= rel
->r_offset
;
7094 if ((tls_mask
& TLS_TPRELGD
) != 0)
7097 r_type
= R_PPC_NONE
;
7098 insn2
= 0x7c631214; /* add 3,3,2 */
7103 r_type
= R_PPC_TPREL16_LO
;
7104 rel
->r_offset
+= d_offset
;
7105 insn2
= 0x38630000; /* addi 3,3,0 */
7107 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7108 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7109 /* Zap the reloc on the _tls_get_addr call too. */
7110 BFD_ASSERT (offset
== rel
[1].r_offset
);
7111 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7116 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
7121 r_symndx
< symtab_hdr
->sh_info
;
7123 if (local_sections
[r_symndx
] == sec
)
7125 if (r_symndx
>= symtab_hdr
->sh_info
)
7126 r_symndx
= STN_UNDEF
;
7127 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7128 if (r_symndx
!= STN_UNDEF
)
7129 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7130 + sec
->output_offset
7131 + sec
->output_section
->vma
);
7133 rel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7134 rel
->r_offset
+= d_offset
;
7135 insn2
= 0x38630000; /* addi 3,3,0 */
7136 bfd_put_32 (output_bfd
, insn2
,
7137 contents
+ rel
->r_offset
- d_offset
);
7138 /* Zap the reloc on the _tls_get_addr call too. */
7139 BFD_ASSERT (rel
->r_offset
- d_offset
== rel
[1].r_offset
);
7140 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7147 /* Handle other relocations that tweak non-addend part of insn. */
7154 /* Branch taken prediction relocations. */
7155 case R_PPC_ADDR14_BRTAKEN
:
7156 case R_PPC_REL14_BRTAKEN
:
7157 branch_bit
= BRANCH_PREDICT_BIT
;
7160 /* Branch not taken prediction relocations. */
7161 case R_PPC_ADDR14_BRNTAKEN
:
7162 case R_PPC_REL14_BRNTAKEN
:
7166 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7167 insn
&= ~BRANCH_PREDICT_BIT
;
7170 from
= (rel
->r_offset
7171 + input_section
->output_offset
7172 + input_section
->output_section
->vma
);
7174 /* Invert 'y' bit if not the default. */
7175 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7176 insn
^= BRANCH_PREDICT_BIT
;
7178 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7184 if (!htab
->is_vxworks
)
7186 struct plt_entry
*ent
;
7190 if (h
->type
== STT_GNU_IFUNC
)
7191 ifunc
= &h
->plt
.plist
;
7193 else if (local_got_offsets
!= NULL
7194 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
7196 struct plt_entry
**local_plt
;
7198 local_plt
= (struct plt_entry
**) (local_got_offsets
7199 + symtab_hdr
->sh_info
);
7200 ifunc
= local_plt
+ r_symndx
;
7206 || is_branch_reloc (r_type
)))
7209 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
7210 addend
= rel
->r_addend
;
7211 ent
= find_plt_ent (ifunc
, got2
, addend
);
7215 if (h
== NULL
&& (ent
->plt
.offset
& 1) == 0)
7217 Elf_Internal_Rela rela
;
7220 rela
.r_offset
= (htab
->iplt
->output_section
->vma
7221 + htab
->iplt
->output_offset
7223 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7224 rela
.r_addend
= relocation
;
7225 loc
= htab
->reliplt
->contents
;
7226 loc
+= (htab
->reliplt
->reloc_count
++
7227 * sizeof (Elf32_External_Rela
));
7228 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
7230 ent
->plt
.offset
|= 1;
7232 if (h
== NULL
&& (ent
->glink_offset
& 1) == 0)
7234 unsigned char *p
= ((unsigned char *) htab
->glink
->contents
7235 + ent
->glink_offset
);
7236 write_glink_stub (ent
, htab
->iplt
, p
, info
);
7237 ent
->glink_offset
|= 1;
7240 unresolved_reloc
= FALSE
;
7241 if (htab
->plt_type
== PLT_NEW
7242 || !htab
->elf
.dynamic_sections_created
7244 relocation
= (htab
->glink
->output_section
->vma
7245 + htab
->glink
->output_offset
7246 + (ent
->glink_offset
& ~1));
7248 relocation
= (htab
->plt
->output_section
->vma
7249 + htab
->plt
->output_offset
7254 addend
= rel
->r_addend
;
7257 if (r_type
< R_PPC_max
)
7258 howto
= ppc_elf_howto_table
[r_type
];
7262 info
->callbacks
->einfo
7263 (_("%P: %B: unknown relocation type %d for symbol %s\n"),
7264 input_bfd
, (int) r_type
, sym_name
);
7266 bfd_set_error (bfd_error_bad_value
);
7274 case R_PPC_EMB_MRKREF
:
7275 case R_PPC_GNU_VTINHERIT
:
7276 case R_PPC_GNU_VTENTRY
:
7279 /* GOT16 relocations. Like an ADDR16 using the symbol's
7280 address in the GOT as relocation value instead of the
7281 symbol's value itself. Also, create a GOT entry for the
7282 symbol and put the symbol value there. */
7283 case R_PPC_GOT_TLSGD16
:
7284 case R_PPC_GOT_TLSGD16_LO
:
7285 case R_PPC_GOT_TLSGD16_HI
:
7286 case R_PPC_GOT_TLSGD16_HA
:
7287 tls_type
= TLS_TLS
| TLS_GD
;
7290 case R_PPC_GOT_TLSLD16
:
7291 case R_PPC_GOT_TLSLD16_LO
:
7292 case R_PPC_GOT_TLSLD16_HI
:
7293 case R_PPC_GOT_TLSLD16_HA
:
7294 tls_type
= TLS_TLS
| TLS_LD
;
7297 case R_PPC_GOT_TPREL16
:
7298 case R_PPC_GOT_TPREL16_LO
:
7299 case R_PPC_GOT_TPREL16_HI
:
7300 case R_PPC_GOT_TPREL16_HA
:
7301 tls_type
= TLS_TLS
| TLS_TPREL
;
7304 case R_PPC_GOT_DTPREL16
:
7305 case R_PPC_GOT_DTPREL16_LO
:
7306 case R_PPC_GOT_DTPREL16_HI
:
7307 case R_PPC_GOT_DTPREL16_HA
:
7308 tls_type
= TLS_TLS
| TLS_DTPREL
;
7312 case R_PPC_GOT16_LO
:
7313 case R_PPC_GOT16_HI
:
7314 case R_PPC_GOT16_HA
:
7318 /* Relocation is to the entry for this symbol in the global
7324 if (htab
->got
== NULL
)
7328 if (tls_type
== (TLS_TLS
| TLS_LD
)
7330 || !h
->def_dynamic
))
7331 offp
= &htab
->tlsld_got
.offset
;
7335 dyn
= htab
->elf
.dynamic_sections_created
;
7336 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7338 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
7339 /* This is actually a static link, or it is a
7340 -Bsymbolic link and the symbol is defined
7341 locally, or the symbol was forced to be local
7342 because of a version file. */
7347 unresolved_reloc
= FALSE
;
7349 offp
= &h
->got
.offset
;
7353 if (local_got_offsets
== NULL
)
7355 offp
= &local_got_offsets
[r_symndx
];
7358 /* The offset must always be a multiple of 4. We use the
7359 least significant bit to record whether we have already
7360 processed this entry. */
7366 unsigned int tls_m
= (tls_mask
7367 & (TLS_LD
| TLS_GD
| TLS_DTPREL
7368 | TLS_TPREL
| TLS_TPRELGD
));
7370 if (offp
== &htab
->tlsld_got
.offset
)
7376 /* We might have multiple got entries for this sym.
7377 Initialize them all. */
7382 if ((tls_m
& TLS_LD
) != 0)
7384 tls_ty
= TLS_TLS
| TLS_LD
;
7387 else if ((tls_m
& TLS_GD
) != 0)
7389 tls_ty
= TLS_TLS
| TLS_GD
;
7392 else if ((tls_m
& TLS_DTPREL
) != 0)
7394 tls_ty
= TLS_TLS
| TLS_DTPREL
;
7395 tls_m
&= ~TLS_DTPREL
;
7397 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
7399 tls_ty
= TLS_TLS
| TLS_TPREL
;
7403 /* Generate relocs for the dynamic linker. */
7404 if ((info
->shared
|| indx
!= 0)
7405 && (offp
== &htab
->tlsld_got
.offset
7407 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7408 || h
->root
.type
!= bfd_link_hash_undefweak
))
7410 asection
*rsec
= htab
->relgot
;
7413 outrel
.r_offset
= (htab
->got
->output_section
->vma
7414 + htab
->got
->output_offset
7416 outrel
.r_addend
= 0;
7417 if (tls_ty
& (TLS_LD
| TLS_GD
))
7419 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
7420 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7422 loc
= rsec
->contents
;
7423 loc
+= (rsec
->reloc_count
++
7424 * sizeof (Elf32_External_Rela
));
7425 bfd_elf32_swap_reloca_out (output_bfd
,
7427 outrel
.r_offset
+= 4;
7429 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7432 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
7433 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7434 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7435 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
7437 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
7438 else if (ifunc
!= NULL
)
7439 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7441 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7442 if (indx
== 0 && tls_ty
!= (TLS_TLS
| TLS_LD
))
7444 outrel
.r_addend
+= relocation
;
7445 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
7446 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
7448 loc
= rsec
->contents
;
7449 loc
+= (rsec
->reloc_count
++
7450 * sizeof (Elf32_External_Rela
));
7451 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7454 /* Init the .got section contents if we're not
7455 emitting a reloc. */
7458 bfd_vma value
= relocation
;
7460 if (tls_ty
== (TLS_TLS
| TLS_LD
))
7462 else if (tls_ty
!= 0)
7464 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7465 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7466 value
+= DTP_OFFSET
- TP_OFFSET
;
7468 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7470 bfd_put_32 (output_bfd
, value
,
7471 htab
->got
->contents
+ off
+ 4);
7475 bfd_put_32 (output_bfd
, value
,
7476 htab
->got
->contents
+ off
);
7480 if (tls_ty
& (TLS_LD
| TLS_GD
))
7489 if (off
>= (bfd_vma
) -2)
7492 if ((tls_type
& TLS_TLS
) != 0)
7494 if (tls_type
!= (TLS_TLS
| TLS_LD
))
7496 if ((tls_mask
& TLS_LD
) != 0
7498 || !h
->def_dynamic
))
7500 if (tls_type
!= (TLS_TLS
| TLS_GD
))
7502 if ((tls_mask
& TLS_GD
) != 0)
7504 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
7506 if ((tls_mask
& TLS_DTPREL
) != 0)
7513 relocation
= (htab
->got
->output_section
->vma
7514 + htab
->got
->output_offset
7516 - SYM_VAL (htab
->elf
.hgot
));
7518 /* Addends on got relocations don't make much sense.
7519 x+off@got is actually x@got+off, and since the got is
7520 generated by a hash table traversal, the value in the
7521 got at entry m+n bears little relation to the entry m. */
7523 info
->callbacks
->einfo
7524 (_("%P: %H: non-zero addend on %s reloc against `%s'\n"),
7525 input_bfd
, input_section
, rel
->r_offset
,
7531 /* Relocations that need no special processing. */
7532 case R_PPC_LOCAL24PC
:
7533 /* It makes no sense to point a local relocation
7534 at a symbol not in this object. */
7535 if (unresolved_reloc
)
7537 if (! (*info
->callbacks
->undefined_symbol
) (info
,
7538 h
->root
.root
.string
,
7548 case R_PPC_DTPREL16
:
7549 case R_PPC_DTPREL16_LO
:
7550 case R_PPC_DTPREL16_HI
:
7551 case R_PPC_DTPREL16_HA
:
7552 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7555 /* Relocations that may need to be propagated if this is a shared
7558 case R_PPC_TPREL16_LO
:
7559 case R_PPC_TPREL16_HI
:
7560 case R_PPC_TPREL16_HA
:
7562 && h
->root
.type
== bfd_link_hash_undefweak
7563 && h
->dynindx
== -1)
7565 /* Make this relocation against an undefined weak symbol
7566 resolve to zero. This is really just a tweak, since
7567 code using weak externs ought to check that they are
7568 defined before using them. */
7569 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
7570 unsigned int insn
= bfd_get_32 (output_bfd
, p
);
7571 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 2);
7573 bfd_put_32 (output_bfd
, insn
, p
);
7576 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7577 /* The TPREL16 relocs shouldn't really be used in shared
7578 libs as they will result in DT_TEXTREL being set, but
7579 support them anyway. */
7583 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7586 case R_PPC_DTPREL32
:
7587 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7590 case R_PPC_DTPMOD32
:
7596 case R_PPC_REL16_LO
:
7597 case R_PPC_REL16_HI
:
7598 case R_PPC_REL16_HA
:
7602 if (h
== NULL
|| h
== htab
->elf
.hgot
)
7608 case R_PPC_ADDR16_LO
:
7609 case R_PPC_ADDR16_HI
:
7610 case R_PPC_ADDR16_HA
:
7617 case R_PPC_REL14_BRTAKEN
:
7618 case R_PPC_REL14_BRNTAKEN
:
7619 /* If these relocations are not to a named symbol, they can be
7620 handled right here, no need to bother the dynamic linker. */
7621 if (SYMBOL_CALLS_LOCAL (info
, h
)
7622 || h
== htab
->elf
.hgot
)
7628 case R_PPC_ADDR14_BRTAKEN
:
7629 case R_PPC_ADDR14_BRNTAKEN
:
7630 if (h
!= NULL
&& !info
->shared
)
7635 if ((input_section
->flags
& SEC_ALLOC
) == 0
7641 && ((h
->root
.type
== bfd_link_hash_undefined
7642 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
7643 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
7644 || (h
->root
.type
== bfd_link_hash_undefweak
7645 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)))
7646 && (must_be_dyn_reloc (info
, r_type
)
7647 || !SYMBOL_CALLS_LOCAL (info
, h
)))
7648 || (ELIMINATE_COPY_RELOCS
7653 && !h
->def_regular
))
7658 fprintf (stderr
, "ppc_elf_relocate_section needs to "
7659 "create relocation for %s\n",
7660 (h
&& h
->root
.root
.string
7661 ? h
->root
.root
.string
: "<unknown>"));
7664 /* When generating a shared object, these relocations
7665 are copied into the output file to be resolved at run
7669 sreloc
= elf_section_data (input_section
)->sreloc
;
7670 if (!htab
->elf
.dynamic_sections_created
)
7671 sreloc
= htab
->reliplt
;
7677 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
, info
,
7680 if (outrel
.r_offset
== (bfd_vma
) -1
7681 || outrel
.r_offset
== (bfd_vma
) -2)
7682 skip
= (int) outrel
.r_offset
;
7683 outrel
.r_offset
+= (input_section
->output_section
->vma
7684 + input_section
->output_offset
);
7687 memset (&outrel
, 0, sizeof outrel
);
7689 && (h
->root
.type
== bfd_link_hash_undefined
7690 || h
->root
.type
== bfd_link_hash_undefweak
))
7691 || !SYMBOL_REFERENCES_LOCAL (info
, h
))
7693 unresolved_reloc
= FALSE
;
7694 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
7695 outrel
.r_addend
= rel
->r_addend
;
7699 outrel
.r_addend
= relocation
+ rel
->r_addend
;
7701 if (r_type
!= R_PPC_ADDR32
)
7707 /* If we get here when building a static
7708 executable, then the libc startup function
7709 responsible for applying indirect function
7710 relocations is going to complain about
7712 If we get here when building a dynamic
7713 executable, it will be because we have
7714 a text relocation. The dynamic loader
7715 will set the text segment writable and
7716 non-executable to apply text relocations.
7717 So we'll segfault when trying to run the
7718 indirection function to resolve the reloc. */
7719 info
->callbacks
->einfo
7720 (_("%P: %H: relocation %s for indirect "
7721 "function %s unsupported\n"),
7722 input_bfd
, input_section
, rel
->r_offset
,
7727 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
7729 else if (sec
== NULL
|| sec
->owner
== NULL
)
7731 bfd_set_error (bfd_error_bad_value
);
7738 /* We are turning this relocation into one
7739 against a section symbol. It would be
7740 proper to subtract the symbol's value,
7741 osec->vma, from the emitted reloc addend,
7742 but ld.so expects buggy relocs.
7743 FIXME: Why not always use a zero index? */
7744 osec
= sec
->output_section
;
7745 indx
= elf_section_data (osec
)->dynindx
;
7748 osec
= htab
->elf
.text_index_section
;
7749 indx
= elf_section_data (osec
)->dynindx
;
7751 BFD_ASSERT (indx
!= 0);
7754 printf ("indx=%ld section=%s flags=%08x name=%s\n",
7755 indx
, osec
->name
, osec
->flags
,
7756 h
->root
.root
.string
);
7760 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
7762 else if (ifunc
!= NULL
)
7763 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7765 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7768 loc
= sreloc
->contents
;
7769 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7770 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7775 /* This reloc will be computed at runtime. We clear the memory
7776 so that it contains predictable value. */
7778 && ((input_section
->flags
& SEC_ALLOC
) != 0
7779 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
7781 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
7788 case R_PPC_RELAX_PLT
:
7789 case R_PPC_RELAX_PLTREL24
:
7792 struct plt_entry
*ent
;
7793 bfd_vma got2_addend
= 0;
7795 if (r_type
== R_PPC_RELAX_PLTREL24
)
7798 got2_addend
= addend
;
7801 ent
= find_plt_ent (&h
->plt
.plist
, got2
, got2_addend
);
7802 if (htab
->plt_type
== PLT_NEW
)
7803 relocation
= (htab
->glink
->output_section
->vma
7804 + htab
->glink
->output_offset
7805 + ent
->glink_offset
);
7807 relocation
= (htab
->plt
->output_section
->vma
7808 + htab
->plt
->output_offset
7815 relocation
-= (input_section
->output_section
->vma
7816 + input_section
->output_offset
7817 + rel
->r_offset
- 4);
7823 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7824 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
7826 /* We're clearing the bits for R_PPC_ADDR16_HA
7827 and R_PPC_ADDR16_LO here. */
7831 /* t0 is HA, t1 is LO */
7832 relocation
+= addend
;
7833 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
7834 t1
|= relocation
& 0xffff;
7836 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
7837 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
7839 /* Rewrite the reloc and convert one of the trailing nop
7840 relocs to describe this relocation. */
7841 BFD_ASSERT (ELF32_R_TYPE (relend
[-1].r_info
) == R_PPC_NONE
);
7842 /* The relocs are at the bottom 2 bytes */
7843 rel
[0].r_offset
+= 2;
7844 memmove (rel
+ 1, rel
, (relend
- rel
- 1) * sizeof (*rel
));
7845 rel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
7846 rel
[1].r_offset
+= 4;
7847 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
7852 /* Indirect .sdata relocation. */
7853 case R_PPC_EMB_SDAI16
:
7854 BFD_ASSERT (htab
->sdata
[0].section
!= NULL
);
7855 if (!is_static_defined (htab
->sdata
[0].sym
))
7857 unresolved_reloc
= TRUE
;
7861 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[0],
7862 h
, relocation
, rel
);
7866 /* Indirect .sdata2 relocation. */
7867 case R_PPC_EMB_SDA2I16
:
7868 BFD_ASSERT (htab
->sdata
[1].section
!= NULL
);
7869 if (!is_static_defined (htab
->sdata
[1].sym
))
7871 unresolved_reloc
= TRUE
;
7875 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[1],
7876 h
, relocation
, rel
);
7880 /* Handle the TOC16 reloc. We want to use the offset within the .got
7881 section, not the actual VMA. This is appropriate when generating
7882 an embedded ELF object, for which the .got section acts like the
7883 AIX .toc section. */
7884 case R_PPC_TOC16
: /* phony GOT16 relocations */
7885 if (sec
== NULL
|| sec
->output_section
== NULL
)
7887 unresolved_reloc
= TRUE
;
7890 BFD_ASSERT (strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
7891 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
7893 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
7896 case R_PPC_PLTREL24
:
7897 if (h
== NULL
|| ifunc
!= NULL
)
7899 /* Relocation is to the entry for this symbol in the
7900 procedure linkage table. */
7902 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
, got2
,
7903 info
->shared
? addend
: 0);
7906 || htab
->plt
== NULL
)
7908 /* We didn't make a PLT entry for this symbol. This
7909 happens when statically linking PIC code, or when
7910 using -Bsymbolic. */
7914 unresolved_reloc
= FALSE
;
7915 if (htab
->plt_type
== PLT_NEW
)
7916 relocation
= (htab
->glink
->output_section
->vma
7917 + htab
->glink
->output_offset
7918 + ent
->glink_offset
);
7920 relocation
= (htab
->plt
->output_section
->vma
7921 + htab
->plt
->output_offset
7926 /* Relocate against _SDA_BASE_. */
7927 case R_PPC_SDAREL16
:
7930 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
7933 || sec
->output_section
== NULL
7934 || !is_static_defined (sda
))
7936 unresolved_reloc
= TRUE
;
7939 addend
-= SYM_VAL (sda
);
7941 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7942 if (! ((CONST_STRNEQ (name
, ".sdata")
7943 && (name
[6] == 0 || name
[6] == '.'))
7944 || (CONST_STRNEQ (name
, ".sbss")
7945 && (name
[5] == 0 || name
[5] == '.'))))
7947 info
->callbacks
->einfo
7948 (_("%P: %B: the target (%s) of a %s relocation is "
7949 "in the wrong output section (%s)\n"),
7958 /* Relocate against _SDA2_BASE_. */
7959 case R_PPC_EMB_SDA2REL
:
7962 struct elf_link_hash_entry
*sda
= htab
->sdata
[1].sym
;
7965 || sec
->output_section
== NULL
7966 || !is_static_defined (sda
))
7968 unresolved_reloc
= TRUE
;
7971 addend
-= SYM_VAL (sda
);
7973 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7974 if (! (CONST_STRNEQ (name
, ".sdata2")
7975 || CONST_STRNEQ (name
, ".sbss2")))
7977 info
->callbacks
->einfo
7978 (_("%P: %B: the target (%s) of a %s relocation is "
7979 "in the wrong output section (%s)\n"),
7988 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
7989 case R_PPC_EMB_SDA21
:
7990 case R_PPC_EMB_RELSDA
:
7994 struct elf_link_hash_entry
*sda
= NULL
;
7996 if (sec
== NULL
|| sec
->output_section
== NULL
)
7998 unresolved_reloc
= TRUE
;
8002 name
= bfd_get_section_name (abfd
, sec
->output_section
);
8003 if (((CONST_STRNEQ (name
, ".sdata")
8004 && (name
[6] == 0 || name
[6] == '.'))
8005 || (CONST_STRNEQ (name
, ".sbss")
8006 && (name
[5] == 0 || name
[5] == '.'))))
8009 sda
= htab
->sdata
[0].sym
;
8011 else if (CONST_STRNEQ (name
, ".sdata2")
8012 || CONST_STRNEQ (name
, ".sbss2"))
8015 sda
= htab
->sdata
[1].sym
;
8017 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
8018 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
8024 info
->callbacks
->einfo
8025 (_("%P: %B: the target (%s) of a %s relocation is "
8026 "in the wrong output section (%s)\n"),
8032 bfd_set_error (bfd_error_bad_value
);
8039 if (!is_static_defined (sda
))
8041 unresolved_reloc
= TRUE
;
8044 addend
-= SYM_VAL (sda
);
8047 if (r_type
== R_PPC_EMB_SDA21
)
8049 bfd_vma insn
; /* Fill in register field. */
8051 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
8052 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
8053 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
8058 /* Relocate against the beginning of the section. */
8060 case R_PPC_SECTOFF_LO
:
8061 case R_PPC_SECTOFF_HI
:
8062 case R_PPC_SECTOFF_HA
:
8063 if (sec
== NULL
|| sec
->output_section
== NULL
)
8065 unresolved_reloc
= TRUE
;
8068 addend
-= sec
->output_section
->vma
;
8071 /* Negative relocations. */
8072 case R_PPC_EMB_NADDR32
:
8073 case R_PPC_EMB_NADDR16
:
8074 case R_PPC_EMB_NADDR16_LO
:
8075 case R_PPC_EMB_NADDR16_HI
:
8076 case R_PPC_EMB_NADDR16_HA
:
8077 addend
-= 2 * relocation
;
8081 case R_PPC_GLOB_DAT
:
8082 case R_PPC_JMP_SLOT
:
8083 case R_PPC_RELATIVE
:
8084 case R_PPC_IRELATIVE
:
8086 case R_PPC_PLTREL32
:
8087 case R_PPC_PLT16_LO
:
8088 case R_PPC_PLT16_HI
:
8089 case R_PPC_PLT16_HA
:
8091 case R_PPC_EMB_RELSEC16
:
8092 case R_PPC_EMB_RELST_LO
:
8093 case R_PPC_EMB_RELST_HI
:
8094 case R_PPC_EMB_RELST_HA
:
8095 case R_PPC_EMB_BIT_FLD
:
8096 info
->callbacks
->einfo
8097 (_("%P: %B: relocation %s is not yet supported for symbol %s\n"),
8102 bfd_set_error (bfd_error_invalid_operation
);
8107 /* Do any further special processing. */
8113 case R_PPC_ADDR16_HA
:
8114 case R_PPC_REL16_HA
:
8115 case R_PPC_SECTOFF_HA
:
8116 case R_PPC_TPREL16_HA
:
8117 case R_PPC_DTPREL16_HA
:
8118 case R_PPC_EMB_NADDR16_HA
:
8119 case R_PPC_EMB_RELST_HA
:
8120 /* It's just possible that this symbol is a weak symbol
8121 that's not actually defined anywhere. In that case,
8122 'sec' would be NULL, and we should leave the symbol
8123 alone (it will be set to zero elsewhere in the link). */
8128 case R_PPC_PLT16_HA
:
8129 case R_PPC_GOT16_HA
:
8130 case R_PPC_GOT_TLSGD16_HA
:
8131 case R_PPC_GOT_TLSLD16_HA
:
8132 case R_PPC_GOT_TPREL16_HA
:
8133 case R_PPC_GOT_DTPREL16_HA
:
8134 /* Add 0x10000 if sign bit in 0:15 is set.
8135 Bits 0:15 are not used. */
8141 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
8142 "offset = %ld, addend = %ld\n",
8147 (long) rel
->r_offset
,
8151 if (unresolved_reloc
8152 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8154 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
8155 rel
->r_offset
) != (bfd_vma
) -1)
8157 info
->callbacks
->einfo
8158 (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
8159 input_bfd
, input_section
, rel
->r_offset
,
8165 r
= _bfd_final_link_relocate (howto
,
8173 if (r
!= bfd_reloc_ok
)
8175 if (r
== bfd_reloc_overflow
)
8180 && h
->root
.type
== bfd_link_hash_undefweak
8181 && howto
->pc_relative
)
8183 /* Assume this is a call protected by other code that
8184 detect the symbol is undefined. If this is the case,
8185 we can safely ignore the overflow. If not, the
8186 program is hosed anyway, and a little warning isn't
8192 if (! (*info
->callbacks
->reloc_overflow
) (info
,
8193 (h
? &h
->root
: NULL
),
8204 info
->callbacks
->einfo
8205 (_("%P: %H: %s reloc against `%s': error %d\n"),
8206 input_bfd
, input_section
, rel
->r_offset
,
8207 howto
->name
, sym_name
, (int) r
);
8214 fprintf (stderr
, "\n");
8220 /* Finish up dynamic symbol handling. We set the contents of various
8221 dynamic sections here. */
8224 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8225 struct bfd_link_info
*info
,
8226 struct elf_link_hash_entry
*h
,
8227 Elf_Internal_Sym
*sym
)
8229 struct ppc_elf_link_hash_table
*htab
;
8230 struct plt_entry
*ent
;
8231 bfd_boolean doneone
;
8234 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
8235 h
->root
.root
.string
);
8238 htab
= ppc_elf_hash_table (info
);
8239 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
8242 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8243 if (ent
->plt
.offset
!= (bfd_vma
) -1)
8247 Elf_Internal_Rela rela
;
8249 bfd_vma reloc_index
;
8251 if (htab
->plt_type
== PLT_NEW
8252 || !htab
->elf
.dynamic_sections_created
8253 || h
->dynindx
== -1)
8254 reloc_index
= ent
->plt
.offset
/ 4;
8257 reloc_index
= ((ent
->plt
.offset
- htab
->plt_initial_entry_size
)
8258 / htab
->plt_slot_size
);
8259 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
8260 && htab
->plt_type
== PLT_OLD
)
8261 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
8264 /* This symbol has an entry in the procedure linkage table.
8266 if (htab
->plt_type
== PLT_VXWORKS
8267 && htab
->elf
.dynamic_sections_created
8268 && h
->dynindx
!= -1)
8271 const bfd_vma
*plt_entry
;
8273 /* The first three entries in .got.plt are reserved. */
8274 got_offset
= (reloc_index
+ 3) * 4;
8276 /* Use the right PLT. */
8277 plt_entry
= info
->shared
? ppc_elf_vxworks_pic_plt_entry
8278 : ppc_elf_vxworks_plt_entry
;
8280 /* Fill in the .plt on VxWorks. */
8283 bfd_put_32 (output_bfd
,
8284 plt_entry
[0] | PPC_HA (got_offset
),
8285 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
8286 bfd_put_32 (output_bfd
,
8287 plt_entry
[1] | PPC_LO (got_offset
),
8288 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
8292 bfd_vma got_loc
= got_offset
+ SYM_VAL (htab
->elf
.hgot
);
8294 bfd_put_32 (output_bfd
,
8295 plt_entry
[0] | PPC_HA (got_loc
),
8296 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
8297 bfd_put_32 (output_bfd
,
8298 plt_entry
[1] | PPC_LO (got_loc
),
8299 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
8302 bfd_put_32 (output_bfd
, plt_entry
[2],
8303 htab
->plt
->contents
+ ent
->plt
.offset
+ 8);
8304 bfd_put_32 (output_bfd
, plt_entry
[3],
8305 htab
->plt
->contents
+ ent
->plt
.offset
+ 12);
8307 /* This instruction is an immediate load. The value loaded is
8308 the byte offset of the R_PPC_JMP_SLOT relocation from the
8309 start of the .rela.plt section. The value is stored in the
8310 low-order 16 bits of the load instruction. */
8311 /* NOTE: It appears that this is now an index rather than a
8312 prescaled offset. */
8313 bfd_put_32 (output_bfd
,
8314 plt_entry
[4] | reloc_index
,
8315 htab
->plt
->contents
+ ent
->plt
.offset
+ 16);
8316 /* This instruction is a PC-relative branch whose target is
8317 the start of the PLT section. The address of this branch
8318 instruction is 20 bytes beyond the start of this PLT entry.
8319 The address is encoded in bits 6-29, inclusive. The value
8320 stored is right-shifted by two bits, permitting a 26-bit
8322 bfd_put_32 (output_bfd
,
8324 | (-(ent
->plt
.offset
+ 20) & 0x03fffffc)),
8325 htab
->plt
->contents
+ ent
->plt
.offset
+ 20);
8326 bfd_put_32 (output_bfd
, plt_entry
[6],
8327 htab
->plt
->contents
+ ent
->plt
.offset
+ 24);
8328 bfd_put_32 (output_bfd
, plt_entry
[7],
8329 htab
->plt
->contents
+ ent
->plt
.offset
+ 28);
8331 /* Fill in the GOT entry corresponding to this PLT slot with
8332 the address immediately after the the "bctr" instruction
8333 in this PLT entry. */
8334 bfd_put_32 (output_bfd
, (htab
->plt
->output_section
->vma
8335 + htab
->plt
->output_offset
8336 + ent
->plt
.offset
+ 16),
8337 htab
->sgotplt
->contents
+ got_offset
);
8341 /* Fill in a couple of entries in .rela.plt.unloaded. */
8342 loc
= htab
->srelplt2
->contents
8343 + ((VXWORKS_PLTRESOLVE_RELOCS
+ reloc_index
8344 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
)
8345 * sizeof (Elf32_External_Rela
));
8347 /* Provide the @ha relocation for the first instruction. */
8348 rela
.r_offset
= (htab
->plt
->output_section
->vma
8349 + htab
->plt
->output_offset
8350 + ent
->plt
.offset
+ 2);
8351 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8353 rela
.r_addend
= got_offset
;
8354 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8355 loc
+= sizeof (Elf32_External_Rela
);
8357 /* Provide the @l relocation for the second instruction. */
8358 rela
.r_offset
= (htab
->plt
->output_section
->vma
8359 + htab
->plt
->output_offset
8360 + ent
->plt
.offset
+ 6);
8361 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8363 rela
.r_addend
= got_offset
;
8364 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8365 loc
+= sizeof (Elf32_External_Rela
);
8367 /* Provide a relocation for the GOT entry corresponding to this
8368 PLT slot. Point it at the middle of the .plt entry. */
8369 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8370 + htab
->sgotplt
->output_offset
8372 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
8374 rela
.r_addend
= ent
->plt
.offset
+ 16;
8375 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8378 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
8379 In particular, the offset for the relocation is not the
8380 address of the PLT entry for this function, as specified
8381 by the ABI. Instead, the offset is set to the address of
8382 the GOT slot for this function. See EABI 4.4.4.1. */
8383 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8384 + htab
->sgotplt
->output_offset
8390 asection
*splt
= htab
->plt
;
8391 if (!htab
->elf
.dynamic_sections_created
8392 || h
->dynindx
== -1)
8395 rela
.r_offset
= (splt
->output_section
->vma
8396 + splt
->output_offset
8398 if (htab
->plt_type
== PLT_OLD
8399 || !htab
->elf
.dynamic_sections_created
8400 || h
->dynindx
== -1)
8402 /* We don't need to fill in the .plt. The ppc dynamic
8403 linker will fill it in. */
8407 bfd_vma val
= (htab
->glink_pltresolve
+ ent
->plt
.offset
8408 + htab
->glink
->output_section
->vma
8409 + htab
->glink
->output_offset
);
8410 bfd_put_32 (output_bfd
, val
,
8411 splt
->contents
+ ent
->plt
.offset
);
8415 /* Fill in the entry in the .rela.plt section. */
8417 if (!htab
->elf
.dynamic_sections_created
8418 || h
->dynindx
== -1)
8420 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
8422 && (h
->root
.type
== bfd_link_hash_defined
8423 || h
->root
.type
== bfd_link_hash_defweak
));
8424 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
8425 rela
.r_addend
= SYM_VAL (h
);
8428 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
8430 if (!htab
->elf
.dynamic_sections_created
8431 || h
->dynindx
== -1)
8432 loc
= (htab
->reliplt
->contents
8433 + (htab
->reliplt
->reloc_count
++
8434 * sizeof (Elf32_External_Rela
)));
8436 loc
= (htab
->relplt
->contents
8437 + reloc_index
* sizeof (Elf32_External_Rela
));
8438 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8440 if (!h
->def_regular
)
8442 /* Mark the symbol as undefined, rather than as
8443 defined in the .plt section. Leave the value if
8444 there were any relocations where pointer equality
8445 matters (this is a clue for the dynamic linker, to
8446 make function pointer comparisons work between an
8447 application and shared library), otherwise set it
8449 sym
->st_shndx
= SHN_UNDEF
;
8450 if (!h
->pointer_equality_needed
)
8452 else if (!h
->ref_regular_nonweak
)
8454 /* This breaks function pointer comparisons, but
8455 that is better than breaking tests for a NULL
8456 function pointer. */
8460 else if (h
->type
== STT_GNU_IFUNC
8463 /* Set the value of ifunc symbols in a non-pie
8464 executable to the glink entry. This is to avoid
8465 text relocations. We can't do this for ifunc in
8466 allocate_dynrelocs, as we do for normal dynamic
8467 function symbols with plt entries, because we need
8468 to keep the original value around for the ifunc
8470 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
8471 (output_bfd
, htab
->glink
->output_section
));
8472 sym
->st_value
= (ent
->glink_offset
8473 + htab
->glink
->output_offset
8474 + htab
->glink
->output_section
->vma
);
8479 if (htab
->plt_type
== PLT_NEW
8480 || !htab
->elf
.dynamic_sections_created
8481 || h
->dynindx
== -1)
8484 asection
*splt
= htab
->plt
;
8485 if (!htab
->elf
.dynamic_sections_created
8486 || h
->dynindx
== -1)
8489 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
8491 if (h
== htab
->tls_get_addr
&& !htab
->no_tls_get_addr_opt
)
8493 bfd_put_32 (output_bfd
, LWZ_11_3
, p
);
8495 bfd_put_32 (output_bfd
, LWZ_12_3
+ 4, p
);
8497 bfd_put_32 (output_bfd
, MR_0_3
, p
);
8499 bfd_put_32 (output_bfd
, CMPWI_11_0
, p
);
8501 bfd_put_32 (output_bfd
, ADD_3_12_2
, p
);
8503 bfd_put_32 (output_bfd
, BEQLR
, p
);
8505 bfd_put_32 (output_bfd
, MR_3_0
, p
);
8507 bfd_put_32 (output_bfd
, NOP
, p
);
8511 write_glink_stub (ent
, splt
, p
, info
);
8514 /* We only need one non-PIC glink stub. */
8524 Elf_Internal_Rela rela
;
8527 /* This symbols needs a copy reloc. Set it up. */
8530 fprintf (stderr
, ", copy");
8533 BFD_ASSERT (h
->dynindx
!= -1);
8535 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
8539 BFD_ASSERT (s
!= NULL
);
8541 rela
.r_offset
= SYM_VAL (h
);
8542 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
8544 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
8545 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8549 fprintf (stderr
, "\n");
8552 /* Mark some specially defined symbols as absolute. */
8553 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
8554 || (!htab
->is_vxworks
8555 && (h
== htab
->elf
.hgot
8556 || strcmp (h
->root
.root
.string
,
8557 "_PROCEDURE_LINKAGE_TABLE_") == 0)))
8558 sym
->st_shndx
= SHN_ABS
;
8563 static enum elf_reloc_type_class
8564 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
8566 switch (ELF32_R_TYPE (rela
->r_info
))
8568 case R_PPC_RELATIVE
:
8569 return reloc_class_relative
;
8572 case R_PPC_JMP_SLOT
:
8573 return reloc_class_plt
;
8575 return reloc_class_copy
;
8577 return reloc_class_normal
;
8581 /* Finish up the dynamic sections. */
8584 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
8585 struct bfd_link_info
*info
)
8589 struct ppc_elf_link_hash_table
*htab
;
8592 bfd_boolean ret
= TRUE
;
8595 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
8598 htab
= ppc_elf_hash_table (info
);
8599 dynobj
= elf_hash_table (info
)->dynobj
;
8600 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8601 if (htab
->is_vxworks
)
8602 splt
= bfd_get_section_by_name (dynobj
, ".plt");
8607 if (htab
->elf
.hgot
!= NULL
)
8608 got
= SYM_VAL (htab
->elf
.hgot
);
8610 if (htab
->elf
.dynamic_sections_created
)
8612 Elf32_External_Dyn
*dyncon
, *dynconend
;
8614 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
8616 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
8617 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8618 for (; dyncon
< dynconend
; dyncon
++)
8620 Elf_Internal_Dyn dyn
;
8623 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8628 if (htab
->is_vxworks
)
8632 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8636 dyn
.d_un
.d_val
= htab
->relplt
->size
;
8641 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8645 dyn
.d_un
.d_ptr
= got
;
8649 if (htab
->is_vxworks
)
8652 dyn
.d_un
.d_ptr
-= htab
->relplt
->size
;
8658 if (htab
->is_vxworks
8659 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
8664 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8668 if (htab
->got
!= NULL
)
8670 if (htab
->elf
.hgot
->root
.u
.def
.section
== htab
->got
8671 || htab
->elf
.hgot
->root
.u
.def
.section
== htab
->sgotplt
)
8673 unsigned char *p
= htab
->elf
.hgot
->root
.u
.def
.section
->contents
;
8675 p
+= htab
->elf
.hgot
->root
.u
.def
.value
;
8676 if (htab
->plt_type
== PLT_OLD
)
8678 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
8679 so that a function can easily find the address of
8680 _GLOBAL_OFFSET_TABLE_. */
8681 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
- 4
8682 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8683 bfd_put_32 (output_bfd
, 0x4e800021, p
- 4);
8688 bfd_vma val
= sdyn
->output_section
->vma
+ sdyn
->output_offset
;
8689 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
8690 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8691 bfd_put_32 (output_bfd
, val
, p
);
8696 info
->callbacks
->einfo (_("%P: %s not defined in linker created %s\n"),
8697 htab
->elf
.hgot
->root
.root
.string
,
8698 (htab
->sgotplt
!= NULL
8699 ? htab
->sgotplt
->name
: htab
->got
->name
));
8700 bfd_set_error (bfd_error_bad_value
);
8704 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
8707 /* Fill in the first entry in the VxWorks procedure linkage table. */
8708 if (splt
&& splt
->size
> 0)
8710 /* Use the right PLT. */
8711 const bfd_vma
*plt_entry
= (info
->shared
8712 ? ppc_elf_vxworks_pic_plt0_entry
8713 : ppc_elf_vxworks_plt0_entry
);
8717 bfd_vma got_value
= SYM_VAL (htab
->elf
.hgot
);
8719 bfd_put_32 (output_bfd
, plt_entry
[0] | PPC_HA (got_value
),
8720 splt
->contents
+ 0);
8721 bfd_put_32 (output_bfd
, plt_entry
[1] | PPC_LO (got_value
),
8722 splt
->contents
+ 4);
8726 bfd_put_32 (output_bfd
, plt_entry
[0], splt
->contents
+ 0);
8727 bfd_put_32 (output_bfd
, plt_entry
[1], splt
->contents
+ 4);
8729 bfd_put_32 (output_bfd
, plt_entry
[2], splt
->contents
+ 8);
8730 bfd_put_32 (output_bfd
, plt_entry
[3], splt
->contents
+ 12);
8731 bfd_put_32 (output_bfd
, plt_entry
[4], splt
->contents
+ 16);
8732 bfd_put_32 (output_bfd
, plt_entry
[5], splt
->contents
+ 20);
8733 bfd_put_32 (output_bfd
, plt_entry
[6], splt
->contents
+ 24);
8734 bfd_put_32 (output_bfd
, plt_entry
[7], splt
->contents
+ 28);
8738 Elf_Internal_Rela rela
;
8741 loc
= htab
->srelplt2
->contents
;
8743 /* Output the @ha relocation for the first instruction. */
8744 rela
.r_offset
= (htab
->plt
->output_section
->vma
8745 + htab
->plt
->output_offset
8747 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8749 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8750 loc
+= sizeof (Elf32_External_Rela
);
8752 /* Output the @l relocation for the second instruction. */
8753 rela
.r_offset
= (htab
->plt
->output_section
->vma
8754 + htab
->plt
->output_offset
8756 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8758 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8759 loc
+= sizeof (Elf32_External_Rela
);
8761 /* Fix up the remaining relocations. They may have the wrong
8762 symbol index for _G_O_T_ or _P_L_T_ depending on the order
8763 in which symbols were output. */
8764 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
8766 Elf_Internal_Rela rel
;
8768 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8769 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8770 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8771 loc
+= sizeof (Elf32_External_Rela
);
8773 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8774 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8775 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8776 loc
+= sizeof (Elf32_External_Rela
);
8778 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8779 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_PPC_ADDR32
);
8780 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8781 loc
+= sizeof (Elf32_External_Rela
);
8786 if (htab
->glink
!= NULL
8787 && htab
->glink
->contents
!= NULL
8788 && htab
->elf
.dynamic_sections_created
)
8791 unsigned char *endp
;
8796 * PIC glink code is the following:
8798 * # ith PLT code stub.
8799 * addis 11,30,(plt+(i-1)*4-got)@ha
8800 * lwz 11,(plt+(i-1)*4-got)@l(11)
8804 * # A table of branches, one for each plt entry.
8805 * # The idea is that the plt call stub loads ctr and r11 with these
8806 * # addresses, so (r11 - res_0) gives the plt index * 4.
8807 * res_0: b PLTresolve
8808 * res_1: b PLTresolve
8810 * # Some number of entries towards the end can be nops
8816 * addis 11,11,(1f-res_0)@ha
8819 * 1: addi 11,11,(1b-res_0)@l
8822 * sub 11,11,12 # r11 = index * 4
8823 * addis 12,12,(got+4-1b)@ha
8824 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
8825 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
8828 * add 11,0,11 # r11 = index * 12 = reloc offset.
8831 static const unsigned int pic_plt_resolve
[] =
8852 * Non-PIC glink code is a little simpler.
8854 * # ith PLT code stub.
8855 * lis 11,(plt+(i-1)*4)@ha
8856 * lwz 11,(plt+(i-1)*4)@l(11)
8860 * The branch table is the same, then comes
8864 * addis 11,11,(-res_0)@ha
8865 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
8866 * addi 11,11,(-res_0)@l # r11 = index * 4
8869 * lwz 12,(got+8)@l(12) # got[2] contains the map address
8870 * add 11,0,11 # r11 = index * 12 = reloc offset.
8873 static const unsigned int plt_resolve
[] =
8893 if (ARRAY_SIZE (pic_plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8895 if (ARRAY_SIZE (plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8898 /* Build the branch table, one for each plt entry (less one),
8899 and perhaps some padding. */
8900 p
= htab
->glink
->contents
;
8901 p
+= htab
->glink_pltresolve
;
8902 endp
= htab
->glink
->contents
;
8903 endp
+= htab
->glink
->size
- GLINK_PLTRESOLVE
;
8904 while (p
< endp
- 8 * 4)
8906 bfd_put_32 (output_bfd
, B
+ endp
- p
, p
);
8911 bfd_put_32 (output_bfd
, NOP
, p
);
8915 res0
= (htab
->glink_pltresolve
8916 + htab
->glink
->output_section
->vma
8917 + htab
->glink
->output_offset
);
8919 /* Last comes the PLTresolve stub. */
8924 for (i
= 0; i
< ARRAY_SIZE (pic_plt_resolve
); i
++)
8926 bfd_put_32 (output_bfd
, pic_plt_resolve
[i
], p
);
8929 p
-= 4 * ARRAY_SIZE (pic_plt_resolve
);
8931 bcl
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 3*4
8932 + htab
->glink
->output_section
->vma
8933 + htab
->glink
->output_offset
);
8935 bfd_put_32 (output_bfd
,
8936 ADDIS_11_11
+ PPC_HA (bcl
- res0
), p
+ 0*4);
8937 bfd_put_32 (output_bfd
,
8938 ADDI_11_11
+ PPC_LO (bcl
- res0
), p
+ 3*4);
8939 bfd_put_32 (output_bfd
,
8940 ADDIS_12_12
+ PPC_HA (got
+ 4 - bcl
), p
+ 7*4);
8941 if (PPC_HA (got
+ 4 - bcl
) == PPC_HA (got
+ 8 - bcl
))
8943 bfd_put_32 (output_bfd
,
8944 LWZ_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8945 bfd_put_32 (output_bfd
,
8946 LWZ_12_12
+ PPC_LO (got
+ 8 - bcl
), p
+ 9*4);
8950 bfd_put_32 (output_bfd
,
8951 LWZU_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8952 bfd_put_32 (output_bfd
,
8953 LWZ_12_12
+ 4, p
+ 9*4);
8958 for (i
= 0; i
< ARRAY_SIZE (plt_resolve
); i
++)
8960 bfd_put_32 (output_bfd
, plt_resolve
[i
], p
);
8963 p
-= 4 * ARRAY_SIZE (plt_resolve
);
8965 bfd_put_32 (output_bfd
,
8966 LIS_12
+ PPC_HA (got
+ 4), p
+ 0*4);
8967 bfd_put_32 (output_bfd
,
8968 ADDIS_11_11
+ PPC_HA (-res0
), p
+ 1*4);
8969 bfd_put_32 (output_bfd
,
8970 ADDI_11_11
+ PPC_LO (-res0
), p
+ 3*4);
8971 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
8973 bfd_put_32 (output_bfd
,
8974 LWZ_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8975 bfd_put_32 (output_bfd
,
8976 LWZ_12_12
+ PPC_LO (got
+ 8), p
+ 6*4);
8980 bfd_put_32 (output_bfd
,
8981 LWZU_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8982 bfd_put_32 (output_bfd
,
8983 LWZ_12_12
+ 4, p
+ 6*4);
8988 if (htab
->glink_eh_frame
!= NULL
8989 && htab
->glink_eh_frame
->contents
!= NULL
)
8991 unsigned char *p
= htab
->glink_eh_frame
->contents
;
8994 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
8995 /* CIE length (rewrite in case little-endian). */
8996 bfd_put_32 (htab
->elf
.dynobj
, sizeof (glink_eh_frame_cie
) - 4, p
);
8997 p
+= sizeof (glink_eh_frame_cie
);
8999 val
= htab
->glink_eh_frame
->size
- 4 - sizeof (glink_eh_frame_cie
);
9000 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
9003 val
= p
- htab
->glink_eh_frame
->contents
;
9004 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
9006 /* Offset to .glink. */
9007 val
= (htab
->glink
->output_section
->vma
9008 + htab
->glink
->output_offset
);
9009 val
-= (htab
->glink_eh_frame
->output_section
->vma
9010 + htab
->glink_eh_frame
->output_offset
);
9011 val
-= p
- htab
->glink_eh_frame
->contents
;
9012 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
9015 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
, p
);
9021 && htab
->elf
.dynamic_sections_created
)
9023 bfd_vma adv
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 8) >> 2;
9025 *p
++ = DW_CFA_advance_loc
+ adv
;
9028 *p
++ = DW_CFA_advance_loc1
;
9031 else if (adv
< 65536)
9033 *p
++ = DW_CFA_advance_loc2
;
9034 bfd_put_16 (htab
->elf
.dynobj
, adv
, p
);
9039 *p
++ = DW_CFA_advance_loc4
;
9040 bfd_put_32 (htab
->elf
.dynobj
, adv
, p
);
9043 *p
++ = DW_CFA_register
;
9046 *p
++ = DW_CFA_advance_loc
+ 4;
9047 *p
++ = DW_CFA_restore_extended
;
9050 BFD_ASSERT ((bfd_vma
) ((p
+ 3 - htab
->glink_eh_frame
->contents
) & -4)
9051 == htab
->glink_eh_frame
->size
);
9053 if (htab
->glink_eh_frame
->sec_info_type
== ELF_INFO_TYPE_EH_FRAME
9054 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
9055 htab
->glink_eh_frame
,
9056 htab
->glink_eh_frame
->contents
))
9063 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
9064 #define TARGET_LITTLE_NAME "elf32-powerpcle"
9065 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
9066 #define TARGET_BIG_NAME "elf32-powerpc"
9067 #define ELF_ARCH bfd_arch_powerpc
9068 #define ELF_TARGET_ID PPC32_ELF_DATA
9069 #define ELF_MACHINE_CODE EM_PPC
9070 #ifdef __QNXTARGET__
9071 #define ELF_MAXPAGESIZE 0x1000
9073 #define ELF_MAXPAGESIZE 0x10000
9075 #define ELF_MINPAGESIZE 0x1000
9076 #define ELF_COMMONPAGESIZE 0x1000
9077 #define elf_info_to_howto ppc_elf_info_to_howto
9079 #ifdef EM_CYGNUS_POWERPC
9080 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
9084 #define ELF_MACHINE_ALT2 EM_PPC_OLD
9087 #define elf_backend_plt_not_loaded 1
9088 #define elf_backend_can_gc_sections 1
9089 #define elf_backend_can_refcount 1
9090 #define elf_backend_rela_normal 1
9092 #define bfd_elf32_mkobject ppc_elf_mkobject
9093 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
9094 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
9095 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
9096 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
9097 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
9098 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
9099 #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
9101 #define elf_backend_object_p ppc_elf_object_p
9102 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
9103 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
9104 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
9105 #define elf_backend_relocate_section ppc_elf_relocate_section
9106 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
9107 #define elf_backend_check_relocs ppc_elf_check_relocs
9108 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
9109 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
9110 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
9111 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
9112 #define elf_backend_hash_symbol ppc_elf_hash_symbol
9113 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
9114 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
9115 #define elf_backend_fake_sections ppc_elf_fake_sections
9116 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
9117 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
9118 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
9119 #define elf_backend_write_core_note ppc_elf_write_core_note
9120 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
9121 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
9122 #define elf_backend_final_write_processing ppc_elf_final_write_processing
9123 #define elf_backend_write_section ppc_elf_write_section
9124 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
9125 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
9126 #define elf_backend_action_discarded ppc_elf_action_discarded
9127 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
9128 #define elf_backend_post_process_headers _bfd_elf_set_osabi
9130 #include "elf32-target.h"
9132 /* VxWorks Target */
9134 #undef TARGET_LITTLE_SYM
9135 #undef TARGET_LITTLE_NAME
9137 #undef TARGET_BIG_SYM
9138 #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
9139 #undef TARGET_BIG_NAME
9140 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
9142 /* VxWorks uses the elf default section flags for .plt. */
9143 static const struct bfd_elf_special_section
*
9144 ppc_elf_vxworks_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
9146 if (sec
->name
== NULL
)
9149 if (strcmp (sec
->name
, ".plt") == 0)
9150 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
9152 return ppc_elf_get_sec_type_attr (abfd
, sec
);
9155 /* Like ppc_elf_link_hash_table_create, but overrides
9156 appropriately for VxWorks. */
9157 static struct bfd_link_hash_table
*
9158 ppc_elf_vxworks_link_hash_table_create (bfd
*abfd
)
9160 struct bfd_link_hash_table
*ret
;
9162 ret
= ppc_elf_link_hash_table_create (abfd
);
9165 struct ppc_elf_link_hash_table
*htab
9166 = (struct ppc_elf_link_hash_table
*)ret
;
9167 htab
->is_vxworks
= 1;
9168 htab
->plt_type
= PLT_VXWORKS
;
9169 htab
->plt_entry_size
= VXWORKS_PLT_ENTRY_SIZE
;
9170 htab
->plt_slot_size
= VXWORKS_PLT_ENTRY_SIZE
;
9171 htab
->plt_initial_entry_size
= VXWORKS_PLT_INITIAL_ENTRY_SIZE
;
9176 /* Tweak magic VxWorks symbols as they are loaded. */
9178 ppc_elf_vxworks_add_symbol_hook (bfd
*abfd
,
9179 struct bfd_link_info
*info
,
9180 Elf_Internal_Sym
*sym
,
9181 const char **namep ATTRIBUTE_UNUSED
,
9182 flagword
*flagsp ATTRIBUTE_UNUSED
,
9186 if (!elf_vxworks_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
,
9190 return ppc_elf_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
, valp
);
9194 ppc_elf_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
9196 ppc_elf_final_write_processing(abfd
, linker
);
9197 elf_vxworks_final_write_processing(abfd
, linker
);
9200 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
9202 #undef elf_backend_want_plt_sym
9203 #define elf_backend_want_plt_sym 1
9204 #undef elf_backend_want_got_plt
9205 #define elf_backend_want_got_plt 1
9206 #undef elf_backend_got_symbol_offset
9207 #define elf_backend_got_symbol_offset 0
9208 #undef elf_backend_plt_not_loaded
9209 #define elf_backend_plt_not_loaded 0
9210 #undef elf_backend_plt_readonly
9211 #define elf_backend_plt_readonly 1
9212 #undef elf_backend_got_header_size
9213 #define elf_backend_got_header_size 12
9215 #undef bfd_elf32_get_synthetic_symtab
9217 #undef bfd_elf32_bfd_link_hash_table_create
9218 #define bfd_elf32_bfd_link_hash_table_create \
9219 ppc_elf_vxworks_link_hash_table_create
9220 #undef elf_backend_add_symbol_hook
9221 #define elf_backend_add_symbol_hook \
9222 ppc_elf_vxworks_add_symbol_hook
9223 #undef elf_backend_link_output_symbol_hook
9224 #define elf_backend_link_output_symbol_hook \
9225 elf_vxworks_link_output_symbol_hook
9226 #undef elf_backend_final_write_processing
9227 #define elf_backend_final_write_processing \
9228 ppc_elf_vxworks_final_write_processing
9229 #undef elf_backend_get_sec_type_attr
9230 #define elf_backend_get_sec_type_attr \
9231 ppc_elf_vxworks_get_sec_type_attr
9232 #undef elf_backend_emit_relocs
9233 #define elf_backend_emit_relocs \
9234 elf_vxworks_emit_relocs
9237 #define elf32_bed ppc_elf_vxworks_bed
9238 #undef elf_backend_post_process_headers
9240 #include "elf32-target.h"