1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on a preliminary PowerPC ELF ABI. The
23 information may not match the final PowerPC ELF ABI. It includes
24 suggestions from the in-progress Embedded PowerPC ABI, and that
25 information may also not match. */
34 #define USE_RELA /* we want RELA relocations, not REL */
36 static reloc_howto_type
*ppc_elf_reloc_type_lookup
37 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
38 static void ppc_elf_info_to_howto
39 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
40 static void ppc_elf_howto_init
PARAMS ((void));
41 static int ppc_elf_sort_rela
PARAMS ((const PTR
, const PTR
));
42 static boolean ppc_elf_relax_section
43 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
44 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
47 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
48 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
50 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
51 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
53 static boolean ppc_elf_create_dynamic_sections
54 PARAMS ((bfd
*, struct bfd_link_info
*));
56 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
57 Elf32_Internal_Shdr
*,
59 static boolean ppc_elf_fake_sections
60 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
62 static elf_linker_section_t
*ppc_elf_create_linker_section
64 struct bfd_link_info
*info
,
65 enum elf_linker_section_enum
));
67 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
68 struct bfd_link_info
*,
70 const Elf_Internal_Rela
*));
72 static asection
* ppc_elf_gc_mark_hook
PARAMS ((bfd
*abfd
,
73 struct bfd_link_info
*info
,
74 Elf_Internal_Rela
*rel
,
75 struct elf_link_hash_entry
*h
,
76 Elf_Internal_Sym
*sym
));
78 static boolean ppc_elf_gc_sweep_hook
PARAMS ((bfd
*abfd
,
79 struct bfd_link_info
*info
,
81 const Elf_Internal_Rela
*relocs
));
83 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
84 struct elf_link_hash_entry
*));
86 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
88 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
89 struct bfd_link_info
*info
,
93 Elf_Internal_Rela
*relocs
,
94 Elf_Internal_Sym
*local_syms
,
97 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
98 struct bfd_link_info
*,
99 const Elf_Internal_Sym
*,
105 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
106 struct bfd_link_info
*,
107 struct elf_link_hash_entry
*,
108 Elf_Internal_Sym
*));
110 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
111 static enum elf_reloc_type_class ppc_elf_reloc_type_class
PARAMS ((int));
113 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
114 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
115 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
117 /* The name of the dynamic interpreter. This is put in the .interp
120 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
122 /* The size in bytes of an entry in the procedure linkage table. */
123 #define PLT_ENTRY_SIZE 12
124 /* The initial size of the plt reserved for the dynamic linker. */
125 #define PLT_INITIAL_ENTRY_SIZE 72
126 /* The size of the gap between entries in the PLT. */
127 #define PLT_SLOT_SIZE 8
128 /* The number of single-slot PLT entries (the rest use two slots). */
129 #define PLT_NUM_SINGLE_ENTRIES 8192
131 /* Will references to this symbol always reference the symbol
133 #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
136 || H->dynindx == -1 \
137 || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \
138 || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \
139 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
141 /* Will _calls_ to this symbol always call the version in this object? */
142 #define SYMBOL_CALLS_LOCAL(INFO, H) \
145 || H->dynindx == -1 \
146 || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \
147 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
149 static reloc_howto_type
*ppc_elf_howto_table
[(int) R_PPC_max
];
151 static reloc_howto_type ppc_elf_howto_raw
[] = {
152 /* This reloc does nothing. */
153 HOWTO (R_PPC_NONE
, /* type */
155 2, /* size (0 = byte, 1 = short, 2 = long) */
157 false, /* pc_relative */
159 complain_overflow_bitfield
, /* complain_on_overflow */
160 bfd_elf_generic_reloc
, /* special_function */
161 "R_PPC_NONE", /* name */
162 false, /* partial_inplace */
165 false), /* pcrel_offset */
167 /* A standard 32 bit relocation. */
168 HOWTO (R_PPC_ADDR32
, /* type */
170 2, /* size (0 = byte, 1 = short, 2 = long) */
172 false, /* pc_relative */
174 complain_overflow_bitfield
, /* complain_on_overflow */
175 bfd_elf_generic_reloc
, /* special_function */
176 "R_PPC_ADDR32", /* name */
177 false, /* partial_inplace */
179 0xffffffff, /* dst_mask */
180 false), /* pcrel_offset */
182 /* An absolute 26 bit branch; the lower two bits must be zero.
183 FIXME: we don't check that, we just clear them. */
184 HOWTO (R_PPC_ADDR24
, /* type */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
188 false, /* pc_relative */
190 complain_overflow_bitfield
, /* complain_on_overflow */
191 bfd_elf_generic_reloc
, /* special_function */
192 "R_PPC_ADDR24", /* name */
193 false, /* partial_inplace */
195 0x3fffffc, /* dst_mask */
196 false), /* pcrel_offset */
198 /* A standard 16 bit relocation. */
199 HOWTO (R_PPC_ADDR16
, /* type */
201 1, /* size (0 = byte, 1 = short, 2 = long) */
203 false, /* pc_relative */
205 complain_overflow_bitfield
, /* complain_on_overflow */
206 bfd_elf_generic_reloc
, /* special_function */
207 "R_PPC_ADDR16", /* name */
208 false, /* partial_inplace */
210 0xffff, /* dst_mask */
211 false), /* pcrel_offset */
213 /* A 16 bit relocation without overflow. */
214 HOWTO (R_PPC_ADDR16_LO
, /* type */
216 1, /* size (0 = byte, 1 = short, 2 = long) */
218 false, /* pc_relative */
220 complain_overflow_dont
,/* complain_on_overflow */
221 bfd_elf_generic_reloc
, /* special_function */
222 "R_PPC_ADDR16_LO", /* name */
223 false, /* partial_inplace */
225 0xffff, /* dst_mask */
226 false), /* pcrel_offset */
228 /* The high order 16 bits of an address. */
229 HOWTO (R_PPC_ADDR16_HI
, /* type */
231 1, /* size (0 = byte, 1 = short, 2 = long) */
233 false, /* pc_relative */
235 complain_overflow_dont
, /* complain_on_overflow */
236 bfd_elf_generic_reloc
, /* special_function */
237 "R_PPC_ADDR16_HI", /* name */
238 false, /* partial_inplace */
240 0xffff, /* dst_mask */
241 false), /* pcrel_offset */
243 /* The high order 16 bits of an address, plus 1 if the contents of
244 the low 16 bits, treated as a signed number, is negative. */
245 HOWTO (R_PPC_ADDR16_HA
, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_dont
, /* complain_on_overflow */
252 ppc_elf_addr16_ha_reloc
, /* special_function */
253 "R_PPC_ADDR16_HA", /* name */
254 false, /* partial_inplace */
256 0xffff, /* dst_mask */
257 false), /* pcrel_offset */
259 /* An absolute 16 bit branch; the lower two bits must be zero.
260 FIXME: we don't check that, we just clear them. */
261 HOWTO (R_PPC_ADDR14
, /* type */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
265 false, /* pc_relative */
267 complain_overflow_bitfield
, /* complain_on_overflow */
268 bfd_elf_generic_reloc
, /* special_function */
269 "R_PPC_ADDR14", /* name */
270 false, /* partial_inplace */
272 0xfffc, /* dst_mask */
273 false), /* pcrel_offset */
275 /* An absolute 16 bit branch, for which bit 10 should be set to
276 indicate that the branch is expected to be taken. The lower two
277 bits must be zero. */
278 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 false, /* pc_relative */
284 complain_overflow_bitfield
, /* complain_on_overflow */
285 bfd_elf_generic_reloc
, /* special_function */
286 "R_PPC_ADDR14_BRTAKEN",/* name */
287 false, /* partial_inplace */
289 0xfffc, /* dst_mask */
290 false), /* pcrel_offset */
292 /* An absolute 16 bit branch, for which bit 10 should be set to
293 indicate that the branch is not expected to be taken. The lower
294 two bits must be zero. */
295 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
299 false, /* pc_relative */
301 complain_overflow_bitfield
, /* complain_on_overflow */
302 bfd_elf_generic_reloc
, /* special_function */
303 "R_PPC_ADDR14_BRNTAKEN",/* name */
304 false, /* partial_inplace */
306 0xfffc, /* dst_mask */
307 false), /* pcrel_offset */
309 /* A relative 26 bit branch; the lower two bits must be zero. */
310 HOWTO (R_PPC_REL24
, /* type */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 true, /* pc_relative */
316 complain_overflow_signed
, /* complain_on_overflow */
317 bfd_elf_generic_reloc
, /* special_function */
318 "R_PPC_REL24", /* name */
319 false, /* partial_inplace */
321 0x3fffffc, /* dst_mask */
322 true), /* pcrel_offset */
324 /* A relative 16 bit branch; the lower two bits must be zero. */
325 HOWTO (R_PPC_REL14
, /* type */
327 2, /* size (0 = byte, 1 = short, 2 = long) */
329 true, /* pc_relative */
331 complain_overflow_signed
, /* complain_on_overflow */
332 bfd_elf_generic_reloc
, /* special_function */
333 "R_PPC_REL14", /* name */
334 false, /* partial_inplace */
336 0xfffc, /* dst_mask */
337 true), /* pcrel_offset */
339 /* A relative 16 bit branch. Bit 10 should be set to indicate that
340 the branch is expected to be taken. The lower two bits must be
342 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 true, /* pc_relative */
348 complain_overflow_signed
, /* complain_on_overflow */
349 bfd_elf_generic_reloc
, /* special_function */
350 "R_PPC_REL14_BRTAKEN", /* name */
351 false, /* partial_inplace */
353 0xfffc, /* dst_mask */
354 true), /* pcrel_offset */
356 /* A relative 16 bit branch. Bit 10 should be set to indicate that
357 the branch is not expected to be taken. The lower two bits must
359 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 true, /* pc_relative */
365 complain_overflow_signed
, /* complain_on_overflow */
366 bfd_elf_generic_reloc
, /* special_function */
367 "R_PPC_REL14_BRNTAKEN",/* name */
368 false, /* partial_inplace */
370 0xfffc, /* dst_mask */
371 true), /* pcrel_offset */
373 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
375 HOWTO (R_PPC_GOT16
, /* type */
377 1, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_signed
, /* complain_on_overflow */
382 bfd_elf_generic_reloc
, /* special_function */
383 "R_PPC_GOT16", /* name */
384 false, /* partial_inplace */
386 0xffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
391 HOWTO (R_PPC_GOT16_LO
, /* type */
393 1, /* size (0 = byte, 1 = short, 2 = long) */
395 false, /* pc_relative */
397 complain_overflow_dont
, /* complain_on_overflow */
398 bfd_elf_generic_reloc
, /* special_function */
399 "R_PPC_GOT16_LO", /* name */
400 false, /* partial_inplace */
402 0xffff, /* dst_mask */
403 false), /* pcrel_offset */
405 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
407 HOWTO (R_PPC_GOT16_HI
, /* type */
409 1, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_bitfield
, /* complain_on_overflow */
414 bfd_elf_generic_reloc
, /* special_function */
415 "R_PPC_GOT16_HI", /* name */
416 false, /* partial_inplace */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
423 HOWTO (R_PPC_GOT16_HA
, /* type */
425 1, /* size (0 = byte, 1 = short, 2 = long) */
427 false, /* pc_relative */
429 complain_overflow_bitfield
, /* complain_on_overflow */
430 ppc_elf_addr16_ha_reloc
, /* special_function */
431 "R_PPC_GOT16_HA", /* name */
432 false, /* partial_inplace */
434 0xffff, /* dst_mask */
435 false), /* pcrel_offset */
437 /* Like R_PPC_REL24, but referring to the procedure linkage table
438 entry for the symbol. */
439 HOWTO (R_PPC_PLTREL24
, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 true, /* pc_relative */
445 complain_overflow_signed
, /* complain_on_overflow */
446 bfd_elf_generic_reloc
, /* special_function */
447 "R_PPC_PLTREL24", /* name */
448 false, /* partial_inplace */
450 0x3fffffc, /* dst_mask */
451 true), /* pcrel_offset */
453 /* This is used only by the dynamic linker. The symbol should exist
454 both in the object being run and in some shared library. The
455 dynamic linker copies the data addressed by the symbol from the
456 shared library into the object, because the object being
457 run has to have the data at some particular address. */
458 HOWTO (R_PPC_COPY
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_bitfield
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_PPC_COPY", /* name */
467 false, /* partial_inplace */
470 false), /* pcrel_offset */
472 /* Like R_PPC_ADDR32, but used when setting global offset table
474 HOWTO (R_PPC_GLOB_DAT
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 false, /* pc_relative */
480 complain_overflow_bitfield
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_PPC_GLOB_DAT", /* name */
483 false, /* partial_inplace */
485 0xffffffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* Marks a procedure linkage table entry for a symbol. */
489 HOWTO (R_PPC_JMP_SLOT
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_PPC_JMP_SLOT", /* name */
498 false, /* partial_inplace */
501 false), /* pcrel_offset */
503 /* Used only by the dynamic linker. When the object is run, this
504 longword is set to the load address of the object, plus the
506 HOWTO (R_PPC_RELATIVE
, /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 false, /* pc_relative */
512 complain_overflow_bitfield
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 "R_PPC_RELATIVE", /* name */
515 false, /* partial_inplace */
517 0xffffffff, /* dst_mask */
518 false), /* pcrel_offset */
520 /* Like R_PPC_REL24, but uses the value of the symbol within the
521 object rather than the final value. Normally used for
522 _GLOBAL_OFFSET_TABLE_. */
523 HOWTO (R_PPC_LOCAL24PC
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 true, /* pc_relative */
529 complain_overflow_signed
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_PPC_LOCAL24PC", /* name */
532 false, /* partial_inplace */
534 0x3fffffc, /* dst_mask */
535 true), /* pcrel_offset */
537 /* Like R_PPC_ADDR32, but may be unaligned. */
538 HOWTO (R_PPC_UADDR32
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 false, /* pc_relative */
544 complain_overflow_bitfield
, /* complain_on_overflow */
545 bfd_elf_generic_reloc
, /* special_function */
546 "R_PPC_UADDR32", /* name */
547 false, /* partial_inplace */
549 0xffffffff, /* dst_mask */
550 false), /* pcrel_offset */
552 /* Like R_PPC_ADDR16, but may be unaligned. */
553 HOWTO (R_PPC_UADDR16
, /* type */
555 1, /* size (0 = byte, 1 = short, 2 = long) */
557 false, /* pc_relative */
559 complain_overflow_bitfield
, /* complain_on_overflow */
560 bfd_elf_generic_reloc
, /* special_function */
561 "R_PPC_UADDR16", /* name */
562 false, /* partial_inplace */
564 0xffff, /* dst_mask */
565 false), /* pcrel_offset */
567 /* 32-bit PC relative */
568 HOWTO (R_PPC_REL32
, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 true, /* pc_relative */
574 complain_overflow_bitfield
, /* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 "R_PPC_REL32", /* name */
577 false, /* partial_inplace */
579 0xffffffff, /* dst_mask */
580 true), /* pcrel_offset */
582 /* 32-bit relocation to the symbol's procedure linkage table.
583 FIXME: not supported. */
584 HOWTO (R_PPC_PLT32
, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_bitfield
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_PPC_PLT32", /* name */
593 false, /* partial_inplace */
596 false), /* pcrel_offset */
598 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
599 FIXME: not supported. */
600 HOWTO (R_PPC_PLTREL32
, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 true, /* pc_relative */
606 complain_overflow_bitfield
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 "R_PPC_PLTREL32", /* name */
609 false, /* partial_inplace */
612 true), /* pcrel_offset */
614 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
616 HOWTO (R_PPC_PLT16_LO
, /* type */
618 1, /* size (0 = byte, 1 = short, 2 = long) */
620 false, /* pc_relative */
622 complain_overflow_dont
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_PPC_PLT16_LO", /* name */
625 false, /* partial_inplace */
627 0xffff, /* dst_mask */
628 false), /* pcrel_offset */
630 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
632 HOWTO (R_PPC_PLT16_HI
, /* type */
634 1, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_bitfield
, /* complain_on_overflow */
639 bfd_elf_generic_reloc
, /* special_function */
640 "R_PPC_PLT16_HI", /* name */
641 false, /* partial_inplace */
643 0xffff, /* dst_mask */
644 false), /* pcrel_offset */
646 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
648 HOWTO (R_PPC_PLT16_HA
, /* type */
650 1, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_bitfield
, /* complain_on_overflow */
655 ppc_elf_addr16_ha_reloc
, /* special_function */
656 "R_PPC_PLT16_HA", /* name */
657 false, /* partial_inplace */
659 0xffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
664 HOWTO (R_PPC_SDAREL16
, /* type */
666 1, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_signed
, /* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_PPC_SDAREL16", /* name */
673 false, /* partial_inplace */
675 0xffff, /* dst_mask */
676 false), /* pcrel_offset */
678 /* 32-bit section relative relocation. */
679 HOWTO (R_PPC_SECTOFF
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 true, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC_SECTOFF", /* name */
688 false, /* partial_inplace */
691 true), /* pcrel_offset */
693 /* 16-bit lower half section relative relocation. */
694 HOWTO (R_PPC_SECTOFF_LO
, /* type */
696 1, /* size (0 = byte, 1 = short, 2 = long) */
698 false, /* pc_relative */
700 complain_overflow_dont
, /* complain_on_overflow */
701 bfd_elf_generic_reloc
, /* special_function */
702 "R_PPC_SECTOFF_LO", /* name */
703 false, /* partial_inplace */
705 0xffff, /* dst_mask */
706 false), /* pcrel_offset */
708 /* 16-bit upper half section relative relocation. */
709 HOWTO (R_PPC_SECTOFF_HI
, /* type */
711 1, /* size (0 = byte, 1 = short, 2 = long) */
713 false, /* pc_relative */
715 complain_overflow_bitfield
, /* complain_on_overflow */
716 bfd_elf_generic_reloc
, /* special_function */
717 "R_PPC_SECTOFF_HI", /* name */
718 false, /* partial_inplace */
720 0xffff, /* dst_mask */
721 false), /* pcrel_offset */
723 /* 16-bit upper half adjusted section relative relocation. */
724 HOWTO (R_PPC_SECTOFF_HA
, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_bitfield
, /* complain_on_overflow */
731 ppc_elf_addr16_ha_reloc
, /* special_function */
732 "R_PPC_SECTOFF_HA", /* name */
733 false, /* partial_inplace */
735 0xffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* The remaining relocs are from the Embedded ELF ABI, and are not
739 in the SVR4 ELF ABI. */
741 /* 32 bit value resulting from the addend minus the symbol */
742 HOWTO (R_PPC_EMB_NADDR32
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 false, /* pc_relative */
748 complain_overflow_bitfield
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_PPC_EMB_NADDR32", /* name */
751 false, /* partial_inplace */
753 0xffffffff, /* dst_mask */
754 false), /* pcrel_offset */
756 /* 16 bit value resulting from the addend minus the symbol */
757 HOWTO (R_PPC_EMB_NADDR16
, /* type */
759 1, /* size (0 = byte, 1 = short, 2 = long) */
761 false, /* pc_relative */
763 complain_overflow_bitfield
, /* complain_on_overflow */
764 bfd_elf_generic_reloc
, /* special_function */
765 "R_PPC_EMB_NADDR16", /* name */
766 false, /* partial_inplace */
768 0xffff, /* dst_mask */
769 false), /* pcrel_offset */
771 /* 16 bit value resulting from the addend minus the symbol */
772 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
774 1, /* size (0 = byte, 1 = short, 2 = long) */
776 false, /* pc_relative */
778 complain_overflow_dont
,/* complain_on_overflow */
779 bfd_elf_generic_reloc
, /* special_function */
780 "R_PPC_EMB_ADDR16_LO", /* name */
781 false, /* partial_inplace */
783 0xffff, /* dst_mask */
784 false), /* pcrel_offset */
786 /* The high order 16 bits of the addend minus the symbol */
787 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
789 1, /* size (0 = byte, 1 = short, 2 = long) */
791 false, /* pc_relative */
793 complain_overflow_dont
, /* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* special_function */
795 "R_PPC_EMB_NADDR16_HI", /* name */
796 false, /* partial_inplace */
798 0xffff, /* dst_mask */
799 false), /* pcrel_offset */
801 /* The high order 16 bits of the result of the addend minus the address,
802 plus 1 if the contents of the low 16 bits, treated as a signed number,
804 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
806 1, /* size (0 = byte, 1 = short, 2 = long) */
808 false, /* pc_relative */
810 complain_overflow_dont
, /* complain_on_overflow */
811 ppc_elf_addr16_ha_reloc
, /* special_function */
812 "R_PPC_EMB_NADDR16_HA", /* name */
813 false, /* partial_inplace */
815 0xffff, /* dst_mask */
816 false), /* pcrel_offset */
818 /* 16 bit value resulting from allocating a 4 byte word to hold an
819 address in the .sdata section, and returning the offset from
820 _SDA_BASE_ for that relocation */
821 HOWTO (R_PPC_EMB_SDAI16
, /* type */
823 1, /* size (0 = byte, 1 = short, 2 = long) */
825 false, /* pc_relative */
827 complain_overflow_bitfield
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_PPC_EMB_SDAI16", /* name */
830 false, /* partial_inplace */
832 0xffff, /* dst_mask */
833 false), /* pcrel_offset */
835 /* 16 bit value resulting from allocating a 4 byte word to hold an
836 address in the .sdata2 section, and returning the offset from
837 _SDA2_BASE_ for that relocation */
838 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
840 1, /* size (0 = byte, 1 = short, 2 = long) */
842 false, /* pc_relative */
844 complain_overflow_bitfield
, /* complain_on_overflow */
845 bfd_elf_generic_reloc
, /* special_function */
846 "R_PPC_EMB_SDA2I16", /* name */
847 false, /* partial_inplace */
849 0xffff, /* dst_mask */
850 false), /* pcrel_offset */
852 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
854 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
856 1, /* size (0 = byte, 1 = short, 2 = long) */
858 false, /* pc_relative */
860 complain_overflow_signed
, /* complain_on_overflow */
861 bfd_elf_generic_reloc
, /* special_function */
862 "R_PPC_EMB_SDA2REL", /* name */
863 false, /* partial_inplace */
865 0xffff, /* dst_mask */
866 false), /* pcrel_offset */
868 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
869 signed offset from the appropriate base, and filling in the register
870 field with the appropriate register (0, 2, or 13). */
871 HOWTO (R_PPC_EMB_SDA21
, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 false, /* pc_relative */
877 complain_overflow_signed
, /* complain_on_overflow */
878 bfd_elf_generic_reloc
, /* special_function */
879 "R_PPC_EMB_SDA21", /* name */
880 false, /* partial_inplace */
882 0xffff, /* dst_mask */
883 false), /* pcrel_offset */
885 /* Relocation not handled: R_PPC_EMB_MRKREF */
886 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
887 /* Relocation not handled: R_PPC_EMB_RELST_LO */
888 /* Relocation not handled: R_PPC_EMB_RELST_HI */
889 /* Relocation not handled: R_PPC_EMB_RELST_HA */
890 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
892 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
893 in the 16 bit signed offset from the appropriate base, and filling in the
894 register field with the appropriate register (0, 2, or 13). */
895 HOWTO (R_PPC_EMB_RELSDA
, /* type */
897 1, /* size (0 = byte, 1 = short, 2 = long) */
899 true, /* pc_relative */
901 complain_overflow_signed
, /* complain_on_overflow */
902 bfd_elf_generic_reloc
, /* special_function */
903 "R_PPC_EMB_RELSDA", /* name */
904 false, /* partial_inplace */
906 0xffff, /* dst_mask */
907 false), /* pcrel_offset */
909 /* GNU extension to record C++ vtable hierarchy */
910 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
912 0, /* size (0 = byte, 1 = short, 2 = long) */
914 false, /* pc_relative */
916 complain_overflow_dont
, /* complain_on_overflow */
917 NULL
, /* special_function */
918 "R_PPC_GNU_VTINHERIT", /* name */
919 false, /* partial_inplace */
922 false), /* pcrel_offset */
924 /* GNU extension to record C++ vtable member usage */
925 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
927 0, /* size (0 = byte, 1 = short, 2 = long) */
929 false, /* pc_relative */
931 complain_overflow_dont
, /* complain_on_overflow */
932 NULL
, /* special_function */
933 "R_PPC_GNU_VTENTRY", /* name */
934 false, /* partial_inplace */
937 false), /* pcrel_offset */
939 /* Phony reloc to handle AIX style TOC entries */
940 HOWTO (R_PPC_TOC16
, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 false, /* pc_relative */
946 complain_overflow_signed
, /* complain_on_overflow */
947 bfd_elf_generic_reloc
, /* special_function */
948 "R_PPC_TOC16", /* name */
949 false, /* partial_inplace */
951 0xffff, /* dst_mask */
952 false), /* pcrel_offset */
955 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
958 ppc_elf_howto_init ()
960 unsigned int i
, type
;
962 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
964 type
= ppc_elf_howto_raw
[i
].type
;
965 BFD_ASSERT (type
< sizeof (ppc_elf_howto_table
) / sizeof (ppc_elf_howto_table
[0]));
966 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
970 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
972 The MPC860, revision C0 or earlier contains a bug in the die.
973 If all of the following conditions are true, the next instruction
974 to be executed *may* be treated as a no-op.
975 1/ A forward branch is executed.
976 2/ The branch is predicted as not taken.
977 3/ The branch is taken.
978 4/ The branch is located in the last 5 words of a page.
979 (The EOP limit is 5 by default but may be specified as any value from 1-10.)
981 Our software solution is to detect these problematic branches in a
982 linker pass and modify them as follows:
983 1/ Unconditional branches - Since these are always predicted taken,
984 there is no problem and no action is required.
985 2/ Conditional backward branches - No problem, no action required.
986 3/ Conditional forward branches - Ensure that the "inverse prediction
987 bit" is set (ensure it is predicted taken).
988 4/ Conditional register branches - Ensure that the "y bit" is set
989 (ensure it is predicted taken).
992 /* Sort sections by address. */
995 ppc_elf_sort_rela (arg1
, arg2
)
999 const Elf_Internal_Rela
**rela1
= (const Elf_Internal_Rela
**) arg1
;
1000 const Elf_Internal_Rela
**rela2
= (const Elf_Internal_Rela
**) arg2
;
1002 /* Sort by offset. */
1003 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1007 ppc_elf_relax_section (abfd
, isec
, link_info
, again
)
1010 struct bfd_link_info
*link_info
;
1013 #define PAGESIZE 0x1000
1015 bfd_byte
*contents
= NULL
;
1016 bfd_byte
*free_contents
= NULL
;
1017 Elf_Internal_Rela
*internal_relocs
= NULL
;
1018 Elf_Internal_Rela
*free_relocs
= NULL
;
1019 Elf_Internal_Rela
**rela_comb
= NULL
;
1020 int comb_curr
, comb_count
;
1022 /* We never have to do this more than once per input section. */
1025 /* If needed, initialize this section's cooked size. */
1026 if (isec
->_cooked_size
== 0)
1027 isec
->_cooked_size
= isec
->_raw_size
;
1029 /* We're only interested in text sections which overlap the
1030 troublesome area at the end of a page. */
1031 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1033 bfd_vma dot
, end_page
, end_section
;
1034 boolean section_modified
;
1036 /* Get the section contents. */
1037 /* Get cached copy if it exists. */
1038 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1039 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1042 /* Go get them off disk. */
1043 contents
= (bfd_byte
*) bfd_malloc (isec
->_raw_size
);
1044 if (contents
== NULL
)
1046 free_contents
= contents
;
1048 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1049 (file_ptr
) 0, isec
->_raw_size
))
1055 if (isec
->reloc_count
)
1059 /* Get a copy of the native relocations. */
1060 internal_relocs
= _bfd_elf32_link_read_relocs (
1061 abfd
, isec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1062 link_info
->keep_memory
);
1063 if (internal_relocs
== NULL
)
1065 if (! link_info
->keep_memory
)
1066 free_relocs
= internal_relocs
;
1068 /* Setup a faster access method for the reloc info we need. */
1069 rela_comb
= (Elf_Internal_Rela
**)
1070 bfd_malloc (isec
->reloc_count
*sizeof (Elf_Internal_Rela
*));
1071 if (rela_comb
== NULL
)
1073 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1077 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1078 if (r_type
< 0 || r_type
>= (int) R_PPC_max
)
1081 /* Prologue constants are sometimes present in the ".text"
1082 sections and they can be identified by their associated relocation.
1083 We don't want to process those words and some others which
1084 can also be identified by their relocations. However, not all
1085 conditional branches will have a relocation so we will
1086 only ignore words that 1) have a reloc, and 2) the reloc
1087 is not applicable to a conditional branch.
1088 The array rela_comb is built here for use in the EOP scan loop. */
1091 case R_PPC_ADDR14_BRNTAKEN
: /* absolute, predicted not taken */
1092 case R_PPC_REL14
: /* relative cond. br. */
1093 case R_PPC_REL14_BRNTAKEN
: /* rel. cond. br., predicted not taken */
1094 /* We should check the instruction. */
1097 /* The word is not a conditional branch - ignore it. */
1098 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1103 qsort (rela_comb
, (size_t) comb_count
, sizeof (int), ppc_elf_sort_rela
);
1106 /* Enumerate each EOP region that overlaps this section. */
1107 end_section
= isec
->vma
+ isec
->_cooked_size
;
1108 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1109 dot
-= link_info
->mpc860c0
;
1110 section_modified
= false;
1111 if (dot
< isec
->vma
) /* Increment the start position if this section */
1112 dot
= isec
->vma
; /* begins in the middle of its first EOP region. */
1115 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1118 /* Check each word in this EOP region. */
1119 for (; dot
< end_page
; dot
+= 4)
1121 bfd_vma isec_offset
;
1123 boolean skip
, modified
;
1125 /* Don't process this word if there is a relocation for it and
1126 the relocation indicates the word is not a conditional branch. */
1128 isec_offset
= dot
- isec
->vma
;
1129 for (; comb_curr
<comb_count
; ++comb_curr
)
1133 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1134 if (r_offset
>= isec_offset
)
1136 if (r_offset
== isec_offset
) skip
= true;
1142 /* Check the current word for a problematic conditional branch. */
1143 #define BO0(insn) ((insn) & 0x02000000)
1144 #define BO2(insn) ((insn) & 0x00800000)
1145 #define BO4(insn) ((insn) & 0x00200000)
1146 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1148 if ((insn
& 0xFc000000) == 0x40000000)
1150 /* Instruction is BCx */
1151 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1154 /* This branch is predicted as "normal".
1155 If this is a forward branch, it is problematic. */
1157 target
= insn
& 0x0000Fffc; /*extract*/
1158 target
= (target
^ 0x8000) - 0x8000; /*sign extend*/
1159 if ((insn
& 0x00000002) == 0)
1160 target
+= dot
; /*convert to abs*/
1163 insn
|= 0x00200000; /* set the prediction bit */
1168 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1170 /* Instruction is BCCTRx */
1171 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1173 /* This branch is predicted as not-taken.
1174 If this is a forward branch, it is problematic.
1175 Since we can't tell statically if it will branch forward,
1176 always set the prediction bit. */
1177 insn
|= 0x00200000; /* set the prediction bit */
1181 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1183 /* Instruction is BCLRx */
1184 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1186 /* This branch is predicted as not-taken.
1187 If this is a forward branch, it is problematic.
1188 Since we can't tell statically if it will branch forward,
1189 always set the prediction bit. */
1190 insn
|= 0x00200000; /* set the prediction bit */
1199 bfd_put_32 (abfd
, insn
, contents
+ isec_offset
);
1200 section_modified
= true;
1204 if (section_modified
)
1206 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1207 free_contents
= NULL
;
1211 if (rela_comb
!= NULL
)
1217 if (free_relocs
!= NULL
)
1223 if (free_contents
!= NULL
)
1225 if (! link_info
->keep_memory
)
1226 free (free_contents
);
1229 /* Cache the section contents for elf_link_input_bfd. */
1230 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1232 free_contents
= NULL
;
1238 if (rela_comb
!= NULL
)
1240 if (free_relocs
!= NULL
)
1242 if (free_contents
!= NULL
)
1243 free (free_contents
);
1247 static reloc_howto_type
*
1248 ppc_elf_reloc_type_lookup (abfd
, code
)
1249 bfd
*abfd ATTRIBUTE_UNUSED
;
1250 bfd_reloc_code_real_type code
;
1252 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1254 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1255 /* Initialize howto table if needed. */
1256 ppc_elf_howto_init ();
1261 return (reloc_howto_type
*) NULL
;
1263 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
1264 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
1265 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
1266 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
1267 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
1268 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
1269 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
1270 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
1271 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
1272 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
1273 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
1274 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
1275 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
1276 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
1277 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
1278 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
1279 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
1280 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
1281 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
1282 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
1283 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
1284 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
1285 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
1286 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
1287 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
1288 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
1289 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
1290 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
1291 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1292 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1293 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1294 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1295 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1296 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1297 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1298 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1299 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1300 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1301 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1302 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1303 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1304 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1305 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1306 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1307 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1308 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1309 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1310 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1311 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1312 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1313 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1314 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC_GNU_VTINHERIT
; break;
1315 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC_GNU_VTENTRY
; break;
1318 return ppc_elf_howto_table
[(int) ppc_reloc
];
1321 /* Set the howto pointer for a PowerPC ELF reloc. */
1324 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1325 bfd
*abfd ATTRIBUTE_UNUSED
;
1327 Elf32_Internal_Rela
*dst
;
1329 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1330 /* Initialize howto table if needed. */
1331 ppc_elf_howto_init ();
1333 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1334 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1337 /* Handle the R_PPC_ADDR16_HA reloc. */
1339 static bfd_reloc_status_type
1340 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1341 output_bfd
, error_message
)
1342 bfd
*abfd ATTRIBUTE_UNUSED
;
1343 arelent
*reloc_entry
;
1345 PTR data ATTRIBUTE_UNUSED
;
1346 asection
*input_section
;
1348 char **error_message ATTRIBUTE_UNUSED
;
1352 if (output_bfd
!= NULL
)
1354 reloc_entry
->address
+= input_section
->output_offset
;
1355 return bfd_reloc_ok
;
1358 if (reloc_entry
->address
> input_section
->_cooked_size
)
1359 return bfd_reloc_outofrange
;
1361 if (bfd_is_com_section (symbol
->section
))
1364 relocation
= symbol
->value
;
1366 relocation
+= symbol
->section
->output_section
->vma
;
1367 relocation
+= symbol
->section
->output_offset
;
1368 relocation
+= reloc_entry
->addend
;
1370 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1372 return bfd_reloc_continue
;
1375 /* Function to set whether a module needs the -mrelocatable bit set. */
1378 ppc_elf_set_private_flags (abfd
, flags
)
1382 BFD_ASSERT (!elf_flags_init (abfd
)
1383 || elf_elfheader (abfd
)->e_flags
== flags
);
1385 elf_elfheader (abfd
)->e_flags
= flags
;
1386 elf_flags_init (abfd
) = true;
1390 /* Copy backend specific data from one object module to another */
1392 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1396 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1397 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1400 BFD_ASSERT (!elf_flags_init (obfd
)
1401 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1403 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1404 elf_flags_init (obfd
) = true;
1408 /* Merge backend specific data from an object file to the output
1409 object file when linking */
1411 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1419 /* Check if we have the same endianess */
1420 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
1423 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1424 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1427 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1428 old_flags
= elf_elfheader (obfd
)->e_flags
;
1429 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1431 elf_flags_init (obfd
) = true;
1432 elf_elfheader (obfd
)->e_flags
= new_flags
;
1435 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1438 else /* Incompatible flags */
1440 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1443 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1444 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1447 (*_bfd_error_handler
)
1448 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1449 bfd_get_filename (ibfd
));
1451 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1452 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1455 (*_bfd_error_handler
)
1456 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1457 bfd_get_filename (ibfd
));
1460 /* The output is -mrelocatable-lib iff both the input files are. */
1461 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1462 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1464 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1465 but each input file is either -mrelocatable or -mrelocatable-lib. */
1466 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1467 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1468 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1469 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1471 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1472 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1474 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1475 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1477 /* Warn about any other mismatches */
1478 if (new_flags
!= old_flags
)
1481 (*_bfd_error_handler
)
1482 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1483 bfd_get_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1488 bfd_set_error (bfd_error_bad_value
);
1496 /* Handle a PowerPC specific section when reading an object file. This
1497 is called when elfcode.h finds a section with an unknown type. */
1500 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1502 Elf32_Internal_Shdr
*hdr
;
1508 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1511 newsect
= hdr
->bfd_section
;
1512 flags
= bfd_get_section_flags (abfd
, newsect
);
1513 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1514 flags
|= SEC_EXCLUDE
;
1516 if (hdr
->sh_type
== SHT_ORDERED
)
1517 flags
|= SEC_SORT_ENTRIES
;
1519 bfd_set_section_flags (abfd
, newsect
, flags
);
1523 /* Set up any other section flags and such that may be necessary. */
1526 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1527 bfd
*abfd ATTRIBUTE_UNUSED
;
1528 Elf32_Internal_Shdr
*shdr
;
1531 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1532 shdr
->sh_flags
|= SHF_EXCLUDE
;
1534 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1535 shdr
->sh_type
= SHT_ORDERED
;
1540 /* Create a special linker section */
1541 static elf_linker_section_t
*
1542 ppc_elf_create_linker_section (abfd
, info
, which
)
1544 struct bfd_link_info
*info
;
1545 enum elf_linker_section_enum which
;
1547 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1548 elf_linker_section_t
*lsect
;
1550 /* Record the first bfd section that needs the special section */
1552 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1554 /* If this is the first time, create the section */
1555 lsect
= elf_linker_section (dynobj
, which
);
1558 elf_linker_section_t defaults
;
1559 static elf_linker_section_t zero_section
;
1561 defaults
= zero_section
;
1562 defaults
.which
= which
;
1563 defaults
.hole_written_p
= false;
1564 defaults
.alignment
= 2;
1566 /* Both of these sections are (technically) created by the user
1567 putting data in them, so they shouldn't be marked
1570 The linker creates them so it has somewhere to attach their
1571 respective symbols. In fact, if they were empty it would
1572 be OK to leave the symbol set to 0 (or any random number), because
1573 the appropriate register should never be used. */
1574 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1580 (*_bfd_error_handler
) (_("%s: Unknown special linker type %d"),
1581 bfd_get_filename (abfd
),
1584 bfd_set_error (bfd_error_bad_value
);
1585 return (elf_linker_section_t
*) 0;
1587 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1588 defaults
.name
= ".sdata";
1589 defaults
.rel_name
= ".rela.sdata";
1590 defaults
.bss_name
= ".sbss";
1591 defaults
.sym_name
= "_SDA_BASE_";
1592 defaults
.sym_offset
= 32768;
1595 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1596 defaults
.name
= ".sdata2";
1597 defaults
.rel_name
= ".rela.sdata2";
1598 defaults
.bss_name
= ".sbss2";
1599 defaults
.sym_name
= "_SDA2_BASE_";
1600 defaults
.sym_offset
= 32768;
1601 defaults
.flags
|= SEC_READONLY
;
1605 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1611 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
1612 need to bump up the number of section headers. */
1615 ppc_elf_additional_program_headers (abfd
)
1623 s
= bfd_get_section_by_name (abfd
, ".interp");
1627 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1628 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1631 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1632 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1638 /* Modify the segment map if needed. */
1641 ppc_elf_modify_segment_map (abfd
)
1642 bfd
*abfd ATTRIBUTE_UNUSED
;
1647 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
1648 to output sections (just like _bfd_elf_create_dynamic_sections has
1649 to create .dynbss and .rela.bss). */
1652 ppc_elf_create_dynamic_sections (abfd
, info
)
1654 struct bfd_link_info
*info
;
1656 register asection
*s
;
1659 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
1662 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1663 | SEC_LINKER_CREATED
);
1665 s
= bfd_make_section (abfd
, ".dynsbss");
1667 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
1672 s
= bfd_make_section (abfd
, ".rela.sbss");
1674 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1675 || ! bfd_set_section_alignment (abfd
, s
, 2))
1681 /* Adjust a symbol defined by a dynamic object and referenced by a
1682 regular object. The current definition is in some section of the
1683 dynamic object, but we're not including those sections. We have to
1684 change the definition to something the rest of the link can
1688 ppc_elf_adjust_dynamic_symbol (info
, h
)
1689 struct bfd_link_info
*info
;
1690 struct elf_link_hash_entry
*h
;
1692 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1694 unsigned int power_of_two
;
1698 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1701 /* Make sure we know what is going on here. */
1702 BFD_ASSERT (dynobj
!= NULL
1703 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1704 || h
->weakdef
!= NULL
1705 || ((h
->elf_link_hash_flags
1706 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1707 && (h
->elf_link_hash_flags
1708 & ELF_LINK_HASH_REF_REGULAR
) != 0
1709 && (h
->elf_link_hash_flags
1710 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1712 /* If this is a function, put it in the procedure linkage table. We
1713 will fill in the contents of the procedure linkage table later,
1714 when we know the address of the .got section. */
1715 if (h
->type
== STT_FUNC
1716 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1718 if (! elf_hash_table (info
)->dynamic_sections_created
1719 || SYMBOL_CALLS_LOCAL (info
, h
)
1720 || (info
->shared
&& h
->plt
.refcount
<= 0))
1722 /* A PLT entry is not required/allowed when:
1724 1. We are not using ld.so; because then the PLT entry
1725 can't be set up, so we can't use one.
1727 2. We know for certain that a call to this symbol
1728 will go to this object.
1730 3. GC has rendered the entry unused.
1731 Note, however, that in an executable all references to the
1732 symbol go to the PLT, so we can't turn it off in that case.
1733 ??? The correct thing to do here is to reference count
1734 all uses of the symbol, not just those to the GOT or PLT. */
1735 h
->plt
.offset
= (bfd_vma
) -1;
1736 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1740 /* Make sure this symbol is output as a dynamic symbol. */
1741 if (h
->dynindx
== -1)
1743 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1746 BFD_ASSERT (h
->dynindx
!= -1);
1748 s
= bfd_get_section_by_name (dynobj
, ".plt");
1749 BFD_ASSERT (s
!= NULL
);
1751 /* If this is the first .plt entry, make room for the special
1753 if (s
->_raw_size
== 0)
1754 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1756 /* The PowerPC PLT is actually composed of two parts, the first part
1757 is 2 words (for a load and a jump), and then there is a remaining
1758 word available at the end. */
1759 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1761 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
1762 / PLT_ENTRY_SIZE
)));
1764 /* If this symbol is not defined in a regular file, and we are
1765 not generating a shared library, then set the symbol to this
1766 location in the .plt. This is required to make function
1767 pointers compare as equal between the normal executable and
1768 the shared library. */
1770 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1772 h
->root
.u
.def
.section
= s
;
1773 h
->root
.u
.def
.value
= plt_offset
;
1776 h
->plt
.offset
= plt_offset
;
1778 /* Make room for this entry. After the 8192nd entry, room
1779 for two entries is allocated. */
1780 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
1781 >= PLT_NUM_SINGLE_ENTRIES
)
1782 s
->_raw_size
+= 2 * PLT_ENTRY_SIZE
;
1784 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1786 /* We also need to make an entry in the .rela.plt section. */
1787 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1788 BFD_ASSERT (s
!= NULL
);
1789 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1794 /* If this is a weak symbol, and there is a real definition, the
1795 processor independent code will have arranged for us to see the
1796 real definition first, and we can just use the same value. */
1797 if (h
->weakdef
!= NULL
)
1799 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1800 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1801 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1802 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1806 /* This is a reference to a symbol defined by a dynamic object which
1807 is not a function. */
1809 /* If we are creating a shared library, we must presume that the
1810 only references to the symbol are via the global offset table.
1811 For such cases we need not do anything here; the relocations will
1812 be handled correctly by relocate_section. */
1816 /* We must allocate the symbol in our .dynbss section, which will
1817 become part of the .bss section of the executable. There will be
1818 an entry for this symbol in the .dynsym section. The dynamic
1819 object will contain position independent code, so all references
1820 from the dynamic object to this symbol will go through the global
1821 offset table. The dynamic linker will use the .dynsym entry to
1822 determine the address it must put in the global offset table, so
1823 both the dynamic object and the regular object will refer to the
1824 same memory location for the variable.
1826 Of course, if the symbol is sufficiently small, we must instead
1827 allocate it in .sbss. FIXME: It would be better to do this if and
1828 only if there were actually SDAREL relocs for that symbol. */
1830 if (h
->size
<= elf_gp_size (dynobj
))
1831 s
= bfd_get_section_by_name (dynobj
, ".dynsbss");
1833 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1834 BFD_ASSERT (s
!= NULL
);
1836 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1837 copy the initial value out of the dynamic object and into the
1838 runtime process image. We need to remember the offset into the
1839 .rela.bss section we are going to use. */
1840 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1844 if (h
->size
<= elf_gp_size (dynobj
))
1845 srel
= bfd_get_section_by_name (dynobj
, ".rela.sbss");
1847 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1848 BFD_ASSERT (srel
!= NULL
);
1849 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1850 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1853 /* We need to figure out the alignment required for this symbol. I
1854 have no idea how ELF linkers handle this. */
1855 power_of_two
= bfd_log2 (h
->size
);
1856 if (power_of_two
> 4)
1859 /* Apply the required alignment. */
1860 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1861 (bfd_size_type
) (1 << power_of_two
));
1862 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1864 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1868 /* Define the symbol as being at this point in the section. */
1869 h
->root
.u
.def
.section
= s
;
1870 h
->root
.u
.def
.value
= s
->_raw_size
;
1872 /* Increment the section size to make room for the symbol. */
1873 s
->_raw_size
+= h
->size
;
1878 /* Set the sizes of the dynamic sections. */
1881 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1882 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1883 struct bfd_link_info
*info
;
1891 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1894 dynobj
= elf_hash_table (info
)->dynobj
;
1895 BFD_ASSERT (dynobj
!= NULL
);
1897 if (elf_hash_table (info
)->dynamic_sections_created
)
1899 /* Set the contents of the .interp section to the interpreter. */
1902 s
= bfd_get_section_by_name (dynobj
, ".interp");
1903 BFD_ASSERT (s
!= NULL
);
1904 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1905 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1910 /* We may have created entries in the .rela.got, .rela.sdata, and
1911 .rela.sdata2 sections. However, if we are not creating the
1912 dynamic sections, we will not actually use these entries. Reset
1913 the size of .rela.got, et al, which will cause it to get
1914 stripped from the output file below. */
1915 static char *rela_sections
[] = { ".rela.got", ".rela.sdata",
1916 ".rela.sdata2", ".rela.sbss",
1920 for (p
= rela_sections
; *p
!= (char *) 0; p
++)
1922 s
= bfd_get_section_by_name (dynobj
, *p
);
1928 /* The check_relocs and adjust_dynamic_symbol entry points have
1929 determined the sizes of the various dynamic sections. Allocate
1933 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1938 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1941 /* It's OK to base decisions on the section name, because none
1942 of the dynobj section names depend upon the input files. */
1943 name
= bfd_get_section_name (dynobj
, s
);
1947 if (strcmp (name
, ".plt") == 0)
1949 if (s
->_raw_size
== 0)
1951 /* Strip this section if we don't need it; see the
1957 /* Remember whether there is a PLT. */
1961 else if (strncmp (name
, ".rela", 5) == 0)
1963 if (s
->_raw_size
== 0)
1965 /* If we don't need this section, strip it from the
1966 output file. This is mostly to handle .rela.bss and
1967 .rela.plt. We must create both sections in
1968 create_dynamic_sections, because they must be created
1969 before the linker maps input sections to output
1970 sections. The linker does that before
1971 adjust_dynamic_symbol is called, and it is that
1972 function which decides whether anything needs to go
1973 into these sections. */
1978 /* Remember whether there are any relocation sections. */
1981 /* We use the reloc_count field as a counter if we need
1982 to copy relocs into the output file. */
1986 else if (strcmp (name
, ".got") != 0
1987 && strcmp (name
, ".sdata") != 0
1988 && strcmp (name
, ".sdata2") != 0)
1990 /* It's not one of our sections, so don't allocate space. */
1996 _bfd_strip_section_from_output (info
, s
);
2000 /* Allocate memory for the section contents. */
2001 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2002 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2006 if (elf_hash_table (info
)->dynamic_sections_created
)
2008 /* Add some entries to the .dynamic section. We fill in the
2009 values later, in ppc_elf_finish_dynamic_sections, but we
2010 must add the entries now so that we get the correct size for
2011 the .dynamic section. The DT_DEBUG entry is filled in by the
2012 dynamic linker and used by the debugger. */
2015 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2021 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
2022 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2023 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2024 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2030 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2031 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2032 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2033 sizeof (Elf32_External_Rela
)))
2037 if ((info
->flags
& DF_TEXTREL
) != 0)
2039 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2041 info
->flags
|= DF_TEXTREL
;
2048 /* Look through the relocs for a section during the first phase, and
2049 allocate space in the global offset table or procedure linkage
2053 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
2055 struct bfd_link_info
*info
;
2057 const Elf_Internal_Rela
*relocs
;
2060 Elf_Internal_Shdr
*symtab_hdr
;
2061 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2062 const Elf_Internal_Rela
*rel
;
2063 const Elf_Internal_Rela
*rel_end
;
2064 bfd_signed_vma
*local_got_refcounts
;
2065 elf_linker_section_t
*sdata
;
2066 elf_linker_section_t
*sdata2
;
2068 asection
*sgot
= NULL
;
2069 asection
*srelgot
= NULL
;
2071 if (info
->relocateable
)
2075 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
2076 bfd_get_section_name (abfd
, sec
),
2077 bfd_get_filename (abfd
));
2080 /* Create the linker generated sections all the time so that the
2081 special symbols are created. */
2083 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
2085 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2090 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
2092 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
2097 dynobj
= elf_hash_table (info
)->dynobj
;
2098 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2099 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2101 sym_hashes
= elf_sym_hashes (abfd
);
2102 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
2103 if (!elf_bad_symtab (abfd
))
2104 sym_hashes_end
-= symtab_hdr
->sh_info
;
2108 rel_end
= relocs
+ sec
->reloc_count
;
2109 for (rel
= relocs
; rel
< rel_end
; rel
++)
2111 unsigned long r_symndx
;
2112 struct elf_link_hash_entry
*h
;
2114 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2115 if (r_symndx
< symtab_hdr
->sh_info
)
2118 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2120 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2121 This shows up in particular in an R_PPC_ADDR32 in the eabi
2123 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2128 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2129 if (! _bfd_elf_create_got_section (dynobj
, info
))
2131 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2132 BFD_ASSERT (sgot
!= NULL
);
2136 switch (ELF32_R_TYPE (rel
->r_info
))
2138 /* GOT16 relocations */
2140 case R_PPC_GOT16_LO
:
2141 case R_PPC_GOT16_HI
:
2142 case R_PPC_GOT16_HA
:
2143 /* This symbol requires a global offset table entry. */
2148 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2149 if (! _bfd_elf_create_got_section (dynobj
, info
))
2151 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2152 BFD_ASSERT (sgot
!= NULL
);
2156 && (h
!= NULL
|| info
->shared
))
2158 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2159 if (srelgot
== NULL
)
2161 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2163 || ! bfd_set_section_flags (dynobj
, srelgot
,
2168 | SEC_LINKER_CREATED
2170 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2177 if (h
->got
.refcount
== -1)
2179 /* Make sure this symbol is output as a dynamic symbol. */
2180 if (h
->dynindx
== -1)
2181 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
2184 /* Allocate space in the .got. */
2185 sgot
->_raw_size
+= 4;
2186 /* Allocate relocation space. */
2187 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2189 h
->got
.refcount
= 1;
2196 /* This is a global offset table entry for a local symbol. */
2197 if (local_got_refcounts
== NULL
)
2201 size
= symtab_hdr
->sh_info
* sizeof (bfd_signed_vma
);
2202 local_got_refcounts
= (bfd_signed_vma
*)
2203 bfd_alloc (abfd
, size
);
2204 if (local_got_refcounts
== NULL
)
2206 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2207 memset (local_got_refcounts
, -1, size
);
2209 if (local_got_refcounts
[r_symndx
] == -1)
2211 sgot
->_raw_size
+= 4;
2213 /* If we are generating a shared object, we need to
2214 output a R_PPC_RELATIVE reloc so that the
2215 dynamic linker can adjust this GOT entry. */
2217 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2219 local_got_refcounts
[r_symndx
] = 1;
2222 local_got_refcounts
[r_symndx
]++;
2226 /* Indirect .sdata relocation */
2227 case R_PPC_EMB_SDAI16
:
2230 ((*_bfd_error_handler
)
2231 (_("%s: relocation %s cannot be used when making a shared object"),
2232 bfd_get_filename (abfd
), "R_PPC_EMB_SDAI16"));
2236 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2238 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2239 if (srelgot
== NULL
)
2241 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2243 || ! bfd_set_section_flags (dynobj
, srelgot
,
2248 | SEC_LINKER_CREATED
2250 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2255 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
2260 /* Indirect .sdata2 relocation */
2261 case R_PPC_EMB_SDA2I16
:
2264 ((*_bfd_error_handler
)
2265 (_("%s: relocation %s cannot be used when making a shared object"),
2266 bfd_get_filename (abfd
), "R_PPC_EMB_SDA2I16"));
2270 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2272 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2273 if (srelgot
== NULL
)
2275 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2277 || ! bfd_set_section_flags (dynobj
, srelgot
,
2282 | SEC_LINKER_CREATED
2284 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2289 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
2294 case R_PPC_SDAREL16
:
2295 case R_PPC_EMB_SDA2REL
:
2296 case R_PPC_EMB_SDA21
:
2299 ((*_bfd_error_handler
)
2300 (_("%s: relocation %s cannot be used when making a shared object"),
2301 bfd_get_filename (abfd
),
2302 ppc_elf_howto_table
[(int) ELF32_R_TYPE (rel
->r_info
)]->name
));
2308 case R_PPC_PLTREL24
:
2309 case R_PPC_PLT16_LO
:
2310 case R_PPC_PLT16_HI
:
2311 case R_PPC_PLT16_HA
:
2313 fprintf (stderr
, "Reloc requires a PLT entry\n");
2315 /* This symbol requires a procedure linkage table entry. We
2316 actually build the entry in adjust_dynamic_symbol,
2317 because this might be a case of linking PIC code without
2318 linking in any dynamic objects, in which case we don't
2319 need to generate a procedure linkage table after all. */
2323 /* It does not make sense to have a procedure linkage
2324 table entry for a local symbol. */
2325 bfd_set_error (bfd_error_bad_value
);
2329 /* Make sure this symbol is output as a dynamic symbol. */
2330 if (h
->dynindx
== -1)
2332 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2335 if (h
->plt
.refcount
== -1)
2337 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2338 h
->plt
.refcount
= 1;
2344 /* The following relocations don't need to propagate the
2345 relocation if linking a shared object since they are
2346 section relative. */
2348 case R_PPC_SECTOFF_LO
:
2349 case R_PPC_SECTOFF_HI
:
2350 case R_PPC_SECTOFF_HA
:
2353 /* This refers only to functions defined in the shared library */
2354 case R_PPC_LOCAL24PC
:
2357 /* This relocation describes the C++ object vtable hierarchy.
2358 Reconstruct it for later use during GC. */
2359 case R_PPC_GNU_VTINHERIT
:
2360 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2364 /* This relocation describes which C++ vtable entries are actually
2365 used. Record for later use during GC. */
2366 case R_PPC_GNU_VTENTRY
:
2367 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2371 /* When creating a shared object, we must copy these
2372 relocs into the output file. We create a reloc
2373 section in dynobj and make room for the reloc. */
2376 case R_PPC_REL14_BRTAKEN
:
2377 case R_PPC_REL14_BRNTAKEN
:
2380 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2381 || SYMBOL_REFERENCES_LOCAL (info
, h
))
2389 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2390 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2396 name
= (bfd_elf_string_from_elf_section
2398 elf_elfheader (abfd
)->e_shstrndx
,
2399 elf_section_data (sec
)->rel_hdr
.sh_name
));
2403 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2404 && strcmp (bfd_get_section_name (abfd
, sec
),
2407 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2412 sreloc
= bfd_make_section (dynobj
, name
);
2413 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2414 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2415 if ((sec
->flags
& SEC_ALLOC
) != 0)
2416 flags
|= SEC_ALLOC
| SEC_LOAD
;
2418 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2419 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2422 if (sec
->flags
& SEC_READONLY
)
2423 info
->flags
|= DF_TEXTREL
;
2426 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2428 /* FIXME: We should here do what the m68k and i386
2429 backends do: if the reloc is pc-relative, record it
2430 in case it turns out that the reloc is unnecessary
2431 because the symbol is forced local by versioning or
2432 we are linking with -Bdynamic. Fortunately this
2433 case is not frequent. */
2443 /* Return the section that should be marked against GC for a given
2447 ppc_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2449 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2450 Elf_Internal_Rela
*rel
;
2451 struct elf_link_hash_entry
*h
;
2452 Elf_Internal_Sym
*sym
;
2456 switch (ELF32_R_TYPE (rel
->r_info
))
2458 case R_PPC_GNU_VTINHERIT
:
2459 case R_PPC_GNU_VTENTRY
:
2463 switch (h
->root
.type
)
2465 case bfd_link_hash_defined
:
2466 case bfd_link_hash_defweak
:
2467 return h
->root
.u
.def
.section
;
2469 case bfd_link_hash_common
:
2470 return h
->root
.u
.c
.p
->section
;
2479 if (!(elf_bad_symtab (abfd
)
2480 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2481 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2482 && sym
->st_shndx
!= SHN_COMMON
))
2484 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2491 /* Update the got entry reference counts for the section being removed. */
2494 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2496 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2498 const Elf_Internal_Rela
*relocs
;
2500 Elf_Internal_Shdr
*symtab_hdr
;
2501 struct elf_link_hash_entry
**sym_hashes
;
2502 bfd_signed_vma
*local_got_refcounts
;
2503 const Elf_Internal_Rela
*rel
, *relend
;
2504 unsigned long r_symndx
;
2505 struct elf_link_hash_entry
*h
;
2507 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2508 sym_hashes
= elf_sym_hashes (abfd
);
2509 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2511 relend
= relocs
+ sec
->reloc_count
;
2512 for (rel
= relocs
; rel
< relend
; rel
++)
2513 switch (ELF32_R_TYPE (rel
->r_info
))
2516 case R_PPC_GOT16_LO
:
2517 case R_PPC_GOT16_HI
:
2518 case R_PPC_GOT16_HA
:
2519 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2520 if (r_symndx
>= symtab_hdr
->sh_info
)
2522 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2523 if (h
->got
.refcount
> 0)
2526 else if (local_got_refcounts
!= NULL
)
2528 if (local_got_refcounts
[r_symndx
] > 0)
2529 local_got_refcounts
[r_symndx
]--;
2534 case R_PPC_PLTREL24
:
2535 case R_PPC_PLT16_LO
:
2536 case R_PPC_PLT16_HI
:
2537 case R_PPC_PLT16_HA
:
2538 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2539 if (r_symndx
>= symtab_hdr
->sh_info
)
2541 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2542 if (h
->plt
.refcount
> 0)
2554 /* Hook called by the linker routine which adds symbols from an object
2555 file. We use it to put .comm items in .sbss, and not .bss. */
2558 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2560 struct bfd_link_info
*info
;
2561 const Elf_Internal_Sym
*sym
;
2562 const char **namep ATTRIBUTE_UNUSED
;
2563 flagword
*flagsp ATTRIBUTE_UNUSED
;
2567 if (sym
->st_shndx
== SHN_COMMON
2568 && !info
->relocateable
2569 && sym
->st_size
<= elf_gp_size (abfd
))
2571 /* Common symbols less than or equal to -G nn bytes are automatically
2573 elf_linker_section_t
*sdata
2574 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2576 if (!sdata
->bss_section
)
2578 /* We don't go through bfd_make_section, because we don't
2579 want to attach this common section to DYNOBJ. The linker
2580 will move the symbols to the appropriate output section
2581 when it defines common symbols. */
2582 sdata
->bss_section
= ((asection
*)
2583 bfd_zalloc (abfd
, sizeof (asection
)));
2584 if (sdata
->bss_section
== NULL
)
2586 sdata
->bss_section
->name
= sdata
->bss_name
;
2587 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2588 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2589 sdata
->bss_section
->symbol
=
2590 (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
2591 sdata
->bss_section
->symbol_ptr_ptr
=
2592 (asymbol
**) bfd_zalloc (abfd
, sizeof (asymbol
*));
2593 if (sdata
->bss_section
->symbol
== NULL
2594 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2596 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2597 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2598 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2599 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2602 *secp
= sdata
->bss_section
;
2603 *valp
= sym
->st_size
;
2609 /* Finish up dynamic symbol handling. We set the contents of various
2610 dynamic sections here. */
2613 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2615 struct bfd_link_info
*info
;
2616 struct elf_link_hash_entry
*h
;
2617 Elf_Internal_Sym
*sym
;
2622 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
2623 h
->root
.root
.string
);
2626 dynobj
= elf_hash_table (info
)->dynobj
;
2627 BFD_ASSERT (dynobj
!= NULL
);
2629 if (h
->plt
.offset
!= (bfd_vma
) -1)
2633 Elf_Internal_Rela rela
;
2634 bfd_vma reloc_index
;
2637 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
2640 /* This symbol has an entry in the procedure linkage table. Set
2643 BFD_ASSERT (h
->dynindx
!= -1);
2645 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2646 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2647 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2649 /* We don't need to fill in the .plt. The ppc dynamic linker
2652 /* Fill in the entry in the .rela.plt section. */
2653 rela
.r_offset
= (splt
->output_section
->vma
2654 + splt
->output_offset
2656 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2659 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
2660 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
2661 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
2662 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2663 ((Elf32_External_Rela
*) srela
->contents
2666 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2668 /* Mark the symbol as undefined, rather than as defined in
2669 the .plt section. Leave the value alone. */
2670 sym
->st_shndx
= SHN_UNDEF
;
2671 /* If the symbol is weak, we do need to clear the value.
2672 Otherwise, the PLT entry would provide a definition for
2673 the symbol even if the symbol wasn't defined anywhere,
2674 and so the symbol would never be NULL. */
2675 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
2681 if (h
->got
.offset
!= (bfd_vma
) -1)
2685 Elf_Internal_Rela rela
;
2687 /* This symbol has an entry in the global offset table. Set it
2690 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2691 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
2692 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2694 rela
.r_offset
= (sgot
->output_section
->vma
2695 + sgot
->output_offset
2696 + (h
->got
.offset
&~ 1));
2698 /* If this is a -Bsymbolic link, and the symbol is defined
2699 locally, we just want to emit a RELATIVE reloc. The entry in
2700 the global offset table will already have been initialized in
2701 the relocate_section function. */
2703 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2705 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2706 rela
.r_addend
= (h
->root
.u
.def
.value
2707 + h
->root
.u
.def
.section
->output_section
->vma
2708 + h
->root
.u
.def
.section
->output_offset
);
2712 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
2713 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2714 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
2718 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2719 ((Elf32_External_Rela
*) srela
->contents
2720 + srela
->reloc_count
));
2721 ++srela
->reloc_count
;
2724 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2727 Elf_Internal_Rela rela
;
2729 /* This symbols needs a copy reloc. Set it up. */
2732 fprintf (stderr
, ", copy");
2735 BFD_ASSERT (h
->dynindx
!= -1);
2737 if (h
->size
<= elf_gp_size (dynobj
))
2738 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2741 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2743 BFD_ASSERT (s
!= NULL
);
2745 rela
.r_offset
= (h
->root
.u
.def
.value
2746 + h
->root
.u
.def
.section
->output_section
->vma
2747 + h
->root
.u
.def
.section
->output_offset
);
2748 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2750 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2751 ((Elf32_External_Rela
*) s
->contents
2757 fprintf (stderr
, "\n");
2760 /* Mark some specially defined symbols as absolute. */
2761 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2762 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2763 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2764 sym
->st_shndx
= SHN_ABS
;
2769 /* Finish up the dynamic sections. */
2772 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2774 struct bfd_link_info
*info
;
2777 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2778 asection
*sgot
= bfd_get_section_by_name (dynobj
, ".got");
2781 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2784 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2786 if (elf_hash_table (info
)->dynamic_sections_created
)
2789 Elf32_External_Dyn
*dyncon
, *dynconend
;
2791 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2792 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2794 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2795 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2796 for (; dyncon
< dynconend
; dyncon
++)
2798 Elf_Internal_Dyn dyn
;
2802 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2806 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2807 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2808 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2809 default: name
= NULL
; size
= false; break;
2816 s
= bfd_get_section_by_name (output_bfd
, name
);
2822 dyn
.d_un
.d_ptr
= s
->vma
;
2825 if (s
->_cooked_size
!= 0)
2826 dyn
.d_un
.d_val
= s
->_cooked_size
;
2828 dyn
.d_un
.d_val
= s
->_raw_size
;
2831 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2836 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2837 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2840 unsigned char *contents
= sgot
->contents
;
2841 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2844 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2846 bfd_put_32 (output_bfd
,
2847 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2850 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2856 /* The RELOCATE_SECTION function is called by the ELF backend linker
2857 to handle the relocations for a section.
2859 The relocs are always passed as Rela structures; if the section
2860 actually uses Rel structures, the r_addend field will always be
2863 This function is responsible for adjust the section contents as
2864 necessary, and (if using Rela relocs and generating a
2865 relocateable output file) adjusting the reloc addend as
2868 This function does not have to worry about setting the reloc
2869 address or the reloc symbol index.
2871 LOCAL_SYMS is a pointer to the swapped in local symbols.
2873 LOCAL_SECTIONS is an array giving the section in the input file
2874 corresponding to the st_shndx field of each local symbol.
2876 The global hash table entry for the global symbols can be found
2877 via elf_sym_hashes (input_bfd).
2879 When generating relocateable output, this function must handle
2880 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2881 going to be the section symbol corresponding to the output
2882 section, which means that the addend must be adjusted
2886 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2887 contents
, relocs
, local_syms
, local_sections
)
2889 struct bfd_link_info
*info
;
2891 asection
*input_section
;
2893 Elf_Internal_Rela
*relocs
;
2894 Elf_Internal_Sym
*local_syms
;
2895 asection
**local_sections
;
2897 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2898 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2899 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2900 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2901 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2902 Elf_Internal_Rela
*rel
= relocs
;
2903 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2904 asection
*sreloc
= NULL
;
2907 bfd_vma
*local_got_offsets
;
2912 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2913 bfd_get_filename (input_bfd
),
2914 bfd_section_name(input_bfd
, input_section
),
2915 (long) input_section
->reloc_count
,
2916 (info
->relocateable
) ? " (relocatable)" : "");
2919 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2920 /* Initialize howto table if needed. */
2921 ppc_elf_howto_init ();
2923 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2928 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2929 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2932 for (; rel
< relend
; rel
++)
2934 enum elf_ppc_reloc_type r_type
= (enum elf_ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2935 bfd_vma offset
= rel
->r_offset
;
2936 bfd_vma addend
= rel
->r_addend
;
2937 bfd_reloc_status_type r
= bfd_reloc_other
;
2938 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*) 0;
2939 asection
*sec
= (asection
*) 0;
2940 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) 0;
2941 const char *sym_name
= (const char *) 0;
2942 reloc_howto_type
*howto
;
2943 unsigned long r_symndx
;
2945 int will_become_local
;
2947 /* Unknown relocation handling */
2948 if ((unsigned) r_type
>= (unsigned) R_PPC_max
2949 || !ppc_elf_howto_table
[(int) r_type
])
2951 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2952 bfd_get_filename (input_bfd
),
2955 bfd_set_error (bfd_error_bad_value
);
2960 howto
= ppc_elf_howto_table
[(int) r_type
];
2961 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2963 if (info
->relocateable
)
2965 /* This is a relocateable link. We don't have to change
2966 anything, unless the reloc is against a section symbol,
2967 in which case we have to adjust according to where the
2968 section symbol winds up in the output section. */
2969 if (r_symndx
< symtab_hdr
->sh_info
)
2971 sym
= local_syms
+ r_symndx
;
2972 if ((unsigned) ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2974 sec
= local_sections
[r_symndx
];
2975 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2980 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2990 /* This is a final link. */
2991 if (r_symndx
< symtab_hdr
->sh_info
)
2993 sym
= local_syms
+ r_symndx
;
2994 sec
= local_sections
[r_symndx
];
2995 sym_name
= "<local symbol>";
2997 relocation
= (sec
->output_section
->vma
2998 + sec
->output_offset
3000 /* Relocs to local symbols are always resolved. */
3001 will_become_local
= 1;
3005 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3006 while (h
->root
.type
== bfd_link_hash_indirect
3007 || h
->root
.type
== bfd_link_hash_warning
)
3008 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3009 sym_name
= h
->root
.root
.string
;
3011 /* Can this relocation be resolved immediately? */
3012 will_become_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
3014 if (h
->root
.type
== bfd_link_hash_defined
3015 || h
->root
.type
== bfd_link_hash_defweak
)
3017 sec
= h
->root
.u
.def
.section
;
3018 if (((r_type
== R_PPC_PLT32
3019 || r_type
== R_PPC_PLTREL24
)
3021 && h
->plt
.offset
!= (bfd_vma
) -1)
3022 || (r_type
== R_PPC_LOCAL24PC
3023 && sec
->output_section
== NULL
)
3024 || ((r_type
== R_PPC_GOT16
3025 || r_type
== R_PPC_GOT16_LO
3026 || r_type
== R_PPC_GOT16_HI
3027 || r_type
== R_PPC_GOT16_HA
)
3028 && elf_hash_table (info
)->dynamic_sections_created
3029 && (! info
->shared
|| ! will_become_local
))
3031 && ! will_become_local
3032 && ((input_section
->flags
& SEC_ALLOC
) != 0
3033 /* Testing SEC_DEBUGGING here may be wrong.
3034 It's here to avoid a crash when
3035 generating a shared library with DWARF
3036 debugging information. */
3037 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
3038 && (h
->elf_link_hash_flags
3039 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
3040 && (r_type
== R_PPC_ADDR32
3041 || r_type
== R_PPC_ADDR24
3042 || r_type
== R_PPC_ADDR16
3043 || r_type
== R_PPC_ADDR16_LO
3044 || r_type
== R_PPC_ADDR16_HI
3045 || r_type
== R_PPC_ADDR16_HA
3046 || r_type
== R_PPC_ADDR14
3047 || r_type
== R_PPC_ADDR14_BRTAKEN
3048 || r_type
== R_PPC_ADDR14_BRNTAKEN
3049 || r_type
== R_PPC_COPY
3050 || r_type
== R_PPC_GLOB_DAT
3051 || r_type
== R_PPC_JMP_SLOT
3052 || r_type
== R_PPC_UADDR32
3053 || r_type
== R_PPC_UADDR16
3054 || r_type
== R_PPC_SDAREL16
3055 || r_type
== R_PPC_EMB_NADDR32
3056 || r_type
== R_PPC_EMB_NADDR16
3057 || r_type
== R_PPC_EMB_NADDR16_LO
3058 || r_type
== R_PPC_EMB_NADDR16_HI
3059 || r_type
== R_PPC_EMB_NADDR16_HA
3060 || r_type
== R_PPC_EMB_SDAI16
3061 || r_type
== R_PPC_EMB_SDA2I16
3062 || r_type
== R_PPC_EMB_SDA2REL
3063 || r_type
== R_PPC_EMB_SDA21
3064 || r_type
== R_PPC_EMB_MRKREF
3065 || r_type
== R_PPC_EMB_BIT_FLD
3066 || r_type
== R_PPC_EMB_RELSDA
3067 || ((r_type
== R_PPC_REL24
3068 || r_type
== R_PPC_REL32
3069 || r_type
== R_PPC_REL14
3070 || r_type
== R_PPC_REL14_BRTAKEN
3071 || r_type
== R_PPC_REL14_BRNTAKEN
3072 || r_type
== R_PPC_RELATIVE
)
3073 && strcmp (h
->root
.root
.string
,
3074 "_GLOBAL_OFFSET_TABLE_") != 0))))
3076 /* In these cases, we don't need the relocation
3077 value. We check specially because in some
3078 obscure cases sec->output_section will be NULL. */
3081 else if (sec
->output_section
== NULL
)
3083 (*_bfd_error_handler
)
3084 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
3085 bfd_get_filename (input_bfd
), h
->root
.root
.string
,
3086 bfd_get_section_name (input_bfd
, input_section
));
3090 relocation
= (h
->root
.u
.def
.value
3091 + sec
->output_section
->vma
3092 + sec
->output_offset
);
3094 else if (h
->root
.type
== bfd_link_hash_undefweak
)
3096 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
3097 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3101 if (! (*info
->callbacks
->undefined_symbol
) (info
,
3102 h
->root
.root
.string
,
3107 || info
->no_undefined
3108 || ELF_ST_VISIBILITY (h
->other
))))
3114 switch ((int) r_type
)
3117 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
3118 bfd_get_filename (input_bfd
),
3119 (int) r_type
, sym_name
);
3121 bfd_set_error (bfd_error_bad_value
);
3125 /* Relocations that need no special processing. */
3126 case (int) R_PPC_LOCAL24PC
:
3127 /* It makes no sense to point a local relocation
3128 at a symbol not in this object. */
3130 && (h
->root
.type
== bfd_link_hash_defined
3131 || h
->root
.type
== bfd_link_hash_defweak
)
3132 && sec
->output_section
== NULL
)
3134 if (! (*info
->callbacks
->undefined_symbol
) (info
,
3135 h
->root
.root
.string
,
3145 /* Relocations that may need to be propagated if this is a shared
3147 case (int) R_PPC_REL24
:
3148 case (int) R_PPC_REL32
:
3149 case (int) R_PPC_REL14
:
3150 /* If these relocations are not to a named symbol, they can be
3151 handled right here, no need to bother the dynamic linker. */
3153 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3154 || SYMBOL_REFERENCES_LOCAL (info
, h
))
3158 /* Relocations that always need to be propagated if this is a shared
3160 case (int) R_PPC_NONE
:
3161 case (int) R_PPC_ADDR32
:
3162 case (int) R_PPC_ADDR24
:
3163 case (int) R_PPC_ADDR16
:
3164 case (int) R_PPC_ADDR16_LO
:
3165 case (int) R_PPC_ADDR16_HI
:
3166 case (int) R_PPC_ADDR16_HA
:
3167 case (int) R_PPC_ADDR14
:
3168 case (int) R_PPC_UADDR32
:
3169 case (int) R_PPC_UADDR16
:
3172 Elf_Internal_Rela outrel
;
3176 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
3177 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
3180 /* When generating a shared object, these relocations
3181 are copied into the output file to be resolved at run
3188 name
= (bfd_elf_string_from_elf_section
3190 elf_elfheader (input_bfd
)->e_shstrndx
,
3191 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3195 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3196 && strcmp (bfd_get_section_name (input_bfd
,
3200 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3201 BFD_ASSERT (sreloc
!= NULL
);
3206 if (elf_section_data (input_section
)->stab_info
== NULL
)
3207 outrel
.r_offset
= rel
->r_offset
;
3212 off
= (_bfd_stab_section_offset
3213 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3215 &elf_section_data (input_section
)->stab_info
,
3217 if (off
== (bfd_vma
) -1)
3219 outrel
.r_offset
= off
;
3222 outrel
.r_offset
+= (input_section
->output_section
->vma
3223 + input_section
->output_offset
);
3226 memset (&outrel
, 0, sizeof outrel
);
3227 /* h->dynindx may be -1 if this symbol was marked to
3229 else if (! will_become_local
)
3231 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3232 outrel
.r_addend
= rel
->r_addend
;
3236 if (r_type
== R_PPC_ADDR32
)
3238 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3239 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3246 sec
= local_sections
[r_symndx
];
3249 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3251 == bfd_link_hash_defweak
));
3252 sec
= h
->root
.u
.def
.section
;
3254 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3256 else if (sec
== NULL
|| sec
->owner
== NULL
)
3258 bfd_set_error (bfd_error_bad_value
);
3265 osec
= sec
->output_section
;
3266 indx
= elf_section_data (osec
)->dynindx
;
3267 BFD_ASSERT (indx
> 0);
3271 printf ("indx=%d section=%s flags=%08x name=%s\n",
3272 indx
, osec
->name
, osec
->flags
,
3273 h
->root
.root
.string
);
3278 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3279 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3283 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3284 (((Elf32_External_Rela
*)
3286 + sreloc
->reloc_count
));
3287 ++sreloc
->reloc_count
;
3289 /* This reloc will be computed at runtime, so there's no
3290 need to do anything now, unless this is a RELATIVE
3291 reloc in an unallocated section. */
3293 || (input_section
->flags
& SEC_ALLOC
) != 0
3294 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
)
3298 /* Arithmetic adjust relocations that aren't going into a
3300 if (r_type
== R_PPC_ADDR16_HA
3301 /* It's just possible that this symbol is a weak symbol
3302 that's not actually defined anywhere. In that case,
3303 'sec' would be NULL, and we should leave the symbol
3304 alone (it will be set to zero elsewhere in the link). */
3307 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3311 /* branch taken prediction relocations */
3312 case (int) R_PPC_ADDR14_BRTAKEN
:
3313 case (int) R_PPC_REL14_BRTAKEN
:
3314 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3315 if ((relocation
- offset
) & 0x8000)
3316 insn
&= ~BRANCH_PREDICT_BIT
;
3318 insn
|= BRANCH_PREDICT_BIT
;
3319 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3322 /* branch not taken predicition relocations */
3323 case (int) R_PPC_ADDR14_BRNTAKEN
:
3324 case (int) R_PPC_REL14_BRNTAKEN
:
3325 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3326 if ((relocation
- offset
) & 0x8000)
3327 insn
|= BRANCH_PREDICT_BIT
;
3329 insn
&= ~BRANCH_PREDICT_BIT
;
3330 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3333 /* GOT16 relocations */
3334 case (int) R_PPC_GOT16
:
3335 case (int) R_PPC_GOT16_LO
:
3336 case (int) R_PPC_GOT16_HI
:
3337 case (int) R_PPC_GOT16_HA
:
3338 /* Relocation is to the entry for this symbol in the global
3340 BFD_ASSERT (sgot
!= NULL
);
3346 off
= h
->got
.offset
;
3347 BFD_ASSERT (off
!= (bfd_vma
) -1);
3349 if (! elf_hash_table (info
)->dynamic_sections_created
3351 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
3353 /* This is actually a static link, or it is a
3354 -Bsymbolic link and the symbol is defined
3355 locally. We must initialize this entry in the
3356 global offset table. Since the offset must
3357 always be a multiple of 4, we use the least
3358 significant bit to record whether we have
3359 initialized it already.
3361 When doing a dynamic link, we create a .rela.got
3362 relocation entry to initialize the value. This
3363 is done in the finish_dynamic_symbol routine. */
3368 bfd_put_32 (output_bfd
, relocation
,
3369 sgot
->contents
+ off
);
3374 relocation
= sgot
->output_offset
+ off
- 4;
3380 BFD_ASSERT (local_got_offsets
!= NULL
3381 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3383 off
= local_got_offsets
[r_symndx
];
3385 /* The offset must always be a multiple of 4. We use
3386 the least significant bit to record whether we have
3387 already processed this entry. */
3392 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
3397 Elf_Internal_Rela outrel
;
3399 /* We need to generate a R_PPC_RELATIVE reloc
3400 for the dynamic linker. */
3401 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3402 BFD_ASSERT (srelgot
!= NULL
);
3404 outrel
.r_offset
= (sgot
->output_section
->vma
3405 + sgot
->output_offset
3407 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3408 outrel
.r_addend
= relocation
;
3409 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3410 (((Elf32_External_Rela
*)
3412 + srelgot
->reloc_count
));
3413 ++srelgot
->reloc_count
;
3416 local_got_offsets
[r_symndx
] |= 1;
3419 relocation
= sgot
->output_offset
+ off
- 4;
3423 /* Indirect .sdata relocation */
3424 case (int) R_PPC_EMB_SDAI16
:
3425 BFD_ASSERT (sdata
!= NULL
);
3426 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3427 sdata
, h
, relocation
, rel
,
3431 /* Indirect .sdata2 relocation */
3432 case (int) R_PPC_EMB_SDA2I16
:
3433 BFD_ASSERT (sdata2
!= NULL
);
3434 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3435 sdata2
, h
, relocation
, rel
,
3439 /* Handle the TOC16 reloc. We want to use the offset within the .got
3440 section, not the actual VMA. This is appropriate when generating
3441 an embedded ELF object, for which the .got section acts like the
3442 AIX .toc section. */
3443 case (int) R_PPC_TOC16
: /* phony GOT16 relocations */
3444 BFD_ASSERT (sec
!= (asection
*) 0);
3445 BFD_ASSERT (bfd_is_und_section (sec
)
3446 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
3447 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
3449 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
3452 case (int) R_PPC_PLTREL24
:
3453 /* Relocation is to the entry for this symbol in the
3454 procedure linkage table. */
3455 BFD_ASSERT (h
!= NULL
);
3457 if (h
->plt
.offset
== (bfd_vma
) -1
3460 /* We didn't make a PLT entry for this symbol. This
3461 happens when statically linking PIC code, or when
3462 using -Bsymbolic. */
3466 relocation
= (splt
->output_section
->vma
3467 + splt
->output_offset
3471 /* relocate against _SDA_BASE_ */
3472 case (int) R_PPC_SDAREL16
:
3476 BFD_ASSERT (sec
!= (asection
*) 0);
3477 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3478 if (strcmp (name
, ".sdata") != 0
3479 && strcmp (name
, ".sbss") != 0)
3481 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3482 bfd_get_filename (input_bfd
),
3484 ppc_elf_howto_table
[(int) r_type
]->name
,
3487 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3488 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3489 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3493 /* relocate against _SDA2_BASE_ */
3494 case (int) R_PPC_EMB_SDA2REL
:
3498 BFD_ASSERT (sec
!= (asection
*) 0);
3499 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3500 if (strcmp (name
, ".sdata2") != 0 && strcmp (name
, ".sbss2") != 0)
3502 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3503 bfd_get_filename (input_bfd
),
3505 ppc_elf_howto_table
[(int) r_type
]->name
,
3508 bfd_set_error (bfd_error_bad_value
);
3512 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3513 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3514 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3518 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3519 case (int) R_PPC_EMB_SDA21
:
3520 case (int) R_PPC_EMB_RELSDA
:
3525 BFD_ASSERT (sec
!= (asection
*) 0);
3526 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3527 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
3530 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3531 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3532 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3535 else if (strcmp (name
, ".sdata2") == 0
3536 || strcmp (name
, ".sbss2") == 0)
3539 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3540 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3541 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3544 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
3545 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
3552 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3553 bfd_get_filename (input_bfd
),
3555 ppc_elf_howto_table
[(int) r_type
]->name
,
3558 bfd_set_error (bfd_error_bad_value
);
3563 if (r_type
== R_PPC_EMB_SDA21
)
3564 { /* fill in register field */
3565 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3566 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
3567 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3572 /* Relocate against the beginning of the section */
3573 case (int) R_PPC_SECTOFF
:
3574 case (int) R_PPC_SECTOFF_LO
:
3575 case (int) R_PPC_SECTOFF_HI
:
3576 BFD_ASSERT (sec
!= (asection
*) 0);
3577 addend
-= sec
->output_section
->vma
;
3580 case (int) R_PPC_SECTOFF_HA
:
3581 BFD_ASSERT (sec
!= (asection
*) 0);
3582 addend
-= sec
->output_section
->vma
;
3583 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3586 /* Negative relocations */
3587 case (int) R_PPC_EMB_NADDR32
:
3588 case (int) R_PPC_EMB_NADDR16
:
3589 case (int) R_PPC_EMB_NADDR16_LO
:
3590 case (int) R_PPC_EMB_NADDR16_HI
:
3591 addend
-= 2 * relocation
;
3594 case (int) R_PPC_EMB_NADDR16_HA
:
3595 addend
-= 2 * relocation
;
3596 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3599 /* NOP relocation that prevents garbage collecting linkers from omitting a
3601 case (int) R_PPC_EMB_MRKREF
:
3604 case (int) R_PPC_COPY
:
3605 case (int) R_PPC_GLOB_DAT
:
3606 case (int) R_PPC_JMP_SLOT
:
3607 case (int) R_PPC_RELATIVE
:
3608 case (int) R_PPC_PLT32
:
3609 case (int) R_PPC_PLTREL32
:
3610 case (int) R_PPC_PLT16_LO
:
3611 case (int) R_PPC_PLT16_HI
:
3612 case (int) R_PPC_PLT16_HA
:
3613 case (int) R_PPC_EMB_RELSEC16
:
3614 case (int) R_PPC_EMB_RELST_LO
:
3615 case (int) R_PPC_EMB_RELST_HI
:
3616 case (int) R_PPC_EMB_RELST_HA
:
3617 case (int) R_PPC_EMB_BIT_FLD
:
3618 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3619 bfd_get_filename (input_bfd
),
3620 ppc_elf_howto_table
[(int) r_type
]->name
,
3623 bfd_set_error (bfd_error_invalid_operation
);
3627 case (int) R_PPC_GNU_VTINHERIT
:
3628 case (int) R_PPC_GNU_VTENTRY
:
3629 /* These are no-ops in the end. */
3634 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3643 r
= _bfd_final_link_relocate (howto
,
3651 if (r
== bfd_reloc_ok
)
3653 else if (r
== bfd_reloc_overflow
)
3659 if (h
->root
.type
== bfd_link_hash_undefweak
3660 && howto
->pc_relative
)
3662 /* Assume this is a call protected by other code that
3663 detect the symbol is undefined. If this is the case,
3664 we can safely ignore the overflow. If not, the
3665 program is hosed anyway, and a little warning isn't
3671 name
= h
->root
.root
.string
;
3675 name
= bfd_elf_string_from_elf_section (input_bfd
,
3676 symtab_hdr
->sh_link
,
3681 name
= bfd_section_name (input_bfd
, sec
);
3684 if (! (*info
->callbacks
->reloc_overflow
) (info
,
3698 fprintf (stderr
, "\n");
3704 static enum elf_reloc_type_class
3705 ppc_elf_reloc_type_class (type
)
3710 case R_PPC_RELATIVE
:
3711 return reloc_class_relative
;
3714 case R_PPC_JMP_SLOT
:
3715 return reloc_class_plt
;
3717 return reloc_class_copy
;
3719 return reloc_class_normal
;
3723 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3724 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3725 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3726 #define TARGET_BIG_NAME "elf32-powerpc"
3727 #define ELF_ARCH bfd_arch_powerpc
3728 #define ELF_MACHINE_CODE EM_PPC
3729 #define ELF_MAXPAGESIZE 0x10000
3730 #define elf_info_to_howto ppc_elf_info_to_howto
3732 #ifdef EM_CYGNUS_POWERPC
3733 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3737 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3740 #define elf_backend_plt_not_loaded 1
3741 #define elf_backend_got_symbol_offset 4
3742 #define elf_backend_can_gc_sections 1
3743 #define elf_backend_got_header_size 12
3744 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3746 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3747 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3748 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
3749 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3750 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3751 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
3753 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
3754 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
3755 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3756 #define elf_backend_relocate_section ppc_elf_relocate_section
3757 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
3758 #define elf_backend_check_relocs ppc_elf_check_relocs
3759 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3760 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3761 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3762 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3763 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3764 #define elf_backend_fake_sections ppc_elf_fake_sections
3765 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3766 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3767 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
3769 #include "elf32-target.h"