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 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 /* This file is based on a preliminary PowerPC ELF ABI. The
25 information may not match the final PowerPC ELF ABI. It includes
26 suggestions from the in-progress Embedded PowerPC ABI, and that
27 information may also not match. */
36 #include "elf32-ppc.h"
37 #include "elf-vxworks.h"
39 /* RELA relocations are used here. */
41 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
42 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 static bfd_reloc_status_type ppc_elf_unhandled_reloc
44 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 /* Branch prediction bit for branch taken relocs. */
47 #define BRANCH_PREDICT_BIT 0x200000
48 /* Mask to set RA in memory instructions. */
49 #define RA_REGISTER_MASK 0x001f0000
50 /* Value to shift register by to insert RA. */
51 #define RA_REGISTER_SHIFT 16
53 /* The name of the dynamic interpreter. This is put in the .interp
55 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
57 /* For old-style PLT. */
58 /* The number of single-slot PLT entries (the rest use two slots). */
59 #define PLT_NUM_SINGLE_ENTRIES 8192
61 /* For new-style .glink and .plt. */
62 #define GLINK_PLTRESOLVE 16*4
63 #define GLINK_ENTRY_SIZE 4*4
64 #define TLS_GET_ADDR_GLINK_SIZE 12*4
66 /* VxWorks uses its own plt layout, filled in by the static linker. */
68 /* The standard VxWorks PLT entry. */
69 #define VXWORKS_PLT_ENTRY_SIZE 32
70 static const bfd_vma ppc_elf_vxworks_plt_entry
71 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
73 0x3d800000, /* lis r12,0 */
74 0x818c0000, /* lwz r12,0(r12) */
75 0x7d8903a6, /* mtctr r12 */
76 0x4e800420, /* bctr */
77 0x39600000, /* li r11,0 */
78 0x48000000, /* b 14 <.PLT0resolve+0x4> */
82 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
83 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
85 0x3d9e0000, /* addis r12,r30,0 */
86 0x818c0000, /* lwz r12,0(r12) */
87 0x7d8903a6, /* mtctr r12 */
88 0x4e800420, /* bctr */
89 0x39600000, /* li r11,0 */
90 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
95 /* The initial VxWorks PLT entry. */
96 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
97 static const bfd_vma ppc_elf_vxworks_plt0_entry
98 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
100 0x3d800000, /* lis r12,0 */
101 0x398c0000, /* addi r12,r12,0 */
102 0x800c0008, /* lwz r0,8(r12) */
103 0x7c0903a6, /* mtctr r0 */
104 0x818c0004, /* lwz r12,4(r12) */
105 0x4e800420, /* bctr */
106 0x60000000, /* nop */
107 0x60000000, /* nop */
109 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
110 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
112 0x819e0008, /* lwz r12,8(r30) */
113 0x7d8903a6, /* mtctr r12 */
114 0x819e0004, /* lwz r12,4(r30) */
115 0x4e800420, /* bctr */
116 0x60000000, /* nop */
117 0x60000000, /* nop */
118 0x60000000, /* nop */
119 0x60000000, /* nop */
122 /* For executables, we have some additional relocations in
123 .rela.plt.unloaded, for the kernel loader. */
125 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
126 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
127 /* The number of relocations in the PLTResolve slot. */
128 #define VXWORKS_PLTRESOLVE_RELOCS 2
129 /* The number of relocations in the PLTResolve slot when when creating
131 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
133 /* Some instructions. */
134 #define ADDIS_11_11 0x3d6b0000
135 #define ADDIS_11_30 0x3d7e0000
136 #define ADDIS_12_12 0x3d8c0000
137 #define ADDI_11_11 0x396b0000
138 #define ADD_0_11_11 0x7c0b5a14
139 #define ADD_3_12_2 0x7c6c1214
140 #define ADD_11_0_11 0x7d605a14
142 #define BCL_20_31 0x429f0005
143 #define BCTR 0x4e800420
144 #define BEQLR 0x4d820020
145 #define CMPWI_11_0 0x2c0b0000
146 #define LIS_11 0x3d600000
147 #define LIS_12 0x3d800000
148 #define LWZU_0_12 0x840c0000
149 #define LWZ_0_12 0x800c0000
150 #define LWZ_11_3 0x81630000
151 #define LWZ_11_11 0x816b0000
152 #define LWZ_11_30 0x817e0000
153 #define LWZ_12_3 0x81830000
154 #define LWZ_12_12 0x818c0000
155 #define MR_0_3 0x7c601b78
156 #define MR_3_0 0x7c030378
157 #define MFLR_0 0x7c0802a6
158 #define MFLR_12 0x7d8802a6
159 #define MTCTR_0 0x7c0903a6
160 #define MTCTR_11 0x7d6903a6
161 #define MTLR_0 0x7c0803a6
162 #define NOP 0x60000000
163 #define SUB_11_11_12 0x7d6c5850
165 /* Offset of tp and dtp pointers from start of TLS block. */
166 #define TP_OFFSET 0x7000
167 #define DTP_OFFSET 0x8000
169 /* The value of a defined global symbol. */
170 #define SYM_VAL(SYM) \
171 ((SYM)->root.u.def.section->output_section->vma \
172 + (SYM)->root.u.def.section->output_offset \
173 + (SYM)->root.u.def.value)
175 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
177 static reloc_howto_type ppc_elf_howto_raw
[] = {
178 /* This reloc does nothing. */
179 HOWTO (R_PPC_NONE
, /* type */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_bitfield
, /* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_PPC_NONE", /* name */
188 FALSE
, /* partial_inplace */
191 FALSE
), /* pcrel_offset */
193 /* A standard 32 bit relocation. */
194 HOWTO (R_PPC_ADDR32
, /* type */
196 2, /* size (0 = byte, 1 = short, 2 = long) */
198 FALSE
, /* pc_relative */
200 complain_overflow_bitfield
, /* complain_on_overflow */
201 bfd_elf_generic_reloc
, /* special_function */
202 "R_PPC_ADDR32", /* name */
203 FALSE
, /* partial_inplace */
205 0xffffffff, /* dst_mask */
206 FALSE
), /* pcrel_offset */
208 /* An absolute 26 bit branch; the lower two bits must be zero.
209 FIXME: we don't check that, we just clear them. */
210 HOWTO (R_PPC_ADDR24
, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE
, /* pc_relative */
216 complain_overflow_bitfield
, /* complain_on_overflow */
217 bfd_elf_generic_reloc
, /* special_function */
218 "R_PPC_ADDR24", /* name */
219 FALSE
, /* partial_inplace */
221 0x3fffffc, /* dst_mask */
222 FALSE
), /* pcrel_offset */
224 /* A standard 16 bit relocation. */
225 HOWTO (R_PPC_ADDR16
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 FALSE
, /* pc_relative */
231 complain_overflow_bitfield
, /* complain_on_overflow */
232 bfd_elf_generic_reloc
, /* special_function */
233 "R_PPC_ADDR16", /* name */
234 FALSE
, /* partial_inplace */
236 0xffff, /* dst_mask */
237 FALSE
), /* pcrel_offset */
239 /* A 16 bit relocation without overflow. */
240 HOWTO (R_PPC_ADDR16_LO
, /* type */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
244 FALSE
, /* pc_relative */
246 complain_overflow_dont
,/* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_PPC_ADDR16_LO", /* name */
249 FALSE
, /* partial_inplace */
251 0xffff, /* dst_mask */
252 FALSE
), /* pcrel_offset */
254 /* The high order 16 bits of an address. */
255 HOWTO (R_PPC_ADDR16_HI
, /* type */
257 1, /* size (0 = byte, 1 = short, 2 = long) */
259 FALSE
, /* pc_relative */
261 complain_overflow_dont
, /* complain_on_overflow */
262 bfd_elf_generic_reloc
, /* special_function */
263 "R_PPC_ADDR16_HI", /* name */
264 FALSE
, /* partial_inplace */
266 0xffff, /* dst_mask */
267 FALSE
), /* pcrel_offset */
269 /* The high order 16 bits of an address, plus 1 if the contents of
270 the low 16 bits, treated as a signed number, is negative. */
271 HOWTO (R_PPC_ADDR16_HA
, /* type */
273 1, /* size (0 = byte, 1 = short, 2 = long) */
275 FALSE
, /* pc_relative */
277 complain_overflow_dont
, /* complain_on_overflow */
278 ppc_elf_addr16_ha_reloc
, /* special_function */
279 "R_PPC_ADDR16_HA", /* name */
280 FALSE
, /* partial_inplace */
282 0xffff, /* dst_mask */
283 FALSE
), /* pcrel_offset */
285 /* An absolute 16 bit branch; the lower two bits must be zero.
286 FIXME: we don't check that, we just clear them. */
287 HOWTO (R_PPC_ADDR14
, /* type */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
291 FALSE
, /* pc_relative */
293 complain_overflow_bitfield
, /* complain_on_overflow */
294 bfd_elf_generic_reloc
, /* special_function */
295 "R_PPC_ADDR14", /* name */
296 FALSE
, /* partial_inplace */
298 0xfffc, /* dst_mask */
299 FALSE
), /* pcrel_offset */
301 /* An absolute 16 bit branch, for which bit 10 should be set to
302 indicate that the branch is expected to be taken. The lower two
303 bits must be zero. */
304 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
306 2, /* size (0 = byte, 1 = short, 2 = long) */
308 FALSE
, /* pc_relative */
310 complain_overflow_bitfield
, /* complain_on_overflow */
311 bfd_elf_generic_reloc
, /* special_function */
312 "R_PPC_ADDR14_BRTAKEN",/* name */
313 FALSE
, /* partial_inplace */
315 0xfffc, /* dst_mask */
316 FALSE
), /* pcrel_offset */
318 /* An absolute 16 bit branch, for which bit 10 should be set to
319 indicate that the branch is not expected to be taken. The lower
320 two bits must be zero. */
321 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE
, /* pc_relative */
327 complain_overflow_bitfield
, /* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_PPC_ADDR14_BRNTAKEN",/* name */
330 FALSE
, /* partial_inplace */
332 0xfffc, /* dst_mask */
333 FALSE
), /* pcrel_offset */
335 /* A relative 26 bit branch; the lower two bits must be zero. */
336 HOWTO (R_PPC_REL24
, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 TRUE
, /* pc_relative */
342 complain_overflow_signed
, /* complain_on_overflow */
343 bfd_elf_generic_reloc
, /* special_function */
344 "R_PPC_REL24", /* name */
345 FALSE
, /* partial_inplace */
347 0x3fffffc, /* dst_mask */
348 TRUE
), /* pcrel_offset */
350 /* A relative 16 bit branch; the lower two bits must be zero. */
351 HOWTO (R_PPC_REL14
, /* type */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
355 TRUE
, /* pc_relative */
357 complain_overflow_signed
, /* complain_on_overflow */
358 bfd_elf_generic_reloc
, /* special_function */
359 "R_PPC_REL14", /* name */
360 FALSE
, /* partial_inplace */
362 0xfffc, /* dst_mask */
363 TRUE
), /* pcrel_offset */
365 /* A relative 16 bit branch. Bit 10 should be set to indicate that
366 the branch is expected to be taken. The lower two bits must be
368 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 TRUE
, /* pc_relative */
374 complain_overflow_signed
, /* complain_on_overflow */
375 bfd_elf_generic_reloc
, /* special_function */
376 "R_PPC_REL14_BRTAKEN", /* name */
377 FALSE
, /* partial_inplace */
379 0xfffc, /* dst_mask */
380 TRUE
), /* pcrel_offset */
382 /* A relative 16 bit branch. Bit 10 should be set to indicate that
383 the branch is not expected to be taken. The lower two bits must
385 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 TRUE
, /* pc_relative */
391 complain_overflow_signed
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_PPC_REL14_BRNTAKEN",/* name */
394 FALSE
, /* partial_inplace */
396 0xfffc, /* dst_mask */
397 TRUE
), /* pcrel_offset */
399 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
401 HOWTO (R_PPC_GOT16
, /* type */
403 1, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_signed
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_PPC_GOT16", /* name */
410 FALSE
, /* partial_inplace */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
417 HOWTO (R_PPC_GOT16_LO
, /* type */
419 1, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE
, /* pc_relative */
423 complain_overflow_dont
, /* complain_on_overflow */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_PPC_GOT16_LO", /* name */
426 FALSE
, /* partial_inplace */
428 0xffff, /* dst_mask */
429 FALSE
), /* pcrel_offset */
431 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
433 HOWTO (R_PPC_GOT16_HI
, /* type */
435 1, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE
, /* pc_relative */
439 complain_overflow_bitfield
, /* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_PPC_GOT16_HI", /* name */
442 FALSE
, /* partial_inplace */
444 0xffff, /* dst_mask */
445 FALSE
), /* pcrel_offset */
447 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
449 HOWTO (R_PPC_GOT16_HA
, /* type */
451 1, /* size (0 = byte, 1 = short, 2 = long) */
453 FALSE
, /* pc_relative */
455 complain_overflow_bitfield
, /* complain_on_overflow */
456 ppc_elf_addr16_ha_reloc
, /* special_function */
457 "R_PPC_GOT16_HA", /* name */
458 FALSE
, /* partial_inplace */
460 0xffff, /* dst_mask */
461 FALSE
), /* pcrel_offset */
463 /* Like R_PPC_REL24, but referring to the procedure linkage table
464 entry for the symbol. */
465 HOWTO (R_PPC_PLTREL24
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_signed
, /* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_PPC_PLTREL24", /* name */
474 FALSE
, /* partial_inplace */
476 0x3fffffc, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 /* This is used only by the dynamic linker. The symbol should exist
480 both in the object being run and in some shared library. The
481 dynamic linker copies the data addressed by the symbol from the
482 shared library into the object, because the object being
483 run has to have the data at some particular address. */
484 HOWTO (R_PPC_COPY
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_bitfield
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_PPC_COPY", /* name */
493 FALSE
, /* partial_inplace */
496 FALSE
), /* pcrel_offset */
498 /* Like R_PPC_ADDR32, but used when setting global offset table
500 HOWTO (R_PPC_GLOB_DAT
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_bitfield
, /* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 "R_PPC_GLOB_DAT", /* name */
509 FALSE
, /* partial_inplace */
511 0xffffffff, /* dst_mask */
512 FALSE
), /* pcrel_offset */
514 /* Marks a procedure linkage table entry for a symbol. */
515 HOWTO (R_PPC_JMP_SLOT
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_bitfield
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_PPC_JMP_SLOT", /* name */
524 FALSE
, /* partial_inplace */
527 FALSE
), /* pcrel_offset */
529 /* Used only by the dynamic linker. When the object is run, this
530 longword is set to the load address of the object, plus the
532 HOWTO (R_PPC_RELATIVE
, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 FALSE
, /* pc_relative */
538 complain_overflow_bitfield
, /* complain_on_overflow */
539 bfd_elf_generic_reloc
, /* special_function */
540 "R_PPC_RELATIVE", /* name */
541 FALSE
, /* partial_inplace */
543 0xffffffff, /* dst_mask */
544 FALSE
), /* pcrel_offset */
546 /* Like R_PPC_REL24, but uses the value of the symbol within the
547 object rather than the final value. Normally used for
548 _GLOBAL_OFFSET_TABLE_. */
549 HOWTO (R_PPC_LOCAL24PC
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 TRUE
, /* pc_relative */
555 complain_overflow_signed
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 "R_PPC_LOCAL24PC", /* name */
558 FALSE
, /* partial_inplace */
560 0x3fffffc, /* dst_mask */
561 TRUE
), /* pcrel_offset */
563 /* Like R_PPC_ADDR32, but may be unaligned. */
564 HOWTO (R_PPC_UADDR32
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE
, /* pc_relative */
570 complain_overflow_bitfield
, /* complain_on_overflow */
571 bfd_elf_generic_reloc
, /* special_function */
572 "R_PPC_UADDR32", /* name */
573 FALSE
, /* partial_inplace */
575 0xffffffff, /* dst_mask */
576 FALSE
), /* pcrel_offset */
578 /* Like R_PPC_ADDR16, but may be unaligned. */
579 HOWTO (R_PPC_UADDR16
, /* type */
581 1, /* size (0 = byte, 1 = short, 2 = long) */
583 FALSE
, /* pc_relative */
585 complain_overflow_bitfield
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_PPC_UADDR16", /* name */
588 FALSE
, /* partial_inplace */
590 0xffff, /* dst_mask */
591 FALSE
), /* pcrel_offset */
593 /* 32-bit PC relative */
594 HOWTO (R_PPC_REL32
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 TRUE
, /* pc_relative */
600 complain_overflow_bitfield
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_PPC_REL32", /* name */
603 FALSE
, /* partial_inplace */
605 0xffffffff, /* dst_mask */
606 TRUE
), /* pcrel_offset */
608 /* 32-bit relocation to the symbol's procedure linkage table.
609 FIXME: not supported. */
610 HOWTO (R_PPC_PLT32
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE
, /* pc_relative */
616 complain_overflow_bitfield
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_PPC_PLT32", /* name */
619 FALSE
, /* partial_inplace */
622 FALSE
), /* pcrel_offset */
624 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
625 FIXME: not supported. */
626 HOWTO (R_PPC_PLTREL32
, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 TRUE
, /* pc_relative */
632 complain_overflow_bitfield
, /* complain_on_overflow */
633 bfd_elf_generic_reloc
, /* special_function */
634 "R_PPC_PLTREL32", /* name */
635 FALSE
, /* partial_inplace */
638 TRUE
), /* pcrel_offset */
640 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
642 HOWTO (R_PPC_PLT16_LO
, /* type */
644 1, /* size (0 = byte, 1 = short, 2 = long) */
646 FALSE
, /* pc_relative */
648 complain_overflow_dont
, /* complain_on_overflow */
649 bfd_elf_generic_reloc
, /* special_function */
650 "R_PPC_PLT16_LO", /* name */
651 FALSE
, /* partial_inplace */
653 0xffff, /* dst_mask */
654 FALSE
), /* pcrel_offset */
656 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
658 HOWTO (R_PPC_PLT16_HI
, /* type */
660 1, /* size (0 = byte, 1 = short, 2 = long) */
662 FALSE
, /* pc_relative */
664 complain_overflow_bitfield
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_PPC_PLT16_HI", /* name */
667 FALSE
, /* partial_inplace */
669 0xffff, /* dst_mask */
670 FALSE
), /* pcrel_offset */
672 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
674 HOWTO (R_PPC_PLT16_HA
, /* type */
676 1, /* size (0 = byte, 1 = short, 2 = long) */
678 FALSE
, /* pc_relative */
680 complain_overflow_bitfield
, /* complain_on_overflow */
681 ppc_elf_addr16_ha_reloc
, /* special_function */
682 "R_PPC_PLT16_HA", /* name */
683 FALSE
, /* partial_inplace */
685 0xffff, /* dst_mask */
686 FALSE
), /* pcrel_offset */
688 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
690 HOWTO (R_PPC_SDAREL16
, /* type */
692 1, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_signed
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_PPC_SDAREL16", /* name */
699 FALSE
, /* partial_inplace */
701 0xffff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* 16-bit section relative relocation. */
705 HOWTO (R_PPC_SECTOFF
, /* type */
707 1, /* size (0 = byte, 1 = short, 2 = long) */
709 FALSE
, /* pc_relative */
711 complain_overflow_bitfield
, /* complain_on_overflow */
712 bfd_elf_generic_reloc
, /* special_function */
713 "R_PPC_SECTOFF", /* name */
714 FALSE
, /* partial_inplace */
716 0xffff, /* dst_mask */
717 FALSE
), /* pcrel_offset */
719 /* 16-bit lower half section relative relocation. */
720 HOWTO (R_PPC_SECTOFF_LO
, /* type */
722 1, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE
, /* pc_relative */
726 complain_overflow_dont
, /* complain_on_overflow */
727 bfd_elf_generic_reloc
, /* special_function */
728 "R_PPC_SECTOFF_LO", /* name */
729 FALSE
, /* partial_inplace */
731 0xffff, /* dst_mask */
732 FALSE
), /* pcrel_offset */
734 /* 16-bit upper half section relative relocation. */
735 HOWTO (R_PPC_SECTOFF_HI
, /* type */
737 1, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE
, /* pc_relative */
741 complain_overflow_bitfield
, /* complain_on_overflow */
742 bfd_elf_generic_reloc
, /* special_function */
743 "R_PPC_SECTOFF_HI", /* name */
744 FALSE
, /* partial_inplace */
746 0xffff, /* dst_mask */
747 FALSE
), /* pcrel_offset */
749 /* 16-bit upper half adjusted section relative relocation. */
750 HOWTO (R_PPC_SECTOFF_HA
, /* type */
752 1, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_bitfield
, /* complain_on_overflow */
757 ppc_elf_addr16_ha_reloc
, /* special_function */
758 "R_PPC_SECTOFF_HA", /* name */
759 FALSE
, /* partial_inplace */
761 0xffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* Marker relocs for TLS. */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 FALSE
, /* pc_relative */
771 complain_overflow_dont
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_PPC_TLS", /* name */
774 FALSE
, /* partial_inplace */
777 FALSE
), /* pcrel_offset */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE
, /* pc_relative */
785 complain_overflow_dont
, /* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_PPC_TLSGD", /* name */
788 FALSE
, /* partial_inplace */
791 FALSE
), /* pcrel_offset */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
797 FALSE
, /* pc_relative */
799 complain_overflow_dont
, /* complain_on_overflow */
800 bfd_elf_generic_reloc
, /* special_function */
801 "R_PPC_TLSLD", /* name */
802 FALSE
, /* partial_inplace */
805 FALSE
), /* pcrel_offset */
807 /* Computes the load module index of the load module that contains the
808 definition of its TLS sym. */
809 HOWTO (R_PPC_DTPMOD32
,
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 FALSE
, /* pc_relative */
815 complain_overflow_dont
, /* complain_on_overflow */
816 ppc_elf_unhandled_reloc
, /* special_function */
817 "R_PPC_DTPMOD32", /* name */
818 FALSE
, /* partial_inplace */
820 0xffffffff, /* dst_mask */
821 FALSE
), /* pcrel_offset */
823 /* Computes a dtv-relative displacement, the difference between the value
824 of sym+add and the base address of the thread-local storage block that
825 contains the definition of sym, minus 0x8000. */
826 HOWTO (R_PPC_DTPREL32
,
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE
, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 ppc_elf_unhandled_reloc
, /* special_function */
834 "R_PPC_DTPREL32", /* name */
835 FALSE
, /* partial_inplace */
837 0xffffffff, /* dst_mask */
838 FALSE
), /* pcrel_offset */
840 /* A 16 bit dtprel reloc. */
841 HOWTO (R_PPC_DTPREL16
,
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_signed
, /* complain_on_overflow */
848 ppc_elf_unhandled_reloc
, /* special_function */
849 "R_PPC_DTPREL16", /* name */
850 FALSE
, /* partial_inplace */
852 0xffff, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* Like DTPREL16, but no overflow. */
856 HOWTO (R_PPC_DTPREL16_LO
,
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
, /* complain_on_overflow */
863 ppc_elf_unhandled_reloc
, /* special_function */
864 "R_PPC_DTPREL16_LO", /* name */
865 FALSE
, /* partial_inplace */
867 0xffff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 /* Like DTPREL16_LO, but next higher group of 16 bits. */
871 HOWTO (R_PPC_DTPREL16_HI
,
873 1, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE
, /* pc_relative */
877 complain_overflow_dont
, /* complain_on_overflow */
878 ppc_elf_unhandled_reloc
, /* special_function */
879 "R_PPC_DTPREL16_HI", /* name */
880 FALSE
, /* partial_inplace */
882 0xffff, /* dst_mask */
883 FALSE
), /* pcrel_offset */
885 /* Like DTPREL16_HI, but adjust for low 16 bits. */
886 HOWTO (R_PPC_DTPREL16_HA
,
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE
, /* pc_relative */
892 complain_overflow_dont
, /* complain_on_overflow */
893 ppc_elf_unhandled_reloc
, /* special_function */
894 "R_PPC_DTPREL16_HA", /* name */
895 FALSE
, /* partial_inplace */
897 0xffff, /* dst_mask */
898 FALSE
), /* pcrel_offset */
900 /* Computes a tp-relative displacement, the difference between the value of
901 sym+add and the value of the thread pointer (r13). */
902 HOWTO (R_PPC_TPREL32
,
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE
, /* pc_relative */
908 complain_overflow_dont
, /* complain_on_overflow */
909 ppc_elf_unhandled_reloc
, /* special_function */
910 "R_PPC_TPREL32", /* name */
911 FALSE
, /* partial_inplace */
913 0xffffffff, /* dst_mask */
914 FALSE
), /* pcrel_offset */
916 /* A 16 bit tprel reloc. */
917 HOWTO (R_PPC_TPREL16
,
919 1, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE
, /* pc_relative */
923 complain_overflow_signed
, /* complain_on_overflow */
924 ppc_elf_unhandled_reloc
, /* special_function */
925 "R_PPC_TPREL16", /* name */
926 FALSE
, /* partial_inplace */
928 0xffff, /* dst_mask */
929 FALSE
), /* pcrel_offset */
931 /* Like TPREL16, but no overflow. */
932 HOWTO (R_PPC_TPREL16_LO
,
934 1, /* size (0 = byte, 1 = short, 2 = long) */
936 FALSE
, /* pc_relative */
938 complain_overflow_dont
, /* complain_on_overflow */
939 ppc_elf_unhandled_reloc
, /* special_function */
940 "R_PPC_TPREL16_LO", /* name */
941 FALSE
, /* partial_inplace */
943 0xffff, /* dst_mask */
944 FALSE
), /* pcrel_offset */
946 /* Like TPREL16_LO, but next higher group of 16 bits. */
947 HOWTO (R_PPC_TPREL16_HI
,
949 1, /* size (0 = byte, 1 = short, 2 = long) */
951 FALSE
, /* pc_relative */
953 complain_overflow_dont
, /* complain_on_overflow */
954 ppc_elf_unhandled_reloc
, /* special_function */
955 "R_PPC_TPREL16_HI", /* name */
956 FALSE
, /* partial_inplace */
958 0xffff, /* dst_mask */
959 FALSE
), /* pcrel_offset */
961 /* Like TPREL16_HI, but adjust for low 16 bits. */
962 HOWTO (R_PPC_TPREL16_HA
,
964 1, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE
, /* pc_relative */
968 complain_overflow_dont
, /* complain_on_overflow */
969 ppc_elf_unhandled_reloc
, /* special_function */
970 "R_PPC_TPREL16_HA", /* name */
971 FALSE
, /* partial_inplace */
973 0xffff, /* dst_mask */
974 FALSE
), /* pcrel_offset */
976 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
977 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
978 to the first entry. */
979 HOWTO (R_PPC_GOT_TLSGD16
,
981 1, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE
, /* pc_relative */
985 complain_overflow_signed
, /* complain_on_overflow */
986 ppc_elf_unhandled_reloc
, /* special_function */
987 "R_PPC_GOT_TLSGD16", /* name */
988 FALSE
, /* partial_inplace */
990 0xffff, /* dst_mask */
991 FALSE
), /* pcrel_offset */
993 /* Like GOT_TLSGD16, but no overflow. */
994 HOWTO (R_PPC_GOT_TLSGD16_LO
,
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE
, /* pc_relative */
1000 complain_overflow_dont
, /* complain_on_overflow */
1001 ppc_elf_unhandled_reloc
, /* special_function */
1002 "R_PPC_GOT_TLSGD16_LO", /* name */
1003 FALSE
, /* partial_inplace */
1005 0xffff, /* dst_mask */
1006 FALSE
), /* pcrel_offset */
1008 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1009 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1010 16, /* rightshift */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE
, /* pc_relative */
1015 complain_overflow_dont
, /* complain_on_overflow */
1016 ppc_elf_unhandled_reloc
, /* special_function */
1017 "R_PPC_GOT_TLSGD16_HI", /* name */
1018 FALSE
, /* partial_inplace */
1020 0xffff, /* dst_mask */
1021 FALSE
), /* pcrel_offset */
1023 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1024 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1025 16, /* rightshift */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE
, /* pc_relative */
1030 complain_overflow_dont
, /* complain_on_overflow */
1031 ppc_elf_unhandled_reloc
, /* special_function */
1032 "R_PPC_GOT_TLSGD16_HA", /* name */
1033 FALSE
, /* partial_inplace */
1035 0xffff, /* dst_mask */
1036 FALSE
), /* pcrel_offset */
1038 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1039 with values (sym+add)@dtpmod and zero, and computes the offset to the
1041 HOWTO (R_PPC_GOT_TLSLD16
,
1043 1, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE
, /* pc_relative */
1047 complain_overflow_signed
, /* complain_on_overflow */
1048 ppc_elf_unhandled_reloc
, /* special_function */
1049 "R_PPC_GOT_TLSLD16", /* name */
1050 FALSE
, /* partial_inplace */
1052 0xffff, /* dst_mask */
1053 FALSE
), /* pcrel_offset */
1055 /* Like GOT_TLSLD16, but no overflow. */
1056 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1058 1, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE
, /* pc_relative */
1062 complain_overflow_dont
, /* complain_on_overflow */
1063 ppc_elf_unhandled_reloc
, /* special_function */
1064 "R_PPC_GOT_TLSLD16_LO", /* name */
1065 FALSE
, /* partial_inplace */
1067 0xffff, /* dst_mask */
1068 FALSE
), /* pcrel_offset */
1070 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1071 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1072 16, /* rightshift */
1073 1, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE
, /* pc_relative */
1077 complain_overflow_dont
, /* complain_on_overflow */
1078 ppc_elf_unhandled_reloc
, /* special_function */
1079 "R_PPC_GOT_TLSLD16_HI", /* name */
1080 FALSE
, /* partial_inplace */
1082 0xffff, /* dst_mask */
1083 FALSE
), /* pcrel_offset */
1085 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1086 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1087 16, /* rightshift */
1088 1, /* size (0 = byte, 1 = short, 2 = long) */
1090 FALSE
, /* pc_relative */
1092 complain_overflow_dont
, /* complain_on_overflow */
1093 ppc_elf_unhandled_reloc
, /* special_function */
1094 "R_PPC_GOT_TLSLD16_HA", /* name */
1095 FALSE
, /* partial_inplace */
1097 0xffff, /* dst_mask */
1098 FALSE
), /* pcrel_offset */
1100 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1101 the offset to the entry. */
1102 HOWTO (R_PPC_GOT_DTPREL16
,
1104 1, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE
, /* pc_relative */
1108 complain_overflow_signed
, /* complain_on_overflow */
1109 ppc_elf_unhandled_reloc
, /* special_function */
1110 "R_PPC_GOT_DTPREL16", /* name */
1111 FALSE
, /* partial_inplace */
1113 0xffff, /* dst_mask */
1114 FALSE
), /* pcrel_offset */
1116 /* Like GOT_DTPREL16, but no overflow. */
1117 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1119 1, /* size (0 = byte, 1 = short, 2 = long) */
1121 FALSE
, /* pc_relative */
1123 complain_overflow_dont
, /* complain_on_overflow */
1124 ppc_elf_unhandled_reloc
, /* special_function */
1125 "R_PPC_GOT_DTPREL16_LO", /* name */
1126 FALSE
, /* partial_inplace */
1128 0xffff, /* dst_mask */
1129 FALSE
), /* pcrel_offset */
1131 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1132 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1133 16, /* rightshift */
1134 1, /* size (0 = byte, 1 = short, 2 = long) */
1136 FALSE
, /* pc_relative */
1138 complain_overflow_dont
, /* complain_on_overflow */
1139 ppc_elf_unhandled_reloc
, /* special_function */
1140 "R_PPC_GOT_DTPREL16_HI", /* name */
1141 FALSE
, /* partial_inplace */
1143 0xffff, /* dst_mask */
1144 FALSE
), /* pcrel_offset */
1146 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1147 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1148 16, /* rightshift */
1149 1, /* size (0 = byte, 1 = short, 2 = long) */
1151 FALSE
, /* pc_relative */
1153 complain_overflow_dont
, /* complain_on_overflow */
1154 ppc_elf_unhandled_reloc
, /* special_function */
1155 "R_PPC_GOT_DTPREL16_HA", /* name */
1156 FALSE
, /* partial_inplace */
1158 0xffff, /* dst_mask */
1159 FALSE
), /* pcrel_offset */
1161 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1162 offset to the entry. */
1163 HOWTO (R_PPC_GOT_TPREL16
,
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE
, /* pc_relative */
1169 complain_overflow_signed
, /* complain_on_overflow */
1170 ppc_elf_unhandled_reloc
, /* special_function */
1171 "R_PPC_GOT_TPREL16", /* name */
1172 FALSE
, /* partial_inplace */
1174 0xffff, /* dst_mask */
1175 FALSE
), /* pcrel_offset */
1177 /* Like GOT_TPREL16, but no overflow. */
1178 HOWTO (R_PPC_GOT_TPREL16_LO
,
1180 1, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE
, /* pc_relative */
1184 complain_overflow_dont
, /* complain_on_overflow */
1185 ppc_elf_unhandled_reloc
, /* special_function */
1186 "R_PPC_GOT_TPREL16_LO", /* name */
1187 FALSE
, /* partial_inplace */
1189 0xffff, /* dst_mask */
1190 FALSE
), /* pcrel_offset */
1192 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1193 HOWTO (R_PPC_GOT_TPREL16_HI
,
1194 16, /* rightshift */
1195 1, /* size (0 = byte, 1 = short, 2 = long) */
1197 FALSE
, /* pc_relative */
1199 complain_overflow_dont
, /* complain_on_overflow */
1200 ppc_elf_unhandled_reloc
, /* special_function */
1201 "R_PPC_GOT_TPREL16_HI", /* name */
1202 FALSE
, /* partial_inplace */
1204 0xffff, /* dst_mask */
1205 FALSE
), /* pcrel_offset */
1207 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1208 HOWTO (R_PPC_GOT_TPREL16_HA
,
1209 16, /* rightshift */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_dont
, /* complain_on_overflow */
1215 ppc_elf_unhandled_reloc
, /* special_function */
1216 "R_PPC_GOT_TPREL16_HA", /* name */
1217 FALSE
, /* partial_inplace */
1219 0xffff, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* The remaining relocs are from the Embedded ELF ABI, and are not
1223 in the SVR4 ELF ABI. */
1225 /* 32 bit value resulting from the addend minus the symbol. */
1226 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE
, /* pc_relative */
1232 complain_overflow_bitfield
, /* complain_on_overflow */
1233 bfd_elf_generic_reloc
, /* special_function */
1234 "R_PPC_EMB_NADDR32", /* name */
1235 FALSE
, /* partial_inplace */
1237 0xffffffff, /* dst_mask */
1238 FALSE
), /* pcrel_offset */
1240 /* 16 bit value resulting from the addend minus the symbol. */
1241 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1243 1, /* size (0 = byte, 1 = short, 2 = long) */
1245 FALSE
, /* pc_relative */
1247 complain_overflow_bitfield
, /* complain_on_overflow */
1248 bfd_elf_generic_reloc
, /* special_function */
1249 "R_PPC_EMB_NADDR16", /* name */
1250 FALSE
, /* partial_inplace */
1252 0xffff, /* dst_mask */
1253 FALSE
), /* pcrel_offset */
1255 /* 16 bit value resulting from the addend minus the symbol. */
1256 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1258 1, /* size (0 = byte, 1 = short, 2 = long) */
1260 FALSE
, /* pc_relative */
1262 complain_overflow_dont
,/* complain_on_overflow */
1263 bfd_elf_generic_reloc
, /* special_function */
1264 "R_PPC_EMB_ADDR16_LO", /* name */
1265 FALSE
, /* partial_inplace */
1267 0xffff, /* dst_mask */
1268 FALSE
), /* pcrel_offset */
1270 /* The high order 16 bits of the addend minus the symbol. */
1271 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1272 16, /* rightshift */
1273 1, /* size (0 = byte, 1 = short, 2 = long) */
1275 FALSE
, /* pc_relative */
1277 complain_overflow_dont
, /* complain_on_overflow */
1278 bfd_elf_generic_reloc
, /* special_function */
1279 "R_PPC_EMB_NADDR16_HI", /* name */
1280 FALSE
, /* partial_inplace */
1282 0xffff, /* dst_mask */
1283 FALSE
), /* pcrel_offset */
1285 /* The high order 16 bits of the result of the addend minus the address,
1286 plus 1 if the contents of the low 16 bits, treated as a signed number,
1288 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1289 16, /* rightshift */
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1292 FALSE
, /* pc_relative */
1294 complain_overflow_dont
, /* complain_on_overflow */
1295 ppc_elf_addr16_ha_reloc
, /* special_function */
1296 "R_PPC_EMB_NADDR16_HA", /* name */
1297 FALSE
, /* partial_inplace */
1299 0xffff, /* dst_mask */
1300 FALSE
), /* pcrel_offset */
1302 /* 16 bit value resulting from allocating a 4 byte word to hold an
1303 address in the .sdata section, and returning the offset from
1304 _SDA_BASE_ for that relocation. */
1305 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1307 1, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE
, /* pc_relative */
1311 complain_overflow_signed
, /* complain_on_overflow */
1312 bfd_elf_generic_reloc
, /* special_function */
1313 "R_PPC_EMB_SDAI16", /* name */
1314 FALSE
, /* partial_inplace */
1316 0xffff, /* dst_mask */
1317 FALSE
), /* pcrel_offset */
1319 /* 16 bit value resulting from allocating a 4 byte word to hold an
1320 address in the .sdata2 section, and returning the offset from
1321 _SDA2_BASE_ for that relocation. */
1322 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1324 1, /* size (0 = byte, 1 = short, 2 = long) */
1326 FALSE
, /* pc_relative */
1328 complain_overflow_signed
, /* complain_on_overflow */
1329 bfd_elf_generic_reloc
, /* special_function */
1330 "R_PPC_EMB_SDA2I16", /* name */
1331 FALSE
, /* partial_inplace */
1333 0xffff, /* dst_mask */
1334 FALSE
), /* pcrel_offset */
1336 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1337 small data items. */
1338 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1340 1, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE
, /* pc_relative */
1344 complain_overflow_signed
, /* complain_on_overflow */
1345 bfd_elf_generic_reloc
, /* special_function */
1346 "R_PPC_EMB_SDA2REL", /* name */
1347 FALSE
, /* partial_inplace */
1349 0xffff, /* dst_mask */
1350 FALSE
), /* pcrel_offset */
1352 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1353 signed offset from the appropriate base, and filling in the register
1354 field with the appropriate register (0, 2, or 13). */
1355 HOWTO (R_PPC_EMB_SDA21
, /* type */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE
, /* pc_relative */
1361 complain_overflow_signed
, /* complain_on_overflow */
1362 bfd_elf_generic_reloc
, /* special_function */
1363 "R_PPC_EMB_SDA21", /* name */
1364 FALSE
, /* partial_inplace */
1366 0xffff, /* dst_mask */
1367 FALSE
), /* pcrel_offset */
1369 /* Relocation not handled: R_PPC_EMB_MRKREF */
1370 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1371 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1372 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1373 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1374 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1376 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1377 in the 16 bit signed offset from the appropriate base, and filling in the
1378 register field with the appropriate register (0, 2, or 13). */
1379 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 TRUE
, /* pc_relative */
1385 complain_overflow_signed
, /* complain_on_overflow */
1386 bfd_elf_generic_reloc
, /* special_function */
1387 "R_PPC_EMB_RELSDA", /* name */
1388 FALSE
, /* partial_inplace */
1390 0xffff, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1393 HOWTO (R_PPC_IRELATIVE
, /* type */
1395 2, /* size (0 = byte, 1 = short, 2 = long) */
1397 FALSE
, /* pc_relative */
1399 complain_overflow_bitfield
, /* complain_on_overflow */
1400 bfd_elf_generic_reloc
, /* special_function */
1401 "R_PPC_IRELATIVE", /* name */
1402 FALSE
, /* partial_inplace */
1404 0xffffffff, /* dst_mask */
1405 FALSE
), /* pcrel_offset */
1407 /* A 16 bit relative relocation. */
1408 HOWTO (R_PPC_REL16
, /* type */
1410 1, /* size (0 = byte, 1 = short, 2 = long) */
1412 TRUE
, /* pc_relative */
1414 complain_overflow_bitfield
, /* complain_on_overflow */
1415 bfd_elf_generic_reloc
, /* special_function */
1416 "R_PPC_REL16", /* name */
1417 FALSE
, /* partial_inplace */
1419 0xffff, /* dst_mask */
1420 TRUE
), /* pcrel_offset */
1422 /* A 16 bit relative relocation without overflow. */
1423 HOWTO (R_PPC_REL16_LO
, /* type */
1425 1, /* size (0 = byte, 1 = short, 2 = long) */
1427 TRUE
, /* pc_relative */
1429 complain_overflow_dont
,/* complain_on_overflow */
1430 bfd_elf_generic_reloc
, /* special_function */
1431 "R_PPC_REL16_LO", /* name */
1432 FALSE
, /* partial_inplace */
1434 0xffff, /* dst_mask */
1435 TRUE
), /* pcrel_offset */
1437 /* The high order 16 bits of a relative address. */
1438 HOWTO (R_PPC_REL16_HI
, /* type */
1439 16, /* rightshift */
1440 1, /* size (0 = byte, 1 = short, 2 = long) */
1442 TRUE
, /* pc_relative */
1444 complain_overflow_dont
, /* complain_on_overflow */
1445 bfd_elf_generic_reloc
, /* special_function */
1446 "R_PPC_REL16_HI", /* name */
1447 FALSE
, /* partial_inplace */
1449 0xffff, /* dst_mask */
1450 TRUE
), /* pcrel_offset */
1452 /* The high order 16 bits of a relative address, plus 1 if the contents of
1453 the low 16 bits, treated as a signed number, is negative. */
1454 HOWTO (R_PPC_REL16_HA
, /* type */
1455 16, /* rightshift */
1456 1, /* size (0 = byte, 1 = short, 2 = long) */
1458 TRUE
, /* pc_relative */
1460 complain_overflow_dont
, /* complain_on_overflow */
1461 ppc_elf_addr16_ha_reloc
, /* special_function */
1462 "R_PPC_REL16_HA", /* name */
1463 FALSE
, /* partial_inplace */
1465 0xffff, /* dst_mask */
1466 TRUE
), /* pcrel_offset */
1468 /* GNU extension to record C++ vtable hierarchy. */
1469 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1471 0, /* size (0 = byte, 1 = short, 2 = long) */
1473 FALSE
, /* pc_relative */
1475 complain_overflow_dont
, /* complain_on_overflow */
1476 NULL
, /* special_function */
1477 "R_PPC_GNU_VTINHERIT", /* name */
1478 FALSE
, /* partial_inplace */
1481 FALSE
), /* pcrel_offset */
1483 /* GNU extension to record C++ vtable member usage. */
1484 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1486 0, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE
, /* pc_relative */
1490 complain_overflow_dont
, /* complain_on_overflow */
1491 NULL
, /* special_function */
1492 "R_PPC_GNU_VTENTRY", /* name */
1493 FALSE
, /* partial_inplace */
1496 FALSE
), /* pcrel_offset */
1498 /* Phony reloc to handle AIX style TOC entries. */
1499 HOWTO (R_PPC_TOC16
, /* type */
1501 1, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_signed
, /* complain_on_overflow */
1506 bfd_elf_generic_reloc
, /* special_function */
1507 "R_PPC_TOC16", /* name */
1508 FALSE
, /* partial_inplace */
1510 0xffff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1514 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1517 ppc_elf_howto_init (void)
1519 unsigned int i
, type
;
1522 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1525 type
= ppc_elf_howto_raw
[i
].type
;
1526 if (type
>= (sizeof (ppc_elf_howto_table
)
1527 / sizeof (ppc_elf_howto_table
[0])))
1529 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1533 static reloc_howto_type
*
1534 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1535 bfd_reloc_code_real_type code
)
1537 enum elf_ppc_reloc_type r
;
1539 /* Initialize howto table if not already done. */
1540 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1541 ppc_elf_howto_init ();
1548 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1549 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1550 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1551 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1552 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1553 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1554 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1555 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1556 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1557 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1558 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1559 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1560 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1561 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1562 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1563 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1564 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1565 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1566 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1567 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1568 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1569 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1570 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1571 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1572 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1573 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1574 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1575 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1576 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1577 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1578 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1579 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1580 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1581 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1582 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1583 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1584 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC_TLSGD
; break;
1585 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC_TLSLD
; break;
1586 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1587 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1588 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1589 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1590 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1591 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1592 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1593 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1594 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1595 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1596 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1597 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1598 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1599 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1600 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1601 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1602 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1603 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1604 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1605 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1606 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1607 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1608 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1609 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1610 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1611 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1612 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1613 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1614 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1615 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1616 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1617 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1618 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1619 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1620 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1621 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1622 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1623 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1624 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1625 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1626 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1627 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1628 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1629 case BFD_RELOC_16_PCREL
: r
= R_PPC_REL16
; break;
1630 case BFD_RELOC_LO16_PCREL
: r
= R_PPC_REL16_LO
; break;
1631 case BFD_RELOC_HI16_PCREL
: r
= R_PPC_REL16_HI
; break;
1632 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC_REL16_HA
; break;
1633 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1634 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1637 return ppc_elf_howto_table
[r
];
1640 static reloc_howto_type
*
1641 ppc_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1647 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1649 if (ppc_elf_howto_raw
[i
].name
!= NULL
1650 && strcasecmp (ppc_elf_howto_raw
[i
].name
, r_name
) == 0)
1651 return &ppc_elf_howto_raw
[i
];
1656 /* Set the howto pointer for a PowerPC ELF reloc. */
1659 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1661 Elf_Internal_Rela
*dst
)
1663 /* Initialize howto table if not already done. */
1664 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1665 ppc_elf_howto_init ();
1667 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1668 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1670 /* Just because the above assert didn't trigger doesn't mean that
1671 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1672 if (!cache_ptr
->howto
)
1674 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
1675 abfd
, ELF32_R_TYPE (dst
->r_info
));
1676 bfd_set_error (bfd_error_bad_value
);
1678 cache_ptr
->howto
= ppc_elf_howto_table
[R_PPC_NONE
];
1682 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
1684 static bfd_reloc_status_type
1685 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1686 arelent
*reloc_entry
,
1688 void *data ATTRIBUTE_UNUSED
,
1689 asection
*input_section
,
1691 char **error_message ATTRIBUTE_UNUSED
)
1695 if (output_bfd
!= NULL
)
1697 reloc_entry
->address
+= input_section
->output_offset
;
1698 return bfd_reloc_ok
;
1701 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1702 return bfd_reloc_outofrange
;
1704 if (bfd_is_com_section (symbol
->section
))
1707 relocation
= symbol
->value
;
1709 relocation
+= symbol
->section
->output_section
->vma
;
1710 relocation
+= symbol
->section
->output_offset
;
1711 relocation
+= reloc_entry
->addend
;
1712 if (reloc_entry
->howto
->pc_relative
)
1713 relocation
-= reloc_entry
->address
;
1715 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1717 return bfd_reloc_continue
;
1720 static bfd_reloc_status_type
1721 ppc_elf_unhandled_reloc (bfd
*abfd
,
1722 arelent
*reloc_entry
,
1725 asection
*input_section
,
1727 char **error_message
)
1729 /* If this is a relocatable link (output_bfd test tells us), just
1730 call the generic function. Any adjustment will be done at final
1732 if (output_bfd
!= NULL
)
1733 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1734 input_section
, output_bfd
, error_message
);
1736 if (error_message
!= NULL
)
1738 static char buf
[60];
1739 sprintf (buf
, _("generic linker can't handle %s"),
1740 reloc_entry
->howto
->name
);
1741 *error_message
= buf
;
1743 return bfd_reloc_dangerous
;
1746 /* Sections created by the linker. */
1748 typedef struct elf_linker_section
1750 /* Pointer to the bfd section. */
1754 /* Associated bss section name. */
1755 const char *bss_name
;
1756 /* Associated symbol name. */
1757 const char *sym_name
;
1758 /* Associated symbol. */
1759 struct elf_link_hash_entry
*sym
;
1760 } elf_linker_section_t
;
1762 /* Linked list of allocated pointer entries. This hangs off of the
1763 symbol lists, and provides allows us to return different pointers,
1764 based on different addend's. */
1766 typedef struct elf_linker_section_pointers
1768 /* next allocated pointer for this symbol */
1769 struct elf_linker_section_pointers
*next
;
1770 /* offset of pointer from beginning of section */
1774 /* which linker section this is */
1775 elf_linker_section_t
*lsect
;
1776 } elf_linker_section_pointers_t
;
1778 struct ppc_elf_obj_tdata
1780 struct elf_obj_tdata elf
;
1782 /* A mapping from local symbols to offsets into the various linker
1783 sections added. This is index by the symbol index. */
1784 elf_linker_section_pointers_t
**linker_section_pointers
;
1786 /* Flags used to auto-detect plt type. */
1787 unsigned int makes_plt_call
: 1;
1788 unsigned int has_rel16
: 1;
1791 #define ppc_elf_tdata(bfd) \
1792 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1794 #define elf_local_ptr_offsets(bfd) \
1795 (ppc_elf_tdata (bfd)->linker_section_pointers)
1797 #define is_ppc_elf(bfd) \
1798 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1799 && elf_object_id (bfd) == PPC32_ELF_DATA)
1801 /* Override the generic function because we store some extras. */
1804 ppc_elf_mkobject (bfd
*abfd
)
1806 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc_elf_obj_tdata
),
1810 /* Fix bad default arch selected for a 32 bit input bfd when the
1811 default is 64 bit. */
1814 ppc_elf_object_p (bfd
*abfd
)
1816 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1818 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1820 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1822 /* Relies on arch after 64 bit default being 32 bit default. */
1823 abfd
->arch_info
= abfd
->arch_info
->next
;
1824 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1830 /* Function to set whether a module needs the -mrelocatable bit set. */
1833 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1835 BFD_ASSERT (!elf_flags_init (abfd
)
1836 || elf_elfheader (abfd
)->e_flags
== flags
);
1838 elf_elfheader (abfd
)->e_flags
= flags
;
1839 elf_flags_init (abfd
) = TRUE
;
1843 /* Support for core dump NOTE sections. */
1846 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1851 switch (note
->descsz
)
1856 case 268: /* Linux/PPC. */
1858 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1861 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1870 /* Make a ".reg/999" section. */
1871 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1872 size
, note
->descpos
+ offset
);
1876 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1878 switch (note
->descsz
)
1883 case 128: /* Linux/PPC elf_prpsinfo. */
1884 elf_tdata (abfd
)->core_program
1885 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1886 elf_tdata (abfd
)->core_command
1887 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1890 /* Note that for some reason, a spurious space is tacked
1891 onto the end of the args in some (at least one anyway)
1892 implementations, so strip it off if it exists. */
1895 char *command
= elf_tdata (abfd
)->core_command
;
1896 int n
= strlen (command
);
1898 if (0 < n
&& command
[n
- 1] == ' ')
1899 command
[n
- 1] = '\0';
1906 ppc_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
, ...)
1918 va_start (ap
, note_type
);
1919 memset (data
, 0, 32);
1920 strncpy (data
+ 32, va_arg (ap
, const char *), 16);
1921 strncpy (data
+ 48, va_arg (ap
, const char *), 80);
1923 return elfcore_write_note (abfd
, buf
, bufsiz
,
1924 "CORE", note_type
, data
, sizeof (data
));
1935 va_start (ap
, note_type
);
1936 memset (data
, 0, 72);
1937 pid
= va_arg (ap
, long);
1938 bfd_put_32 (abfd
, pid
, data
+ 24);
1939 cursig
= va_arg (ap
, int);
1940 bfd_put_16 (abfd
, cursig
, data
+ 12);
1941 greg
= va_arg (ap
, const void *);
1942 memcpy (data
+ 72, greg
, 192);
1943 memset (data
+ 264, 0, 4);
1945 return elfcore_write_note (abfd
, buf
, bufsiz
,
1946 "CORE", note_type
, data
, sizeof (data
));
1951 /* Return address for Ith PLT stub in section PLT, for relocation REL
1952 or (bfd_vma) -1 if it should not be included. */
1955 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1956 const asection
*plt ATTRIBUTE_UNUSED
,
1959 return rel
->address
;
1962 /* Handle a PowerPC specific section when reading an object file. This
1963 is called when bfd_section_from_shdr finds a section with an unknown
1967 ppc_elf_section_from_shdr (bfd
*abfd
,
1968 Elf_Internal_Shdr
*hdr
,
1975 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1978 newsect
= hdr
->bfd_section
;
1979 flags
= bfd_get_section_flags (abfd
, newsect
);
1980 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1981 flags
|= SEC_EXCLUDE
;
1983 if (hdr
->sh_type
== SHT_ORDERED
)
1984 flags
|= SEC_SORT_ENTRIES
;
1986 bfd_set_section_flags (abfd
, newsect
, flags
);
1990 /* Set up any other section flags and such that may be necessary. */
1993 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1994 Elf_Internal_Shdr
*shdr
,
1997 if ((asect
->flags
& (SEC_GROUP
| SEC_EXCLUDE
)) == SEC_EXCLUDE
)
1998 shdr
->sh_flags
|= SHF_EXCLUDE
;
2000 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2001 shdr
->sh_type
= SHT_ORDERED
;
2006 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
2007 need to bump up the number of section headers. */
2010 ppc_elf_additional_program_headers (bfd
*abfd
,
2011 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2016 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2017 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2020 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2021 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
2027 /* Add extra PPC sections -- Note, for now, make .sbss2 and
2028 .PPC.EMB.sbss0 a normal section, and not a bss section so
2029 that the linker doesn't crater when trying to make more than
2032 static const struct bfd_elf_special_section ppc_elf_special_sections
[] =
2034 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
2035 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2036 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2037 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2038 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
2039 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED
, SHF_ALLOC
},
2040 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE
, 0 },
2041 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2042 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
2043 { NULL
, 0, 0, 0, 0 }
2046 /* This is what we want for new plt/got. */
2047 static struct bfd_elf_special_section ppc_alt_plt
=
2048 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
};
2050 static const struct bfd_elf_special_section
*
2051 ppc_elf_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
2053 const struct bfd_elf_special_section
*ssect
;
2055 /* See if this is one of the special sections. */
2056 if (sec
->name
== NULL
)
2059 ssect
= _bfd_elf_get_special_section (sec
->name
, ppc_elf_special_sections
,
2063 if (ssect
== ppc_elf_special_sections
&& (sec
->flags
& SEC_LOAD
) != 0)
2064 ssect
= &ppc_alt_plt
;
2068 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
2071 /* Very simple linked list structure for recording apuinfo values. */
2072 typedef struct apuinfo_list
2074 struct apuinfo_list
*next
;
2075 unsigned long value
;
2079 static apuinfo_list
*head
;
2083 apuinfo_list_init (void)
2089 apuinfo_list_add (unsigned long value
)
2091 apuinfo_list
*entry
= head
;
2093 while (entry
!= NULL
)
2095 if (entry
->value
== value
)
2097 entry
= entry
->next
;
2100 entry
= bfd_malloc (sizeof (* entry
));
2104 entry
->value
= value
;
2110 apuinfo_list_length (void)
2112 apuinfo_list
*entry
;
2113 unsigned long count
;
2115 for (entry
= head
, count
= 0;
2117 entry
= entry
->next
)
2123 static inline unsigned long
2124 apuinfo_list_element (unsigned long number
)
2126 apuinfo_list
* entry
;
2130 entry
= entry
->next
)
2133 return entry
? entry
->value
: 0;
2137 apuinfo_list_finish (void)
2139 apuinfo_list
*entry
;
2141 for (entry
= head
; entry
;)
2143 apuinfo_list
*next
= entry
->next
;
2151 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2152 #define APUINFO_LABEL "APUinfo"
2154 /* Scan the input BFDs and create a linked list of
2155 the APUinfo values that will need to be emitted. */
2158 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
2163 unsigned num_input_sections
;
2164 bfd_size_type output_section_size
;
2166 unsigned num_entries
;
2167 unsigned long offset
;
2168 unsigned long length
;
2169 const char *error_message
= NULL
;
2171 if (link_info
== NULL
)
2174 /* Scan the input bfds, looking for apuinfo sections. */
2175 num_input_sections
= 0;
2176 output_section_size
= 0;
2178 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2180 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2183 ++ num_input_sections
;
2184 output_section_size
+= asec
->size
;
2188 /* We need at least one input sections
2189 in order to make merging worthwhile. */
2190 if (num_input_sections
< 1)
2193 /* Just make sure that the output section exists as well. */
2194 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2198 /* Allocate a buffer for the contents of the input sections. */
2199 buffer
= bfd_malloc (output_section_size
);
2204 apuinfo_list_init ();
2206 /* Read in the input sections contents. */
2207 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
2209 unsigned long datum
;
2212 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
2216 length
= asec
->size
;
2219 error_message
= _("corrupt or empty %s section in %B");
2223 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
2224 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
2226 error_message
= _("unable to read in %s section from %B");
2230 /* Process the contents of the section. */
2231 ptr
= buffer
+ offset
;
2232 error_message
= _("corrupt %s section in %B");
2234 /* Verify the contents of the header. Note - we have to
2235 extract the values this way in order to allow for a
2236 host whose endian-ness is different from the target. */
2237 datum
= bfd_get_32 (ibfd
, ptr
);
2238 if (datum
!= sizeof APUINFO_LABEL
)
2241 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
2245 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
2248 /* Get the number of bytes used for apuinfo entries. */
2249 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
2250 if (datum
+ 20 != length
)
2253 /* Make sure that we do not run off the end of the section. */
2254 if (offset
+ length
> output_section_size
)
2257 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2258 for (i
= 0; i
< datum
; i
+= 4)
2259 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
2261 /* Update the offset. */
2265 error_message
= NULL
;
2267 /* Compute the size of the output section. */
2268 num_entries
= apuinfo_list_length ();
2269 output_section_size
= 20 + num_entries
* 4;
2271 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2273 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
2275 error_message
= _("warning: unable to set size of %s section in %B");
2281 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
2284 /* Prevent the output section from accumulating the input sections'
2285 contents. We have already stored this in our linked list structure. */
2288 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2289 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
2291 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2293 return (apuinfo_list_length ()
2294 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
2297 /* Finally we can generate the output section. */
2300 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
2305 unsigned num_entries
;
2306 bfd_size_type length
;
2308 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
2312 if (apuinfo_list_length () == 0)
2315 length
= asec
->size
;
2319 buffer
= bfd_malloc (length
);
2322 (*_bfd_error_handler
)
2323 (_("failed to allocate space for new APUinfo section."));
2327 /* Create the apuinfo header. */
2328 num_entries
= apuinfo_list_length ();
2329 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
2330 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
2331 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
2332 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
2335 for (i
= 0; i
< num_entries
; i
++)
2337 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
2341 if (length
!= asec
->size
)
2342 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
2344 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
2345 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
2349 apuinfo_list_finish ();
2353 is_nonpic_glink_stub (bfd
*abfd
, asection
*glink
, bfd_vma off
)
2355 bfd_byte buf
[GLINK_ENTRY_SIZE
];
2357 if (!bfd_get_section_contents (abfd
, glink
, buf
, off
, GLINK_ENTRY_SIZE
))
2360 return ((bfd_get_32 (abfd
, buf
+ 0) & 0xffff0000) == LIS_11
2361 && (bfd_get_32 (abfd
, buf
+ 4) & 0xffff0000) == LWZ_11_11
2362 && bfd_get_32 (abfd
, buf
+ 8) == MTCTR_11
2363 && bfd_get_32 (abfd
, buf
+ 12) == BCTR
);
2367 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2369 bfd_vma vma
= *(bfd_vma
*) ptr
;
2370 return ((section
->flags
& SEC_ALLOC
) != 0
2371 && section
->vma
<= vma
2372 && vma
< section
->vma
+ section
->size
);
2376 ppc_elf_get_synthetic_symtab (bfd
*abfd
, long symcount
, asymbol
**syms
,
2377 long dynsymcount
, asymbol
**dynsyms
,
2380 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2381 asection
*plt
, *relplt
, *dynamic
, *glink
;
2382 bfd_vma glink_vma
= 0;
2383 bfd_vma resolv_vma
= 0;
2394 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
2397 if (dynsymcount
<= 0)
2400 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2404 plt
= bfd_get_section_by_name (abfd
, ".plt");
2408 /* Call common code to handle old-style executable PLTs. */
2409 if (elf_section_flags (plt
) & SHF_EXECINSTR
)
2410 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
2411 dynsymcount
, dynsyms
, ret
);
2413 /* If this object was prelinked, the prelinker stored the address
2414 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
2415 dynamic
= bfd_get_section_by_name (abfd
, ".dynamic");
2416 if (dynamic
!= NULL
)
2418 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2420 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2422 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2425 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2426 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2429 extdynend
= extdyn
+ dynamic
->size
;
2430 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2432 Elf_Internal_Dyn dyn
;
2433 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2435 if (dyn
.d_tag
== DT_NULL
)
2438 if (dyn
.d_tag
== DT_PPC_GOT
)
2440 unsigned int g_o_t
= dyn
.d_un
.d_val
;
2441 asection
*got
= bfd_get_section_by_name (abfd
, ".got");
2443 && bfd_get_section_contents (abfd
, got
, buf
,
2444 g_o_t
- got
->vma
+ 4, 4))
2445 glink_vma
= bfd_get_32 (abfd
, buf
);
2452 /* Otherwise we read the first plt entry. */
2455 if (bfd_get_section_contents (abfd
, plt
, buf
, 0, 4))
2456 glink_vma
= bfd_get_32 (abfd
, buf
);
2462 /* The .glink section usually does not survive the final
2463 link; search for the section (usually .text) where the
2464 glink stubs now reside. */
2465 glink
= bfd_sections_find_if (abfd
, section_covers_vma
, &glink_vma
);
2469 /* Determine glink PLT resolver by reading the relative branch
2470 from the first glink stub. */
2471 if (bfd_get_section_contents (abfd
, glink
, buf
,
2472 glink_vma
- glink
->vma
, 4))
2474 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2476 /* The first glink stub may either branch to the resolver ... */
2478 if ((insn
& ~0x3fffffc) == 0)
2479 resolv_vma
= glink_vma
+ (insn
^ 0x2000000) - 0x2000000;
2481 /* ... or fall through a bunch of NOPs. */
2482 else if ((insn
^ B
^ NOP
) == 0)
2484 bfd_get_section_contents (abfd
, glink
, buf
,
2485 glink_vma
- glink
->vma
+ i
, 4);
2487 if (bfd_get_32 (abfd
, buf
) != NOP
)
2489 resolv_vma
= glink_vma
+ i
;
2494 count
= relplt
->size
/ sizeof (Elf32_External_Rela
);
2495 stub_vma
= glink_vma
- (bfd_vma
) count
* 16;
2496 /* If the stubs are those for -shared/-pie then we might have
2497 multiple stubs for each plt entry. If that is the case then
2498 there is no way to associate stubs with their plt entries short
2499 of figuring out the GOT pointer value used in the stub. */
2500 if (!is_nonpic_glink_stub (abfd
, glink
,
2501 glink_vma
- GLINK_ENTRY_SIZE
- glink
->vma
))
2504 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2505 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
2508 size
= count
* sizeof (asymbol
);
2509 p
= relplt
->relocation
;
2510 for (i
= 0; i
< count
; i
++, p
++)
2512 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2514 size
+= sizeof ("+0x") - 1 + 8;
2517 size
+= sizeof (asymbol
) + sizeof ("__glink");
2520 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2522 s
= *ret
= bfd_malloc (size
);
2526 names
= (char *) (s
+ count
+ 1 + (resolv_vma
!= 0));
2527 p
= relplt
->relocation
;
2528 for (i
= 0; i
< count
; i
++, p
++)
2532 *s
= **p
->sym_ptr_ptr
;
2533 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2534 we are defining a symbol, ensure one of them is set. */
2535 if ((s
->flags
& BSF_LOCAL
) == 0)
2536 s
->flags
|= BSF_GLOBAL
;
2537 s
->flags
|= BSF_SYNTHETIC
;
2539 s
->value
= stub_vma
- glink
->vma
;
2542 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2543 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2547 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2548 names
+= sizeof ("+0x") - 1;
2549 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2550 names
+= strlen (names
);
2552 memcpy (names
, "@plt", sizeof ("@plt"));
2553 names
+= sizeof ("@plt");
2558 /* Add a symbol at the start of the glink branch table. */
2559 memset (s
, 0, sizeof *s
);
2561 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2563 s
->value
= glink_vma
- glink
->vma
;
2565 memcpy (names
, "__glink", sizeof ("__glink"));
2566 names
+= sizeof ("__glink");
2572 /* Add a symbol for the glink PLT resolver. */
2573 memset (s
, 0, sizeof *s
);
2575 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2577 s
->value
= resolv_vma
- glink
->vma
;
2579 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2580 names
+= sizeof ("__glink_PLTresolve");
2588 /* The following functions are specific to the ELF linker, while
2589 functions above are used generally. They appear in this file more
2590 or less in the order in which they are called. eg.
2591 ppc_elf_check_relocs is called early in the link process,
2592 ppc_elf_finish_dynamic_sections is one of the last functions
2595 /* The PPC linker needs to keep track of the number of relocs that it
2596 decides to copy as dynamic relocs in check_relocs for each symbol.
2597 This is so that it can later discard them if they are found to be
2598 unnecessary. We store the information in a field extending the
2599 regular ELF linker hash table. */
2601 struct ppc_elf_dyn_relocs
2603 struct ppc_elf_dyn_relocs
*next
;
2605 /* The input section of the reloc. */
2608 /* Total number of relocs copied for the input section. */
2609 bfd_size_type count
;
2611 /* Number of pc-relative relocs copied for the input section. */
2612 bfd_size_type pc_count
;
2615 /* Track PLT entries needed for a given symbol. We might need more
2616 than one glink entry per symbol when generating a pic binary. */
2619 struct plt_entry
*next
;
2621 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2622 This field stores the offset into .got2 used to initialise the
2623 GOT pointer reg. It will always be at least 32768. (Current
2624 gcc always uses an offset of 32768, but ld -r will pack .got2
2625 sections together resulting in larger offsets). */
2628 /* The .got2 section. */
2631 /* PLT refcount or offset. */
2634 bfd_signed_vma refcount
;
2638 /* .glink stub offset. */
2639 bfd_vma glink_offset
;
2642 /* Of those relocs that might be copied as dynamic relocs, this function
2643 selects those that must be copied when linking a shared library,
2644 even when the symbol is local. */
2647 must_be_dyn_reloc (struct bfd_link_info
*info
,
2648 enum elf_ppc_reloc_type r_type
)
2657 case R_PPC_REL14_BRTAKEN
:
2658 case R_PPC_REL14_BRNTAKEN
:
2664 case R_PPC_TPREL16_LO
:
2665 case R_PPC_TPREL16_HI
:
2666 case R_PPC_TPREL16_HA
:
2667 return !info
->executable
;
2671 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2672 copying dynamic variables from a shared lib into an app's dynbss
2673 section, and instead use a dynamic relocation to point into the
2675 #define ELIMINATE_COPY_RELOCS 1
2677 /* PPC ELF linker hash entry. */
2679 struct ppc_elf_link_hash_entry
2681 struct elf_link_hash_entry elf
;
2683 /* If this symbol is used in the linker created sections, the processor
2684 specific backend uses this field to map the field into the offset
2685 from the beginning of the section. */
2686 elf_linker_section_pointers_t
*linker_section_pointer
;
2688 /* Track dynamic relocs copied for this symbol. */
2689 struct ppc_elf_dyn_relocs
*dyn_relocs
;
2691 /* Contexts in which symbol is used in the GOT (or TOC).
2692 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2693 corresponding relocs are encountered during check_relocs.
2694 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2695 indicate the corresponding GOT entry type is not needed. */
2696 #define TLS_GD 1 /* GD reloc. */
2697 #define TLS_LD 2 /* LD reloc. */
2698 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2699 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2700 #define TLS_TLS 16 /* Any TLS reloc. */
2701 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
2702 #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
2705 /* Nonzero if we have seen a small data relocation referring to this
2707 unsigned char has_sda_refs
;
2710 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2712 /* PPC ELF linker hash table. */
2714 struct ppc_elf_link_hash_table
2716 struct elf_link_hash_table elf
;
2718 /* Short-cuts to get to dynamic linker sections. */
2730 elf_linker_section_t sdata
[2];
2733 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2736 /* The .got.plt section (VxWorks only)*/
2739 /* Shortcut to __tls_get_addr. */
2740 struct elf_link_hash_entry
*tls_get_addr
;
2742 /* The bfd that forced an old-style PLT. */
2745 /* TLS local dynamic got entry handling. */
2747 bfd_signed_vma refcount
;
2751 /* Offset of branch table to PltResolve function in glink. */
2752 bfd_vma glink_pltresolve
;
2754 /* Size of reserved GOT entries. */
2755 unsigned int got_header_size
;
2756 /* Non-zero if allocating the header left a gap. */
2757 unsigned int got_gap
;
2759 /* The type of PLT we have chosen to use. */
2760 enum ppc_elf_plt_type plt_type
;
2762 /* Set if we should emit symbols for stubs. */
2763 unsigned int emit_stub_syms
:1;
2765 /* Set if __tls_get_addr optimization should not be done. */
2766 unsigned int no_tls_get_addr_opt
:1;
2768 /* True if the target system is VxWorks. */
2769 unsigned int is_vxworks
:1;
2771 /* The size of PLT entries. */
2773 /* The distance between adjacent PLT slots. */
2775 /* The size of the first PLT entry. */
2776 int plt_initial_entry_size
;
2778 /* Small local sym cache. */
2779 struct sym_cache sym_cache
;
2782 /* Get the PPC ELF linker hash table from a link_info structure. */
2784 #define ppc_elf_hash_table(p) \
2785 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2786 == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
2788 /* Create an entry in a PPC ELF linker hash table. */
2790 static struct bfd_hash_entry
*
2791 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2792 struct bfd_hash_table
*table
,
2795 /* Allocate the structure if it has not already been allocated by a
2799 entry
= bfd_hash_allocate (table
,
2800 sizeof (struct ppc_elf_link_hash_entry
));
2805 /* Call the allocation method of the superclass. */
2806 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2809 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2810 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
2811 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2817 /* Create a PPC ELF linker hash table. */
2819 static struct bfd_link_hash_table
*
2820 ppc_elf_link_hash_table_create (bfd
*abfd
)
2822 struct ppc_elf_link_hash_table
*ret
;
2824 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2828 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2829 ppc_elf_link_hash_newfunc
,
2830 sizeof (struct ppc_elf_link_hash_entry
),
2837 ret
->elf
.init_plt_refcount
.refcount
= 0;
2838 ret
->elf
.init_plt_refcount
.glist
= NULL
;
2839 ret
->elf
.init_plt_offset
.offset
= 0;
2840 ret
->elf
.init_plt_offset
.glist
= NULL
;
2842 ret
->sdata
[0].name
= ".sdata";
2843 ret
->sdata
[0].sym_name
= "_SDA_BASE_";
2844 ret
->sdata
[0].bss_name
= ".sbss";
2846 ret
->sdata
[1].name
= ".sdata2";
2847 ret
->sdata
[1].sym_name
= "_SDA2_BASE_";
2848 ret
->sdata
[1].bss_name
= ".sbss2";
2850 ret
->plt_entry_size
= 12;
2851 ret
->plt_slot_size
= 8;
2852 ret
->plt_initial_entry_size
= 72;
2854 return &ret
->elf
.root
;
2857 /* Create .got and the related sections. */
2860 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2862 struct ppc_elf_link_hash_table
*htab
;
2866 if (!_bfd_elf_create_got_section (abfd
, info
))
2869 htab
= ppc_elf_hash_table (info
);
2870 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2874 if (htab
->is_vxworks
)
2876 htab
->sgotplt
= bfd_get_section_by_name (abfd
, ".got.plt");
2882 /* The powerpc .got has a blrl instruction in it. Mark it
2884 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
2885 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2886 if (!bfd_set_section_flags (abfd
, s
, flags
))
2890 htab
->relgot
= bfd_get_section_by_name (abfd
, ".rela.got");
2898 ppc_elf_create_glink (bfd
*abfd
, struct bfd_link_info
*info
)
2900 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2904 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
| SEC_HAS_CONTENTS
2905 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2906 s
= bfd_make_section_anyway_with_flags (abfd
, ".glink", flags
);
2909 || !bfd_set_section_alignment (abfd
, s
, 4))
2912 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
2913 s
= bfd_make_section_anyway_with_flags (abfd
, ".iplt", flags
);
2916 || !bfd_set_section_alignment (abfd
, s
, 4))
2919 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2920 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2921 s
= bfd_make_section_with_flags (abfd
, ".rela.iplt", flags
);
2924 || ! bfd_set_section_alignment (abfd
, s
, 2))
2929 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2930 to output sections (just like _bfd_elf_create_dynamic_sections has
2931 to create .dynbss and .rela.bss). */
2934 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2936 struct ppc_elf_link_hash_table
*htab
;
2940 htab
= ppc_elf_hash_table (info
);
2942 if (htab
->got
== NULL
2943 && !ppc_elf_create_got (abfd
, info
))
2946 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2949 if (htab
->glink
== NULL
2950 && !ppc_elf_create_glink (abfd
, info
))
2953 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2954 s
= bfd_make_section_with_flags (abfd
, ".dynsbss",
2955 SEC_ALLOC
| SEC_LINKER_CREATED
);
2962 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2963 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2964 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2965 s
= bfd_make_section_with_flags (abfd
, ".rela.sbss", flags
);
2968 || ! bfd_set_section_alignment (abfd
, s
, 2))
2972 if (htab
->is_vxworks
2973 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
2976 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2977 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2981 flags
= SEC_ALLOC
| SEC_CODE
| SEC_LINKER_CREATED
;
2982 if (htab
->plt_type
== PLT_VXWORKS
)
2983 /* The VxWorks PLT is a loaded section with contents. */
2984 flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_READONLY
;
2985 return bfd_set_section_flags (abfd
, s
, flags
);
2988 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2991 ppc_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2992 struct elf_link_hash_entry
*dir
,
2993 struct elf_link_hash_entry
*ind
)
2995 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2997 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2998 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
3000 if (eind
->dyn_relocs
!= NULL
)
3002 if (edir
->dyn_relocs
!= NULL
)
3004 struct ppc_elf_dyn_relocs
**pp
;
3005 struct ppc_elf_dyn_relocs
*p
;
3007 /* Add reloc counts against the indirect sym to the direct sym
3008 list. Merge any entries against the same section. */
3009 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3011 struct ppc_elf_dyn_relocs
*q
;
3013 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3014 if (q
->sec
== p
->sec
)
3016 q
->pc_count
+= p
->pc_count
;
3017 q
->count
+= p
->count
;
3024 *pp
= edir
->dyn_relocs
;
3027 edir
->dyn_relocs
= eind
->dyn_relocs
;
3028 eind
->dyn_relocs
= NULL
;
3031 edir
->tls_mask
|= eind
->tls_mask
;
3032 edir
->has_sda_refs
|= eind
->has_sda_refs
;
3034 /* If called to transfer flags for a weakdef during processing
3035 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3036 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3037 if (!(ELIMINATE_COPY_RELOCS
3038 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3039 && edir
->elf
.dynamic_adjusted
))
3040 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3042 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3043 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3044 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3045 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3046 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3048 /* If we were called to copy over info for a weak sym, that's all. */
3049 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3052 /* Copy over the GOT refcount entries that we may have already seen to
3053 the symbol which just became indirect. */
3054 edir
->elf
.got
.refcount
+= eind
->elf
.got
.refcount
;
3055 eind
->elf
.got
.refcount
= 0;
3057 /* And plt entries. */
3058 if (eind
->elf
.plt
.plist
!= NULL
)
3060 if (edir
->elf
.plt
.plist
!= NULL
)
3062 struct plt_entry
**entp
;
3063 struct plt_entry
*ent
;
3065 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3067 struct plt_entry
*dent
;
3069 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3070 if (dent
->sec
== ent
->sec
&& dent
->addend
== ent
->addend
)
3072 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3079 *entp
= edir
->elf
.plt
.plist
;
3082 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3083 eind
->elf
.plt
.plist
= NULL
;
3086 if (eind
->elf
.dynindx
!= -1)
3088 if (edir
->elf
.dynindx
!= -1)
3089 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3090 edir
->elf
.dynstr_index
);
3091 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3092 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3093 eind
->elf
.dynindx
= -1;
3094 eind
->elf
.dynstr_index
= 0;
3098 /* Hook called by the linker routine which adds symbols from an object
3099 file. We use it to put .comm items in .sbss, and not .bss. */
3102 ppc_elf_add_symbol_hook (bfd
*abfd
,
3103 struct bfd_link_info
*info
,
3104 Elf_Internal_Sym
*sym
,
3105 const char **namep ATTRIBUTE_UNUSED
,
3106 flagword
*flagsp ATTRIBUTE_UNUSED
,
3110 if (sym
->st_shndx
== SHN_COMMON
3111 && !info
->relocatable
3112 && is_ppc_elf (info
->output_bfd
)
3113 && sym
->st_size
<= elf_gp_size (abfd
))
3115 /* Common symbols less than or equal to -G nn bytes are automatically
3117 struct ppc_elf_link_hash_table
*htab
;
3119 htab
= ppc_elf_hash_table (info
);
3120 if (htab
->sbss
== NULL
)
3122 flagword flags
= SEC_IS_COMMON
| SEC_LINKER_CREATED
;
3124 if (!htab
->elf
.dynobj
)
3125 htab
->elf
.dynobj
= abfd
;
3127 htab
->sbss
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3130 if (htab
->sbss
== NULL
)
3135 *valp
= sym
->st_size
;
3138 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
3139 elf_tdata (info
->output_bfd
)->has_ifunc_symbols
= TRUE
;
3145 create_sdata_sym (struct bfd_link_info
*info
, elf_linker_section_t
*lsect
)
3147 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
3149 lsect
->sym
= elf_link_hash_lookup (&htab
->elf
, lsect
->sym_name
,
3151 if (lsect
->sym
== NULL
)
3153 if (lsect
->sym
->root
.type
== bfd_link_hash_new
)
3154 lsect
->sym
->non_elf
= 0;
3155 lsect
->sym
->ref_regular
= 1;
3156 _bfd_elf_link_hash_hide_symbol (info
, lsect
->sym
, TRUE
);
3160 /* Create a special linker section. */
3163 ppc_elf_create_linker_section (bfd
*abfd
,
3164 struct bfd_link_info
*info
,
3166 elf_linker_section_t
*lsect
)
3168 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
3171 flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3172 | SEC_LINKER_CREATED
);
3174 /* Record the first bfd that needs the special sections. */
3175 if (!htab
->elf
.dynobj
)
3176 htab
->elf
.dynobj
= abfd
;
3178 s
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
3182 || !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
3186 return create_sdata_sym (info
, lsect
);
3189 /* Find a linker generated pointer with a given addend and type. */
3191 static elf_linker_section_pointers_t
*
3192 elf_find_pointer_linker_section
3193 (elf_linker_section_pointers_t
*linker_pointers
,
3195 elf_linker_section_t
*lsect
)
3197 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
3198 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
3199 return linker_pointers
;
3204 /* Allocate a pointer to live in a linker created section. */
3207 elf_create_pointer_linker_section (bfd
*abfd
,
3208 elf_linker_section_t
*lsect
,
3209 struct elf_link_hash_entry
*h
,
3210 const Elf_Internal_Rela
*rel
)
3212 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
3213 elf_linker_section_pointers_t
*linker_section_ptr
;
3214 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
3217 BFD_ASSERT (lsect
!= NULL
);
3219 /* Is this a global symbol? */
3222 struct ppc_elf_link_hash_entry
*eh
;
3224 /* Has this symbol already been allocated? If so, our work is done. */
3225 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3226 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
3231 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
3235 BFD_ASSERT (is_ppc_elf (abfd
));
3237 /* Allocation of a pointer to a local symbol. */
3238 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
3240 /* Allocate a table to hold the local symbols if first time. */
3243 unsigned int num_symbols
= elf_symtab_hdr (abfd
).sh_info
;
3246 amt
*= sizeof (elf_linker_section_pointers_t
*);
3247 ptr
= bfd_zalloc (abfd
, amt
);
3252 elf_local_ptr_offsets (abfd
) = ptr
;
3255 /* Has this symbol already been allocated? If so, our work is done. */
3256 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
3261 ptr_linker_section_ptr
= &ptr
[r_symndx
];
3264 /* Allocate space for a pointer in the linker section, and allocate
3265 a new pointer record from internal memory. */
3266 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
3267 amt
= sizeof (elf_linker_section_pointers_t
);
3268 linker_section_ptr
= bfd_alloc (abfd
, amt
);
3270 if (!linker_section_ptr
)
3273 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
3274 linker_section_ptr
->addend
= rel
->r_addend
;
3275 linker_section_ptr
->lsect
= lsect
;
3276 *ptr_linker_section_ptr
= linker_section_ptr
;
3278 linker_section_ptr
->offset
= lsect
->section
->size
;
3279 lsect
->section
->size
+= 4;
3283 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
3284 lsect
->name
, (long) linker_section_ptr
->offset
,
3285 (long) lsect
->section
->size
);
3291 static struct plt_entry
**
3292 update_local_sym_info (bfd
*abfd
,
3293 Elf_Internal_Shdr
*symtab_hdr
,
3294 unsigned long r_symndx
,
3297 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3298 struct plt_entry
**local_plt
;
3299 char *local_got_tls_masks
;
3301 if (local_got_refcounts
== NULL
)
3303 bfd_size_type size
= symtab_hdr
->sh_info
;
3305 size
*= (sizeof (*local_got_refcounts
)
3306 + sizeof (*local_plt
)
3307 + sizeof (*local_got_tls_masks
));
3308 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3309 if (local_got_refcounts
== NULL
)
3311 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3314 local_plt
= (struct plt_entry
**) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3315 local_got_tls_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
3316 local_got_tls_masks
[r_symndx
] |= tls_type
;
3317 if (tls_type
!= PLT_IFUNC
)
3318 local_got_refcounts
[r_symndx
] += 1;
3319 return local_plt
+ r_symndx
;
3323 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
,
3324 asection
*sec
, bfd_vma addend
)
3326 struct plt_entry
*ent
;
3330 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3331 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3335 bfd_size_type amt
= sizeof (*ent
);
3336 ent
= bfd_alloc (abfd
, amt
);
3341 ent
->addend
= addend
;
3342 ent
->plt
.refcount
= 0;
3345 ent
->plt
.refcount
+= 1;
3349 static struct plt_entry
*
3350 find_plt_ent (struct plt_entry
**plist
, asection
*sec
, bfd_vma addend
)
3352 struct plt_entry
*ent
;
3356 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
3357 if (ent
->sec
== sec
&& ent
->addend
== addend
)
3363 is_branch_reloc (enum elf_ppc_reloc_type r_type
)
3365 return (r_type
== R_PPC_PLTREL24
3366 || r_type
== R_PPC_LOCAL24PC
3367 || r_type
== R_PPC_REL24
3368 || r_type
== R_PPC_REL14
3369 || r_type
== R_PPC_REL14_BRTAKEN
3370 || r_type
== R_PPC_REL14_BRNTAKEN
3371 || r_type
== R_PPC_ADDR24
3372 || r_type
== R_PPC_ADDR14
3373 || r_type
== R_PPC_ADDR14_BRTAKEN
3374 || r_type
== R_PPC_ADDR14_BRNTAKEN
);
3378 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3380 (*_bfd_error_handler
)
3381 (_("%B: relocation %s cannot be used when making a shared object"),
3383 ppc_elf_howto_table
[r_type
]->name
);
3384 bfd_set_error (bfd_error_bad_value
);
3387 /* Look through the relocs for a section during the first phase, and
3388 allocate space in the global offset table or procedure linkage
3392 ppc_elf_check_relocs (bfd
*abfd
,
3393 struct bfd_link_info
*info
,
3395 const Elf_Internal_Rela
*relocs
)
3397 struct ppc_elf_link_hash_table
*htab
;
3398 Elf_Internal_Shdr
*symtab_hdr
;
3399 struct elf_link_hash_entry
**sym_hashes
;
3400 const Elf_Internal_Rela
*rel
;
3401 const Elf_Internal_Rela
*rel_end
;
3402 asection
*got2
, *sreloc
;
3403 struct elf_link_hash_entry
*tga
;
3405 if (info
->relocatable
)
3408 /* Don't do anything special with non-loaded, non-alloced sections.
3409 In particular, any relocs in such sections should not affect GOT
3410 and PLT reference counting (ie. we don't allow them to create GOT
3411 or PLT entries), there's no possibility or desire to optimize TLS
3412 relocs, and there's not much point in propagating relocs to shared
3413 libs that the dynamic linker won't relocate. */
3414 if ((sec
->flags
& SEC_ALLOC
) == 0)
3418 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3422 BFD_ASSERT (is_ppc_elf (abfd
));
3424 /* Initialize howto table if not already done. */
3425 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3426 ppc_elf_howto_init ();
3428 htab
= ppc_elf_hash_table (info
);
3429 if (htab
->glink
== NULL
)
3431 if (htab
->elf
.dynobj
== NULL
)
3432 htab
->elf
.dynobj
= abfd
;
3433 if (!ppc_elf_create_glink (htab
->elf
.dynobj
, info
))
3436 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3437 FALSE
, FALSE
, TRUE
);
3438 symtab_hdr
= &elf_symtab_hdr (abfd
);
3439 sym_hashes
= elf_sym_hashes (abfd
);
3440 got2
= bfd_get_section_by_name (abfd
, ".got2");
3443 rel_end
= relocs
+ sec
->reloc_count
;
3444 for (rel
= relocs
; rel
< rel_end
; rel
++)
3446 unsigned long r_symndx
;
3447 enum elf_ppc_reloc_type r_type
;
3448 struct elf_link_hash_entry
*h
;
3450 struct plt_entry
**ifunc
;
3452 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3453 if (r_symndx
< symtab_hdr
->sh_info
)
3457 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3458 while (h
->root
.type
== bfd_link_hash_indirect
3459 || h
->root
.type
== bfd_link_hash_warning
)
3460 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3463 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3464 This shows up in particular in an R_PPC_ADDR32 in the eabi
3467 && htab
->got
== NULL
3468 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3470 if (htab
->elf
.dynobj
== NULL
)
3471 htab
->elf
.dynobj
= abfd
;
3472 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3474 BFD_ASSERT (h
== htab
->elf
.hgot
);
3479 r_type
= ELF32_R_TYPE (rel
->r_info
);
3480 if (!htab
->is_vxworks
)
3484 if (h
->type
== STT_GNU_IFUNC
)
3485 ifunc
= &h
->plt
.plist
;
3489 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3494 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
3496 || is_branch_reloc (r_type
)))
3500 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3505 /* STT_GNU_IFUNC symbols must have a PLT entry;
3506 In a non-pie executable even when there are
3509 if (r_type
== R_PPC_PLTREL24
)
3511 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3513 addend
= rel
->r_addend
;
3515 if (!update_plt_info (abfd
, ifunc
, got2
, addend
))
3521 if (!htab
->is_vxworks
3522 && is_branch_reloc (r_type
)
3527 && (ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSGD
3528 || ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSLD
))
3529 /* We have a new-style __tls_get_addr call with a marker
3533 /* Mark this section as having an old-style call. */
3534 sec
->has_tls_get_addr_call
= 1;
3541 /* These special tls relocs tie a call to __tls_get_addr with
3542 its parameter symbol. */
3545 case R_PPC_GOT_TLSLD16
:
3546 case R_PPC_GOT_TLSLD16_LO
:
3547 case R_PPC_GOT_TLSLD16_HI
:
3548 case R_PPC_GOT_TLSLD16_HA
:
3549 tls_type
= TLS_TLS
| TLS_LD
;
3552 case R_PPC_GOT_TLSGD16
:
3553 case R_PPC_GOT_TLSGD16_LO
:
3554 case R_PPC_GOT_TLSGD16_HI
:
3555 case R_PPC_GOT_TLSGD16_HA
:
3556 tls_type
= TLS_TLS
| TLS_GD
;
3559 case R_PPC_GOT_TPREL16
:
3560 case R_PPC_GOT_TPREL16_LO
:
3561 case R_PPC_GOT_TPREL16_HI
:
3562 case R_PPC_GOT_TPREL16_HA
:
3563 if (!info
->executable
)
3564 info
->flags
|= DF_STATIC_TLS
;
3565 tls_type
= TLS_TLS
| TLS_TPREL
;
3568 case R_PPC_GOT_DTPREL16
:
3569 case R_PPC_GOT_DTPREL16_LO
:
3570 case R_PPC_GOT_DTPREL16_HI
:
3571 case R_PPC_GOT_DTPREL16_HA
:
3572 tls_type
= TLS_TLS
| TLS_DTPREL
;
3574 sec
->has_tls_reloc
= 1;
3577 /* GOT16 relocations */
3579 case R_PPC_GOT16_LO
:
3580 case R_PPC_GOT16_HI
:
3581 case R_PPC_GOT16_HA
:
3582 /* This symbol requires a global offset table entry. */
3583 if (htab
->got
== NULL
)
3585 if (htab
->elf
.dynobj
== NULL
)
3586 htab
->elf
.dynobj
= abfd
;
3587 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3592 h
->got
.refcount
+= 1;
3593 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3596 /* This is a global offset table entry for a local symbol. */
3597 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3600 /* We may also need a plt entry if the symbol turns out to be
3602 if (h
!= NULL
&& !info
->shared
)
3604 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3609 /* Indirect .sdata relocation. */
3610 case R_PPC_EMB_SDAI16
:
3613 bad_shared_reloc (abfd
, r_type
);
3616 if (htab
->sdata
[0].section
== NULL
3617 && !ppc_elf_create_linker_section (abfd
, info
, 0,
3620 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[0],
3625 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3626 h
->non_got_ref
= TRUE
;
3630 /* Indirect .sdata2 relocation. */
3631 case R_PPC_EMB_SDA2I16
:
3634 bad_shared_reloc (abfd
, r_type
);
3637 if (htab
->sdata
[1].section
== NULL
3638 && !ppc_elf_create_linker_section (abfd
, info
, SEC_READONLY
,
3641 if (!elf_create_pointer_linker_section (abfd
, &htab
->sdata
[1],
3646 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3647 h
->non_got_ref
= TRUE
;
3651 case R_PPC_SDAREL16
:
3652 if (htab
->sdata
[0].sym
== NULL
3653 && !create_sdata_sym (info
, &htab
->sdata
[0]))
3657 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3658 h
->non_got_ref
= TRUE
;
3662 case R_PPC_EMB_SDA2REL
:
3665 bad_shared_reloc (abfd
, r_type
);
3668 if (htab
->sdata
[1].sym
== NULL
3669 && !create_sdata_sym (info
, &htab
->sdata
[1]))
3673 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3674 h
->non_got_ref
= TRUE
;
3678 case R_PPC_EMB_SDA21
:
3679 case R_PPC_EMB_RELSDA
:
3682 bad_shared_reloc (abfd
, r_type
);
3685 if (htab
->sdata
[0].sym
== NULL
3686 && !create_sdata_sym (info
, &htab
->sdata
[0]))
3688 if (htab
->sdata
[1].sym
== NULL
3689 && !create_sdata_sym (info
, &htab
->sdata
[1]))
3693 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3694 h
->non_got_ref
= TRUE
;
3698 case R_PPC_EMB_NADDR32
:
3699 case R_PPC_EMB_NADDR16
:
3700 case R_PPC_EMB_NADDR16_LO
:
3701 case R_PPC_EMB_NADDR16_HI
:
3702 case R_PPC_EMB_NADDR16_HA
:
3705 bad_shared_reloc (abfd
, r_type
);
3709 h
->non_got_ref
= TRUE
;
3712 case R_PPC_PLTREL24
:
3717 case R_PPC_PLTREL32
:
3718 case R_PPC_PLT16_LO
:
3719 case R_PPC_PLT16_HI
:
3720 case R_PPC_PLT16_HA
:
3722 fprintf (stderr
, "Reloc requires a PLT entry\n");
3724 /* This symbol requires a procedure linkage table entry. We
3725 actually build the entry in finish_dynamic_symbol,
3726 because this might be a case of linking PIC code without
3727 linking in any dynamic objects, in which case we don't
3728 need to generate a procedure linkage table after all. */
3732 /* It does not make sense to have a procedure linkage
3733 table entry for a local symbol. */
3734 (*_bfd_error_handler
) (_("%B(%A+0x%lx): %s reloc against "
3738 (long) rel
->r_offset
,
3739 ppc_elf_howto_table
[r_type
]->name
);
3740 bfd_set_error (bfd_error_bad_value
);
3747 if (r_type
== R_PPC_PLTREL24
)
3749 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3751 addend
= rel
->r_addend
;
3754 if (!update_plt_info (abfd
, &h
->plt
.plist
, got2
, addend
))
3759 /* The following relocations don't need to propagate the
3760 relocation if linking a shared object since they are
3761 section relative. */
3763 case R_PPC_SECTOFF_LO
:
3764 case R_PPC_SECTOFF_HI
:
3765 case R_PPC_SECTOFF_HA
:
3766 case R_PPC_DTPREL16
:
3767 case R_PPC_DTPREL16_LO
:
3768 case R_PPC_DTPREL16_HI
:
3769 case R_PPC_DTPREL16_HA
:
3774 case R_PPC_REL16_LO
:
3775 case R_PPC_REL16_HI
:
3776 case R_PPC_REL16_HA
:
3777 ppc_elf_tdata (abfd
)->has_rel16
= 1;
3780 /* These are just markers. */
3782 case R_PPC_EMB_MRKREF
:
3786 case R_PPC_RELAX_PLT
:
3787 case R_PPC_RELAX_PLTREL24
:
3790 /* These should only appear in dynamic objects. */
3792 case R_PPC_GLOB_DAT
:
3793 case R_PPC_JMP_SLOT
:
3794 case R_PPC_RELATIVE
:
3795 case R_PPC_IRELATIVE
:
3798 /* These aren't handled yet. We'll report an error later. */
3800 case R_PPC_EMB_RELSEC16
:
3801 case R_PPC_EMB_RELST_LO
:
3802 case R_PPC_EMB_RELST_HI
:
3803 case R_PPC_EMB_RELST_HA
:
3804 case R_PPC_EMB_BIT_FLD
:
3807 /* This refers only to functions defined in the shared library. */
3808 case R_PPC_LOCAL24PC
:
3809 if (h
!= NULL
&& h
== htab
->elf
.hgot
&& htab
->plt_type
== PLT_UNSET
)
3811 htab
->plt_type
= PLT_OLD
;
3812 htab
->old_bfd
= abfd
;
3816 /* This relocation describes the C++ object vtable hierarchy.
3817 Reconstruct it for later use during GC. */
3818 case R_PPC_GNU_VTINHERIT
:
3819 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3823 /* This relocation describes which C++ vtable entries are actually
3824 used. Record for later use during GC. */
3825 case R_PPC_GNU_VTENTRY
:
3826 BFD_ASSERT (h
!= NULL
);
3828 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3832 /* We shouldn't really be seeing these. */
3835 case R_PPC_TPREL16_LO
:
3836 case R_PPC_TPREL16_HI
:
3837 case R_PPC_TPREL16_HA
:
3838 if (!info
->executable
)
3839 info
->flags
|= DF_STATIC_TLS
;
3843 case R_PPC_DTPMOD32
:
3844 case R_PPC_DTPREL32
:
3850 && (sec
->flags
& SEC_CODE
) != 0
3852 && htab
->plt_type
== PLT_UNSET
)
3854 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3855 the start of a function, which assembles to a REL32
3856 reference to .got2. If we detect one of these, then
3857 force the old PLT layout because the linker cannot
3858 reliably deduce the GOT pointer value needed for
3861 Elf_Internal_Sym
*isym
;
3863 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
3868 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3871 htab
->plt_type
= PLT_OLD
;
3872 htab
->old_bfd
= abfd
;
3875 if (h
== NULL
|| h
== htab
->elf
.hgot
)
3881 case R_PPC_ADDR16_LO
:
3882 case R_PPC_ADDR16_HI
:
3883 case R_PPC_ADDR16_HA
:
3886 if (h
!= NULL
&& !info
->shared
)
3888 /* We may need a plt entry if the symbol turns out to be
3889 a function defined in a dynamic object. */
3890 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3893 /* We may need a copy reloc too. */
3895 h
->pointer_equality_needed
= 1;
3901 case R_PPC_REL14_BRTAKEN
:
3902 case R_PPC_REL14_BRNTAKEN
:
3905 if (h
== htab
->elf
.hgot
)
3907 if (htab
->plt_type
== PLT_UNSET
)
3909 htab
->plt_type
= PLT_OLD
;
3910 htab
->old_bfd
= abfd
;
3918 case R_PPC_ADDR14_BRTAKEN
:
3919 case R_PPC_ADDR14_BRNTAKEN
:
3920 if (h
!= NULL
&& !info
->shared
)
3922 /* We may need a plt entry if the symbol turns out to be
3923 a function defined in a dynamic object. */
3925 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3931 /* If we are creating a shared library, and this is a reloc
3932 against a global symbol, or a non PC relative reloc
3933 against a local symbol, then we need to copy the reloc
3934 into the shared library. However, if we are linking with
3935 -Bsymbolic, we do not need to copy a reloc against a
3936 global symbol which is defined in an object we are
3937 including in the link (i.e., DEF_REGULAR is set). At
3938 this point we have not seen all the input files, so it is
3939 possible that DEF_REGULAR is not set now but will be set
3940 later (it is never cleared). In case of a weak definition,
3941 DEF_REGULAR may be cleared later by a strong definition in
3942 a shared library. We account for that possibility below by
3943 storing information in the dyn_relocs field of the hash
3944 table entry. A similar situation occurs when creating
3945 shared libraries and symbol visibility changes render the
3948 If on the other hand, we are creating an executable, we
3949 may need to keep relocations for symbols satisfied by a
3950 dynamic library if we manage to avoid copy relocs for the
3953 && (must_be_dyn_reloc (info
, r_type
)
3955 && (! info
->symbolic
3956 || h
->root
.type
== bfd_link_hash_defweak
3957 || !h
->def_regular
))))
3958 || (ELIMINATE_COPY_RELOCS
3961 && (h
->root
.type
== bfd_link_hash_defweak
3962 || !h
->def_regular
)))
3964 struct ppc_elf_dyn_relocs
*p
;
3965 struct ppc_elf_dyn_relocs
**rel_head
;
3969 "ppc_elf_check_relocs needs to "
3970 "create relocation for %s\n",
3971 (h
&& h
->root
.root
.string
3972 ? h
->root
.root
.string
: "<unknown>"));
3976 if (htab
->elf
.dynobj
== NULL
)
3977 htab
->elf
.dynobj
= abfd
;
3979 sreloc
= _bfd_elf_make_dynamic_reloc_section
3980 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3986 /* If this is a global symbol, we count the number of
3987 relocations we need for this symbol. */
3990 rel_head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3994 /* Track dynamic relocs needed for local syms too.
3995 We really need local syms available to do this
3999 Elf_Internal_Sym
*isym
;
4001 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4006 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4010 vpp
= &elf_section_data (s
)->local_dynrel
;
4011 rel_head
= (struct ppc_elf_dyn_relocs
**) vpp
;
4015 if (p
== NULL
|| p
->sec
!= sec
)
4017 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4020 p
->next
= *rel_head
;
4028 if (!must_be_dyn_reloc (info
, r_type
))
4040 /* Merge object attributes from IBFD into OBFD. Raise an error if
4041 there are conflicting attributes. */
4043 ppc_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
4045 obj_attribute
*in_attr
, *in_attrs
;
4046 obj_attribute
*out_attr
, *out_attrs
;
4048 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
4050 /* This is the first object. Copy the attributes. */
4051 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
4053 /* Use the Tag_null value to indicate the attributes have been
4055 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
4060 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
4061 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
4063 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
4064 non-conflicting ones. */
4065 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_FP
];
4066 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_FP
];
4067 if (in_attr
->i
!= out_attr
->i
)
4070 if (out_attr
->i
== 0)
4071 out_attr
->i
= in_attr
->i
;
4072 else if (in_attr
->i
== 0)
4074 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4076 (_("Warning: %B uses hard float, %B uses soft float"), obfd
, ibfd
);
4077 else if (out_attr
->i
== 1 && in_attr
->i
== 3)
4079 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4081 else if (out_attr
->i
== 3 && in_attr
->i
== 1)
4083 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
4085 else if (out_attr
->i
== 3 && in_attr
->i
== 2)
4087 (_("Warning: %B uses soft float, %B uses single-precision hard float"),
4089 else if (out_attr
->i
== 2 && (in_attr
->i
== 1 || in_attr
->i
== 3))
4091 (_("Warning: %B uses hard float, %B uses soft float"), ibfd
, obfd
);
4092 else if (in_attr
->i
> 3)
4094 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
4098 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
4102 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
4103 merge non-conflicting ones. */
4104 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Vector
];
4105 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Vector
];
4106 if (in_attr
->i
!= out_attr
->i
)
4108 const char *in_abi
= NULL
, *out_abi
= NULL
;
4112 case 1: in_abi
= "generic"; break;
4113 case 2: in_abi
= "AltiVec"; break;
4114 case 3: in_abi
= "SPE"; break;
4117 switch (out_attr
->i
)
4119 case 1: out_abi
= "generic"; break;
4120 case 2: out_abi
= "AltiVec"; break;
4121 case 3: out_abi
= "SPE"; break;
4125 if (out_attr
->i
== 0)
4126 out_attr
->i
= in_attr
->i
;
4127 else if (in_attr
->i
== 0)
4129 /* For now, allow generic to transition to AltiVec or SPE
4130 without a warning. If GCC marked files with their stack
4131 alignment and used don't-care markings for files which are
4132 not affected by the vector ABI, we could warn about this
4134 else if (out_attr
->i
== 1)
4135 out_attr
->i
= in_attr
->i
;
4136 else if (in_attr
->i
== 1)
4138 else if (in_abi
== NULL
)
4140 (_("Warning: %B uses unknown vector ABI %d"), ibfd
,
4142 else if (out_abi
== NULL
)
4144 (_("Warning: %B uses unknown vector ABI %d"), obfd
,
4148 (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
4149 ibfd
, obfd
, in_abi
, out_abi
);
4152 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
4153 and merge non-conflicting ones. */
4154 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4155 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
4156 if (in_attr
->i
!= out_attr
->i
)
4159 if (out_attr
->i
== 0)
4160 out_attr
->i
= in_attr
->i
;
4161 else if (in_attr
->i
== 0)
4163 else if (out_attr
->i
== 1 && in_attr
->i
== 2)
4165 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd
, ibfd
);
4166 else if (out_attr
->i
== 2 && in_attr
->i
== 1)
4168 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd
, obfd
);
4169 else if (in_attr
->i
> 2)
4171 (_("Warning: %B uses unknown small structure return convention %d"), ibfd
,
4175 (_("Warning: %B uses unknown small structure return convention %d"), obfd
,
4179 /* Merge Tag_compatibility attributes and any common GNU ones. */
4180 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
4185 /* Merge backend specific data from an object file to the output
4186 object file when linking. */
4189 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4195 if (!is_ppc_elf (ibfd
) || !is_ppc_elf (obfd
))
4198 /* Check if we have the same endianess. */
4199 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
4202 if (!ppc_elf_merge_obj_attributes (ibfd
, obfd
))
4205 new_flags
= elf_elfheader (ibfd
)->e_flags
;
4206 old_flags
= elf_elfheader (obfd
)->e_flags
;
4207 if (!elf_flags_init (obfd
))
4209 /* First call, no flags set. */
4210 elf_flags_init (obfd
) = TRUE
;
4211 elf_elfheader (obfd
)->e_flags
= new_flags
;
4214 /* Compatible flags are ok. */
4215 else if (new_flags
== old_flags
)
4218 /* Incompatible flags. */
4221 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
4222 to be linked with either. */
4224 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
4225 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
4228 (*_bfd_error_handler
)
4229 (_("%B: compiled with -mrelocatable and linked with "
4230 "modules compiled normally"), ibfd
);
4232 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
4233 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
4236 (*_bfd_error_handler
)
4237 (_("%B: compiled normally and linked with "
4238 "modules compiled with -mrelocatable"), ibfd
);
4241 /* The output is -mrelocatable-lib iff both the input files are. */
4242 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
4243 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
4245 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
4246 but each input file is either -mrelocatable or -mrelocatable-lib. */
4247 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
4248 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
4249 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
4250 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
4252 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
4253 any module uses it. */
4254 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
4256 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4257 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
4259 /* Warn about any other mismatches. */
4260 if (new_flags
!= old_flags
)
4263 (*_bfd_error_handler
)
4264 (_("%B: uses different e_flags (0x%lx) fields "
4265 "than previous modules (0x%lx)"),
4266 ibfd
, (long) new_flags
, (long) old_flags
);
4271 bfd_set_error (bfd_error_bad_value
);
4279 /* Choose which PLT scheme to use, and set .plt flags appropriately.
4280 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
4282 ppc_elf_select_plt_layout (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4283 struct bfd_link_info
*info
,
4284 enum ppc_elf_plt_type plt_style
,
4287 struct ppc_elf_link_hash_table
*htab
;
4290 htab
= ppc_elf_hash_table (info
);
4292 htab
->emit_stub_syms
= emit_stub_syms
;
4294 if (htab
->plt_type
== PLT_UNSET
)
4296 if (plt_style
== PLT_OLD
)
4297 htab
->plt_type
= PLT_OLD
;
4301 enum ppc_elf_plt_type plt_type
= plt_style
;
4303 /* Look through the reloc flags left by ppc_elf_check_relocs.
4304 Use the old style bss plt if a file makes plt calls
4305 without using the new relocs, and if ld isn't given
4306 --secure-plt and we never see REL16 relocs. */
4307 if (plt_type
== PLT_UNSET
)
4309 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
4310 if (is_ppc_elf (ibfd
))
4312 if (ppc_elf_tdata (ibfd
)->has_rel16
)
4314 else if (ppc_elf_tdata (ibfd
)->makes_plt_call
)
4317 htab
->old_bfd
= ibfd
;
4321 htab
->plt_type
= plt_type
;
4324 if (htab
->plt_type
== PLT_OLD
&& plt_style
== PLT_NEW
)
4325 info
->callbacks
->info (_("Using bss-plt due to %B"), htab
->old_bfd
);
4327 BFD_ASSERT (htab
->plt_type
!= PLT_VXWORKS
);
4329 if (htab
->plt_type
== PLT_NEW
)
4331 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4332 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4334 /* The new PLT is a loaded section. */
4335 if (htab
->plt
!= NULL
4336 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->plt
, flags
))
4339 /* The new GOT is not executable. */
4340 if (htab
->got
!= NULL
4341 && !bfd_set_section_flags (htab
->elf
.dynobj
, htab
->got
, flags
))
4346 /* Stop an unused .glink section from affecting .text alignment. */
4347 if (htab
->glink
!= NULL
4348 && !bfd_set_section_alignment (htab
->elf
.dynobj
, htab
->glink
, 0))
4351 return htab
->plt_type
== PLT_NEW
;
4354 /* Return the section that should be marked against GC for a given
4358 ppc_elf_gc_mark_hook (asection
*sec
,
4359 struct bfd_link_info
*info
,
4360 Elf_Internal_Rela
*rel
,
4361 struct elf_link_hash_entry
*h
,
4362 Elf_Internal_Sym
*sym
)
4365 switch (ELF32_R_TYPE (rel
->r_info
))
4367 case R_PPC_GNU_VTINHERIT
:
4368 case R_PPC_GNU_VTENTRY
:
4372 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4375 /* Update the got, plt and dynamic reloc reference counts for the
4376 section being removed. */
4379 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4380 struct bfd_link_info
*info
,
4382 const Elf_Internal_Rela
*relocs
)
4384 struct ppc_elf_link_hash_table
*htab
;
4385 Elf_Internal_Shdr
*symtab_hdr
;
4386 struct elf_link_hash_entry
**sym_hashes
;
4387 bfd_signed_vma
*local_got_refcounts
;
4388 const Elf_Internal_Rela
*rel
, *relend
;
4391 if (info
->relocatable
)
4394 if ((sec
->flags
& SEC_ALLOC
) == 0)
4397 elf_section_data (sec
)->local_dynrel
= NULL
;
4399 htab
= ppc_elf_hash_table (info
);
4400 symtab_hdr
= &elf_symtab_hdr (abfd
);
4401 sym_hashes
= elf_sym_hashes (abfd
);
4402 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4403 got2
= bfd_get_section_by_name (abfd
, ".got2");
4405 relend
= relocs
+ sec
->reloc_count
;
4406 for (rel
= relocs
; rel
< relend
; rel
++)
4408 unsigned long r_symndx
;
4409 enum elf_ppc_reloc_type r_type
;
4410 struct elf_link_hash_entry
*h
= NULL
;
4412 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4413 if (r_symndx
>= symtab_hdr
->sh_info
)
4415 struct ppc_elf_dyn_relocs
**pp
, *p
;
4416 struct ppc_elf_link_hash_entry
*eh
;
4418 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4419 while (h
->root
.type
== bfd_link_hash_indirect
4420 || h
->root
.type
== bfd_link_hash_warning
)
4421 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4422 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4424 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4427 /* Everything must go for SEC. */
4433 r_type
= ELF32_R_TYPE (rel
->r_info
);
4434 if (!htab
->is_vxworks
4436 && local_got_refcounts
!= NULL
4438 || is_branch_reloc (r_type
)))
4440 struct plt_entry
**local_plt
= (struct plt_entry
**)
4441 (local_got_refcounts
+ symtab_hdr
->sh_info
);
4442 char *local_got_tls_masks
= (char *)
4443 (local_plt
+ symtab_hdr
->sh_info
);
4444 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
4446 struct plt_entry
**ifunc
= local_plt
+ r_symndx
;
4448 struct plt_entry
*ent
;
4450 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
4451 addend
= rel
->r_addend
;
4452 ent
= find_plt_ent (ifunc
, got2
, addend
);
4453 if (ent
->plt
.refcount
> 0)
4454 ent
->plt
.refcount
-= 1;
4461 case R_PPC_GOT_TLSLD16
:
4462 case R_PPC_GOT_TLSLD16_LO
:
4463 case R_PPC_GOT_TLSLD16_HI
:
4464 case R_PPC_GOT_TLSLD16_HA
:
4465 case R_PPC_GOT_TLSGD16
:
4466 case R_PPC_GOT_TLSGD16_LO
:
4467 case R_PPC_GOT_TLSGD16_HI
:
4468 case R_PPC_GOT_TLSGD16_HA
:
4469 case R_PPC_GOT_TPREL16
:
4470 case R_PPC_GOT_TPREL16_LO
:
4471 case R_PPC_GOT_TPREL16_HI
:
4472 case R_PPC_GOT_TPREL16_HA
:
4473 case R_PPC_GOT_DTPREL16
:
4474 case R_PPC_GOT_DTPREL16_LO
:
4475 case R_PPC_GOT_DTPREL16_HI
:
4476 case R_PPC_GOT_DTPREL16_HA
:
4478 case R_PPC_GOT16_LO
:
4479 case R_PPC_GOT16_HI
:
4480 case R_PPC_GOT16_HA
:
4483 if (h
->got
.refcount
> 0)
4487 struct plt_entry
*ent
;
4489 ent
= find_plt_ent (&h
->plt
.plist
, NULL
, 0);
4490 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4491 ent
->plt
.refcount
-= 1;
4494 else if (local_got_refcounts
!= NULL
)
4496 if (local_got_refcounts
[r_symndx
] > 0)
4497 local_got_refcounts
[r_symndx
]--;
4503 case R_PPC_REL14_BRTAKEN
:
4504 case R_PPC_REL14_BRNTAKEN
:
4506 if (h
== NULL
|| h
== htab
->elf
.hgot
)
4513 case R_PPC_ADDR16_LO
:
4514 case R_PPC_ADDR16_HI
:
4515 case R_PPC_ADDR16_HA
:
4517 case R_PPC_ADDR14_BRTAKEN
:
4518 case R_PPC_ADDR14_BRNTAKEN
:
4525 case R_PPC_PLTREL24
:
4526 case R_PPC_PLTREL32
:
4527 case R_PPC_PLT16_LO
:
4528 case R_PPC_PLT16_HI
:
4529 case R_PPC_PLT16_HA
:
4533 struct plt_entry
*ent
;
4535 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
4536 addend
= rel
->r_addend
;
4537 ent
= find_plt_ent (&h
->plt
.plist
, got2
, addend
);
4538 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4539 ent
->plt
.refcount
-= 1;
4550 /* Set plt output section type, htab->tls_get_addr, and call the
4551 generic ELF tls_setup function. */
4554 ppc_elf_tls_setup (bfd
*obfd
,
4555 struct bfd_link_info
*info
,
4556 int no_tls_get_addr_opt
)
4558 struct ppc_elf_link_hash_table
*htab
;
4560 htab
= ppc_elf_hash_table (info
);
4561 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4562 FALSE
, FALSE
, TRUE
);
4563 if (!no_tls_get_addr_opt
)
4565 struct elf_link_hash_entry
*opt
, *tga
;
4566 opt
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
4567 FALSE
, FALSE
, TRUE
);
4569 && (opt
->root
.type
== bfd_link_hash_defined
4570 || opt
->root
.type
== bfd_link_hash_defweak
))
4572 /* If glibc supports an optimized __tls_get_addr call stub,
4573 signalled by the presence of __tls_get_addr_opt, and we'll
4574 be calling __tls_get_addr via a plt call stub, then
4575 make __tls_get_addr point to __tls_get_addr_opt. */
4576 tga
= htab
->tls_get_addr
;
4577 if (htab
->elf
.dynamic_sections_created
4579 && (tga
->type
== STT_FUNC
4581 && !(SYMBOL_CALLS_LOCAL (info
, tga
)
4582 || (ELF_ST_VISIBILITY (tga
->other
) != STV_DEFAULT
4583 && tga
->root
.type
== bfd_link_hash_undefweak
)))
4585 struct plt_entry
*ent
;
4586 for (ent
= tga
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4587 if (ent
->plt
.refcount
> 0)
4591 tga
->root
.type
= bfd_link_hash_indirect
;
4592 tga
->root
.u
.i
.link
= &opt
->root
;
4593 ppc_elf_copy_indirect_symbol (info
, opt
, tga
);
4594 if (opt
->dynindx
!= -1)
4596 /* Use __tls_get_addr_opt in dynamic relocations. */
4598 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4600 if (!bfd_elf_link_record_dynamic_symbol (info
, opt
))
4603 htab
->tls_get_addr
= opt
;
4608 no_tls_get_addr_opt
= TRUE
;
4610 htab
->no_tls_get_addr_opt
= no_tls_get_addr_opt
;
4611 if (htab
->plt_type
== PLT_NEW
4612 && htab
->plt
!= NULL
4613 && htab
->plt
->output_section
!= NULL
)
4615 elf_section_type (htab
->plt
->output_section
) = SHT_PROGBITS
;
4616 elf_section_flags (htab
->plt
->output_section
) = SHF_ALLOC
+ SHF_WRITE
;
4619 return _bfd_elf_tls_setup (obfd
, info
);
4622 /* Return TRUE iff REL is a branch reloc with a global symbol matching
4626 branch_reloc_hash_match (const bfd
*ibfd
,
4627 const Elf_Internal_Rela
*rel
,
4628 const struct elf_link_hash_entry
*hash
)
4630 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4631 enum elf_ppc_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
4632 unsigned int r_symndx
= ELF32_R_SYM (rel
->r_info
);
4634 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
4636 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4637 struct elf_link_hash_entry
*h
;
4639 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4640 while (h
->root
.type
== bfd_link_hash_indirect
4641 || h
->root
.type
== bfd_link_hash_warning
)
4642 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4649 /* Run through all the TLS relocs looking for optimization
4653 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4654 struct bfd_link_info
*info
)
4658 struct ppc_elf_link_hash_table
*htab
;
4661 if (info
->relocatable
|| !info
->executable
)
4664 htab
= ppc_elf_hash_table (info
);
4665 /* Make two passes through the relocs. First time check that tls
4666 relocs involved in setting up a tls_get_addr call are indeed
4667 followed by such a call. If they are not, exclude them from
4668 the optimizations done on the second pass. */
4669 for (pass
= 0; pass
< 2; ++pass
)
4670 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4672 Elf_Internal_Sym
*locsyms
= NULL
;
4673 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4674 asection
*got2
= bfd_get_section_by_name (ibfd
, ".got2");
4676 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4677 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4679 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4681 /* Read the relocations. */
4682 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4684 if (relstart
== NULL
)
4687 relend
= relstart
+ sec
->reloc_count
;
4688 for (rel
= relstart
; rel
< relend
; rel
++)
4690 enum elf_ppc_reloc_type r_type
;
4691 unsigned long r_symndx
;
4692 struct elf_link_hash_entry
*h
= NULL
;
4694 char tls_set
, tls_clear
;
4695 bfd_boolean is_local
;
4696 int expecting_tls_get_addr
;
4697 bfd_signed_vma
*got_count
;
4699 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4700 if (r_symndx
>= symtab_hdr
->sh_info
)
4702 struct elf_link_hash_entry
**sym_hashes
;
4704 sym_hashes
= elf_sym_hashes (ibfd
);
4705 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4706 while (h
->root
.type
== bfd_link_hash_indirect
4707 || h
->root
.type
== bfd_link_hash_warning
)
4708 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4711 expecting_tls_get_addr
= 0;
4717 r_type
= ELF32_R_TYPE (rel
->r_info
);
4720 case R_PPC_GOT_TLSLD16
:
4721 case R_PPC_GOT_TLSLD16_LO
:
4722 expecting_tls_get_addr
= 1;
4725 case R_PPC_GOT_TLSLD16_HI
:
4726 case R_PPC_GOT_TLSLD16_HA
:
4727 /* These relocs should never be against a symbol
4728 defined in a shared lib. Leave them alone if
4729 that turns out to be the case. */
4738 case R_PPC_GOT_TLSGD16
:
4739 case R_PPC_GOT_TLSGD16_LO
:
4740 expecting_tls_get_addr
= 1;
4743 case R_PPC_GOT_TLSGD16_HI
:
4744 case R_PPC_GOT_TLSGD16_HA
:
4750 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4754 case R_PPC_GOT_TPREL16
:
4755 case R_PPC_GOT_TPREL16_LO
:
4756 case R_PPC_GOT_TPREL16_HI
:
4757 case R_PPC_GOT_TPREL16_HA
:
4762 tls_clear
= TLS_TPREL
;
4770 expecting_tls_get_addr
= 2;
4781 if (!expecting_tls_get_addr
4782 || (expecting_tls_get_addr
== 1
4783 && !sec
->has_tls_get_addr_call
))
4786 if (rel
+ 1 < relend
4787 && branch_reloc_hash_match (ibfd
, rel
+ 1,
4788 htab
->tls_get_addr
))
4791 /* Uh oh, we didn't find the expected call. We
4792 could just mark this symbol to exclude it
4793 from tls optimization but it's safer to skip
4794 the entire section. */
4795 sec
->has_tls_reloc
= 0;
4799 if (expecting_tls_get_addr
)
4801 struct plt_entry
*ent
;
4805 && ELF32_R_TYPE (rel
[1].r_info
) == R_PPC_PLTREL24
)
4806 addend
= rel
[1].r_addend
;
4807 ent
= find_plt_ent (&htab
->tls_get_addr
->plt
.plist
,
4809 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4810 ent
->plt
.refcount
-= 1;
4812 if (expecting_tls_get_addr
== 2)
4818 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4819 got_count
= &h
->got
.refcount
;
4823 Elf_Internal_Sym
*sym
;
4824 bfd_signed_vma
*lgot_refs
;
4825 struct plt_entry
**local_plt
;
4828 if (locsyms
== NULL
)
4830 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4831 if (locsyms
== NULL
)
4832 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4833 symtab_hdr
->sh_info
,
4834 0, NULL
, NULL
, NULL
);
4835 if (locsyms
== NULL
)
4837 if (elf_section_data (sec
)->relocs
!= relstart
)
4842 sym
= locsyms
+ r_symndx
;
4843 lgot_refs
= elf_local_got_refcounts (ibfd
);
4844 if (lgot_refs
== NULL
)
4846 local_plt
= (struct plt_entry
**)
4847 (lgot_refs
+ symtab_hdr
->sh_info
);
4848 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
4849 tls_mask
= &lgot_masks
[r_symndx
];
4850 got_count
= &lgot_refs
[r_symndx
];
4855 /* We managed to get rid of a got entry. */
4860 *tls_mask
|= tls_set
;
4861 *tls_mask
&= ~tls_clear
;
4864 if (elf_section_data (sec
)->relocs
!= relstart
)
4869 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4871 if (!info
->keep_memory
)
4874 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4880 /* Return true if we have dynamic relocs that apply to read-only sections. */
4883 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
4885 struct ppc_elf_dyn_relocs
*p
;
4887 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4889 asection
*s
= p
->sec
->output_section
;
4892 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
4893 == (SEC_READONLY
| SEC_ALLOC
)))
4899 /* Adjust a symbol defined by a dynamic object and referenced by a
4900 regular object. The current definition is in some section of the
4901 dynamic object, but we're not including those sections. We have to
4902 change the definition to something the rest of the link can
4906 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4907 struct elf_link_hash_entry
*h
)
4909 struct ppc_elf_link_hash_table
*htab
;
4913 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4914 h
->root
.root
.string
);
4917 /* Make sure we know what is going on here. */
4918 htab
= ppc_elf_hash_table (info
);
4919 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
4921 || h
->type
== STT_GNU_IFUNC
4922 || h
->u
.weakdef
!= NULL
4925 && !h
->def_regular
)));
4927 /* Deal with function syms. */
4928 if (h
->type
== STT_FUNC
4929 || h
->type
== STT_GNU_IFUNC
4932 /* Clear procedure linkage table information for any symbol that
4933 won't need a .plt entry. */
4934 struct plt_entry
*ent
;
4935 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4936 if (ent
->plt
.refcount
> 0)
4939 || (h
->type
!= STT_GNU_IFUNC
4940 && (SYMBOL_CALLS_LOCAL (info
, h
)
4941 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4942 && h
->root
.type
== bfd_link_hash_undefweak
))))
4944 /* A PLT entry is not required/allowed when:
4946 1. We are not using ld.so; because then the PLT entry
4947 can't be set up, so we can't use one. In this case,
4948 ppc_elf_adjust_dynamic_symbol won't even be called.
4950 2. GC has rendered the entry unused.
4952 3. We know for certain that a call to this symbol
4953 will go to this object, or will remain undefined. */
4954 h
->plt
.plist
= NULL
;
4959 /* After adjust_dynamic_symbol, non_got_ref set in the
4960 non-shared case means that we have allocated space in
4961 .dynbss for the symbol and thus dyn_relocs for this
4962 symbol should be discarded.
4963 If we get here we know we are making a PLT entry for this
4964 symbol, and in an executable we'd normally resolve
4965 relocations against this symbol to the PLT entry. Allow
4966 dynamic relocs if the reference is weak, and the dynamic
4967 relocs will not cause text relocation. */
4968 if (!h
->ref_regular_nonweak
4970 && h
->type
!= STT_GNU_IFUNC
4971 && !htab
->is_vxworks
4972 && !ppc_elf_hash_entry (h
)->has_sda_refs
4973 && !readonly_dynrelocs (h
))
4979 h
->plt
.plist
= NULL
;
4981 /* If this is a weak symbol, and there is a real definition, the
4982 processor independent code will have arranged for us to see the
4983 real definition first, and we can just use the same value. */
4984 if (h
->u
.weakdef
!= NULL
)
4986 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
4987 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
4988 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
4989 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
4990 if (ELIMINATE_COPY_RELOCS
)
4991 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
4995 /* This is a reference to a symbol defined by a dynamic object which
4996 is not a function. */
4998 /* If we are creating a shared library, we must presume that the
4999 only references to the symbol are via the global offset table.
5000 For such cases we need not do anything here; the relocations will
5001 be handled correctly by relocate_section. */
5005 /* If there are no references to this symbol that do not use the
5006 GOT, we don't need to generate a copy reloc. */
5007 if (!h
->non_got_ref
)
5010 /* If we didn't find any dynamic relocs in read-only sections, then
5011 we'll be keeping the dynamic relocs and avoiding the copy reloc.
5012 We can't do this if there are any small data relocations. This
5013 doesn't work on VxWorks, where we can not have dynamic
5014 relocations (other than copy and jump slot relocations) in an
5016 if (ELIMINATE_COPY_RELOCS
5017 && !ppc_elf_hash_entry (h
)->has_sda_refs
5018 && !htab
->is_vxworks
5020 && !readonly_dynrelocs (h
))
5028 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
5029 h
->root
.root
.string
);
5033 /* We must allocate the symbol in our .dynbss section, which will
5034 become part of the .bss section of the executable. There will be
5035 an entry for this symbol in the .dynsym section. The dynamic
5036 object will contain position independent code, so all references
5037 from the dynamic object to this symbol will go through the global
5038 offset table. The dynamic linker will use the .dynsym entry to
5039 determine the address it must put in the global offset table, so
5040 both the dynamic object and the regular object will refer to the
5041 same memory location for the variable.
5043 Of course, if the symbol is referenced using SDAREL relocs, we
5044 must instead allocate it in .sbss. */
5046 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
5050 BFD_ASSERT (s
!= NULL
);
5052 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
5053 copy the initial value out of the dynamic object and into the
5054 runtime process image. We need to remember the offset into the
5055 .rela.bss section we are going to use. */
5056 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5060 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
5061 srel
= htab
->relsbss
;
5063 srel
= htab
->relbss
;
5064 BFD_ASSERT (srel
!= NULL
);
5065 srel
->size
+= sizeof (Elf32_External_Rela
);
5069 return _bfd_elf_adjust_dynamic_copy (h
, s
);
5072 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
5073 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
5074 specifying the addend on the plt relocation. For -fpic code, the sym
5075 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
5076 xxxxxxxx.got2.plt_pic32.<callee>. */
5079 add_stub_sym (struct plt_entry
*ent
,
5080 struct elf_link_hash_entry
*h
,
5081 struct bfd_link_info
*info
)
5083 struct elf_link_hash_entry
*sh
;
5084 size_t len1
, len2
, len3
;
5087 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
5090 stub
= ".plt_pic32.";
5092 stub
= ".plt_call32.";
5094 len1
= strlen (h
->root
.root
.string
);
5095 len2
= strlen (stub
);
5098 len3
= strlen (ent
->sec
->name
);
5099 name
= bfd_malloc (len1
+ len2
+ len3
+ 9);
5102 sprintf (name
, "%08x", (unsigned) ent
->addend
& 0xffffffff);
5104 memcpy (name
+ 8, ent
->sec
->name
, len3
);
5105 memcpy (name
+ 8 + len3
, stub
, len2
);
5106 memcpy (name
+ 8 + len3
+ len2
, h
->root
.root
.string
, len1
+ 1);
5107 sh
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
5110 if (sh
->root
.type
== bfd_link_hash_new
)
5112 sh
->root
.type
= bfd_link_hash_defined
;
5113 sh
->root
.u
.def
.section
= htab
->glink
;
5114 sh
->root
.u
.def
.value
= ent
->glink_offset
;
5115 sh
->ref_regular
= 1;
5116 sh
->def_regular
= 1;
5117 sh
->ref_regular_nonweak
= 1;
5118 sh
->forced_local
= 1;
5124 /* Allocate NEED contiguous space in .got, and return the offset.
5125 Handles allocation of the got header when crossing 32k. */
5128 allocate_got (struct ppc_elf_link_hash_table
*htab
, unsigned int need
)
5131 unsigned int max_before_header
;
5133 if (htab
->plt_type
== PLT_VXWORKS
)
5135 where
= htab
->got
->size
;
5136 htab
->got
->size
+= need
;
5140 max_before_header
= htab
->plt_type
== PLT_NEW
? 32768 : 32764;
5141 if (need
<= htab
->got_gap
)
5143 where
= max_before_header
- htab
->got_gap
;
5144 htab
->got_gap
-= need
;
5148 if (htab
->got
->size
+ need
> max_before_header
5149 && htab
->got
->size
<= max_before_header
)
5151 htab
->got_gap
= max_before_header
- htab
->got
->size
;
5152 htab
->got
->size
= max_before_header
+ htab
->got_header_size
;
5154 where
= htab
->got
->size
;
5155 htab
->got
->size
+= need
;
5161 /* Allocate space in associated reloc sections for dynamic relocs. */
5164 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5166 struct bfd_link_info
*info
= inf
;
5167 struct ppc_elf_link_hash_entry
*eh
;
5168 struct ppc_elf_link_hash_table
*htab
;
5169 struct ppc_elf_dyn_relocs
*p
;
5171 if (h
->root
.type
== bfd_link_hash_indirect
)
5174 if (h
->root
.type
== bfd_link_hash_warning
)
5175 /* When warning symbols are created, they **replace** the "real"
5176 entry in the hash table, thus we never get to see the real
5177 symbol in a hash traversal. So look at it now. */
5178 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5180 htab
= ppc_elf_hash_table (info
);
5181 if (htab
->elf
.dynamic_sections_created
5182 || h
->type
== STT_GNU_IFUNC
)
5184 struct plt_entry
*ent
;
5185 bfd_boolean doneone
= FALSE
;
5186 bfd_vma plt_offset
= 0, glink_offset
= 0;
5189 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5190 if (ent
->plt
.refcount
> 0)
5192 /* Make sure this symbol is output as a dynamic symbol. */
5193 if (h
->dynindx
== -1
5196 && htab
->elf
.dynamic_sections_created
)
5198 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5202 dyn
= htab
->elf
.dynamic_sections_created
;
5204 || h
->type
== STT_GNU_IFUNC
5205 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5207 asection
*s
= htab
->plt
;
5208 if (!dyn
|| h
->dynindx
== -1)
5211 if (htab
->plt_type
== PLT_NEW
|| !dyn
|| h
->dynindx
== -1)
5215 plt_offset
= s
->size
;
5218 ent
->plt
.offset
= plt_offset
;
5221 if (!doneone
|| info
->shared
)
5223 glink_offset
= s
->size
;
5224 s
->size
+= GLINK_ENTRY_SIZE
;
5225 if (h
== htab
->tls_get_addr
5226 && !htab
->no_tls_get_addr_opt
)
5227 s
->size
+= TLS_GET_ADDR_GLINK_SIZE
- GLINK_ENTRY_SIZE
;
5234 h
->root
.u
.def
.section
= s
;
5235 h
->root
.u
.def
.value
= glink_offset
;
5237 ent
->glink_offset
= glink_offset
;
5239 if (htab
->emit_stub_syms
5240 && !add_stub_sym (ent
, h
, info
))
5247 /* If this is the first .plt entry, make room
5248 for the special first entry. */
5250 s
->size
+= htab
->plt_initial_entry_size
;
5252 /* The PowerPC PLT is actually composed of two
5253 parts, the first part is 2 words (for a load
5254 and a jump), and then there is a remaining
5255 word available at the end. */
5256 plt_offset
= (htab
->plt_initial_entry_size
5257 + (htab
->plt_slot_size
5259 - htab
->plt_initial_entry_size
)
5260 / htab
->plt_entry_size
)));
5262 /* If this symbol is not defined in a regular
5263 file, and we are not generating a shared
5264 library, then set the symbol to this location
5265 in the .plt. This is to avoid text
5266 relocations, and is required to make
5267 function pointers compare as equal between
5268 the normal executable and the shared library. */
5273 h
->root
.u
.def
.section
= s
;
5274 h
->root
.u
.def
.value
= plt_offset
;
5277 /* Make room for this entry. */
5278 s
->size
+= htab
->plt_entry_size
;
5279 /* After the 8192nd entry, room for two entries
5281 if (htab
->plt_type
== PLT_OLD
5282 && (s
->size
- htab
->plt_initial_entry_size
)
5283 / htab
->plt_entry_size
5284 > PLT_NUM_SINGLE_ENTRIES
)
5285 s
->size
+= htab
->plt_entry_size
;
5287 ent
->plt
.offset
= plt_offset
;
5290 /* We also need to make an entry in the .rela.plt section. */
5293 if (!htab
->elf
.dynamic_sections_created
5294 || h
->dynindx
== -1)
5295 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5298 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
5300 if (htab
->plt_type
== PLT_VXWORKS
)
5302 /* Allocate space for the unloaded relocations. */
5304 && htab
->elf
.dynamic_sections_created
)
5307 == (bfd_vma
) htab
->plt_initial_entry_size
)
5309 htab
->srelplt2
->size
5310 += (sizeof (Elf32_External_Rela
)
5311 * VXWORKS_PLTRESOLVE_RELOCS
);
5314 htab
->srelplt2
->size
5315 += (sizeof (Elf32_External_Rela
)
5316 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
);
5319 /* Every PLT entry has an associated GOT entry in
5321 htab
->sgotplt
->size
+= 4;
5328 ent
->plt
.offset
= (bfd_vma
) -1;
5331 ent
->plt
.offset
= (bfd_vma
) -1;
5335 h
->plt
.plist
= NULL
;
5341 h
->plt
.plist
= NULL
;
5345 eh
= (struct ppc_elf_link_hash_entry
*) h
;
5346 if (eh
->elf
.got
.refcount
> 0)
5351 /* Make sure this symbol is output as a dynamic symbol. */
5352 if (eh
->elf
.dynindx
== -1
5353 && !eh
->elf
.forced_local
5354 && eh
->elf
.type
!= STT_GNU_IFUNC
5355 && htab
->elf
.dynamic_sections_created
)
5357 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
5362 if ((eh
->tls_mask
& TLS_TLS
) != 0)
5364 if ((eh
->tls_mask
& TLS_LD
) != 0)
5366 if (!eh
->elf
.def_dynamic
)
5367 /* We'll just use htab->tlsld_got.offset. This should
5368 always be the case. It's a little odd if we have
5369 a local dynamic reloc against a non-local symbol. */
5370 htab
->tlsld_got
.refcount
+= 1;
5374 if ((eh
->tls_mask
& TLS_GD
) != 0)
5376 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5378 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
5384 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5387 eh
->elf
.got
.offset
= allocate_got (htab
, need
);
5388 dyn
= htab
->elf
.dynamic_sections_created
;
5390 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
5391 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
5392 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
5394 asection
*rsec
= htab
->relgot
;
5395 /* All the entries we allocated need relocs.
5396 Except LD only needs one. */
5397 if ((eh
->tls_mask
& TLS_LD
) != 0
5398 && eh
->elf
.def_dynamic
)
5400 rsec
->size
+= need
* (sizeof (Elf32_External_Rela
) / 4);
5405 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5407 if (eh
->dyn_relocs
== NULL
5408 || !htab
->elf
.dynamic_sections_created
)
5411 /* In the shared -Bsymbolic case, discard space allocated for
5412 dynamic pc-relative relocs against symbols which turn out to be
5413 defined in regular objects. For the normal shared case, discard
5414 space for relocs that have become local due to symbol visibility
5419 /* Relocs that use pc_count are those that appear on a call insn,
5420 or certain REL relocs (see must_be_dyn_reloc) that can be
5421 generated via assembly. We want calls to protected symbols to
5422 resolve directly to the function rather than going via the plt.
5423 If people want function pointer comparisons to work as expected
5424 then they should avoid writing weird assembly. */
5425 if (SYMBOL_CALLS_LOCAL (info
, h
))
5427 struct ppc_elf_dyn_relocs
**pp
;
5429 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5431 p
->count
-= p
->pc_count
;
5440 if (htab
->is_vxworks
)
5442 struct ppc_elf_dyn_relocs
**pp
;
5444 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5446 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
5453 /* Discard relocs on undefined symbols that must be local. */
5454 if (eh
->dyn_relocs
!= NULL
5455 && h
->root
.type
== bfd_link_hash_undefined
5456 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
5457 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
5458 eh
->dyn_relocs
= NULL
;
5460 /* Also discard relocs on undefined weak syms with non-default
5462 if (eh
->dyn_relocs
!= NULL
5463 && h
->root
.type
== bfd_link_hash_undefweak
)
5465 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5466 eh
->dyn_relocs
= NULL
;
5468 /* Make sure undefined weak symbols are output as a dynamic
5470 else if (h
->dynindx
== -1
5474 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5479 else if (ELIMINATE_COPY_RELOCS
)
5481 /* For the non-shared case, discard space for relocs against
5482 symbols which turn out to need copy relocs or are not
5488 /* Make sure this symbol is output as a dynamic symbol.
5489 Undefined weak syms won't yet be marked as dynamic. */
5490 if (h
->dynindx
== -1
5491 && !h
->forced_local
)
5493 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5497 /* If that succeeded, we know we'll be keeping all the
5499 if (h
->dynindx
!= -1)
5503 eh
->dyn_relocs
= NULL
;
5508 /* Finally, allocate space. */
5509 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5511 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5512 if (!htab
->elf
.dynamic_sections_created
)
5513 sreloc
= htab
->reliplt
;
5514 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5520 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
5521 read-only sections. */
5524 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info
)
5526 if (h
->root
.type
== bfd_link_hash_indirect
)
5529 if (h
->root
.type
== bfd_link_hash_warning
)
5530 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5532 if (readonly_dynrelocs (h
))
5534 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
5536 /* Not an error, just cut short the traversal. */
5542 /* Set the sizes of the dynamic sections. */
5545 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5546 struct bfd_link_info
*info
)
5548 struct ppc_elf_link_hash_table
*htab
;
5554 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
5557 htab
= ppc_elf_hash_table (info
);
5558 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
5560 if (elf_hash_table (info
)->dynamic_sections_created
)
5562 /* Set the contents of the .interp section to the interpreter. */
5563 if (info
->executable
)
5565 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
5566 BFD_ASSERT (s
!= NULL
);
5567 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5568 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5572 if (htab
->plt_type
== PLT_OLD
)
5573 htab
->got_header_size
= 16;
5574 else if (htab
->plt_type
== PLT_NEW
)
5575 htab
->got_header_size
= 12;
5577 /* Set up .got offsets for local syms, and space for local dynamic
5579 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5581 bfd_signed_vma
*local_got
;
5582 bfd_signed_vma
*end_local_got
;
5583 struct plt_entry
**local_plt
;
5584 struct plt_entry
**end_local_plt
;
5586 bfd_size_type locsymcount
;
5587 Elf_Internal_Shdr
*symtab_hdr
;
5589 if (!is_ppc_elf (ibfd
))
5592 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5594 struct ppc_elf_dyn_relocs
*p
;
5596 for (p
= ((struct ppc_elf_dyn_relocs
*)
5597 elf_section_data (s
)->local_dynrel
);
5601 if (!bfd_is_abs_section (p
->sec
)
5602 && bfd_is_abs_section (p
->sec
->output_section
))
5604 /* Input section has been discarded, either because
5605 it is a copy of a linkonce section or due to
5606 linker script /DISCARD/, so we'll be discarding
5609 else if (htab
->is_vxworks
5610 && strcmp (p
->sec
->output_section
->name
,
5613 /* Relocations in vxworks .tls_vars sections are
5614 handled specially by the loader. */
5616 else if (p
->count
!= 0)
5618 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5619 if (!htab
->elf
.dynamic_sections_created
)
5620 sreloc
= htab
->reliplt
;
5621 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5622 if ((p
->sec
->output_section
->flags
5623 & (SEC_READONLY
| SEC_ALLOC
))
5624 == (SEC_READONLY
| SEC_ALLOC
))
5625 info
->flags
|= DF_TEXTREL
;
5630 local_got
= elf_local_got_refcounts (ibfd
);
5634 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5635 locsymcount
= symtab_hdr
->sh_info
;
5636 end_local_got
= local_got
+ locsymcount
;
5637 local_plt
= (struct plt_entry
**) end_local_got
;
5638 end_local_plt
= local_plt
+ locsymcount
;
5639 lgot_masks
= (char *) end_local_plt
;
5641 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
5644 unsigned int need
= 0;
5645 if ((*lgot_masks
& TLS_TLS
) != 0)
5647 if ((*lgot_masks
& TLS_GD
) != 0)
5649 if ((*lgot_masks
& TLS_LD
) != 0)
5650 htab
->tlsld_got
.refcount
+= 1;
5651 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5653 if ((*lgot_masks
& TLS_DTPREL
) != 0)
5659 *local_got
= (bfd_vma
) -1;
5662 *local_got
= allocate_got (htab
, need
);
5664 htab
->relgot
->size
+= (need
5665 * (sizeof (Elf32_External_Rela
) / 4));
5669 *local_got
= (bfd_vma
) -1;
5671 if (htab
->is_vxworks
)
5674 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
5675 for (; local_plt
< end_local_plt
; ++local_plt
)
5677 struct plt_entry
*ent
;
5678 bfd_boolean doneone
= FALSE
;
5679 bfd_vma plt_offset
= 0, glink_offset
= 0;
5681 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
5682 if (ent
->plt
.refcount
> 0)
5688 plt_offset
= s
->size
;
5691 ent
->plt
.offset
= plt_offset
;
5694 if (!doneone
|| info
->shared
)
5696 glink_offset
= s
->size
;
5697 s
->size
+= GLINK_ENTRY_SIZE
;
5699 ent
->glink_offset
= glink_offset
;
5703 htab
->reliplt
->size
+= sizeof (Elf32_External_Rela
);
5708 ent
->plt
.offset
= (bfd_vma
) -1;
5712 /* Allocate space for global sym dynamic relocs. */
5713 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
5715 if (htab
->tlsld_got
.refcount
> 0)
5717 htab
->tlsld_got
.offset
= allocate_got (htab
, 8);
5719 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
5722 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
5724 if (htab
->got
!= NULL
&& htab
->plt_type
!= PLT_VXWORKS
)
5726 unsigned int g_o_t
= 32768;
5728 /* If we haven't allocated the header, do so now. When we get here,
5729 for old plt/got the got size will be 0 to 32764 (not allocated),
5730 or 32780 to 65536 (header allocated). For new plt/got, the
5731 corresponding ranges are 0 to 32768 and 32780 to 65536. */
5732 if (htab
->got
->size
<= 32768)
5734 g_o_t
= htab
->got
->size
;
5735 if (htab
->plt_type
== PLT_OLD
)
5737 htab
->got
->size
+= htab
->got_header_size
;
5740 htab
->elf
.hgot
->root
.u
.def
.value
= g_o_t
;
5744 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
5746 && !(sda
->root
.type
== bfd_link_hash_defined
5747 || sda
->root
.type
== bfd_link_hash_defweak
))
5749 sda
->root
.type
= bfd_link_hash_defined
;
5750 sda
->root
.u
.def
.section
= htab
->elf
.hgot
->root
.u
.def
.section
;
5751 sda
->root
.u
.def
.value
= htab
->elf
.hgot
->root
.u
.def
.value
;
5755 if (htab
->glink
!= NULL
5756 && htab
->glink
->size
!= 0
5757 && htab
->elf
.dynamic_sections_created
)
5759 htab
->glink_pltresolve
= htab
->glink
->size
;
5760 /* Space for the branch table. */
5761 htab
->glink
->size
+= htab
->glink
->size
/ (GLINK_ENTRY_SIZE
/ 4) - 4;
5762 /* Pad out to align the start of PLTresolve. */
5763 htab
->glink
->size
+= -htab
->glink
->size
& 15;
5764 htab
->glink
->size
+= GLINK_PLTRESOLVE
;
5766 if (htab
->emit_stub_syms
)
5768 struct elf_link_hash_entry
*sh
;
5769 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink",
5770 TRUE
, FALSE
, FALSE
);
5773 if (sh
->root
.type
== bfd_link_hash_new
)
5775 sh
->root
.type
= bfd_link_hash_defined
;
5776 sh
->root
.u
.def
.section
= htab
->glink
;
5777 sh
->root
.u
.def
.value
= htab
->glink_pltresolve
;
5778 sh
->ref_regular
= 1;
5779 sh
->def_regular
= 1;
5780 sh
->ref_regular_nonweak
= 1;
5781 sh
->forced_local
= 1;
5784 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
5785 TRUE
, FALSE
, FALSE
);
5788 if (sh
->root
.type
== bfd_link_hash_new
)
5790 sh
->root
.type
= bfd_link_hash_defined
;
5791 sh
->root
.u
.def
.section
= htab
->glink
;
5792 sh
->root
.u
.def
.value
= htab
->glink
->size
- GLINK_PLTRESOLVE
;
5793 sh
->ref_regular
= 1;
5794 sh
->def_regular
= 1;
5795 sh
->ref_regular_nonweak
= 1;
5796 sh
->forced_local
= 1;
5802 /* We've now determined the sizes of the various dynamic sections.
5803 Allocate memory for them. */
5805 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5807 bfd_boolean strip_section
= TRUE
;
5809 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5815 /* We'd like to strip these sections if they aren't needed, but if
5816 we've exported dynamic symbols from them we must leave them.
5817 It's too late to tell BFD to get rid of the symbols. */
5818 if (htab
->elf
.hplt
!= NULL
)
5819 strip_section
= FALSE
;
5820 /* Strip this section if we don't need it; see the
5823 else if (s
== htab
->iplt
5825 || s
== htab
->sgotplt
5827 || s
== htab
->dynbss
5828 || s
== htab
->dynsbss
5829 || s
== htab
->sdata
[0].section
5830 || s
== htab
->sdata
[1].section
)
5832 /* Strip these too. */
5834 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
5838 /* Remember whether there are any relocation sections. */
5841 /* We use the reloc_count field as a counter if we need
5842 to copy relocs into the output file. */
5848 /* It's not one of our sections, so don't allocate space. */
5852 if (s
->size
== 0 && strip_section
)
5854 /* If we don't need this section, strip it from the
5855 output file. This is mostly to handle .rela.bss and
5856 .rela.plt. We must create both sections in
5857 create_dynamic_sections, because they must be created
5858 before the linker maps input sections to output
5859 sections. The linker does that before
5860 adjust_dynamic_symbol is called, and it is that
5861 function which decides whether anything needs to go
5862 into these sections. */
5863 s
->flags
|= SEC_EXCLUDE
;
5867 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
5870 /* Allocate memory for the section contents. */
5871 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
5872 if (s
->contents
== NULL
)
5876 if (htab
->elf
.dynamic_sections_created
)
5878 /* Add some entries to the .dynamic section. We fill in the
5879 values later, in ppc_elf_finish_dynamic_sections, but we
5880 must add the entries now so that we get the correct size for
5881 the .dynamic section. The DT_DEBUG entry is filled in by the
5882 dynamic linker and used by the debugger. */
5883 #define add_dynamic_entry(TAG, VAL) \
5884 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5886 if (info
->executable
)
5888 if (!add_dynamic_entry (DT_DEBUG
, 0))
5892 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
5894 if (!add_dynamic_entry (DT_PLTGOT
, 0)
5895 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
5896 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
5897 || !add_dynamic_entry (DT_JMPREL
, 0))
5901 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
5903 if (!add_dynamic_entry (DT_PPC_GOT
, 0))
5905 if (!htab
->no_tls_get_addr_opt
5906 && htab
->tls_get_addr
!= NULL
5907 && htab
->tls_get_addr
->plt
.plist
!= NULL
5908 && !add_dynamic_entry (DT_PPC_TLSOPT
, 0))
5914 if (!add_dynamic_entry (DT_RELA
, 0)
5915 || !add_dynamic_entry (DT_RELASZ
, 0)
5916 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
5920 /* If any dynamic relocs apply to a read-only section, then we
5921 need a DT_TEXTREL entry. */
5922 if ((info
->flags
& DF_TEXTREL
) == 0)
5923 elf_link_hash_traverse (elf_hash_table (info
), maybe_set_textrel
,
5926 if ((info
->flags
& DF_TEXTREL
) != 0)
5928 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5931 if (htab
->is_vxworks
5932 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
5935 #undef add_dynamic_entry
5940 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5943 ppc_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5945 if (h
->plt
.plist
!= NULL
5947 && (!h
->pointer_equality_needed
5948 || !h
->ref_regular_nonweak
))
5951 return _bfd_elf_hash_symbol (h
);
5954 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5956 /* Relaxation trampolines. r12 is available for clobbering (r11, is
5957 used for some functions that are allowed to break the ABI). */
5958 static const int shared_stub_entry
[] =
5960 0x7c0802a6, /* mflr 0 */
5961 0x429f0005, /* bcl 20, 31, .Lxxx */
5962 0x7d8802a6, /* mflr 12 */
5963 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
5964 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */
5965 0x7c0803a6, /* mtlr 0 */
5966 0x7d8903a6, /* mtctr 12 */
5967 0x4e800420, /* bctr */
5970 static const int stub_entry
[] =
5972 0x3d800000, /* lis 12,xxx@ha */
5973 0x398c0000, /* addi 12,12,xxx@l */
5974 0x7d8903a6, /* mtctr 12 */
5975 0x4e800420, /* bctr */
5979 ppc_elf_relax_section (bfd
*abfd
,
5981 struct bfd_link_info
*link_info
,
5986 struct one_fixup
*next
;
5988 /* Final link, can use the symbol offset. For a
5989 relocatable link we use the symbol's index. */
5994 Elf_Internal_Shdr
*symtab_hdr
;
5995 bfd_byte
*contents
= NULL
;
5996 Elf_Internal_Sym
*isymbuf
= NULL
;
5997 Elf_Internal_Rela
*internal_relocs
= NULL
;
5998 Elf_Internal_Rela
*irel
, *irelend
;
5999 struct one_fixup
*fixups
= NULL
;
6000 unsigned changes
= 0;
6001 struct ppc_elf_link_hash_table
*htab
;
6002 bfd_size_type trampoff
;
6007 /* Nothing to do if there are no relocations, and no need to do
6008 anything with non-alloc or non-code sections. */
6009 if ((isec
->flags
& SEC_ALLOC
) == 0
6010 || (isec
->flags
& SEC_CODE
) == 0
6011 || (isec
->flags
& SEC_RELOC
) == 0
6012 || isec
->reloc_count
== 0)
6015 /* We cannot represent the required PIC relocs in the output, so don't
6016 do anything. The linker doesn't support mixing -shared and -r
6018 if (link_info
->relocatable
&& link_info
->shared
)
6021 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
6022 /* Space for a branch around any trampolines. */
6025 symtab_hdr
= &elf_symtab_hdr (abfd
);
6027 /* Get a copy of the native relocations. */
6028 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
6029 link_info
->keep_memory
);
6030 if (internal_relocs
== NULL
)
6033 htab
= ppc_elf_hash_table (link_info
);
6034 got2
= bfd_get_section_by_name (abfd
, ".got2");
6036 irelend
= internal_relocs
+ isec
->reloc_count
;
6037 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6039 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
6042 struct one_fixup
*f
;
6043 size_t insn_offset
= 0;
6044 bfd_vma max_branch_offset
, val
;
6047 struct elf_link_hash_entry
*h
;
6048 struct plt_entry
**plist
;
6049 unsigned char sym_type
;
6054 case R_PPC_LOCAL24PC
:
6055 case R_PPC_PLTREL24
:
6056 max_branch_offset
= 1 << 25;
6060 case R_PPC_REL14_BRTAKEN
:
6061 case R_PPC_REL14_BRNTAKEN
:
6062 max_branch_offset
= 1 << 15;
6069 /* Get the value of the symbol referred to by the reloc. */
6071 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
6073 /* A local symbol. */
6074 Elf_Internal_Sym
*isym
;
6076 /* Read this BFD's local symbols. */
6077 if (isymbuf
== NULL
)
6079 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6080 if (isymbuf
== NULL
)
6081 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
6082 symtab_hdr
->sh_info
, 0,
6087 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
6088 if (isym
->st_shndx
== SHN_UNDEF
)
6089 tsec
= bfd_und_section_ptr
;
6090 else if (isym
->st_shndx
== SHN_ABS
)
6091 tsec
= bfd_abs_section_ptr
;
6092 else if (isym
->st_shndx
== SHN_COMMON
)
6093 tsec
= bfd_com_section_ptr
;
6095 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6097 toff
= isym
->st_value
;
6098 sym_type
= ELF_ST_TYPE (isym
->st_info
);
6102 /* Global symbol handling. */
6105 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6106 h
= elf_sym_hashes (abfd
)[indx
];
6108 while (h
->root
.type
== bfd_link_hash_indirect
6109 || h
->root
.type
== bfd_link_hash_warning
)
6110 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6112 if (h
->root
.type
== bfd_link_hash_defined
6113 || h
->root
.type
== bfd_link_hash_defweak
)
6115 tsec
= h
->root
.u
.def
.section
;
6116 toff
= h
->root
.u
.def
.value
;
6118 else if (h
->root
.type
== bfd_link_hash_undefined
6119 || h
->root
.type
== bfd_link_hash_undefweak
)
6121 tsec
= bfd_und_section_ptr
;
6122 toff
= link_info
->relocatable
? indx
: 0;
6130 /* The condition here under which we call find_plt_ent must
6131 match that in relocate_section. If we call find_plt_ent here
6132 but not in relocate_section, or vice versa, then the branch
6133 destination used here may be incorrect. */
6137 /* We know is_branch_reloc (r_type) is true. */
6138 if (h
->type
== STT_GNU_IFUNC
6139 || r_type
== R_PPC_PLTREL24
)
6140 plist
= &h
->plt
.plist
;
6142 else if (sym_type
== STT_GNU_IFUNC
6143 && elf_local_got_offsets (abfd
) != NULL
)
6145 bfd_vma
*local_got_offsets
= elf_local_got_offsets (abfd
);
6146 struct plt_entry
**local_plt
= (struct plt_entry
**)
6147 (local_got_offsets
+ symtab_hdr
->sh_info
);
6148 plist
= local_plt
+ ELF32_R_SYM (irel
->r_info
);
6153 struct plt_entry
*ent
;
6155 if (r_type
== R_PPC_PLTREL24
&& link_info
->shared
)
6156 addend
= irel
->r_addend
;
6157 ent
= find_plt_ent (plist
, got2
, addend
);
6160 if (htab
->plt_type
== PLT_NEW
6162 || !htab
->elf
.dynamic_sections_created
6163 || h
->dynindx
== -1)
6166 toff
= ent
->glink_offset
;
6171 toff
= ent
->plt
.offset
;
6176 /* If the branch and target are in the same section, you have
6177 no hope of adding stubs. We'll error out later should the
6182 /* There probably isn't any reason to handle symbols in
6183 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6184 attribute for a code section, and we are only looking at
6185 branches. However, implement it correctly here as a
6186 reference for other target relax_section functions. */
6187 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
6189 /* At this stage in linking, no SEC_MERGE symbol has been
6190 adjusted, so all references to such symbols need to be
6191 passed through _bfd_merged_section_offset. (Later, in
6192 relocate_section, all SEC_MERGE symbols *except* for
6193 section symbols have been adjusted.)
6195 gas may reduce relocations against symbols in SEC_MERGE
6196 sections to a relocation against the section symbol when
6197 the original addend was zero. When the reloc is against
6198 a section symbol we should include the addend in the
6199 offset passed to _bfd_merged_section_offset, since the
6200 location of interest is the original symbol. On the
6201 other hand, an access to "sym+addend" where "sym" is not
6202 a section symbol should not include the addend; Such an
6203 access is presumed to be an offset from "sym"; The
6204 location of interest is just "sym". */
6205 if (sym_type
== STT_SECTION
)
6206 toff
+= irel
->r_addend
;
6208 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
6209 elf_section_data (tsec
)->sec_info
,
6212 if (sym_type
!= STT_SECTION
)
6213 toff
+= irel
->r_addend
;
6215 /* PLTREL24 addends are special. */
6216 else if (r_type
!= R_PPC_PLTREL24
)
6217 toff
+= irel
->r_addend
;
6219 /* Attempted -shared link of non-pic code loses. */
6220 if (tsec
->output_section
== NULL
)
6223 roff
= irel
->r_offset
;
6225 /* If the branch is in range, no need to do anything. */
6226 if (tsec
!= bfd_und_section_ptr
6227 && (!link_info
->relocatable
6228 /* A relocatable link may have sections moved during
6229 final link, so do not presume they remain in range. */
6230 || tsec
->output_section
== isec
->output_section
))
6232 bfd_vma symaddr
, reladdr
;
6234 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
6235 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
6236 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
6240 /* Look for an existing fixup to this address. */
6241 for (f
= fixups
; f
; f
= f
->next
)
6242 if (f
->tsec
== tsec
&& f
->toff
== toff
)
6248 unsigned long stub_rtype
;
6250 val
= trampoff
- roff
;
6251 if (val
>= max_branch_offset
)
6252 /* Oh dear, we can't reach a trampoline. Don't try to add
6253 one. We'll report an error later. */
6256 if (link_info
->shared
)
6258 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
6263 size
= 4 * ARRAY_SIZE (stub_entry
);
6266 stub_rtype
= R_PPC_RELAX
;
6267 if (tsec
== htab
->plt
6268 || tsec
== htab
->glink
)
6270 stub_rtype
= R_PPC_RELAX_PLT
;
6271 if (r_type
== R_PPC_PLTREL24
)
6272 stub_rtype
= R_PPC_RELAX_PLTREL24
;
6275 /* Hijack the old relocation. Since we need two
6276 relocations for this use a "composite" reloc. */
6277 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
6279 irel
->r_offset
= trampoff
+ insn_offset
;
6280 if (r_type
== R_PPC_PLTREL24
6281 && stub_rtype
!= R_PPC_RELAX_PLTREL24
)
6284 /* Record the fixup so we don't do it again this section. */
6285 f
= bfd_malloc (sizeof (*f
));
6289 f
->trampoff
= trampoff
;
6297 val
= f
->trampoff
- roff
;
6298 if (val
>= max_branch_offset
)
6301 /* Nop out the reloc, since we're finalizing things here. */
6302 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6305 /* Get the section contents. */
6306 if (contents
== NULL
)
6308 /* Get cached copy if it exists. */
6309 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
6310 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6313 /* Go get them off disk. */
6314 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
6319 /* Fix up the existing branch to hit the trampoline. */
6320 hit_addr
= contents
+ roff
;
6324 case R_PPC_LOCAL24PC
:
6325 case R_PPC_PLTREL24
:
6326 t0
= bfd_get_32 (abfd
, hit_addr
);
6328 t0
|= val
& 0x3fffffc;
6329 bfd_put_32 (abfd
, t0
, hit_addr
);
6333 case R_PPC_REL14_BRTAKEN
:
6334 case R_PPC_REL14_BRNTAKEN
:
6335 t0
= bfd_get_32 (abfd
, hit_addr
);
6338 bfd_put_32 (abfd
, t0
, hit_addr
);
6343 /* Write out the trampolines. */
6353 struct one_fixup
*f
= fixups
;
6354 fixups
= fixups
->next
;
6359 contents
= bfd_realloc_or_free (contents
, trampoff
);
6360 if (contents
== NULL
)
6363 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
6364 /* Branch around the trampolines. */
6365 val
= B
+ trampoff
- isec
->size
;
6366 dest
= contents
+ isec
->size
;
6367 isec
->size
= trampoff
;
6368 bfd_put_32 (abfd
, val
, dest
);
6371 if (link_info
->shared
)
6373 stub
= shared_stub_entry
;
6374 size
= ARRAY_SIZE (shared_stub_entry
);
6379 size
= ARRAY_SIZE (stub_entry
);
6383 while (dest
< contents
+ trampoff
)
6385 bfd_put_32 (abfd
, stub
[i
], dest
);
6391 BFD_ASSERT (i
== 0);
6395 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
6397 if (! link_info
->keep_memory
)
6401 /* Cache the symbols for elf_link_input_bfd. */
6402 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
6406 if (contents
!= NULL
6407 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6409 if (!changes
&& !link_info
->keep_memory
)
6413 /* Cache the section contents for elf_link_input_bfd. */
6414 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6420 /* Append sufficient NOP relocs so we can write out relocation
6421 information for the trampolines. */
6422 Elf_Internal_Rela
*new_relocs
= bfd_malloc ((changes
+ isec
->reloc_count
)
6423 * sizeof (*new_relocs
));
6428 memcpy (new_relocs
, internal_relocs
,
6429 isec
->reloc_count
* sizeof (*new_relocs
));
6430 for (ix
= changes
; ix
--;)
6432 irel
= new_relocs
+ ix
+ isec
->reloc_count
;
6434 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6436 if (internal_relocs
!= elf_section_data (isec
)->relocs
)
6437 free (internal_relocs
);
6438 elf_section_data (isec
)->relocs
= new_relocs
;
6439 isec
->reloc_count
+= changes
;
6440 elf_section_data (isec
)->rel_hdr
.sh_size
6441 += changes
* elf_section_data (isec
)->rel_hdr
.sh_entsize
;
6443 else if (elf_section_data (isec
)->relocs
!= internal_relocs
)
6444 free (internal_relocs
);
6446 *again
= changes
!= 0;
6447 if (!*again
&& link_info
->relocatable
)
6449 /* Convert the internal relax relocs to external form. */
6450 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6451 if (ELF32_R_TYPE (irel
->r_info
) == R_PPC_RELAX
)
6453 unsigned long r_symndx
= ELF32_R_SYM (irel
->r_info
);
6455 /* Rewrite the reloc and convert one of the trailing nop
6456 relocs to describe this relocation. */
6457 BFD_ASSERT (ELF32_R_TYPE (irelend
[-1].r_info
) == R_PPC_NONE
);
6458 /* The relocs are at the bottom 2 bytes */
6459 irel
[0].r_offset
+= 2;
6460 memmove (irel
+ 1, irel
, (irelend
- irel
- 1) * sizeof (*irel
));
6461 irel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
6462 irel
[1].r_offset
+= 4;
6463 irel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
6471 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
6473 if (contents
!= NULL
6474 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6476 if (internal_relocs
!= NULL
6477 && elf_section_data (isec
)->relocs
!= internal_relocs
)
6478 free (internal_relocs
);
6482 /* What to do when ld finds relocations against symbols defined in
6483 discarded sections. */
6486 ppc_elf_action_discarded (asection
*sec
)
6488 if (strcmp (".fixup", sec
->name
) == 0)
6491 if (strcmp (".got2", sec
->name
) == 0)
6494 return _bfd_elf_default_action_discarded (sec
);
6497 /* Fill in the address for a pointer generated in a linker section. */
6500 elf_finish_pointer_linker_section (bfd
*input_bfd
,
6501 elf_linker_section_t
*lsect
,
6502 struct elf_link_hash_entry
*h
,
6504 const Elf_Internal_Rela
*rel
)
6506 elf_linker_section_pointers_t
*linker_section_ptr
;
6508 BFD_ASSERT (lsect
!= NULL
);
6512 /* Handle global symbol. */
6513 struct ppc_elf_link_hash_entry
*eh
;
6515 eh
= (struct ppc_elf_link_hash_entry
*) h
;
6516 BFD_ASSERT (eh
->elf
.def_regular
);
6517 linker_section_ptr
= eh
->linker_section_pointer
;
6521 /* Handle local symbol. */
6522 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
6524 BFD_ASSERT (is_ppc_elf (input_bfd
));
6525 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6526 linker_section_ptr
= elf_local_ptr_offsets (input_bfd
)[r_symndx
];
6529 linker_section_ptr
= elf_find_pointer_linker_section (linker_section_ptr
,
6532 BFD_ASSERT (linker_section_ptr
!= NULL
);
6534 /* Offset will always be a multiple of four, so use the bottom bit
6535 as a "written" flag. */
6536 if ((linker_section_ptr
->offset
& 1) == 0)
6538 bfd_put_32 (lsect
->section
->owner
,
6539 relocation
+ linker_section_ptr
->addend
,
6540 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6541 linker_section_ptr
->offset
+= 1;
6544 relocation
= (lsect
->section
->output_section
->vma
6545 + lsect
->section
->output_offset
6546 + linker_section_ptr
->offset
- 1
6547 - SYM_VAL (lsect
->sym
));
6551 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6552 lsect
->name
, (long) relocation
, (long) relocation
);
6558 #define PPC_LO(v) ((v) & 0xffff)
6559 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6560 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6563 write_glink_stub (struct plt_entry
*ent
, asection
*plt_sec
, unsigned char *p
,
6564 struct bfd_link_info
*info
)
6566 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
6567 bfd
*output_bfd
= info
->output_bfd
;
6570 plt
= ((ent
->plt
.offset
& ~1)
6571 + plt_sec
->output_section
->vma
6572 + plt_sec
->output_offset
);
6578 if (ent
->addend
>= 32768)
6580 + ent
->sec
->output_section
->vma
6581 + ent
->sec
->output_offset
);
6582 else if (htab
->elf
.hgot
!= NULL
)
6583 got
= SYM_VAL (htab
->elf
.hgot
);
6587 if (plt
+ 0x8000 < 0x10000)
6589 bfd_put_32 (output_bfd
, LWZ_11_30
+ PPC_LO (plt
), p
);
6591 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6593 bfd_put_32 (output_bfd
, BCTR
, p
);
6595 bfd_put_32 (output_bfd
, NOP
, p
);
6600 bfd_put_32 (output_bfd
, ADDIS_11_30
+ PPC_HA (plt
), p
);
6602 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6604 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6606 bfd_put_32 (output_bfd
, BCTR
, p
);
6612 bfd_put_32 (output_bfd
, LIS_11
+ PPC_HA (plt
), p
);
6614 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6616 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6618 bfd_put_32 (output_bfd
, BCTR
, p
);
6623 /* Return true if symbol is defined statically. */
6626 is_static_defined (struct elf_link_hash_entry
*h
)
6628 return ((h
->root
.type
== bfd_link_hash_defined
6629 || h
->root
.type
== bfd_link_hash_defweak
)
6630 && h
->root
.u
.def
.section
!= NULL
6631 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6634 /* If INSN is an opcode that may be used with an @tls operand, return
6635 the transformed insn for TLS optimisation, otherwise return 0. If
6636 REG is non-zero only match an insn with RB or RA equal to REG. */
6639 _bfd_elf_ppc_at_tls_transform (unsigned int insn
, unsigned int reg
)
6643 if ((insn
& (0x3f << 26)) != 31 << 26)
6646 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
6647 rtra
= insn
& ((1 << 26) - (1 << 16));
6648 else if (((insn
>> 16) & 0x1f) == reg
)
6649 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
6653 if ((insn
& (0x3ff << 1)) == 266 << 1)
6656 else if ((insn
& (0x1f << 1)) == 23 << 1
6657 && ((insn
& (0x1f << 6)) < 14 << 6
6658 || ((insn
& (0x1f << 6)) >= 16 << 6
6659 && (insn
& (0x1f << 6)) < 24 << 6)))
6660 /* load and store indexed -> dform. */
6661 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
6662 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
6663 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
6664 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
6665 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
6667 insn
= (58 << 26) | 2;
6674 /* If INSN is an opcode that may be used with an @tprel operand, return
6675 the transformed insn for an undefined weak symbol, ie. with the
6676 thread pointer REG operand removed. Otherwise return 0. */
6679 _bfd_elf_ppc_at_tprel_transform (unsigned int insn
, unsigned int reg
)
6681 if ((insn
& (0x1f << 16)) == reg
<< 16
6682 && ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6683 || (insn
& (0x3f << 26)) == 15u << 26 /* addis */
6684 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6685 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6686 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6687 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6688 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6689 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6690 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6691 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6692 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6693 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6694 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6695 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6696 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6697 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6699 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6700 && ((insn
& 3) == 0 || (insn
& 3) == 3))))
6702 insn
&= ~(0x1f << 16);
6704 else if ((insn
& (0x1f << 21)) == reg
<< 21
6705 && ((insn
& (0x3e << 26)) == 24u << 26 /* ori, oris */
6706 || (insn
& (0x3e << 26)) == 26u << 26 /* xori,xoris */
6707 || (insn
& (0x3e << 26)) == 28u << 26 /* andi,andis */))
6709 insn
&= ~(0x1f << 21);
6710 insn
|= (insn
& (0x1f << 16)) << 5;
6711 if ((insn
& (0x3e << 26)) == 26 << 26 /* xori,xoris */)
6712 insn
-= 2 >> 26; /* convert to ori,oris */
6719 /* The RELOCATE_SECTION function is called by the ELF backend linker
6720 to handle the relocations for a section.
6722 The relocs are always passed as Rela structures; if the section
6723 actually uses Rel structures, the r_addend field will always be
6726 This function is responsible for adjust the section contents as
6727 necessary, and (if using Rela relocs and generating a
6728 relocatable output file) adjusting the reloc addend as
6731 This function does not have to worry about setting the reloc
6732 address or the reloc symbol index.
6734 LOCAL_SYMS is a pointer to the swapped in local symbols.
6736 LOCAL_SECTIONS is an array giving the section in the input file
6737 corresponding to the st_shndx field of each local symbol.
6739 The global hash table entry for the global symbols can be found
6740 via elf_sym_hashes (input_bfd).
6742 When generating relocatable output, this function must handle
6743 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6744 going to be the section symbol corresponding to the output
6745 section, which means that the addend must be adjusted
6749 ppc_elf_relocate_section (bfd
*output_bfd
,
6750 struct bfd_link_info
*info
,
6752 asection
*input_section
,
6754 Elf_Internal_Rela
*relocs
,
6755 Elf_Internal_Sym
*local_syms
,
6756 asection
**local_sections
)
6758 Elf_Internal_Shdr
*symtab_hdr
;
6759 struct elf_link_hash_entry
**sym_hashes
;
6760 struct ppc_elf_link_hash_table
*htab
;
6761 Elf_Internal_Rela
*rel
;
6762 Elf_Internal_Rela
*relend
;
6763 Elf_Internal_Rela outrel
;
6764 asection
*got2
, *sreloc
= NULL
;
6765 bfd_vma
*local_got_offsets
;
6766 bfd_boolean ret
= TRUE
;
6767 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
6768 bfd_boolean is_vxworks_tls
;
6771 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
6772 "%ld relocations%s",
6773 input_bfd
, input_section
,
6774 (long) input_section
->reloc_count
,
6775 (info
->relocatable
) ? " (relocatable)" : "");
6778 got2
= bfd_get_section_by_name (input_bfd
, ".got2");
6780 /* Initialize howto table if not already done. */
6781 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
6782 ppc_elf_howto_init ();
6784 htab
= ppc_elf_hash_table (info
);
6785 local_got_offsets
= elf_local_got_offsets (input_bfd
);
6786 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6787 sym_hashes
= elf_sym_hashes (input_bfd
);
6788 /* We have to handle relocations in vxworks .tls_vars sections
6789 specially, because the dynamic loader is 'weird'. */
6790 is_vxworks_tls
= (htab
->is_vxworks
&& info
->shared
6791 && !strcmp (input_section
->output_section
->name
,
6794 relend
= relocs
+ input_section
->reloc_count
;
6795 for (; rel
< relend
; rel
++)
6797 enum elf_ppc_reloc_type r_type
;
6799 bfd_reloc_status_type r
;
6800 Elf_Internal_Sym
*sym
;
6802 struct elf_link_hash_entry
*h
;
6803 const char *sym_name
;
6804 reloc_howto_type
*howto
;
6805 unsigned long r_symndx
;
6807 bfd_vma branch_bit
, from
;
6808 bfd_boolean unresolved_reloc
;
6810 unsigned int tls_type
, tls_mask
, tls_gd
;
6811 struct plt_entry
**ifunc
;
6813 r_type
= ELF32_R_TYPE (rel
->r_info
);
6817 unresolved_reloc
= FALSE
;
6819 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6821 if (r_symndx
< symtab_hdr
->sh_info
)
6823 sym
= local_syms
+ r_symndx
;
6824 sec
= local_sections
[r_symndx
];
6825 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
6827 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
6831 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
6832 r_symndx
, symtab_hdr
, sym_hashes
,
6834 unresolved_reloc
, warned
);
6836 sym_name
= h
->root
.root
.string
;
6839 if (sec
!= NULL
&& elf_discarded_section (sec
))
6841 /* For relocs against symbols from removed linkonce sections,
6842 or sections discarded by a linker script, we just want the
6843 section contents zeroed. Avoid any special processing. */
6845 if (r_type
< R_PPC_max
)
6846 howto
= ppc_elf_howto_table
[r_type
];
6847 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
6853 if (info
->relocatable
)
6856 && r_type
== R_PPC_PLTREL24
6857 && rel
->r_addend
>= 32768)
6859 /* R_PPC_PLTREL24 is rather special. If non-zero, the
6860 addend specifies the GOT pointer offset within .got2. */
6861 rel
->r_addend
+= got2
->output_offset
;
6866 /* TLS optimizations. Replace instruction sequences and relocs
6867 based on information we collected in tls_optimize. We edit
6868 RELOCS so that --emit-relocs will output something sensible
6869 for the final instruction stream. */
6873 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
6874 else if (local_got_offsets
!= NULL
)
6876 struct plt_entry
**local_plt
;
6879 = (struct plt_entry
**) (local_got_offsets
+ symtab_hdr
->sh_info
);
6880 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
6881 tls_mask
= lgot_masks
[r_symndx
];
6884 /* Ensure reloc mapping code below stays sane. */
6885 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
6886 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
6887 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
6888 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
6889 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
6890 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
6891 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
6892 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
6899 case R_PPC_GOT_TPREL16
:
6900 case R_PPC_GOT_TPREL16_LO
:
6901 if ((tls_mask
& TLS_TLS
) != 0
6902 && (tls_mask
& TLS_TPREL
) == 0)
6906 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
6908 insn
|= 0x3c020000; /* addis 0,2,0 */
6909 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
6910 r_type
= R_PPC_TPREL16_HA
;
6911 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6916 if ((tls_mask
& TLS_TLS
) != 0
6917 && (tls_mask
& TLS_TPREL
) == 0)
6921 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
6922 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 2);
6925 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
6926 r_type
= R_PPC_TPREL16_LO
;
6927 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6929 /* Was PPC_TLS which sits on insn boundary, now
6930 PPC_TPREL16_LO which is at low-order half-word. */
6931 rel
->r_offset
+= d_offset
;
6935 case R_PPC_GOT_TLSGD16_HI
:
6936 case R_PPC_GOT_TLSGD16_HA
:
6937 tls_gd
= TLS_TPRELGD
;
6938 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6942 case R_PPC_GOT_TLSLD16_HI
:
6943 case R_PPC_GOT_TLSLD16_HA
:
6944 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6947 if ((tls_mask
& tls_gd
) != 0)
6948 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
6949 + R_PPC_GOT_TPREL16
);
6952 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
6953 rel
->r_offset
-= d_offset
;
6954 r_type
= R_PPC_NONE
;
6956 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
6960 case R_PPC_GOT_TLSGD16
:
6961 case R_PPC_GOT_TLSGD16_LO
:
6962 tls_gd
= TLS_TPRELGD
;
6963 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
6967 case R_PPC_GOT_TLSLD16
:
6968 case R_PPC_GOT_TLSLD16_LO
:
6969 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
6971 unsigned int insn1
, insn2
;
6975 offset
= (bfd_vma
) -1;
6976 /* If not using the newer R_PPC_TLSGD/LD to mark
6977 __tls_get_addr calls, we must trust that the call
6978 stays with its arg setup insns, ie. that the next
6979 reloc is the __tls_get_addr call associated with
6980 the current reloc. Edit both insns. */
6981 if (input_section
->has_tls_get_addr_call
6983 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
6984 htab
->tls_get_addr
))
6985 offset
= rel
[1].r_offset
;
6986 if ((tls_mask
& tls_gd
) != 0)
6989 insn1
= bfd_get_32 (output_bfd
,
6990 contents
+ rel
->r_offset
- d_offset
);
6991 insn1
&= (1 << 26) - 1;
6992 insn1
|= 32 << 26; /* lwz */
6993 if (offset
!= (bfd_vma
) -1)
6995 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
6996 insn2
= 0x7c631214; /* add 3,3,2 */
6997 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
6999 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
7000 + R_PPC_GOT_TPREL16
);
7001 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7006 insn1
= 0x3c620000; /* addis 3,2,0 */
7009 /* Was an LD reloc. */
7011 r_symndx
< symtab_hdr
->sh_info
;
7013 if (local_sections
[r_symndx
] == sec
)
7015 if (r_symndx
>= symtab_hdr
->sh_info
)
7017 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7019 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7020 + sec
->output_offset
7021 + sec
->output_section
->vma
);
7023 r_type
= R_PPC_TPREL16_HA
;
7024 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7025 if (offset
!= (bfd_vma
) -1)
7027 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7028 rel
[1].r_offset
= offset
+ d_offset
;
7029 rel
[1].r_addend
= rel
->r_addend
;
7030 insn2
= 0x38630000; /* addi 3,3,0 */
7031 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7034 bfd_put_32 (output_bfd
, insn1
,
7035 contents
+ rel
->r_offset
- d_offset
);
7038 /* We changed the symbol on an LD reloc. Start over
7039 in order to get h, sym, sec etc. right. */
7047 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
7050 bfd_vma offset
= rel
->r_offset
;
7052 if ((tls_mask
& TLS_TPRELGD
) != 0)
7055 r_type
= R_PPC_NONE
;
7056 insn2
= 0x7c631214; /* add 3,3,2 */
7061 r_type
= R_PPC_TPREL16_LO
;
7062 rel
->r_offset
+= d_offset
;
7063 insn2
= 0x38630000; /* addi 3,3,0 */
7065 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7066 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7067 /* Zap the reloc on the _tls_get_addr call too. */
7068 BFD_ASSERT (offset
== rel
[1].r_offset
);
7069 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7074 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
7079 r_symndx
< symtab_hdr
->sh_info
;
7081 if (local_sections
[r_symndx
] == sec
)
7083 if (r_symndx
>= symtab_hdr
->sh_info
)
7085 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7087 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7088 + sec
->output_offset
7089 + sec
->output_section
->vma
);
7091 rel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7092 rel
->r_offset
+= d_offset
;
7093 insn2
= 0x38630000; /* addi 3,3,0 */
7094 bfd_put_32 (output_bfd
, insn2
,
7095 contents
+ rel
->r_offset
- d_offset
);
7096 /* Zap the reloc on the _tls_get_addr call too. */
7097 BFD_ASSERT (rel
->r_offset
- d_offset
== rel
[1].r_offset
);
7098 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7105 /* Handle other relocations that tweak non-addend part of insn. */
7112 /* Branch taken prediction relocations. */
7113 case R_PPC_ADDR14_BRTAKEN
:
7114 case R_PPC_REL14_BRTAKEN
:
7115 branch_bit
= BRANCH_PREDICT_BIT
;
7118 /* Branch not taken prediction relocations. */
7119 case R_PPC_ADDR14_BRNTAKEN
:
7120 case R_PPC_REL14_BRNTAKEN
:
7124 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7125 insn
&= ~BRANCH_PREDICT_BIT
;
7128 from
= (rel
->r_offset
7129 + input_section
->output_offset
7130 + input_section
->output_section
->vma
);
7132 /* Invert 'y' bit if not the default. */
7133 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7134 insn
^= BRANCH_PREDICT_BIT
;
7136 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7142 if (!htab
->is_vxworks
)
7144 struct plt_entry
*ent
;
7148 if (h
->type
== STT_GNU_IFUNC
)
7149 ifunc
= &h
->plt
.plist
;
7151 else if (local_got_offsets
!= NULL
7152 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
7154 struct plt_entry
**local_plt
;
7156 local_plt
= (struct plt_entry
**) (local_got_offsets
7157 + symtab_hdr
->sh_info
);
7158 ifunc
= local_plt
+ r_symndx
;
7164 || is_branch_reloc (r_type
)))
7167 if (r_type
== R_PPC_PLTREL24
&& info
->shared
)
7168 addend
= rel
->r_addend
;
7169 ent
= find_plt_ent (ifunc
, got2
, addend
);
7173 if (h
== NULL
&& (ent
->plt
.offset
& 1) == 0)
7175 Elf_Internal_Rela rela
;
7178 rela
.r_offset
= (htab
->iplt
->output_section
->vma
7179 + htab
->iplt
->output_offset
7181 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7182 rela
.r_addend
= relocation
;
7183 loc
= htab
->reliplt
->contents
;
7184 loc
+= (htab
->reliplt
->reloc_count
++
7185 * sizeof (Elf32_External_Rela
));
7186 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
7188 ent
->plt
.offset
|= 1;
7190 if (h
== NULL
&& (ent
->glink_offset
& 1) == 0)
7192 unsigned char *p
= ((unsigned char *) htab
->glink
->contents
7193 + ent
->glink_offset
);
7194 write_glink_stub (ent
, htab
->iplt
, p
, info
);
7195 ent
->glink_offset
|= 1;
7198 unresolved_reloc
= FALSE
;
7199 if (htab
->plt_type
== PLT_NEW
7200 || !htab
->elf
.dynamic_sections_created
7202 relocation
= (htab
->glink
->output_section
->vma
7203 + htab
->glink
->output_offset
7204 + (ent
->glink_offset
& ~1));
7206 relocation
= (htab
->plt
->output_section
->vma
7207 + htab
->plt
->output_offset
7212 addend
= rel
->r_addend
;
7215 if (r_type
< R_PPC_max
)
7216 howto
= ppc_elf_howto_table
[r_type
];
7220 (*_bfd_error_handler
)
7221 (_("%B: unknown relocation type %d for symbol %s"),
7222 input_bfd
, (int) r_type
, sym_name
);
7224 bfd_set_error (bfd_error_bad_value
);
7232 case R_PPC_EMB_MRKREF
:
7233 case R_PPC_GNU_VTINHERIT
:
7234 case R_PPC_GNU_VTENTRY
:
7237 /* GOT16 relocations. Like an ADDR16 using the symbol's
7238 address in the GOT as relocation value instead of the
7239 symbol's value itself. Also, create a GOT entry for the
7240 symbol and put the symbol value there. */
7241 case R_PPC_GOT_TLSGD16
:
7242 case R_PPC_GOT_TLSGD16_LO
:
7243 case R_PPC_GOT_TLSGD16_HI
:
7244 case R_PPC_GOT_TLSGD16_HA
:
7245 tls_type
= TLS_TLS
| TLS_GD
;
7248 case R_PPC_GOT_TLSLD16
:
7249 case R_PPC_GOT_TLSLD16_LO
:
7250 case R_PPC_GOT_TLSLD16_HI
:
7251 case R_PPC_GOT_TLSLD16_HA
:
7252 tls_type
= TLS_TLS
| TLS_LD
;
7255 case R_PPC_GOT_TPREL16
:
7256 case R_PPC_GOT_TPREL16_LO
:
7257 case R_PPC_GOT_TPREL16_HI
:
7258 case R_PPC_GOT_TPREL16_HA
:
7259 tls_type
= TLS_TLS
| TLS_TPREL
;
7262 case R_PPC_GOT_DTPREL16
:
7263 case R_PPC_GOT_DTPREL16_LO
:
7264 case R_PPC_GOT_DTPREL16_HI
:
7265 case R_PPC_GOT_DTPREL16_HA
:
7266 tls_type
= TLS_TLS
| TLS_DTPREL
;
7270 case R_PPC_GOT16_LO
:
7271 case R_PPC_GOT16_HI
:
7272 case R_PPC_GOT16_HA
:
7276 /* Relocation is to the entry for this symbol in the global
7282 if (htab
->got
== NULL
)
7286 if (tls_type
== (TLS_TLS
| TLS_LD
)
7288 || !h
->def_dynamic
))
7289 offp
= &htab
->tlsld_got
.offset
;
7293 dyn
= htab
->elf
.dynamic_sections_created
;
7294 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7296 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
7297 /* This is actually a static link, or it is a
7298 -Bsymbolic link and the symbol is defined
7299 locally, or the symbol was forced to be local
7300 because of a version file. */
7305 unresolved_reloc
= FALSE
;
7307 offp
= &h
->got
.offset
;
7311 if (local_got_offsets
== NULL
)
7313 offp
= &local_got_offsets
[r_symndx
];
7316 /* The offset must always be a multiple of 4. We use the
7317 least significant bit to record whether we have already
7318 processed this entry. */
7324 unsigned int tls_m
= (tls_mask
7325 & (TLS_LD
| TLS_GD
| TLS_DTPREL
7326 | TLS_TPREL
| TLS_TPRELGD
));
7328 if (offp
== &htab
->tlsld_got
.offset
)
7334 /* We might have multiple got entries for this sym.
7335 Initialize them all. */
7340 if ((tls_m
& TLS_LD
) != 0)
7342 tls_ty
= TLS_TLS
| TLS_LD
;
7345 else if ((tls_m
& TLS_GD
) != 0)
7347 tls_ty
= TLS_TLS
| TLS_GD
;
7350 else if ((tls_m
& TLS_DTPREL
) != 0)
7352 tls_ty
= TLS_TLS
| TLS_DTPREL
;
7353 tls_m
&= ~TLS_DTPREL
;
7355 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
7357 tls_ty
= TLS_TLS
| TLS_TPREL
;
7361 /* Generate relocs for the dynamic linker. */
7362 if ((info
->shared
|| indx
!= 0)
7363 && (offp
== &htab
->tlsld_got
.offset
7365 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7366 || h
->root
.type
!= bfd_link_hash_undefweak
))
7368 asection
*rsec
= htab
->relgot
;
7371 outrel
.r_offset
= (htab
->got
->output_section
->vma
7372 + htab
->got
->output_offset
7374 outrel
.r_addend
= 0;
7375 if (tls_ty
& (TLS_LD
| TLS_GD
))
7377 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
7378 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7380 loc
= rsec
->contents
;
7381 loc
+= (rsec
->reloc_count
++
7382 * sizeof (Elf32_External_Rela
));
7383 bfd_elf32_swap_reloca_out (output_bfd
,
7385 outrel
.r_offset
+= 4;
7387 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7390 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
7391 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7392 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7393 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
7395 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
7396 else if (ifunc
!= NULL
)
7397 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7399 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7400 if (indx
== 0 && tls_ty
!= (TLS_TLS
| TLS_LD
))
7402 outrel
.r_addend
+= relocation
;
7403 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
7404 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
7406 loc
= rsec
->contents
;
7407 loc
+= (rsec
->reloc_count
++
7408 * sizeof (Elf32_External_Rela
));
7409 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7412 /* Init the .got section contents if we're not
7413 emitting a reloc. */
7416 bfd_vma value
= relocation
;
7418 if (tls_ty
== (TLS_TLS
| TLS_LD
))
7420 else if (tls_ty
!= 0)
7422 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7423 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7424 value
+= DTP_OFFSET
- TP_OFFSET
;
7426 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7428 bfd_put_32 (output_bfd
, value
,
7429 htab
->got
->contents
+ off
+ 4);
7433 bfd_put_32 (output_bfd
, value
,
7434 htab
->got
->contents
+ off
);
7438 if (tls_ty
& (TLS_LD
| TLS_GD
))
7447 if (off
>= (bfd_vma
) -2)
7450 if ((tls_type
& TLS_TLS
) != 0)
7452 if (tls_type
!= (TLS_TLS
| TLS_LD
))
7454 if ((tls_mask
& TLS_LD
) != 0
7456 || !h
->def_dynamic
))
7458 if (tls_type
!= (TLS_TLS
| TLS_GD
))
7460 if ((tls_mask
& TLS_GD
) != 0)
7462 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
7464 if ((tls_mask
& TLS_DTPREL
) != 0)
7471 relocation
= (htab
->got
->output_section
->vma
7472 + htab
->got
->output_offset
7474 - SYM_VAL (htab
->elf
.hgot
));
7476 /* Addends on got relocations don't make much sense.
7477 x+off@got is actually x@got+off, and since the got is
7478 generated by a hash table traversal, the value in the
7479 got at entry m+n bears little relation to the entry m. */
7481 (*_bfd_error_handler
)
7482 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
7485 (long) rel
->r_offset
,
7491 /* Relocations that need no special processing. */
7492 case R_PPC_LOCAL24PC
:
7493 /* It makes no sense to point a local relocation
7494 at a symbol not in this object. */
7495 if (unresolved_reloc
)
7497 if (! (*info
->callbacks
->undefined_symbol
) (info
,
7498 h
->root
.root
.string
,
7508 case R_PPC_DTPREL16
:
7509 case R_PPC_DTPREL16_LO
:
7510 case R_PPC_DTPREL16_HI
:
7511 case R_PPC_DTPREL16_HA
:
7512 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7515 /* Relocations that may need to be propagated if this is a shared
7518 case R_PPC_TPREL16_LO
:
7519 case R_PPC_TPREL16_HI
:
7520 case R_PPC_TPREL16_HA
:
7522 && h
->root
.type
== bfd_link_hash_undefweak
7523 && h
->dynindx
== -1)
7525 /* Make this relocation against an undefined weak symbol
7526 resolve to zero. This is really just a tweak, since
7527 code using weak externs ought to check that they are
7528 defined before using them. */
7529 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
7530 unsigned int insn
= bfd_get_32 (output_bfd
, p
);
7531 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 2);
7533 bfd_put_32 (output_bfd
, insn
, p
);
7536 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7537 /* The TPREL16 relocs shouldn't really be used in shared
7538 libs as they will result in DT_TEXTREL being set, but
7539 support them anyway. */
7543 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7546 case R_PPC_DTPREL32
:
7547 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7550 case R_PPC_DTPMOD32
:
7556 case R_PPC_REL16_LO
:
7557 case R_PPC_REL16_HI
:
7558 case R_PPC_REL16_HA
:
7562 if (h
== NULL
|| h
== htab
->elf
.hgot
)
7568 case R_PPC_ADDR16_LO
:
7569 case R_PPC_ADDR16_HI
:
7570 case R_PPC_ADDR16_HA
:
7577 case R_PPC_REL14_BRTAKEN
:
7578 case R_PPC_REL14_BRNTAKEN
:
7579 /* If these relocations are not to a named symbol, they can be
7580 handled right here, no need to bother the dynamic linker. */
7581 if (SYMBOL_CALLS_LOCAL (info
, h
)
7582 || h
== htab
->elf
.hgot
)
7588 case R_PPC_ADDR14_BRTAKEN
:
7589 case R_PPC_ADDR14_BRNTAKEN
:
7590 if (h
!= NULL
&& !info
->shared
)
7595 if ((input_section
->flags
& SEC_ALLOC
) == 0
7601 && ((h
->root
.type
== bfd_link_hash_undefined
7602 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
7603 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
7604 || (h
->root
.type
== bfd_link_hash_undefweak
7605 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)))
7606 && (must_be_dyn_reloc (info
, r_type
)
7607 || !SYMBOL_CALLS_LOCAL (info
, h
)))
7608 || (ELIMINATE_COPY_RELOCS
7613 && !h
->def_regular
))
7618 fprintf (stderr
, "ppc_elf_relocate_section needs to "
7619 "create relocation for %s\n",
7620 (h
&& h
->root
.root
.string
7621 ? h
->root
.root
.string
: "<unknown>"));
7624 /* When generating a shared object, these relocations
7625 are copied into the output file to be resolved at run
7629 sreloc
= elf_section_data (input_section
)->sreloc
;
7630 if (!htab
->elf
.dynamic_sections_created
)
7631 sreloc
= htab
->reliplt
;
7638 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
7640 if (outrel
.r_offset
== (bfd_vma
) -1
7641 || outrel
.r_offset
== (bfd_vma
) -2)
7642 skip
= (int) outrel
.r_offset
;
7643 outrel
.r_offset
+= (input_section
->output_section
->vma
7644 + input_section
->output_offset
);
7647 memset (&outrel
, 0, sizeof outrel
);
7649 && (h
->root
.type
== bfd_link_hash_undefined
7650 || h
->root
.type
== bfd_link_hash_undefweak
))
7651 || !SYMBOL_REFERENCES_LOCAL (info
, h
))
7653 unresolved_reloc
= FALSE
;
7654 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
7655 outrel
.r_addend
= rel
->r_addend
;
7659 outrel
.r_addend
= relocation
+ rel
->r_addend
;
7661 if (r_type
!= R_PPC_ADDR32
)
7667 /* If we get here when building a static
7668 executable, then the libc startup function
7669 responsible for applying indirect function
7670 relocations is going to complain about
7672 If we get here when building a dynamic
7673 executable, it will be because we have
7674 a text relocation. The dynamic loader
7675 will set the text segment writable and
7676 non-executable to apply text relocations.
7677 So we'll segfault when trying to run the
7678 indirection function to resolve the reloc. */
7679 (*_bfd_error_handler
)
7680 (_("%B(%A+0x%lx): relocation %s for indirect "
7681 "function %s unsupported"),
7684 (long) rel
->r_offset
,
7689 else if (r_symndx
== 0 || bfd_is_abs_section (sec
))
7691 else if (sec
== NULL
|| sec
->owner
== NULL
)
7693 bfd_set_error (bfd_error_bad_value
);
7700 /* We are turning this relocation into one
7701 against a section symbol. It would be
7702 proper to subtract the symbol's value,
7703 osec->vma, from the emitted reloc addend,
7704 but ld.so expects buggy relocs.
7705 FIXME: Why not always use a zero index? */
7706 osec
= sec
->output_section
;
7707 indx
= elf_section_data (osec
)->dynindx
;
7710 osec
= htab
->elf
.text_index_section
;
7711 indx
= elf_section_data (osec
)->dynindx
;
7713 BFD_ASSERT (indx
!= 0);
7716 printf ("indx=%ld section=%s flags=%08x name=%s\n",
7717 indx
, osec
->name
, osec
->flags
,
7718 h
->root
.root
.string
);
7722 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
7724 else if (ifunc
!= NULL
)
7725 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7727 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7730 loc
= sreloc
->contents
;
7731 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7732 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7737 /* This reloc will be computed at runtime. We clear the memory
7738 so that it contains predictable value. */
7740 && ((input_section
->flags
& SEC_ALLOC
) != 0
7741 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
7743 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
7750 case R_PPC_RELAX_PLT
:
7751 case R_PPC_RELAX_PLTREL24
:
7754 struct plt_entry
*ent
;
7755 bfd_vma got2_addend
= 0;
7757 if (r_type
== R_PPC_RELAX_PLTREL24
)
7760 got2_addend
= addend
;
7763 ent
= find_plt_ent (&h
->plt
.plist
, got2
, got2_addend
);
7764 if (htab
->plt_type
== PLT_NEW
)
7765 relocation
= (htab
->glink
->output_section
->vma
7766 + htab
->glink
->output_offset
7767 + ent
->glink_offset
);
7769 relocation
= (htab
->plt
->output_section
->vma
7770 + htab
->plt
->output_offset
7777 relocation
-= (input_section
->output_section
->vma
7778 + input_section
->output_offset
7779 + rel
->r_offset
- 4);
7785 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7786 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
7788 /* We're clearing the bits for R_PPC_ADDR16_HA
7789 and R_PPC_ADDR16_LO here. */
7793 /* t0 is HA, t1 is LO */
7794 relocation
+= addend
;
7795 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
7796 t1
|= relocation
& 0xffff;
7798 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
7799 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
7801 /* Rewrite the reloc and convert one of the trailing nop
7802 relocs to describe this relocation. */
7803 BFD_ASSERT (ELF32_R_TYPE (relend
[-1].r_info
) == R_PPC_NONE
);
7804 /* The relocs are at the bottom 2 bytes */
7805 rel
[0].r_offset
+= 2;
7806 memmove (rel
+ 1, rel
, (relend
- rel
- 1) * sizeof (*rel
));
7807 rel
[0].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
7808 rel
[1].r_offset
+= 4;
7809 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
7814 /* Indirect .sdata relocation. */
7815 case R_PPC_EMB_SDAI16
:
7816 BFD_ASSERT (htab
->sdata
[0].section
!= NULL
);
7817 if (!is_static_defined (htab
->sdata
[0].sym
))
7819 unresolved_reloc
= TRUE
;
7823 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[0],
7824 h
, relocation
, rel
);
7828 /* Indirect .sdata2 relocation. */
7829 case R_PPC_EMB_SDA2I16
:
7830 BFD_ASSERT (htab
->sdata
[1].section
!= NULL
);
7831 if (!is_static_defined (htab
->sdata
[1].sym
))
7833 unresolved_reloc
= TRUE
;
7837 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[1],
7838 h
, relocation
, rel
);
7842 /* Handle the TOC16 reloc. We want to use the offset within the .got
7843 section, not the actual VMA. This is appropriate when generating
7844 an embedded ELF object, for which the .got section acts like the
7845 AIX .toc section. */
7846 case R_PPC_TOC16
: /* phony GOT16 relocations */
7847 if (sec
== NULL
|| sec
->output_section
== NULL
)
7849 unresolved_reloc
= TRUE
;
7852 BFD_ASSERT (strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
7853 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
7855 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
7858 case R_PPC_PLTREL24
:
7859 if (h
== NULL
|| ifunc
!= NULL
)
7861 /* Relocation is to the entry for this symbol in the
7862 procedure linkage table. */
7864 struct plt_entry
*ent
= find_plt_ent (&h
->plt
.plist
, got2
,
7865 info
->shared
? addend
: 0);
7868 || htab
->plt
== NULL
)
7870 /* We didn't make a PLT entry for this symbol. This
7871 happens when statically linking PIC code, or when
7872 using -Bsymbolic. */
7876 unresolved_reloc
= FALSE
;
7877 if (htab
->plt_type
== PLT_NEW
)
7878 relocation
= (htab
->glink
->output_section
->vma
7879 + htab
->glink
->output_offset
7880 + ent
->glink_offset
);
7882 relocation
= (htab
->plt
->output_section
->vma
7883 + htab
->plt
->output_offset
7888 /* Relocate against _SDA_BASE_. */
7889 case R_PPC_SDAREL16
:
7892 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
7895 || sec
->output_section
== NULL
7896 || !is_static_defined (sda
))
7898 unresolved_reloc
= TRUE
;
7901 addend
-= SYM_VAL (sda
);
7903 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7904 if (! ((CONST_STRNEQ (name
, ".sdata")
7905 && (name
[6] == 0 || name
[6] == '.'))
7906 || (CONST_STRNEQ (name
, ".sbss")
7907 && (name
[5] == 0 || name
[5] == '.'))))
7909 (*_bfd_error_handler
)
7910 (_("%B: the target (%s) of a %s relocation is "
7911 "in the wrong output section (%s)"),
7920 /* Relocate against _SDA2_BASE_. */
7921 case R_PPC_EMB_SDA2REL
:
7924 struct elf_link_hash_entry
*sda
= htab
->sdata
[1].sym
;
7927 || sec
->output_section
== NULL
7928 || !is_static_defined (sda
))
7930 unresolved_reloc
= TRUE
;
7933 addend
-= SYM_VAL (sda
);
7935 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7936 if (! (CONST_STRNEQ (name
, ".sdata2")
7937 || CONST_STRNEQ (name
, ".sbss2")))
7939 (*_bfd_error_handler
)
7940 (_("%B: the target (%s) of a %s relocation is "
7941 "in the wrong output section (%s)"),
7950 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
7951 case R_PPC_EMB_SDA21
:
7952 case R_PPC_EMB_RELSDA
:
7956 struct elf_link_hash_entry
*sda
= NULL
;
7958 if (sec
== NULL
|| sec
->output_section
== NULL
)
7960 unresolved_reloc
= TRUE
;
7964 name
= bfd_get_section_name (abfd
, sec
->output_section
);
7965 if (((CONST_STRNEQ (name
, ".sdata")
7966 && (name
[6] == 0 || name
[6] == '.'))
7967 || (CONST_STRNEQ (name
, ".sbss")
7968 && (name
[5] == 0 || name
[5] == '.'))))
7971 sda
= htab
->sdata
[0].sym
;
7973 else if (CONST_STRNEQ (name
, ".sdata2")
7974 || CONST_STRNEQ (name
, ".sbss2"))
7977 sda
= htab
->sdata
[1].sym
;
7979 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
7980 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
7986 (*_bfd_error_handler
)
7987 (_("%B: the target (%s) of a %s relocation is "
7988 "in the wrong output section (%s)"),
7994 bfd_set_error (bfd_error_bad_value
);
8001 if (!is_static_defined (sda
))
8003 unresolved_reloc
= TRUE
;
8006 addend
-= SYM_VAL (sda
);
8009 if (r_type
== R_PPC_EMB_SDA21
)
8011 bfd_vma insn
; /* Fill in register field. */
8013 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
8014 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
8015 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
8020 /* Relocate against the beginning of the section. */
8022 case R_PPC_SECTOFF_LO
:
8023 case R_PPC_SECTOFF_HI
:
8024 case R_PPC_SECTOFF_HA
:
8025 if (sec
== NULL
|| sec
->output_section
== NULL
)
8027 unresolved_reloc
= TRUE
;
8030 addend
-= sec
->output_section
->vma
;
8033 /* Negative relocations. */
8034 case R_PPC_EMB_NADDR32
:
8035 case R_PPC_EMB_NADDR16
:
8036 case R_PPC_EMB_NADDR16_LO
:
8037 case R_PPC_EMB_NADDR16_HI
:
8038 case R_PPC_EMB_NADDR16_HA
:
8039 addend
-= 2 * relocation
;
8043 case R_PPC_GLOB_DAT
:
8044 case R_PPC_JMP_SLOT
:
8045 case R_PPC_RELATIVE
:
8046 case R_PPC_IRELATIVE
:
8048 case R_PPC_PLTREL32
:
8049 case R_PPC_PLT16_LO
:
8050 case R_PPC_PLT16_HI
:
8051 case R_PPC_PLT16_HA
:
8053 case R_PPC_EMB_RELSEC16
:
8054 case R_PPC_EMB_RELST_LO
:
8055 case R_PPC_EMB_RELST_HI
:
8056 case R_PPC_EMB_RELST_HA
:
8057 case R_PPC_EMB_BIT_FLD
:
8058 (*_bfd_error_handler
)
8059 (_("%B: relocation %s is not yet supported for symbol %s."),
8064 bfd_set_error (bfd_error_invalid_operation
);
8069 /* Do any further special processing. */
8075 case R_PPC_ADDR16_HA
:
8076 case R_PPC_REL16_HA
:
8077 case R_PPC_SECTOFF_HA
:
8078 case R_PPC_TPREL16_HA
:
8079 case R_PPC_DTPREL16_HA
:
8080 case R_PPC_EMB_NADDR16_HA
:
8081 case R_PPC_EMB_RELST_HA
:
8082 /* It's just possible that this symbol is a weak symbol
8083 that's not actually defined anywhere. In that case,
8084 'sec' would be NULL, and we should leave the symbol
8085 alone (it will be set to zero elsewhere in the link). */
8090 case R_PPC_PLT16_HA
:
8091 case R_PPC_GOT16_HA
:
8092 case R_PPC_GOT_TLSGD16_HA
:
8093 case R_PPC_GOT_TLSLD16_HA
:
8094 case R_PPC_GOT_TPREL16_HA
:
8095 case R_PPC_GOT_DTPREL16_HA
:
8096 /* Add 0x10000 if sign bit in 0:15 is set.
8097 Bits 0:15 are not used. */
8103 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
8104 "offset = %ld, addend = %ld\n",
8109 (long) rel
->r_offset
,
8113 if (unresolved_reloc
8114 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8117 (*_bfd_error_handler
)
8118 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8121 (long) rel
->r_offset
,
8127 r
= _bfd_final_link_relocate (howto
,
8135 if (r
!= bfd_reloc_ok
)
8137 if (r
== bfd_reloc_overflow
)
8142 && h
->root
.type
== bfd_link_hash_undefweak
8143 && howto
->pc_relative
)
8145 /* Assume this is a call protected by other code that
8146 detect the symbol is undefined. If this is the case,
8147 we can safely ignore the overflow. If not, the
8148 program is hosed anyway, and a little warning isn't
8154 if (! (*info
->callbacks
->reloc_overflow
) (info
,
8155 (h
? &h
->root
: NULL
),
8166 (*_bfd_error_handler
)
8167 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
8168 input_bfd
, input_section
,
8169 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
8176 fprintf (stderr
, "\n");
8182 /* Finish up dynamic symbol handling. We set the contents of various
8183 dynamic sections here. */
8186 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8187 struct bfd_link_info
*info
,
8188 struct elf_link_hash_entry
*h
,
8189 Elf_Internal_Sym
*sym
)
8191 struct ppc_elf_link_hash_table
*htab
;
8192 struct plt_entry
*ent
;
8193 bfd_boolean doneone
;
8196 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
8197 h
->root
.root
.string
);
8200 htab
= ppc_elf_hash_table (info
);
8201 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
8204 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8205 if (ent
->plt
.offset
!= (bfd_vma
) -1)
8209 Elf_Internal_Rela rela
;
8211 bfd_vma reloc_index
;
8213 if (htab
->plt_type
== PLT_NEW
8214 || !htab
->elf
.dynamic_sections_created
8215 || h
->dynindx
== -1)
8216 reloc_index
= ent
->plt
.offset
/ 4;
8219 reloc_index
= ((ent
->plt
.offset
- htab
->plt_initial_entry_size
)
8220 / htab
->plt_slot_size
);
8221 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
8222 && htab
->plt_type
== PLT_OLD
)
8223 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
8226 /* This symbol has an entry in the procedure linkage table.
8228 if (htab
->plt_type
== PLT_VXWORKS
8229 && htab
->elf
.dynamic_sections_created
8230 && h
->dynindx
!= -1)
8233 const bfd_vma
*plt_entry
;
8235 /* The first three entries in .got.plt are reserved. */
8236 got_offset
= (reloc_index
+ 3) * 4;
8238 /* Use the right PLT. */
8239 plt_entry
= info
->shared
? ppc_elf_vxworks_pic_plt_entry
8240 : ppc_elf_vxworks_plt_entry
;
8242 /* Fill in the .plt on VxWorks. */
8245 bfd_put_32 (output_bfd
,
8246 plt_entry
[0] | PPC_HA (got_offset
),
8247 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
8248 bfd_put_32 (output_bfd
,
8249 plt_entry
[1] | PPC_LO (got_offset
),
8250 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
8254 bfd_vma got_loc
= got_offset
+ SYM_VAL (htab
->elf
.hgot
);
8256 bfd_put_32 (output_bfd
,
8257 plt_entry
[0] | PPC_HA (got_loc
),
8258 htab
->plt
->contents
+ ent
->plt
.offset
+ 0);
8259 bfd_put_32 (output_bfd
,
8260 plt_entry
[1] | PPC_LO (got_loc
),
8261 htab
->plt
->contents
+ ent
->plt
.offset
+ 4);
8264 bfd_put_32 (output_bfd
, plt_entry
[2],
8265 htab
->plt
->contents
+ ent
->plt
.offset
+ 8);
8266 bfd_put_32 (output_bfd
, plt_entry
[3],
8267 htab
->plt
->contents
+ ent
->plt
.offset
+ 12);
8269 /* This instruction is an immediate load. The value loaded is
8270 the byte offset of the R_PPC_JMP_SLOT relocation from the
8271 start of the .rela.plt section. The value is stored in the
8272 low-order 16 bits of the load instruction. */
8273 /* NOTE: It appears that this is now an index rather than a
8274 prescaled offset. */
8275 bfd_put_32 (output_bfd
,
8276 plt_entry
[4] | reloc_index
,
8277 htab
->plt
->contents
+ ent
->plt
.offset
+ 16);
8278 /* This instruction is a PC-relative branch whose target is
8279 the start of the PLT section. The address of this branch
8280 instruction is 20 bytes beyond the start of this PLT entry.
8281 The address is encoded in bits 6-29, inclusive. The value
8282 stored is right-shifted by two bits, permitting a 26-bit
8284 bfd_put_32 (output_bfd
,
8286 | (-(ent
->plt
.offset
+ 20) & 0x03fffffc)),
8287 htab
->plt
->contents
+ ent
->plt
.offset
+ 20);
8288 bfd_put_32 (output_bfd
, plt_entry
[6],
8289 htab
->plt
->contents
+ ent
->plt
.offset
+ 24);
8290 bfd_put_32 (output_bfd
, plt_entry
[7],
8291 htab
->plt
->contents
+ ent
->plt
.offset
+ 28);
8293 /* Fill in the GOT entry corresponding to this PLT slot with
8294 the address immediately after the the "bctr" instruction
8295 in this PLT entry. */
8296 bfd_put_32 (output_bfd
, (htab
->plt
->output_section
->vma
8297 + htab
->plt
->output_offset
8298 + ent
->plt
.offset
+ 16),
8299 htab
->sgotplt
->contents
+ got_offset
);
8303 /* Fill in a couple of entries in .rela.plt.unloaded. */
8304 loc
= htab
->srelplt2
->contents
8305 + ((VXWORKS_PLTRESOLVE_RELOCS
+ reloc_index
8306 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
)
8307 * sizeof (Elf32_External_Rela
));
8309 /* Provide the @ha relocation for the first instruction. */
8310 rela
.r_offset
= (htab
->plt
->output_section
->vma
8311 + htab
->plt
->output_offset
8312 + ent
->plt
.offset
+ 2);
8313 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8315 rela
.r_addend
= got_offset
;
8316 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8317 loc
+= sizeof (Elf32_External_Rela
);
8319 /* Provide the @l relocation for the second instruction. */
8320 rela
.r_offset
= (htab
->plt
->output_section
->vma
8321 + htab
->plt
->output_offset
8322 + ent
->plt
.offset
+ 6);
8323 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
8325 rela
.r_addend
= got_offset
;
8326 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8327 loc
+= sizeof (Elf32_External_Rela
);
8329 /* Provide a relocation for the GOT entry corresponding to this
8330 PLT slot. Point it at the middle of the .plt entry. */
8331 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8332 + htab
->sgotplt
->output_offset
8334 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
8336 rela
.r_addend
= ent
->plt
.offset
+ 16;
8337 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8340 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
8341 In particular, the offset for the relocation is not the
8342 address of the PLT entry for this function, as specified
8343 by the ABI. Instead, the offset is set to the address of
8344 the GOT slot for this function. See EABI 4.4.4.1. */
8345 rela
.r_offset
= (htab
->sgotplt
->output_section
->vma
8346 + htab
->sgotplt
->output_offset
8352 asection
*splt
= htab
->plt
;
8353 if (!htab
->elf
.dynamic_sections_created
8354 || h
->dynindx
== -1)
8357 rela
.r_offset
= (splt
->output_section
->vma
8358 + splt
->output_offset
8360 if (htab
->plt_type
== PLT_OLD
8361 || !htab
->elf
.dynamic_sections_created
8362 || h
->dynindx
== -1)
8364 /* We don't need to fill in the .plt. The ppc dynamic
8365 linker will fill it in. */
8369 bfd_vma val
= (htab
->glink_pltresolve
+ ent
->plt
.offset
8370 + htab
->glink
->output_section
->vma
8371 + htab
->glink
->output_offset
);
8372 bfd_put_32 (output_bfd
, val
,
8373 splt
->contents
+ ent
->plt
.offset
);
8377 /* Fill in the entry in the .rela.plt section. */
8379 if (!htab
->elf
.dynamic_sections_created
8380 || h
->dynindx
== -1)
8382 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
8384 && (h
->root
.type
== bfd_link_hash_defined
8385 || h
->root
.type
== bfd_link_hash_defweak
));
8386 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
8387 rela
.r_addend
= SYM_VAL (h
);
8390 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
8392 if (!htab
->elf
.dynamic_sections_created
8393 || h
->dynindx
== -1)
8394 loc
= (htab
->reliplt
->contents
8395 + (htab
->reliplt
->reloc_count
++
8396 * sizeof (Elf32_External_Rela
)));
8398 loc
= (htab
->relplt
->contents
8399 + reloc_index
* sizeof (Elf32_External_Rela
));
8400 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8402 if (!h
->def_regular
)
8404 /* Mark the symbol as undefined, rather than as
8405 defined in the .plt section. Leave the value if
8406 there were any relocations where pointer equality
8407 matters (this is a clue for the dynamic linker, to
8408 make function pointer comparisons work between an
8409 application and shared library), otherwise set it
8411 sym
->st_shndx
= SHN_UNDEF
;
8412 if (!h
->pointer_equality_needed
)
8414 else if (!h
->ref_regular_nonweak
)
8416 /* This breaks function pointer comparisons, but
8417 that is better than breaking tests for a NULL
8418 function pointer. */
8422 else if (h
->type
== STT_GNU_IFUNC
8425 /* Set the value of ifunc symbols in a non-pie
8426 executable to the glink entry. This is to avoid
8427 text relocations. We can't do this for ifunc in
8428 allocate_dynrelocs, as we do for normal dynamic
8429 function symbols with plt entries, because we need
8430 to keep the original value around for the ifunc
8432 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
8433 (output_bfd
, htab
->glink
->output_section
));
8434 sym
->st_value
= (ent
->glink_offset
+
8435 htab
->glink
->output_offset
8436 + htab
->glink
->output_section
->vma
);
8441 if (htab
->plt_type
== PLT_NEW
8442 || !htab
->elf
.dynamic_sections_created
8443 || h
->dynindx
== -1)
8446 asection
*splt
= htab
->plt
;
8447 if (!htab
->elf
.dynamic_sections_created
8448 || h
->dynindx
== -1)
8451 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
8453 if (h
== htab
->tls_get_addr
&& !htab
->no_tls_get_addr_opt
)
8455 bfd_put_32 (output_bfd
, LWZ_11_3
, p
);
8457 bfd_put_32 (output_bfd
, LWZ_12_3
+ 4, p
);
8459 bfd_put_32 (output_bfd
, MR_0_3
, p
);
8461 bfd_put_32 (output_bfd
, CMPWI_11_0
, p
);
8463 bfd_put_32 (output_bfd
, ADD_3_12_2
, p
);
8465 bfd_put_32 (output_bfd
, BEQLR
, p
);
8467 bfd_put_32 (output_bfd
, MR_3_0
, p
);
8469 bfd_put_32 (output_bfd
, NOP
, p
);
8473 write_glink_stub (ent
, splt
, p
, info
);
8476 /* We only need one non-PIC glink stub. */
8486 Elf_Internal_Rela rela
;
8489 /* This symbols needs a copy reloc. Set it up. */
8492 fprintf (stderr
, ", copy");
8495 BFD_ASSERT (h
->dynindx
!= -1);
8497 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
8501 BFD_ASSERT (s
!= NULL
);
8503 rela
.r_offset
= SYM_VAL (h
);
8504 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
8506 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
8507 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8511 fprintf (stderr
, "\n");
8514 /* Mark some specially defined symbols as absolute. */
8515 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
8516 || (!htab
->is_vxworks
8517 && (h
== htab
->elf
.hgot
8518 || strcmp (h
->root
.root
.string
,
8519 "_PROCEDURE_LINKAGE_TABLE_") == 0)))
8520 sym
->st_shndx
= SHN_ABS
;
8525 static enum elf_reloc_type_class
8526 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
8528 switch (ELF32_R_TYPE (rela
->r_info
))
8530 case R_PPC_RELATIVE
:
8531 return reloc_class_relative
;
8534 case R_PPC_JMP_SLOT
:
8535 return reloc_class_plt
;
8537 return reloc_class_copy
;
8539 return reloc_class_normal
;
8543 /* Finish up the dynamic sections. */
8546 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
8547 struct bfd_link_info
*info
)
8551 struct ppc_elf_link_hash_table
*htab
;
8554 bfd_boolean ret
= TRUE
;
8557 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
8560 htab
= ppc_elf_hash_table (info
);
8561 dynobj
= elf_hash_table (info
)->dynobj
;
8562 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8563 if (htab
->is_vxworks
)
8564 splt
= bfd_get_section_by_name (dynobj
, ".plt");
8569 if (htab
->elf
.hgot
!= NULL
)
8570 got
= SYM_VAL (htab
->elf
.hgot
);
8572 if (htab
->elf
.dynamic_sections_created
)
8574 Elf32_External_Dyn
*dyncon
, *dynconend
;
8576 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
8578 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
8579 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8580 for (; dyncon
< dynconend
; dyncon
++)
8582 Elf_Internal_Dyn dyn
;
8585 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8590 if (htab
->is_vxworks
)
8594 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8598 dyn
.d_un
.d_val
= htab
->relplt
->size
;
8603 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8607 dyn
.d_un
.d_ptr
= got
;
8611 if (htab
->is_vxworks
)
8614 dyn
.d_un
.d_ptr
-= htab
->relplt
->size
;
8620 if (htab
->is_vxworks
8621 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
8626 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8630 if (htab
->got
!= NULL
)
8632 if (htab
->elf
.hgot
->root
.u
.def
.section
== htab
->got
8633 || htab
->elf
.hgot
->root
.u
.def
.section
== htab
->sgotplt
)
8635 unsigned char *p
= htab
->elf
.hgot
->root
.u
.def
.section
->contents
;
8637 p
+= htab
->elf
.hgot
->root
.u
.def
.value
;
8638 if (htab
->plt_type
== PLT_OLD
)
8640 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
8641 so that a function can easily find the address of
8642 _GLOBAL_OFFSET_TABLE_. */
8643 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
- 4
8644 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8645 bfd_put_32 (output_bfd
, 0x4e800021, p
- 4);
8650 bfd_vma val
= sdyn
->output_section
->vma
+ sdyn
->output_offset
;
8651 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
8652 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
8653 bfd_put_32 (output_bfd
, val
, p
);
8658 (*_bfd_error_handler
) (_("%s not defined in linker created %s"),
8659 htab
->elf
.hgot
->root
.root
.string
,
8660 (htab
->sgotplt
!= NULL
8661 ? htab
->sgotplt
->name
: htab
->got
->name
));
8662 bfd_set_error (bfd_error_bad_value
);
8666 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
8669 /* Fill in the first entry in the VxWorks procedure linkage table. */
8670 if (splt
&& splt
->size
> 0)
8672 /* Use the right PLT. */
8673 static const bfd_vma
*plt_entry
= NULL
;
8674 plt_entry
= info
->shared
?
8675 ppc_elf_vxworks_pic_plt0_entry
: ppc_elf_vxworks_plt0_entry
;
8679 bfd_vma got_value
= SYM_VAL (htab
->elf
.hgot
);
8681 bfd_put_32 (output_bfd
, plt_entry
[0] | PPC_HA (got_value
),
8682 splt
->contents
+ 0);
8683 bfd_put_32 (output_bfd
, plt_entry
[1] | PPC_LO (got_value
),
8684 splt
->contents
+ 4);
8688 bfd_put_32 (output_bfd
, plt_entry
[0], splt
->contents
+ 0);
8689 bfd_put_32 (output_bfd
, plt_entry
[1], splt
->contents
+ 4);
8691 bfd_put_32 (output_bfd
, plt_entry
[2], splt
->contents
+ 8);
8692 bfd_put_32 (output_bfd
, plt_entry
[3], splt
->contents
+ 12);
8693 bfd_put_32 (output_bfd
, plt_entry
[4], splt
->contents
+ 16);
8694 bfd_put_32 (output_bfd
, plt_entry
[5], splt
->contents
+ 20);
8695 bfd_put_32 (output_bfd
, plt_entry
[6], splt
->contents
+ 24);
8696 bfd_put_32 (output_bfd
, plt_entry
[7], splt
->contents
+ 28);
8700 Elf_Internal_Rela rela
;
8703 loc
= htab
->srelplt2
->contents
;
8705 /* Output the @ha relocation for the first instruction. */
8706 rela
.r_offset
= (htab
->plt
->output_section
->vma
8707 + htab
->plt
->output_offset
8709 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8711 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8712 loc
+= sizeof (Elf32_External_Rela
);
8714 /* Output the @l relocation for the second instruction. */
8715 rela
.r_offset
= (htab
->plt
->output_section
->vma
8716 + htab
->plt
->output_offset
8718 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8720 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
8721 loc
+= sizeof (Elf32_External_Rela
);
8723 /* Fix up the remaining relocations. They may have the wrong
8724 symbol index for _G_O_T_ or _P_L_T_ depending on the order
8725 in which symbols were output. */
8726 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
8728 Elf_Internal_Rela rel
;
8730 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8731 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
8732 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8733 loc
+= sizeof (Elf32_External_Rela
);
8735 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8736 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
8737 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8738 loc
+= sizeof (Elf32_External_Rela
);
8740 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
8741 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_PPC_ADDR32
);
8742 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
8743 loc
+= sizeof (Elf32_External_Rela
);
8748 if (htab
->glink
!= NULL
8749 && htab
->glink
->contents
!= NULL
8750 && htab
->elf
.dynamic_sections_created
)
8753 unsigned char *endp
;
8758 * PIC glink code is the following:
8760 * # ith PLT code stub.
8761 * addis 11,30,(plt+(i-1)*4-got)@ha
8762 * lwz 11,(plt+(i-1)*4-got)@l(11)
8766 * # A table of branches, one for each plt entry.
8767 * # The idea is that the plt call stub loads ctr and r11 with these
8768 * # addresses, so (r11 - res_0) gives the plt index * 4.
8769 * res_0: b PLTresolve
8770 * res_1: b PLTresolve
8772 * # Some number of entries towards the end can be nops
8778 * addis 11,11,(1f-res_0)@ha
8781 * 1: addi 11,11,(1b-res_0)@l
8784 * sub 11,11,12 # r11 = index * 4
8785 * addis 12,12,(got+4-1b)@ha
8786 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
8787 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
8790 * add 11,0,11 # r11 = index * 12 = reloc offset.
8793 static const unsigned int pic_plt_resolve
[] =
8814 * Non-PIC glink code is a little simpler.
8816 * # ith PLT code stub.
8817 * lis 11,(plt+(i-1)*4)@ha
8818 * lwz 11,(plt+(i-1)*4)@l(11)
8822 * The branch table is the same, then comes
8826 * addis 11,11,(-res_0)@ha
8827 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
8828 * addi 11,11,(-res_0)@l # r11 = index * 4
8831 * lwz 12,(got+8)@l(12) # got[2] contains the map address
8832 * add 11,0,11 # r11 = index * 12 = reloc offset.
8835 static const unsigned int plt_resolve
[] =
8855 if (ARRAY_SIZE (pic_plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8857 if (ARRAY_SIZE (plt_resolve
) != GLINK_PLTRESOLVE
/ 4)
8860 /* Build the branch table, one for each plt entry (less one),
8861 and perhaps some padding. */
8862 p
= htab
->glink
->contents
;
8863 p
+= htab
->glink_pltresolve
;
8864 endp
= htab
->glink
->contents
;
8865 endp
+= htab
->glink
->size
- GLINK_PLTRESOLVE
;
8866 while (p
< endp
- 8 * 4)
8868 bfd_put_32 (output_bfd
, B
+ endp
- p
, p
);
8873 bfd_put_32 (output_bfd
, NOP
, p
);
8877 res0
= (htab
->glink_pltresolve
8878 + htab
->glink
->output_section
->vma
8879 + htab
->glink
->output_offset
);
8881 /* Last comes the PLTresolve stub. */
8886 for (i
= 0; i
< ARRAY_SIZE (pic_plt_resolve
); i
++)
8888 bfd_put_32 (output_bfd
, pic_plt_resolve
[i
], p
);
8891 p
-= 4 * ARRAY_SIZE (pic_plt_resolve
);
8893 bcl
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 3*4
8894 + htab
->glink
->output_section
->vma
8895 + htab
->glink
->output_offset
);
8897 bfd_put_32 (output_bfd
,
8898 ADDIS_11_11
+ PPC_HA (bcl
- res0
), p
+ 0*4);
8899 bfd_put_32 (output_bfd
,
8900 ADDI_11_11
+ PPC_LO (bcl
- res0
), p
+ 3*4);
8901 bfd_put_32 (output_bfd
,
8902 ADDIS_12_12
+ PPC_HA (got
+ 4 - bcl
), p
+ 7*4);
8903 if (PPC_HA (got
+ 4 - bcl
) == PPC_HA (got
+ 8 - bcl
))
8905 bfd_put_32 (output_bfd
,
8906 LWZ_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8907 bfd_put_32 (output_bfd
,
8908 LWZ_12_12
+ PPC_LO (got
+ 8 - bcl
), p
+ 9*4);
8912 bfd_put_32 (output_bfd
,
8913 LWZU_0_12
+ PPC_LO (got
+ 4 - bcl
), p
+ 8*4);
8914 bfd_put_32 (output_bfd
,
8915 LWZ_12_12
+ 4, p
+ 9*4);
8920 for (i
= 0; i
< ARRAY_SIZE (plt_resolve
); i
++)
8922 bfd_put_32 (output_bfd
, plt_resolve
[i
], p
);
8925 p
-= 4 * ARRAY_SIZE (plt_resolve
);
8927 bfd_put_32 (output_bfd
,
8928 LIS_12
+ PPC_HA (got
+ 4), p
+ 0*4);
8929 bfd_put_32 (output_bfd
,
8930 ADDIS_11_11
+ PPC_HA (-res0
), p
+ 1*4);
8931 bfd_put_32 (output_bfd
,
8932 ADDI_11_11
+ PPC_LO (-res0
), p
+ 3*4);
8933 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
8935 bfd_put_32 (output_bfd
,
8936 LWZ_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8937 bfd_put_32 (output_bfd
,
8938 LWZ_12_12
+ PPC_LO (got
+ 8), p
+ 6*4);
8942 bfd_put_32 (output_bfd
,
8943 LWZU_0_12
+ PPC_LO (got
+ 4), p
+ 2*4);
8944 bfd_put_32 (output_bfd
,
8945 LWZ_12_12
+ 4, p
+ 6*4);
8953 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
8954 #define TARGET_LITTLE_NAME "elf32-powerpcle"
8955 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
8956 #define TARGET_BIG_NAME "elf32-powerpc"
8957 #define ELF_ARCH bfd_arch_powerpc
8958 #define ELF_MACHINE_CODE EM_PPC
8959 #ifdef __QNXTARGET__
8960 #define ELF_MAXPAGESIZE 0x1000
8962 #define ELF_MAXPAGESIZE 0x10000
8964 #define ELF_MINPAGESIZE 0x1000
8965 #define ELF_COMMONPAGESIZE 0x1000
8966 #define elf_info_to_howto ppc_elf_info_to_howto
8968 #ifdef EM_CYGNUS_POWERPC
8969 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
8973 #define ELF_MACHINE_ALT2 EM_PPC_OLD
8976 #define elf_backend_plt_not_loaded 1
8977 #define elf_backend_can_gc_sections 1
8978 #define elf_backend_can_refcount 1
8979 #define elf_backend_rela_normal 1
8981 #define bfd_elf32_mkobject ppc_elf_mkobject
8982 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
8983 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
8984 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
8985 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
8986 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
8987 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
8988 #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
8990 #define elf_backend_object_p ppc_elf_object_p
8991 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
8992 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
8993 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
8994 #define elf_backend_relocate_section ppc_elf_relocate_section
8995 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
8996 #define elf_backend_check_relocs ppc_elf_check_relocs
8997 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
8998 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
8999 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
9000 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
9001 #define elf_backend_hash_symbol ppc_elf_hash_symbol
9002 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
9003 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
9004 #define elf_backend_fake_sections ppc_elf_fake_sections
9005 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
9006 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
9007 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
9008 #define elf_backend_write_core_note ppc_elf_write_core_note
9009 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
9010 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
9011 #define elf_backend_final_write_processing ppc_elf_final_write_processing
9012 #define elf_backend_write_section ppc_elf_write_section
9013 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
9014 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
9015 #define elf_backend_action_discarded ppc_elf_action_discarded
9016 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
9017 #define elf_backend_post_process_headers _bfd_elf_set_osabi
9019 #include "elf32-target.h"
9021 /* VxWorks Target */
9023 #undef TARGET_LITTLE_SYM
9024 #undef TARGET_LITTLE_NAME
9026 #undef TARGET_BIG_SYM
9027 #define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
9028 #undef TARGET_BIG_NAME
9029 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
9031 /* VxWorks uses the elf default section flags for .plt. */
9032 static const struct bfd_elf_special_section
*
9033 ppc_elf_vxworks_get_sec_type_attr (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
)
9035 if (sec
->name
== NULL
)
9038 if (strcmp (sec
->name
, ".plt") == 0)
9039 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
9041 return ppc_elf_get_sec_type_attr (abfd
, sec
);
9044 /* Like ppc_elf_link_hash_table_create, but overrides
9045 appropriately for VxWorks. */
9046 static struct bfd_link_hash_table
*
9047 ppc_elf_vxworks_link_hash_table_create (bfd
*abfd
)
9049 struct bfd_link_hash_table
*ret
;
9051 ret
= ppc_elf_link_hash_table_create (abfd
);
9054 struct ppc_elf_link_hash_table
*htab
9055 = (struct ppc_elf_link_hash_table
*)ret
;
9056 htab
->is_vxworks
= 1;
9057 htab
->plt_type
= PLT_VXWORKS
;
9058 htab
->plt_entry_size
= VXWORKS_PLT_ENTRY_SIZE
;
9059 htab
->plt_slot_size
= VXWORKS_PLT_ENTRY_SIZE
;
9060 htab
->plt_initial_entry_size
= VXWORKS_PLT_INITIAL_ENTRY_SIZE
;
9065 /* Tweak magic VxWorks symbols as they are loaded. */
9067 ppc_elf_vxworks_add_symbol_hook (bfd
*abfd
,
9068 struct bfd_link_info
*info
,
9069 Elf_Internal_Sym
*sym
,
9070 const char **namep ATTRIBUTE_UNUSED
,
9071 flagword
*flagsp ATTRIBUTE_UNUSED
,
9075 if (!elf_vxworks_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
,
9079 return ppc_elf_add_symbol_hook(abfd
, info
, sym
,namep
, flagsp
, secp
, valp
);
9083 ppc_elf_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
9085 ppc_elf_final_write_processing(abfd
, linker
);
9086 elf_vxworks_final_write_processing(abfd
, linker
);
9089 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
9091 #undef elf_backend_want_plt_sym
9092 #define elf_backend_want_plt_sym 1
9093 #undef elf_backend_want_got_plt
9094 #define elf_backend_want_got_plt 1
9095 #undef elf_backend_got_symbol_offset
9096 #define elf_backend_got_symbol_offset 0
9097 #undef elf_backend_plt_not_loaded
9098 #define elf_backend_plt_not_loaded 0
9099 #undef elf_backend_plt_readonly
9100 #define elf_backend_plt_readonly 1
9101 #undef elf_backend_got_header_size
9102 #define elf_backend_got_header_size 12
9104 #undef bfd_elf32_get_synthetic_symtab
9106 #undef bfd_elf32_bfd_link_hash_table_create
9107 #define bfd_elf32_bfd_link_hash_table_create \
9108 ppc_elf_vxworks_link_hash_table_create
9109 #undef elf_backend_add_symbol_hook
9110 #define elf_backend_add_symbol_hook \
9111 ppc_elf_vxworks_add_symbol_hook
9112 #undef elf_backend_link_output_symbol_hook
9113 #define elf_backend_link_output_symbol_hook \
9114 elf_vxworks_link_output_symbol_hook
9115 #undef elf_backend_final_write_processing
9116 #define elf_backend_final_write_processing \
9117 ppc_elf_vxworks_final_write_processing
9118 #undef elf_backend_get_sec_type_attr
9119 #define elf_backend_get_sec_type_attr \
9120 ppc_elf_vxworks_get_sec_type_attr
9121 #undef elf_backend_emit_relocs
9122 #define elf_backend_emit_relocs \
9123 elf_vxworks_emit_relocs
9126 #define elf32_bed ppc_elf_vxworks_bed
9127 #undef elf_backend_post_process_headers
9129 #include "elf32-target.h"