1 /* SuperH SH64-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 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 2 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, MA 02110-1301, USA. */
30 /* Add a suffix for datalabel indirection symbols. It must not match any
31 other symbols; user symbols with or without version or other
32 decoration. It must only be used internally and not emitted by any
34 #define DATALABEL_SUFFIX " DL"
36 #define GOT_BIAS (-((long)-32768))
38 #define PLT_ENTRY_SIZE 64
40 /* Return size of a PLT entry. */
41 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
43 /* Return offset of the PLT0 address in an absolute PLT entry. */
44 #define elf_sh64_plt_plt0_offset(info) 32
46 /* Return offset of the linker in PLT0 entry. */
47 #define elf_sh64_plt0_gotplt_offset(info) 0
49 /* Return offset of the trampoline in PLT entry */
50 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
52 /* Return offset of the symbol in PLT entry. */
53 #define elf_sh64_plt_symbol_offset(info) 0
55 /* Return offset of the relocation in PLT entry. */
56 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
58 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
60 /* The sh linker needs to keep track of the number of relocs that it
61 decides to copy in check_relocs for each symbol. This is so that
62 it can discard PC relative relocs if it doesn't need them when
63 linking with -Bsymbolic. We store the information in a field
64 extending the regular ELF linker hash table. */
66 /* This structure keeps track of the number of PC relative relocs we
67 have copied for a given symbol. */
69 struct elf_sh64_pcrel_relocs_copied
72 struct elf_sh64_pcrel_relocs_copied *next;
73 /* A section in dynobj. */
75 /* Number of relocs copied in this section. */
79 /* sh ELF linker hash entry. */
81 struct elf_sh64_link_hash_entry
83 struct elf_link_hash_entry root;
85 bfd_vma datalabel_got_offset;
87 /* Number of PC relative relocs copied for this symbol. */
88 struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied;
91 /* sh ELF linker hash table. */
93 struct elf_sh64_link_hash_table
95 struct elf_link_hash_table root;
98 /* Traverse an sh ELF linker hash table. */
100 #define sh64_elf64_link_hash_traverse(table, func, info) \
101 (elf_link_hash_traverse \
103 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
106 /* Get the sh ELF linker hash table from a link_info structure. */
108 #define sh64_elf64_hash_table(p) \
109 ((struct elf_sh64_link_hash_table *) ((p)->hash))
111 static bfd_reloc_status_type sh_elf64_ignore_reloc
112 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
113 static bfd_reloc_status_type sh_elf64_reloc
114 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
116 static reloc_howto_type sh_elf64_howto_table[] = {
118 HOWTO (R_SH_NONE, /* type */
120 0, /* size (0 = byte, 1 = short, 2 = long) */
122 FALSE, /* pc_relative */
124 complain_overflow_dont, /* complain_on_overflow */
125 sh_elf64_ignore_reloc, /* special_function */
126 "R_SH_NONE", /* name */
127 FALSE, /* partial_inplace */
130 FALSE), /* pcrel_offset */
132 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
133 src_mask to a non-zero value is similar to the COFF toolchain. */
134 HOWTO (R_SH_DIR32, /* type */
136 2, /* size (0 = byte, 1 = short, 2 = long) */
138 FALSE, /* pc_relative */
140 complain_overflow_bitfield, /* complain_on_overflow */
141 sh_elf64_reloc, /* special_function */
142 "R_SH_DIR32", /* name */
143 TRUE, /* partial_inplace */
144 0xffffffff, /* src_mask */
145 0xffffffff, /* dst_mask */
146 FALSE), /* pcrel_offset */
148 /* 32 bit PC relative relocation. */
149 HOWTO (R_SH_REL32, /* type */
151 2, /* size (0 = byte, 1 = short, 2 = long) */
153 TRUE, /* pc_relative */
155 complain_overflow_signed, /* complain_on_overflow */
156 sh_elf64_ignore_reloc, /* special_function */
157 "R_SH_REL32", /* name */
158 FALSE, /* partial_inplace */
160 0xffffffff, /* dst_mask */
161 TRUE), /* pcrel_offset */
163 /* For 32-bit sh, this is R_SH_DIR8WPN. */
166 /* For 32-bit sh, this is R_SH_IND12W. */
169 /* For 32-bit sh, this is R_SH_DIR8WPL. */
172 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
175 /* For 32-bit sh, this is R_SH_DIR8BP. */
178 /* For 32-bit sh, this is R_SH_DIR8W. */
181 /* For 32-bit sh, this is R_SH_DIR8L. */
200 /* The remaining relocs are a GNU extension used for relaxing. The
201 final pass of the linker never needs to do anything with any of
202 these relocs. Any required operations are handled by the
205 /* A 16 bit switch table entry. This is generated for an expression
206 such as ``.word L1 - L2''. The offset holds the difference
207 between the reloc address and L2. */
208 HOWTO (R_SH_SWITCH16, /* type */
210 1, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE, /* pc_relative */
214 complain_overflow_unsigned, /* complain_on_overflow */
215 sh_elf64_ignore_reloc, /* special_function */
216 "R_SH_SWITCH16", /* name */
217 FALSE, /* partial_inplace */
220 TRUE), /* pcrel_offset */
222 /* A 32 bit switch table entry. This is generated for an expression
223 such as ``.long L1 - L2''. The offset holds the difference
224 between the reloc address and L2. */
225 HOWTO (R_SH_SWITCH32, /* type */
227 2, /* size (0 = byte, 1 = short, 2 = long) */
229 FALSE, /* pc_relative */
231 complain_overflow_unsigned, /* complain_on_overflow */
232 sh_elf64_ignore_reloc, /* special_function */
233 "R_SH_SWITCH32", /* name */
234 FALSE, /* partial_inplace */
237 TRUE), /* pcrel_offset */
239 /* For 32-bit sh, this is R_SH_USES. */
242 /* For 32-bit sh, this is R_SH_COUNT. */
245 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
246 this might be emitted. When linker relaxation is implemented, we
247 might want to use it. */
250 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
251 this might be emitted. When linker relaxation is implemented, we
252 might want to use it. */
255 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
256 this might be emitted. When linker relaxation is implemented, we
257 might want to use it. */
260 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
261 this might be emitted. When linker relaxation is implemented, we
262 might want to use it. */
265 /* An 8 bit switch table entry. This is generated for an expression
266 such as ``.word L1 - L2''. The offset holds the difference
267 between the reloc address and L2. */
268 HOWTO (R_SH_SWITCH8, /* type */
270 0, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE, /* pc_relative */
274 complain_overflow_unsigned, /* complain_on_overflow */
275 sh_elf64_ignore_reloc, /* special_function */
276 "R_SH_SWITCH8", /* name */
277 FALSE, /* partial_inplace */
280 TRUE), /* pcrel_offset */
282 /* GNU extension to record C++ vtable hierarchy */
283 HOWTO (R_SH_GNU_VTINHERIT, /* type */
285 2, /* size (0 = byte, 1 = short, 2 = long) */
287 FALSE, /* pc_relative */
289 complain_overflow_dont, /* complain_on_overflow */
290 NULL, /* special_function */
291 "R_SH_GNU_VTINHERIT", /* name */
292 FALSE, /* partial_inplace */
295 FALSE), /* pcrel_offset */
297 /* GNU extension to record C++ vtable member usage */
298 HOWTO (R_SH_GNU_VTENTRY, /* type */
300 2, /* size (0 = byte, 1 = short, 2 = long) */
302 FALSE, /* pc_relative */
304 complain_overflow_dont, /* complain_on_overflow */
305 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
306 "R_SH_GNU_VTENTRY", /* name */
307 FALSE, /* partial_inplace */
310 FALSE), /* pcrel_offset */
312 /* For 32-bit sh, this is R_SH_LOOP_START. */
315 /* For 32-bit sh, this is R_SH_LOOP_END. */
326 /* Used in SHLLI.L and SHLRI.L. */
327 HOWTO (R_SH_DIR5U, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 FALSE, /* pc_relative */
333 complain_overflow_unsigned, /* complain_on_overflow */
334 bfd_elf_generic_reloc, /* special_function */
335 "R_SH_DIR5U", /* name */
336 FALSE, /* partial_inplace */
338 0xfc00, /* dst_mask */
339 FALSE), /* pcrel_offset */
341 /* Used in SHARI, SHLLI et al. */
342 HOWTO (R_SH_DIR6U, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 FALSE, /* pc_relative */
348 complain_overflow_unsigned, /* complain_on_overflow */
349 bfd_elf_generic_reloc, /* special_function */
350 "R_SH_DIR6U", /* name */
351 FALSE, /* partial_inplace */
353 0xfc00, /* dst_mask */
354 FALSE), /* pcrel_offset */
356 /* Used in BxxI, LDHI.L et al. */
357 HOWTO (R_SH_DIR6S, /* type */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE, /* pc_relative */
363 complain_overflow_signed, /* complain_on_overflow */
364 bfd_elf_generic_reloc, /* special_function */
365 "R_SH_DIR6S", /* name */
366 FALSE, /* partial_inplace */
368 0xfc00, /* dst_mask */
369 FALSE), /* pcrel_offset */
371 /* Used in ADDI, ANDI et al. */
372 HOWTO (R_SH_DIR10S, /* type */
374 2, /* size (0 = byte, 1 = short, 2 = long) */
376 FALSE, /* pc_relative */
378 complain_overflow_signed, /* complain_on_overflow */
379 bfd_elf_generic_reloc, /* special_function */
380 "R_SH_DIR10S", /* name */
381 FALSE, /* partial_inplace */
383 0xffc00, /* dst_mask */
384 FALSE), /* pcrel_offset */
386 /* Used in LD.UW, ST.W et al. */
387 HOWTO (R_SH_DIR10SW, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE, /* pc_relative */
393 complain_overflow_signed, /* complain_on_overflow */
394 bfd_elf_generic_reloc, /* special_function */
395 "R_SH_DIR10SW", /* name */
396 FALSE, /* partial_inplace */
398 0xffc00, /* dst_mask */
399 FALSE), /* pcrel_offset */
401 /* Used in LD.L, FLD.S et al. */
402 HOWTO (R_SH_DIR10SL, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE, /* pc_relative */
408 complain_overflow_signed, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_SH_DIR10SL", /* name */
411 FALSE, /* partial_inplace */
413 0xffc00, /* dst_mask */
414 FALSE), /* pcrel_offset */
416 /* Used in FLD.D, FST.P et al. */
417 HOWTO (R_SH_DIR10SQ, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE, /* pc_relative */
423 complain_overflow_signed, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_SH_DIR10SQ", /* name */
426 FALSE, /* partial_inplace */
428 0xffc00, /* dst_mask */
429 FALSE), /* pcrel_offset */
540 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
541 any dynamic linking support for 64-bit SH at present. */
553 /* Back to SH5 relocations. */
554 /* Used in MOVI and SHORI (x & 65536). */
555 HOWTO (R_SH_GOT_LOW16, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 FALSE, /* pc_relative */
561 complain_overflow_dont, /* complain_on_overflow */
562 bfd_elf_generic_reloc, /* special_function */
563 "R_SH_GOT_LOW16", /* name */
564 FALSE, /* partial_inplace */
566 0x3fffc00, /* dst_mask */
567 FALSE), /* pcrel_offset */
569 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
570 HOWTO (R_SH_GOT_MEDLOW16, /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 FALSE, /* pc_relative */
576 complain_overflow_dont, /* complain_on_overflow */
577 bfd_elf_generic_reloc, /* special_function */
578 "R_SH_GOT_MEDLOW16", /* name */
579 FALSE, /* partial_inplace */
581 0x3fffc00, /* dst_mask */
582 FALSE), /* pcrel_offset */
584 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
585 HOWTO (R_SH_GOT_MEDHI16, /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 FALSE, /* pc_relative */
591 complain_overflow_dont, /* complain_on_overflow */
592 bfd_elf_generic_reloc, /* special_function */
593 "R_SH_GOT_MEDHI16", /* name */
594 FALSE, /* partial_inplace */
596 0x3fffc00, /* dst_mask */
597 FALSE), /* pcrel_offset */
599 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
600 HOWTO (R_SH_GOT_HI16, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 FALSE, /* pc_relative */
606 complain_overflow_dont, /* complain_on_overflow */
607 bfd_elf_generic_reloc, /* special_function */
608 "R_SH_GOT_HI16", /* name */
609 FALSE, /* partial_inplace */
611 0x3fffc00, /* dst_mask */
612 FALSE), /* pcrel_offset */
614 /* Used in MOVI and SHORI (x & 65536). */
615 HOWTO (R_SH_GOTPLT_LOW16, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 FALSE, /* pc_relative */
621 complain_overflow_dont, /* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_SH_GOTPLT_LOW16", /* name */
624 FALSE, /* partial_inplace */
626 0x3fffc00, /* dst_mask */
627 FALSE), /* pcrel_offset */
629 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
630 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 FALSE, /* pc_relative */
636 complain_overflow_dont, /* complain_on_overflow */
637 bfd_elf_generic_reloc, /* special_function */
638 "R_SH_GOTPLT_MEDLOW16", /* name */
639 FALSE, /* partial_inplace */
641 0x3fffc00, /* dst_mask */
642 FALSE), /* pcrel_offset */
644 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
645 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
649 FALSE, /* pc_relative */
651 complain_overflow_dont, /* complain_on_overflow */
652 bfd_elf_generic_reloc, /* special_function */
653 "R_SH_GOTPLT_MEDHI16", /* name */
654 FALSE, /* partial_inplace */
656 0x3fffc00, /* dst_mask */
657 FALSE), /* pcrel_offset */
659 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
660 HOWTO (R_SH_GOTPLT_HI16, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE, /* pc_relative */
666 complain_overflow_dont, /* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_SH_GOTPLT_HI16", /* name */
669 FALSE, /* partial_inplace */
671 0x3fffc00, /* dst_mask */
672 FALSE), /* pcrel_offset */
674 /* Used in MOVI and SHORI (x & 65536). */
675 HOWTO (R_SH_PLT_LOW16, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 TRUE, /* pc_relative */
681 complain_overflow_dont, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_SH_PLT_LOW16", /* name */
684 FALSE, /* partial_inplace */
686 0x3fffc00, /* dst_mask */
687 TRUE), /* pcrel_offset */
689 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
690 HOWTO (R_SH_PLT_MEDLOW16, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 TRUE, /* pc_relative */
696 complain_overflow_dont, /* complain_on_overflow */
697 bfd_elf_generic_reloc, /* special_function */
698 "R_SH_PLT_MEDLOW16", /* name */
699 FALSE, /* partial_inplace */
701 0x3fffc00, /* dst_mask */
702 TRUE), /* pcrel_offset */
704 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
705 HOWTO (R_SH_PLT_MEDHI16, /* type */
707 2, /* size (0 = byte, 1 = short, 2 = long) */
709 TRUE, /* pc_relative */
711 complain_overflow_dont, /* complain_on_overflow */
712 bfd_elf_generic_reloc, /* special_function */
713 "R_SH_PLT_MEDHI16", /* name */
714 FALSE, /* partial_inplace */
716 0x3fffc00, /* dst_mask */
717 TRUE), /* pcrel_offset */
719 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
720 HOWTO (R_SH_PLT_HI16, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 TRUE, /* pc_relative */
726 complain_overflow_dont, /* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_SH_PLT_HI16", /* name */
729 FALSE, /* partial_inplace */
731 0x3fffc00, /* dst_mask */
732 TRUE), /* pcrel_offset */
734 /* Used in MOVI and SHORI (x & 65536). */
735 HOWTO (R_SH_GOTOFF_LOW16, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE, /* pc_relative */
741 complain_overflow_dont, /* complain_on_overflow */
742 bfd_elf_generic_reloc, /* special_function */
743 "R_SH_GOTOFF_LOW16", /* name */
744 FALSE, /* partial_inplace */
746 0x3fffc00, /* dst_mask */
747 FALSE), /* pcrel_offset */
749 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
750 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE, /* pc_relative */
756 complain_overflow_dont, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_SH_GOTOFF_MEDLOW16", /* name */
759 FALSE, /* partial_inplace */
761 0x3fffc00, /* dst_mask */
762 FALSE), /* pcrel_offset */
764 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
765 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 FALSE, /* pc_relative */
771 complain_overflow_dont, /* complain_on_overflow */
772 bfd_elf_generic_reloc, /* special_function */
773 "R_SH_GOTOFF_MEDHI16", /* name */
774 FALSE, /* partial_inplace */
776 0x3fffc00, /* dst_mask */
777 FALSE), /* pcrel_offset */
779 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
780 HOWTO (R_SH_GOTOFF_HI16, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE, /* pc_relative */
786 complain_overflow_dont, /* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_SH_GOTOFF_HI16", /* name */
789 FALSE, /* partial_inplace */
791 0x3fffc00, /* dst_mask */
792 FALSE), /* pcrel_offset */
794 /* Used in MOVI and SHORI (x & 65536). */
795 HOWTO (R_SH_GOTPC_LOW16, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 TRUE, /* pc_relative */
801 complain_overflow_dont, /* complain_on_overflow */
802 bfd_elf_generic_reloc, /* special_function */
803 "R_SH_GOTPC_LOW16", /* name */
804 FALSE, /* partial_inplace */
806 0x3fffc00, /* dst_mask */
807 TRUE), /* pcrel_offset */
809 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
810 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 TRUE, /* pc_relative */
816 complain_overflow_dont, /* complain_on_overflow */
817 bfd_elf_generic_reloc, /* special_function */
818 "R_SH_GOTPC_MEDLOW16", /* name */
819 FALSE, /* partial_inplace */
821 0x3fffc00, /* dst_mask */
822 TRUE), /* pcrel_offset */
824 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
825 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
827 2, /* size (0 = byte, 1 = short, 2 = long) */
829 TRUE, /* pc_relative */
831 complain_overflow_dont, /* complain_on_overflow */
832 bfd_elf_generic_reloc, /* special_function */
833 "R_SH_GOTPC_MEDHI16", /* name */
834 FALSE, /* partial_inplace */
836 0x3fffc00, /* dst_mask */
837 TRUE), /* pcrel_offset */
839 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
840 HOWTO (R_SH_GOTPC_HI16, /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 TRUE, /* pc_relative */
846 complain_overflow_dont, /* complain_on_overflow */
847 bfd_elf_generic_reloc, /* special_function */
848 "R_SH_GOTPC_HI16", /* name */
849 FALSE, /* partial_inplace */
851 0x3fffc00, /* dst_mask */
852 TRUE), /* pcrel_offset */
854 /* Used in LD.L, FLD.S et al. */
855 HOWTO (R_SH_GOT10BY4, /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 FALSE, /* pc_relative */
861 complain_overflow_signed, /* complain_on_overflow */
862 bfd_elf_generic_reloc, /* special_function */
863 "R_SH_GOT10BY4", /* name */
864 FALSE, /* partial_inplace */
866 0xffc00, /* dst_mask */
867 FALSE), /* pcrel_offset */
869 /* Used in LD.L, FLD.S et al. */
870 HOWTO (R_SH_GOTPLT10BY4, /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 FALSE, /* pc_relative */
876 complain_overflow_signed, /* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_SH_GOTPLT10BY4", /* name */
879 FALSE, /* partial_inplace */
881 0xffc00, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* Used in FLD.D, FST.P et al. */
885 HOWTO (R_SH_GOT10BY8, /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 FALSE, /* pc_relative */
891 complain_overflow_signed, /* complain_on_overflow */
892 bfd_elf_generic_reloc, /* special_function */
893 "R_SH_GOT10BY8", /* name */
894 FALSE, /* partial_inplace */
896 0xffc00, /* dst_mask */
897 FALSE), /* pcrel_offset */
899 /* Used in FLD.D, FST.P et al. */
900 HOWTO (R_SH_GOTPLT10BY8, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 FALSE, /* pc_relative */
906 complain_overflow_signed, /* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_SH_GOTPLT10BY8", /* name */
909 FALSE, /* partial_inplace */
911 0xffc00, /* dst_mask */
912 FALSE), /* pcrel_offset */
914 HOWTO (R_SH_COPY64, /* type */
916 4, /* size (0 = byte, 1 = short, 2 = long) */
918 FALSE, /* pc_relative */
920 complain_overflow_dont, /* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_SH_COPY64", /* name */
923 FALSE, /* partial_inplace */
925 ((bfd_vma) 0) - 1, /* dst_mask */
926 FALSE), /* pcrel_offset */
928 HOWTO (R_SH_GLOB_DAT64, /* type */
930 4, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE, /* pc_relative */
934 complain_overflow_dont, /* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_SH_GLOB_DAT64", /* name */
937 FALSE, /* partial_inplace */
939 ((bfd_vma) 0) - 1, /* dst_mask */
940 FALSE), /* pcrel_offset */
942 HOWTO (R_SH_JMP_SLOT64, /* type */
944 4, /* size (0 = byte, 1 = short, 2 = long) */
946 FALSE, /* pc_relative */
948 complain_overflow_dont, /* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_SH_JMP_SLOT64", /* name */
951 FALSE, /* partial_inplace */
953 ((bfd_vma) 0) - 1, /* dst_mask */
954 FALSE), /* pcrel_offset */
956 HOWTO (R_SH_RELATIVE64, /* type */
958 4, /* size (0 = byte, 1 = short, 2 = long) */
960 FALSE, /* pc_relative */
962 complain_overflow_dont, /* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_SH_RELATIVE64", /* name */
965 FALSE, /* partial_inplace */
967 ((bfd_vma) 0) - 1, /* dst_mask */
968 FALSE), /* pcrel_offset */
1016 /* Relocations for SHmedia code. None of these are partial_inplace or
1017 use the field being relocated. */
1019 /* The assembler will generate this reloc before a block of SHmedia
1020 instructions. A section should be processed as assuming it contains
1021 data, unless this reloc is seen. Note that a block of SHcompact
1022 instructions are instead preceded by R_SH_CODE.
1023 This is currently not implemented, but should be used for SHmedia
1024 linker relaxation. */
1025 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1027 1, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE, /* pc_relative */
1031 complain_overflow_unsigned, /* complain_on_overflow */
1032 sh_elf64_ignore_reloc, /* special_function */
1033 "R_SH_SHMEDIA_CODE", /* name */
1034 FALSE, /* partial_inplace */
1037 FALSE), /* pcrel_offset */
1039 /* The assembler will generate this reloc at a PTA or PTB instruction,
1040 and the linker checks the right type of target, or changes a PTA to a
1041 PTB, if the original insn was PT. */
1042 HOWTO (R_SH_PT_16, /* type */
1044 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 TRUE, /* pc_relative */
1048 complain_overflow_signed, /* complain_on_overflow */
1049 bfd_elf_generic_reloc, /* special_function */
1050 "R_SH_PT_16", /* name */
1051 FALSE, /* partial_inplace */
1053 0x3fffc00, /* dst_mask */
1054 TRUE), /* pcrel_offset */
1056 /* Used in unexpanded MOVI. */
1057 HOWTO (R_SH_IMMS16, /* type */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1061 FALSE, /* pc_relative */
1063 complain_overflow_signed, /* complain_on_overflow */
1064 bfd_elf_generic_reloc, /* special_function */
1065 "R_SH_IMMS16", /* name */
1066 FALSE, /* partial_inplace */
1068 0x3fffc00, /* dst_mask */
1069 FALSE), /* pcrel_offset */
1071 /* Used in SHORI. */
1072 HOWTO (R_SH_IMMU16, /* type */
1074 2, /* size (0 = byte, 1 = short, 2 = long) */
1076 FALSE, /* pc_relative */
1078 complain_overflow_unsigned, /* complain_on_overflow */
1079 bfd_elf_generic_reloc, /* special_function */
1080 "R_SH_IMMU16", /* name */
1081 FALSE, /* partial_inplace */
1083 0x3fffc00, /* dst_mask */
1084 FALSE), /* pcrel_offset */
1086 /* Used in MOVI and SHORI (x & 65536). */
1087 HOWTO (R_SH_IMM_LOW16, /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE, /* pc_relative */
1093 complain_overflow_dont, /* complain_on_overflow */
1094 bfd_elf_generic_reloc, /* special_function */
1095 "R_SH_IMM_LOW16", /* name */
1096 FALSE, /* partial_inplace */
1098 0x3fffc00, /* dst_mask */
1099 FALSE), /* pcrel_offset */
1101 /* Used in MOVI and SHORI ((x - $) & 65536). */
1102 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1104 2, /* size (0 = byte, 1 = short, 2 = long) */
1106 TRUE, /* pc_relative */
1108 complain_overflow_dont, /* complain_on_overflow */
1109 bfd_elf_generic_reloc, /* special_function */
1110 "R_SH_IMM_LOW16_PCREL", /* name */
1111 FALSE, /* partial_inplace */
1113 0x3fffc00, /* dst_mask */
1114 TRUE), /* pcrel_offset */
1116 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1117 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1118 16, /* rightshift */
1119 2, /* size (0 = byte, 1 = short, 2 = long) */
1121 FALSE, /* pc_relative */
1123 complain_overflow_dont, /* complain_on_overflow */
1124 bfd_elf_generic_reloc, /* special_function */
1125 "R_SH_IMM_MEDLOW16", /* name */
1126 FALSE, /* partial_inplace */
1128 0x3fffc00, /* dst_mask */
1129 FALSE), /* pcrel_offset */
1131 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1132 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1133 16, /* rightshift */
1134 2, /* size (0 = byte, 1 = short, 2 = long) */
1136 TRUE, /* pc_relative */
1138 complain_overflow_dont, /* complain_on_overflow */
1139 bfd_elf_generic_reloc, /* special_function */
1140 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1141 FALSE, /* partial_inplace */
1143 0x3fffc00, /* dst_mask */
1144 TRUE), /* pcrel_offset */
1146 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1147 HOWTO (R_SH_IMM_MEDHI16, /* type */
1148 32, /* rightshift */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 FALSE, /* pc_relative */
1153 complain_overflow_dont, /* complain_on_overflow */
1154 bfd_elf_generic_reloc, /* special_function */
1155 "R_SH_IMM_MEDHI16", /* name */
1156 FALSE, /* partial_inplace */
1158 0x3fffc00, /* dst_mask */
1159 FALSE), /* pcrel_offset */
1161 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1162 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1163 32, /* rightshift */
1164 2, /* size (0 = byte, 1 = short, 2 = long) */
1166 TRUE, /* pc_relative */
1168 complain_overflow_dont, /* complain_on_overflow */
1169 bfd_elf_generic_reloc, /* special_function */
1170 "R_SH_IMM_MEDHI16_PCREL", /* name */
1171 FALSE, /* partial_inplace */
1173 0x3fffc00, /* dst_mask */
1174 TRUE), /* pcrel_offset */
1176 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1177 HOWTO (R_SH_IMM_HI16, /* type */
1178 48, /* rightshift */
1179 2, /* size (0 = byte, 1 = short, 2 = long) */
1181 FALSE, /* pc_relative */
1183 complain_overflow_dont, /* complain_on_overflow */
1184 bfd_elf_generic_reloc, /* special_function */
1185 "R_SH_IMM_HI16", /* name */
1186 FALSE, /* partial_inplace */
1188 0x3fffc00, /* dst_mask */
1189 FALSE), /* pcrel_offset */
1191 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1192 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1193 48, /* rightshift */
1194 2, /* size (0 = byte, 1 = short, 2 = long) */
1196 TRUE, /* pc_relative */
1198 complain_overflow_dont, /* complain_on_overflow */
1199 bfd_elf_generic_reloc, /* special_function */
1200 "R_SH_IMM_HI16_PCREL", /* name */
1201 FALSE, /* partial_inplace */
1203 0x3fffc00, /* dst_mask */
1204 TRUE), /* pcrel_offset */
1206 /* For the .uaquad pseudo. */
1207 HOWTO (R_SH_64, /* type */
1209 4, /* size (0 = byte, 1 = short, 2 = long) */
1211 FALSE, /* pc_relative */
1213 complain_overflow_dont, /* complain_on_overflow */
1214 bfd_elf_generic_reloc, /* special_function */
1215 "R_SH_64", /* name */
1216 FALSE, /* partial_inplace */
1218 ((bfd_vma) 0) - 1, /* dst_mask */
1219 FALSE), /* pcrel_offset */
1221 /* For the .uaquad pseudo, (x - $). */
1222 HOWTO (R_SH_64_PCREL, /* type */
1223 48, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 TRUE, /* pc_relative */
1228 complain_overflow_dont, /* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_SH_64_PCREL", /* name */
1231 FALSE, /* partial_inplace */
1233 ((bfd_vma) 0) - 1, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1238 /* This function is used for relocs which are only used for relaxing,
1239 which the linker should otherwise ignore. */
1241 static bfd_reloc_status_type
1242 sh_elf64_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1243 asymbol *symbol ATTRIBUTE_UNUSED,
1244 void *data ATTRIBUTE_UNUSED, asection *input_section,
1246 char **error_message ATTRIBUTE_UNUSED)
1248 if (output_bfd != NULL)
1249 reloc_entry->address += input_section->output_offset;
1250 return bfd_reloc_ok;
1253 /* This function is used for normal relocs. This used to be like the COFF
1254 function, and is almost certainly incorrect for other ELF targets.
1256 See sh_elf_reloc in elf32-sh.c for the original. */
1258 static bfd_reloc_status_type
1259 sh_elf64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1260 void *data, asection *input_section, bfd *output_bfd,
1261 char **error_message ATTRIBUTE_UNUSED)
1265 enum elf_sh_reloc_type r_type;
1266 bfd_vma addr = reloc_entry->address;
1267 bfd_byte *hit_data = addr + (bfd_byte *) data;
1269 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1271 if (output_bfd != NULL)
1273 /* Partial linking--do nothing. */
1274 reloc_entry->address += input_section->output_offset;
1275 return bfd_reloc_ok;
1278 if (symbol_in != NULL
1279 && bfd_is_und_section (symbol_in->section))
1280 return bfd_reloc_undefined;
1282 if (bfd_is_com_section (symbol_in->section))
1285 sym_value = (symbol_in->value +
1286 symbol_in->section->output_section->vma +
1287 symbol_in->section->output_offset);
1292 insn = bfd_get_32 (abfd, hit_data);
1293 insn += sym_value + reloc_entry->addend;
1294 bfd_put_32 (abfd, insn, hit_data);
1302 return bfd_reloc_ok;
1305 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1307 struct elf_reloc_map
1309 bfd_reloc_code_real_type bfd_reloc_val;
1310 unsigned char elf_reloc_val;
1313 /* An array mapping BFD reloc codes to SH ELF relocs. */
1315 static const struct elf_reloc_map sh64_reloc_map[] =
1317 { BFD_RELOC_NONE, R_SH_NONE },
1318 { BFD_RELOC_32, R_SH_DIR32 },
1319 { BFD_RELOC_CTOR, R_SH_DIR32 },
1320 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1321 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1322 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1323 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1324 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1325 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1326 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1327 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1328 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1329 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1330 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1331 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1332 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1333 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1334 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1335 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1336 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1337 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1338 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1339 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1340 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1341 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1342 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1343 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1344 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1345 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1346 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1347 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1348 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1349 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1350 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1351 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1352 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1353 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1354 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1355 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1356 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1357 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1358 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1359 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1360 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1361 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1362 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1363 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1364 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1365 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1366 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1367 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1368 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1369 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1370 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1371 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1372 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1373 { BFD_RELOC_64, R_SH_64 },
1374 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1377 /* Given a BFD reloc code, return the howto structure for the
1378 corresponding SH ELf reloc. */
1380 static reloc_howto_type *
1381 sh_elf64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1382 bfd_reloc_code_real_type code)
1386 for (i = 0; i < sizeof (sh64_reloc_map) / sizeof (struct elf_reloc_map); i++)
1388 if (sh64_reloc_map[i].bfd_reloc_val == code)
1389 return &sh_elf64_howto_table[(int) sh64_reloc_map[i].elf_reloc_val];
1395 /* Given an ELF reloc, fill in the howto field of a relent.
1397 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1400 sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
1401 Elf_Internal_Rela *dst)
1405 r = ELF64_R_TYPE (dst->r_info);
1407 BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL);
1408 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1409 BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2);
1410 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32);
1411 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1413 cache_ptr->howto = &sh_elf64_howto_table[r];
1416 /* Relocate an SH ELF section.
1418 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1421 sh_elf64_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1422 struct bfd_link_info *info, bfd *input_bfd,
1423 asection *input_section, bfd_byte *contents,
1424 Elf_Internal_Rela *relocs,
1425 Elf_Internal_Sym *local_syms,
1426 asection **local_sections)
1428 Elf_Internal_Shdr *symtab_hdr;
1429 struct elf_link_hash_entry **sym_hashes;
1430 Elf_Internal_Rela *rel, *relend;
1432 bfd_vma *local_got_offsets;
1437 bfd_vma disp, dropped;
1439 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1440 sym_hashes = elf_sym_hashes (input_bfd);
1441 dynobj = elf_hash_table (info)->dynobj;
1442 local_got_offsets = elf_local_got_offsets (input_bfd);
1450 relend = relocs + input_section->reloc_count;
1451 for (; rel < relend; rel++)
1454 reloc_howto_type *howto;
1455 unsigned long r_symndx;
1456 Elf_Internal_Sym *sym;
1458 struct elf_link_hash_entry *h;
1460 bfd_vma addend = (bfd_vma)0;
1461 bfd_reloc_status_type r;
1462 int seen_stt_datalabel = 0;
1464 r_symndx = ELF64_R_SYM (rel->r_info);
1466 r_type = ELF64_R_TYPE (rel->r_info);
1468 if (r_type == (int) R_SH_NONE)
1472 || r_type > R_SH_64_PCREL
1473 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
1474 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1475 || (r_type >= (int) R_SH_DIR8WPN
1476 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
1477 || (r_type >= (int) R_SH_GNU_VTINHERIT
1478 && r_type <= (int) R_SH_PSHL)
1479 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
1480 && r_type <= R_SH_GOTPLT32)
1481 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
1482 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4))
1484 bfd_set_error (bfd_error_bad_value);
1488 howto = sh_elf64_howto_table + r_type;
1494 if (r_symndx < symtab_hdr->sh_info)
1496 sym = local_syms + r_symndx;
1497 sec = local_sections[r_symndx];
1498 relocation = ((sec->output_section->vma
1499 + sec->output_offset
1501 | ((sym->st_other & STO_SH5_ISA32) != 0));
1503 /* A local symbol never has STO_SH5_ISA32, so we don't need
1504 datalabel processing here. Make sure this does not change
1506 if ((sym->st_other & STO_SH5_ISA32) != 0)
1507 ((*info->callbacks->reloc_dangerous)
1509 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1510 input_bfd, input_section, rel->r_offset));
1512 if (sec != NULL && elf_discarded_section (sec))
1513 /* Handled below. */
1515 else if (info->relocatable)
1517 /* This is a relocatable link. We don't have to change
1518 anything, unless the reloc is against a section symbol,
1519 in which case we have to adjust according to where the
1520 section symbol winds up in the output section. */
1521 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1522 goto final_link_relocate;
1526 else if (! howto->partial_inplace)
1528 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1529 relocation |= ((sym->st_other & STO_SH5_ISA32) != 0);
1531 else if ((sec->flags & SEC_MERGE)
1532 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1536 if (howto->rightshift || howto->src_mask != 0xffffffff)
1538 (*_bfd_error_handler)
1539 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
1540 input_bfd, input_section,
1541 (long) rel->r_offset, howto->name);
1545 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
1548 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
1550 addend += msec->output_section->vma + msec->output_offset;
1551 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
1557 /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ? */
1559 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1560 while (h->root.type == bfd_link_hash_indirect
1561 || h->root.type == bfd_link_hash_warning)
1563 /* If the reference passes a symbol marked with
1564 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1566 seen_stt_datalabel |= h->type == STT_DATALABEL;
1567 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1570 if (h->root.type == bfd_link_hash_defined
1571 || h->root.type == bfd_link_hash_defweak)
1573 sec = h->root.u.def.section;
1574 /* In these cases, we don't need the relocation value.
1575 We check specially because in some obscure cases
1576 sec->output_section will be NULL. */
1577 if (r_type == R_SH_GOTPC_LOW16
1578 || r_type == R_SH_GOTPC_MEDLOW16
1579 || r_type == R_SH_GOTPC_MEDHI16
1580 || r_type == R_SH_GOTPC_HI16
1581 || ((r_type == R_SH_PLT_LOW16
1582 || r_type == R_SH_PLT_MEDLOW16
1583 || r_type == R_SH_PLT_MEDHI16
1584 || r_type == R_SH_PLT_HI16)
1585 && h->plt.offset != (bfd_vma) -1)
1586 || ((r_type == R_SH_GOT_LOW16
1587 || r_type == R_SH_GOT_MEDLOW16
1588 || r_type == R_SH_GOT_MEDHI16
1589 || r_type == R_SH_GOT_HI16)
1590 && elf_hash_table (info)->dynamic_sections_created
1592 || (! info->symbolic && h->dynindx != -1)
1593 || !h->def_regular))
1594 /* The cases above are those in which relocation is
1595 overwritten in the switch block below. The cases
1596 below are those in which we must defer relocation
1597 to run-time, because we can't resolve absolute
1598 addresses when creating a shared library. */
1600 && ((! info->symbolic && h->dynindx != -1)
1602 && ((r_type == R_SH_64
1603 && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1604 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
1605 || r_type == R_SH_64_PCREL)
1606 && ((input_section->flags & SEC_ALLOC) != 0
1607 /* DWARF will emit R_SH_DIR32 relocations in its
1608 sections against symbols defined externally
1609 in shared libraries. We can't do anything
1611 || (input_section->flags & SEC_DEBUGGING) != 0))
1612 /* Dynamic relocs are not propagated for SEC_DEBUGGING
1613 sections because such sections are not SEC_ALLOC and
1614 thus ld.so will not process them. */
1615 || (sec->output_section == NULL
1616 && ((input_section->flags & SEC_DEBUGGING) != 0
1617 && h->def_dynamic)))
1619 else if (sec->output_section != NULL)
1620 relocation = ((h->root.u.def.value
1621 + sec->output_section->vma
1622 + sec->output_offset)
1623 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1624 symbol value, unless we've seen
1625 STT_DATALABEL on the way to it. */
1626 | ((h->other & STO_SH5_ISA32) != 0
1627 && ! seen_stt_datalabel));
1628 else if (!info->relocatable)
1630 (*_bfd_error_handler)
1631 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1634 (long) rel->r_offset,
1636 h->root.root.string);
1639 else if (h->root.type == bfd_link_hash_undefweak)
1641 else if (info->unresolved_syms_in_objects == RM_IGNORE
1642 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1644 else if (!info->relocatable)
1646 if (! ((*info->callbacks->undefined_symbol)
1647 (info, h->root.root.string, input_bfd,
1648 input_section, rel->r_offset,
1649 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
1650 || ELF_ST_VISIBILITY (h->other)))))
1655 if (sec != NULL && elf_discarded_section (sec))
1657 /* For relocs against symbols from removed linkonce sections,
1658 or sections discarded by a linker script, we just want the
1659 section contents zeroed. Avoid any special processing. */
1660 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1666 if (info->relocatable)
1670 - input_section->output_section->vma
1671 - input_section->output_offset
1674 switch ((int)r_type)
1676 case R_SH_PT_16: dropped = disp & 2; break;
1677 case R_SH_DIR10SW: dropped = disp & 1; break;
1678 case R_SH_DIR10SL: dropped = disp & 3; break;
1679 case R_SH_DIR10SQ: dropped = disp & 7; break;
1683 (*_bfd_error_handler)
1684 (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1685 bfd_get_filename (input_bfd), (int)r_type, (unsigned)rel->r_offset, (unsigned)relocation);
1686 bfd_set_error (bfd_error_bad_value);
1689 switch ((int)r_type)
1694 && (input_section->flags & SEC_ALLOC) != 0
1695 && (r_type != R_SH_64_PCREL
1698 && (! info->symbolic
1699 || !h->def_regular))))
1701 Elf_Internal_Rela outrel;
1703 bfd_boolean skip, relocate;
1705 /* When generating a shared object, these relocations
1706 are copied into the output file to be resolved at run
1713 name = (bfd_elf_string_from_elf_section
1715 elf_elfheader (input_bfd)->e_shstrndx,
1716 elf_section_data (input_section)->rel_hdr.sh_name));
1720 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
1721 && strcmp (bfd_get_section_name (input_bfd,
1725 sreloc = bfd_get_section_by_name (dynobj, name);
1726 BFD_ASSERT (sreloc != NULL);
1733 = _bfd_elf_section_offset (output_bfd, info,
1734 input_section, rel->r_offset);
1736 if (outrel.r_offset == (bfd_vma) -1)
1738 else if (outrel.r_offset == (bfd_vma) -2)
1739 skip = TRUE, relocate = TRUE;
1741 outrel.r_offset += (input_section->output_section->vma
1742 + input_section->output_offset);
1745 memset (&outrel, 0, sizeof outrel);
1746 else if (r_type == R_SH_64_PCREL)
1748 BFD_ASSERT (h != NULL && h->dynindx != -1);
1749 outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64_PCREL);
1750 outrel.r_addend = rel->r_addend;
1754 /* h->dynindx may be -1 if this symbol was marked to
1757 || ((info->symbolic || h->dynindx == -1)
1761 outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1762 outrel.r_addend = relocation + rel->r_addend;
1766 BFD_ASSERT (h->dynindx != -1);
1767 outrel.r_info = ELF64_R_INFO (h->dynindx, R_SH_64);
1768 outrel.r_addend = relocation + rel->r_addend;
1772 loc = sreloc->contents;
1773 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
1774 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1776 /* If this reloc is against an external symbol, we do
1777 not want to fiddle with the addend. Otherwise, we
1778 need to include the symbol value so that it becomes
1779 an addend for the dynamic reloc. */
1783 else if (r_type == R_SH_64)
1784 addend = rel->r_addend;
1785 goto final_link_relocate;
1787 case R_SH_GOTPLT_LOW16:
1788 case R_SH_GOTPLT_MEDLOW16:
1789 case R_SH_GOTPLT_MEDHI16:
1790 case R_SH_GOTPLT_HI16:
1791 case R_SH_GOTPLT10BY4:
1792 case R_SH_GOTPLT10BY8:
1793 /* Relocation is to the entry for this symbol in the
1794 procedure linkage table. */
1797 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1798 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
1802 || h->plt.offset == (bfd_vma) -1
1803 || h->got.offset != (bfd_vma) -1)
1806 /* Relocation is to the entry for this symbol in the global
1807 offset table extension for the procedure linkage table. */
1808 if (sgotplt == NULL)
1810 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1811 BFD_ASSERT (sgotplt != NULL);
1814 relocation = (sgotplt->output_offset
1815 + ((h->plt.offset / elf_sh64_sizeof_plt (info)
1818 relocation -= GOT_BIAS;
1820 goto final_link_relocate;
1823 case R_SH_GOT_LOW16:
1824 case R_SH_GOT_MEDLOW16:
1825 case R_SH_GOT_MEDHI16:
1829 /* Relocation is to the entry for this symbol in the global
1833 sgot = bfd_get_section_by_name (dynobj, ".got");
1834 BFD_ASSERT (sgot != NULL);
1841 off = h->got.offset;
1842 if (seen_stt_datalabel)
1844 struct elf_sh64_link_hash_entry *hsh;
1846 hsh = (struct elf_sh64_link_hash_entry *)h;
1847 off = hsh->datalabel_got_offset;
1849 BFD_ASSERT (off != (bfd_vma) -1);
1851 if (! elf_hash_table (info)->dynamic_sections_created
1853 && (info->symbolic || h->dynindx == -1
1854 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
1855 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
1858 /* This is actually a static link, or it is a
1859 -Bsymbolic link and the symbol is defined
1860 locally, or the symbol was forced to be local
1861 because of a version file. We must initialize
1862 this entry in the global offset table. Since the
1863 offset must always be a multiple of 4, we use the
1864 least significant bit to record whether we have
1865 initialized it already.
1867 When doing a dynamic link, we create a .rela.got
1868 relocation entry to initialize the value. This
1869 is done in the finish_dynamic_symbol routine. */
1874 bfd_put_64 (output_bfd, relocation,
1875 sgot->contents + off);
1876 if (seen_stt_datalabel)
1878 struct elf_sh64_link_hash_entry *hsh;
1880 hsh = (struct elf_sh64_link_hash_entry *)h;
1881 hsh->datalabel_got_offset |= 1;
1888 relocation = sgot->output_offset + off;
1896 BFD_ASSERT (local_got_offsets != NULL
1897 && (local_got_offsets[symtab_hdr->sh_info
1901 off = local_got_offsets[symtab_hdr->sh_info
1906 BFD_ASSERT (local_got_offsets != NULL
1907 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1909 off = local_got_offsets[r_symndx];
1912 /* The offset must always be a multiple of 8. We use
1913 the least significant bit to record whether we have
1914 already generated the necessary reloc. */
1919 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
1924 Elf_Internal_Rela outrel;
1927 s = bfd_get_section_by_name (dynobj, ".rela.got");
1928 BFD_ASSERT (s != NULL);
1930 outrel.r_offset = (sgot->output_section->vma
1931 + sgot->output_offset
1933 outrel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
1934 outrel.r_addend = relocation;
1936 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
1937 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1941 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
1943 local_got_offsets[r_symndx] |= 1;
1946 relocation = sgot->output_offset + off;
1949 relocation -= GOT_BIAS;
1951 goto final_link_relocate;
1953 case R_SH_GOTOFF_LOW16:
1954 case R_SH_GOTOFF_MEDLOW16:
1955 case R_SH_GOTOFF_MEDHI16:
1956 case R_SH_GOTOFF_HI16:
1957 /* Relocation is relative to the start of the global offset
1962 sgot = bfd_get_section_by_name (dynobj, ".got");
1963 BFD_ASSERT (sgot != NULL);
1966 /* Note that sgot->output_offset is not involved in this
1967 calculation. We always want the start of .got. If we
1968 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1969 permitted by the ABI, we might have to change this
1971 relocation -= sgot->output_section->vma;
1973 relocation -= GOT_BIAS;
1975 addend = rel->r_addend;
1977 goto final_link_relocate;
1979 case R_SH_GOTPC_LOW16:
1980 case R_SH_GOTPC_MEDLOW16:
1981 case R_SH_GOTPC_MEDHI16:
1982 case R_SH_GOTPC_HI16:
1983 /* Use global offset table as symbol value. */
1987 sgot = bfd_get_section_by_name (dynobj, ".got");
1988 BFD_ASSERT (sgot != NULL);
1991 relocation = sgot->output_section->vma;
1993 relocation += GOT_BIAS;
1995 addend = rel->r_addend;
1997 goto final_link_relocate;
1999 case R_SH_PLT_LOW16:
2000 case R_SH_PLT_MEDLOW16:
2001 case R_SH_PLT_MEDHI16:
2003 /* Relocation is to the entry for this symbol in the
2004 procedure linkage table. */
2006 /* Resolve a PLT reloc against a local symbol directly,
2007 without using the procedure linkage table. */
2009 goto final_link_relocate;
2011 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2012 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2013 goto final_link_relocate;
2015 if (h->plt.offset == (bfd_vma) -1)
2017 /* We didn't make a PLT entry for this symbol. This
2018 happens when statically linking PIC code, or when
2019 using -Bsymbolic. */
2020 goto final_link_relocate;
2025 splt = bfd_get_section_by_name (dynobj, ".plt");
2026 BFD_ASSERT (splt != NULL);
2029 relocation = (splt->output_section->vma
2030 + splt->output_offset
2034 addend = rel->r_addend;
2036 goto final_link_relocate;
2039 case R_SH_SHMEDIA_CODE:
2050 case R_SH_IMM_LOW16:
2051 case R_SH_IMM_LOW16_PCREL:
2052 case R_SH_IMM_MEDLOW16:
2053 case R_SH_IMM_MEDLOW16_PCREL:
2054 case R_SH_IMM_MEDHI16:
2055 case R_SH_IMM_MEDHI16_PCREL:
2057 case R_SH_IMM_HI16_PCREL:
2058 addend = rel->r_addend;
2061 final_link_relocate:
2062 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2063 contents, rel->r_offset,
2064 relocation, addend);
2068 bfd_set_error (bfd_error_bad_value);
2073 if (r != bfd_reloc_ok)
2078 case bfd_reloc_outofrange:
2080 case bfd_reloc_overflow:
2088 name = (bfd_elf_string_from_elf_section
2089 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2093 name = bfd_section_name (input_bfd, sec);
2095 if (! ((*info->callbacks->reloc_overflow)
2096 (info, (h ? &h->root : NULL), name, howto->name,
2097 (bfd_vma) 0, input_bfd, input_section,
2109 /* This is a version of bfd_generic_get_relocated_section_contents
2110 that uses sh_elf64_relocate_section.
2112 See sh_elf_relocate_section in elf32-sh.c for the original. */
2115 sh_elf64_get_relocated_section_contents (bfd *output_bfd,
2116 struct bfd_link_info *link_info,
2117 struct bfd_link_order *link_order,
2119 bfd_boolean relocatable,
2122 Elf_Internal_Shdr *symtab_hdr;
2123 asection *input_section = link_order->u.indirect.section;
2124 bfd *input_bfd = input_section->owner;
2125 asection **sections = NULL;
2126 Elf_Internal_Rela *internal_relocs = NULL;
2127 Elf_Internal_Sym *isymbuf = NULL;
2129 /* We only need to handle the case of relaxing, or of having a
2130 particular set of section contents, specially. */
2132 || elf_section_data (input_section)->this_hdr.contents == NULL)
2133 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2138 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2140 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
2141 input_section->size);
2143 if ((input_section->flags & SEC_RELOC) != 0
2144 && input_section->reloc_count > 0)
2146 Elf_Internal_Sym *isymp;
2147 Elf_Internal_Sym *isymend;
2150 /* Read this BFD's local symbols. */
2151 if (symtab_hdr->sh_info != 0)
2153 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2154 if (isymbuf == NULL)
2155 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2156 symtab_hdr->sh_info, 0,
2158 if (isymbuf == NULL)
2162 internal_relocs = (_bfd_elf_link_read_relocs
2163 (input_bfd, input_section, NULL,
2164 (Elf_Internal_Rela *) NULL, FALSE));
2165 if (internal_relocs == NULL)
2168 sections = (asection **) bfd_malloc (symtab_hdr->sh_info
2169 * sizeof (asection *));
2170 if (sections == NULL && symtab_hdr->sh_info > 0)
2174 isymend = isymbuf + symtab_hdr->sh_info;
2175 for (isymp = isymbuf; isymp < isymend; ++isymp, ++secpp)
2179 if (isymp->st_shndx == SHN_UNDEF)
2180 isec = bfd_und_section_ptr;
2181 else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
2182 isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
2183 else if (isymp->st_shndx == SHN_ABS)
2184 isec = bfd_abs_section_ptr;
2185 else if (isymp->st_shndx == SHN_COMMON)
2186 isec = bfd_com_section_ptr;
2196 if (! sh_elf64_relocate_section (output_bfd, link_info, input_bfd,
2197 input_section, data, internal_relocs,
2201 if (sections != NULL)
2203 if (internal_relocs != elf_section_data (input_section)->relocs)
2204 free (internal_relocs);
2206 && (unsigned char *) isymbuf != symtab_hdr->contents)
2213 if (sections != NULL)
2215 if (internal_relocs != NULL
2216 && internal_relocs != elf_section_data (input_section)->relocs)
2217 free (internal_relocs);
2219 && (unsigned char *) isymbuf != symtab_hdr->contents)
2224 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */
2227 sh64_elf64_fake_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2228 Elf_Internal_Shdr *elf_section_hdr,
2231 /* Code sections can only contain SH64 code, so mark them as such. */
2232 if (bfd_get_section_flags (output_bfd, asect) & SEC_CODE)
2233 elf_section_hdr->sh_flags |= SHF_SH5_ISA32;
2239 sh_elf64_set_mach_from_flags (bfd *abfd)
2241 flagword flags = elf_elfheader (abfd)->e_flags;
2243 switch (flags & EF_SH_MACH_MASK)
2246 /* Just one, but keep the switch construct to make additions easy. */
2247 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh5);
2251 bfd_set_error (bfd_error_wrong_format);
2257 /* Function to keep SH64 specific file flags.
2259 See sh64_elf_set_private_flags in elf32-sh64.c for the original. */
2262 sh_elf64_set_private_flags (bfd *abfd, flagword flags)
2264 BFD_ASSERT (! elf_flags_init (abfd)
2265 || elf_elfheader (abfd)->e_flags == flags);
2267 elf_elfheader (abfd)->e_flags = flags;
2268 elf_flags_init (abfd) = TRUE;
2269 return sh_elf64_set_mach_from_flags (abfd);
2272 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2273 code, to keep attributes the same as for SHmedia in 32-bit ELF. */
2276 sh_elf64_copy_private_data_internal (bfd *ibfd, bfd *obfd)
2278 Elf_Internal_Shdr **o_shdrp;
2282 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2283 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2286 o_shdrp = elf_elfsections (obfd);
2287 for (osec = obfd->sections; osec; osec = osec->next)
2289 int oIndex = ((struct bfd_elf_section_data *) elf_section_data (osec))->this_idx;
2290 for (isec = ibfd->sections; isec; isec = isec->next)
2292 if (strcmp (osec->name, isec->name) == 0)
2294 /* Note that we're not disallowing mixing data and code. */
2295 if ((elf_section_data (isec)->this_hdr.sh_flags
2296 & SHF_SH5_ISA32) != 0)
2297 o_shdrp[oIndex]->sh_flags |= SHF_SH5_ISA32;
2303 return sh_elf64_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
2307 sh_elf64_copy_private_data (bfd *ibfd, bfd *obfd)
2309 return sh_elf64_copy_private_data_internal (ibfd, obfd);
2313 sh_elf64_merge_private_data (bfd *ibfd, bfd *obfd)
2315 flagword old_flags, new_flags;
2317 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2320 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2321 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2324 if (bfd_get_arch_size (ibfd) != bfd_get_arch_size (obfd))
2328 if (bfd_get_arch_size (ibfd) == 32
2329 && bfd_get_arch_size (obfd) == 64)
2330 msg = _("%s: compiled as 32-bit object and %s is 64-bit");
2331 else if (bfd_get_arch_size (ibfd) == 64
2332 && bfd_get_arch_size (obfd) == 32)
2333 msg = _("%s: compiled as 64-bit object and %s is 32-bit");
2335 msg = _("%s: object size does not match that of target %s");
2337 (*_bfd_error_handler) (msg, bfd_get_filename (ibfd),
2338 bfd_get_filename (obfd));
2339 bfd_set_error (bfd_error_wrong_format);
2343 old_flags = elf_elfheader (obfd)->e_flags;
2344 new_flags = elf_elfheader (ibfd)->e_flags;
2345 if (! elf_flags_init (obfd))
2347 /* This happens when ld starts out with a 'blank' output file. */
2348 elf_flags_init (obfd) = TRUE;
2349 elf_elfheader (obfd)->e_flags = old_flags = new_flags;
2351 /* We don't allow linking in anything else than SH64 code, and since
2352 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2353 here as things change. */
2354 else if ((new_flags & EF_SH_MACH_MASK) != EF_SH5)
2356 (*_bfd_error_handler)
2357 ("%s: does not use the SH64 64-bit ABI as previous modules do",
2358 bfd_get_filename (ibfd));
2359 bfd_set_error (bfd_error_bad_value);
2363 sh_elf64_copy_private_data_internal (ibfd, obfd);
2365 /* I can't think of anything sane other than old_flags being EF_SH5 and
2366 that we need to preserve that. */
2367 elf_elfheader (obfd)->e_flags = old_flags;
2369 return sh_elf64_set_mach_from_flags (obfd);
2372 /* Return the section that should be marked against GC for a given
2376 sh_elf64_gc_mark_hook (asection *sec,
2377 struct bfd_link_info *info,
2378 Elf_Internal_Rela *rel,
2379 struct elf_link_hash_entry *h,
2380 Elf_Internal_Sym *sym)
2383 switch (ELF64_R_TYPE (rel->r_info))
2385 case R_SH_GNU_VTINHERIT:
2386 case R_SH_GNU_VTENTRY:
2390 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2393 /* Look through the relocs for a section during the first phase.
2394 Since we don't do .gots or .plts, we just need to consider the
2395 virtual table relocs for gc. */
2398 sh_elf64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2399 asection *sec, const Elf_Internal_Rela *relocs)
2401 Elf_Internal_Shdr *symtab_hdr;
2402 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2403 const Elf_Internal_Rela *rel;
2404 const Elf_Internal_Rela *rel_end;
2406 bfd_vma *local_got_offsets;
2415 if (info->relocatable)
2418 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2419 sym_hashes = elf_sym_hashes (abfd);
2420 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym);
2421 if (!elf_bad_symtab (abfd))
2422 sym_hashes_end -= symtab_hdr->sh_info;
2424 dynobj = elf_hash_table (info)->dynobj;
2425 local_got_offsets = elf_local_got_offsets (abfd);
2427 rel_end = relocs + sec->reloc_count;
2428 for (rel = relocs; rel < rel_end; rel++)
2430 struct elf_link_hash_entry *h;
2431 unsigned long r_symndx;
2433 r_symndx = ELF64_R_SYM (rel->r_info);
2434 if (r_symndx < symtab_hdr->sh_info)
2438 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2439 while (h->root.type == bfd_link_hash_indirect
2440 || h->root.type == bfd_link_hash_warning)
2441 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2444 /* Some relocs require a global offset table. */
2447 switch (ELF64_R_TYPE (rel->r_info))
2449 case R_SH_GOTPLT_LOW16:
2450 case R_SH_GOTPLT_MEDLOW16:
2451 case R_SH_GOTPLT_MEDHI16:
2452 case R_SH_GOTPLT_HI16:
2453 case R_SH_GOTPLT10BY4:
2454 case R_SH_GOTPLT10BY8:
2455 case R_SH_GOT_LOW16:
2456 case R_SH_GOT_MEDLOW16:
2457 case R_SH_GOT_MEDHI16:
2461 case R_SH_GOTOFF_LOW16:
2462 case R_SH_GOTOFF_MEDLOW16:
2463 case R_SH_GOTOFF_MEDHI16:
2464 case R_SH_GOTOFF_HI16:
2465 case R_SH_GOTPC_LOW16:
2466 case R_SH_GOTPC_MEDLOW16:
2467 case R_SH_GOTPC_MEDHI16:
2468 case R_SH_GOTPC_HI16:
2469 elf_hash_table (info)->dynobj = dynobj = abfd;
2470 if (! _bfd_elf_create_got_section (dynobj, info))
2479 switch (ELF64_R_TYPE (rel->r_info))
2481 /* This relocation describes the C++ object vtable hierarchy.
2482 Reconstruct it for later use during GC. */
2483 case R_SH_GNU_VTINHERIT:
2484 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2488 /* This relocation describes which C++ vtable entries are actually
2489 used. Record for later use during GC. */
2490 case R_SH_GNU_VTENTRY:
2491 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2496 case R_SH_GOT_LOW16:
2497 case R_SH_GOT_MEDLOW16:
2498 case R_SH_GOT_MEDHI16:
2502 /* This symbol requires a global offset table entry. */
2506 sgot = bfd_get_section_by_name (dynobj, ".got");
2507 BFD_ASSERT (sgot != NULL);
2511 && (h != NULL || info->shared))
2513 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2514 if (srelgot == NULL)
2516 srelgot = bfd_make_section_with_flags (dynobj,
2522 | SEC_LINKER_CREATED
2525 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2532 if (h->type == STT_DATALABEL)
2534 struct elf_sh64_link_hash_entry *hsh;
2536 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2537 hsh = (struct elf_sh64_link_hash_entry *)h;
2538 if (hsh->datalabel_got_offset != (bfd_vma) -1)
2541 hsh->datalabel_got_offset = sgot->size;
2545 if (h->got.offset != (bfd_vma) -1)
2547 /* We have already allocated space in the .got. */
2550 h->got.offset = sgot->size;
2553 /* Make sure this symbol is output as a dynamic symbol. */
2554 if (h->dynindx == -1)
2556 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2560 srelgot->size += sizeof (Elf64_External_Rela);
2564 /* This is a global offset table entry for a local
2566 if (local_got_offsets == NULL)
2569 register unsigned int i;
2571 size = symtab_hdr->sh_info * sizeof (bfd_vma);
2572 /* Reserve space for both the datalabel and
2573 codelabel local GOT offsets. */
2575 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
2576 if (local_got_offsets == NULL)
2578 elf_local_got_offsets (abfd) = local_got_offsets;
2579 for (i = 0; i < symtab_hdr->sh_info; i++)
2580 local_got_offsets[i] = (bfd_vma) -1;
2581 for (; i < 2 * symtab_hdr->sh_info; i++)
2582 local_got_offsets[i] = (bfd_vma) -1;
2584 if ((rel->r_addend & 1) != 0)
2586 if (local_got_offsets[symtab_hdr->sh_info
2587 + r_symndx] != (bfd_vma) -1)
2589 /* We have already allocated space in the .got. */
2592 local_got_offsets[symtab_hdr->sh_info
2593 + r_symndx] = sgot->size;
2597 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
2599 /* We have already allocated space in the .got. */
2602 local_got_offsets[r_symndx] = sgot->size;
2607 /* If we are generating a shared object, we need to
2608 output a R_SH_RELATIVE reloc so that the dynamic
2609 linker can adjust this GOT entry. */
2610 srelgot->size += sizeof (Elf64_External_Rela);
2618 case R_SH_GOTPLT_LOW16:
2619 case R_SH_GOTPLT_MEDLOW16:
2620 case R_SH_GOTPLT_MEDHI16:
2621 case R_SH_GOTPLT_HI16:
2622 case R_SH_GOTPLT10BY4:
2623 case R_SH_GOTPLT10BY8:
2624 /* If this is a local symbol, we resolve it directly without
2625 creating a procedure linkage table entry. */
2628 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2629 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
2633 || h->got.offset != (bfd_vma) -1)
2636 /* Make sure this symbol is output as a dynamic symbol. */
2637 if (h->dynindx == -1)
2639 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2647 case R_SH_PLT_LOW16:
2648 case R_SH_PLT_MEDLOW16:
2649 case R_SH_PLT_MEDHI16:
2651 /* This symbol requires a procedure linkage table entry. We
2652 actually build the entry in adjust_dynamic_symbol,
2653 because this might be a case of linking PIC code which is
2654 never referenced by a dynamic object, in which case we
2655 don't need to generate a procedure linkage table entry
2658 /* If this is a local symbol, we resolve it directly without
2659 creating a procedure linkage table entry. */
2663 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2664 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2676 /* If we are creating a shared library, and this is a reloc
2677 against a global symbol, or a non PC relative reloc
2678 against a local symbol, then we need to copy the reloc
2679 into the shared library. However, if we are linking with
2680 -Bsymbolic, we do not need to copy a reloc against a
2681 global symbol which is defined in an object we are
2682 including in the link (i.e., DEF_REGULAR is set). At
2683 this point we have not seen all the input files, so it is
2684 possible that DEF_REGULAR is not set now but will be set
2685 later (it is never cleared). We account for that
2686 possibility below by storing information in the
2687 pcrel_relocs_copied field of the hash table entry. */
2689 && (sec->flags & SEC_ALLOC) != 0
2690 && (ELF32_R_TYPE (rel->r_info) != R_SH_64_PCREL
2692 && (! info->symbolic
2693 || !h->def_regular))))
2695 /* When creating a shared object, we must copy these
2696 reloc types into the output file. We create a reloc
2697 section in dynobj and make room for this reloc. */
2702 name = (bfd_elf_string_from_elf_section
2704 elf_elfheader (abfd)->e_shstrndx,
2705 elf_section_data (sec)->rel_hdr.sh_name));
2709 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
2710 && strcmp (bfd_get_section_name (abfd, sec),
2713 sreloc = bfd_get_section_by_name (dynobj, name);
2718 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2719 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2720 if ((sec->flags & SEC_ALLOC) != 0)
2721 flags |= SEC_ALLOC | SEC_LOAD;
2722 sreloc = bfd_make_section_with_flags (dynobj,
2726 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
2731 sreloc->size += sizeof (Elf64_External_Rela);
2733 /* If we are linking with -Bsymbolic, and this is a
2734 global symbol, we count the number of PC relative
2735 relocations we have entered for this symbol, so that
2736 we can discard them again if the symbol is later
2737 defined by a regular object. Note that this function
2738 is only called if we are using an elf_sh linker
2739 hash table, which means that h is really a pointer to
2740 an elf_sh_link_hash_entry. */
2741 if (h != NULL && info->symbolic
2742 && ELF64_R_TYPE (rel->r_info) == R_SH_64_PCREL)
2744 struct elf_sh64_link_hash_entry *eh;
2745 struct elf_sh64_pcrel_relocs_copied *p;
2747 eh = (struct elf_sh64_link_hash_entry *) h;
2749 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
2750 if (p->section == sreloc)
2755 p = ((struct elf_sh64_pcrel_relocs_copied *)
2756 bfd_alloc (dynobj, sizeof *p));
2759 p->next = eh->pcrel_relocs_copied;
2760 eh->pcrel_relocs_copied = p;
2761 p->section = sreloc;
2777 sh64_elf64_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
2779 if (ELF_ST_TYPE (elf_sym->st_info) == STT_DATALABEL)
2780 return STT_DATALABEL;
2785 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2786 Either file can presumably exist without the other, but do not differ
2787 in elf-size-ness. How to share?
2789 Hook called by the linker routine which adds symbols from an object
2790 file. We must make indirect symbols for undefined symbols marked with
2791 STT_DATALABEL, so relocations passing them will pick up that attribute
2792 and neutralize STO_SH5_ISA32 found on the symbol definition.
2794 There is a problem, though: We want to fill in the hash-table entry for
2795 this symbol and signal to the caller that no further processing is
2796 needed. But we don't have the index for this hash-table entry. We
2797 rely here on that the current entry is the first hash-entry with NULL,
2798 which seems brittle. Also, iterating over the hash-table to find that
2799 entry is a linear operation on the number of symbols in this input
2800 file, and this function should take constant time, so that's not good
2801 too. Only comfort is that DataLabel references should only be found in
2802 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2803 into adding an option to elf_add_symbol_hook (preferably) for the index
2804 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2808 sh64_elf64_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
2809 Elf_Internal_Sym *sym, const char **namep,
2810 flagword *flagsp ATTRIBUTE_UNUSED,
2811 asection **secp, bfd_vma *valp)
2813 /* We want to do this for relocatable as well as final linking. */
2814 if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL
2815 && is_elf_hash_table (info->hash))
2817 struct elf_link_hash_entry *h;
2819 /* For relocatable links, we register the DataLabel sym in its own
2820 right, and tweak the name when it's output. Otherwise, we make
2821 an indirect symbol of it. */
2823 = info->relocatable || info->emitrelocations
2824 ? BSF_GLOBAL : BSF_GLOBAL | BSF_INDIRECT;
2827 = bfd_malloc (strlen (*namep) + sizeof (DATALABEL_SUFFIX));
2828 struct elf_link_hash_entry ** sym_hash = elf_sym_hashes (abfd);
2830 BFD_ASSERT (sym_hash != NULL);
2832 /* Allocation may fail. */
2833 if (dl_name == NULL)
2836 strcpy (dl_name, *namep);
2837 strcat (dl_name, DATALABEL_SUFFIX);
2839 h = (struct elf_link_hash_entry *)
2840 bfd_link_hash_lookup (info->hash, dl_name, FALSE, FALSE, FALSE);
2844 /* No previous datalabel symbol. Make one. */
2845 struct bfd_link_hash_entry *bh = NULL;
2846 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2848 if (! _bfd_generic_link_add_one_symbol (info, abfd, dl_name,
2849 flags, *secp, *valp,
2857 h = (struct elf_link_hash_entry *) bh;
2859 h->type = STT_DATALABEL;
2862 /* If a new symbol was created, it holds the allocated name.
2863 Otherwise, we don't need it anymore and should deallocate it. */
2866 if (h->type != STT_DATALABEL
2867 || ((info->relocatable || info->emitrelocations)
2868 && h->root.type != bfd_link_hash_undefined)
2869 || (! info->relocatable && !info->emitrelocations
2870 && h->root.type != bfd_link_hash_indirect))
2872 /* Make sure we don't get confused on invalid input. */
2873 (*_bfd_error_handler)
2874 (_("%s: encountered datalabel symbol in input"),
2875 bfd_get_filename (abfd));
2876 bfd_set_error (bfd_error_bad_value);
2880 /* Now find the hash-table slot for this entry and fill it in. */
2881 while (*sym_hash != NULL)
2885 /* Signal to caller to skip this symbol - we've handled it. */
2892 /* This hook function is called before the linker writes out a global
2893 symbol. For relocatable links, DataLabel symbols will be present in
2894 linker output. We cut off the special suffix on those symbols, so the
2895 right name appears in the output.
2897 When linking and emitting relocations, there can appear global symbols
2898 that are not referenced by relocs, but rather only implicitly through
2899 DataLabel references, a relation that is not visible to the linker.
2900 Since no stripping of global symbols in done when doing such linking,
2901 we don't need to look up and make sure to emit the main symbol for each
2902 DataLabel symbol. */
2905 sh64_elf64_link_output_symbol_hook (struct bfd_link_info *info,
2907 Elf_Internal_Sym *sym,
2908 asection *input_sec ATTRIBUTE_UNUSED,
2909 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2911 char *name = (char *) cname;
2913 if (info->relocatable || info->emitrelocations)
2915 if (ELF_ST_TYPE (sym->st_info) == STT_DATALABEL)
2916 name[strlen (name) - strlen (DATALABEL_SUFFIX)] = 0;
2922 /* Set bit 0 on the entry address; it always points to SHmedia code. This
2923 is mostly for symmetry with the 32-bit format, where code can be
2924 SHcompact and we need to make a distinction to make sure execution
2925 starts in the right ISA mode. It is also convenient for a loader,
2926 which would otherwise have to set this bit when loading a TR register
2927 before jumping to the program entry. */
2930 sh64_elf64_final_write_processing (bfd *abfd,
2931 bfd_boolean linker ATTRIBUTE_UNUSED)
2933 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
2934 numerically, but we currently lack the infrastructure to recognize
2935 that: The entry symbol, and info whether it is numeric or a symbol
2936 name is kept private in the linker. */
2937 if (elf_elfheader (abfd)->e_type == ET_EXEC)
2938 elf_elfheader (abfd)->e_entry |= 1;
2941 /* First entry in an absolute procedure linkage table look like this. */
2943 static const bfd_byte elf_sh64_plt0_entry_be[PLT_ENTRY_SIZE] =
2945 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
2946 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
2947 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
2948 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2949 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
2950 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2951 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
2952 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2953 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2954 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2955 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2956 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2957 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2958 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2959 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2960 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2963 static const bfd_byte elf_sh64_plt0_entry_le[PLT_ENTRY_SIZE] =
2965 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
2966 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
2967 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
2968 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2969 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
2970 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2971 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
2972 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2973 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2974 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2975 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2976 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2977 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2978 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2979 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2980 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2983 /* Sebsequent entries in an absolute procedure linkage table look like
2986 static const bfd_byte elf_sh64_plt_entry_be[PLT_ENTRY_SIZE] =
2988 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
2989 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
2990 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
2991 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
2992 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
2993 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2994 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2995 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2996 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */
2997 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
2998 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
2999 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3000 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3001 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3002 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3003 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3006 static const bfd_byte elf_sh64_plt_entry_le[PLT_ENTRY_SIZE] =
3008 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3009 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3010 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3011 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3012 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
3013 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3014 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3015 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3016 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */
3017 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
3018 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
3019 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3020 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3021 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3022 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3023 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3026 /* Entries in a PIC procedure linkage table look like this. */
3028 static const bfd_byte elf_sh64_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3030 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3031 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3032 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
3033 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3034 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3035 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3036 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3037 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3038 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3039 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */
3040 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3041 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3042 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3043 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3044 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3045 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3048 static const bfd_byte elf_sh64_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3050 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3051 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3052 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3053 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3054 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3055 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3056 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3057 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3058 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3059 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */
3060 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3061 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3062 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3063 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3064 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3065 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3068 static const bfd_byte *elf_sh64_plt0_entry;
3069 static const bfd_byte *elf_sh64_plt_entry;
3070 static const bfd_byte *elf_sh64_pic_plt_entry;
3072 /* Create an entry in an sh ELF linker hash table. */
3074 static struct bfd_hash_entry *
3075 sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry,
3076 struct bfd_hash_table *table,
3079 struct elf_sh64_link_hash_entry *ret =
3080 (struct elf_sh64_link_hash_entry *) entry;
3082 /* Allocate the structure if it has not already been allocated by a
3084 if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3085 ret = ((struct elf_sh64_link_hash_entry *)
3086 bfd_hash_allocate (table,
3087 sizeof (struct elf_sh64_link_hash_entry)));
3088 if (ret == (struct elf_sh64_link_hash_entry *) NULL)
3089 return (struct bfd_hash_entry *) ret;
3091 /* Call the allocation method of the superclass. */
3092 ret = ((struct elf_sh64_link_hash_entry *)
3093 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3095 if (ret != (struct elf_sh64_link_hash_entry *) NULL)
3097 ret->pcrel_relocs_copied = NULL;
3098 ret->datalabel_got_offset = (bfd_vma) -1;
3101 return (struct bfd_hash_entry *) ret;
3104 /* Create an sh64 ELF linker hash table. */
3106 static struct bfd_link_hash_table *
3107 sh64_elf64_link_hash_table_create (bfd *abfd)
3109 struct elf_sh64_link_hash_table *ret;
3111 ret = ((struct elf_sh64_link_hash_table *)
3112 bfd_malloc (sizeof (struct elf_sh64_link_hash_table)));
3113 if (ret == (struct elf_sh64_link_hash_table *) NULL)
3116 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
3117 sh64_elf64_link_hash_newfunc,
3118 sizeof (struct elf_sh64_link_hash_entry)))
3124 return &ret->root.root;
3128 movi_shori_putval (bfd *output_bfd, unsigned long value, bfd_byte *addr)
3130 bfd_put_32 (output_bfd,
3131 bfd_get_32 (output_bfd, addr)
3132 | ((value >> 6) & 0x3fffc00),
3134 bfd_put_32 (output_bfd,
3135 bfd_get_32 (output_bfd, addr + 4)
3136 | ((value << 10) & 0x3fffc00),
3141 movi_3shori_putval (bfd *output_bfd, bfd_vma value, bfd_byte *addr)
3143 bfd_put_32 (output_bfd,
3144 bfd_get_32 (output_bfd, addr)
3145 | ((value >> 38) & 0x3fffc00),
3147 bfd_put_32 (output_bfd,
3148 bfd_get_32 (output_bfd, addr + 4)
3149 | ((value >> 22) & 0x3fffc00),
3151 bfd_put_32 (output_bfd,
3152 bfd_get_32 (output_bfd, addr + 8)
3153 | ((value >> 6) & 0x3fffc00),
3155 bfd_put_32 (output_bfd,
3156 bfd_get_32 (output_bfd, addr + 12)
3157 | ((value << 10) & 0x3fffc00),
3161 /* Create dynamic sections when linking against a dynamic object. */
3164 sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3166 flagword flags, pltflags;
3167 register asection *s;
3168 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3171 switch (bed->s->arch_size)
3182 bfd_set_error (bfd_error_bad_value);
3186 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3187 .rel[a].bss sections. */
3189 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3190 | SEC_LINKER_CREATED);
3193 pltflags |= SEC_CODE;
3194 if (bed->plt_not_loaded)
3195 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3196 if (bed->plt_readonly)
3197 pltflags |= SEC_READONLY;
3199 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
3201 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3204 if (bed->want_plt_sym)
3206 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3208 struct elf_link_hash_entry *h;
3209 struct bfd_link_hash_entry *bh = NULL;
3211 if (! (_bfd_generic_link_add_one_symbol
3212 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3213 (bfd_vma) 0, (const char *) NULL, FALSE, bed->collect, &bh)))
3216 h = (struct elf_link_hash_entry *) bh;
3218 h->type = STT_OBJECT;
3219 elf_hash_table (info)->hplt = h;
3222 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3226 s = bfd_make_section_with_flags (abfd,
3227 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt",
3228 flags | SEC_READONLY);
3230 || ! bfd_set_section_alignment (abfd, s, ptralign))
3233 if (! _bfd_elf_create_got_section (abfd, info))
3237 const char *secname;
3242 for (sec = abfd->sections; sec; sec = sec->next)
3244 secflags = bfd_get_section_flags (abfd, sec);
3245 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3246 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3248 secname = bfd_get_section_name (abfd, sec);
3249 relname = (char *) bfd_malloc (strlen (secname) + 6);
3250 strcpy (relname, ".rela");
3251 strcat (relname, secname);
3252 s = bfd_make_section_with_flags (abfd, relname,
3253 flags | SEC_READONLY);
3255 || ! bfd_set_section_alignment (abfd, s, ptralign))
3260 if (bed->want_dynbss)
3262 /* The .dynbss section is a place to put symbols which are defined
3263 by dynamic objects, are referenced by regular objects, and are
3264 not functions. We must allocate space for them in the process
3265 image and use a R_*_COPY reloc to tell the dynamic linker to
3266 initialize them at run time. The linker script puts the .dynbss
3267 section into the .bss section of the final image. */
3268 s = bfd_make_section_with_flags (abfd, ".dynbss",
3269 SEC_ALLOC | SEC_LINKER_CREATED);
3273 /* The .rel[a].bss section holds copy relocs. This section is not
3274 normally needed. We need to create it here, though, so that the
3275 linker will map it to an output section. We can't just create it
3276 only if we need it, because we will not know whether we need it
3277 until we have seen all the input files, and the first time the
3278 main linker code calls BFD after examining all the input files
3279 (size_dynamic_sections) the input sections have already been
3280 mapped to the output sections. If the section turns out not to
3281 be needed, we can discard it later. We will never need this
3282 section when generating a shared object, since they do not use
3286 s = bfd_make_section_with_flags (abfd,
3287 (bed->default_use_rela_p
3288 ? ".rela.bss" : ".rel.bss"),
3289 flags | SEC_READONLY);
3291 || ! bfd_set_section_alignment (abfd, s, ptralign))
3299 /* Adjust a symbol defined by a dynamic object and referenced by a
3300 regular object. The current definition is in some section of the
3301 dynamic object, but we're not including those sections. We have to
3302 change the definition to something the rest of the link can
3306 sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info,
3307 struct elf_link_hash_entry *h)
3311 unsigned int power_of_two;
3313 dynobj = elf_hash_table (info)->dynobj;
3315 /* Make sure we know what is going on here. */
3316 BFD_ASSERT (dynobj != NULL
3318 || h->u.weakdef != NULL
3321 && !h->def_regular)));
3323 /* If this is a function, put it in the procedure linkage table. We
3324 will fill in the contents of the procedure linkage table later,
3325 when we know the address of the .got section. */
3326 if (h->type == STT_FUNC
3333 /* This case can occur if we saw a PLT reloc in an input
3334 file, but the symbol was never referred to by a dynamic
3335 object. In such a case, we don't actually need to build
3336 a procedure linkage table, and we can just do a REL64
3338 BFD_ASSERT (h->needs_plt);
3342 /* Make sure this symbol is output as a dynamic symbol. */
3343 if (h->dynindx == -1)
3345 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3349 s = bfd_get_section_by_name (dynobj, ".plt");
3350 BFD_ASSERT (s != NULL);
3352 /* If this is the first .plt entry, make room for the special
3355 s->size += PLT_ENTRY_SIZE;
3357 /* If this symbol is not defined in a regular file, and we are
3358 not generating a shared library, then set the symbol to this
3359 location in the .plt. This is required to make function
3360 pointers compare as equal between the normal executable and
3361 the shared library. */
3365 h->root.u.def.section = s;
3366 h->root.u.def.value = s->size;
3369 h->plt.offset = s->size;
3371 /* Make room for this entry. */
3372 s->size += elf_sh64_sizeof_plt (info);
3374 /* We also need to make an entry in the .got.plt section, which
3375 will be placed in the .got section by the linker script. */
3377 s = bfd_get_section_by_name (dynobj, ".got.plt");
3378 BFD_ASSERT (s != NULL);
3381 /* We also need to make an entry in the .rela.plt section. */
3383 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3384 BFD_ASSERT (s != NULL);
3385 s->size += sizeof (Elf64_External_Rela);
3390 /* If this is a weak symbol, and there is a real definition, the
3391 processor independent code will have arranged for us to see the
3392 real definition first, and we can just use the same value. */
3393 if (h->u.weakdef != NULL)
3395 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3396 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3397 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3398 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3402 /* This is a reference to a symbol defined by a dynamic object which
3403 is not a function. */
3405 /* If we are creating a shared library, we must presume that the
3406 only references to the symbol are via the global offset table.
3407 For such cases we need not do anything here; the relocations will
3408 be handled correctly by relocate_section. */
3412 /* If there are no references to this symbol that do not use the
3413 GOT, we don't need to generate a copy reloc. */
3414 if (!h->non_got_ref)
3419 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
3420 h->root.root.string);
3424 /* We must allocate the symbol in our .dynbss section, which will
3425 become part of the .bss section of the executable. There will be
3426 an entry for this symbol in the .dynsym section. The dynamic
3427 object will contain position independent code, so all references
3428 from the dynamic object to this symbol will go through the global
3429 offset table. The dynamic linker will use the .dynsym entry to
3430 determine the address it must put in the global offset table, so
3431 both the dynamic object and the regular object will refer to the
3432 same memory location for the variable. */
3434 s = bfd_get_section_by_name (dynobj, ".dynbss");
3435 BFD_ASSERT (s != NULL);
3437 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3438 copy the initial value out of the dynamic object and into the
3439 runtime process image. We need to remember the offset into the
3440 .rela.bss section we are going to use. */
3441 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3445 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
3446 BFD_ASSERT (srel != NULL);
3447 srel->size += sizeof (Elf64_External_Rela);
3451 /* We need to figure out the alignment required for this symbol. I
3452 have no idea how ELF linkers handle this. */
3453 power_of_two = bfd_log2 (h->size);
3454 if (power_of_two > 3)
3457 /* Apply the required alignment. */
3458 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
3459 if (power_of_two > bfd_get_section_alignment (dynobj, s))
3461 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
3465 /* Define the symbol as being at this point in the section. */
3466 h->root.u.def.section = s;
3467 h->root.u.def.value = s->size;
3469 /* Increment the section size to make room for the symbol. */
3475 /* This function is called via sh_elf_link_hash_traverse if we are
3476 creating a shared object with -Bsymbolic. It discards the space
3477 allocated to copy PC relative relocs against symbols which are
3478 defined in regular objects. We allocated space for them in the
3479 check_relocs routine, but we won't fill them in in the
3480 relocate_section routine. */
3483 sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry *h,
3484 void *ignore ATTRIBUTE_UNUSED)
3486 struct elf_sh64_pcrel_relocs_copied *s;
3488 if (h->root.root.type == bfd_link_hash_warning)
3489 h = (struct elf_sh64_link_hash_entry *) h->root.root.u.i.link;
3491 /* We only discard relocs for symbols defined in a regular object. */
3492 if (!h->root.def_regular)
3495 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3496 s->section->size -= s->count * sizeof (Elf64_External_Rela);
3501 /* Set the sizes of the dynamic sections. */
3504 sh64_elf64_size_dynamic_sections (bfd *output_bfd,
3505 struct bfd_link_info *info)
3511 bfd_boolean reltext;
3513 dynobj = elf_hash_table (info)->dynobj;
3514 BFD_ASSERT (dynobj != NULL);
3516 if (elf_hash_table (info)->dynamic_sections_created)
3518 /* Set the contents of the .interp section to the interpreter. */
3519 if (info->executable)
3521 s = bfd_get_section_by_name (dynobj, ".interp");
3522 BFD_ASSERT (s != NULL);
3523 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3524 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3529 /* We may have created entries in the .rela.got section.
3530 However, if we are not creating the dynamic sections, we will
3531 not actually use these entries. Reset the size of .rela.got,
3532 which will cause it to get stripped from the output file
3534 s = bfd_get_section_by_name (dynobj, ".rela.got");
3539 /* If this is a -Bsymbolic shared link, then we need to discard all
3540 PC relative relocs against symbols defined in a regular object.
3541 We allocated space for them in the check_relocs routine, but we
3542 will not fill them in in the relocate_section routine. */
3543 if (info->shared && info->symbolic)
3544 sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info),
3545 sh64_elf64_discard_copies, NULL);
3547 /* The check_relocs and adjust_dynamic_symbol entry points have
3548 determined the sizes of the various dynamic sections. Allocate
3553 for (s = dynobj->sections; s != NULL; s = s->next)
3557 if ((s->flags & SEC_LINKER_CREATED) == 0)
3560 /* It's OK to base decisions on the section name, because none
3561 of the dynobj section names depend upon the input files. */
3562 name = bfd_get_section_name (dynobj, s);
3564 if (strcmp (name, ".plt") == 0)
3566 /* Remember whether there is a PLT. */
3569 else if (CONST_STRNEQ (name, ".rela"))
3575 /* Remember whether there are any reloc sections other
3577 if (strcmp (name, ".rela.plt") != 0)
3579 const char *outname;
3583 /* If this relocation section applies to a read only
3584 section, then we probably need a DT_TEXTREL
3585 entry. The entries in the .rela.plt section
3586 really apply to the .got section, which we
3587 created ourselves and so know is not readonly. */
3588 outname = bfd_get_section_name (output_bfd,
3590 target = bfd_get_section_by_name (output_bfd, outname + 5);
3592 && (target->flags & SEC_READONLY) != 0
3593 && (target->flags & SEC_ALLOC) != 0)
3597 /* We use the reloc_count field as a counter if we need
3598 to copy relocs into the output file. */
3602 else if (! CONST_STRNEQ (name, ".got")
3603 && strcmp (name, ".dynbss") != 0)
3605 /* It's not one of our sections, so don't allocate space. */
3611 /* If we don't need this section, strip it from the
3612 output file. This is mostly to handle .rela.bss and
3613 .rela.plt. We must create both sections in
3614 create_dynamic_sections, because they must be created
3615 before the linker maps input sections to output
3616 sections. The linker does that before
3617 adjust_dynamic_symbol is called, and it is that
3618 function which decides whether anything needs to go
3619 into these sections. */
3620 s->flags |= SEC_EXCLUDE;
3624 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3627 /* Allocate memory for the section contents. */
3628 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3629 if (s->contents == NULL)
3633 if (elf_hash_table (info)->dynamic_sections_created)
3635 /* Add some entries to the .dynamic section. We fill in the
3636 values later, in sh64_elf64_finish_dynamic_sections, but we
3637 must add the entries now so that we get the correct size for
3638 the .dynamic section. The DT_DEBUG entry is filled in by the
3639 dynamic linker and used by the debugger. */
3640 if (info->executable)
3642 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
3648 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
3649 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3650 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
3651 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
3657 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
3658 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
3659 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
3660 sizeof (Elf64_External_Rela)))
3666 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
3674 /* Finish up dynamic symbol handling. We set the contents of various
3675 dynamic sections here. */
3678 sh64_elf64_finish_dynamic_symbol (bfd *output_bfd,
3679 struct bfd_link_info *info,
3680 struct elf_link_hash_entry *h,
3681 Elf_Internal_Sym *sym)
3685 dynobj = elf_hash_table (info)->dynobj;
3687 if (h->plt.offset != (bfd_vma) -1)
3695 Elf_Internal_Rela rel;
3698 /* This symbol has an entry in the procedure linkage table. Set
3701 BFD_ASSERT (h->dynindx != -1);
3703 splt = bfd_get_section_by_name (dynobj, ".plt");
3704 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3705 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
3706 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
3708 /* Get the index in the procedure linkage table which
3709 corresponds to this symbol. This is the index of this symbol
3710 in all the symbols for which we are making plt entries. The
3711 first entry in the procedure linkage table is reserved. */
3712 plt_index = h->plt.offset / elf_sh64_sizeof_plt (info) - 1;
3714 /* Get the offset into the .got table of the entry that
3715 corresponds to this function. Each .got entry is 8 bytes.
3716 The first three are reserved. */
3717 got_offset = (plt_index + 3) * 8;
3720 got_offset -= GOT_BIAS;
3722 /* Fill in the entry in the procedure linkage table. */
3725 if (elf_sh64_plt_entry == NULL)
3727 elf_sh64_plt_entry = (bfd_big_endian (output_bfd) ?
3728 elf_sh64_plt_entry_be : elf_sh64_plt_entry_le);
3730 memcpy (splt->contents + h->plt.offset, elf_sh64_plt_entry,
3731 elf_sh64_sizeof_plt (info));
3732 movi_3shori_putval (output_bfd,
3733 (sgot->output_section->vma
3734 + sgot->output_offset
3736 (splt->contents + h->plt.offset
3737 + elf_sh64_plt_symbol_offset (info)));
3739 /* Set bottom bit because its for a branch to SHmedia */
3740 movi_shori_putval (output_bfd,
3742 + elf_sh64_plt_plt0_offset (info) + 8)
3744 (splt->contents + h->plt.offset
3745 + elf_sh64_plt_plt0_offset (info)));
3749 if (elf_sh64_pic_plt_entry == NULL)
3751 elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3752 elf_sh64_pic_plt_entry_be :
3753 elf_sh64_pic_plt_entry_le);
3755 memcpy (splt->contents + h->plt.offset, elf_sh64_pic_plt_entry,
3756 elf_sh64_sizeof_plt (info));
3757 movi_shori_putval (output_bfd, got_offset,
3758 (splt->contents + h->plt.offset
3759 + elf_sh64_plt_symbol_offset (info)));
3763 got_offset += GOT_BIAS;
3765 movi_shori_putval (output_bfd,
3766 plt_index * sizeof (Elf64_External_Rela),
3767 (splt->contents + h->plt.offset
3768 + elf_sh64_plt_reloc_offset (info)));
3770 /* Fill in the entry in the global offset table. */
3771 bfd_put_64 (output_bfd,
3772 (splt->output_section->vma
3773 + splt->output_offset
3775 + elf_sh64_plt_temp_offset (info)),
3776 sgot->contents + got_offset);
3778 /* Fill in the entry in the .rela.plt section. */
3779 rel.r_offset = (sgot->output_section->vma
3780 + sgot->output_offset
3782 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_JMP_SLOT64);
3784 rel.r_addend = GOT_BIAS;
3785 loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
3786 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3788 if (!h->def_regular)
3790 /* Mark the symbol as undefined, rather than as defined in
3791 the .plt section. Leave the value alone. */
3792 sym->st_shndx = SHN_UNDEF;
3796 if (h->got.offset != (bfd_vma) -1)
3800 Elf_Internal_Rela rel;
3803 /* This symbol has an entry in the global offset table. Set it
3806 sgot = bfd_get_section_by_name (dynobj, ".got");
3807 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3808 BFD_ASSERT (sgot != NULL && srel != NULL);
3810 rel.r_offset = (sgot->output_section->vma
3811 + sgot->output_offset
3812 + (h->got.offset &~ 1));
3814 /* If this is a -Bsymbolic link, and the symbol is defined
3815 locally, we just want to emit a RELATIVE reloc. Likewise if
3816 the symbol was forced to be local because of a version file.
3817 The entry in the global offset table will already have been
3818 initialized in the relocate_section function. */
3820 && (info->symbolic || h->dynindx == -1)
3823 rel.r_info = ELF64_R_INFO (0, R_SH_RELATIVE64);
3824 rel.r_addend = (h->root.u.def.value
3825 + h->root.u.def.section->output_section->vma
3826 + h->root.u.def.section->output_offset);
3830 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3831 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_GLOB_DAT64);
3835 loc = srel->contents;
3836 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
3837 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3843 Elf_Internal_Rela rel;
3846 /* This symbol needs a copy reloc. Set it up. */
3848 BFD_ASSERT (h->dynindx != -1
3849 && (h->root.type == bfd_link_hash_defined
3850 || h->root.type == bfd_link_hash_defweak));
3852 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3854 BFD_ASSERT (s != NULL);
3856 rel.r_offset = (h->root.u.def.value
3857 + h->root.u.def.section->output_section->vma
3858 + h->root.u.def.section->output_offset);
3859 rel.r_info = ELF64_R_INFO (h->dynindx, R_SH_COPY64);
3862 loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
3863 bfd_elf64_swap_reloca_out (output_bfd, &rel, loc);
3866 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3867 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3868 || h == elf_hash_table (info)->hgot)
3869 sym->st_shndx = SHN_ABS;
3874 /* Finish up the dynamic sections. */
3877 sh64_elf64_finish_dynamic_sections (bfd *output_bfd,
3878 struct bfd_link_info *info)
3884 dynobj = elf_hash_table (info)->dynobj;
3886 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3887 BFD_ASSERT (sgot != NULL);
3888 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3890 if (elf_hash_table (info)->dynamic_sections_created)
3893 Elf64_External_Dyn *dyncon, *dynconend;
3895 BFD_ASSERT (sdyn != NULL);
3897 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3898 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3899 for (; dyncon < dynconend; dyncon++)
3901 Elf_Internal_Dyn dyn;
3904 struct elf_link_hash_entry *h;
3906 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3914 name = info->init_function;
3918 name = info->fini_function;
3920 if (dyn.d_un.d_val != 0)
3922 h = elf_link_hash_lookup (elf_hash_table (info), name,
3923 FALSE, FALSE, TRUE);
3924 if (h != NULL && (h->other & STO_SH5_ISA32))
3926 dyn.d_un.d_val |= 1;
3927 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3939 s = bfd_get_section_by_name (output_bfd, name);
3940 BFD_ASSERT (s != NULL);
3941 dyn.d_un.d_ptr = s->vma;
3942 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3946 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3947 BFD_ASSERT (s != NULL);
3948 dyn.d_un.d_val = s->size;
3949 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3953 /* My reading of the SVR4 ABI indicates that the
3954 procedure linkage table relocs (DT_JMPREL) should be
3955 included in the overall relocs (DT_RELA). This is
3956 what Solaris does. However, UnixWare can not handle
3957 that case. Therefore, we override the DT_RELASZ entry
3958 here to make it not include the JMPREL relocs. Since
3959 the linker script arranges for .rela.plt to follow all
3960 other relocation sections, we don't have to worry
3961 about changing the DT_RELA entry. */
3962 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3964 dyn.d_un.d_val -= s->size;
3965 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3970 /* Fill in the first entry in the procedure linkage table. */
3971 splt = bfd_get_section_by_name (dynobj, ".plt");
3972 if (splt && splt->size > 0)
3976 if (elf_sh64_pic_plt_entry == NULL)
3978 elf_sh64_pic_plt_entry = (bfd_big_endian (output_bfd) ?
3979 elf_sh64_pic_plt_entry_be :
3980 elf_sh64_pic_plt_entry_le);
3982 memcpy (splt->contents, elf_sh64_pic_plt_entry,
3983 elf_sh64_sizeof_plt (info));
3987 if (elf_sh64_plt0_entry == NULL)
3989 elf_sh64_plt0_entry = (bfd_big_endian (output_bfd) ?
3990 elf_sh64_plt0_entry_be :
3991 elf_sh64_plt0_entry_le);
3993 memcpy (splt->contents, elf_sh64_plt0_entry, PLT_ENTRY_SIZE);
3994 movi_3shori_putval (output_bfd,
3995 sgot->output_section->vma
3996 + sgot->output_offset,
3998 + elf_sh64_plt0_gotplt_offset (info));
4001 /* UnixWare sets the entsize of .plt to 8, although that doesn't
4002 really seem like the right value. */
4003 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 8;
4007 /* Fill in the first three entries in the global offset table. */
4011 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
4013 bfd_put_64 (output_bfd,
4014 sdyn->output_section->vma + sdyn->output_offset,
4016 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4017 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + 16);
4020 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8;
4025 /* Merge non visibility st_other attribute when the symbol comes from
4026 a dynamic object. */
4028 sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry *h,
4029 const Elf_Internal_Sym *isym,
4030 bfd_boolean definition,
4031 bfd_boolean dynamic ATTRIBUTE_UNUSED)
4033 if ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) != 0)
4035 unsigned char other;
4037 /* Take the balance of OTHER from the definition. */
4038 other = (definition ? isym->st_other : h->other);
4039 other &= ~ ELF_ST_VISIBILITY (-1);
4040 h->other = other | ELF_ST_VISIBILITY (h->other);
4046 static const struct bfd_elf_special_section sh64_elf64_special_sections[]=
4048 { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS, 0 },
4049 { NULL, 0, 0, 0, 0 }
4052 #define TARGET_BIG_SYM bfd_elf64_sh64_vec
4053 #define TARGET_BIG_NAME "elf64-sh64"
4054 #define TARGET_LITTLE_SYM bfd_elf64_sh64l_vec
4055 #define TARGET_LITTLE_NAME "elf64-sh64l"
4056 #define ELF_ARCH bfd_arch_sh
4057 #define ELF_MACHINE_CODE EM_SH
4058 #define ELF_MAXPAGESIZE 128
4060 #define elf_symbol_leading_char '_'
4062 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
4063 #define elf_info_to_howto sh_elf64_info_to_howto
4065 /* Note: there's no relaxation at present. */
4067 #define elf_backend_relocate_section sh_elf64_relocate_section
4068 #define bfd_elf64_bfd_get_relocated_section_contents \
4069 sh_elf64_get_relocated_section_contents
4070 #define elf_backend_object_p sh_elf64_set_mach_from_flags
4071 #define bfd_elf64_bfd_set_private_flags \
4072 sh_elf64_set_private_flags
4073 #define bfd_elf64_bfd_copy_private_bfd_data \
4074 sh_elf64_copy_private_data
4075 #define bfd_elf64_bfd_merge_private_bfd_data \
4076 sh_elf64_merge_private_data
4077 #define elf_backend_fake_sections sh64_elf64_fake_sections
4079 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
4080 #define elf_backend_check_relocs sh_elf64_check_relocs
4082 #define elf_backend_can_gc_sections 1
4084 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
4086 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
4088 #define elf_backend_link_output_symbol_hook \
4089 sh64_elf64_link_output_symbol_hook
4091 #define elf_backend_merge_symbol_attribute \
4092 sh64_elf64_merge_symbol_attribute
4094 #define elf_backend_final_write_processing \
4095 sh64_elf64_final_write_processing
4097 #define elf_backend_create_dynamic_sections \
4098 sh64_elf64_create_dynamic_sections
4099 #define bfd_elf64_bfd_link_hash_table_create \
4100 sh64_elf64_link_hash_table_create
4101 #define elf_backend_adjust_dynamic_symbol \
4102 sh64_elf64_adjust_dynamic_symbol
4103 #define elf_backend_size_dynamic_sections \
4104 sh64_elf64_size_dynamic_sections
4105 #define elf_backend_omit_section_dynsym \
4106 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4107 #define elf_backend_finish_dynamic_symbol \
4108 sh64_elf64_finish_dynamic_symbol
4109 #define elf_backend_finish_dynamic_sections \
4110 sh64_elf64_finish_dynamic_sections
4111 #define elf_backend_special_sections sh64_elf64_special_sections
4113 #define elf_backend_want_got_plt 1
4114 #define elf_backend_plt_readonly 1
4115 #define elf_backend_want_plt_sym 0
4116 #define elf_backend_got_header_size 24
4118 #include "elf64-target.h"
4120 /* NetBSD support. */
4121 #undef TARGET_BIG_SYM
4122 #define TARGET_BIG_SYM bfd_elf64_sh64nbsd_vec
4123 #undef TARGET_BIG_NAME
4124 #define TARGET_BIG_NAME "elf64-sh64-nbsd"
4125 #undef TARGET_LITTLE_SYM
4126 #define TARGET_LITTLE_SYM bfd_elf64_sh64lnbsd_vec
4127 #undef TARGET_LITTLE_NAME
4128 #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd"
4129 #undef ELF_MAXPAGESIZE
4130 #define ELF_MAXPAGESIZE 0x10000
4131 #undef elf_symbol_leading_char
4132 #define elf_symbol_leading_char 0
4134 #define elf64_bed elf64_sh64_nbsd_bed
4136 #include "elf64-target.h"
4138 /* Linux support. */
4139 #undef TARGET_BIG_SYM
4140 #define TARGET_BIG_SYM bfd_elf64_sh64blin_vec
4141 #undef TARGET_BIG_NAME
4142 #define TARGET_BIG_NAME "elf64-sh64big-linux"
4143 #undef TARGET_LITTLE_SYM
4144 #define TARGET_LITTLE_SYM bfd_elf64_sh64lin_vec
4145 #undef TARGET_LITTLE_NAME
4146 #define TARGET_LITTLE_NAME "elf64-sh64-linux"
4148 #define elf64_bed elf64_sh64_linux_bed
4150 #include "elf64-target.h"