1 /* SuperH SH64-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010, 2011, 2012 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
31 /* Add a suffix for datalabel indirection symbols. It must not match any
32 other symbols; user symbols with or without version or other
33 decoration. It must only be used internally and not emitted by any
35 #define DATALABEL_SUFFIX " DL"
37 #define GOT_BIAS (-((long)-32768))
39 #define PLT_ENTRY_SIZE 64
41 /* Return size of a PLT entry. */
42 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
44 /* Return offset of the PLT0 address in an absolute PLT entry. */
45 #define elf_sh64_plt_plt0_offset(info) 32
47 /* Return offset of the linker in PLT0 entry. */
48 #define elf_sh64_plt0_gotplt_offset(info) 0
50 /* Return offset of the trampoline in PLT entry */
51 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
53 /* Return offset of the symbol in PLT entry. */
54 #define elf_sh64_plt_symbol_offset(info) 0
56 /* Return offset of the relocation in PLT entry. */
57 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
59 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
61 /* The sh linker needs to keep track of the number of relocs that it
62 decides to copy in check_relocs for each symbol. This is so that
63 it can discard PC relative relocs if it doesn't need them when
64 linking with -Bsymbolic. We store the information in a field
65 extending the regular ELF linker hash table. */
67 /* This structure keeps track of the number of PC relative relocs we
68 have copied for a given symbol. */
70 struct elf_sh64_pcrel_relocs_copied
73 struct elf_sh64_pcrel_relocs_copied *next;
74 /* A section in dynobj. */
76 /* Number of relocs copied in this section. */
80 /* sh ELF linker hash entry. */
82 struct elf_sh64_link_hash_entry
84 struct elf_link_hash_entry root;
86 bfd_vma datalabel_got_offset;
88 /* Number of PC relative relocs copied for this symbol. */
89 struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied;
92 /* Traverse an sh ELF linker hash table. */
94 #define sh64_elf64_link_hash_traverse(table, func, info) \
95 (elf_link_hash_traverse \
97 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
100 static bfd_reloc_status_type sh_elf64_ignore_reloc
101 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
102 static bfd_reloc_status_type sh_elf64_reloc
103 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
105 static reloc_howto_type sh_elf64_howto_table[] = {
107 HOWTO (R_SH_NONE, /* type */
109 0, /* size (0 = byte, 1 = short, 2 = long) */
111 FALSE, /* pc_relative */
113 complain_overflow_dont, /* complain_on_overflow */
114 sh_elf64_ignore_reloc, /* special_function */
115 "R_SH_NONE", /* name */
116 FALSE, /* partial_inplace */
119 FALSE), /* pcrel_offset */
121 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
122 src_mask to a non-zero value is similar to the COFF toolchain. */
123 HOWTO (R_SH_DIR32, /* type */
125 2, /* size (0 = byte, 1 = short, 2 = long) */
127 FALSE, /* pc_relative */
129 complain_overflow_bitfield, /* complain_on_overflow */
130 sh_elf64_reloc, /* special_function */
131 "R_SH_DIR32", /* name */
132 TRUE, /* partial_inplace */
133 0xffffffff, /* src_mask */
134 0xffffffff, /* dst_mask */
135 FALSE), /* pcrel_offset */
137 /* 32 bit PC relative relocation. */
138 HOWTO (R_SH_REL32, /* type */
140 2, /* size (0 = byte, 1 = short, 2 = long) */
142 TRUE, /* pc_relative */
144 complain_overflow_signed, /* complain_on_overflow */
145 sh_elf64_ignore_reloc, /* special_function */
146 "R_SH_REL32", /* name */
147 FALSE, /* partial_inplace */
149 0xffffffff, /* dst_mask */
150 TRUE), /* pcrel_offset */
152 /* For 32-bit sh, this is R_SH_DIR8WPN. */
155 /* For 32-bit sh, this is R_SH_IND12W. */
158 /* For 32-bit sh, this is R_SH_DIR8WPL. */
161 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
164 /* For 32-bit sh, this is R_SH_DIR8BP. */
167 /* For 32-bit sh, this is R_SH_DIR8W. */
170 /* For 32-bit sh, this is R_SH_DIR8L. */
189 /* The remaining relocs are a GNU extension used for relaxing. The
190 final pass of the linker never needs to do anything with any of
191 these relocs. Any required operations are handled by the
194 /* A 16 bit switch table entry. This is generated for an expression
195 such as ``.word L1 - L2''. The offset holds the difference
196 between the reloc address and L2. */
197 HOWTO (R_SH_SWITCH16, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 FALSE, /* pc_relative */
203 complain_overflow_unsigned, /* complain_on_overflow */
204 sh_elf64_ignore_reloc, /* special_function */
205 "R_SH_SWITCH16", /* name */
206 FALSE, /* partial_inplace */
209 TRUE), /* pcrel_offset */
211 /* A 32 bit switch table entry. This is generated for an expression
212 such as ``.long L1 - L2''. The offset holds the difference
213 between the reloc address and L2. */
214 HOWTO (R_SH_SWITCH32, /* type */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
218 FALSE, /* pc_relative */
220 complain_overflow_unsigned, /* complain_on_overflow */
221 sh_elf64_ignore_reloc, /* special_function */
222 "R_SH_SWITCH32", /* name */
223 FALSE, /* partial_inplace */
226 TRUE), /* pcrel_offset */
228 /* For 32-bit sh, this is R_SH_USES. */
231 /* For 32-bit sh, this is R_SH_COUNT. */
234 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
235 this might be emitted. When linker relaxation is implemented, we
236 might want to use it. */
239 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
240 this might be emitted. When linker relaxation is implemented, we
241 might want to use it. */
244 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
245 this might be emitted. When linker relaxation is implemented, we
246 might want to use it. */
249 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
250 this might be emitted. When linker relaxation is implemented, we
251 might want to use it. */
254 /* An 8 bit switch table entry. This is generated for an expression
255 such as ``.word L1 - L2''. The offset holds the difference
256 between the reloc address and L2. */
257 HOWTO (R_SH_SWITCH8, /* type */
259 0, /* size (0 = byte, 1 = short, 2 = long) */
261 FALSE, /* pc_relative */
263 complain_overflow_unsigned, /* complain_on_overflow */
264 sh_elf64_ignore_reloc, /* special_function */
265 "R_SH_SWITCH8", /* name */
266 FALSE, /* partial_inplace */
269 TRUE), /* pcrel_offset */
271 /* GNU extension to record C++ vtable hierarchy */
272 HOWTO (R_SH_GNU_VTINHERIT, /* type */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
276 FALSE, /* pc_relative */
278 complain_overflow_dont, /* complain_on_overflow */
279 NULL, /* special_function */
280 "R_SH_GNU_VTINHERIT", /* name */
281 FALSE, /* partial_inplace */
284 FALSE), /* pcrel_offset */
286 /* GNU extension to record C++ vtable member usage */
287 HOWTO (R_SH_GNU_VTENTRY, /* type */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
291 FALSE, /* pc_relative */
293 complain_overflow_dont, /* complain_on_overflow */
294 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
295 "R_SH_GNU_VTENTRY", /* name */
296 FALSE, /* partial_inplace */
299 FALSE), /* pcrel_offset */
301 /* For 32-bit sh, this is R_SH_LOOP_START. */
304 /* For 32-bit sh, this is R_SH_LOOP_END. */
315 /* Used in SHLLI.L and SHLRI.L. */
316 HOWTO (R_SH_DIR5U, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE, /* pc_relative */
322 complain_overflow_unsigned, /* complain_on_overflow */
323 bfd_elf_generic_reloc, /* special_function */
324 "R_SH_DIR5U", /* name */
325 FALSE, /* partial_inplace */
327 0xfc00, /* dst_mask */
328 FALSE), /* pcrel_offset */
330 /* Used in SHARI, SHLLI et al. */
331 HOWTO (R_SH_DIR6U, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE, /* pc_relative */
337 complain_overflow_unsigned, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_SH_DIR6U", /* name */
340 FALSE, /* partial_inplace */
342 0xfc00, /* dst_mask */
343 FALSE), /* pcrel_offset */
345 /* Used in BxxI, LDHI.L et al. */
346 HOWTO (R_SH_DIR6S, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 FALSE, /* pc_relative */
352 complain_overflow_signed, /* complain_on_overflow */
353 bfd_elf_generic_reloc, /* special_function */
354 "R_SH_DIR6S", /* name */
355 FALSE, /* partial_inplace */
357 0xfc00, /* dst_mask */
358 FALSE), /* pcrel_offset */
360 /* Used in ADDI, ANDI et al. */
361 HOWTO (R_SH_DIR10S, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE, /* pc_relative */
367 complain_overflow_signed, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* special_function */
369 "R_SH_DIR10S", /* name */
370 FALSE, /* partial_inplace */
372 0xffc00, /* dst_mask */
373 FALSE), /* pcrel_offset */
375 /* Used in LD.UW, ST.W et al. */
376 HOWTO (R_SH_DIR10SW, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE, /* pc_relative */
382 complain_overflow_signed, /* complain_on_overflow */
383 bfd_elf_generic_reloc, /* special_function */
384 "R_SH_DIR10SW", /* name */
385 FALSE, /* partial_inplace */
387 0xffc00, /* dst_mask */
388 FALSE), /* pcrel_offset */
390 /* Used in LD.L, FLD.S et al. */
391 HOWTO (R_SH_DIR10SL, /* type */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
395 FALSE, /* pc_relative */
397 complain_overflow_signed, /* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_SH_DIR10SL", /* name */
400 FALSE, /* partial_inplace */
402 0xffc00, /* dst_mask */
403 FALSE), /* pcrel_offset */
405 /* Used in FLD.D, FST.P et al. */
406 HOWTO (R_SH_DIR10SQ, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE, /* pc_relative */
412 complain_overflow_signed, /* complain_on_overflow */
413 bfd_elf_generic_reloc, /* special_function */
414 "R_SH_DIR10SQ", /* name */
415 FALSE, /* partial_inplace */
417 0xffc00, /* dst_mask */
418 FALSE), /* pcrel_offset */
529 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
530 any dynamic linking support for 64-bit SH at present. */
542 /* Back to SH5 relocations. */
543 /* Used in MOVI and SHORI (x & 65536). */
544 HOWTO (R_SH_GOT_LOW16, /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 FALSE, /* pc_relative */
550 complain_overflow_dont, /* complain_on_overflow */
551 bfd_elf_generic_reloc, /* special_function */
552 "R_SH_GOT_LOW16", /* name */
553 FALSE, /* partial_inplace */
555 0x3fffc00, /* dst_mask */
556 FALSE), /* pcrel_offset */
558 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
559 HOWTO (R_SH_GOT_MEDLOW16, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 FALSE, /* pc_relative */
565 complain_overflow_dont, /* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_SH_GOT_MEDLOW16", /* name */
568 FALSE, /* partial_inplace */
570 0x3fffc00, /* dst_mask */
571 FALSE), /* pcrel_offset */
573 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
574 HOWTO (R_SH_GOT_MEDHI16, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 FALSE, /* pc_relative */
580 complain_overflow_dont, /* complain_on_overflow */
581 bfd_elf_generic_reloc, /* special_function */
582 "R_SH_GOT_MEDHI16", /* name */
583 FALSE, /* partial_inplace */
585 0x3fffc00, /* dst_mask */
586 FALSE), /* pcrel_offset */
588 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
589 HOWTO (R_SH_GOT_HI16, /* type */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
593 FALSE, /* pc_relative */
595 complain_overflow_dont, /* complain_on_overflow */
596 bfd_elf_generic_reloc, /* special_function */
597 "R_SH_GOT_HI16", /* name */
598 FALSE, /* partial_inplace */
600 0x3fffc00, /* dst_mask */
601 FALSE), /* pcrel_offset */
603 /* Used in MOVI and SHORI (x & 65536). */
604 HOWTO (R_SH_GOTPLT_LOW16, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 FALSE, /* pc_relative */
610 complain_overflow_dont, /* complain_on_overflow */
611 bfd_elf_generic_reloc, /* special_function */
612 "R_SH_GOTPLT_LOW16", /* name */
613 FALSE, /* partial_inplace */
615 0x3fffc00, /* dst_mask */
616 FALSE), /* pcrel_offset */
618 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
619 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 FALSE, /* pc_relative */
625 complain_overflow_dont, /* complain_on_overflow */
626 bfd_elf_generic_reloc, /* special_function */
627 "R_SH_GOTPLT_MEDLOW16", /* name */
628 FALSE, /* partial_inplace */
630 0x3fffc00, /* dst_mask */
631 FALSE), /* pcrel_offset */
633 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
634 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
636 2, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE, /* pc_relative */
640 complain_overflow_dont, /* complain_on_overflow */
641 bfd_elf_generic_reloc, /* special_function */
642 "R_SH_GOTPLT_MEDHI16", /* name */
643 FALSE, /* partial_inplace */
645 0x3fffc00, /* dst_mask */
646 FALSE), /* pcrel_offset */
648 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
649 HOWTO (R_SH_GOTPLT_HI16, /* type */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
653 FALSE, /* pc_relative */
655 complain_overflow_dont, /* complain_on_overflow */
656 bfd_elf_generic_reloc, /* special_function */
657 "R_SH_GOTPLT_HI16", /* name */
658 FALSE, /* partial_inplace */
660 0x3fffc00, /* dst_mask */
661 FALSE), /* pcrel_offset */
663 /* Used in MOVI and SHORI (x & 65536). */
664 HOWTO (R_SH_PLT_LOW16, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 TRUE, /* pc_relative */
670 complain_overflow_dont, /* complain_on_overflow */
671 bfd_elf_generic_reloc, /* special_function */
672 "R_SH_PLT_LOW16", /* name */
673 FALSE, /* partial_inplace */
675 0x3fffc00, /* dst_mask */
676 TRUE), /* pcrel_offset */
678 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
679 HOWTO (R_SH_PLT_MEDLOW16, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 TRUE, /* pc_relative */
685 complain_overflow_dont, /* complain_on_overflow */
686 bfd_elf_generic_reloc, /* special_function */
687 "R_SH_PLT_MEDLOW16", /* name */
688 FALSE, /* partial_inplace */
690 0x3fffc00, /* dst_mask */
691 TRUE), /* pcrel_offset */
693 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
694 HOWTO (R_SH_PLT_MEDHI16, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 TRUE, /* pc_relative */
700 complain_overflow_dont, /* complain_on_overflow */
701 bfd_elf_generic_reloc, /* special_function */
702 "R_SH_PLT_MEDHI16", /* name */
703 FALSE, /* partial_inplace */
705 0x3fffc00, /* dst_mask */
706 TRUE), /* pcrel_offset */
708 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
709 HOWTO (R_SH_PLT_HI16, /* type */
711 2, /* size (0 = byte, 1 = short, 2 = long) */
713 TRUE, /* pc_relative */
715 complain_overflow_dont, /* complain_on_overflow */
716 bfd_elf_generic_reloc, /* special_function */
717 "R_SH_PLT_HI16", /* name */
718 FALSE, /* partial_inplace */
720 0x3fffc00, /* dst_mask */
721 TRUE), /* pcrel_offset */
723 /* Used in MOVI and SHORI (x & 65536). */
724 HOWTO (R_SH_GOTOFF_LOW16, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 FALSE, /* pc_relative */
730 complain_overflow_dont, /* complain_on_overflow */
731 bfd_elf_generic_reloc, /* special_function */
732 "R_SH_GOTOFF_LOW16", /* name */
733 FALSE, /* partial_inplace */
735 0x3fffc00, /* dst_mask */
736 FALSE), /* pcrel_offset */
738 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
739 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
741 2, /* size (0 = byte, 1 = short, 2 = long) */
743 FALSE, /* pc_relative */
745 complain_overflow_dont, /* complain_on_overflow */
746 bfd_elf_generic_reloc, /* special_function */
747 "R_SH_GOTOFF_MEDLOW16", /* name */
748 FALSE, /* partial_inplace */
750 0x3fffc00, /* dst_mask */
751 FALSE), /* pcrel_offset */
753 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
754 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
758 FALSE, /* pc_relative */
760 complain_overflow_dont, /* complain_on_overflow */
761 bfd_elf_generic_reloc, /* special_function */
762 "R_SH_GOTOFF_MEDHI16", /* name */
763 FALSE, /* partial_inplace */
765 0x3fffc00, /* dst_mask */
766 FALSE), /* pcrel_offset */
768 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
769 HOWTO (R_SH_GOTOFF_HI16, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 FALSE, /* pc_relative */
775 complain_overflow_dont, /* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_SH_GOTOFF_HI16", /* name */
778 FALSE, /* partial_inplace */
780 0x3fffc00, /* dst_mask */
781 FALSE), /* pcrel_offset */
783 /* Used in MOVI and SHORI (x & 65536). */
784 HOWTO (R_SH_GOTPC_LOW16, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 TRUE, /* pc_relative */
790 complain_overflow_dont, /* complain_on_overflow */
791 bfd_elf_generic_reloc, /* special_function */
792 "R_SH_GOTPC_LOW16", /* name */
793 FALSE, /* partial_inplace */
795 0x3fffc00, /* dst_mask */
796 TRUE), /* pcrel_offset */
798 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
799 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
801 2, /* size (0 = byte, 1 = short, 2 = long) */
803 TRUE, /* pc_relative */
805 complain_overflow_dont, /* complain_on_overflow */
806 bfd_elf_generic_reloc, /* special_function */
807 "R_SH_GOTPC_MEDLOW16", /* name */
808 FALSE, /* partial_inplace */
810 0x3fffc00, /* dst_mask */
811 TRUE), /* pcrel_offset */
813 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
814 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 TRUE, /* pc_relative */
820 complain_overflow_dont, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_SH_GOTPC_MEDHI16", /* name */
823 FALSE, /* partial_inplace */
825 0x3fffc00, /* dst_mask */
826 TRUE), /* pcrel_offset */
828 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
829 HOWTO (R_SH_GOTPC_HI16, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 TRUE, /* pc_relative */
835 complain_overflow_dont, /* complain_on_overflow */
836 bfd_elf_generic_reloc, /* special_function */
837 "R_SH_GOTPC_HI16", /* name */
838 FALSE, /* partial_inplace */
840 0x3fffc00, /* dst_mask */
841 TRUE), /* pcrel_offset */
843 /* Used in LD.L, FLD.S et al. */
844 HOWTO (R_SH_GOT10BY4, /* type */
846 2, /* size (0 = byte, 1 = short, 2 = long) */
848 FALSE, /* pc_relative */
850 complain_overflow_signed, /* complain_on_overflow */
851 bfd_elf_generic_reloc, /* special_function */
852 "R_SH_GOT10BY4", /* name */
853 FALSE, /* partial_inplace */
855 0xffc00, /* dst_mask */
856 FALSE), /* pcrel_offset */
858 /* Used in LD.L, FLD.S et al. */
859 HOWTO (R_SH_GOTPLT10BY4, /* type */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
863 FALSE, /* pc_relative */
865 complain_overflow_signed, /* complain_on_overflow */
866 bfd_elf_generic_reloc, /* special_function */
867 "R_SH_GOTPLT10BY4", /* name */
868 FALSE, /* partial_inplace */
870 0xffc00, /* dst_mask */
871 FALSE), /* pcrel_offset */
873 /* Used in FLD.D, FST.P et al. */
874 HOWTO (R_SH_GOT10BY8, /* type */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
878 FALSE, /* pc_relative */
880 complain_overflow_signed, /* complain_on_overflow */
881 bfd_elf_generic_reloc, /* special_function */
882 "R_SH_GOT10BY8", /* name */
883 FALSE, /* partial_inplace */
885 0xffc00, /* dst_mask */
886 FALSE), /* pcrel_offset */
888 /* Used in FLD.D, FST.P et al. */
889 HOWTO (R_SH_GOTPLT10BY8, /* type */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
893 FALSE, /* pc_relative */
895 complain_overflow_signed, /* complain_on_overflow */
896 bfd_elf_generic_reloc, /* special_function */
897 "R_SH_GOTPLT10BY8", /* name */
898 FALSE, /* partial_inplace */
900 0xffc00, /* dst_mask */
901 FALSE), /* pcrel_offset */
903 HOWTO (R_SH_COPY64, /* type */
905 4, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE, /* pc_relative */
909 complain_overflow_dont, /* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 "R_SH_COPY64", /* name */
912 FALSE, /* partial_inplace */
914 ((bfd_vma) 0) - 1, /* dst_mask */
915 FALSE), /* pcrel_offset */
917 HOWTO (R_SH_GLOB_DAT64, /* type */
919 4, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE, /* pc_relative */
923 complain_overflow_dont, /* complain_on_overflow */
924 bfd_elf_generic_reloc, /* special_function */
925 "R_SH_GLOB_DAT64", /* name */
926 FALSE, /* partial_inplace */
928 ((bfd_vma) 0) - 1, /* dst_mask */
929 FALSE), /* pcrel_offset */
931 HOWTO (R_SH_JMP_SLOT64, /* type */
933 4, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE, /* pc_relative */
937 complain_overflow_dont, /* complain_on_overflow */
938 bfd_elf_generic_reloc, /* special_function */
939 "R_SH_JMP_SLOT64", /* name */
940 FALSE, /* partial_inplace */
942 ((bfd_vma) 0) - 1, /* dst_mask */
943 FALSE), /* pcrel_offset */
945 HOWTO (R_SH_RELATIVE64, /* type */
947 4, /* size (0 = byte, 1 = short, 2 = long) */
949 FALSE, /* pc_relative */
951 complain_overflow_dont, /* complain_on_overflow */
952 bfd_elf_generic_reloc, /* special_function */
953 "R_SH_RELATIVE64", /* name */
954 FALSE, /* partial_inplace */
956 ((bfd_vma) 0) - 1, /* dst_mask */
957 FALSE), /* pcrel_offset */
1005 /* Relocations for SHmedia code. None of these are partial_inplace or
1006 use the field being relocated. */
1008 /* The assembler will generate this reloc before a block of SHmedia
1009 instructions. A section should be processed as assuming it contains
1010 data, unless this reloc is seen. Note that a block of SHcompact
1011 instructions are instead preceded by R_SH_CODE.
1012 This is currently not implemented, but should be used for SHmedia
1013 linker relaxation. */
1014 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1016 1, /* size (0 = byte, 1 = short, 2 = long) */
1018 FALSE, /* pc_relative */
1020 complain_overflow_unsigned, /* complain_on_overflow */
1021 sh_elf64_ignore_reloc, /* special_function */
1022 "R_SH_SHMEDIA_CODE", /* name */
1023 FALSE, /* partial_inplace */
1026 FALSE), /* pcrel_offset */
1028 /* The assembler will generate this reloc at a PTA or PTB instruction,
1029 and the linker checks the right type of target, or changes a PTA to a
1030 PTB, if the original insn was PT. */
1031 HOWTO (R_SH_PT_16, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 TRUE, /* pc_relative */
1037 complain_overflow_signed, /* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 "R_SH_PT_16", /* name */
1040 FALSE, /* partial_inplace */
1042 0x3fffc00, /* dst_mask */
1043 TRUE), /* pcrel_offset */
1045 /* Used in unexpanded MOVI. */
1046 HOWTO (R_SH_IMMS16, /* type */
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE, /* pc_relative */
1052 complain_overflow_signed, /* complain_on_overflow */
1053 bfd_elf_generic_reloc, /* special_function */
1054 "R_SH_IMMS16", /* name */
1055 FALSE, /* partial_inplace */
1057 0x3fffc00, /* dst_mask */
1058 FALSE), /* pcrel_offset */
1060 /* Used in SHORI. */
1061 HOWTO (R_SH_IMMU16, /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE, /* pc_relative */
1067 complain_overflow_unsigned, /* complain_on_overflow */
1068 bfd_elf_generic_reloc, /* special_function */
1069 "R_SH_IMMU16", /* name */
1070 FALSE, /* partial_inplace */
1072 0x3fffc00, /* dst_mask */
1073 FALSE), /* pcrel_offset */
1075 /* Used in MOVI and SHORI (x & 65536). */
1076 HOWTO (R_SH_IMM_LOW16, /* type */
1078 2, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE, /* pc_relative */
1082 complain_overflow_dont, /* complain_on_overflow */
1083 bfd_elf_generic_reloc, /* special_function */
1084 "R_SH_IMM_LOW16", /* name */
1085 FALSE, /* partial_inplace */
1087 0x3fffc00, /* dst_mask */
1088 FALSE), /* pcrel_offset */
1090 /* Used in MOVI and SHORI ((x - $) & 65536). */
1091 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE, /* pc_relative */
1097 complain_overflow_dont, /* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 "R_SH_IMM_LOW16_PCREL", /* name */
1100 FALSE, /* partial_inplace */
1102 0x3fffc00, /* dst_mask */
1103 TRUE), /* pcrel_offset */
1105 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1106 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1107 16, /* rightshift */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE, /* pc_relative */
1112 complain_overflow_dont, /* complain_on_overflow */
1113 bfd_elf_generic_reloc, /* special_function */
1114 "R_SH_IMM_MEDLOW16", /* name */
1115 FALSE, /* partial_inplace */
1117 0x3fffc00, /* dst_mask */
1118 FALSE), /* pcrel_offset */
1120 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1121 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1122 16, /* rightshift */
1123 2, /* size (0 = byte, 1 = short, 2 = long) */
1125 TRUE, /* pc_relative */
1127 complain_overflow_dont, /* complain_on_overflow */
1128 bfd_elf_generic_reloc, /* special_function */
1129 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1130 FALSE, /* partial_inplace */
1132 0x3fffc00, /* dst_mask */
1133 TRUE), /* pcrel_offset */
1135 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1136 HOWTO (R_SH_IMM_MEDHI16, /* type */
1137 32, /* rightshift */
1138 2, /* size (0 = byte, 1 = short, 2 = long) */
1140 FALSE, /* pc_relative */
1142 complain_overflow_dont, /* complain_on_overflow */
1143 bfd_elf_generic_reloc, /* special_function */
1144 "R_SH_IMM_MEDHI16", /* name */
1145 FALSE, /* partial_inplace */
1147 0x3fffc00, /* dst_mask */
1148 FALSE), /* pcrel_offset */
1150 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1151 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1152 32, /* rightshift */
1153 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 TRUE, /* pc_relative */
1157 complain_overflow_dont, /* complain_on_overflow */
1158 bfd_elf_generic_reloc, /* special_function */
1159 "R_SH_IMM_MEDHI16_PCREL", /* name */
1160 FALSE, /* partial_inplace */
1162 0x3fffc00, /* dst_mask */
1163 TRUE), /* pcrel_offset */
1165 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1166 HOWTO (R_SH_IMM_HI16, /* type */
1167 48, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE, /* pc_relative */
1172 complain_overflow_dont, /* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_SH_IMM_HI16", /* name */
1175 FALSE, /* partial_inplace */
1177 0x3fffc00, /* dst_mask */
1178 FALSE), /* pcrel_offset */
1180 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1181 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1182 48, /* rightshift */
1183 2, /* size (0 = byte, 1 = short, 2 = long) */
1185 TRUE, /* pc_relative */
1187 complain_overflow_dont, /* complain_on_overflow */
1188 bfd_elf_generic_reloc, /* special_function */
1189 "R_SH_IMM_HI16_PCREL", /* name */
1190 FALSE, /* partial_inplace */
1192 0x3fffc00, /* dst_mask */
1193 TRUE), /* pcrel_offset */
1195 /* For the .uaquad pseudo. */
1196 HOWTO (R_SH_64, /* type */
1198 4, /* size (0 = byte, 1 = short, 2 = long) */
1200 FALSE, /* pc_relative */
1202 complain_overflow_dont, /* complain_on_overflow */
1203 bfd_elf_generic_reloc, /* special_function */
1204 "R_SH_64", /* name */
1205 FALSE, /* partial_inplace */
1207 ((bfd_vma) 0) - 1, /* dst_mask */
1208 FALSE), /* pcrel_offset */
1210 /* For the .uaquad pseudo, (x - $). */
1211 HOWTO (R_SH_64_PCREL, /* type */
1212 48, /* rightshift */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 TRUE, /* pc_relative */
1217 complain_overflow_dont, /* complain_on_overflow */
1218 bfd_elf_generic_reloc, /* special_function */
1219 "R_SH_64_PCREL", /* name */
1220 FALSE, /* partial_inplace */
1222 ((bfd_vma) 0) - 1, /* dst_mask */
1223 TRUE), /* pcrel_offset */
1227 /* This function is used for relocs which are only used for relaxing,
1228 which the linker should otherwise ignore. */
1230 static bfd_reloc_status_type
1231 sh_elf64_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1232 asymbol *symbol ATTRIBUTE_UNUSED,
1233 void *data ATTRIBUTE_UNUSED, asection *input_section,
1235 char **error_message ATTRIBUTE_UNUSED)
1237 if (output_bfd != NULL)
1238 reloc_entry->address += input_section->output_offset;
1239 return bfd_reloc_ok;
1242 /* This function is used for normal relocs. This used to be like the COFF
1243 function, and is almost certainly incorrect for other ELF targets.
1245 See sh_elf_reloc in elf32-sh.c for the original. */
1247 static bfd_reloc_status_type
1248 sh_elf64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1249 void *data, asection *input_section, bfd *output_bfd,
1250 char **error_message ATTRIBUTE_UNUSED)
1254 enum elf_sh_reloc_type r_type;
1255 bfd_vma addr = reloc_entry->address;
1256 bfd_byte *hit_data = addr + (bfd_byte *) data;
1258 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1260 if (output_bfd != NULL)
1262 /* Partial linking--do nothing. */
1263 reloc_entry->address += input_section->output_offset;
1264 return bfd_reloc_ok;
1267 if (symbol_in != NULL
1268 && bfd_is_und_section (symbol_in->section))
1269 return bfd_reloc_undefined;
1271 if (bfd_is_com_section (symbol_in->section))
1274 sym_value = (symbol_in->value +
1275 symbol_in->section->output_section->vma +
1276 symbol_in->section->output_offset);
1281 insn = bfd_get_32 (abfd, hit_data);
1282 insn += sym_value + reloc_entry->addend;
1283 bfd_put_32 (abfd, insn, hit_data);
1291 return bfd_reloc_ok;
1294 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1296 struct elf_reloc_map
1298 bfd_reloc_code_real_type bfd_reloc_val;
1299 unsigned char elf_reloc_val;
1302 /* An array mapping BFD reloc codes to SH ELF relocs. */
1304 static const struct elf_reloc_map sh64_reloc_map[] =
1306 { BFD_RELOC_NONE, R_SH_NONE },
1307 { BFD_RELOC_32, R_SH_DIR32 },
1308 { BFD_RELOC_CTOR, R_SH_DIR32 },
1309 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1310 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1311 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1312 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1313 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1314 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1315 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1316 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1317 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1318 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1319 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1320 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1321 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1322 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1323 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1324 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1325 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1326 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1327 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1328 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1329 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1330 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1331 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1332 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1333 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1334 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1335 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1336 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1337 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1338 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1339 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1340 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1341 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1342 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1343 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1344 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1345 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1346 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1347 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1348 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1349 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1350 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1351 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1352 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1353 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1354 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1355 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1356 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1357 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1358 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1359 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1360 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1361 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1362 { BFD_RELOC_64, R_SH_64 },
1363 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1366 /* Given a BFD reloc code, return the howto structure for the
1367 corresponding SH ELf reloc. */
1369 static reloc_howto_type *
1370 sh_elf64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1371 bfd_reloc_code_real_type code)
1375 for (i = 0; i < sizeof (sh64_reloc_map) / sizeof (struct elf_reloc_map); i++)
1377 if (sh64_reloc_map[i].bfd_reloc_val == code)
1378 return &sh_elf64_howto_table[(int) sh64_reloc_map[i].elf_reloc_val];
1384 static reloc_howto_type *
1385 sh_elf64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1391 i < sizeof (sh_elf64_howto_table) / sizeof (sh_elf64_howto_table[0]);
1393 if (sh_elf64_howto_table[i].name != NULL
1394 && strcasecmp (sh_elf64_howto_table[i].name, r_name) == 0)
1395 return &sh_elf64_howto_table[i];
1400 /* Given an ELF reloc, fill in the howto field of a relent.
1402 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1405 sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
1406 Elf_Internal_Rela *dst)
1410 r = ELF64_R_TYPE (dst->r_info);
1412 BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL);
1413 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1414 BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2);
1415 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32);
1416 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1418 cache_ptr->howto = &sh_elf64_howto_table[r];
1421 /* Relocate an SH ELF section.
1423 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1426 sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1427 struct bfd_link_info *info, bfd *input_bfd,
1428 asection *input_section, bfd_byte *contents,
1429 Elf_Internal_Rela *relocs,
1430 Elf_Internal_Sym *local_syms,
1431 asection **local_sections)
1433 Elf_Internal_Shdr *symtab_hdr;
1434 struct elf_link_hash_entry **sym_hashes;
1435 Elf_Internal_Rela *rel, *relend;
1437 bfd_vma *local_got_offsets;
1442 bfd_vma disp, dropped;
1444 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1445 sym_hashes = elf_sym_hashes (input_bfd);
1446 dynobj = elf_hash_table (info)->dynobj;
1447 local_got_offsets = elf_local_got_offsets (input_bfd);
1455 relend = relocs + input_section->reloc_count;
1456 for (; rel < relend; rel++)
1459 reloc_howto_type *howto;
1460 unsigned long r_symndx;
1461 Elf_Internal_Sym *sym;
1463 struct elf_link_hash_entry *h;
1465 bfd_vma addend = (bfd_vma)0;
1466 bfd_reloc_status_type r;
1467 int seen_stt_datalabel = 0;
1469 r_symndx = ELF64_R_SYM (rel->r_info);
1471 r_type = ELF64_R_TYPE (rel->r_info);
1473 if (r_type == (int) R_SH_NONE)
1477 || r_type > R_SH_64_PCREL
1478 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
1479 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1480 || (r_type >= (int) R_SH_DIR8WPN
1481 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1482 || (r_type >= (int) R_SH_GNU_VTINHERIT
1483 && r_type <= (int) R_SH_PSHL)
1484 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
1485 && r_type <= R_SH_GOTPLT32)
1486 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
1487 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4))
1489 bfd_set_error (bfd_error_bad_value);
1493 howto = sh_elf64_howto_table + r_type;
1499 if (r_symndx < symtab_hdr->sh_info)
1501 sym = local_syms + r_symndx;
1502 sec = local_sections[r_symndx];
1503 relocation = ((sec->output_section->vma
1504 + sec->output_offset
1506 | ((sym->st_other & STO_SH5_ISA32) != 0));
1508 /* A local symbol never has STO_SH5_ISA32, so we don't need
1509 datalabel processing here. Make sure this does not change
1511 if ((sym->st_other & STO_SH5_ISA32) != 0)
1512 ((*info->callbacks->reloc_dangerous)
1514 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1515 input_bfd, input_section, rel->r_offset));
1517 if (sec != NULL && discarded_section (sec))
1518 /* Handled below. */
1520 else if (info->relocatable)
1522 /* This is a relocatable link. We don't have to change
1523 anything, unless the reloc is against a section symbol,
1524 in which case we have to adjust according to where the
1525 section symbol winds up in the output section. */
1526 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1527 goto final_link_relocate;
1531 else if (! howto->partial_inplace)
1533 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1534 relocation |= ((sym->st_other & STO_SH5_ISA32) != 0);
1536 else if ((sec->flags & SEC_MERGE)
1537 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1541 if (howto->rightshift || howto->src_mask != 0xffffffff)
1543 (*_bfd_error_handler)
1544 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
1545 input_bfd, input_section,
1546 (long) rel->r_offset, howto->name);
1550 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
1553 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
1555 addend += msec->output_section->vma + msec->output_offset;
1556 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
1562 /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ? */
1564 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1565 while (h->root.type == bfd_link_hash_indirect
1566 || h->root.type == bfd_link_hash_warning)
1568 /* If the reference passes a symbol marked with
1569 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1571 seen_stt_datalabel |= h->type == STT_DATALABEL;
1572 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1575 if (h->root.type == bfd_link_hash_defined
1576 || h->root.type == bfd_link_hash_defweak)
1578 sec = h->root.u.def.section;
1579 /* In these cases, we don't need the relocation value.
1580 We check specially because in some obscure cases
1581 sec->output_section will be NULL. */
1582 if (r_type == R_SH_GOTPC_LOW16
1583 || r_type == R_SH_GOTPC_MEDLOW16
1584 || r_type == R_SH_GOTPC_MEDHI16
1585 || r_type == R_SH_GOTPC_HI16
1586 || ((r_type == R_SH_PLT_LOW16
1587 || r_type == R_SH_PLT_MEDLOW16
1588 || r_type == R_SH_PLT_MEDHI16
1589 || r_type == R_SH_PLT_HI16)
1590 && h->plt.offset != (bfd_vma) -1)
1591 || ((r_type == R_SH_GOT_LOW16
1592 || r_type == R_SH_GOT_MEDLOW16
1593 || r_type == R_SH_GOT_MEDHI16
1594 || r_type == R_SH_GOT_HI16)
1595 && elf_hash_table (info)->dynamic_sections_created
1597 || (! info->symbolic && h->dynindx != -1)
1598 || !h->def_regular))
1599 /* The cases above are those in which relocation is
1600 overwritten in the switch block below. The cases
1601 below are those in which we must defer relocation
1602 to run-time, because we can't resolve absolute
1603 addresses when creating a shared library. */
1605 && ((! info->symbolic && h->dynindx != -1)
1607 && ((r_type == R_SH_64
1608 && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1609 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
1610 || r_type == R_SH_64_PCREL)
1611 && ((input_section->flags & SEC_ALLOC) != 0
1612 /* DWARF will emit R_SH_DIR32 relocations in its
1613 sections against symbols defined externally
1614 in shared libraries. We can't do anything
1616 || (input_section->flags & SEC_DEBUGGING) != 0))
1617 /* Dynamic relocs are not propagated for SEC_DEBUGGING
1618 sections because such sections are not SEC_ALLOC and
1619 thus ld.so will not process them. */
1620 || (sec->output_section == NULL
1621 && ((input_section->flags & SEC_DEBUGGING) != 0
1622 && h->def_dynamic)))
1624 else if (sec->output_section != NULL)
1625 relocation = ((h->root.u.def.value
1626 + sec->output_section->vma
1627 + sec->output_offset)
1628 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1629 symbol value, unless we've seen
1630 STT_DATALABEL on the way to it. */
1631 | ((h->other & STO_SH5_ISA32) != 0
1632 && ! seen_stt_datalabel));
1633 else if (!info->relocatable
1634 && (_bfd_elf_section_offset (output_bfd, info,
1639 (*_bfd_error_handler)
1640 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1643 (long) rel->r_offset,
1645 h->root.root.string);
1648 else if (h->root.type == bfd_link_hash_undefweak)
1650 else if (info->unresolved_syms_in_objects == RM_IGNORE
1651 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1653 else if (!info->relocatable)
1655 if (! ((*info->callbacks->undefined_symbol)
1656 (info, h->root.root.string, input_bfd,
1657 input_section, rel->r_offset,
1658 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
1659 || ELF_ST_VISIBILITY (h->other)))))
1664 if (sec != NULL && discarded_section (sec))
1665 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1666 rel, 1, relend, howto, 0, contents);
1668 if (info->relocatable)
1672 - input_section->output_section->vma
1673 - input_section->output_offset
1676 switch ((int)r_type)
1678 case R_SH_PT_16: dropped = disp & 2; break;
1679 case R_SH_DIR10SW: dropped = disp & 1; break;
1680 case R_SH_DIR10SL: dropped = disp & 3; break;
1681 case R_SH_DIR10SQ: dropped = disp & 7; break;
1685 (*_bfd_error_handler)
1686 (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1687 bfd_get_filename (input_bfd), (int)r_type, (unsigned)rel->r_offset, (unsigned)relocation);
1688 bfd_set_error (bfd_error_bad_value);
1691 switch ((int)r_type)
1696 && (input_section->flags & SEC_ALLOC) != 0
1697 && (r_type != R_SH_64_PCREL
1700 && (! info->symbolic
1701 || !h->def_regular))))
1703 Elf_Internal_Rela outrel;
1705 bfd_boolean skip, relocate;
1707 /* When generating a shared object, these relocations
1708 are copied into the output file to be resolved at run
1713 sreloc = _bfd_elf_get_dynamic_reloc_section
1714 (input_bfd, input_section, /*rela?*/ TRUE);
1723 = _bfd_elf_section_offset (output_bfd, info,
1724 input_section, rel->r_offset);
1726 if (outrel.r_offset == (bfd_vma) -1)
1728 else if (outrel.r_offset == (bfd_vma) -2)
1729 skip = TRUE, relocate = TRUE;
1731 outrel.r_offset += (input_section->output_section->vma
1732 + input_section->output_offset);
1735 memset (&outrel, 0, sizeof outrel);
1736 else if (r_type == R_SH_64_PCREL)
1738 BFD_ASSERT (h != NULL && h->dynindx != -1);
1739 outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64_PCREL);
1740 outrel.r_addend = rel->r_addend;
1744 /* h->dynindx may be -1 if this symbol was marked to
1747 || ((info->symbolic || h->dynindx == -1)
1751 outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1752 outrel.r_addend = relocation + rel->r_addend;
1756 BFD_ASSERT (h->dynindx != -1);
1757 outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64);
1758 outrel.r_addend = relocation + rel->r_addend;
1762 loc = sreloc->contents;
1763 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
1764 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1766 /* If this reloc is against an external symbol, we do
1767 not want to fiddle with the addend. Otherwise, we
1768 need to include the symbol value so that it becomes
1769 an addend for the dynamic reloc. */
1773 else if (r_type == R_SH_64)
1774 addend = rel->r_addend;
1775 goto final_link_relocate;
1777 case R_SH_GOTPLT_LOW16:
1778 case R_SH_GOTPLT_MEDLOW16:
1779 case R_SH_GOTPLT_MEDHI16:
1780 case R_SH_GOTPLT_HI16:
1781 case R_SH_GOTPLT10BY4:
1782 case R_SH_GOTPLT10BY8:
1783 /* Relocation is to the entry for this symbol in the
1784 procedure linkage table. */
1787 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1788 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
1792 || h->plt.offset == (bfd_vma) -1
1793 || h->got.offset != (bfd_vma) -1)
1796 /* Relocation is to the entry for this symbol in the global
1797 offset table extension for the procedure linkage table. */
1798 if (sgotplt == NULL)
1800 sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
1801 BFD_ASSERT (sgotplt != NULL);
1804 relocation = (sgotplt->output_offset
1805 + ((h->plt.offset / elf_sh64_sizeof_plt (info)
1808 relocation -= GOT_BIAS;
1810 goto final_link_relocate;
1813 case R_SH_GOT_LOW16:
1814 case R_SH_GOT_MEDLOW16:
1815 case R_SH_GOT_MEDHI16:
1819 /* Relocation is to the entry for this symbol in the global
1823 sgot = bfd_get_linker_section (dynobj, ".got");
1824 BFD_ASSERT (sgot != NULL);
1831 off = h->got.offset;
1832 if (seen_stt_datalabel)
1834 struct elf_sh64_link_hash_entry *hsh;
1836 hsh = (struct elf_sh64_link_hash_entry *)h;
1837 off = hsh->datalabel_got_offset;
1839 BFD_ASSERT (off != (bfd_vma) -1);
1841 if (! elf_hash_table (info)->dynamic_sections_created
1843 && (info->symbolic || h->dynindx == -1
1844 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1845 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
1848 /* This is actually a static link, or it is a
1849 -Bsymbolic link and the symbol is defined
1850 locally, or the symbol was forced to be local
1851 because of a version file. We must initialize
1852 this entry in the global offset table. Since the
1853 offset must always be a multiple of 4, we use the
1854 least significant bit to record whether we have
1855 initialized it already.
1857 When doing a dynamic link, we create a .rela.got
1858 relocation entry to initialize the value. This
1859 is done in the finish_dynamic_symbol routine. */
1864 bfd_put_64 (output_bfd, relocation,
1865 sgot->contents + off);
1866 if (seen_stt_datalabel)
1868 struct elf_sh64_link_hash_entry *hsh;
1870 hsh = (struct elf_sh64_link_hash_entry *)h;
1871 hsh->datalabel_got_offset |= 1;
1878 relocation = sgot->output_offset + off;
1886 BFD_ASSERT (local_got_offsets != NULL
1887 && (local_got_offsets[symtab_hdr->sh_info
1891 off = local_got_offsets[symtab_hdr->sh_info
1896 BFD_ASSERT (local_got_offsets != NULL
1897 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1899 off = local_got_offsets[r_symndx];
1902 /* The offset must always be a multiple of 8. We use
1903 the least significant bit to record whether we have
1904 already generated the necessary reloc. */
1909 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
1914 Elf_Internal_Rela outrel;
1917 s = bfd_get_linker_section (dynobj, ".rela.got");
1918 BFD_ASSERT (s != NULL);
1920 outrel.r_offset = (sgot->output_section->vma
1921 + sgot->output_offset
1923 outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1924 outrel.r_addend = relocation;
1926 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
1927 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1931 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
1933 local_got_offsets[r_symndx] |= 1;
1936 relocation = sgot->output_offset + off;
1939 relocation -= GOT_BIAS;
1941 goto final_link_relocate;
1943 case R_SH_GOTOFF_LOW16:
1944 case R_SH_GOTOFF_MEDLOW16:
1945 case R_SH_GOTOFF_MEDHI16:
1946 case R_SH_GOTOFF_HI16:
1947 /* Relocation is relative to the start of the global offset
1952 sgot = bfd_get_linker_section (dynobj, ".got");
1953 BFD_ASSERT (sgot != NULL);
1956 /* Note that sgot->output_offset is not involved in this
1957 calculation. We always want the start of .got. If we
1958 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1959 permitted by the ABI, we might have to change this
1961 relocation -= sgot->output_section->vma;
1963 relocation -= GOT_BIAS;
1965 addend = rel->r_addend;
1967 goto final_link_relocate;
1969 case R_SH_GOTPC_LOW16:
1970 case R_SH_GOTPC_MEDLOW16:
1971 case R_SH_GOTPC_MEDHI16:
1972 case R_SH_GOTPC_HI16:
1973 /* Use global offset table as symbol value. */
1977 sgot = bfd_get_linker_section (dynobj, ".got");
1978 BFD_ASSERT (sgot != NULL);
1981 relocation = sgot->output_section->vma;
1983 relocation += GOT_BIAS;
1985 addend = rel->r_addend;
1987 goto final_link_relocate;
1989 case R_SH_PLT_LOW16:
1990 case R_SH_PLT_MEDLOW16:
1991 case R_SH_PLT_MEDHI16:
1993 /* Relocation is to the entry for this symbol in the
1994 procedure linkage table. */
1996 /* Resolve a PLT reloc against a local symbol directly,
1997 without using the procedure linkage table. */
1999 goto final_link_relocate;
2001 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2002 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2003 goto final_link_relocate;
2005 if (h->plt.offset == (bfd_vma) -1)
2007 /* We didn't make a PLT entry for this symbol. This
2008 happens when statically linking PIC code, or when
2009 using -Bsymbolic. */
2010 goto final_link_relocate;
2015 splt = bfd_get_linker_section (dynobj, ".plt");
2016 BFD_ASSERT (splt != NULL);
2019 relocation = (splt->output_section->vma
2020 + splt->output_offset
2024 addend = rel->r_addend;
2026 goto final_link_relocate;
2029 case R_SH_SHMEDIA_CODE:
2040 case R_SH_IMM_LOW16:
2041 case R_SH_IMM_LOW16_PCREL:
2042 case R_SH_IMM_MEDLOW16:
2043 case R_SH_IMM_MEDLOW16_PCREL:
2044 case R_SH_IMM_MEDHI16:
2045 case R_SH_IMM_MEDHI16_PCREL:
2047 case R_SH_IMM_HI16_PCREL:
2048 addend = rel->r_addend;
2051 final_link_relocate:
2052 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2053 contents, rel->r_offset,
2054 relocation, addend);
2058 bfd_set_error (bfd_error_bad_value);
2063 if (r != bfd_reloc_ok)
2068 case bfd_reloc_outofrange:
2070 case bfd_reloc_overflow:
2078 name = (bfd_elf_string_from_elf_section
2079 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2083 name = bfd_section_name (input_bfd, sec);
2085 if (! ((*info->callbacks->reloc_overflow)
2086 (info, (h ? &h->root : NULL), name, howto->name,
2087 (bfd_vma) 0, input_bfd, input_section,
2099 /* This is a version of bfd_generic_get_relocated_section_contents
2100 that uses sh_elf64_relocate_section.
2102 See sh_elf_relocate_section in elf32-sh.c for the original. */
2105 sh_elf64_get_relocated_section_contents (bfd *output_bfd,
2106 struct bfd_link_info *link_info,
2107 struct bfd_link_order *link_order,
2109 bfd_boolean relocatable,
2112 Elf_Internal_Shdr *symtab_hdr;
2113 asection *input_section = link_order->u.indirect.section;
2114 bfd *input_bfd = input_section->owner;
2115 asection **sections = NULL;
2116 Elf_Internal_Rela *internal_relocs = NULL;
2117 Elf_Internal_Sym *isymbuf = NULL;
2119 /* We only need to handle the case of relaxing, or of having a
2120 particular set of section contents, specially. */
2122 || elf_section_data (input_section)->this_hdr.contents == NULL)
2123 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2128 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2130 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
2131 input_section->size);
2133 if ((input_section->flags & SEC_RELOC) != 0
2134 && input_section->reloc_count > 0)
2136 Elf_Internal_Sym *isymp;
2137 Elf_Internal_Sym *isymend;
2140 /* Read this BFD's local symbols. */
2141 if (symtab_hdr->sh_info != 0)
2143 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2144 if (isymbuf == NULL)
2145 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2146 symtab_hdr->sh_info, 0,
2148 if (isymbuf == NULL)
2152 internal_relocs = (_bfd_elf_link_read_relocs
2153 (input_bfd, input_section, NULL,
2154 (Elf_Internal_Rela *) NULL, FALSE));
2155 if (internal_relocs == NULL)
2158 sections = (asection **) bfd_malloc (symtab_hdr->sh_info
2159 * sizeof (asection *));
2160 if (sections == NULL && symtab_hdr->sh_info > 0)
2164 isymend = isymbuf + symtab_hdr->sh_info;
2165 for (isymp = isymbuf; isymp < isymend; ++isymp, ++secpp)
2169 if (isymp->st_shndx == SHN_UNDEF)
2170 isec = bfd_und_section_ptr;
2171 else if (isymp->st_shndx == SHN_ABS)
2172 isec = bfd_abs_section_ptr;
2173 else if (isymp->st_shndx == SHN_COMMON)
2174 isec = bfd_com_section_ptr;
2176 isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
2181 if (! sh_elf64_relocate_section (output_bfd, link_info, input_bfd,
2182 input_section, data, internal_relocs,
2186 if (sections != NULL)
2188 if (internal_relocs != elf_section_data (input_section)->relocs)
2189 free (internal_relocs);
2191 && (unsigned char *) isymbuf != symtab_hdr->contents)
2198 if (sections != NULL)
2200 if (internal_relocs != NULL
2201 && internal_relocs != elf_section_data (input_section)->relocs)
2202 free (internal_relocs);
2204 && (unsigned char *) isymbuf != symtab_hdr->contents)
2209 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */
2212 sh64_elf64_fake_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2213 Elf_Internal_Shdr *elf_section_hdr,
2216 /* Code sections can only contain SH64 code, so mark them as such. */
2217 if (bfd_get_section_flags (output_bfd, asect) & SEC_CODE)
2218 elf_section_hdr->sh_flags |= SHF_SH5_ISA32;
2224 sh_elf64_set_mach_from_flags (bfd *abfd)
2226 flagword flags = elf_elfheader (abfd)->e_flags;
2228 switch (flags & EF_SH_MACH_MASK)
2231 /* Just one, but keep the switch construct to make additions easy. */
2232 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh5);
2236 bfd_set_error (bfd_error_wrong_format);
2242 /* Function to keep SH64 specific file flags.
2244 See sh64_elf_set_private_flags in elf32-sh64.c for the original. */
2247 sh_elf64_set_private_flags (bfd *abfd, flagword flags)
2249 BFD_ASSERT (! elf_flags_init (abfd)
2250 || elf_elfheader (abfd)->e_flags == flags);
2252 elf_elfheader (abfd)->e_flags = flags;
2253 elf_flags_init (abfd) = TRUE;
2254 return sh_elf64_set_mach_from_flags (abfd);
2257 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2258 code, to keep attributes the same as for SHmedia in 32-bit ELF. */
2261 sh_elf64_copy_private_data_internal (bfd *ibfd, bfd *obfd)
2263 Elf_Internal_Shdr **o_shdrp;
2267 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2268 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2271 o_shdrp = elf_elfsections (obfd);
2272 for (osec = obfd->sections; osec; osec = osec->next)
2274 int oIndex = ((struct bfd_elf_section_data *) elf_section_data (osec))->this_idx;
2275 for (isec = ibfd->sections; isec; isec = isec->next)
2277 if (strcmp (osec->name, isec->name) == 0)
2279 /* Note that we're not disallowing mixing data and code. */
2280 if ((elf_section_data (isec)->this_hdr.sh_flags
2281 & SHF_SH5_ISA32) != 0)
2282 o_shdrp[oIndex]->sh_flags |= SHF_SH5_ISA32;
2288 /* Copy object attributes. */
2289 _bfd_elf_copy_obj_attributes (ibfd, obfd);
2291 return sh_elf64_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
2295 sh_elf64_copy_private_data (bfd *ibfd, bfd *obfd)
2297 return sh_elf64_copy_private_data_internal (ibfd, obfd);
2301 sh_elf64_merge_private_data (bfd *ibfd, bfd *obfd)
2303 flagword old_flags, new_flags;
2305 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2308 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2309 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2312 if (bfd_get_arch_size (ibfd) != bfd_get_arch_size (obfd))
2316 if (bfd_get_arch_size (ibfd) == 32
2317 && bfd_get_arch_size (obfd) == 64)
2318 msg = _("%s: compiled as 32-bit object and %s is 64-bit");
2319 else if (bfd_get_arch_size (ibfd) == 64
2320 && bfd_get_arch_size (obfd) == 32)
2321 msg = _("%s: compiled as 64-bit object and %s is 32-bit");
2323 msg = _("%s: object size does not match that of target %s");
2325 (*_bfd_error_handler) (msg, bfd_get_filename (ibfd),
2326 bfd_get_filename (obfd));
2327 bfd_set_error (bfd_error_wrong_format);
2331 old_flags = elf_elfheader (obfd)->e_flags;
2332 new_flags = elf_elfheader (ibfd)->e_flags;
2333 if (! elf_flags_init (obfd))
2335 /* This happens when ld starts out with a 'blank' output file. */
2336 elf_flags_init (obfd) = TRUE;
2337 elf_elfheader (obfd)->e_flags = old_flags = new_flags;
2339 /* We don't allow linking in anything else than SH64 code, and since
2340 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2341 here as things change. */
2342 else if ((new_flags & EF_SH_MACH_MASK) != EF_SH5)
2344 (*_bfd_error_handler)
2345 ("%s: does not use the SH64 64-bit ABI as previous modules do",
2346 bfd_get_filename (ibfd));
2347 bfd_set_error (bfd_error_bad_value);
2351 sh_elf64_copy_private_data_internal (ibfd, obfd);
2353 /* I can't think of anything sane other than old_flags being EF_SH5 and
2354 that we need to preserve that. */
2355 elf_elfheader (obfd)->e_flags = old_flags;
2357 return sh_elf64_set_mach_from_flags (obfd);
2360 /* Return the section that should be marked against GC for a given
2364 sh_elf64_gc_mark_hook (asection *sec,
2365 struct bfd_link_info *info,
2366 Elf_Internal_Rela *rel,
2367 struct elf_link_hash_entry *h,
2368 Elf_Internal_Sym *sym)
2371 switch (ELF64_R_TYPE (rel->r_info))
2373 case R_SH_GNU_VTINHERIT:
2374 case R_SH_GNU_VTENTRY:
2378 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2381 /* Look through the relocs for a section during the first phase.
2382 Since we don't do .gots or .plts, we just need to consider the
2383 virtual table relocs for gc. */
2386 sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2387 asection *sec, const Elf_Internal_Rela *relocs)
2389 Elf_Internal_Shdr *symtab_hdr;
2390 struct elf_link_hash_entry **sym_hashes;
2391 const Elf_Internal_Rela *rel;
2392 const Elf_Internal_Rela *rel_end;
2394 bfd_vma *local_got_offsets;
2403 if (info->relocatable)
2406 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2407 sym_hashes = elf_sym_hashes (abfd);
2409 dynobj = elf_hash_table (info)->dynobj;
2410 local_got_offsets = elf_local_got_offsets (abfd);
2412 rel_end = relocs + sec->reloc_count;
2413 for (rel = relocs; rel < rel_end; rel++)
2415 struct elf_link_hash_entry *h;
2416 unsigned long r_symndx;
2418 r_symndx = ELF64_R_SYM (rel->r_info);
2419 if (r_symndx < symtab_hdr->sh_info)
2423 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2424 while (h->root.type == bfd_link_hash_indirect
2425 || h->root.type == bfd_link_hash_warning)
2426 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2428 /* PR15323, ref flags aren't set for references in the same
2430 h->root.non_ir_ref = 1;
2433 /* Some relocs require a global offset table. */
2436 switch (ELF64_R_TYPE (rel->r_info))
2438 case R_SH_GOTPLT_LOW16:
2439 case R_SH_GOTPLT_MEDLOW16:
2440 case R_SH_GOTPLT_MEDHI16:
2441 case R_SH_GOTPLT_HI16:
2442 case R_SH_GOTPLT10BY4:
2443 case R_SH_GOTPLT10BY8:
2444 case R_SH_GOT_LOW16:
2445 case R_SH_GOT_MEDLOW16:
2446 case R_SH_GOT_MEDHI16:
2450 case R_SH_GOTOFF_LOW16:
2451 case R_SH_GOTOFF_MEDLOW16:
2452 case R_SH_GOTOFF_MEDHI16:
2453 case R_SH_GOTOFF_HI16:
2454 case R_SH_GOTPC_LOW16:
2455 case R_SH_GOTPC_MEDLOW16:
2456 case R_SH_GOTPC_MEDHI16:
2457 case R_SH_GOTPC_HI16:
2458 elf_hash_table (info)->dynobj = dynobj = abfd;
2459 if (! _bfd_elf_create_got_section (dynobj, info))
2468 switch (ELF64_R_TYPE (rel->r_info))
2470 /* This relocation describes the C++ object vtable hierarchy.
2471 Reconstruct it for later use during GC. */
2472 case R_SH_GNU_VTINHERIT:
2473 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2477 /* This relocation describes which C++ vtable entries are actually
2478 used. Record for later use during GC. */
2479 case R_SH_GNU_VTENTRY:
2480 BFD_ASSERT (h != NULL);
2482 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2487 case R_SH_GOT_LOW16:
2488 case R_SH_GOT_MEDLOW16:
2489 case R_SH_GOT_MEDHI16:
2493 /* This symbol requires a global offset table entry. */
2497 sgot = bfd_get_linker_section (dynobj, ".got");
2498 BFD_ASSERT (sgot != NULL);
2502 && (h != NULL || info->shared))
2504 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2505 if (srelgot == NULL)
2507 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2508 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2510 srelgot = bfd_make_section_anyway_with_flags (dynobj,
2514 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2521 if (h->type == STT_DATALABEL)
2523 struct elf_sh64_link_hash_entry *hsh;
2525 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2526 hsh = (struct elf_sh64_link_hash_entry *)h;
2527 if (hsh->datalabel_got_offset != (bfd_vma) -1)
2530 hsh->datalabel_got_offset = sgot->size;
2534 if (h->got.offset != (bfd_vma) -1)
2536 /* We have already allocated space in the .got. */
2539 h->got.offset = sgot->size;
2542 /* Make sure this symbol is output as a dynamic symbol. */
2543 if (h->dynindx == -1)
2545 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2549 srelgot->size += sizeof (Elf64_External_Rela);
2553 /* This is a global offset table entry for a local
2555 if (local_got_offsets == NULL)
2558 register unsigned int i;
2560 size = symtab_hdr->sh_info * sizeof (bfd_vma);
2561 /* Reserve space for both the datalabel and
2562 codelabel local GOT offsets. */
2564 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
2565 if (local_got_offsets == NULL)
2567 elf_local_got_offsets (abfd) = local_got_offsets;
2568 for (i = 0; i < symtab_hdr->sh_info; i++)
2569 local_got_offsets[i] = (bfd_vma) -1;
2570 for (; i < 2 * symtab_hdr->sh_info; i++)
2571 local_got_offsets[i] = (bfd_vma) -1;
2573 if ((rel->r_addend & 1) != 0)
2575 if (local_got_offsets[symtab_hdr->sh_info
2576 + r_symndx] != (bfd_vma) -1)
2578 /* We have already allocated space in the .got. */
2581 local_got_offsets[symtab_hdr->sh_info
2582 + r_symndx] = sgot->size;
2586 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
2588 /* We have already allocated space in the .got. */
2591 local_got_offsets[r_symndx] = sgot->size;
2596 /* If we are generating a shared object, we need to
2597 output a R_SH_RELATIVE reloc so that the dynamic
2598 linker can adjust this GOT entry. */
2599 srelgot->size += sizeof (Elf64_External_Rela);
2607 case R_SH_GOTPLT_LOW16:
2608 case R_SH_GOTPLT_MEDLOW16:
2609 case R_SH_GOTPLT_MEDHI16:
2610 case R_SH_GOTPLT_HI16:
2611 case R_SH_GOTPLT10BY4:
2612 case R_SH_GOTPLT10BY8:
2613 /* If this is a local symbol, we resolve it directly without
2614 creating a procedure linkage table entry. */
2617 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2618 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
2622 || h->got.offset != (bfd_vma) -1)
2625 /* Make sure this symbol is output as a dynamic symbol. */
2626 if (h->dynindx == -1)
2628 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2636 case R_SH_PLT_LOW16:
2637 case R_SH_PLT_MEDLOW16:
2638 case R_SH_PLT_MEDHI16:
2640 /* This symbol requires a procedure linkage table entry. We
2641 actually build the entry in adjust_dynamic_symbol,
2642 because this might be a case of linking PIC code which is
2643 never referenced by a dynamic object, in which case we
2644 don't need to generate a procedure linkage table entry
2647 /* If this is a local symbol, we resolve it directly without
2648 creating a procedure linkage table entry. */
2652 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2653 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2665 /* If we are creating a shared library, and this is a reloc
2666 against a global symbol, or a non PC relative reloc
2667 against a local symbol, then we need to copy the reloc
2668 into the shared library. However, if we are linking with
2669 -Bsymbolic, we do not need to copy a reloc against a
2670 global symbol which is defined in an object we are
2671 including in the link (i.e., DEF_REGULAR is set). At
2672 this point we have not seen all the input files, so it is
2673 possible that DEF_REGULAR is not set now but will be set
2674 later (it is never cleared). We account for that
2675 possibility below by storing information in the
2676 pcrel_relocs_copied field of the hash table entry. */
2678 && (sec->flags & SEC_ALLOC) != 0
2679 && (ELF32_R_TYPE (rel->r_info) != R_SH_64_PCREL
2681 && (! info->symbolic
2682 || !h->def_regular))))
2684 /* When creating a shared object, we must copy these
2685 reloc types into the output file. We create a reloc
2686 section in dynobj and make room for this reloc. */
2689 sreloc = _bfd_elf_make_dynamic_reloc_section
2690 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2696 sreloc->size += sizeof (Elf64_External_Rela);
2698 /* If we are linking with -Bsymbolic, and this is a
2699 global symbol, we count the number of PC relative
2700 relocations we have entered for this symbol, so that
2701 we can discard them again if the symbol is later
2702 defined by a regular object. Note that this function
2703 is only called if we are using an elf_sh linker
2704 hash table, which means that h is really a pointer to
2705 an elf_sh_link_hash_entry. */
2706 if (h != NULL && info->symbolic
2707 && ELF64_R_TYPE (rel->r_info) == R_SH_64_PCREL)
2709 struct elf_sh64_link_hash_entry *eh;
2710 struct elf_sh64_pcrel_relocs_copied *p;
2712 eh = (struct elf_sh64_link_hash_entry *) h;
2714 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
2715 if (p->section == sreloc)
2720 p = ((struct elf_sh64_pcrel_relocs_copied *)
2721 bfd_alloc (dynobj, sizeof *p));
2724 p->next = eh->pcrel_relocs_copied;
2725 eh->pcrel_relocs_copied = p;
2726 p->section = sreloc;
2742 sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
2744 if (ELF_ST_TYPE (elf_sym->st_info) == STT_DATALABEL)
2745 return STT_DATALABEL;
2750 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2751 Either file can presumably exist without the other, but do not differ
2752 in elf-size-ness. How to share?
2754 Hook called by the linker routine which adds symbols from an object
2755 file. We must make indirect symbols for undefined symbols marked with
2756 STT_DATALABEL, so relocations passing them will pick up that attribute
2757 and neutralize STO_SH5_ISA32 found on the symbol definition.
2759 There is a problem, though: We want to fill in the hash-table entry for
2760 this symbol and signal to the caller that no further processing is
2761 needed. But we don't have the index for this hash-table entry. We
2762 rely here on that the current entry is the first hash-entry with NULL,
2763 which seems brittle. Also, iterating over the hash-table to find that
2764 entry is a linear operation on the number of symbols in this input
2765 file, and this function should take constant time, so that's not good
2766 too. Only comfort is that DataLabel references should only be found in
2767 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2768 into adding an option to elf_add_symbol_hook (preferably) for the index
2769 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2773 sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
2774 Elf_Internal_Sym *sym, const char **namep,
2775 flagword *flagsp ATTRIBUTE_UNUSED,
2776 asection **secp, bfd_vma *valp)
2778 /* We want to do this for relocatable as well as final linking. */
2779 if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL
2780 && is_elf_hash_table (info->hash))
2782 struct elf_link_hash_entry *h;
2784 /* For relocatable links, we register the DataLabel sym in its own
2785 right, and tweak the name when it's output. Otherwise, we make
2786 an indirect symbol of it. */
2788 = info->relocatable || info->emitrelocations
2789 ? BSF_GLOBAL : BSF_GLOBAL | BSF_INDIRECT;
2792 = bfd_malloc (strlen (*namep) + sizeof (DATALABEL_SUFFIX));
2793 struct elf_link_hash_entry ** sym_hash = elf_sym_hashes (abfd);
2795 BFD_ASSERT (sym_hash != NULL);
2797 /* Allocation may fail. */
2798 if (dl_name == NULL)
2801 strcpy (dl_name, *namep);
2802 strcat (dl_name, DATALABEL_SUFFIX);
2804 h = (struct elf_link_hash_entry *)
2805 bfd_link_hash_lookup (info->hash, dl_name, FALSE, FALSE, FALSE);
2809 /* No previous datalabel symbol. Make one. */
2810 struct bfd_link_hash_entry *bh = NULL;
2811 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2813 if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name,
2814 flags, *secp, *valp,
2822 h = (struct elf_link_hash_entry *) bh;
2824 h->type = STT_DATALABEL;
2827 /* If a new symbol was created, it holds the allocated name.
2828 Otherwise, we don't need it anymore and should deallocate it. */
2831 if (h->type != STT_DATALABEL
2832 || ((info->relocatable || info->emitrelocations)
2833 && h->root.type != bfd_link_hash_undefined)
2834 || (! info->relocatable && !info->emitrelocations
2835 && h->root.type != bfd_link_hash_indirect))
2837 /* Make sure we don't get confused on invalid input. */
2838 (*_bfd_error_handler)
2839 (_("%s: encountered datalabel symbol in input"),
2840 bfd_get_filename (abfd));
2841 bfd_set_error (bfd_error_bad_value);
2845 /* Now find the hash-table slot for this entry and fill it in. */
2846 while (*sym_hash != NULL)
2850 /* Signal to caller to skip this symbol - we've handled it. */
2857 /* This hook function is called before the linker writes out a global
2858 symbol. For relocatable links, DataLabel symbols will be present in
2859 linker output. We cut off the special suffix on those symbols, so the
2860 right name appears in the output.
2862 When linking and emitting relocations, there can appear global symbols
2863 that are not referenced by relocs, but rather only implicitly through
2864 DataLabel references, a relation that is not visible to the linker.
2865 Since no stripping of global symbols in done when doing such linking,
2866 we don't need to look up and make sure to emit the main symbol for each
2867 DataLabel symbol. */
2870 sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info,
2872 Elf_Internal_Sym *sym,
2873 asection *input_sec ATTRIBUTE_UNUSED,
2874 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2876 char *name = (char *) cname;
2878 if (info->relocatable || info->emitrelocations)
2880 if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL)
2881 name[strlen (name) - strlen (DATALABEL_SUFFIX)] = 0;
2887 /* Set bit 0 on the entry address; it always points to SHmedia code. This
2888 is mostly for symmetry with the 32-bit format, where code can be
2889 SHcompact and we need to make a distinction to make sure execution
2890 starts in the right ISA mode. It is also convenient for a loader,
2891 which would otherwise have to set this bit when loading a TR register
2892 before jumping to the program entry. */
2895 sh64_elf64_final_write_processing (bfd *abfd,
2896 bfd_boolean linker ATTRIBUTE_UNUSED)
2898 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
2899 numerically, but we currently lack the infrastructure to recognize
2900 that: The entry symbol, and info whether it is numeric or a symbol
2901 name is kept private in the linker. */
2902 if (elf_elfheader (abfd)->e_type == ET_EXEC)
2903 elf_elfheader (abfd)->e_entry |= 1;
2906 /* First entry in an absolute procedure linkage table look like this. */
2908 static const bfd_byte elf_sh64_plt0_entry_be[PLT_ENTRY_SIZE] =
2910 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
2911 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
2912 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
2913 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2914 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
2915 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2916 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
2917 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2918 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2919 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2920 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2921 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2922 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2923 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2924 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2925 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2928 static const bfd_byte elf_sh64_plt0_entry_le[PLT_ENTRY_SIZE] =
2930 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
2931 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
2932 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
2933 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2934 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
2935 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2936 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
2937 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2938 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2939 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2940 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2941 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2942 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2943 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2944 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2945 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2948 /* Sebsequent entries in an absolute procedure linkage table look like
2951 static const bfd_byte elf_sh64_plt_entry_be[PLT_ENTRY_SIZE] =
2953 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
2954 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
2955 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
2956 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
2957 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
2958 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2959 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2960 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2961 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */
2962 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
2963 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
2964 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
2965 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
2966 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2967 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2968 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2971 static const bfd_byte elf_sh64_plt_entry_le[PLT_ENTRY_SIZE] =
2973 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
2974 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2975 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2976 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2977 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
2978 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2979 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2980 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2981 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */
2982 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
2983 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
2984 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
2985 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
2986 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2987 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2988 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2991 /* Entries in a PIC procedure linkage table look like this. */
2993 static const bfd_byte elf_sh64_pic_plt_entry_be[PLT_ENTRY_SIZE] =
2995 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
2996 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
2997 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
2998 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2999 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3000 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3001 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3002 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3003 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3004 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */
3005 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3006 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3007 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3008 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3009 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3010 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3013 static const bfd_byte elf_sh64_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3015 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3016 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3017 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3018 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3019 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3020 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3021 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3022 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3023 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3024 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */
3025 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3026 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3027 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3028 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3029 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3030 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3033 static const bfd_byte *elf_sh64_plt0_entry;
3034 static const bfd_byte *elf_sh64_plt_entry;
3035 static const bfd_byte *elf_sh64_pic_plt_entry;
3037 /* Create an entry in an sh ELF linker hash table. */
3039 static struct bfd_hash_entry *
3040 sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry,
3041 struct bfd_hash_table *table,
3044 struct elf_sh64_link_hash_entry *ret =
3045 (struct elf_sh64_link_hash_entry *) entry;
3047 /* Allocate the structure if it has not already been allocated by a
3049 if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3050 ret = ((struct elf_sh64_link_hash_entry *)
3051 bfd_hash_allocate (table,
3052 sizeof (struct elf_sh64_link_hash_entry)));
3053 if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3054 return (struct bfd_hash_entry *) ret;
3056 /* Call the allocation method of the superclass. */
3057 ret = ((struct elf_sh64_link_hash_entry *)
3058 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3060 if (ret != (struct elf_sh64_link_hash_entry *) NULL)
3062 ret->pcrel_relocs_copied = NULL;
3063 ret->datalabel_got_offset = (bfd_vma) -1;
3066 return (struct bfd_hash_entry *) ret;
3069 /* Create an sh64 ELF linker hash table. */
3071 static struct bfd_link_hash_table *
3072 sh64_elf64_link_hash_table_create (bfd *abfd)
3074 struct elf_link_hash_table *ret;
3076 ret = (struct elf_link_hash_table *) bfd_zmalloc (sizeof (* ret));
3077 if (ret == (struct elf_link_hash_table *) NULL)
3080 if (!_bfd_elf_link_hash_table_init (ret, abfd,
3081 sh64_elf64_link_hash_newfunc,
3082 sizeof (struct elf_sh64_link_hash_entry),
3093 movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr)
3095 bfd_put_32 (output_bfd,
3096 bfd_get_32 (output_bfd, addr)
3097 | ((value >> 6) & 0x3fffc00),
3099 bfd_put_32 (output_bfd,
3100 bfd_get_32 (output_bfd, addr + 4)
3101 | ((value << 10) & 0x3fffc00),
3106 movi_3shori_putval (bfd *output_bfd, bfd_vma value, bfd_byte *addr)
3108 bfd_put_32 (output_bfd,
3109 bfd_get_32 (output_bfd, addr)
3110 | ((value >> 38) & 0x3fffc00),
3112 bfd_put_32 (output_bfd,
3113 bfd_get_32 (output_bfd, addr + 4)
3114 | ((value >> 22) & 0x3fffc00),
3116 bfd_put_32 (output_bfd,
3117 bfd_get_32 (output_bfd, addr + 8)
3118 | ((value >> 6) & 0x3fffc00),
3120 bfd_put_32 (output_bfd,
3121 bfd_get_32 (output_bfd, addr + 12)
3122 | ((value << 10) & 0x3fffc00),
3126 /* Create dynamic sections when linking against a dynamic object. */
3129 sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3131 flagword flags, pltflags;
3132 register asection *s;
3133 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3136 switch (bed->s->arch_size)
3147 bfd_set_error (bfd_error_bad_value);
3151 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3152 .rel[a].bss sections. */
3154 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3155 | SEC_LINKER_CREATED);
3158 pltflags |= SEC_CODE;
3159 if (bed->plt_not_loaded)
3160 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3161 if (bed->plt_readonly)
3162 pltflags |= SEC_READONLY;
3164 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
3166 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3169 if (bed->want_plt_sym)
3171 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3173 struct elf_link_hash_entry *h;
3174 struct bfd_link_hash_entry *bh = NULL;
3176 if (! (_bfd_generic_link_add_one_symbol
3177 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3178 (bfd_vma) 0, (const char *) NULL, FALSE, bed->collect, &bh)))
3181 h = (struct elf_link_hash_entry *) bh;
3183 h->type = STT_OBJECT;
3184 elf_hash_table (info)->hplt = h;
3187 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3191 s = bfd_make_section_anyway_with_flags (abfd,
3192 bed->default_use_rela_p
3193 ? ".rela.plt" : ".rel.plt",
3194 flags | SEC_READONLY);
3196 || ! bfd_set_section_alignment (abfd, s, ptralign))
3199 if (! _bfd_elf_create_got_section (abfd, info))
3202 if (bed->want_dynbss)
3204 /* The .dynbss section is a place to put symbols which are defined
3205 by dynamic objects, are referenced by regular objects, and are
3206 not functions. We must allocate space for them in the process
3207 image and use a R_*_COPY reloc to tell the dynamic linker to
3208 initialize them at run time. The linker script puts the .dynbss
3209 section into the .bss section of the final image. */
3210 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
3211 SEC_ALLOC | SEC_LINKER_CREATED);
3215 /* The .rel[a].bss section holds copy relocs. This section is not
3216 normally needed. We need to create it here, though, so that the
3217 linker will map it to an output section. We can't just create it
3218 only if we need it, because we will not know whether we need it
3219 until we have seen all the input files, and the first time the
3220 main linker code calls BFD after examining all the input files
3221 (size_dynamic_sections) the input sections have already been
3222 mapped to the output sections. If the section turns out not to
3223 be needed, we can discard it later. We will never need this
3224 section when generating a shared object, since they do not use
3228 s = bfd_make_section_anyway_with_flags (abfd,
3229 (bed->default_use_rela_p
3230 ? ".rela.bss" : ".rel.bss"),
3231 flags | SEC_READONLY);
3233 || ! bfd_set_section_alignment (abfd, s, ptralign))
3241 /* Adjust a symbol defined by a dynamic object and referenced by a
3242 regular object. The current definition is in some section of the
3243 dynamic object, but we're not including those sections. We have to
3244 change the definition to something the rest of the link can
3248 sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
3249 struct elf_link_hash_entry *h)
3254 dynobj = elf_hash_table (info)->dynobj;
3256 /* Make sure we know what is going on here. */
3257 BFD_ASSERT (dynobj != NULL
3259 || h->u.weakdef != NULL
3262 && !h->def_regular)));
3264 /* If this is a function, put it in the procedure linkage table. We
3265 will fill in the contents of the procedure linkage table later,
3266 when we know the address of the .got section. */
3267 if (h->type == STT_FUNC
3274 /* This case can occur if we saw a PLT reloc in an input
3275 file, but the symbol was never referred to by a dynamic
3276 object. In such a case, we don't actually need to build
3277 a procedure linkage table, and we can just do a REL64
3279 BFD_ASSERT (h->needs_plt);
3283 /* Make sure this symbol is output as a dynamic symbol. */
3284 if (h->dynindx == -1)
3286 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3290 s = bfd_get_linker_section (dynobj, ".plt");
3291 BFD_ASSERT (s != NULL);
3293 /* If this is the first .plt entry, make room for the special
3296 s->size += PLT_ENTRY_SIZE;
3298 /* If this symbol is not defined in a regular file, and we are
3299 not generating a shared library, then set the symbol to this
3300 location in the .plt. This is required to make function
3301 pointers compare as equal between the normal executable and
3302 the shared library. */
3306 h->root.u.def.section = s;
3307 h->root.u.def.value = s->size;
3310 h->plt.offset = s->size;
3312 /* Make room for this entry. */
3313 s->size += elf_sh64_sizeof_plt (info);
3315 /* We also need to make an entry in the .got.plt section, which
3316 will be placed in the .got section by the linker script. */
3318 s = bfd_get_linker_section (dynobj, ".got.plt");
3319 BFD_ASSERT (s != NULL);
3322 /* We also need to make an entry in the .rela.plt section. */
3324 s = bfd_get_linker_section (dynobj, ".rela.plt");
3325 BFD_ASSERT (s != NULL);
3326 s->size += sizeof (Elf64_External_Rela);
3331 /* If this is a weak symbol, and there is a real definition, the
3332 processor independent code will have arranged for us to see the
3333 real definition first, and we can just use the same value. */
3334 if (h->u.weakdef != NULL)
3336 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3337 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3338 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3339 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3343 /* This is a reference to a symbol defined by a dynamic object which
3344 is not a function. */
3346 /* If we are creating a shared library, we must presume that the
3347 only references to the symbol are via the global offset table.
3348 For such cases we need not do anything here; the relocations will
3349 be handled correctly by relocate_section. */
3353 /* If there are no references to this symbol that do not use the
3354 GOT, we don't need to generate a copy reloc. */
3355 if (!h->non_got_ref)
3358 /* We must allocate the symbol in our .dynbss section, which will
3359 become part of the .bss section of the executable. There will be
3360 an entry for this symbol in the .dynsym section. The dynamic
3361 object will contain position independent code, so all references
3362 from the dynamic object to this symbol will go through the global
3363 offset table. The dynamic linker will use the .dynsym entry to
3364 determine the address it must put in the global offset table, so
3365 both the dynamic object and the regular object will refer to the
3366 same memory location for the variable. */
3368 s = bfd_get_linker_section (dynobj, ".dynbss");
3369 BFD_ASSERT (s != NULL);
3371 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3372 copy the initial value out of the dynamic object and into the
3373 runtime process image. We need to remember the offset into the
3374 .rela.bss section we are going to use. */
3375 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3379 srel = bfd_get_linker_section (dynobj, ".rela.bss");
3380 BFD_ASSERT (srel != NULL);
3381 srel->size += sizeof (Elf64_External_Rela);
3385 return _bfd_elf_adjust_dynamic_copy (h, s);
3388 /* This function is called via sh_elf_link_hash_traverse if we are
3389 creating a shared object with -Bsymbolic. It discards the space
3390 allocated to copy PC relative relocs against symbols which are
3391 defined in regular objects. We allocated space for them in the
3392 check_relocs routine, but we won't fill them in in the
3393 relocate_section routine. */
3396 sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h,
3397 void *ignore ATTRIBUTE_UNUSED)
3399 struct elf_sh64_pcrel_relocs_copied *s;
3401 /* We only discard relocs for symbols defined in a regular object. */
3402 if (!h->root.def_regular)
3405 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3406 s->section->size -= s->count * sizeof (Elf64_External_Rela);
3411 /* Set the sizes of the dynamic sections. */
3414 sh64_elf64_size_dynamic_sections (bfd *output_bfd,
3415 struct bfd_link_info *info)
3421 bfd_boolean reltext;
3423 dynobj = elf_hash_table (info)->dynobj;
3424 BFD_ASSERT (dynobj != NULL);
3426 if (elf_hash_table (info)->dynamic_sections_created)
3428 /* Set the contents of the .interp section to the interpreter. */
3429 if (info->executable)
3431 s = bfd_get_linker_section (dynobj, ".interp");
3432 BFD_ASSERT (s != NULL);
3433 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3434 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3439 /* We may have created entries in the .rela.got section.
3440 However, if we are not creating the dynamic sections, we will
3441 not actually use these entries. Reset the size of .rela.got,
3442 which will cause it to get stripped from the output file
3444 s = bfd_get_linker_section (dynobj, ".rela.got");
3449 /* If this is a -Bsymbolic shared link, then we need to discard all
3450 PC relative relocs against symbols defined in a regular object.
3451 We allocated space for them in the check_relocs routine, but we
3452 will not fill them in in the relocate_section routine. */
3453 if (info->shared && info->symbolic)
3454 sh64_elf64_link_hash_traverse (elf_hash_table (info),
3455 sh64_elf64_discard_copies, NULL);
3457 /* The check_relocs and adjust_dynamic_symbol entry points have
3458 determined the sizes of the various dynamic sections. Allocate
3463 for (s = dynobj->sections; s != NULL; s = s->next)
3467 if ((s->flags & SEC_LINKER_CREATED) == 0)
3470 /* It's OK to base decisions on the section name, because none
3471 of the dynobj section names depend upon the input files. */
3472 name = bfd_get_section_name (dynobj, s);
3474 if (strcmp (name, ".plt") == 0)
3476 /* Remember whether there is a PLT. */
3479 else if (CONST_STRNEQ (name, ".rela"))
3485 /* Remember whether there are any reloc sections other
3487 if (strcmp (name, ".rela.plt") != 0)
3489 const char *outname;
3493 /* If this relocation section applies to a read only
3494 section, then we probably need a DT_TEXTREL
3495 entry. The entries in the .rela.plt section
3496 really apply to the .got section, which we
3497 created ourselves and so know is not readonly. */
3498 outname = bfd_get_section_name (output_bfd,
3500 target = bfd_get_section_by_name (output_bfd, outname + 5);
3502 && (target->flags & SEC_READONLY) != 0
3503 && (target->flags & SEC_ALLOC) != 0)
3507 /* We use the reloc_count field as a counter if we need
3508 to copy relocs into the output file. */
3512 else if (! CONST_STRNEQ (name, ".got")
3513 && strcmp (name, ".dynbss") != 0)
3515 /* It's not one of our sections, so don't allocate space. */
3521 /* If we don't need this section, strip it from the
3522 output file. This is mostly to handle .rela.bss and
3523 .rela.plt. We must create both sections in
3524 create_dynamic_sections, because they must be created
3525 before the linker maps input sections to output
3526 sections. The linker does that before
3527 adjust_dynamic_symbol is called, and it is that
3528 function which decides whether anything needs to go
3529 into these sections. */
3530 s->flags |= SEC_EXCLUDE;
3534 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3537 /* Allocate memory for the section contents. */
3538 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3539 if (s->contents == NULL)
3543 if (elf_hash_table (info)->dynamic_sections_created)
3545 /* Add some entries to the .dynamic section. We fill in the
3546 values later, in sh64_elf64_finish_dynamic_sections, but we
3547 must add the entries now so that we get the correct size for
3548 the .dynamic section. The DT_DEBUG entry is filled in by the
3549 dynamic linker and used by the debugger. */
3550 if (info->executable)
3552 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
3558 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
3559 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3560 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
3561 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
3567 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
3568 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
3569 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
3570 sizeof (Elf64_External_Rela)))
3576 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
3584 /* Finish up dynamic symbol handling. We set the contents of various
3585 dynamic sections here. */
3588 sh64_elf64_finish_dynamic_symbol (bfd *output_bfd,
3589 struct bfd_link_info *info,
3590 struct elf_link_hash_entry *h,
3591 Elf_Internal_Sym *sym)
3595 dynobj = elf_hash_table (info)->dynobj;
3597 if (h->plt.offset != (bfd_vma) -1)
3605 Elf_Internal_Rela rel;
3608 /* This symbol has an entry in the procedure linkage table. Set
3611 BFD_ASSERT (h->dynindx != -1);
3613 splt = bfd_get_linker_section (dynobj, ".plt");
3614 sgot = bfd_get_linker_section (dynobj, ".got.plt");
3615 srel = bfd_get_linker_section (dynobj, ".rela.plt");
3616 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
3618 /* Get the index in the procedure linkage table which
3619 corresponds to this symbol. This is the index of this symbol
3620 in all the symbols for which we are making plt entries. The
3621 first entry in the procedure linkage table is reserved. */
3622 plt_index = h->plt.offset / elf_sh64_sizeof_plt (info) - 1;
3624 /* Get the offset into the .got table of the entry that
3625 corresponds to this function. Each .got entry is 8 bytes.
3626 The first three are reserved. */
3627 got_offset = (plt_index + 3) * 8;
3630 got_offset -= GOT_BIAS;
3632 /* Fill in the entry in the procedure linkage table. */
3635 if (elf_sh64_plt_entry == NULL)
3637 elf_sh64_plt_entry = (bfd_big_endian (output_bfd) ?
3638 elf_sh64_plt_entry_be : elf_sh64_plt_entry_le);
3640 memcpy (splt->contents + h->plt.offset, elf_sh64_plt_entry,
3641 elf_sh64_sizeof_plt (info));
3642 movi_3shori_putval (output_bfd,
3643 (sgot->output_section->vma
3644 + sgot->output_offset
3646 (splt->contents + h->plt.offset
3647 + elf_sh64_plt_symbol_offset (info)));
3649 /* Set bottom bit because its for a branch to SHmedia */
3650 movi_shori_putval (output_bfd,
3652 + elf_sh64_plt_plt0_offset (info) + 8)
3654 (splt->contents + h->plt.offset
3655 + elf_sh64_plt_plt0_offset (info)));
3659 if (elf_sh64_pic_plt_entry == NULL)
3661 elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3662 elf_sh64_pic_plt_entry_be :
3663 elf_sh64_pic_plt_entry_le);
3665 memcpy (splt->contents + h->plt.offset, elf_sh64_pic_plt_entry,
3666 elf_sh64_sizeof_plt (info));
3667 movi_shori_putval (output_bfd, got_offset,
3668 (splt->contents + h->plt.offset
3669 + elf_sh64_plt_symbol_offset (info)));
3673 got_offset += GOT_BIAS;
3675 movi_shori_putval (output_bfd,
3676 plt_index * sizeof (Elf64_External_Rela),
3677 (splt->contents + h->plt.offset
3678 + elf_sh64_plt_reloc_offset (info)));
3680 /* Fill in the entry in the global offset table. */
3681 bfd_put_64 (output_bfd,
3682 (splt->output_section->vma
3683 + splt->output_offset
3685 + elf_sh64_plt_temp_offset (info)),
3686 sgot->contents + got_offset);
3688 /* Fill in the entry in the .rela.plt section. */
3689 rel.r_offset = (sgot->output_section->vma
3690 + sgot->output_offset
3692 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_JMP_SLOT64);
3694 rel.r_addend = GOT_BIAS;
3695 loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
3696 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3698 if (!h->def_regular)
3700 /* Mark the symbol as undefined, rather than as defined in
3701 the .plt section. Leave the value alone. */
3702 sym->st_shndx = SHN_UNDEF;
3706 if (h->got.offset != (bfd_vma) -1)
3710 Elf_Internal_Rela rel;
3713 /* This symbol has an entry in the global offset table. Set it
3716 sgot = bfd_get_linker_section (dynobj, ".got");
3717 srel = bfd_get_linker_section (dynobj, ".rela.got");
3718 BFD_ASSERT (sgot != NULL && srel != NULL);
3720 rel.r_offset = (sgot->output_section->vma
3721 + sgot->output_offset
3722 + (h->got.offset &~ 1));
3724 /* If this is a -Bsymbolic link, and the symbol is defined
3725 locally, we just want to emit a RELATIVE reloc. Likewise if
3726 the symbol was forced to be local because of a version file.
3727 The entry in the global offset table will already have been
3728 initialized in the relocate_section function. */
3730 && (info->symbolic || h->dynindx == -1)
3733 rel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
3734 rel.r_addend = (h->root.u.def.value
3735 + h->root.u.def.section->output_section->vma
3736 + h->root.u.def.section->output_offset);
3740 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3741 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_GLOB_DAT64);
3745 loc = srel->contents;
3746 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
3747 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3753 Elf_Internal_Rela rel;
3756 /* This symbol needs a copy reloc. Set it up. */
3758 BFD_ASSERT (h->dynindx != -1
3759 && (h->root.type == bfd_link_hash_defined
3760 || h->root.type == bfd_link_hash_defweak));
3762 s = bfd_get_linker_section (dynobj, ".rela.bss");
3763 BFD_ASSERT (s != NULL);
3765 rel.r_offset = (h->root.u.def.value
3766 + h->root.u.def.section->output_section->vma
3767 + h->root.u.def.section->output_offset);
3768 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_COPY64);
3771 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
3772 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3775 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3776 if (h == elf_hash_table (info)->hdynamic
3777 || h == elf_hash_table (info)->hgot)
3778 sym->st_shndx = SHN_ABS;
3783 /* Finish up the dynamic sections. */
3786 sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
3787 struct bfd_link_info *info)
3793 dynobj = elf_hash_table (info)->dynobj;
3795 sgot = bfd_get_linker_section (dynobj, ".got.plt");
3796 BFD_ASSERT (sgot != NULL);
3797 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3799 if (elf_hash_table (info)->dynamic_sections_created)
3802 Elf64_External_Dyn *dyncon, *dynconend;
3804 BFD_ASSERT (sdyn != NULL);
3806 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3807 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3808 for (; dyncon < dynconend; dyncon++)
3810 Elf_Internal_Dyn dyn;
3813 struct elf_link_hash_entry *h;
3815 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3823 name = info->init_function;
3827 name = info->fini_function;
3829 if (dyn.d_un.d_val != 0)
3831 h = elf_link_hash_lookup (elf_hash_table (info), name,
3832 FALSE, FALSE, TRUE);
3833 if (h != NULL && (h->other & STO_SH5_ISA32))
3835 dyn.d_un.d_val |= 1;
3836 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3848 s = bfd_get_section_by_name (output_bfd, name);
3849 BFD_ASSERT (s != NULL);
3850 dyn.d_un.d_ptr = s->vma;
3851 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3855 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3856 BFD_ASSERT (s != NULL);
3857 dyn.d_un.d_val = s->size;
3858 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3862 /* My reading of the SVR4 ABI indicates that the
3863 procedure linkage table relocs (DT_JMPREL) should be
3864 included in the overall relocs (DT_RELA). This is
3865 what Solaris does. However, UnixWare can not handle
3866 that case. Therefore, we override the DT_RELASZ entry
3867 here to make it not include the JMPREL relocs. Since
3868 the linker script arranges for .rela.plt to follow all
3869 other relocation sections, we don't have to worry
3870 about changing the DT_RELA entry. */
3871 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3873 dyn.d_un.d_val -= s->size;
3874 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3879 /* Fill in the first entry in the procedure linkage table. */
3880 splt = bfd_get_linker_section (dynobj, ".plt");
3881 if (splt && splt->size > 0)
3885 if (elf_sh64_pic_plt_entry == NULL)
3887 elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3888 elf_sh64_pic_plt_entry_be :
3889 elf_sh64_pic_plt_entry_le);
3891 memcpy (splt->contents, elf_sh64_pic_plt_entry,
3892 elf_sh64_sizeof_plt (info));
3896 if (elf_sh64_plt0_entry == NULL)
3898 elf_sh64_plt0_entry = (bfd_big_endian (output_bfd) ?
3899 elf_sh64_plt0_entry_be :
3900 elf_sh64_plt0_entry_le);
3902 memcpy (splt->contents, elf_sh64_plt0_entry, PLT_ENTRY_SIZE);
3903 movi_3shori_putval (output_bfd,
3904 sgot->output_section->vma
3905 + sgot->output_offset,
3907 + elf_sh64_plt0_gotplt_offset (info));
3910 /* UnixWare sets the entsize of .plt to 8, although that doesn't
3911 really seem like the right value. */
3912 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 8;
3916 /* Fill in the first three entries in the global offset table. */
3920 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
3922 bfd_put_64 (output_bfd,
3923 sdyn->output_section->vma + sdyn->output_offset,
3925 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3926 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 16);
3929 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8;
3934 /* Merge non visibility st_other attribute when the symbol comes from
3935 a dynamic object. */
3937 sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h,
3938 const Elf_Internal_Sym *isym,
3939 bfd_boolean definition,
3940 bfd_boolean dynamic ATTRIBUTE_UNUSED)
3942 if ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) != 0)
3944 unsigned char other;
3946 /* Take the balance of OTHER from the definition. */
3947 other = (definition ? isym->st_other : h->other);
3948 other &= ~ ELF_ST_VISIBILITY (-1);
3949 h->other = other | ELF_ST_VISIBILITY (h->other);
3955 static const struct bfd_elf_special_section sh64_elf64_special_sections[]=
3957 { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS, 0 },
3958 { NULL, 0, 0, 0, 0 }
3961 #define TARGET_BIG_SYM bfd_elf64_sh64_vec
3962 #define TARGET_BIG_NAME "elf64-sh64"
3963 #define TARGET_LITTLE_SYM bfd_elf64_sh64l_vec
3964 #define TARGET_LITTLE_NAME "elf64-sh64l"
3965 #define ELF_ARCH bfd_arch_sh
3966 #define ELF_MACHINE_CODE EM_SH
3967 #define ELF_MAXPAGESIZE 128
3969 #define elf_symbol_leading_char '_'
3971 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
3972 #define bfd_elf64_bfd_reloc_name_lookup \
3973 sh_elf64_reloc_name_lookup
3974 #define elf_info_to_howto sh_elf64_info_to_howto
3976 /* Note: there's no relaxation at present. */
3978 #define elf_backend_relocate_section sh_elf64_relocate_section
3979 #define bfd_elf64_bfd_get_relocated_section_contents \
3980 sh_elf64_get_relocated_section_contents
3981 #define elf_backend_object_p sh_elf64_set_mach_from_flags
3982 #define bfd_elf64_bfd_set_private_flags \
3983 sh_elf64_set_private_flags
3984 #define bfd_elf64_bfd_copy_private_bfd_data \
3985 sh_elf64_copy_private_data
3986 #define bfd_elf64_bfd_merge_private_bfd_data \
3987 sh_elf64_merge_private_data
3988 #define elf_backend_fake_sections sh64_elf64_fake_sections
3990 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
3991 #define elf_backend_check_relocs sh_elf64_check_relocs
3993 #define elf_backend_can_gc_sections 1
3995 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
3997 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
3999 #define elf_backend_link_output_symbol_hook \
4000 sh64_elf64_link_output_symbol_hook
4002 #define elf_backend_merge_symbol_attribute \
4003 sh64_elf64_merge_symbol_attribute
4005 #define elf_backend_final_write_processing \
4006 sh64_elf64_final_write_processing
4008 #define elf_backend_create_dynamic_sections \
4009 sh64_elf64_create_dynamic_sections
4010 #define bfd_elf64_bfd_link_hash_table_create \
4011 sh64_elf64_link_hash_table_create
4012 #define elf_backend_adjust_dynamic_symbol \
4013 sh64_elf64_adjust_dynamic_symbol
4014 #define elf_backend_size_dynamic_sections \
4015 sh64_elf64_size_dynamic_sections
4016 #define elf_backend_omit_section_dynsym \
4017 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4018 #define elf_backend_finish_dynamic_symbol \
4019 sh64_elf64_finish_dynamic_symbol
4020 #define elf_backend_finish_dynamic_sections \
4021 sh64_elf64_finish_dynamic_sections
4022 #define elf_backend_special_sections sh64_elf64_special_sections
4024 #define elf_backend_want_got_plt 1
4025 #define elf_backend_plt_readonly 1
4026 #define elf_backend_want_plt_sym 0
4027 #define elf_backend_got_header_size 24
4029 #include "elf64-target.h"
4031 /* NetBSD support. */
4032 #undef TARGET_BIG_SYM
4033 #define TARGET_BIG_SYM bfd_elf64_sh64nbsd_vec
4034 #undef TARGET_BIG_NAME
4035 #define TARGET_BIG_NAME "elf64-sh64-nbsd"
4036 #undef TARGET_LITTLE_SYM
4037 #define TARGET_LITTLE_SYM bfd_elf64_sh64lnbsd_vec
4038 #undef TARGET_LITTLE_NAME
4039 #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd"
4040 #undef ELF_MAXPAGESIZE
4041 #define ELF_MAXPAGESIZE 0x10000
4042 #undef elf_symbol_leading_char
4043 #define elf_symbol_leading_char 0
4045 #define elf64_bed elf64_sh64_nbsd_bed
4047 #include "elf64-target.h"
4049 /* Linux support. */
4050 #undef TARGET_BIG_SYM
4051 #define TARGET_BIG_SYM bfd_elf64_sh64blin_vec
4052 #undef TARGET_BIG_NAME
4053 #define TARGET_BIG_NAME "elf64-sh64big-linux"
4054 #undef TARGET_LITTLE_SYM
4055 #define TARGET_LITTLE_SYM bfd_elf64_sh64lin_vec
4056 #undef TARGET_LITTLE_NAME
4057 #define TARGET_LITTLE_NAME "elf64-sh64-linux"
4059 #define elf64_bed elf64_sh64_linux_bed
4061 #include "elf64-target.h"