1 /* Hitachi SH64-specific support for 64-bit ELF
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 /* Add a suffix for datalabel indirection symbols. It must not match any
30 other symbols; user symbols with or without version or other
31 decoration. It must only be used internally and not emitted by any
33 #define DATALABEL_SUFFIX " DL"
35 #define GOT_BIAS (-((long)-32768))
37 #define PLT_ENTRY_SIZE 64
39 /* Return size of a PLT entry. */
40 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
42 /* Return offset of the PLT0 address in an absolute PLT entry. */
43 #define elf_sh64_plt_plt0_offset(info) 32
45 /* Return offset of the linker in PLT0 entry. */
46 #define elf_sh64_plt0_gotplt_offset(info) 0
48 /* Return offset of the trampoline in PLT entry */
49 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
51 /* Return offset of the symbol in PLT entry. */
52 #define elf_sh64_plt_symbol_offset(info) 0
54 /* Return offset of the relocation in PLT entry. */
55 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
57 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
59 /* The sh linker needs to keep track of the number of relocs that it
60 decides to copy in check_relocs for each symbol. This is so that
61 it can discard PC relative relocs if it doesn't need them when
62 linking with -Bsymbolic. We store the information in a field
63 extending the regular ELF linker hash table. */
65 /* This structure keeps track of the number of PC relative relocs we
66 have copied for a given symbol. */
68 struct elf_sh64_pcrel_relocs_copied
71 struct elf_sh64_pcrel_relocs_copied
*next
;
72 /* A section in dynobj. */
74 /* Number of relocs copied in this section. */
78 /* sh ELF linker hash entry. */
80 struct elf_sh64_link_hash_entry
82 struct elf_link_hash_entry root
;
84 bfd_vma datalabel_got_offset
;
86 /* Number of PC relative relocs copied for this symbol. */
87 struct elf_sh_pcrel_relocs_copied
*pcrel_relocs_copied
;
90 /* sh ELF linker hash table. */
92 struct elf_sh64_link_hash_table
94 struct elf_link_hash_table root
;
97 /* Traverse an sh ELF linker hash table. */
99 #define sh64_elf64_link_hash_traverse(table, func, info) \
100 (elf_link_hash_traverse \
102 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
105 /* Get the sh ELF linker hash table from a link_info structure. */
107 #define sh64_elf64_hash_table(p) \
108 ((struct elf_sh64_link_hash_table *) ((p)->hash))
110 static boolean sh_elf64_copy_private_data
PARAMS ((bfd
*, bfd
*));
111 static boolean sh_elf64_copy_private_data_internal
PARAMS ((bfd
*, bfd
*));
112 static boolean sh_elf64_merge_private_data
PARAMS ((bfd
*, bfd
*));
113 static bfd_reloc_status_type sh_elf64_ignore_reloc
114 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
115 static bfd_reloc_status_type sh_elf64_reloc
116 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
117 static reloc_howto_type
*sh_elf64_reloc_type_lookup
118 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
119 static void sh_elf64_info_to_howto
120 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
121 static boolean sh_elf64_relocate_section
122 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
123 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
124 static bfd_byte
*sh_elf64_get_relocated_section_contents
125 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
126 bfd_byte
*, boolean
, asymbol
**));
127 static boolean sh_elf64_set_mach_from_flags
PARAMS ((bfd
*));
128 static boolean sh_elf64_set_private_flags
PARAMS ((bfd
*, flagword
));
129 static asection
*sh_elf64_gc_mark_hook
130 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
131 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
132 static boolean sh_elf64_gc_sweep_hook
133 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
134 const Elf_Internal_Rela
*));
135 static boolean sh_elf64_check_relocs
136 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
137 const Elf_Internal_Rela
*));
138 static int sh64_elf64_get_symbol_type
PARAMS ((Elf_Internal_Sym
*, int));
139 static boolean sh64_elf64_add_symbol_hook
140 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
141 const char **, flagword
*, asection
**, bfd_vma
*));
142 extern boolean sh64_elf64_link_output_symbol_hook
143 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
145 static boolean sh64_elf64_fake_sections
146 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
147 static void sh64_elf64_final_write_processing
PARAMS ((bfd
*, boolean
));
149 static reloc_howto_type sh_elf64_howto_table
[] = {
151 HOWTO (R_SH_NONE
, /* type */
153 0, /* size (0 = byte, 1 = short, 2 = long) */
155 false, /* pc_relative */
157 complain_overflow_dont
, /* complain_on_overflow */
158 sh_elf64_ignore_reloc
, /* special_function */
159 "R_SH_NONE", /* name */
160 false, /* partial_inplace */
163 false), /* pcrel_offset */
165 /* 32 bit absolute relocation. Setting partial_inplace to true and
166 src_mask to a non-zero value is similar to the COFF toolchain. */
167 HOWTO (R_SH_DIR32
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 false, /* pc_relative */
173 complain_overflow_bitfield
, /* complain_on_overflow */
174 sh_elf64_reloc
, /* special_function */
175 "R_SH_DIR32", /* name */
176 true, /* partial_inplace */
177 0xffffffff, /* src_mask */
178 0xffffffff, /* dst_mask */
179 false), /* pcrel_offset */
181 /* 32 bit PC relative relocation. */
182 HOWTO (R_SH_REL32
, /* type */
184 2, /* size (0 = byte, 1 = short, 2 = long) */
186 true, /* pc_relative */
188 complain_overflow_signed
, /* complain_on_overflow */
189 sh_elf64_ignore_reloc
, /* special_function */
190 "R_SH_REL32", /* name */
191 false, /* partial_inplace */
193 0xffffffff, /* dst_mask */
194 true), /* pcrel_offset */
196 /* For 32-bit sh, this is R_SH_DIR8WPN. */
199 /* For 32-bit sh, this is R_SH_IND12W. */
202 /* For 32-bit sh, this is R_SH_DIR8WPL. */
205 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
208 /* For 32-bit sh, this is R_SH_DIR8BP. */
211 /* For 32-bit sh, this is R_SH_DIR8W. */
214 /* For 32-bit sh, this is R_SH_DIR8L. */
233 /* The remaining relocs are a GNU extension used for relaxing. The
234 final pass of the linker never needs to do anything with any of
235 these relocs. Any required operations are handled by the
238 /* A 16 bit switch table entry. This is generated for an expression
239 such as ``.word L1 - L2''. The offset holds the difference
240 between the reloc address and L2. */
241 HOWTO (R_SH_SWITCH16
, /* type */
243 1, /* size (0 = byte, 1 = short, 2 = long) */
245 false, /* pc_relative */
247 complain_overflow_unsigned
, /* complain_on_overflow */
248 sh_elf64_ignore_reloc
, /* special_function */
249 "R_SH_SWITCH16", /* name */
250 false, /* partial_inplace */
253 true), /* pcrel_offset */
255 /* A 32 bit switch table entry. This is generated for an expression
256 such as ``.long L1 - L2''. The offset holds the difference
257 between the reloc address and L2. */
258 HOWTO (R_SH_SWITCH32
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 false, /* pc_relative */
264 complain_overflow_unsigned
, /* complain_on_overflow */
265 sh_elf64_ignore_reloc
, /* special_function */
266 "R_SH_SWITCH32", /* name */
267 false, /* partial_inplace */
270 true), /* pcrel_offset */
272 /* For 32-bit sh, this is R_SH_USES. */
275 /* For 32-bit sh, this is R_SH_COUNT. */
278 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
279 this might be emitted. When linker relaxation is implemented, we
280 might want to use it. */
283 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
284 this might be emitted. When linker relaxation is implemented, we
285 might want to use it. */
288 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
289 this might be emitted. When linker relaxation is implemented, we
290 might want to use it. */
293 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
294 this might be emitted. When linker relaxation is implemented, we
295 might want to use it. */
298 /* An 8 bit switch table entry. This is generated for an expression
299 such as ``.word L1 - L2''. The offset holds the difference
300 between the reloc address and L2. */
301 HOWTO (R_SH_SWITCH8
, /* type */
303 0, /* size (0 = byte, 1 = short, 2 = long) */
305 false, /* pc_relative */
307 complain_overflow_unsigned
, /* complain_on_overflow */
308 sh_elf64_ignore_reloc
, /* special_function */
309 "R_SH_SWITCH8", /* name */
310 false, /* partial_inplace */
313 true), /* pcrel_offset */
315 /* GNU extension to record C++ vtable hierarchy */
316 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 false, /* pc_relative */
322 complain_overflow_dont
, /* complain_on_overflow */
323 NULL
, /* special_function */
324 "R_SH_GNU_VTINHERIT", /* name */
325 false, /* partial_inplace */
328 false), /* pcrel_offset */
330 /* GNU extension to record C++ vtable member usage */
331 HOWTO (R_SH_GNU_VTENTRY
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 false, /* pc_relative */
337 complain_overflow_dont
, /* complain_on_overflow */
338 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
339 "R_SH_GNU_VTENTRY", /* name */
340 false, /* partial_inplace */
343 false), /* pcrel_offset */
345 /* For 32-bit sh, this is R_SH_LOOP_START. */
348 /* For 32-bit sh, this is R_SH_LOOP_END. */
359 /* Used in SHLLI.L and SHLRI.L. */
360 HOWTO (R_SH_DIR5U
, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 false, /* pc_relative */
366 complain_overflow_unsigned
, /* complain_on_overflow */
367 bfd_elf_generic_reloc
, /* special_function */
368 "R_SH_DIR5U", /* name */
369 false, /* partial_inplace */
371 0xfc00, /* dst_mask */
372 false), /* pcrel_offset */
374 /* Used in SHARI, SHLLI et al. */
375 HOWTO (R_SH_DIR6U
, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_unsigned
, /* complain_on_overflow */
382 bfd_elf_generic_reloc
, /* special_function */
383 "R_SH_DIR6U", /* name */
384 false, /* partial_inplace */
386 0xfc00, /* dst_mask */
387 false), /* pcrel_offset */
389 /* Used in BxxI, LDHI.L et al. */
390 HOWTO (R_SH_DIR6S
, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_signed
, /* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_SH_DIR6S", /* name */
399 false, /* partial_inplace */
401 0xfc00, /* dst_mask */
402 false), /* pcrel_offset */
404 /* Used in ADDI, ANDI et al. */
405 HOWTO (R_SH_DIR10S
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 false, /* pc_relative */
411 complain_overflow_signed
, /* complain_on_overflow */
412 bfd_elf_generic_reloc
, /* special_function */
413 "R_SH_DIR10S", /* name */
414 false, /* partial_inplace */
416 0xffc00, /* dst_mask */
417 false), /* pcrel_offset */
419 /* Used in LD.UW, ST.W et al. */
420 HOWTO (R_SH_DIR10SW
, /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 false, /* pc_relative */
426 complain_overflow_signed
, /* complain_on_overflow */
427 bfd_elf_generic_reloc
, /* special_function */
428 "R_SH_DIR10SW", /* name */
429 false, /* partial_inplace */
431 0xffc00, /* dst_mask */
432 false), /* pcrel_offset */
434 /* Used in LD.L, FLD.S et al. */
435 HOWTO (R_SH_DIR10SL
, /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 false, /* pc_relative */
441 complain_overflow_signed
, /* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_SH_DIR10SL", /* name */
444 false, /* partial_inplace */
446 0xffc00, /* dst_mask */
447 false), /* pcrel_offset */
449 /* Used in FLD.D, FST.P et al. */
450 HOWTO (R_SH_DIR10SQ
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 false, /* pc_relative */
456 complain_overflow_signed
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_SH_DIR10SQ", /* name */
459 false, /* partial_inplace */
461 0xffc00, /* dst_mask */
462 false), /* pcrel_offset */
573 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
574 any dynamic linking support for 64-bit SH at present. */
586 /* Back to SH5 relocations. */
587 /* Used in MOVI and SHORI (x & 65536). */
588 HOWTO (R_SH_GOT_LOW16
, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 false, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 bfd_elf_generic_reloc
, /* special_function */
596 "R_SH_GOT_LOW16", /* name */
597 false, /* partial_inplace */
599 0x3fffc00, /* dst_mask */
600 false), /* pcrel_offset */
602 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
603 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 false, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_SH_GOT_MEDLOW16", /* name */
612 false, /* partial_inplace */
614 0x3fffc00, /* dst_mask */
615 false), /* pcrel_offset */
617 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
618 HOWTO (R_SH_GOT_MEDHI16
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 false, /* pc_relative */
624 complain_overflow_dont
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_SH_GOT_MEDHI16", /* name */
627 false, /* partial_inplace */
629 0x3fffc00, /* dst_mask */
630 false), /* pcrel_offset */
632 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
633 HOWTO (R_SH_GOT_HI16
, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 false, /* pc_relative */
639 complain_overflow_dont
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_SH_GOT_HI16", /* name */
642 false, /* partial_inplace */
644 0x3fffc00, /* dst_mask */
645 false), /* pcrel_offset */
647 /* Used in MOVI and SHORI (x & 65536). */
648 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_SH_GOTPLT_LOW16", /* name */
657 false, /* partial_inplace */
659 0x3fffc00, /* dst_mask */
660 false), /* pcrel_offset */
662 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
663 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_SH_GOTPLT_MEDLOW16", /* name */
672 false, /* partial_inplace */
674 0x3fffc00, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
678 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 false, /* pc_relative */
684 complain_overflow_dont
, /* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 "R_SH_GOTPLT_MEDHI16", /* name */
687 false, /* partial_inplace */
689 0x3fffc00, /* dst_mask */
690 false), /* pcrel_offset */
692 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
693 HOWTO (R_SH_GOTPLT_HI16
, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 false, /* pc_relative */
699 complain_overflow_dont
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_SH_GOTPLT_HI16", /* name */
702 false, /* partial_inplace */
704 0x3fffc00, /* dst_mask */
705 false), /* pcrel_offset */
707 /* Used in MOVI and SHORI (x & 65536). */
708 HOWTO (R_SH_PLT_LOW16
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 true, /* pc_relative */
714 complain_overflow_dont
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_SH_PLT_LOW16", /* name */
717 false, /* partial_inplace */
719 0x3fffc00, /* dst_mask */
720 true), /* pcrel_offset */
722 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
723 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 true, /* pc_relative */
729 complain_overflow_dont
, /* complain_on_overflow */
730 bfd_elf_generic_reloc
, /* special_function */
731 "R_SH_PLT_MEDLOW16", /* name */
732 false, /* partial_inplace */
734 0x3fffc00, /* dst_mask */
735 true), /* pcrel_offset */
737 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
738 HOWTO (R_SH_PLT_MEDHI16
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 true, /* pc_relative */
744 complain_overflow_dont
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* special_function */
746 "R_SH_PLT_MEDHI16", /* name */
747 false, /* partial_inplace */
749 0x3fffc00, /* dst_mask */
750 true), /* pcrel_offset */
752 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
753 HOWTO (R_SH_PLT_HI16
, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 true, /* pc_relative */
759 complain_overflow_dont
, /* complain_on_overflow */
760 bfd_elf_generic_reloc
, /* special_function */
761 "R_SH_PLT_HI16", /* name */
762 false, /* partial_inplace */
764 0x3fffc00, /* dst_mask */
765 true), /* pcrel_offset */
767 /* Used in MOVI and SHORI (x & 65536). */
768 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 false, /* pc_relative */
774 complain_overflow_dont
, /* complain_on_overflow */
775 bfd_elf_generic_reloc
, /* special_function */
776 "R_SH_GOTOFF_LOW16", /* name */
777 false, /* partial_inplace */
779 0x3fffc00, /* dst_mask */
780 false), /* pcrel_offset */
782 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
783 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 false, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_SH_GOTOFF_MEDLOW16", /* name */
792 false, /* partial_inplace */
794 0x3fffc00, /* dst_mask */
795 false), /* pcrel_offset */
797 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
798 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 false, /* pc_relative */
804 complain_overflow_dont
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 "R_SH_GOTOFF_MEDHI16", /* name */
807 false, /* partial_inplace */
809 0x3fffc00, /* dst_mask */
810 false), /* pcrel_offset */
812 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
813 HOWTO (R_SH_GOTOFF_HI16
, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 false, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 "R_SH_GOTOFF_HI16", /* name */
822 false, /* partial_inplace */
824 0x3fffc00, /* dst_mask */
825 false), /* pcrel_offset */
827 /* Used in MOVI and SHORI (x & 65536). */
828 HOWTO (R_SH_GOTPC_LOW16
, /* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 true, /* pc_relative */
834 complain_overflow_dont
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_SH_GOTPC_LOW16", /* name */
837 false, /* partial_inplace */
839 0x3fffc00, /* dst_mask */
840 true), /* pcrel_offset */
842 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
843 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
845 2, /* size (0 = byte, 1 = short, 2 = long) */
847 true, /* pc_relative */
849 complain_overflow_dont
, /* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 "R_SH_GOTPC_MEDLOW16", /* name */
852 false, /* partial_inplace */
854 0x3fffc00, /* dst_mask */
855 true), /* pcrel_offset */
857 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
858 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
860 2, /* size (0 = byte, 1 = short, 2 = long) */
862 true, /* pc_relative */
864 complain_overflow_dont
, /* complain_on_overflow */
865 bfd_elf_generic_reloc
, /* special_function */
866 "R_SH_GOTPC_MEDHI16", /* name */
867 false, /* partial_inplace */
869 0x3fffc00, /* dst_mask */
870 true), /* pcrel_offset */
872 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
873 HOWTO (R_SH_GOTPC_HI16
, /* type */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
877 true, /* pc_relative */
879 complain_overflow_dont
, /* complain_on_overflow */
880 bfd_elf_generic_reloc
, /* special_function */
881 "R_SH_GOTPC_HI16", /* name */
882 false, /* partial_inplace */
884 0x3fffc00, /* dst_mask */
885 true), /* pcrel_offset */
887 /* Used in LD.L, FLD.S et al. */
888 HOWTO (R_SH_GOT10BY4
, /* type */
890 2, /* size (0 = byte, 1 = short, 2 = long) */
892 false, /* pc_relative */
894 complain_overflow_signed
, /* complain_on_overflow */
895 bfd_elf_generic_reloc
, /* special_function */
896 "R_SH_GOT10BY4", /* name */
897 false, /* partial_inplace */
899 0xffc00, /* dst_mask */
900 false), /* pcrel_offset */
902 /* Used in LD.L, FLD.S et al. */
903 HOWTO (R_SH_GOTPLT10BY4
, /* type */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
907 false, /* pc_relative */
909 complain_overflow_signed
, /* complain_on_overflow */
910 bfd_elf_generic_reloc
, /* special_function */
911 "R_SH_GOTPLT10BY4", /* name */
912 false, /* partial_inplace */
914 0xffc00, /* dst_mask */
915 false), /* pcrel_offset */
917 /* Used in FLD.D, FST.P et al. */
918 HOWTO (R_SH_GOT10BY8
, /* type */
920 2, /* size (0 = byte, 1 = short, 2 = long) */
922 false, /* pc_relative */
924 complain_overflow_signed
, /* complain_on_overflow */
925 bfd_elf_generic_reloc
, /* special_function */
926 "R_SH_GOT10BY8", /* name */
927 false, /* partial_inplace */
929 0xffc00, /* dst_mask */
930 false), /* pcrel_offset */
932 /* Used in FLD.D, FST.P et al. */
933 HOWTO (R_SH_GOTPLT10BY8
, /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 false, /* pc_relative */
939 complain_overflow_signed
, /* complain_on_overflow */
940 bfd_elf_generic_reloc
, /* special_function */
941 "R_SH_GOTPLT10BY8", /* name */
942 false, /* partial_inplace */
944 0xffc00, /* dst_mask */
945 false), /* pcrel_offset */
947 HOWTO (R_SH_COPY64
, /* type */
949 4, /* size (0 = byte, 1 = short, 2 = long) */
951 false, /* pc_relative */
953 complain_overflow_dont
, /* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_SH_COPY64", /* name */
956 false, /* partial_inplace */
958 ((bfd_vma
) 0) - 1, /* dst_mask */
959 false), /* pcrel_offset */
961 HOWTO (R_SH_GLOB_DAT64
, /* type */
963 4, /* size (0 = byte, 1 = short, 2 = long) */
965 false, /* pc_relative */
967 complain_overflow_dont
, /* complain_on_overflow */
968 bfd_elf_generic_reloc
, /* special_function */
969 "R_SH_GLOB_DAT64", /* name */
970 false, /* partial_inplace */
972 ((bfd_vma
) 0) - 1, /* dst_mask */
973 false), /* pcrel_offset */
975 HOWTO (R_SH_JMP_SLOT64
, /* type */
977 4, /* size (0 = byte, 1 = short, 2 = long) */
979 false, /* pc_relative */
981 complain_overflow_dont
, /* complain_on_overflow */
982 bfd_elf_generic_reloc
, /* special_function */
983 "R_SH_JMP_SLOT64", /* name */
984 false, /* partial_inplace */
986 ((bfd_vma
) 0) - 1, /* dst_mask */
987 false), /* pcrel_offset */
989 HOWTO (R_SH_RELATIVE64
, /* type */
991 4, /* size (0 = byte, 1 = short, 2 = long) */
993 false, /* pc_relative */
995 complain_overflow_dont
, /* complain_on_overflow */
996 bfd_elf_generic_reloc
, /* special_function */
997 "R_SH_RELATIVE64", /* name */
998 false, /* partial_inplace */
1000 ((bfd_vma
) 0) - 1, /* dst_mask */
1001 false), /* pcrel_offset */
1049 /* Relocations for SHmedia code. None of these are partial_inplace or
1050 use the field being relocated. */
1052 /* The assembler will generate this reloc before a block of SHmedia
1053 instructions. A section should be processed as assuming it contains
1054 data, unless this reloc is seen. Note that a block of SHcompact
1055 instructions are instead preceded by R_SH_CODE.
1056 This is currently not implemented, but should be used for SHmedia
1057 linker relaxation. */
1058 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 false, /* pc_relative */
1064 complain_overflow_unsigned
, /* complain_on_overflow */
1065 sh_elf64_ignore_reloc
, /* special_function */
1066 "R_SH_SHMEDIA_CODE", /* name */
1067 false, /* partial_inplace */
1070 false), /* pcrel_offset */
1072 /* The assembler will generate this reloc at a PTA or PTB instruction,
1073 and the linker checks the right type of target, or changes a PTA to a
1074 PTB, if the original insn was PT. */
1075 HOWTO (R_SH_PT_16
, /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 true, /* pc_relative */
1081 complain_overflow_signed
, /* complain_on_overflow */
1082 bfd_elf_generic_reloc
, /* special_function */
1083 "R_SH_PT_16", /* name */
1084 false, /* partial_inplace */
1086 0x3fffc00, /* dst_mask */
1087 true), /* pcrel_offset */
1089 /* Used in unexpanded MOVI. */
1090 HOWTO (R_SH_IMMS16
, /* type */
1092 2, /* size (0 = byte, 1 = short, 2 = long) */
1094 false, /* pc_relative */
1096 complain_overflow_signed
, /* complain_on_overflow */
1097 bfd_elf_generic_reloc
, /* special_function */
1098 "R_SH_IMMS16", /* name */
1099 false, /* partial_inplace */
1101 0x3fffc00, /* dst_mask */
1102 false), /* pcrel_offset */
1104 /* Used in SHORI. */
1105 HOWTO (R_SH_IMMU16
, /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 false, /* pc_relative */
1111 complain_overflow_unsigned
, /* complain_on_overflow */
1112 bfd_elf_generic_reloc
, /* special_function */
1113 "R_SH_IMMU16", /* name */
1114 false, /* partial_inplace */
1116 0x3fffc00, /* dst_mask */
1117 false), /* pcrel_offset */
1119 /* Used in MOVI and SHORI (x & 65536). */
1120 HOWTO (R_SH_IMM_LOW16
, /* type */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 false, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* special_function */
1128 "R_SH_IMM_LOW16", /* name */
1129 false, /* partial_inplace */
1131 0x3fffc00, /* dst_mask */
1132 false), /* pcrel_offset */
1134 /* Used in MOVI and SHORI ((x - $) & 65536). */
1135 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 true, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 bfd_elf_generic_reloc
, /* special_function */
1143 "R_SH_IMM_LOW16_PCREL", /* name */
1144 false, /* partial_inplace */
1146 0x3fffc00, /* dst_mask */
1147 true), /* pcrel_offset */
1149 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1150 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1151 16, /* rightshift */
1152 2, /* size (0 = byte, 1 = short, 2 = long) */
1154 false, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 "R_SH_IMM_MEDLOW16", /* name */
1159 false, /* partial_inplace */
1161 0x3fffc00, /* dst_mask */
1162 false), /* pcrel_offset */
1164 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1165 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1166 16, /* rightshift */
1167 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 true, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 bfd_elf_generic_reloc
, /* special_function */
1173 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1174 false, /* partial_inplace */
1176 0x3fffc00, /* dst_mask */
1177 true), /* pcrel_offset */
1179 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1180 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1181 32, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 false, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 bfd_elf_generic_reloc
, /* special_function */
1188 "R_SH_IMM_MEDHI16", /* name */
1189 false, /* partial_inplace */
1191 0x3fffc00, /* dst_mask */
1192 false), /* pcrel_offset */
1194 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1195 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1196 32, /* rightshift */
1197 2, /* size (0 = byte, 1 = short, 2 = long) */
1199 true, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 bfd_elf_generic_reloc
, /* special_function */
1203 "R_SH_IMM_MEDHI16_PCREL", /* name */
1204 false, /* partial_inplace */
1206 0x3fffc00, /* dst_mask */
1207 true), /* pcrel_offset */
1209 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1210 HOWTO (R_SH_IMM_HI16
, /* type */
1211 48, /* rightshift */
1212 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 false, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 bfd_elf_generic_reloc
, /* special_function */
1218 "R_SH_IMM_HI16", /* name */
1219 false, /* partial_inplace */
1221 0x3fffc00, /* dst_mask */
1222 false), /* pcrel_offset */
1224 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1225 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1226 48, /* rightshift */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 true, /* pc_relative */
1231 complain_overflow_dont
, /* complain_on_overflow */
1232 bfd_elf_generic_reloc
, /* special_function */
1233 "R_SH_IMM_HI16_PCREL", /* name */
1234 false, /* partial_inplace */
1236 0x3fffc00, /* dst_mask */
1237 true), /* pcrel_offset */
1239 /* For the .uaquad pseudo. */
1240 HOWTO (R_SH_64
, /* type */
1242 4, /* size (0 = byte, 1 = short, 2 = long) */
1244 false, /* pc_relative */
1246 complain_overflow_dont
, /* complain_on_overflow */
1247 bfd_elf_generic_reloc
, /* special_function */
1248 "R_SH_64", /* name */
1249 false, /* partial_inplace */
1251 ((bfd_vma
) 0) - 1, /* dst_mask */
1252 false), /* pcrel_offset */
1254 /* For the .uaquad pseudo, (x - $). */
1255 HOWTO (R_SH_64_PCREL
, /* type */
1256 48, /* rightshift */
1257 2, /* size (0 = byte, 1 = short, 2 = long) */
1259 true, /* pc_relative */
1261 complain_overflow_dont
, /* complain_on_overflow */
1262 bfd_elf_generic_reloc
, /* special_function */
1263 "R_SH_64_PCREL", /* name */
1264 false, /* partial_inplace */
1266 ((bfd_vma
) 0) - 1, /* dst_mask */
1267 true), /* pcrel_offset */
1271 /* This function is used for relocs which are only used for relaxing,
1272 which the linker should otherwise ignore. */
1274 static bfd_reloc_status_type
1275 sh_elf64_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1276 output_bfd
, error_message
)
1277 bfd
*abfd ATTRIBUTE_UNUSED
;
1278 arelent
*reloc_entry
;
1279 asymbol
*symbol ATTRIBUTE_UNUSED
;
1280 PTR data ATTRIBUTE_UNUSED
;
1281 asection
*input_section
;
1283 char **error_message ATTRIBUTE_UNUSED
;
1285 if (output_bfd
!= NULL
)
1286 reloc_entry
->address
+= input_section
->output_offset
;
1287 return bfd_reloc_ok
;
1290 /* This function is used for normal relocs. This used to be like the COFF
1291 function, and is almost certainly incorrect for other ELF targets.
1293 See sh_elf_reloc in elf32-sh.c for the original. */
1295 static bfd_reloc_status_type
1296 sh_elf64_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1299 arelent
*reloc_entry
;
1302 asection
*input_section
;
1304 char **error_message ATTRIBUTE_UNUSED
;
1308 enum elf_sh_reloc_type r_type
;
1309 bfd_vma addr
= reloc_entry
->address
;
1310 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1312 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1314 if (output_bfd
!= NULL
)
1316 /* Partial linking--do nothing. */
1317 reloc_entry
->address
+= input_section
->output_offset
;
1318 return bfd_reloc_ok
;
1321 if (symbol_in
!= NULL
1322 && bfd_is_und_section (symbol_in
->section
))
1323 return bfd_reloc_undefined
;
1325 if (bfd_is_com_section (symbol_in
->section
))
1328 sym_value
= (symbol_in
->value
+
1329 symbol_in
->section
->output_section
->vma
+
1330 symbol_in
->section
->output_offset
);
1335 insn
= bfd_get_32 (abfd
, hit_data
);
1336 insn
+= sym_value
+ reloc_entry
->addend
;
1337 bfd_put_32 (abfd
, insn
, hit_data
);
1345 return bfd_reloc_ok
;
1348 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1350 struct elf_reloc_map
1352 bfd_reloc_code_real_type bfd_reloc_val
;
1353 unsigned char elf_reloc_val
;
1356 /* An array mapping BFD reloc codes to SH ELF relocs. */
1358 static const struct elf_reloc_map sh64_reloc_map
[] =
1360 { BFD_RELOC_NONE
, R_SH_NONE
},
1361 { BFD_RELOC_32
, R_SH_DIR32
},
1362 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1363 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1364 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1365 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1366 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1367 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1368 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1369 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1370 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1371 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1372 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1373 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1374 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1375 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1376 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1377 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1378 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1379 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1380 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1381 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1382 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1383 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1384 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1385 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1386 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1387 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1388 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1389 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1390 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1391 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1392 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1393 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1394 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1395 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1396 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1397 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1398 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1399 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1400 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1401 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1402 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1403 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1404 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1405 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1406 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1407 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1408 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1409 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1410 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1411 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1412 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1413 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1414 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1415 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1416 { BFD_RELOC_64
, R_SH_64
},
1417 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1420 /* Given a BFD reloc code, return the howto structure for the
1421 corresponding SH ELf reloc. */
1423 static reloc_howto_type
*
1424 sh_elf64_reloc_type_lookup (abfd
, code
)
1425 bfd
*abfd ATTRIBUTE_UNUSED
;
1426 bfd_reloc_code_real_type code
;
1430 for (i
= 0; i
< sizeof (sh64_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1432 if (sh64_reloc_map
[i
].bfd_reloc_val
== code
)
1433 return &sh_elf64_howto_table
[(int) sh64_reloc_map
[i
].elf_reloc_val
];
1439 /* Given an ELF reloc, fill in the howto field of a relent.
1441 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1444 sh_elf64_info_to_howto (abfd
, cache_ptr
, dst
)
1445 bfd
*abfd ATTRIBUTE_UNUSED
;
1447 Elf_Internal_Rela
*dst
;
1451 r
= ELF64_R_TYPE (dst
->r_info
);
1453 BFD_ASSERT (r
<= (unsigned int) R_SH_64_PCREL
);
1454 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1455 BFD_ASSERT (r
< R_SH_DIR8WPN
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1456 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_GOTPLT32
);
1457 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1459 cache_ptr
->howto
= &sh_elf64_howto_table
[r
];
1462 /* Relocate an SH ELF section.
1464 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1467 sh_elf64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1468 contents
, relocs
, local_syms
, local_sections
)
1469 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1470 struct bfd_link_info
*info
;
1472 asection
*input_section
;
1474 Elf_Internal_Rela
*relocs
;
1475 Elf_Internal_Sym
*local_syms
;
1476 asection
**local_sections
;
1478 Elf_Internal_Shdr
*symtab_hdr
;
1479 struct elf_link_hash_entry
**sym_hashes
;
1480 Elf_Internal_Rela
*rel
, *relend
;
1482 bfd_vma
*local_got_offsets
;
1487 bfd_vma disp
, dropped
;
1489 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1490 sym_hashes
= elf_sym_hashes (input_bfd
);
1491 dynobj
= elf_hash_table (info
)->dynobj
;
1492 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1500 relend
= relocs
+ input_section
->reloc_count
;
1501 for (; rel
< relend
; rel
++)
1504 reloc_howto_type
*howto
;
1505 unsigned long r_symndx
;
1506 Elf_Internal_Sym
*sym
;
1508 struct elf_link_hash_entry
*h
;
1510 bfd_vma addend
= (bfd_vma
)0;
1511 bfd_reloc_status_type r
;
1512 int seen_stt_datalabel
= 0;
1514 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1516 r_type
= ELF64_R_TYPE (rel
->r_info
);
1518 if (r_type
== (int) R_SH_NONE
)
1522 || r_type
> R_SH_64_PCREL
1523 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1524 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1525 || (r_type
>= (int) R_SH_DIR8WPN
1526 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
)
1527 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
1528 && r_type
<= R_SH_GOTPLT32
)
1529 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
1530 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
))
1532 bfd_set_error (bfd_error_bad_value
);
1536 howto
= sh_elf64_howto_table
+ r_type
;
1538 /* This is a final link. */
1542 if (r_symndx
< symtab_hdr
->sh_info
)
1544 sym
= local_syms
+ r_symndx
;
1545 sec
= local_sections
[r_symndx
];
1546 relocation
= ((sec
->output_section
->vma
1547 + sec
->output_offset
1549 | ((sym
->st_other
& STO_SH5_ISA32
) != 0));
1551 /* A local symbol never has STO_SH5_ISA32, so we don't need
1552 datalabel processing here. Make sure this does not change
1554 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
1555 ((*info
->callbacks
->reloc_dangerous
)
1557 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1558 input_bfd
, input_section
, rel
->r_offset
));
1560 if (info
->relocateable
)
1562 /* This is a relocateable link. We don't have to change
1563 anything, unless the reloc is against a section symbol,
1564 in which case we have to adjust according to where the
1565 section symbol winds up in the output section. */
1566 sym
= local_syms
+ r_symndx
;
1567 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1568 goto final_link_relocate
;
1575 /* Section symbols are never (?) placed in the hash table, so
1576 we can just ignore hash relocations when creating a
1577 relocateable object file. */
1578 if (info
->relocateable
)
1581 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1582 while (h
->root
.type
== bfd_link_hash_indirect
1583 || h
->root
.type
== bfd_link_hash_warning
)
1585 /* If the reference passes a symbol marked with
1586 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1588 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
1589 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1592 if (h
->root
.type
== bfd_link_hash_defined
1593 || h
->root
.type
== bfd_link_hash_defweak
)
1595 sec
= h
->root
.u
.def
.section
;
1596 /* In these cases, we don't need the relocation value.
1597 We check specially because in some obscure cases
1598 sec->output_section will be NULL. */
1599 if (r_type
== R_SH_GOTPC_LOW16
1600 || r_type
== R_SH_GOTPC_MEDLOW16
1601 || r_type
== R_SH_GOTPC_MEDHI16
1602 || r_type
== R_SH_GOTPC_HI16
1603 || ((r_type
== R_SH_PLT_LOW16
1604 || r_type
== R_SH_PLT_MEDLOW16
1605 || r_type
== R_SH_PLT_MEDHI16
1606 || r_type
== R_SH_PLT_HI16
)
1607 && h
->plt
.offset
!= (bfd_vma
) -1)
1608 || ((r_type
== R_SH_GOT_LOW16
1609 || r_type
== R_SH_GOT_MEDLOW16
1610 || r_type
== R_SH_GOT_MEDHI16
1611 || r_type
== R_SH_GOT_HI16
)
1612 && elf_hash_table (info
)->dynamic_sections_created
1614 || (! info
->symbolic
&& h
->dynindx
!= -1)
1615 || (h
->elf_link_hash_flags
1616 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1617 /* The cases above are those in which relocation is
1618 overwritten in the switch block below. The cases
1619 below are those in which we must defer relocation
1620 to run-time, because we can't resolve absolute
1621 addresses when creating a shared library. */
1623 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1624 || (h
->elf_link_hash_flags
1625 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1626 && ((r_type
== R_SH_64
1627 && !(ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1628 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
))
1629 || r_type
== R_SH_64_PCREL
)
1630 && ((input_section
->flags
& SEC_ALLOC
) != 0
1631 /* DWARF will emit R_SH_DIR32 relocations in its
1632 sections against symbols defined externally
1633 in shared libraries. We can't do anything
1635 || (input_section
->flags
& SEC_DEBUGGING
) != 0)))
1637 else if (sec
->output_section
== NULL
)
1639 (*_bfd_error_handler
)
1640 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
1641 bfd_get_filename (input_bfd
), h
->root
.root
.string
,
1642 bfd_get_section_name (input_bfd
, input_section
));
1646 relocation
= ((h
->root
.u
.def
.value
1647 + sec
->output_section
->vma
1648 + sec
->output_offset
)
1649 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1650 symbol value, unless we've seen
1651 STT_DATALABEL on the way to it. */
1652 | ((h
->other
& STO_SH5_ISA32
) != 0
1653 && ! seen_stt_datalabel
));
1655 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1657 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
1661 if (! ((*info
->callbacks
->undefined_symbol
)
1662 (info
, h
->root
.root
.string
, input_bfd
,
1663 input_section
, rel
->r_offset
, true)))
1670 - input_section
->output_section
->vma
1671 - input_section
->output_offset
1674 switch ((int)r_type
)
1676 case R_SH_PT_16
: dropped
= disp
& 2; break;
1677 case R_SH_DIR10SW
: dropped
= disp
& 1; break;
1678 case R_SH_DIR10SL
: dropped
= disp
& 3; break;
1679 case R_SH_DIR10SQ
: dropped
= disp
& 7; break;
1683 (*_bfd_error_handler
)
1684 (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1685 bfd_get_filename (input_bfd
), (int)r_type
, (unsigned)rel
->r_offset
, (unsigned)relocation
);
1686 bfd_set_error (bfd_error_bad_value
);
1689 switch ((int)r_type
)
1694 && (input_section
->flags
& SEC_ALLOC
) != 0
1695 && (r_type
!= R_SH_64_PCREL
1698 && (! info
->symbolic
1699 || (h
->elf_link_hash_flags
1700 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1702 Elf_Internal_Rela outrel
;
1703 boolean skip
, relocate
;
1705 /* When generating a shared object, these relocations
1706 are copied into the output file to be resolved at run
1713 name
= (bfd_elf_string_from_elf_section
1715 elf_elfheader (input_bfd
)->e_shstrndx
,
1716 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1720 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1721 && strcmp (bfd_get_section_name (input_bfd
,
1725 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1726 BFD_ASSERT (sreloc
!= NULL
);
1732 = _bfd_elf_section_offset (output_bfd
,
1733 &elf_hash_table (info
)->stab_info
,
1737 if (outrel
.r_offset
== (bfd_vma
) -1)
1740 outrel
.r_offset
+= (input_section
->output_section
->vma
1741 + input_section
->output_offset
);
1745 memset (&outrel
, 0, sizeof outrel
);
1748 else if (r_type
== R_SH_64_PCREL
)
1750 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
1752 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64_PCREL
);
1753 outrel
.r_addend
= rel
->r_addend
;
1757 /* h->dynindx may be -1 if this symbol was marked to
1760 || ((info
->symbolic
|| h
->dynindx
== -1)
1761 && (h
->elf_link_hash_flags
1762 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
1765 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1766 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1770 BFD_ASSERT (h
->dynindx
!= -1);
1772 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64
);
1773 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1777 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1778 (((Elf64_External_Rela
*)
1780 + sreloc
->reloc_count
));
1781 ++sreloc
->reloc_count
;
1783 /* If this reloc is against an external symbol, we do
1784 not want to fiddle with the addend. Otherwise, we
1785 need to include the symbol value so that it becomes
1786 an addend for the dynamic reloc. */
1790 else if (r_type
== R_SH_64
)
1791 addend
= rel
->r_addend
;
1792 goto final_link_relocate
;
1794 case R_SH_GOTPLT_LOW16
:
1795 case R_SH_GOTPLT_MEDLOW16
:
1796 case R_SH_GOTPLT_MEDHI16
:
1797 case R_SH_GOTPLT_HI16
:
1798 case R_SH_GOTPLT10BY4
:
1799 case R_SH_GOTPLT10BY8
:
1800 /* Relocation is to the entry for this symbol in the
1801 procedure linkage table. */
1804 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1805 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
1809 || h
->plt
.offset
== (bfd_vma
) -1
1810 || h
->got
.offset
!= (bfd_vma
) -1)
1813 /* Relocation is to the entry for this symbol in the global
1814 offset table extension for the procedure linkage table. */
1815 if (sgotplt
== NULL
)
1817 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1818 BFD_ASSERT (sgotplt
!= NULL
);
1821 relocation
= (sgotplt
->output_offset
1822 + ((h
->plt
.offset
/ elf_sh64_sizeof_plt (info
)
1825 relocation
-= GOT_BIAS
;
1827 goto final_link_relocate
;
1830 case R_SH_GOT_LOW16
:
1831 case R_SH_GOT_MEDLOW16
:
1832 case R_SH_GOT_MEDHI16
:
1836 /* Relocation is to the entry for this symbol in the global
1840 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1841 BFD_ASSERT (sgot
!= NULL
);
1848 off
= h
->got
.offset
;
1849 if (seen_stt_datalabel
)
1851 struct elf_sh64_link_hash_entry
*hsh
;
1853 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1854 off
= hsh
->datalabel_got_offset
;
1856 BFD_ASSERT (off
!= (bfd_vma
) -1);
1858 if (! elf_hash_table (info
)->dynamic_sections_created
1860 && (info
->symbolic
|| h
->dynindx
== -1
1861 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1862 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
1863 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1865 /* This is actually a static link, or it is a
1866 -Bsymbolic link and the symbol is defined
1867 locally, or the symbol was forced to be local
1868 because of a version file. We must initialize
1869 this entry in the global offset table. Since the
1870 offset must always be a multiple of 4, we use the
1871 least significant bit to record whether we have
1872 initialized it already.
1874 When doing a dynamic link, we create a .rela.got
1875 relocation entry to initialize the value. This
1876 is done in the finish_dynamic_symbol routine. */
1881 bfd_put_64 (output_bfd
, relocation
,
1882 sgot
->contents
+ off
);
1883 if (seen_stt_datalabel
)
1885 struct elf_sh64_link_hash_entry
*hsh
;
1887 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1888 hsh
->datalabel_got_offset
|= 1;
1895 relocation
= sgot
->output_offset
+ off
;
1903 BFD_ASSERT (local_got_offsets
!= NULL
1904 && (local_got_offsets
[symtab_hdr
->sh_info
1908 off
= local_got_offsets
[symtab_hdr
->sh_info
1913 BFD_ASSERT (local_got_offsets
!= NULL
1914 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1916 off
= local_got_offsets
[r_symndx
];
1919 /* The offset must always be a multiple of 8. We use
1920 the least significant bit to record whether we have
1921 already generated the necessary reloc. */
1926 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1931 Elf_Internal_Rela outrel
;
1933 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1934 BFD_ASSERT (srelgot
!= NULL
);
1936 outrel
.r_offset
= (sgot
->output_section
->vma
1937 + sgot
->output_offset
1939 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1940 outrel
.r_addend
= relocation
;
1941 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1942 (((Elf64_External_Rela
*)
1944 + srelgot
->reloc_count
));
1945 ++srelgot
->reloc_count
;
1949 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
1951 local_got_offsets
[r_symndx
] |= 1;
1954 relocation
= sgot
->output_offset
+ off
;
1957 relocation
-= GOT_BIAS
;
1959 goto final_link_relocate
;
1961 case R_SH_GOTOFF_LOW16
:
1962 case R_SH_GOTOFF_MEDLOW16
:
1963 case R_SH_GOTOFF_MEDHI16
:
1964 case R_SH_GOTOFF_HI16
:
1965 /* Relocation is relative to the start of the global offset
1970 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1971 BFD_ASSERT (sgot
!= NULL
);
1974 /* Note that sgot->output_offset is not involved in this
1975 calculation. We always want the start of .got. If we
1976 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1977 permitted by the ABI, we might have to change this
1979 relocation
-= sgot
->output_section
->vma
;
1981 relocation
-= GOT_BIAS
;
1983 addend
= rel
->r_addend
;
1985 goto final_link_relocate
;
1987 case R_SH_GOTPC_LOW16
:
1988 case R_SH_GOTPC_MEDLOW16
:
1989 case R_SH_GOTPC_MEDHI16
:
1990 case R_SH_GOTPC_HI16
:
1991 /* Use global offset table as symbol value. */
1995 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1996 BFD_ASSERT (sgot
!= NULL
);
1999 relocation
= sgot
->output_section
->vma
;
2001 relocation
+= GOT_BIAS
;
2003 addend
= rel
->r_addend
;
2005 goto final_link_relocate
;
2007 case R_SH_PLT_LOW16
:
2008 case R_SH_PLT_MEDLOW16
:
2009 case R_SH_PLT_MEDHI16
:
2011 /* Relocation is to the entry for this symbol in the
2012 procedure linkage table. */
2014 /* Resolve a PLT reloc against a local symbol directly,
2015 without using the procedure linkage table. */
2017 goto final_link_relocate
;
2019 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2020 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2021 goto final_link_relocate
;
2023 if (h
->plt
.offset
== (bfd_vma
) -1)
2025 /* We didn't make a PLT entry for this symbol. This
2026 happens when statically linking PIC code, or when
2027 using -Bsymbolic. */
2028 goto final_link_relocate
;
2033 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2034 BFD_ASSERT (splt
!= NULL
);
2037 relocation
= (splt
->output_section
->vma
2038 + splt
->output_offset
2042 addend
= rel
->r_addend
;
2044 goto final_link_relocate
;
2047 case R_SH_SHMEDIA_CODE
:
2058 case R_SH_IMM_LOW16
:
2059 case R_SH_IMM_LOW16_PCREL
:
2060 case R_SH_IMM_MEDLOW16
:
2061 case R_SH_IMM_MEDLOW16_PCREL
:
2062 case R_SH_IMM_MEDHI16
:
2063 case R_SH_IMM_MEDHI16_PCREL
:
2065 case R_SH_IMM_HI16_PCREL
:
2066 addend
= rel
->r_addend
;
2069 final_link_relocate
:
2070 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2071 contents
, rel
->r_offset
,
2072 relocation
, addend
);
2076 bfd_set_error (bfd_error_bad_value
);
2081 if (r
!= bfd_reloc_ok
)
2086 case bfd_reloc_outofrange
:
2088 case bfd_reloc_overflow
:
2093 name
= h
->root
.root
.string
;
2096 name
= (bfd_elf_string_from_elf_section
2097 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2101 name
= bfd_section_name (input_bfd
, sec
);
2103 if (! ((*info
->callbacks
->reloc_overflow
)
2104 (info
, name
, howto
->name
, (bfd_vma
) 0,
2105 input_bfd
, input_section
, rel
->r_offset
)))
2116 /* This is a version of bfd_generic_get_relocated_section_contents
2117 that uses sh_elf64_relocate_section.
2119 See sh_elf_relocate_section in elf32-sh.c for the original. */
2122 sh_elf64_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
2123 data
, relocateable
, symbols
)
2125 struct bfd_link_info
*link_info
;
2126 struct bfd_link_order
*link_order
;
2128 boolean relocateable
;
2131 Elf_Internal_Shdr
*symtab_hdr
;
2132 Elf_Internal_Shdr
*shndx_hdr
;
2133 asection
*input_section
= link_order
->u
.indirect
.section
;
2134 bfd
*input_bfd
= input_section
->owner
;
2135 asection
**sections
= NULL
;
2136 Elf_Internal_Rela
*internal_relocs
= NULL
;
2137 Elf64_External_Sym
*external_syms
= NULL
;
2138 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
2139 Elf_External_Sym_Shndx
*shndx
;
2140 Elf_Internal_Sym
*internal_syms
= NULL
;
2142 /* We only need to handle the case of relaxing, or of having a
2143 particular set of section contents, specially. */
2145 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2146 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2151 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2152 shndx_hdr
= &elf_tdata (input_bfd
)->symtab_shndx_hdr
;
2154 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2155 input_section
->_raw_size
);
2157 if ((input_section
->flags
& SEC_RELOC
) != 0
2158 && input_section
->reloc_count
> 0)
2160 Elf_Internal_Sym
*isymp
;
2162 Elf64_External_Sym
*esym
, *esymend
;
2165 if (symtab_hdr
->contents
!= NULL
)
2166 external_syms
= (Elf64_External_Sym
*) symtab_hdr
->contents
;
2169 amt
= symtab_hdr
->sh_info
;
2170 amt
*= sizeof (Elf64_External_Sym
);
2172 external_syms
= (Elf64_External_Sym
*) bfd_malloc (amt
);
2173 if (external_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2176 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2177 || (bfd_bread ((PTR
) external_syms
, amt
, input_bfd
) != amt
))
2181 if (symtab_hdr
->sh_info
!= 0 && shndx_hdr
->sh_size
!= 0)
2183 amt
= symtab_hdr
->sh_info
;
2184 amt
*= sizeof (Elf_External_Sym_Shndx
);
2186 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
2187 if (shndx_buf
== NULL
)
2190 if (bfd_seek (input_bfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
2191 || bfd_bread ((PTR
) shndx_buf
, amt
, input_bfd
) != amt
)
2195 internal_relocs
= (_bfd_elf64_link_read_relocs
2196 (input_bfd
, input_section
, (PTR
) NULL
,
2197 (Elf_Internal_Rela
*) NULL
, false));
2198 if (internal_relocs
== NULL
)
2201 internal_syms
= ((Elf_Internal_Sym
*)
2202 bfd_malloc (symtab_hdr
->sh_info
2203 * sizeof (Elf_Internal_Sym
)));
2204 if (internal_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2207 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2208 * sizeof (asection
*));
2209 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2212 isymp
= internal_syms
;
2214 esym
= external_syms
;
2215 esymend
= esym
+ symtab_hdr
->sh_info
;
2217 for (; esym
< esymend
;
2218 ++esym
, ++isymp
, ++secpp
, shndx
= (shndx
? shndx
+ 1 : NULL
))
2222 bfd_elf64_swap_symbol_in (input_bfd
, esym
, shndx
, isymp
);
2224 if (isymp
->st_shndx
== SHN_UNDEF
)
2225 isec
= bfd_und_section_ptr
;
2226 else if (isymp
->st_shndx
> 0 && isymp
->st_shndx
< SHN_LORESERVE
)
2227 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
2228 else if (isymp
->st_shndx
== SHN_ABS
)
2229 isec
= bfd_abs_section_ptr
;
2230 else if (isymp
->st_shndx
== SHN_COMMON
)
2231 isec
= bfd_com_section_ptr
;
2241 if (! sh_elf64_relocate_section (output_bfd
, link_info
, input_bfd
,
2242 input_section
, data
, internal_relocs
,
2243 internal_syms
, sections
))
2246 if (sections
!= NULL
)
2249 if (internal_syms
!= NULL
)
2250 free (internal_syms
);
2251 internal_syms
= NULL
;
2252 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2253 free (external_syms
);
2254 external_syms
= NULL
;
2255 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
2256 free (internal_relocs
);
2257 internal_relocs
= NULL
;
2263 if (internal_relocs
!= NULL
2264 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
2265 free (internal_relocs
);
2266 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2267 free (external_syms
);
2268 if (internal_syms
!= NULL
)
2269 free (internal_syms
);
2270 if (sections
!= NULL
)
2275 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */
2278 sh64_elf64_fake_sections (output_bfd
, elf_section_hdr
, asect
)
2279 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2280 Elf_Internal_Shdr
*elf_section_hdr
;
2283 /* Code sections can only contain SH64 code, so mark them as such. */
2284 if (bfd_get_section_flags (output_bfd
, asect
) & SEC_CODE
)
2285 elf_section_hdr
->sh_flags
|= SHF_SH5_ISA32
;
2291 sh_elf64_set_mach_from_flags (abfd
)
2294 flagword flags
= elf_elfheader (abfd
)->e_flags
;
2296 switch (flags
& EF_SH_MACH_MASK
)
2299 /* Just one, but keep the switch construct to make additions easy. */
2300 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh5
);
2304 bfd_set_error (bfd_error_wrong_format
);
2310 /* Function to keep SH64 specific file flags.
2312 See sh64_elf_set_private_flags in elf32-sh64.c for the original. */
2315 sh_elf64_set_private_flags (abfd
, flags
)
2319 BFD_ASSERT (! elf_flags_init (abfd
)
2320 || elf_elfheader (abfd
)->e_flags
== flags
);
2322 elf_elfheader (abfd
)->e_flags
= flags
;
2323 elf_flags_init (abfd
) = true;
2324 return sh_elf64_set_mach_from_flags (abfd
);
2327 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2328 code, to keep attributes the same as for SHmedia in 32-bit ELF. */
2331 sh_elf64_copy_private_data_internal (ibfd
, obfd
)
2335 Elf_Internal_Shdr
**o_shdrp
;
2339 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2340 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2343 o_shdrp
= elf_elfsections (obfd
);
2344 for (osec
= obfd
->sections
; osec
; osec
= osec
->next
)
2346 int oIndex
= ((struct bfd_elf_section_data
*) elf_section_data (osec
))->this_idx
;
2347 for (isec
= ibfd
->sections
; isec
; isec
= isec
->next
)
2349 if (strcmp (osec
->name
, isec
->name
) == 0)
2351 /* Note that we're not disallowing mixing data and code. */
2352 if ((elf_section_data (isec
)->this_hdr
.sh_flags
2353 & SHF_SH5_ISA32
) != 0)
2354 o_shdrp
[oIndex
]->sh_flags
|= SHF_SH5_ISA32
;
2360 return sh_elf64_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2364 sh_elf64_copy_private_data (ibfd
, obfd
)
2368 return sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2372 sh_elf64_merge_private_data (ibfd
, obfd
)
2376 flagword old_flags
, new_flags
;
2378 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2381 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2382 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2385 if (bfd_get_arch_size (ibfd
) != bfd_get_arch_size (obfd
))
2389 if (bfd_get_arch_size (ibfd
) == 32
2390 && bfd_get_arch_size (obfd
) == 64)
2391 msg
= _("%s: compiled as 32-bit object and %s is 64-bit");
2392 else if (bfd_get_arch_size (ibfd
) == 64
2393 && bfd_get_arch_size (obfd
) == 32)
2394 msg
= _("%s: compiled as 64-bit object and %s is 32-bit");
2396 msg
= _("%s: object size does not match that of target %s");
2398 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
),
2399 bfd_get_filename (obfd
));
2400 bfd_set_error (bfd_error_wrong_format
);
2404 old_flags
= elf_elfheader (obfd
)->e_flags
;
2405 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2406 if (! elf_flags_init (obfd
))
2408 /* This happens when ld starts out with a 'blank' output file. */
2409 elf_flags_init (obfd
) = true;
2410 elf_elfheader (obfd
)->e_flags
= old_flags
= new_flags
;
2412 /* We don't allow linking in anything else than SH64 code, and since
2413 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2414 here as things change. */
2415 else if ((new_flags
& EF_SH_MACH_MASK
) != EF_SH5
)
2417 (*_bfd_error_handler
)
2418 ("%s: does not use the SH64 64-bit ABI as previous modules do",
2419 bfd_get_filename (ibfd
));
2420 bfd_set_error (bfd_error_bad_value
);
2424 sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2426 /* I can't think of anything sane other than old_flags being EF_SH5 and
2427 that we need to preserve that. */
2428 elf_elfheader (obfd
)->e_flags
= old_flags
;
2430 return sh_elf64_set_mach_from_flags (obfd
);
2433 /* Return the section that should be marked against GC for a given
2437 sh_elf64_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2439 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2440 Elf_Internal_Rela
*rel
;
2441 struct elf_link_hash_entry
*h
;
2442 Elf_Internal_Sym
*sym
;
2446 switch (ELF64_R_TYPE (rel
->r_info
))
2448 case R_SH_GNU_VTINHERIT
:
2449 case R_SH_GNU_VTENTRY
:
2453 switch (h
->root
.type
)
2455 case bfd_link_hash_defined
:
2456 case bfd_link_hash_defweak
:
2457 return h
->root
.u
.def
.section
;
2459 case bfd_link_hash_common
:
2460 return h
->root
.u
.c
.p
->section
;
2469 if (!(elf_bad_symtab (abfd
)
2470 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2471 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2472 && sym
->st_shndx
!= SHN_COMMON
))
2473 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2479 /* Update the got entry reference counts for the section being removed. */
2482 sh_elf64_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2483 bfd
*abfd ATTRIBUTE_UNUSED
;
2484 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2485 asection
*sec ATTRIBUTE_UNUSED
;
2486 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2488 /* No got and plt entries for 64-bit SH at present. */
2492 /* Look through the relocs for a section during the first phase.
2493 Since we don't do .gots or .plts, we just need to consider the
2494 virtual table relocs for gc. */
2497 sh_elf64_check_relocs (abfd
, info
, sec
, relocs
)
2499 struct bfd_link_info
*info
;
2501 const Elf_Internal_Rela
*relocs
;
2503 Elf_Internal_Shdr
*symtab_hdr
;
2504 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2505 const Elf_Internal_Rela
*rel
;
2506 const Elf_Internal_Rela
*rel_end
;
2508 bfd_vma
*local_got_offsets
;
2517 if (info
->relocateable
)
2520 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2521 sym_hashes
= elf_sym_hashes (abfd
);
2522 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf64_External_Sym
);
2523 if (!elf_bad_symtab (abfd
))
2524 sym_hashes_end
-= symtab_hdr
->sh_info
;
2526 dynobj
= elf_hash_table (info
)->dynobj
;
2527 local_got_offsets
= elf_local_got_offsets (abfd
);
2529 rel_end
= relocs
+ sec
->reloc_count
;
2530 for (rel
= relocs
; rel
< rel_end
; rel
++)
2532 struct elf_link_hash_entry
*h
;
2533 unsigned long r_symndx
;
2535 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2536 if (r_symndx
< symtab_hdr
->sh_info
)
2539 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2541 /* Some relocs require a global offset table. */
2544 switch (ELF64_R_TYPE (rel
->r_info
))
2546 case R_SH_GOTPLT_LOW16
:
2547 case R_SH_GOTPLT_MEDLOW16
:
2548 case R_SH_GOTPLT_MEDHI16
:
2549 case R_SH_GOTPLT_HI16
:
2550 case R_SH_GOTPLT10BY4
:
2551 case R_SH_GOTPLT10BY8
:
2552 case R_SH_GOT_LOW16
:
2553 case R_SH_GOT_MEDLOW16
:
2554 case R_SH_GOT_MEDHI16
:
2558 case R_SH_GOTOFF_LOW16
:
2559 case R_SH_GOTOFF_MEDLOW16
:
2560 case R_SH_GOTOFF_MEDHI16
:
2561 case R_SH_GOTOFF_HI16
:
2562 case R_SH_GOTPC_LOW16
:
2563 case R_SH_GOTPC_MEDLOW16
:
2564 case R_SH_GOTPC_MEDHI16
:
2565 case R_SH_GOTPC_HI16
:
2566 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2567 if (! _bfd_elf_create_got_section (dynobj
, info
))
2576 switch (ELF64_R_TYPE (rel
->r_info
))
2578 /* This relocation describes the C++ object vtable hierarchy.
2579 Reconstruct it for later use during GC. */
2580 case R_SH_GNU_VTINHERIT
:
2581 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2585 /* This relocation describes which C++ vtable entries are actually
2586 used. Record for later use during GC. */
2587 case R_SH_GNU_VTENTRY
:
2588 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2593 case R_SH_GOT_LOW16
:
2594 case R_SH_GOT_MEDLOW16
:
2595 case R_SH_GOT_MEDHI16
:
2599 /* This symbol requires a global offset table entry. */
2603 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2604 BFD_ASSERT (sgot
!= NULL
);
2608 && (h
!= NULL
|| info
->shared
))
2610 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2611 if (srelgot
== NULL
)
2613 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2615 || ! bfd_set_section_flags (dynobj
, srelgot
,
2620 | SEC_LINKER_CREATED
2622 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2629 if (h
->type
== STT_DATALABEL
)
2631 struct elf_sh64_link_hash_entry
*hsh
;
2633 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2634 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
2635 if (hsh
->datalabel_got_offset
!= (bfd_vma
) -1)
2638 hsh
->datalabel_got_offset
= sgot
->_raw_size
;
2642 if (h
->got
.offset
!= (bfd_vma
) -1)
2644 /* We have already allocated space in the .got. */
2647 h
->got
.offset
= sgot
->_raw_size
;
2650 /* Make sure this symbol is output as a dynamic symbol. */
2651 if (h
->dynindx
== -1)
2653 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2657 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
2661 /* This is a global offset table entry for a local
2663 if (local_got_offsets
== NULL
)
2666 register unsigned int i
;
2668 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
2669 /* Reserve space for both the datalabel and
2670 codelabel local GOT offsets. */
2672 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
2673 if (local_got_offsets
== NULL
)
2675 elf_local_got_offsets (abfd
) = local_got_offsets
;
2676 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
2677 local_got_offsets
[i
] = (bfd_vma
) -1;
2678 for (; i
< 2 * symtab_hdr
->sh_info
; i
++)
2679 local_got_offsets
[i
] = (bfd_vma
) -1;
2681 if ((rel
->r_addend
& 1) != 0)
2683 if (local_got_offsets
[symtab_hdr
->sh_info
2684 + r_symndx
] != (bfd_vma
) -1)
2686 /* We have already allocated space in the .got. */
2689 local_got_offsets
[symtab_hdr
->sh_info
2690 + r_symndx
] = sgot
->_raw_size
;
2694 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
2696 /* We have already allocated space in the .got. */
2699 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
2704 /* If we are generating a shared object, we need to
2705 output a R_SH_RELATIVE reloc so that the dynamic
2706 linker can adjust this GOT entry. */
2707 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
2711 sgot
->_raw_size
+= 8;
2715 case R_SH_GOTPLT_LOW16
:
2716 case R_SH_GOTPLT_MEDLOW16
:
2717 case R_SH_GOTPLT_MEDHI16
:
2718 case R_SH_GOTPLT_HI16
:
2719 case R_SH_GOTPLT10BY4
:
2720 case R_SH_GOTPLT10BY8
:
2721 /* If this is a local symbol, we resolve it directly without
2722 creating a procedure linkage table entry. */
2725 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2726 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
2730 || h
->got
.offset
!= (bfd_vma
) -1)
2733 /* Make sure this symbol is output as a dynamic symbol. */
2734 if (h
->dynindx
== -1)
2736 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2740 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2744 case R_SH_PLT_LOW16
:
2745 case R_SH_PLT_MEDLOW16
:
2746 case R_SH_PLT_MEDHI16
:
2748 /* This symbol requires a procedure linkage table entry. We
2749 actually build the entry in adjust_dynamic_symbol,
2750 because this might be a case of linking PIC code which is
2751 never referenced by a dynamic object, in which case we
2752 don't need to generate a procedure linkage table entry
2755 /* If this is a local symbol, we resolve it directly without
2756 creating a procedure linkage table entry. */
2760 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2761 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2764 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2771 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
2773 /* If we are creating a shared library, and this is a reloc
2774 against a global symbol, or a non PC relative reloc
2775 against a local symbol, then we need to copy the reloc
2776 into the shared library. However, if we are linking with
2777 -Bsymbolic, we do not need to copy a reloc against a
2778 global symbol which is defined in an object we are
2779 including in the link (i.e., DEF_REGULAR is set). At
2780 this point we have not seen all the input files, so it is
2781 possible that DEF_REGULAR is not set now but will be set
2782 later (it is never cleared). We account for that
2783 possibility below by storing information in the
2784 pcrel_relocs_copied field of the hash table entry. */
2786 && (sec
->flags
& SEC_ALLOC
) != 0
2787 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_64_PCREL
2789 && (! info
->symbolic
2790 || (h
->elf_link_hash_flags
2791 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2793 /* When creating a shared object, we must copy these
2794 reloc types into the output file. We create a reloc
2795 section in dynobj and make room for this reloc. */
2800 name
= (bfd_elf_string_from_elf_section
2802 elf_elfheader (abfd
)->e_shstrndx
,
2803 elf_section_data (sec
)->rel_hdr
.sh_name
));
2807 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2808 && strcmp (bfd_get_section_name (abfd
, sec
),
2811 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2816 sreloc
= bfd_make_section (dynobj
, name
);
2817 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2818 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2819 if ((sec
->flags
& SEC_ALLOC
) != 0)
2820 flags
|= SEC_ALLOC
| SEC_LOAD
;
2822 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2823 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2828 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
2830 /* If we are linking with -Bsymbolic, and this is a
2831 global symbol, we count the number of PC relative
2832 relocations we have entered for this symbol, so that
2833 we can discard them again if the symbol is later
2834 defined by a regular object. Note that this function
2835 is only called if we are using an elf_sh linker
2836 hash table, which means that h is really a pointer to
2837 an elf_sh_link_hash_entry. */
2838 if (h
!= NULL
&& info
->symbolic
2839 && ELF64_R_TYPE (rel
->r_info
) == R_SH_64_PCREL
)
2841 struct elf_sh64_link_hash_entry
*eh
;
2842 struct elf_sh64_pcrel_relocs_copied
*p
;
2844 eh
= (struct elf_sh64_link_hash_entry
*) h
;
2846 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
2847 if (p
->section
== sreloc
)
2852 p
= ((struct elf_sh64_pcrel_relocs_copied
*)
2853 bfd_alloc (dynobj
, sizeof *p
));
2856 p
->next
= eh
->pcrel_relocs_copied
;
2857 eh
->pcrel_relocs_copied
= p
;
2858 p
->section
= sreloc
;
2874 sh64_elf64_get_symbol_type (elf_sym
, type
)
2875 Elf_Internal_Sym
* elf_sym
;
2878 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_DATALABEL
)
2879 return STT_DATALABEL
;
2884 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2885 Either file can presumably exist without the other, but do not differ
2886 in elf-size-ness. How to share?
2888 Hook called by the linker routine which adds symbols from an object
2889 file. We must make indirect symbols for undefined symbols marked with
2890 STT_DATALABEL, so relocations passing them will pick up that attribute
2891 and neutralize STO_SH5_ISA32 found on the symbol definition.
2893 There is a problem, though: We want to fill in the hash-table entry for
2894 this symbol and signal to the caller that no further processing is
2895 needed. But we don't have the index for this hash-table entry. We
2896 rely here on that the current entry is the first hash-entry with NULL,
2897 which seems brittle. Also, iterating over the hash-table to find that
2898 entry is a linear operation on the number of symbols in this input
2899 file, and this function should take constant time, so that's not good
2900 too. Only comfort is that DataLabel references should only be found in
2901 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2902 into adding an option to elf_add_symbol_hook (preferably) for the index
2903 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2907 sh64_elf64_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2909 struct bfd_link_info
*info
;
2910 const Elf_Internal_Sym
*sym
;
2912 flagword
*flagsp ATTRIBUTE_UNUSED
;
2916 /* We want to do this for relocatable as well as final linking. */
2917 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
)
2919 struct elf_link_hash_entry
*h
;
2921 /* For relocateable links, we register the DataLabel sym in its own
2922 right, and tweak the name when it's output. Otherwise, we make
2923 an indirect symbol of it. */
2925 = info
->relocateable
|| info
->emitrelocations
2926 ? BSF_GLOBAL
: BSF_GLOBAL
| BSF_INDIRECT
;
2929 = bfd_malloc (strlen (*namep
) + sizeof (DATALABEL_SUFFIX
));
2930 struct elf_link_hash_entry
** sym_hash
= elf_sym_hashes (abfd
);
2932 BFD_ASSERT (sym_hash
!= NULL
);
2934 /* Allocation may fail. */
2935 if (dl_name
== NULL
)
2938 strcpy (dl_name
, *namep
);
2939 strcat (dl_name
, DATALABEL_SUFFIX
);
2941 h
= (struct elf_link_hash_entry
*)
2942 bfd_link_hash_lookup (info
->hash
, dl_name
, false, false, false);
2946 /* No previous datalabel symbol. Make one. */
2947 if (! _bfd_generic_link_add_one_symbol (info
, abfd
, dl_name
,
2948 flags
, *secp
, *valp
,
2950 get_elf_backend_data (abfd
)->collect
,
2951 (struct bfd_link_hash_entry
**) &h
))
2957 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
2958 h
->type
= STT_DATALABEL
;
2961 /* If a new symbol was created, it holds the allocated name.
2962 Otherwise, we don't need it anymore and should deallocate it. */
2965 if (h
->type
!= STT_DATALABEL
2966 || ((info
->relocateable
|| info
->emitrelocations
)
2967 && h
->root
.type
!= bfd_link_hash_undefined
)
2968 || (! info
->relocateable
&& !info
->emitrelocations
2969 && h
->root
.type
!= bfd_link_hash_indirect
))
2971 /* Make sure we don't get confused on invalid input. */
2972 (*_bfd_error_handler
)
2973 (_("%s: encountered datalabel symbol in input"),
2974 bfd_get_filename (abfd
));
2975 bfd_set_error (bfd_error_bad_value
);
2979 /* Now find the hash-table slot for this entry and fill it in. */
2980 while (*sym_hash
!= NULL
)
2984 /* Signal to caller to skip this symbol - we've handled it. */
2991 /* This hook function is called before the linker writes out a global
2992 symbol. For relocatable links, DataLabel symbols will be present in
2993 linker output. We cut off the special suffix on those symbols, so the
2994 right name appears in the output.
2996 When linking and emitting relocations, there can appear global symbols
2997 that are not referenced by relocs, but rather only implicitly through
2998 DataLabel references, a relation that is not visible to the linker.
2999 Since no stripping of global symbols in done when doing such linking,
3000 we don't need to look up and make sure to emit the main symbol for each
3001 DataLabel symbol. */
3004 sh64_elf64_link_output_symbol_hook (abfd
, info
, cname
, sym
, input_sec
)
3005 bfd
*abfd ATTRIBUTE_UNUSED
;
3006 struct bfd_link_info
*info
;
3008 Elf_Internal_Sym
*sym
;
3009 asection
*input_sec ATTRIBUTE_UNUSED
;
3011 char *name
= (char *) cname
;
3013 if (info
->relocateable
|| info
->emitrelocations
)
3015 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
)
3016 name
[strlen (name
) - strlen (DATALABEL_SUFFIX
)] = 0;
3022 /* Set bit 0 on the entry address; it always points to SHmedia code. This
3023 is mostly for symmetry with the 32-bit format, where code can be
3024 SHcompact and we need to make a distinction to make sure execution
3025 starts in the right ISA mode. It is also convenient for a loader,
3026 which would otherwise have to set this bit when loading a TR register
3027 before jumping to the program entry. */
3030 sh64_elf64_final_write_processing (abfd
, linker
)
3032 boolean linker ATTRIBUTE_UNUSED
;
3034 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
3035 numerically, but we currently lack the infrastructure to recognize
3036 that: The entry symbol, and info whether it is numeric or a symbol
3037 name is kept private in the linker. */
3038 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
)
3039 elf_elfheader (abfd
)->e_entry
|= 1;
3042 /* First entry in an absolute procedure linkage table look like this. */
3044 static const bfd_byte elf_sh64_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3046 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
3047 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
3048 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
3049 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3050 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3051 0x6b, 0xf1, 0x46, 0x00, /* ptabs r17, tr0 */
3052 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3053 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3054 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3055 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3056 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3057 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3058 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3059 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3060 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3061 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3064 static const bfd_byte elf_sh64_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3066 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3067 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
3068 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
3069 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3070 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3071 0x00, 0x46, 0xf1, 0x6b, /* ptabs r17, tr0 */
3072 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3073 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3074 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3075 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3076 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3077 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3078 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3079 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3080 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3081 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3084 /* Sebsequent entries in an absolute procedure linkage table look like
3087 static const bfd_byte elf_sh64_plt_entry_be
[PLT_ENTRY_SIZE
] =
3089 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
3090 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
3091 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
3092 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3093 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
3094 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3095 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3096 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3097 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3098 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3099 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3100 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3101 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3102 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3103 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3104 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3107 static const bfd_byte elf_sh64_plt_entry_le
[PLT_ENTRY_SIZE
] =
3109 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3110 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3111 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3112 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3113 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
3114 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3115 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3116 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3117 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3118 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3119 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3120 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3121 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3122 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3123 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3124 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3127 /* Entries in a PIC procedure linkage table look like this. */
3129 static const bfd_byte elf_sh64_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3131 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3132 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3133 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
3134 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3135 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3136 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3137 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3138 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3139 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3140 0x00, 0xcb, 0x45, 0x10, /* sub r12, r17, r17 */
3141 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3142 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3143 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3144 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3145 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3146 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3149 static const bfd_byte elf_sh64_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3151 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3152 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3153 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3154 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3155 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3156 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3157 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3158 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3159 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3160 0x10, 0x45, 0xcb, 0x00, /* sub r12, r17, r17 */
3161 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3162 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3163 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3164 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3165 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3166 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3169 static const bfd_byte
*elf_sh64_plt0_entry
;
3170 static const bfd_byte
*elf_sh64_plt_entry
;
3171 static const bfd_byte
*elf_sh64_pic_plt_entry
;
3173 /* Create an entry in an sh ELF linker hash table. */
3175 static struct bfd_hash_entry
*
3176 sh64_elf64_link_hash_newfunc (entry
, table
, string
)
3177 struct bfd_hash_entry
*entry
;
3178 struct bfd_hash_table
*table
;
3181 struct elf_sh64_link_hash_entry
*ret
=
3182 (struct elf_sh64_link_hash_entry
*) entry
;
3184 /* Allocate the structure if it has not already been allocated by a
3186 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3187 ret
= ((struct elf_sh64_link_hash_entry
*)
3188 bfd_hash_allocate (table
,
3189 sizeof (struct elf_sh64_link_hash_entry
)));
3190 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3191 return (struct bfd_hash_entry
*) ret
;
3193 /* Call the allocation method of the superclass. */
3194 ret
= ((struct elf_sh64_link_hash_entry
*)
3195 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3197 if (ret
!= (struct elf_sh64_link_hash_entry
*) NULL
)
3199 ret
->pcrel_relocs_copied
= NULL
;
3200 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3203 return (struct bfd_hash_entry
*) ret
;
3206 /* Create an sh64 ELF linker hash table. */
3208 static struct bfd_link_hash_table
*
3209 sh64_elf64_link_hash_table_create (abfd
)
3212 struct elf_sh64_link_hash_table
*ret
;
3214 ret
= ((struct elf_sh64_link_hash_table
*)
3215 bfd_alloc (abfd
, sizeof (struct elf_sh64_link_hash_table
)));
3216 if (ret
== (struct elf_sh64_link_hash_table
*) NULL
)
3219 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3220 sh64_elf64_link_hash_newfunc
))
3222 bfd_release (abfd
, ret
);
3226 return &ret
->root
.root
;
3230 movi_shori_putval (output_bfd
, value
, addr
)
3232 unsigned long value
;
3235 bfd_put_32 (output_bfd
,
3236 bfd_get_32 (output_bfd
, addr
)
3237 | ((value
>> 6) & 0x3fffc00),
3239 bfd_put_32 (output_bfd
,
3240 bfd_get_32 (output_bfd
, addr
+ 4)
3241 | ((value
<< 10) & 0x3fffc00),
3246 movi_3shori_putval (output_bfd
, value
, addr
)
3251 bfd_put_32 (output_bfd
,
3252 bfd_get_32 (output_bfd
, addr
)
3253 | ((value
>> 38) & 0x3fffc00),
3255 bfd_put_32 (output_bfd
,
3256 bfd_get_32 (output_bfd
, addr
+ 4)
3257 | ((value
>> 22) & 0x3fffc00),
3259 bfd_put_32 (output_bfd
,
3260 bfd_get_32 (output_bfd
, addr
+ 8)
3261 | ((value
>> 6) & 0x3fffc00),
3263 bfd_put_32 (output_bfd
,
3264 bfd_get_32 (output_bfd
, addr
+ 12)
3265 | ((value
<< 10) & 0x3fffc00),
3269 /* Create dynamic sections when linking against a dynamic object. */
3272 sh64_elf64_create_dynamic_sections (abfd
, info
)
3274 struct bfd_link_info
*info
;
3276 flagword flags
, pltflags
;
3277 register asection
*s
;
3278 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3281 switch (bed
->s
->arch_size
)
3292 bfd_set_error (bfd_error_bad_value
);
3296 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3297 .rel[a].bss sections. */
3299 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3300 | SEC_LINKER_CREATED
);
3303 pltflags
|= SEC_CODE
;
3304 if (bed
->plt_not_loaded
)
3305 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3306 if (bed
->plt_readonly
)
3307 pltflags
|= SEC_READONLY
;
3309 s
= bfd_make_section (abfd
, ".plt");
3311 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3312 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3315 if (bed
->want_plt_sym
)
3317 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3319 struct elf_link_hash_entry
*h
= NULL
;
3320 if (! (_bfd_generic_link_add_one_symbol
3321 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3322 (bfd_vma
) 0, (const char *) NULL
, false,
3323 get_elf_backend_data (abfd
)->collect
,
3324 (struct bfd_link_hash_entry
**) &h
)))
3326 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3327 h
->type
= STT_OBJECT
;
3330 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3334 s
= bfd_make_section (abfd
,
3335 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3337 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3338 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3341 if (! _bfd_elf_create_got_section (abfd
, info
))
3345 const char *secname
;
3350 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3352 secflags
= bfd_get_section_flags (abfd
, sec
);
3353 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3354 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3356 secname
= bfd_get_section_name (abfd
, sec
);
3357 relname
= (char *) bfd_malloc (strlen (secname
) + 6);
3358 strcpy (relname
, ".rela");
3359 strcat (relname
, secname
);
3360 s
= bfd_make_section (abfd
, relname
);
3362 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3363 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3368 if (bed
->want_dynbss
)
3370 /* The .dynbss section is a place to put symbols which are defined
3371 by dynamic objects, are referenced by regular objects, and are
3372 not functions. We must allocate space for them in the process
3373 image and use a R_*_COPY reloc to tell the dynamic linker to
3374 initialize them at run time. The linker script puts the .dynbss
3375 section into the .bss section of the final image. */
3376 s
= bfd_make_section (abfd
, ".dynbss");
3378 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3381 /* The .rel[a].bss section holds copy relocs. This section is not
3382 normally needed. We need to create it here, though, so that the
3383 linker will map it to an output section. We can't just create it
3384 only if we need it, because we will not know whether we need it
3385 until we have seen all the input files, and the first time the
3386 main linker code calls BFD after examining all the input files
3387 (size_dynamic_sections) the input sections have already been
3388 mapped to the output sections. If the section turns out not to
3389 be needed, we can discard it later. We will never need this
3390 section when generating a shared object, since they do not use
3394 s
= bfd_make_section (abfd
,
3395 (bed
->default_use_rela_p
3396 ? ".rela.bss" : ".rel.bss"));
3398 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3399 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3407 /* Adjust a symbol defined by a dynamic object and referenced by a
3408 regular object. The current definition is in some section of the
3409 dynamic object, but we're not including those sections. We have to
3410 change the definition to something the rest of the link can
3414 sh64_elf64_adjust_dynamic_symbol (info
, h
)
3415 struct bfd_link_info
*info
;
3416 struct elf_link_hash_entry
*h
;
3420 unsigned int power_of_two
;
3422 dynobj
= elf_hash_table (info
)->dynobj
;
3424 /* Make sure we know what is going on here. */
3425 BFD_ASSERT (dynobj
!= NULL
3426 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3427 || h
->weakdef
!= NULL
3428 || ((h
->elf_link_hash_flags
3429 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3430 && (h
->elf_link_hash_flags
3431 & ELF_LINK_HASH_REF_REGULAR
) != 0
3432 && (h
->elf_link_hash_flags
3433 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3435 /* If this is a function, put it in the procedure linkage table. We
3436 will fill in the contents of the procedure linkage table later,
3437 when we know the address of the .got section. */
3438 if (h
->type
== STT_FUNC
3439 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3442 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3443 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
3445 /* This case can occur if we saw a PLT reloc in an input
3446 file, but the symbol was never referred to by a dynamic
3447 object. In such a case, we don't actually need to build
3448 a procedure linkage table, and we can just do a REL64
3450 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
3454 /* Make sure this symbol is output as a dynamic symbol. */
3455 if (h
->dynindx
== -1)
3457 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3461 s
= bfd_get_section_by_name (dynobj
, ".plt");
3462 BFD_ASSERT (s
!= NULL
);
3464 /* If this is the first .plt entry, make room for the special
3466 if (s
->_raw_size
== 0)
3467 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3469 /* If this symbol is not defined in a regular file, and we are
3470 not generating a shared library, then set the symbol to this
3471 location in the .plt. This is required to make function
3472 pointers compare as equal between the normal executable and
3473 the shared library. */
3475 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3477 h
->root
.u
.def
.section
= s
;
3478 h
->root
.u
.def
.value
= s
->_raw_size
;
3481 h
->plt
.offset
= s
->_raw_size
;
3483 /* Make room for this entry. */
3484 s
->_raw_size
+= elf_sh64_sizeof_plt (info
);
3486 /* We also need to make an entry in the .got.plt section, which
3487 will be placed in the .got section by the linker script. */
3489 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3490 BFD_ASSERT (s
!= NULL
);
3493 /* We also need to make an entry in the .rela.plt section. */
3495 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3496 BFD_ASSERT (s
!= NULL
);
3497 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3502 /* If this is a weak symbol, and there is a real definition, the
3503 processor independent code will have arranged for us to see the
3504 real definition first, and we can just use the same value. */
3505 if (h
->weakdef
!= NULL
)
3507 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3508 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3509 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3510 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3514 /* This is a reference to a symbol defined by a dynamic object which
3515 is not a function. */
3517 /* If we are creating a shared library, we must presume that the
3518 only references to the symbol are via the global offset table.
3519 For such cases we need not do anything here; the relocations will
3520 be handled correctly by relocate_section. */
3524 /* If there are no references to this symbol that do not use the
3525 GOT, we don't need to generate a copy reloc. */
3526 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3529 /* We must allocate the symbol in our .dynbss section, which will
3530 become part of the .bss section of the executable. There will be
3531 an entry for this symbol in the .dynsym section. The dynamic
3532 object will contain position independent code, so all references
3533 from the dynamic object to this symbol will go through the global
3534 offset table. The dynamic linker will use the .dynsym entry to
3535 determine the address it must put in the global offset table, so
3536 both the dynamic object and the regular object will refer to the
3537 same memory location for the variable. */
3539 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3540 BFD_ASSERT (s
!= NULL
);
3542 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3543 copy the initial value out of the dynamic object and into the
3544 runtime process image. We need to remember the offset into the
3545 .rela.bss section we are going to use. */
3546 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3550 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3551 BFD_ASSERT (srel
!= NULL
);
3552 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
3553 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3556 /* We need to figure out the alignment required for this symbol. I
3557 have no idea how ELF linkers handle this. */
3558 power_of_two
= bfd_log2 (h
->size
);
3559 if (power_of_two
> 3)
3562 /* Apply the required alignment. */
3563 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3564 (bfd_size_type
) (1 << power_of_two
));
3565 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3567 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3571 /* Define the symbol as being at this point in the section. */
3572 h
->root
.u
.def
.section
= s
;
3573 h
->root
.u
.def
.value
= s
->_raw_size
;
3575 /* Increment the section size to make room for the symbol. */
3576 s
->_raw_size
+= h
->size
;
3581 /* This function is called via sh_elf_link_hash_traverse if we are
3582 creating a shared object with -Bsymbolic. It discards the space
3583 allocated to copy PC relative relocs against symbols which are
3584 defined in regular objects. We allocated space for them in the
3585 check_relocs routine, but we won't fill them in in the
3586 relocate_section routine. */
3589 sh64_elf64_discard_copies (h
, ignore
)
3590 struct elf_sh64_link_hash_entry
*h
;
3591 PTR ignore ATTRIBUTE_UNUSED
;
3593 struct elf_sh64_pcrel_relocs_copied
*s
;
3595 /* We only discard relocs for symbols defined in a regular object. */
3596 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3599 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3600 s
->section
->_raw_size
-= s
->count
* sizeof (Elf64_External_Rela
);
3605 /* Set the sizes of the dynamic sections. */
3608 sh64_elf64_size_dynamic_sections (output_bfd
, info
)
3610 struct bfd_link_info
*info
;
3618 dynobj
= elf_hash_table (info
)->dynobj
;
3619 BFD_ASSERT (dynobj
!= NULL
);
3621 if (elf_hash_table (info
)->dynamic_sections_created
)
3623 /* Set the contents of the .interp section to the interpreter. */
3626 s
= bfd_get_section_by_name (dynobj
, ".interp");
3627 BFD_ASSERT (s
!= NULL
);
3628 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3629 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3634 /* We may have created entries in the .rela.got section.
3635 However, if we are not creating the dynamic sections, we will
3636 not actually use these entries. Reset the size of .rela.got,
3637 which will cause it to get stripped from the output file
3639 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
3644 /* If this is a -Bsymbolic shared link, then we need to discard all
3645 PC relative relocs against symbols defined in a regular object.
3646 We allocated space for them in the check_relocs routine, but we
3647 will not fill them in in the relocate_section routine. */
3648 if (info
->shared
&& info
->symbolic
)
3649 sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info
),
3650 sh64_elf64_discard_copies
,
3653 /* The check_relocs and adjust_dynamic_symbol entry points have
3654 determined the sizes of the various dynamic sections. Allocate
3659 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3664 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3667 /* It's OK to base decisions on the section name, because none
3668 of the dynobj section names depend upon the input files. */
3669 name
= bfd_get_section_name (dynobj
, s
);
3673 if (strcmp (name
, ".plt") == 0)
3675 if (s
->_raw_size
== 0)
3677 /* Strip this section if we don't need it; see the
3683 /* Remember whether there is a PLT. */
3687 else if (strncmp (name
, ".rela", 5) == 0)
3689 if (s
->_raw_size
== 0)
3691 /* If we don't need this section, strip it from the
3692 output file. This is mostly to handle .rela.bss and
3693 .rela.plt. We must create both sections in
3694 create_dynamic_sections, because they must be created
3695 before the linker maps input sections to output
3696 sections. The linker does that before
3697 adjust_dynamic_symbol is called, and it is that
3698 function which decides whether anything needs to go
3699 into these sections. */
3706 /* Remember whether there are any reloc sections other
3708 if (strcmp (name
, ".rela.plt") != 0)
3710 const char *outname
;
3714 /* If this relocation section applies to a read only
3715 section, then we probably need a DT_TEXTREL
3716 entry. The entries in the .rela.plt section
3717 really apply to the .got section, which we
3718 created ourselves and so know is not readonly. */
3719 outname
= bfd_get_section_name (output_bfd
,
3721 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3723 && (target
->flags
& SEC_READONLY
) != 0
3724 && (target
->flags
& SEC_ALLOC
) != 0)
3728 /* We use the reloc_count field as a counter if we need
3729 to copy relocs into the output file. */
3733 else if (strncmp (name
, ".got", 4) != 0)
3735 /* It's not one of our sections, so don't allocate space. */
3741 _bfd_strip_section_from_output (info
, s
);
3745 /* Allocate memory for the section contents. */
3746 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
3747 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3751 if (elf_hash_table (info
)->dynamic_sections_created
)
3753 /* Add some entries to the .dynamic section. We fill in the
3754 values later, in sh64_elf64_finish_dynamic_sections, but we
3755 must add the entries now so that we get the correct size for
3756 the .dynamic section. The DT_DEBUG entry is filled in by the
3757 dynamic linker and used by the debugger. */
3760 if (! bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
3766 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0)
3767 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3768 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3769 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
3775 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
3776 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
3777 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
3778 sizeof (Elf64_External_Rela
)))
3784 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3792 /* Finish up dynamic symbol handling. We set the contents of various
3793 dynamic sections here. */
3796 sh64_elf64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3798 struct bfd_link_info
*info
;
3799 struct elf_link_hash_entry
*h
;
3800 Elf_Internal_Sym
*sym
;
3804 dynobj
= elf_hash_table (info
)->dynobj
;
3806 if (h
->plt
.offset
!= (bfd_vma
) -1)
3814 Elf_Internal_Rela rel
;
3816 /* This symbol has an entry in the procedure linkage table. Set
3819 BFD_ASSERT (h
->dynindx
!= -1);
3821 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3822 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3823 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3824 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3826 /* Get the index in the procedure linkage table which
3827 corresponds to this symbol. This is the index of this symbol
3828 in all the symbols for which we are making plt entries. The
3829 first entry in the procedure linkage table is reserved. */
3830 plt_index
= h
->plt
.offset
/ elf_sh64_sizeof_plt (info
) - 1;
3832 /* Get the offset into the .got table of the entry that
3833 corresponds to this function. Each .got entry is 8 bytes.
3834 The first three are reserved. */
3835 got_offset
= (plt_index
+ 3) * 8;
3837 got_offset
-= GOT_BIAS
;
3839 /* Fill in the entry in the procedure linkage table. */
3842 if (elf_sh64_plt_entry
== NULL
)
3844 elf_sh64_plt_entry
= (bfd_big_endian (output_bfd
) ?
3845 elf_sh64_plt_entry_be
: elf_sh64_plt_entry_le
);
3847 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_plt_entry
,
3848 elf_sh64_sizeof_plt (info
));
3849 movi_3shori_putval (output_bfd
,
3850 (sgot
->output_section
->vma
3851 + sgot
->output_offset
3853 (splt
->contents
+ h
->plt
.offset
3854 + elf_sh64_plt_symbol_offset (info
)));
3856 movi_shori_putval (output_bfd
,
3857 (splt
->output_section
->vma
+ splt
->output_offset
),
3858 (splt
->contents
+ h
->plt
.offset
3859 + elf_sh64_plt_plt0_offset (info
)));
3863 if (elf_sh64_pic_plt_entry
== NULL
)
3865 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3866 elf_sh64_pic_plt_entry_be
:
3867 elf_sh64_pic_plt_entry_le
);
3869 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_pic_plt_entry
,
3870 elf_sh64_sizeof_plt (info
));
3871 movi_shori_putval (output_bfd
, got_offset
,
3872 (splt
->contents
+ h
->plt
.offset
3873 + elf_sh64_plt_symbol_offset (info
)));
3876 got_offset
+= GOT_BIAS
;
3878 movi_shori_putval (output_bfd
,
3879 plt_index
* sizeof (Elf64_External_Rela
),
3880 (splt
->contents
+ h
->plt
.offset
3881 + elf_sh64_plt_reloc_offset (info
)));
3883 /* Fill in the entry in the global offset table. */
3884 bfd_put_64 (output_bfd
,
3885 (splt
->output_section
->vma
3886 + splt
->output_offset
3888 + elf_sh64_plt_temp_offset (info
)),
3889 sgot
->contents
+ got_offset
);
3891 /* Fill in the entry in the .rela.plt section. */
3892 rel
.r_offset
= (sgot
->output_section
->vma
3893 + sgot
->output_offset
3895 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_JMP_SLOT64
);
3897 rel
.r_addend
= GOT_BIAS
;
3898 bfd_elf64_swap_reloca_out (output_bfd
, &rel
,
3899 ((Elf64_External_Rela
*) srel
->contents
3902 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3904 /* Mark the symbol as undefined, rather than as defined in
3905 the .plt section. Leave the value alone. */
3906 sym
->st_shndx
= SHN_UNDEF
;
3910 if (h
->got
.offset
!= (bfd_vma
) -1)
3914 Elf_Internal_Rela rel
;
3916 /* This symbol has an entry in the global offset table. Set it
3919 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3920 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3921 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3923 rel
.r_offset
= (sgot
->output_section
->vma
3924 + sgot
->output_offset
3925 + (h
->got
.offset
&~ 1));
3927 /* If this is a -Bsymbolic link, and the symbol is defined
3928 locally, we just want to emit a RELATIVE reloc. Likewise if
3929 the symbol was forced to be local because of a version file.
3930 The entry in the global offset table will already have been
3931 initialized in the relocate_section function. */
3933 && (info
->symbolic
|| h
->dynindx
== -1)
3934 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3936 rel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
3937 rel
.r_addend
= (h
->root
.u
.def
.value
3938 + h
->root
.u
.def
.section
->output_section
->vma
3939 + h
->root
.u
.def
.section
->output_offset
);
3943 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3944 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_GLOB_DAT64
);
3948 bfd_elf64_swap_reloca_out (output_bfd
, &rel
,
3949 ((Elf64_External_Rela
*) srel
->contents
3950 + srel
->reloc_count
));
3951 ++srel
->reloc_count
;
3954 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3957 Elf_Internal_Rela rel
;
3959 /* This symbol needs a copy reloc. Set it up. */
3961 BFD_ASSERT (h
->dynindx
!= -1
3962 && (h
->root
.type
== bfd_link_hash_defined
3963 || h
->root
.type
== bfd_link_hash_defweak
));
3965 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3967 BFD_ASSERT (s
!= NULL
);
3969 rel
.r_offset
= (h
->root
.u
.def
.value
3970 + h
->root
.u
.def
.section
->output_section
->vma
3971 + h
->root
.u
.def
.section
->output_offset
);
3972 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_COPY64
);
3974 bfd_elf64_swap_reloca_out (output_bfd
, &rel
,
3975 ((Elf64_External_Rela
*) s
->contents
3980 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3981 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3982 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3983 sym
->st_shndx
= SHN_ABS
;
3988 /* Finish up the dynamic sections. */
3991 sh64_elf64_finish_dynamic_sections (output_bfd
, info
)
3993 struct bfd_link_info
*info
;
3999 dynobj
= elf_hash_table (info
)->dynobj
;
4001 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4002 BFD_ASSERT (sgot
!= NULL
);
4003 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4005 if (elf_hash_table (info
)->dynamic_sections_created
)
4008 Elf64_External_Dyn
*dyncon
, *dynconend
;
4010 BFD_ASSERT (sdyn
!= NULL
);
4012 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4013 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4014 for (; dyncon
< dynconend
; dyncon
++)
4016 Elf_Internal_Dyn dyn
;
4020 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4034 s
= bfd_get_section_by_name (output_bfd
, name
);
4035 BFD_ASSERT (s
!= NULL
);
4036 dyn
.d_un
.d_ptr
= s
->vma
;
4037 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4041 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4042 BFD_ASSERT (s
!= NULL
);
4043 if (s
->_cooked_size
!= 0)
4044 dyn
.d_un
.d_val
= s
->_cooked_size
;
4046 dyn
.d_un
.d_val
= s
->_raw_size
;
4047 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4051 /* My reading of the SVR4 ABI indicates that the
4052 procedure linkage table relocs (DT_JMPREL) should be
4053 included in the overall relocs (DT_RELA). This is
4054 what Solaris does. However, UnixWare can not handle
4055 that case. Therefore, we override the DT_RELASZ entry
4056 here to make it not include the JMPREL relocs. Since
4057 the linker script arranges for .rela.plt to follow all
4058 other relocation sections, we don't have to worry
4059 about changing the DT_RELA entry. */
4060 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4063 if (s
->_cooked_size
!= 0)
4064 dyn
.d_un
.d_val
-= s
->_cooked_size
;
4066 dyn
.d_un
.d_val
-= s
->_raw_size
;
4068 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4073 /* Fill in the first entry in the procedure linkage table. */
4074 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4075 if (splt
&& splt
->_raw_size
> 0)
4079 if (elf_sh64_pic_plt_entry
== NULL
)
4081 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
4082 elf_sh64_pic_plt_entry_be
:
4083 elf_sh64_pic_plt_entry_le
);
4085 memcpy (splt
->contents
, elf_sh64_pic_plt_entry
,
4086 elf_sh64_sizeof_plt (info
));
4090 if (elf_sh64_plt0_entry
== NULL
)
4092 elf_sh64_plt0_entry
= (bfd_big_endian (output_bfd
) ?
4093 elf_sh64_plt0_entry_be
:
4094 elf_sh64_plt0_entry_le
);
4096 memcpy (splt
->contents
, elf_sh64_plt0_entry
, PLT_ENTRY_SIZE
);
4097 movi_3shori_putval (output_bfd
,
4098 sgot
->output_section
->vma
4099 + sgot
->output_offset
,
4101 + elf_sh64_plt0_gotplt_offset (info
));
4104 /* UnixWare sets the entsize of .plt to 8, although that doesn't
4105 really seem like the right value. */
4106 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 8;
4110 /* Fill in the first three entries in the global offset table. */
4111 if (sgot
->_raw_size
> 0)
4114 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4116 bfd_put_64 (output_bfd
,
4117 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4119 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4120 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 16);
4123 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
4130 #define TARGET_BIG_SYM bfd_elf64_sh64_vec
4131 #define TARGET_BIG_NAME "elf64-sh64"
4132 #define TARGET_LITTLE_SYM bfd_elf64_sh64l_vec
4133 #define TARGET_LITTLE_NAME "elf64-sh64l"
4134 #define ELF_ARCH bfd_arch_sh
4135 #define ELF_MACHINE_CODE EM_SH
4136 #define ELF_MAXPAGESIZE 128
4138 #define elf_symbol_leading_char '_'
4139 #endif /* ELF_ARCH */
4141 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
4142 #define elf_info_to_howto sh_elf64_info_to_howto
4144 /* Note: there's no relaxation at present. */
4146 #define elf_backend_relocate_section sh_elf64_relocate_section
4147 #define bfd_elf64_bfd_get_relocated_section_contents \
4148 sh_elf64_get_relocated_section_contents
4149 #define elf_backend_object_p sh_elf64_set_mach_from_flags
4150 #define bfd_elf64_bfd_set_private_flags \
4151 sh_elf64_set_private_flags
4152 #define bfd_elf64_bfd_copy_private_bfd_data \
4153 sh_elf64_copy_private_data
4154 #define bfd_elf64_bfd_merge_private_bfd_data \
4155 sh_elf64_merge_private_data
4156 #define elf_backend_fake_sections sh64_elf64_fake_sections
4158 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
4159 #define elf_backend_gc_sweep_hook sh_elf64_gc_sweep_hook
4160 #define elf_backend_check_relocs sh_elf64_check_relocs
4162 #define elf_backend_can_gc_sections 1
4164 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
4166 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
4168 #define elf_backend_link_output_symbol_hook \
4169 sh64_elf64_link_output_symbol_hook
4171 #define elf_backend_final_write_processing \
4172 sh64_elf64_final_write_processing
4174 #define elf_backend_create_dynamic_sections \
4175 sh64_elf64_create_dynamic_sections
4176 #define bfd_elf64_bfd_link_hash_table_create \
4177 sh64_elf64_link_hash_table_create
4178 #define elf_backend_adjust_dynamic_symbol \
4179 sh64_elf64_adjust_dynamic_symbol
4180 #define elf_backend_size_dynamic_sections \
4181 sh64_elf64_size_dynamic_sections
4182 #define elf_backend_finish_dynamic_symbol \
4183 sh64_elf64_finish_dynamic_symbol
4184 #define elf_backend_finish_dynamic_sections \
4185 sh64_elf64_finish_dynamic_sections
4187 #define elf_backend_want_got_plt 1
4188 #define elf_backend_plt_readonly 1
4189 #define elf_backend_want_plt_sym 0
4190 #define elf_backend_got_header_size 24
4191 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
4193 #include "elf64-target.h"