1 /* SuperH SH64-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
31 /* Add a suffix for datalabel indirection symbols. It must not match any
32 other symbols; user symbols with or without version or other
33 decoration. It must only be used internally and not emitted by any
35 #define DATALABEL_SUFFIX " DL"
37 #define GOT_BIAS (-((long)-32768))
39 #define PLT_ENTRY_SIZE 64
41 /* Return size of a PLT entry. */
42 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
44 /* Return offset of the PLT0 address in an absolute PLT entry. */
45 #define elf_sh64_plt_plt0_offset(info) 32
47 /* Return offset of the linker in PLT0 entry. */
48 #define elf_sh64_plt0_gotplt_offset(info) 0
50 /* Return offset of the trampoline in PLT entry */
51 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
53 /* Return offset of the symbol in PLT entry. */
54 #define elf_sh64_plt_symbol_offset(info) 0
56 /* Return offset of the relocation in PLT entry. */
57 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
59 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
61 /* The sh linker needs to keep track of the number of relocs that it
62 decides to copy in check_relocs for each symbol. This is so that
63 it can discard PC relative relocs if it doesn't need them when
64 linking with -Bsymbolic. We store the information in a field
65 extending the regular ELF linker hash table. */
67 /* This structure keeps track of the number of PC relative relocs we
68 have copied for a given symbol. */
70 struct elf_sh64_pcrel_relocs_copied
73 struct elf_sh64_pcrel_relocs_copied
*next
;
74 /* A section in dynobj. */
76 /* Number of relocs copied in this section. */
80 /* sh ELF linker hash entry. */
82 struct elf_sh64_link_hash_entry
84 struct elf_link_hash_entry root
;
86 bfd_vma datalabel_got_offset
;
88 /* Number of PC relative relocs copied for this symbol. */
89 struct elf_sh64_pcrel_relocs_copied
*pcrel_relocs_copied
;
92 /* sh ELF linker hash table. */
94 struct elf_sh64_link_hash_table
96 struct elf_link_hash_table root
;
99 /* Traverse an sh ELF linker hash table. */
101 #define sh64_elf64_link_hash_traverse(table, func, info) \
102 (elf_link_hash_traverse \
104 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
107 /* Get the sh ELF linker hash table from a link_info structure. */
109 #define sh64_elf64_hash_table(p) \
110 ((struct elf_sh64_link_hash_table *) ((p)->hash))
112 static bfd_reloc_status_type sh_elf64_ignore_reloc
113 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
114 static bfd_reloc_status_type sh_elf64_reloc
115 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
117 static reloc_howto_type sh_elf64_howto_table
[] = {
119 HOWTO (R_SH_NONE
, /* type */
121 0, /* size (0 = byte, 1 = short, 2 = long) */
123 FALSE
, /* pc_relative */
125 complain_overflow_dont
, /* complain_on_overflow */
126 sh_elf64_ignore_reloc
, /* special_function */
127 "R_SH_NONE", /* name */
128 FALSE
, /* partial_inplace */
131 FALSE
), /* pcrel_offset */
133 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
134 src_mask to a non-zero value is similar to the COFF toolchain. */
135 HOWTO (R_SH_DIR32
, /* type */
137 2, /* size (0 = byte, 1 = short, 2 = long) */
139 FALSE
, /* pc_relative */
141 complain_overflow_bitfield
, /* complain_on_overflow */
142 sh_elf64_reloc
, /* special_function */
143 "R_SH_DIR32", /* name */
144 TRUE
, /* partial_inplace */
145 0xffffffff, /* src_mask */
146 0xffffffff, /* dst_mask */
147 FALSE
), /* pcrel_offset */
149 /* 32 bit PC relative relocation. */
150 HOWTO (R_SH_REL32
, /* type */
152 2, /* size (0 = byte, 1 = short, 2 = long) */
154 TRUE
, /* pc_relative */
156 complain_overflow_signed
, /* complain_on_overflow */
157 sh_elf64_ignore_reloc
, /* special_function */
158 "R_SH_REL32", /* name */
159 FALSE
, /* partial_inplace */
161 0xffffffff, /* dst_mask */
162 TRUE
), /* pcrel_offset */
164 /* For 32-bit sh, this is R_SH_DIR8WPN. */
167 /* For 32-bit sh, this is R_SH_IND12W. */
170 /* For 32-bit sh, this is R_SH_DIR8WPL. */
173 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
176 /* For 32-bit sh, this is R_SH_DIR8BP. */
179 /* For 32-bit sh, this is R_SH_DIR8W. */
182 /* For 32-bit sh, this is R_SH_DIR8L. */
201 /* The remaining relocs are a GNU extension used for relaxing. The
202 final pass of the linker never needs to do anything with any of
203 these relocs. Any required operations are handled by the
206 /* A 16 bit switch table entry. This is generated for an expression
207 such as ``.word L1 - L2''. The offset holds the difference
208 between the reloc address and L2. */
209 HOWTO (R_SH_SWITCH16
, /* type */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
213 FALSE
, /* pc_relative */
215 complain_overflow_unsigned
, /* complain_on_overflow */
216 sh_elf64_ignore_reloc
, /* special_function */
217 "R_SH_SWITCH16", /* name */
218 FALSE
, /* partial_inplace */
221 TRUE
), /* pcrel_offset */
223 /* A 32 bit switch table entry. This is generated for an expression
224 such as ``.long L1 - L2''. The offset holds the difference
225 between the reloc address and L2. */
226 HOWTO (R_SH_SWITCH32
, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_unsigned
, /* complain_on_overflow */
233 sh_elf64_ignore_reloc
, /* special_function */
234 "R_SH_SWITCH32", /* name */
235 FALSE
, /* partial_inplace */
238 TRUE
), /* pcrel_offset */
240 /* For 32-bit sh, this is R_SH_USES. */
243 /* For 32-bit sh, this is R_SH_COUNT. */
246 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
247 this might be emitted. When linker relaxation is implemented, we
248 might want to use it. */
251 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
252 this might be emitted. When linker relaxation is implemented, we
253 might want to use it. */
256 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
257 this might be emitted. When linker relaxation is implemented, we
258 might want to use it. */
261 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
262 this might be emitted. When linker relaxation is implemented, we
263 might want to use it. */
266 /* An 8 bit switch table entry. This is generated for an expression
267 such as ``.word L1 - L2''. The offset holds the difference
268 between the reloc address and L2. */
269 HOWTO (R_SH_SWITCH8
, /* type */
271 0, /* size (0 = byte, 1 = short, 2 = long) */
273 FALSE
, /* pc_relative */
275 complain_overflow_unsigned
, /* complain_on_overflow */
276 sh_elf64_ignore_reloc
, /* special_function */
277 "R_SH_SWITCH8", /* name */
278 FALSE
, /* partial_inplace */
281 TRUE
), /* pcrel_offset */
283 /* GNU extension to record C++ vtable hierarchy */
284 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
288 FALSE
, /* pc_relative */
290 complain_overflow_dont
, /* complain_on_overflow */
291 NULL
, /* special_function */
292 "R_SH_GNU_VTINHERIT", /* name */
293 FALSE
, /* partial_inplace */
296 FALSE
), /* pcrel_offset */
298 /* GNU extension to record C++ vtable member usage */
299 HOWTO (R_SH_GNU_VTENTRY
, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 FALSE
, /* pc_relative */
305 complain_overflow_dont
, /* complain_on_overflow */
306 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
307 "R_SH_GNU_VTENTRY", /* name */
308 FALSE
, /* partial_inplace */
311 FALSE
), /* pcrel_offset */
313 /* For 32-bit sh, this is R_SH_LOOP_START. */
316 /* For 32-bit sh, this is R_SH_LOOP_END. */
327 /* Used in SHLLI.L and SHLRI.L. */
328 HOWTO (R_SH_DIR5U
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 FALSE
, /* pc_relative */
334 complain_overflow_unsigned
, /* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_SH_DIR5U", /* name */
337 FALSE
, /* partial_inplace */
339 0xfc00, /* dst_mask */
340 FALSE
), /* pcrel_offset */
342 /* Used in SHARI, SHLLI et al. */
343 HOWTO (R_SH_DIR6U
, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 FALSE
, /* pc_relative */
349 complain_overflow_unsigned
, /* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_SH_DIR6U", /* name */
352 FALSE
, /* partial_inplace */
354 0xfc00, /* dst_mask */
355 FALSE
), /* pcrel_offset */
357 /* Used in BxxI, LDHI.L et al. */
358 HOWTO (R_SH_DIR6S
, /* type */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_signed
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_SH_DIR6S", /* name */
367 FALSE
, /* partial_inplace */
369 0xfc00, /* dst_mask */
370 FALSE
), /* pcrel_offset */
372 /* Used in ADDI, ANDI et al. */
373 HOWTO (R_SH_DIR10S
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_signed
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_SH_DIR10S", /* name */
382 FALSE
, /* partial_inplace */
384 0xffc00, /* dst_mask */
385 FALSE
), /* pcrel_offset */
387 /* Used in LD.UW, ST.W et al. */
388 HOWTO (R_SH_DIR10SW
, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE
, /* pc_relative */
394 complain_overflow_signed
, /* complain_on_overflow */
395 bfd_elf_generic_reloc
, /* special_function */
396 "R_SH_DIR10SW", /* name */
397 FALSE
, /* partial_inplace */
399 0xffc00, /* dst_mask */
400 FALSE
), /* pcrel_offset */
402 /* Used in LD.L, FLD.S et al. */
403 HOWTO (R_SH_DIR10SL
, /* type */
405 2, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE
, /* pc_relative */
409 complain_overflow_signed
, /* complain_on_overflow */
410 bfd_elf_generic_reloc
, /* special_function */
411 "R_SH_DIR10SL", /* name */
412 FALSE
, /* partial_inplace */
414 0xffc00, /* dst_mask */
415 FALSE
), /* pcrel_offset */
417 /* Used in FLD.D, FST.P et al. */
418 HOWTO (R_SH_DIR10SQ
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_SH_DIR10SQ", /* name */
427 FALSE
, /* partial_inplace */
429 0xffc00, /* dst_mask */
430 FALSE
), /* pcrel_offset */
541 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
542 any dynamic linking support for 64-bit SH at present. */
554 /* Back to SH5 relocations. */
555 /* Used in MOVI and SHORI (x & 65536). */
556 HOWTO (R_SH_GOT_LOW16
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE
, /* pc_relative */
562 complain_overflow_dont
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_SH_GOT_LOW16", /* name */
565 FALSE
, /* partial_inplace */
567 0x3fffc00, /* dst_mask */
568 FALSE
), /* pcrel_offset */
570 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
571 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 FALSE
, /* pc_relative */
577 complain_overflow_dont
, /* complain_on_overflow */
578 bfd_elf_generic_reloc
, /* special_function */
579 "R_SH_GOT_MEDLOW16", /* name */
580 FALSE
, /* partial_inplace */
582 0x3fffc00, /* dst_mask */
583 FALSE
), /* pcrel_offset */
585 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
586 HOWTO (R_SH_GOT_MEDHI16
, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 FALSE
, /* pc_relative */
592 complain_overflow_dont
, /* complain_on_overflow */
593 bfd_elf_generic_reloc
, /* special_function */
594 "R_SH_GOT_MEDHI16", /* name */
595 FALSE
, /* partial_inplace */
597 0x3fffc00, /* dst_mask */
598 FALSE
), /* pcrel_offset */
600 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
601 HOWTO (R_SH_GOT_HI16
, /* type */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
605 FALSE
, /* pc_relative */
607 complain_overflow_dont
, /* complain_on_overflow */
608 bfd_elf_generic_reloc
, /* special_function */
609 "R_SH_GOT_HI16", /* name */
610 FALSE
, /* partial_inplace */
612 0x3fffc00, /* dst_mask */
613 FALSE
), /* pcrel_offset */
615 /* Used in MOVI and SHORI (x & 65536). */
616 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 FALSE
, /* pc_relative */
622 complain_overflow_dont
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_SH_GOTPLT_LOW16", /* name */
625 FALSE
, /* partial_inplace */
627 0x3fffc00, /* dst_mask */
628 FALSE
), /* pcrel_offset */
630 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
631 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 FALSE
, /* pc_relative */
637 complain_overflow_dont
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_SH_GOTPLT_MEDLOW16", /* name */
640 FALSE
, /* partial_inplace */
642 0x3fffc00, /* dst_mask */
643 FALSE
), /* pcrel_offset */
645 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
646 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 FALSE
, /* pc_relative */
652 complain_overflow_dont
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 "R_SH_GOTPLT_MEDHI16", /* name */
655 FALSE
, /* partial_inplace */
657 0x3fffc00, /* dst_mask */
658 FALSE
), /* pcrel_offset */
660 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
661 HOWTO (R_SH_GOTPLT_HI16
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 FALSE
, /* pc_relative */
667 complain_overflow_dont
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_SH_GOTPLT_HI16", /* name */
670 FALSE
, /* partial_inplace */
672 0x3fffc00, /* dst_mask */
673 FALSE
), /* pcrel_offset */
675 /* Used in MOVI and SHORI (x & 65536). */
676 HOWTO (R_SH_PLT_LOW16
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_SH_PLT_LOW16", /* name */
685 FALSE
, /* partial_inplace */
687 0x3fffc00, /* dst_mask */
688 TRUE
), /* pcrel_offset */
690 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
691 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE
, /* pc_relative */
697 complain_overflow_dont
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 "R_SH_PLT_MEDLOW16", /* name */
700 FALSE
, /* partial_inplace */
702 0x3fffc00, /* dst_mask */
703 TRUE
), /* pcrel_offset */
705 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
706 HOWTO (R_SH_PLT_MEDHI16
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 TRUE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_SH_PLT_MEDHI16", /* name */
715 FALSE
, /* partial_inplace */
717 0x3fffc00, /* dst_mask */
718 TRUE
), /* pcrel_offset */
720 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
721 HOWTO (R_SH_PLT_HI16
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE
, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_SH_PLT_HI16", /* name */
730 FALSE
, /* partial_inplace */
732 0x3fffc00, /* dst_mask */
733 TRUE
), /* pcrel_offset */
735 /* Used in MOVI and SHORI (x & 65536). */
736 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE
, /* pc_relative */
742 complain_overflow_dont
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_SH_GOTOFF_LOW16", /* name */
745 FALSE
, /* partial_inplace */
747 0x3fffc00, /* dst_mask */
748 FALSE
), /* pcrel_offset */
750 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
751 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
753 2, /* size (0 = byte, 1 = short, 2 = long) */
755 FALSE
, /* pc_relative */
757 complain_overflow_dont
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_SH_GOTOFF_MEDLOW16", /* name */
760 FALSE
, /* partial_inplace */
762 0x3fffc00, /* dst_mask */
763 FALSE
), /* pcrel_offset */
765 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
766 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 FALSE
, /* pc_relative */
772 complain_overflow_dont
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* special_function */
774 "R_SH_GOTOFF_MEDHI16", /* name */
775 FALSE
, /* partial_inplace */
777 0x3fffc00, /* dst_mask */
778 FALSE
), /* pcrel_offset */
780 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
781 HOWTO (R_SH_GOTOFF_HI16
, /* type */
783 2, /* size (0 = byte, 1 = short, 2 = long) */
785 FALSE
, /* pc_relative */
787 complain_overflow_dont
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_SH_GOTOFF_HI16", /* name */
790 FALSE
, /* partial_inplace */
792 0x3fffc00, /* dst_mask */
793 FALSE
), /* pcrel_offset */
795 /* Used in MOVI and SHORI (x & 65536). */
796 HOWTO (R_SH_GOTPC_LOW16
, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 TRUE
, /* pc_relative */
802 complain_overflow_dont
, /* complain_on_overflow */
803 bfd_elf_generic_reloc
, /* special_function */
804 "R_SH_GOTPC_LOW16", /* name */
805 FALSE
, /* partial_inplace */
807 0x3fffc00, /* dst_mask */
808 TRUE
), /* pcrel_offset */
810 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
811 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 TRUE
, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_SH_GOTPC_MEDLOW16", /* name */
820 FALSE
, /* partial_inplace */
822 0x3fffc00, /* dst_mask */
823 TRUE
), /* pcrel_offset */
825 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
826 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 TRUE
, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_SH_GOTPC_MEDHI16", /* name */
835 FALSE
, /* partial_inplace */
837 0x3fffc00, /* dst_mask */
838 TRUE
), /* pcrel_offset */
840 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
841 HOWTO (R_SH_GOTPC_HI16
, /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 TRUE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 bfd_elf_generic_reloc
, /* special_function */
849 "R_SH_GOTPC_HI16", /* name */
850 FALSE
, /* partial_inplace */
852 0x3fffc00, /* dst_mask */
853 TRUE
), /* pcrel_offset */
855 /* Used in LD.L, FLD.S et al. */
856 HOWTO (R_SH_GOT10BY4
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_signed
, /* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_SH_GOT10BY4", /* name */
865 FALSE
, /* partial_inplace */
867 0xffc00, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 /* Used in LD.L, FLD.S et al. */
871 HOWTO (R_SH_GOTPLT10BY4
, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE
, /* pc_relative */
877 complain_overflow_signed
, /* complain_on_overflow */
878 bfd_elf_generic_reloc
, /* special_function */
879 "R_SH_GOTPLT10BY4", /* name */
880 FALSE
, /* partial_inplace */
882 0xffc00, /* dst_mask */
883 FALSE
), /* pcrel_offset */
885 /* Used in FLD.D, FST.P et al. */
886 HOWTO (R_SH_GOT10BY8
, /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE
, /* pc_relative */
892 complain_overflow_signed
, /* complain_on_overflow */
893 bfd_elf_generic_reloc
, /* special_function */
894 "R_SH_GOT10BY8", /* name */
895 FALSE
, /* partial_inplace */
897 0xffc00, /* dst_mask */
898 FALSE
), /* pcrel_offset */
900 /* Used in FLD.D, FST.P et al. */
901 HOWTO (R_SH_GOTPLT10BY8
, /* type */
903 2, /* size (0 = byte, 1 = short, 2 = long) */
905 FALSE
, /* pc_relative */
907 complain_overflow_signed
, /* complain_on_overflow */
908 bfd_elf_generic_reloc
, /* special_function */
909 "R_SH_GOTPLT10BY8", /* name */
910 FALSE
, /* partial_inplace */
912 0xffc00, /* dst_mask */
913 FALSE
), /* pcrel_offset */
915 HOWTO (R_SH_COPY64
, /* type */
917 4, /* size (0 = byte, 1 = short, 2 = long) */
919 FALSE
, /* pc_relative */
921 complain_overflow_dont
, /* complain_on_overflow */
922 bfd_elf_generic_reloc
, /* special_function */
923 "R_SH_COPY64", /* name */
924 FALSE
, /* partial_inplace */
926 ((bfd_vma
) 0) - 1, /* dst_mask */
927 FALSE
), /* pcrel_offset */
929 HOWTO (R_SH_GLOB_DAT64
, /* type */
931 4, /* size (0 = byte, 1 = short, 2 = long) */
933 FALSE
, /* pc_relative */
935 complain_overflow_dont
, /* complain_on_overflow */
936 bfd_elf_generic_reloc
, /* special_function */
937 "R_SH_GLOB_DAT64", /* name */
938 FALSE
, /* partial_inplace */
940 ((bfd_vma
) 0) - 1, /* dst_mask */
941 FALSE
), /* pcrel_offset */
943 HOWTO (R_SH_JMP_SLOT64
, /* type */
945 4, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_dont
, /* complain_on_overflow */
950 bfd_elf_generic_reloc
, /* special_function */
951 "R_SH_JMP_SLOT64", /* name */
952 FALSE
, /* partial_inplace */
954 ((bfd_vma
) 0) - 1, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 HOWTO (R_SH_RELATIVE64
, /* type */
959 4, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_dont
, /* complain_on_overflow */
964 bfd_elf_generic_reloc
, /* special_function */
965 "R_SH_RELATIVE64", /* name */
966 FALSE
, /* partial_inplace */
968 ((bfd_vma
) 0) - 1, /* dst_mask */
969 FALSE
), /* pcrel_offset */
1017 /* Relocations for SHmedia code. None of these are partial_inplace or
1018 use the field being relocated. */
1020 /* The assembler will generate this reloc before a block of SHmedia
1021 instructions. A section should be processed as assuming it contains
1022 data, unless this reloc is seen. Note that a block of SHcompact
1023 instructions are instead preceded by R_SH_CODE.
1024 This is currently not implemented, but should be used for SHmedia
1025 linker relaxation. */
1026 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_unsigned
, /* complain_on_overflow */
1033 sh_elf64_ignore_reloc
, /* special_function */
1034 "R_SH_SHMEDIA_CODE", /* name */
1035 FALSE
, /* partial_inplace */
1038 FALSE
), /* pcrel_offset */
1040 /* The assembler will generate this reloc at a PTA or PTB instruction,
1041 and the linker checks the right type of target, or changes a PTA to a
1042 PTB, if the original insn was PT. */
1043 HOWTO (R_SH_PT_16
, /* type */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 TRUE
, /* pc_relative */
1049 complain_overflow_signed
, /* complain_on_overflow */
1050 bfd_elf_generic_reloc
, /* special_function */
1051 "R_SH_PT_16", /* name */
1052 FALSE
, /* partial_inplace */
1054 0x3fffc00, /* dst_mask */
1055 TRUE
), /* pcrel_offset */
1057 /* Used in unexpanded MOVI. */
1058 HOWTO (R_SH_IMMS16
, /* type */
1060 2, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE
, /* pc_relative */
1064 complain_overflow_signed
, /* complain_on_overflow */
1065 bfd_elf_generic_reloc
, /* special_function */
1066 "R_SH_IMMS16", /* name */
1067 FALSE
, /* partial_inplace */
1069 0x3fffc00, /* dst_mask */
1070 FALSE
), /* pcrel_offset */
1072 /* Used in SHORI. */
1073 HOWTO (R_SH_IMMU16
, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_unsigned
, /* complain_on_overflow */
1080 bfd_elf_generic_reloc
, /* special_function */
1081 "R_SH_IMMU16", /* name */
1082 FALSE
, /* partial_inplace */
1084 0x3fffc00, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1087 /* Used in MOVI and SHORI (x & 65536). */
1088 HOWTO (R_SH_IMM_LOW16
, /* type */
1090 2, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 bfd_elf_generic_reloc
, /* special_function */
1096 "R_SH_IMM_LOW16", /* name */
1097 FALSE
, /* partial_inplace */
1099 0x3fffc00, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* Used in MOVI and SHORI ((x - $) & 65536). */
1103 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 TRUE
, /* pc_relative */
1109 complain_overflow_dont
, /* complain_on_overflow */
1110 bfd_elf_generic_reloc
, /* special_function */
1111 "R_SH_IMM_LOW16_PCREL", /* name */
1112 FALSE
, /* partial_inplace */
1114 0x3fffc00, /* dst_mask */
1115 TRUE
), /* pcrel_offset */
1117 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1118 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1119 16, /* rightshift */
1120 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE
, /* pc_relative */
1124 complain_overflow_dont
, /* complain_on_overflow */
1125 bfd_elf_generic_reloc
, /* special_function */
1126 "R_SH_IMM_MEDLOW16", /* name */
1127 FALSE
, /* partial_inplace */
1129 0x3fffc00, /* dst_mask */
1130 FALSE
), /* pcrel_offset */
1132 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1133 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1134 16, /* rightshift */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 TRUE
, /* pc_relative */
1139 complain_overflow_dont
, /* complain_on_overflow */
1140 bfd_elf_generic_reloc
, /* special_function */
1141 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1142 FALSE
, /* partial_inplace */
1144 0x3fffc00, /* dst_mask */
1145 TRUE
), /* pcrel_offset */
1147 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1148 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1149 32, /* rightshift */
1150 2, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_dont
, /* complain_on_overflow */
1155 bfd_elf_generic_reloc
, /* special_function */
1156 "R_SH_IMM_MEDHI16", /* name */
1157 FALSE
, /* partial_inplace */
1159 0x3fffc00, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1163 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1164 32, /* rightshift */
1165 2, /* size (0 = byte, 1 = short, 2 = long) */
1167 TRUE
, /* pc_relative */
1169 complain_overflow_dont
, /* complain_on_overflow */
1170 bfd_elf_generic_reloc
, /* special_function */
1171 "R_SH_IMM_MEDHI16_PCREL", /* name */
1172 FALSE
, /* partial_inplace */
1174 0x3fffc00, /* dst_mask */
1175 TRUE
), /* pcrel_offset */
1177 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1178 HOWTO (R_SH_IMM_HI16
, /* type */
1179 48, /* rightshift */
1180 2, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE
, /* pc_relative */
1184 complain_overflow_dont
, /* complain_on_overflow */
1185 bfd_elf_generic_reloc
, /* special_function */
1186 "R_SH_IMM_HI16", /* name */
1187 FALSE
, /* partial_inplace */
1189 0x3fffc00, /* dst_mask */
1190 FALSE
), /* pcrel_offset */
1192 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1193 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1194 48, /* rightshift */
1195 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 TRUE
, /* pc_relative */
1199 complain_overflow_dont
, /* complain_on_overflow */
1200 bfd_elf_generic_reloc
, /* special_function */
1201 "R_SH_IMM_HI16_PCREL", /* name */
1202 FALSE
, /* partial_inplace */
1204 0x3fffc00, /* dst_mask */
1205 TRUE
), /* pcrel_offset */
1207 /* For the .uaquad pseudo. */
1208 HOWTO (R_SH_64
, /* type */
1210 4, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_dont
, /* complain_on_overflow */
1215 bfd_elf_generic_reloc
, /* special_function */
1216 "R_SH_64", /* name */
1217 FALSE
, /* partial_inplace */
1219 ((bfd_vma
) 0) - 1, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* For the .uaquad pseudo, (x - $). */
1223 HOWTO (R_SH_64_PCREL
, /* type */
1224 48, /* rightshift */
1225 2, /* size (0 = byte, 1 = short, 2 = long) */
1227 TRUE
, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 bfd_elf_generic_reloc
, /* special_function */
1231 "R_SH_64_PCREL", /* name */
1232 FALSE
, /* partial_inplace */
1234 ((bfd_vma
) 0) - 1, /* dst_mask */
1235 TRUE
), /* pcrel_offset */
1239 /* This function is used for relocs which are only used for relaxing,
1240 which the linker should otherwise ignore. */
1242 static bfd_reloc_status_type
1243 sh_elf64_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1244 asymbol
*symbol ATTRIBUTE_UNUSED
,
1245 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
1247 char **error_message ATTRIBUTE_UNUSED
)
1249 if (output_bfd
!= NULL
)
1250 reloc_entry
->address
+= input_section
->output_offset
;
1251 return bfd_reloc_ok
;
1254 /* This function is used for normal relocs. This used to be like the COFF
1255 function, and is almost certainly incorrect for other ELF targets.
1257 See sh_elf_reloc in elf32-sh.c for the original. */
1259 static bfd_reloc_status_type
1260 sh_elf64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
1261 void *data
, asection
*input_section
, bfd
*output_bfd
,
1262 char **error_message ATTRIBUTE_UNUSED
)
1266 enum elf_sh_reloc_type r_type
;
1267 bfd_vma addr
= reloc_entry
->address
;
1268 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1270 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1272 if (output_bfd
!= NULL
)
1274 /* Partial linking--do nothing. */
1275 reloc_entry
->address
+= input_section
->output_offset
;
1276 return bfd_reloc_ok
;
1279 if (symbol_in
!= NULL
1280 && bfd_is_und_section (symbol_in
->section
))
1281 return bfd_reloc_undefined
;
1283 if (bfd_is_com_section (symbol_in
->section
))
1286 sym_value
= (symbol_in
->value
+
1287 symbol_in
->section
->output_section
->vma
+
1288 symbol_in
->section
->output_offset
);
1293 insn
= bfd_get_32 (abfd
, hit_data
);
1294 insn
+= sym_value
+ reloc_entry
->addend
;
1295 bfd_put_32 (abfd
, insn
, hit_data
);
1303 return bfd_reloc_ok
;
1306 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1308 struct elf_reloc_map
1310 bfd_reloc_code_real_type bfd_reloc_val
;
1311 unsigned char elf_reloc_val
;
1314 /* An array mapping BFD reloc codes to SH ELF relocs. */
1316 static const struct elf_reloc_map sh64_reloc_map
[] =
1318 { BFD_RELOC_NONE
, R_SH_NONE
},
1319 { BFD_RELOC_32
, R_SH_DIR32
},
1320 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1321 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1322 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1323 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1324 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1325 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1326 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1327 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1328 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1329 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1330 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1331 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1332 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1333 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1334 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1335 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1336 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1337 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1338 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1339 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1340 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1341 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1342 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1343 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1344 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1345 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1346 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1347 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1348 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1349 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1350 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1351 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1352 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1353 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1354 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1355 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1356 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1357 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1358 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1359 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1360 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1361 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1362 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1363 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1364 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1365 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1366 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1367 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1368 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1369 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1370 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1371 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1372 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1373 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1374 { BFD_RELOC_64
, R_SH_64
},
1375 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1378 /* Given a BFD reloc code, return the howto structure for the
1379 corresponding SH ELf reloc. */
1381 static reloc_howto_type
*
1382 sh_elf64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1383 bfd_reloc_code_real_type code
)
1387 for (i
= 0; i
< sizeof (sh64_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1389 if (sh64_reloc_map
[i
].bfd_reloc_val
== code
)
1390 return &sh_elf64_howto_table
[(int) sh64_reloc_map
[i
].elf_reloc_val
];
1396 static reloc_howto_type
*
1397 sh_elf64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1403 i
< sizeof (sh_elf64_howto_table
) / sizeof (sh_elf64_howto_table
[0]);
1405 if (sh_elf64_howto_table
[i
].name
!= NULL
1406 && strcasecmp (sh_elf64_howto_table
[i
].name
, r_name
) == 0)
1407 return &sh_elf64_howto_table
[i
];
1412 /* Given an ELF reloc, fill in the howto field of a relent.
1414 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1417 sh_elf64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
1418 Elf_Internal_Rela
*dst
)
1422 r
= ELF64_R_TYPE (dst
->r_info
);
1424 BFD_ASSERT (r
<= (unsigned int) R_SH_64_PCREL
);
1425 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1426 BFD_ASSERT (r
< R_SH_DIR8WPN
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1427 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_GOTPLT32
);
1428 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1430 cache_ptr
->howto
= &sh_elf64_howto_table
[r
];
1433 /* Relocate an SH ELF section.
1435 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1438 sh_elf64_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1439 struct bfd_link_info
*info
, bfd
*input_bfd
,
1440 asection
*input_section
, bfd_byte
*contents
,
1441 Elf_Internal_Rela
*relocs
,
1442 Elf_Internal_Sym
*local_syms
,
1443 asection
**local_sections
)
1445 Elf_Internal_Shdr
*symtab_hdr
;
1446 struct elf_link_hash_entry
**sym_hashes
;
1447 Elf_Internal_Rela
*rel
, *relend
;
1449 bfd_vma
*local_got_offsets
;
1454 bfd_vma disp
, dropped
;
1456 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1457 sym_hashes
= elf_sym_hashes (input_bfd
);
1458 dynobj
= elf_hash_table (info
)->dynobj
;
1459 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1467 relend
= relocs
+ input_section
->reloc_count
;
1468 for (; rel
< relend
; rel
++)
1471 reloc_howto_type
*howto
;
1472 unsigned long r_symndx
;
1473 Elf_Internal_Sym
*sym
;
1475 struct elf_link_hash_entry
*h
;
1477 bfd_vma addend
= (bfd_vma
)0;
1478 bfd_reloc_status_type r
;
1479 int seen_stt_datalabel
= 0;
1481 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1483 r_type
= ELF64_R_TYPE (rel
->r_info
);
1485 if (r_type
== (int) R_SH_NONE
)
1489 || r_type
> R_SH_64_PCREL
1490 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1491 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1492 || (r_type
>= (int) R_SH_DIR8WPN
1493 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1494 || (r_type
>= (int) R_SH_GNU_VTINHERIT
1495 && r_type
<= (int) R_SH_PSHL
)
1496 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
1497 && r_type
<= R_SH_GOTPLT32
)
1498 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
1499 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
))
1501 bfd_set_error (bfd_error_bad_value
);
1505 howto
= sh_elf64_howto_table
+ r_type
;
1511 if (r_symndx
< symtab_hdr
->sh_info
)
1513 sym
= local_syms
+ r_symndx
;
1514 sec
= local_sections
[r_symndx
];
1515 relocation
= ((sec
->output_section
->vma
1516 + sec
->output_offset
1518 | ((sym
->st_other
& STO_SH5_ISA32
) != 0));
1520 /* A local symbol never has STO_SH5_ISA32, so we don't need
1521 datalabel processing here. Make sure this does not change
1523 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
1524 ((*info
->callbacks
->reloc_dangerous
)
1526 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1527 input_bfd
, input_section
, rel
->r_offset
));
1529 if (sec
!= NULL
&& elf_discarded_section (sec
))
1530 /* Handled below. */
1532 else if (info
->relocatable
)
1534 /* This is a relocatable link. We don't have to change
1535 anything, unless the reloc is against a section symbol,
1536 in which case we have to adjust according to where the
1537 section symbol winds up in the output section. */
1538 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1539 goto final_link_relocate
;
1543 else if (! howto
->partial_inplace
)
1545 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1546 relocation
|= ((sym
->st_other
& STO_SH5_ISA32
) != 0);
1548 else if ((sec
->flags
& SEC_MERGE
)
1549 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1553 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
1555 (*_bfd_error_handler
)
1556 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
1557 input_bfd
, input_section
,
1558 (long) rel
->r_offset
, howto
->name
);
1562 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1565 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
1567 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
1568 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
1574 /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ? */
1576 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1577 while (h
->root
.type
== bfd_link_hash_indirect
1578 || h
->root
.type
== bfd_link_hash_warning
)
1580 /* If the reference passes a symbol marked with
1581 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1583 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
1584 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1587 if (h
->root
.type
== bfd_link_hash_defined
1588 || h
->root
.type
== bfd_link_hash_defweak
)
1590 sec
= h
->root
.u
.def
.section
;
1591 /* In these cases, we don't need the relocation value.
1592 We check specially because in some obscure cases
1593 sec->output_section will be NULL. */
1594 if (r_type
== R_SH_GOTPC_LOW16
1595 || r_type
== R_SH_GOTPC_MEDLOW16
1596 || r_type
== R_SH_GOTPC_MEDHI16
1597 || r_type
== R_SH_GOTPC_HI16
1598 || ((r_type
== R_SH_PLT_LOW16
1599 || r_type
== R_SH_PLT_MEDLOW16
1600 || r_type
== R_SH_PLT_MEDHI16
1601 || r_type
== R_SH_PLT_HI16
)
1602 && h
->plt
.offset
!= (bfd_vma
) -1)
1603 || ((r_type
== R_SH_GOT_LOW16
1604 || r_type
== R_SH_GOT_MEDLOW16
1605 || r_type
== R_SH_GOT_MEDHI16
1606 || r_type
== R_SH_GOT_HI16
)
1607 && elf_hash_table (info
)->dynamic_sections_created
1609 || (! info
->symbolic
&& h
->dynindx
!= -1)
1610 || !h
->def_regular
))
1611 /* The cases above are those in which relocation is
1612 overwritten in the switch block below. The cases
1613 below are those in which we must defer relocation
1614 to run-time, because we can't resolve absolute
1615 addresses when creating a shared library. */
1617 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1619 && ((r_type
== R_SH_64
1620 && !(ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1621 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
))
1622 || r_type
== R_SH_64_PCREL
)
1623 && ((input_section
->flags
& SEC_ALLOC
) != 0
1624 /* DWARF will emit R_SH_DIR32 relocations in its
1625 sections against symbols defined externally
1626 in shared libraries. We can't do anything
1628 || (input_section
->flags
& SEC_DEBUGGING
) != 0))
1629 /* Dynamic relocs are not propagated for SEC_DEBUGGING
1630 sections because such sections are not SEC_ALLOC and
1631 thus ld.so will not process them. */
1632 || (sec
->output_section
== NULL
1633 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
1634 && h
->def_dynamic
)))
1636 else if (sec
->output_section
!= NULL
)
1637 relocation
= ((h
->root
.u
.def
.value
1638 + sec
->output_section
->vma
1639 + sec
->output_offset
)
1640 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1641 symbol value, unless we've seen
1642 STT_DATALABEL on the way to it. */
1643 | ((h
->other
& STO_SH5_ISA32
) != 0
1644 && ! seen_stt_datalabel
));
1645 else if (!info
->relocatable
)
1647 (*_bfd_error_handler
)
1648 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1651 (long) rel
->r_offset
,
1653 h
->root
.root
.string
);
1656 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1658 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
1659 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1661 else if (!info
->relocatable
)
1663 if (! ((*info
->callbacks
->undefined_symbol
)
1664 (info
, h
->root
.root
.string
, input_bfd
,
1665 input_section
, rel
->r_offset
,
1666 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
1667 || ELF_ST_VISIBILITY (h
->other
)))))
1672 if (sec
!= NULL
&& elf_discarded_section (sec
))
1674 /* For relocs against symbols from removed linkonce sections,
1675 or sections discarded by a linker script, we just want the
1676 section contents zeroed. Avoid any special processing. */
1677 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
1683 if (info
->relocatable
)
1687 - input_section
->output_section
->vma
1688 - input_section
->output_offset
1691 switch ((int)r_type
)
1693 case R_SH_PT_16
: dropped
= disp
& 2; break;
1694 case R_SH_DIR10SW
: dropped
= disp
& 1; break;
1695 case R_SH_DIR10SL
: dropped
= disp
& 3; break;
1696 case R_SH_DIR10SQ
: dropped
= disp
& 7; break;
1700 (*_bfd_error_handler
)
1701 (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1702 bfd_get_filename (input_bfd
), (int)r_type
, (unsigned)rel
->r_offset
, (unsigned)relocation
);
1703 bfd_set_error (bfd_error_bad_value
);
1706 switch ((int)r_type
)
1711 && (input_section
->flags
& SEC_ALLOC
) != 0
1712 && (r_type
!= R_SH_64_PCREL
1715 && (! info
->symbolic
1716 || !h
->def_regular
))))
1718 Elf_Internal_Rela outrel
;
1720 bfd_boolean skip
, relocate
;
1722 /* When generating a shared object, these relocations
1723 are copied into the output file to be resolved at run
1728 sreloc
= _bfd_elf_get_dynamic_reloc_section
1729 (input_bfd
, input_section
, /*rela?*/ TRUE
);
1738 = _bfd_elf_section_offset (output_bfd
, info
,
1739 input_section
, rel
->r_offset
);
1741 if (outrel
.r_offset
== (bfd_vma
) -1)
1743 else if (outrel
.r_offset
== (bfd_vma
) -2)
1744 skip
= TRUE
, relocate
= TRUE
;
1746 outrel
.r_offset
+= (input_section
->output_section
->vma
1747 + input_section
->output_offset
);
1750 memset (&outrel
, 0, sizeof outrel
);
1751 else if (r_type
== R_SH_64_PCREL
)
1753 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
1754 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64_PCREL
);
1755 outrel
.r_addend
= rel
->r_addend
;
1759 /* h->dynindx may be -1 if this symbol was marked to
1762 || ((info
->symbolic
|| h
->dynindx
== -1)
1766 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1767 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1771 BFD_ASSERT (h
->dynindx
!= -1);
1772 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64
);
1773 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1777 loc
= sreloc
->contents
;
1778 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1779 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1781 /* If this reloc is against an external symbol, we do
1782 not want to fiddle with the addend. Otherwise, we
1783 need to include the symbol value so that it becomes
1784 an addend for the dynamic reloc. */
1788 else if (r_type
== R_SH_64
)
1789 addend
= rel
->r_addend
;
1790 goto final_link_relocate
;
1792 case R_SH_GOTPLT_LOW16
:
1793 case R_SH_GOTPLT_MEDLOW16
:
1794 case R_SH_GOTPLT_MEDHI16
:
1795 case R_SH_GOTPLT_HI16
:
1796 case R_SH_GOTPLT10BY4
:
1797 case R_SH_GOTPLT10BY8
:
1798 /* Relocation is to the entry for this symbol in the
1799 procedure linkage table. */
1802 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1803 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
1807 || h
->plt
.offset
== (bfd_vma
) -1
1808 || h
->got
.offset
!= (bfd_vma
) -1)
1811 /* Relocation is to the entry for this symbol in the global
1812 offset table extension for the procedure linkage table. */
1813 if (sgotplt
== NULL
)
1815 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1816 BFD_ASSERT (sgotplt
!= NULL
);
1819 relocation
= (sgotplt
->output_offset
1820 + ((h
->plt
.offset
/ elf_sh64_sizeof_plt (info
)
1823 relocation
-= GOT_BIAS
;
1825 goto final_link_relocate
;
1828 case R_SH_GOT_LOW16
:
1829 case R_SH_GOT_MEDLOW16
:
1830 case R_SH_GOT_MEDHI16
:
1834 /* Relocation is to the entry for this symbol in the global
1838 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1839 BFD_ASSERT (sgot
!= NULL
);
1846 off
= h
->got
.offset
;
1847 if (seen_stt_datalabel
)
1849 struct elf_sh64_link_hash_entry
*hsh
;
1851 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1852 off
= hsh
->datalabel_got_offset
;
1854 BFD_ASSERT (off
!= (bfd_vma
) -1);
1856 if (! elf_hash_table (info
)->dynamic_sections_created
1858 && (info
->symbolic
|| h
->dynindx
== -1
1859 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1860 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
1863 /* This is actually a static link, or it is a
1864 -Bsymbolic link and the symbol is defined
1865 locally, or the symbol was forced to be local
1866 because of a version file. We must initialize
1867 this entry in the global offset table. Since the
1868 offset must always be a multiple of 4, we use the
1869 least significant bit to record whether we have
1870 initialized it already.
1872 When doing a dynamic link, we create a .rela.got
1873 relocation entry to initialize the value. This
1874 is done in the finish_dynamic_symbol routine. */
1879 bfd_put_64 (output_bfd
, relocation
,
1880 sgot
->contents
+ off
);
1881 if (seen_stt_datalabel
)
1883 struct elf_sh64_link_hash_entry
*hsh
;
1885 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1886 hsh
->datalabel_got_offset
|= 1;
1893 relocation
= sgot
->output_offset
+ off
;
1901 BFD_ASSERT (local_got_offsets
!= NULL
1902 && (local_got_offsets
[symtab_hdr
->sh_info
1906 off
= local_got_offsets
[symtab_hdr
->sh_info
1911 BFD_ASSERT (local_got_offsets
!= NULL
1912 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1914 off
= local_got_offsets
[r_symndx
];
1917 /* The offset must always be a multiple of 8. We use
1918 the least significant bit to record whether we have
1919 already generated the necessary reloc. */
1924 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1929 Elf_Internal_Rela outrel
;
1932 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1933 BFD_ASSERT (s
!= NULL
);
1935 outrel
.r_offset
= (sgot
->output_section
->vma
1936 + sgot
->output_offset
1938 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1939 outrel
.r_addend
= relocation
;
1941 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1942 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1946 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
1948 local_got_offsets
[r_symndx
] |= 1;
1951 relocation
= sgot
->output_offset
+ off
;
1954 relocation
-= GOT_BIAS
;
1956 goto final_link_relocate
;
1958 case R_SH_GOTOFF_LOW16
:
1959 case R_SH_GOTOFF_MEDLOW16
:
1960 case R_SH_GOTOFF_MEDHI16
:
1961 case R_SH_GOTOFF_HI16
:
1962 /* Relocation is relative to the start of the global offset
1967 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1968 BFD_ASSERT (sgot
!= NULL
);
1971 /* Note that sgot->output_offset is not involved in this
1972 calculation. We always want the start of .got. If we
1973 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1974 permitted by the ABI, we might have to change this
1976 relocation
-= sgot
->output_section
->vma
;
1978 relocation
-= GOT_BIAS
;
1980 addend
= rel
->r_addend
;
1982 goto final_link_relocate
;
1984 case R_SH_GOTPC_LOW16
:
1985 case R_SH_GOTPC_MEDLOW16
:
1986 case R_SH_GOTPC_MEDHI16
:
1987 case R_SH_GOTPC_HI16
:
1988 /* Use global offset table as symbol value. */
1992 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1993 BFD_ASSERT (sgot
!= NULL
);
1996 relocation
= sgot
->output_section
->vma
;
1998 relocation
+= GOT_BIAS
;
2000 addend
= rel
->r_addend
;
2002 goto final_link_relocate
;
2004 case R_SH_PLT_LOW16
:
2005 case R_SH_PLT_MEDLOW16
:
2006 case R_SH_PLT_MEDHI16
:
2008 /* Relocation is to the entry for this symbol in the
2009 procedure linkage table. */
2011 /* Resolve a PLT reloc against a local symbol directly,
2012 without using the procedure linkage table. */
2014 goto final_link_relocate
;
2016 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2017 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2018 goto final_link_relocate
;
2020 if (h
->plt
.offset
== (bfd_vma
) -1)
2022 /* We didn't make a PLT entry for this symbol. This
2023 happens when statically linking PIC code, or when
2024 using -Bsymbolic. */
2025 goto final_link_relocate
;
2030 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2031 BFD_ASSERT (splt
!= NULL
);
2034 relocation
= (splt
->output_section
->vma
2035 + splt
->output_offset
2039 addend
= rel
->r_addend
;
2041 goto final_link_relocate
;
2044 case R_SH_SHMEDIA_CODE
:
2055 case R_SH_IMM_LOW16
:
2056 case R_SH_IMM_LOW16_PCREL
:
2057 case R_SH_IMM_MEDLOW16
:
2058 case R_SH_IMM_MEDLOW16_PCREL
:
2059 case R_SH_IMM_MEDHI16
:
2060 case R_SH_IMM_MEDHI16_PCREL
:
2062 case R_SH_IMM_HI16_PCREL
:
2063 addend
= rel
->r_addend
;
2066 final_link_relocate
:
2067 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2068 contents
, rel
->r_offset
,
2069 relocation
, addend
);
2073 bfd_set_error (bfd_error_bad_value
);
2078 if (r
!= bfd_reloc_ok
)
2083 case bfd_reloc_outofrange
:
2085 case bfd_reloc_overflow
:
2093 name
= (bfd_elf_string_from_elf_section
2094 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2098 name
= bfd_section_name (input_bfd
, sec
);
2100 if (! ((*info
->callbacks
->reloc_overflow
)
2101 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2102 (bfd_vma
) 0, input_bfd
, input_section
,
2114 /* This is a version of bfd_generic_get_relocated_section_contents
2115 that uses sh_elf64_relocate_section.
2117 See sh_elf_relocate_section in elf32-sh.c for the original. */
2120 sh_elf64_get_relocated_section_contents (bfd
*output_bfd
,
2121 struct bfd_link_info
*link_info
,
2122 struct bfd_link_order
*link_order
,
2124 bfd_boolean relocatable
,
2127 Elf_Internal_Shdr
*symtab_hdr
;
2128 asection
*input_section
= link_order
->u
.indirect
.section
;
2129 bfd
*input_bfd
= input_section
->owner
;
2130 asection
**sections
= NULL
;
2131 Elf_Internal_Rela
*internal_relocs
= NULL
;
2132 Elf_Internal_Sym
*isymbuf
= NULL
;
2134 /* We only need to handle the case of relaxing, or of having a
2135 particular set of section contents, specially. */
2137 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2138 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2143 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2145 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2146 input_section
->size
);
2148 if ((input_section
->flags
& SEC_RELOC
) != 0
2149 && input_section
->reloc_count
> 0)
2151 Elf_Internal_Sym
*isymp
;
2152 Elf_Internal_Sym
*isymend
;
2155 /* Read this BFD's local symbols. */
2156 if (symtab_hdr
->sh_info
!= 0)
2158 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2159 if (isymbuf
== NULL
)
2160 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2161 symtab_hdr
->sh_info
, 0,
2163 if (isymbuf
== NULL
)
2167 internal_relocs
= (_bfd_elf_link_read_relocs
2168 (input_bfd
, input_section
, NULL
,
2169 (Elf_Internal_Rela
*) NULL
, FALSE
));
2170 if (internal_relocs
== NULL
)
2173 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2174 * sizeof (asection
*));
2175 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2179 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2180 for (isymp
= isymbuf
; isymp
< isymend
; ++isymp
, ++secpp
)
2184 if (isymp
->st_shndx
== SHN_UNDEF
)
2185 isec
= bfd_und_section_ptr
;
2186 else if (isymp
->st_shndx
== SHN_ABS
)
2187 isec
= bfd_abs_section_ptr
;
2188 else if (isymp
->st_shndx
== SHN_COMMON
)
2189 isec
= bfd_com_section_ptr
;
2191 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
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 /* Copy object attributes. */
2304 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
2306 return sh_elf64_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2310 sh_elf64_copy_private_data (bfd
*ibfd
, bfd
*obfd
)
2312 return sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2316 sh_elf64_merge_private_data (bfd
*ibfd
, bfd
*obfd
)
2318 flagword old_flags
, new_flags
;
2320 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2323 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2324 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2327 if (bfd_get_arch_size (ibfd
) != bfd_get_arch_size (obfd
))
2331 if (bfd_get_arch_size (ibfd
) == 32
2332 && bfd_get_arch_size (obfd
) == 64)
2333 msg
= _("%s: compiled as 32-bit object and %s is 64-bit");
2334 else if (bfd_get_arch_size (ibfd
) == 64
2335 && bfd_get_arch_size (obfd
) == 32)
2336 msg
= _("%s: compiled as 64-bit object and %s is 32-bit");
2338 msg
= _("%s: object size does not match that of target %s");
2340 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
),
2341 bfd_get_filename (obfd
));
2342 bfd_set_error (bfd_error_wrong_format
);
2346 old_flags
= elf_elfheader (obfd
)->e_flags
;
2347 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2348 if (! elf_flags_init (obfd
))
2350 /* This happens when ld starts out with a 'blank' output file. */
2351 elf_flags_init (obfd
) = TRUE
;
2352 elf_elfheader (obfd
)->e_flags
= old_flags
= new_flags
;
2354 /* We don't allow linking in anything else than SH64 code, and since
2355 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2356 here as things change. */
2357 else if ((new_flags
& EF_SH_MACH_MASK
) != EF_SH5
)
2359 (*_bfd_error_handler
)
2360 ("%s: does not use the SH64 64-bit ABI as previous modules do",
2361 bfd_get_filename (ibfd
));
2362 bfd_set_error (bfd_error_bad_value
);
2366 sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2368 /* I can't think of anything sane other than old_flags being EF_SH5 and
2369 that we need to preserve that. */
2370 elf_elfheader (obfd
)->e_flags
= old_flags
;
2372 return sh_elf64_set_mach_from_flags (obfd
);
2375 /* Return the section that should be marked against GC for a given
2379 sh_elf64_gc_mark_hook (asection
*sec
,
2380 struct bfd_link_info
*info
,
2381 Elf_Internal_Rela
*rel
,
2382 struct elf_link_hash_entry
*h
,
2383 Elf_Internal_Sym
*sym
)
2386 switch (ELF64_R_TYPE (rel
->r_info
))
2388 case R_SH_GNU_VTINHERIT
:
2389 case R_SH_GNU_VTENTRY
:
2393 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2396 /* Look through the relocs for a section during the first phase.
2397 Since we don't do .gots or .plts, we just need to consider the
2398 virtual table relocs for gc. */
2401 sh_elf64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2402 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2404 Elf_Internal_Shdr
*symtab_hdr
;
2405 struct elf_link_hash_entry
**sym_hashes
;
2406 const Elf_Internal_Rela
*rel
;
2407 const Elf_Internal_Rela
*rel_end
;
2409 bfd_vma
*local_got_offsets
;
2418 if (info
->relocatable
)
2421 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2422 sym_hashes
= elf_sym_hashes (abfd
);
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 BFD_ASSERT (h
!= NULL
);
2493 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2498 case R_SH_GOT_LOW16
:
2499 case R_SH_GOT_MEDLOW16
:
2500 case R_SH_GOT_MEDHI16
:
2504 /* This symbol requires a global offset table entry. */
2508 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2509 BFD_ASSERT (sgot
!= NULL
);
2513 && (h
!= NULL
|| info
->shared
))
2515 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2516 if (srelgot
== NULL
)
2518 srelgot
= bfd_make_section_with_flags (dynobj
,
2524 | SEC_LINKER_CREATED
2527 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2534 if (h
->type
== STT_DATALABEL
)
2536 struct elf_sh64_link_hash_entry
*hsh
;
2538 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2539 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
2540 if (hsh
->datalabel_got_offset
!= (bfd_vma
) -1)
2543 hsh
->datalabel_got_offset
= sgot
->size
;
2547 if (h
->got
.offset
!= (bfd_vma
) -1)
2549 /* We have already allocated space in the .got. */
2552 h
->got
.offset
= sgot
->size
;
2555 /* Make sure this symbol is output as a dynamic symbol. */
2556 if (h
->dynindx
== -1)
2558 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2562 srelgot
->size
+= sizeof (Elf64_External_Rela
);
2566 /* This is a global offset table entry for a local
2568 if (local_got_offsets
== NULL
)
2571 register unsigned int i
;
2573 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
2574 /* Reserve space for both the datalabel and
2575 codelabel local GOT offsets. */
2577 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
2578 if (local_got_offsets
== NULL
)
2580 elf_local_got_offsets (abfd
) = local_got_offsets
;
2581 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
2582 local_got_offsets
[i
] = (bfd_vma
) -1;
2583 for (; i
< 2 * symtab_hdr
->sh_info
; i
++)
2584 local_got_offsets
[i
] = (bfd_vma
) -1;
2586 if ((rel
->r_addend
& 1) != 0)
2588 if (local_got_offsets
[symtab_hdr
->sh_info
2589 + r_symndx
] != (bfd_vma
) -1)
2591 /* We have already allocated space in the .got. */
2594 local_got_offsets
[symtab_hdr
->sh_info
2595 + r_symndx
] = sgot
->size
;
2599 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
2601 /* We have already allocated space in the .got. */
2604 local_got_offsets
[r_symndx
] = sgot
->size
;
2609 /* If we are generating a shared object, we need to
2610 output a R_SH_RELATIVE reloc so that the dynamic
2611 linker can adjust this GOT entry. */
2612 srelgot
->size
+= sizeof (Elf64_External_Rela
);
2620 case R_SH_GOTPLT_LOW16
:
2621 case R_SH_GOTPLT_MEDLOW16
:
2622 case R_SH_GOTPLT_MEDHI16
:
2623 case R_SH_GOTPLT_HI16
:
2624 case R_SH_GOTPLT10BY4
:
2625 case R_SH_GOTPLT10BY8
:
2626 /* If this is a local symbol, we resolve it directly without
2627 creating a procedure linkage table entry. */
2630 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2631 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
2635 || h
->got
.offset
!= (bfd_vma
) -1)
2638 /* Make sure this symbol is output as a dynamic symbol. */
2639 if (h
->dynindx
== -1)
2641 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2649 case R_SH_PLT_LOW16
:
2650 case R_SH_PLT_MEDLOW16
:
2651 case R_SH_PLT_MEDHI16
:
2653 /* This symbol requires a procedure linkage table entry. We
2654 actually build the entry in adjust_dynamic_symbol,
2655 because this might be a case of linking PIC code which is
2656 never referenced by a dynamic object, in which case we
2657 don't need to generate a procedure linkage table entry
2660 /* If this is a local symbol, we resolve it directly without
2661 creating a procedure linkage table entry. */
2665 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2666 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2678 /* If we are creating a shared library, and this is a reloc
2679 against a global symbol, or a non PC relative reloc
2680 against a local symbol, then we need to copy the reloc
2681 into the shared library. However, if we are linking with
2682 -Bsymbolic, we do not need to copy a reloc against a
2683 global symbol which is defined in an object we are
2684 including in the link (i.e., DEF_REGULAR is set). At
2685 this point we have not seen all the input files, so it is
2686 possible that DEF_REGULAR is not set now but will be set
2687 later (it is never cleared). We account for that
2688 possibility below by storing information in the
2689 pcrel_relocs_copied field of the hash table entry. */
2691 && (sec
->flags
& SEC_ALLOC
) != 0
2692 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_64_PCREL
2694 && (! info
->symbolic
2695 || !h
->def_regular
))))
2697 /* When creating a shared object, we must copy these
2698 reloc types into the output file. We create a reloc
2699 section in dynobj and make room for this reloc. */
2702 sreloc
= _bfd_elf_make_dynamic_reloc_section
2703 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2709 sreloc
->size
+= sizeof (Elf64_External_Rela
);
2711 /* If we are linking with -Bsymbolic, and this is a
2712 global symbol, we count the number of PC relative
2713 relocations we have entered for this symbol, so that
2714 we can discard them again if the symbol is later
2715 defined by a regular object. Note that this function
2716 is only called if we are using an elf_sh linker
2717 hash table, which means that h is really a pointer to
2718 an elf_sh_link_hash_entry. */
2719 if (h
!= NULL
&& info
->symbolic
2720 && ELF64_R_TYPE (rel
->r_info
) == R_SH_64_PCREL
)
2722 struct elf_sh64_link_hash_entry
*eh
;
2723 struct elf_sh64_pcrel_relocs_copied
*p
;
2725 eh
= (struct elf_sh64_link_hash_entry
*) h
;
2727 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
2728 if (p
->section
== sreloc
)
2733 p
= ((struct elf_sh64_pcrel_relocs_copied
*)
2734 bfd_alloc (dynobj
, sizeof *p
));
2737 p
->next
= eh
->pcrel_relocs_copied
;
2738 eh
->pcrel_relocs_copied
= p
;
2739 p
->section
= sreloc
;
2755 sh64_elf64_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
2757 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_DATALABEL
)
2758 return STT_DATALABEL
;
2763 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2764 Either file can presumably exist without the other, but do not differ
2765 in elf-size-ness. How to share?
2767 Hook called by the linker routine which adds symbols from an object
2768 file. We must make indirect symbols for undefined symbols marked with
2769 STT_DATALABEL, so relocations passing them will pick up that attribute
2770 and neutralize STO_SH5_ISA32 found on the symbol definition.
2772 There is a problem, though: We want to fill in the hash-table entry for
2773 this symbol and signal to the caller that no further processing is
2774 needed. But we don't have the index for this hash-table entry. We
2775 rely here on that the current entry is the first hash-entry with NULL,
2776 which seems brittle. Also, iterating over the hash-table to find that
2777 entry is a linear operation on the number of symbols in this input
2778 file, and this function should take constant time, so that's not good
2779 too. Only comfort is that DataLabel references should only be found in
2780 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2781 into adding an option to elf_add_symbol_hook (preferably) for the index
2782 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2786 sh64_elf64_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
2787 Elf_Internal_Sym
*sym
, const char **namep
,
2788 flagword
*flagsp ATTRIBUTE_UNUSED
,
2789 asection
**secp
, bfd_vma
*valp
)
2791 /* We want to do this for relocatable as well as final linking. */
2792 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
2793 && is_elf_hash_table (info
->hash
))
2795 struct elf_link_hash_entry
*h
;
2797 /* For relocatable links, we register the DataLabel sym in its own
2798 right, and tweak the name when it's output. Otherwise, we make
2799 an indirect symbol of it. */
2801 = info
->relocatable
|| info
->emitrelocations
2802 ? BSF_GLOBAL
: BSF_GLOBAL
| BSF_INDIRECT
;
2805 = bfd_malloc (strlen (*namep
) + sizeof (DATALABEL_SUFFIX
));
2806 struct elf_link_hash_entry
** sym_hash
= elf_sym_hashes (abfd
);
2808 BFD_ASSERT (sym_hash
!= NULL
);
2810 /* Allocation may fail. */
2811 if (dl_name
== NULL
)
2814 strcpy (dl_name
, *namep
);
2815 strcat (dl_name
, DATALABEL_SUFFIX
);
2817 h
= (struct elf_link_hash_entry
*)
2818 bfd_link_hash_lookup (info
->hash
, dl_name
, FALSE
, FALSE
, FALSE
);
2822 /* No previous datalabel symbol. Make one. */
2823 struct bfd_link_hash_entry
*bh
= NULL
;
2824 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2826 if (! _bfd_generic_link_add_one_symbol (info
, abfd
, dl_name
,
2827 flags
, *secp
, *valp
,
2835 h
= (struct elf_link_hash_entry
*) bh
;
2837 h
->type
= STT_DATALABEL
;
2840 /* If a new symbol was created, it holds the allocated name.
2841 Otherwise, we don't need it anymore and should deallocate it. */
2844 if (h
->type
!= STT_DATALABEL
2845 || ((info
->relocatable
|| info
->emitrelocations
)
2846 && h
->root
.type
!= bfd_link_hash_undefined
)
2847 || (! info
->relocatable
&& !info
->emitrelocations
2848 && h
->root
.type
!= bfd_link_hash_indirect
))
2850 /* Make sure we don't get confused on invalid input. */
2851 (*_bfd_error_handler
)
2852 (_("%s: encountered datalabel symbol in input"),
2853 bfd_get_filename (abfd
));
2854 bfd_set_error (bfd_error_bad_value
);
2858 /* Now find the hash-table slot for this entry and fill it in. */
2859 while (*sym_hash
!= NULL
)
2863 /* Signal to caller to skip this symbol - we've handled it. */
2870 /* This hook function is called before the linker writes out a global
2871 symbol. For relocatable links, DataLabel symbols will be present in
2872 linker output. We cut off the special suffix on those symbols, so the
2873 right name appears in the output.
2875 When linking and emitting relocations, there can appear global symbols
2876 that are not referenced by relocs, but rather only implicitly through
2877 DataLabel references, a relation that is not visible to the linker.
2878 Since no stripping of global symbols in done when doing such linking,
2879 we don't need to look up and make sure to emit the main symbol for each
2880 DataLabel symbol. */
2883 sh64_elf64_link_output_symbol_hook (struct bfd_link_info
*info
,
2885 Elf_Internal_Sym
*sym
,
2886 asection
*input_sec ATTRIBUTE_UNUSED
,
2887 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2889 char *name
= (char *) cname
;
2891 if (info
->relocatable
|| info
->emitrelocations
)
2893 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
)
2894 name
[strlen (name
) - strlen (DATALABEL_SUFFIX
)] = 0;
2900 /* Set bit 0 on the entry address; it always points to SHmedia code. This
2901 is mostly for symmetry with the 32-bit format, where code can be
2902 SHcompact and we need to make a distinction to make sure execution
2903 starts in the right ISA mode. It is also convenient for a loader,
2904 which would otherwise have to set this bit when loading a TR register
2905 before jumping to the program entry. */
2908 sh64_elf64_final_write_processing (bfd
*abfd
,
2909 bfd_boolean linker ATTRIBUTE_UNUSED
)
2911 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
2912 numerically, but we currently lack the infrastructure to recognize
2913 that: The entry symbol, and info whether it is numeric or a symbol
2914 name is kept private in the linker. */
2915 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
)
2916 elf_elfheader (abfd
)->e_entry
|= 1;
2919 /* First entry in an absolute procedure linkage table look like this. */
2921 static const bfd_byte elf_sh64_plt0_entry_be
[PLT_ENTRY_SIZE
] =
2923 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
2924 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
2925 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
2926 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2927 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
2928 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2929 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
2930 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2931 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2932 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2933 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2934 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2935 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2936 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2937 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2938 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2941 static const bfd_byte elf_sh64_plt0_entry_le
[PLT_ENTRY_SIZE
] =
2943 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
2944 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
2945 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
2946 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2947 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
2948 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2949 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
2950 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2951 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2952 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2953 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2954 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2955 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2956 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2957 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2958 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2961 /* Sebsequent entries in an absolute procedure linkage table look like
2964 static const bfd_byte elf_sh64_plt_entry_be
[PLT_ENTRY_SIZE
] =
2966 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
2967 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
2968 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
2969 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
2970 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
2971 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2972 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2973 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2974 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */
2975 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
2976 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
2977 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
2978 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
2979 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2980 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2981 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2984 static const bfd_byte elf_sh64_plt_entry_le
[PLT_ENTRY_SIZE
] =
2986 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
2987 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2988 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2989 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2990 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
2991 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2992 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2993 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2994 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */
2995 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
2996 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
2997 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
2998 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
2999 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3000 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3001 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3004 /* Entries in a PIC procedure linkage table look like this. */
3006 static const bfd_byte elf_sh64_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3008 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3009 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3010 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
3011 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3012 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3013 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3014 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3015 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3016 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3017 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */
3018 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3019 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3020 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3021 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3022 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3023 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3026 static const bfd_byte elf_sh64_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3028 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3029 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3030 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3031 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3032 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3033 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3034 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3035 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3036 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3037 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */
3038 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3039 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3040 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3041 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3042 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3043 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3046 static const bfd_byte
*elf_sh64_plt0_entry
;
3047 static const bfd_byte
*elf_sh64_plt_entry
;
3048 static const bfd_byte
*elf_sh64_pic_plt_entry
;
3050 /* Create an entry in an sh ELF linker hash table. */
3052 static struct bfd_hash_entry
*
3053 sh64_elf64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3054 struct bfd_hash_table
*table
,
3057 struct elf_sh64_link_hash_entry
*ret
=
3058 (struct elf_sh64_link_hash_entry
*) entry
;
3060 /* Allocate the structure if it has not already been allocated by a
3062 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3063 ret
= ((struct elf_sh64_link_hash_entry
*)
3064 bfd_hash_allocate (table
,
3065 sizeof (struct elf_sh64_link_hash_entry
)));
3066 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3067 return (struct bfd_hash_entry
*) ret
;
3069 /* Call the allocation method of the superclass. */
3070 ret
= ((struct elf_sh64_link_hash_entry
*)
3071 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3073 if (ret
!= (struct elf_sh64_link_hash_entry
*) NULL
)
3075 ret
->pcrel_relocs_copied
= NULL
;
3076 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3079 return (struct bfd_hash_entry
*) ret
;
3082 /* Create an sh64 ELF linker hash table. */
3084 static struct bfd_link_hash_table
*
3085 sh64_elf64_link_hash_table_create (bfd
*abfd
)
3087 struct elf_sh64_link_hash_table
*ret
;
3089 ret
= ((struct elf_sh64_link_hash_table
*)
3090 bfd_malloc (sizeof (struct elf_sh64_link_hash_table
)));
3091 if (ret
== (struct elf_sh64_link_hash_table
*) NULL
)
3094 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3095 sh64_elf64_link_hash_newfunc
,
3096 sizeof (struct elf_sh64_link_hash_entry
)))
3102 return &ret
->root
.root
;
3106 movi_shori_putval (bfd
*output_bfd
, unsigned long value
, bfd_byte
*addr
)
3108 bfd_put_32 (output_bfd
,
3109 bfd_get_32 (output_bfd
, addr
)
3110 | ((value
>> 6) & 0x3fffc00),
3112 bfd_put_32 (output_bfd
,
3113 bfd_get_32 (output_bfd
, addr
+ 4)
3114 | ((value
<< 10) & 0x3fffc00),
3119 movi_3shori_putval (bfd
*output_bfd
, bfd_vma value
, bfd_byte
*addr
)
3121 bfd_put_32 (output_bfd
,
3122 bfd_get_32 (output_bfd
, addr
)
3123 | ((value
>> 38) & 0x3fffc00),
3125 bfd_put_32 (output_bfd
,
3126 bfd_get_32 (output_bfd
, addr
+ 4)
3127 | ((value
>> 22) & 0x3fffc00),
3129 bfd_put_32 (output_bfd
,
3130 bfd_get_32 (output_bfd
, addr
+ 8)
3131 | ((value
>> 6) & 0x3fffc00),
3133 bfd_put_32 (output_bfd
,
3134 bfd_get_32 (output_bfd
, addr
+ 12)
3135 | ((value
<< 10) & 0x3fffc00),
3139 /* Create dynamic sections when linking against a dynamic object. */
3142 sh64_elf64_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3144 flagword flags
, pltflags
;
3145 register asection
*s
;
3146 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3149 switch (bed
->s
->arch_size
)
3160 bfd_set_error (bfd_error_bad_value
);
3164 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3165 .rel[a].bss sections. */
3167 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3168 | SEC_LINKER_CREATED
);
3171 pltflags
|= SEC_CODE
;
3172 if (bed
->plt_not_loaded
)
3173 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3174 if (bed
->plt_readonly
)
3175 pltflags
|= SEC_READONLY
;
3177 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
3179 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3182 if (bed
->want_plt_sym
)
3184 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3186 struct elf_link_hash_entry
*h
;
3187 struct bfd_link_hash_entry
*bh
= NULL
;
3189 if (! (_bfd_generic_link_add_one_symbol
3190 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3191 (bfd_vma
) 0, (const char *) NULL
, FALSE
, bed
->collect
, &bh
)))
3194 h
= (struct elf_link_hash_entry
*) bh
;
3196 h
->type
= STT_OBJECT
;
3197 elf_hash_table (info
)->hplt
= h
;
3200 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3204 s
= bfd_make_section_with_flags (abfd
,
3205 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt",
3206 flags
| SEC_READONLY
);
3208 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3211 if (! _bfd_elf_create_got_section (abfd
, info
))
3215 const char *secname
;
3220 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3222 secflags
= bfd_get_section_flags (abfd
, sec
);
3223 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3224 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3226 secname
= bfd_get_section_name (abfd
, sec
);
3227 relname
= (char *) bfd_malloc (strlen (secname
) + 6);
3228 strcpy (relname
, ".rela");
3229 strcat (relname
, secname
);
3230 s
= bfd_make_section_with_flags (abfd
, relname
,
3231 flags
| SEC_READONLY
);
3233 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3238 if (bed
->want_dynbss
)
3240 /* The .dynbss section is a place to put symbols which are defined
3241 by dynamic objects, are referenced by regular objects, and are
3242 not functions. We must allocate space for them in the process
3243 image and use a R_*_COPY reloc to tell the dynamic linker to
3244 initialize them at run time. The linker script puts the .dynbss
3245 section into the .bss section of the final image. */
3246 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
3247 SEC_ALLOC
| SEC_LINKER_CREATED
);
3251 /* The .rel[a].bss section holds copy relocs. This section is not
3252 normally needed. We need to create it here, though, so that the
3253 linker will map it to an output section. We can't just create it
3254 only if we need it, because we will not know whether we need it
3255 until we have seen all the input files, and the first time the
3256 main linker code calls BFD after examining all the input files
3257 (size_dynamic_sections) the input sections have already been
3258 mapped to the output sections. If the section turns out not to
3259 be needed, we can discard it later. We will never need this
3260 section when generating a shared object, since they do not use
3264 s
= bfd_make_section_with_flags (abfd
,
3265 (bed
->default_use_rela_p
3266 ? ".rela.bss" : ".rel.bss"),
3267 flags
| SEC_READONLY
);
3269 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3277 /* Adjust a symbol defined by a dynamic object and referenced by a
3278 regular object. The current definition is in some section of the
3279 dynamic object, but we're not including those sections. We have to
3280 change the definition to something the rest of the link can
3284 sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3285 struct elf_link_hash_entry
*h
)
3290 dynobj
= elf_hash_table (info
)->dynobj
;
3292 /* Make sure we know what is going on here. */
3293 BFD_ASSERT (dynobj
!= NULL
3295 || h
->u
.weakdef
!= NULL
3298 && !h
->def_regular
)));
3300 /* If this is a function, put it in the procedure linkage table. We
3301 will fill in the contents of the procedure linkage table later,
3302 when we know the address of the .got section. */
3303 if (h
->type
== STT_FUNC
3310 /* This case can occur if we saw a PLT reloc in an input
3311 file, but the symbol was never referred to by a dynamic
3312 object. In such a case, we don't actually need to build
3313 a procedure linkage table, and we can just do a REL64
3315 BFD_ASSERT (h
->needs_plt
);
3319 /* Make sure this symbol is output as a dynamic symbol. */
3320 if (h
->dynindx
== -1)
3322 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3326 s
= bfd_get_section_by_name (dynobj
, ".plt");
3327 BFD_ASSERT (s
!= NULL
);
3329 /* If this is the first .plt entry, make room for the special
3332 s
->size
+= PLT_ENTRY_SIZE
;
3334 /* If this symbol is not defined in a regular file, and we are
3335 not generating a shared library, then set the symbol to this
3336 location in the .plt. This is required to make function
3337 pointers compare as equal between the normal executable and
3338 the shared library. */
3342 h
->root
.u
.def
.section
= s
;
3343 h
->root
.u
.def
.value
= s
->size
;
3346 h
->plt
.offset
= s
->size
;
3348 /* Make room for this entry. */
3349 s
->size
+= elf_sh64_sizeof_plt (info
);
3351 /* We also need to make an entry in the .got.plt section, which
3352 will be placed in the .got section by the linker script. */
3354 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3355 BFD_ASSERT (s
!= NULL
);
3358 /* We also need to make an entry in the .rela.plt section. */
3360 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3361 BFD_ASSERT (s
!= NULL
);
3362 s
->size
+= sizeof (Elf64_External_Rela
);
3367 /* If this is a weak symbol, and there is a real definition, the
3368 processor independent code will have arranged for us to see the
3369 real definition first, and we can just use the same value. */
3370 if (h
->u
.weakdef
!= NULL
)
3372 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3373 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3374 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3375 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3379 /* This is a reference to a symbol defined by a dynamic object which
3380 is not a function. */
3382 /* If we are creating a shared library, we must presume that the
3383 only references to the symbol are via the global offset table.
3384 For such cases we need not do anything here; the relocations will
3385 be handled correctly by relocate_section. */
3389 /* If there are no references to this symbol that do not use the
3390 GOT, we don't need to generate a copy reloc. */
3391 if (!h
->non_got_ref
)
3396 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
3397 h
->root
.root
.string
);
3401 /* We must allocate the symbol in our .dynbss section, which will
3402 become part of the .bss section of the executable. There will be
3403 an entry for this symbol in the .dynsym section. The dynamic
3404 object will contain position independent code, so all references
3405 from the dynamic object to this symbol will go through the global
3406 offset table. The dynamic linker will use the .dynsym entry to
3407 determine the address it must put in the global offset table, so
3408 both the dynamic object and the regular object will refer to the
3409 same memory location for the variable. */
3411 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3412 BFD_ASSERT (s
!= NULL
);
3414 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3415 copy the initial value out of the dynamic object and into the
3416 runtime process image. We need to remember the offset into the
3417 .rela.bss section we are going to use. */
3418 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3422 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3423 BFD_ASSERT (srel
!= NULL
);
3424 srel
->size
+= sizeof (Elf64_External_Rela
);
3428 return _bfd_elf_adjust_dynamic_copy (h
, s
);
3431 /* This function is called via sh_elf_link_hash_traverse if we are
3432 creating a shared object with -Bsymbolic. It discards the space
3433 allocated to copy PC relative relocs against symbols which are
3434 defined in regular objects. We allocated space for them in the
3435 check_relocs routine, but we won't fill them in in the
3436 relocate_section routine. */
3439 sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry
*h
,
3440 void *ignore ATTRIBUTE_UNUSED
)
3442 struct elf_sh64_pcrel_relocs_copied
*s
;
3444 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3445 h
= (struct elf_sh64_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3447 /* We only discard relocs for symbols defined in a regular object. */
3448 if (!h
->root
.def_regular
)
3451 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3452 s
->section
->size
-= s
->count
* sizeof (Elf64_External_Rela
);
3457 /* Set the sizes of the dynamic sections. */
3460 sh64_elf64_size_dynamic_sections (bfd
*output_bfd
,
3461 struct bfd_link_info
*info
)
3467 bfd_boolean reltext
;
3469 dynobj
= elf_hash_table (info
)->dynobj
;
3470 BFD_ASSERT (dynobj
!= NULL
);
3472 if (elf_hash_table (info
)->dynamic_sections_created
)
3474 /* Set the contents of the .interp section to the interpreter. */
3475 if (info
->executable
)
3477 s
= bfd_get_section_by_name (dynobj
, ".interp");
3478 BFD_ASSERT (s
!= NULL
);
3479 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3480 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3485 /* We may have created entries in the .rela.got section.
3486 However, if we are not creating the dynamic sections, we will
3487 not actually use these entries. Reset the size of .rela.got,
3488 which will cause it to get stripped from the output file
3490 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
3495 /* If this is a -Bsymbolic shared link, then we need to discard all
3496 PC relative relocs against symbols defined in a regular object.
3497 We allocated space for them in the check_relocs routine, but we
3498 will not fill them in in the relocate_section routine. */
3499 if (info
->shared
&& info
->symbolic
)
3500 sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info
),
3501 sh64_elf64_discard_copies
, NULL
);
3503 /* The check_relocs and adjust_dynamic_symbol entry points have
3504 determined the sizes of the various dynamic sections. Allocate
3509 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3513 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3516 /* It's OK to base decisions on the section name, because none
3517 of the dynobj section names depend upon the input files. */
3518 name
= bfd_get_section_name (dynobj
, s
);
3520 if (strcmp (name
, ".plt") == 0)
3522 /* Remember whether there is a PLT. */
3525 else if (CONST_STRNEQ (name
, ".rela"))
3531 /* Remember whether there are any reloc sections other
3533 if (strcmp (name
, ".rela.plt") != 0)
3535 const char *outname
;
3539 /* If this relocation section applies to a read only
3540 section, then we probably need a DT_TEXTREL
3541 entry. The entries in the .rela.plt section
3542 really apply to the .got section, which we
3543 created ourselves and so know is not readonly. */
3544 outname
= bfd_get_section_name (output_bfd
,
3546 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3548 && (target
->flags
& SEC_READONLY
) != 0
3549 && (target
->flags
& SEC_ALLOC
) != 0)
3553 /* We use the reloc_count field as a counter if we need
3554 to copy relocs into the output file. */
3558 else if (! CONST_STRNEQ (name
, ".got")
3559 && strcmp (name
, ".dynbss") != 0)
3561 /* It's not one of our sections, so don't allocate space. */
3567 /* If we don't need this section, strip it from the
3568 output file. This is mostly to handle .rela.bss and
3569 .rela.plt. We must create both sections in
3570 create_dynamic_sections, because they must be created
3571 before the linker maps input sections to output
3572 sections. The linker does that before
3573 adjust_dynamic_symbol is called, and it is that
3574 function which decides whether anything needs to go
3575 into these sections. */
3576 s
->flags
|= SEC_EXCLUDE
;
3580 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3583 /* Allocate memory for the section contents. */
3584 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3585 if (s
->contents
== NULL
)
3589 if (elf_hash_table (info
)->dynamic_sections_created
)
3591 /* Add some entries to the .dynamic section. We fill in the
3592 values later, in sh64_elf64_finish_dynamic_sections, but we
3593 must add the entries now so that we get the correct size for
3594 the .dynamic section. The DT_DEBUG entry is filled in by the
3595 dynamic linker and used by the debugger. */
3596 if (info
->executable
)
3598 if (!_bfd_elf_add_dynamic_entry (info
, DT_DEBUG
, 0))
3604 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0)
3605 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3606 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3607 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
3613 if (!_bfd_elf_add_dynamic_entry (info
, DT_RELA
, 0)
3614 || !_bfd_elf_add_dynamic_entry (info
, DT_RELASZ
, 0)
3615 || !_bfd_elf_add_dynamic_entry (info
, DT_RELAENT
,
3616 sizeof (Elf64_External_Rela
)))
3622 if (!_bfd_elf_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3630 /* Finish up dynamic symbol handling. We set the contents of various
3631 dynamic sections here. */
3634 sh64_elf64_finish_dynamic_symbol (bfd
*output_bfd
,
3635 struct bfd_link_info
*info
,
3636 struct elf_link_hash_entry
*h
,
3637 Elf_Internal_Sym
*sym
)
3641 dynobj
= elf_hash_table (info
)->dynobj
;
3643 if (h
->plt
.offset
!= (bfd_vma
) -1)
3651 Elf_Internal_Rela rel
;
3654 /* This symbol has an entry in the procedure linkage table. Set
3657 BFD_ASSERT (h
->dynindx
!= -1);
3659 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3660 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3661 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3662 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3664 /* Get the index in the procedure linkage table which
3665 corresponds to this symbol. This is the index of this symbol
3666 in all the symbols for which we are making plt entries. The
3667 first entry in the procedure linkage table is reserved. */
3668 plt_index
= h
->plt
.offset
/ elf_sh64_sizeof_plt (info
) - 1;
3670 /* Get the offset into the .got table of the entry that
3671 corresponds to this function. Each .got entry is 8 bytes.
3672 The first three are reserved. */
3673 got_offset
= (plt_index
+ 3) * 8;
3676 got_offset
-= GOT_BIAS
;
3678 /* Fill in the entry in the procedure linkage table. */
3681 if (elf_sh64_plt_entry
== NULL
)
3683 elf_sh64_plt_entry
= (bfd_big_endian (output_bfd
) ?
3684 elf_sh64_plt_entry_be
: elf_sh64_plt_entry_le
);
3686 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_plt_entry
,
3687 elf_sh64_sizeof_plt (info
));
3688 movi_3shori_putval (output_bfd
,
3689 (sgot
->output_section
->vma
3690 + sgot
->output_offset
3692 (splt
->contents
+ h
->plt
.offset
3693 + elf_sh64_plt_symbol_offset (info
)));
3695 /* Set bottom bit because its for a branch to SHmedia */
3696 movi_shori_putval (output_bfd
,
3698 + elf_sh64_plt_plt0_offset (info
) + 8)
3700 (splt
->contents
+ h
->plt
.offset
3701 + elf_sh64_plt_plt0_offset (info
)));
3705 if (elf_sh64_pic_plt_entry
== NULL
)
3707 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3708 elf_sh64_pic_plt_entry_be
:
3709 elf_sh64_pic_plt_entry_le
);
3711 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_pic_plt_entry
,
3712 elf_sh64_sizeof_plt (info
));
3713 movi_shori_putval (output_bfd
, got_offset
,
3714 (splt
->contents
+ h
->plt
.offset
3715 + elf_sh64_plt_symbol_offset (info
)));
3719 got_offset
+= GOT_BIAS
;
3721 movi_shori_putval (output_bfd
,
3722 plt_index
* sizeof (Elf64_External_Rela
),
3723 (splt
->contents
+ h
->plt
.offset
3724 + elf_sh64_plt_reloc_offset (info
)));
3726 /* Fill in the entry in the global offset table. */
3727 bfd_put_64 (output_bfd
,
3728 (splt
->output_section
->vma
3729 + splt
->output_offset
3731 + elf_sh64_plt_temp_offset (info
)),
3732 sgot
->contents
+ got_offset
);
3734 /* Fill in the entry in the .rela.plt section. */
3735 rel
.r_offset
= (sgot
->output_section
->vma
3736 + sgot
->output_offset
3738 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_JMP_SLOT64
);
3740 rel
.r_addend
= GOT_BIAS
;
3741 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3742 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3744 if (!h
->def_regular
)
3746 /* Mark the symbol as undefined, rather than as defined in
3747 the .plt section. Leave the value alone. */
3748 sym
->st_shndx
= SHN_UNDEF
;
3752 if (h
->got
.offset
!= (bfd_vma
) -1)
3756 Elf_Internal_Rela rel
;
3759 /* This symbol has an entry in the global offset table. Set it
3762 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3763 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3764 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3766 rel
.r_offset
= (sgot
->output_section
->vma
3767 + sgot
->output_offset
3768 + (h
->got
.offset
&~ 1));
3770 /* If this is a -Bsymbolic link, and the symbol is defined
3771 locally, we just want to emit a RELATIVE reloc. Likewise if
3772 the symbol was forced to be local because of a version file.
3773 The entry in the global offset table will already have been
3774 initialized in the relocate_section function. */
3776 && (info
->symbolic
|| h
->dynindx
== -1)
3779 rel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
3780 rel
.r_addend
= (h
->root
.u
.def
.value
3781 + h
->root
.u
.def
.section
->output_section
->vma
3782 + h
->root
.u
.def
.section
->output_offset
);
3786 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3787 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_GLOB_DAT64
);
3791 loc
= srel
->contents
;
3792 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3793 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3799 Elf_Internal_Rela rel
;
3802 /* This symbol needs a copy reloc. Set it up. */
3804 BFD_ASSERT (h
->dynindx
!= -1
3805 && (h
->root
.type
== bfd_link_hash_defined
3806 || h
->root
.type
== bfd_link_hash_defweak
));
3808 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3810 BFD_ASSERT (s
!= NULL
);
3812 rel
.r_offset
= (h
->root
.u
.def
.value
3813 + h
->root
.u
.def
.section
->output_section
->vma
3814 + h
->root
.u
.def
.section
->output_offset
);
3815 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_COPY64
);
3818 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3819 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3822 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3823 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3824 || h
== elf_hash_table (info
)->hgot
)
3825 sym
->st_shndx
= SHN_ABS
;
3830 /* Finish up the dynamic sections. */
3833 sh64_elf64_finish_dynamic_sections (bfd
*output_bfd
,
3834 struct bfd_link_info
*info
)
3840 dynobj
= elf_hash_table (info
)->dynobj
;
3842 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3843 BFD_ASSERT (sgot
!= NULL
);
3844 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3846 if (elf_hash_table (info
)->dynamic_sections_created
)
3849 Elf64_External_Dyn
*dyncon
, *dynconend
;
3851 BFD_ASSERT (sdyn
!= NULL
);
3853 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3854 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3855 for (; dyncon
< dynconend
; dyncon
++)
3857 Elf_Internal_Dyn dyn
;
3860 struct elf_link_hash_entry
*h
;
3862 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3870 name
= info
->init_function
;
3874 name
= info
->fini_function
;
3876 if (dyn
.d_un
.d_val
!= 0)
3878 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
3879 FALSE
, FALSE
, TRUE
);
3880 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
3882 dyn
.d_un
.d_val
|= 1;
3883 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3895 s
= bfd_get_section_by_name (output_bfd
, name
);
3896 BFD_ASSERT (s
!= NULL
);
3897 dyn
.d_un
.d_ptr
= s
->vma
;
3898 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3902 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
3903 BFD_ASSERT (s
!= NULL
);
3904 dyn
.d_un
.d_val
= s
->size
;
3905 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3909 /* My reading of the SVR4 ABI indicates that the
3910 procedure linkage table relocs (DT_JMPREL) should be
3911 included in the overall relocs (DT_RELA). This is
3912 what Solaris does. However, UnixWare can not handle
3913 that case. Therefore, we override the DT_RELASZ entry
3914 here to make it not include the JMPREL relocs. Since
3915 the linker script arranges for .rela.plt to follow all
3916 other relocation sections, we don't have to worry
3917 about changing the DT_RELA entry. */
3918 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
3920 dyn
.d_un
.d_val
-= s
->size
;
3921 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3926 /* Fill in the first entry in the procedure linkage table. */
3927 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3928 if (splt
&& splt
->size
> 0)
3932 if (elf_sh64_pic_plt_entry
== NULL
)
3934 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3935 elf_sh64_pic_plt_entry_be
:
3936 elf_sh64_pic_plt_entry_le
);
3938 memcpy (splt
->contents
, elf_sh64_pic_plt_entry
,
3939 elf_sh64_sizeof_plt (info
));
3943 if (elf_sh64_plt0_entry
== NULL
)
3945 elf_sh64_plt0_entry
= (bfd_big_endian (output_bfd
) ?
3946 elf_sh64_plt0_entry_be
:
3947 elf_sh64_plt0_entry_le
);
3949 memcpy (splt
->contents
, elf_sh64_plt0_entry
, PLT_ENTRY_SIZE
);
3950 movi_3shori_putval (output_bfd
,
3951 sgot
->output_section
->vma
3952 + sgot
->output_offset
,
3954 + elf_sh64_plt0_gotplt_offset (info
));
3957 /* UnixWare sets the entsize of .plt to 8, although that doesn't
3958 really seem like the right value. */
3959 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 8;
3963 /* Fill in the first three entries in the global offset table. */
3967 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
3969 bfd_put_64 (output_bfd
,
3970 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3972 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
3973 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 16);
3976 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
3981 /* Merge non visibility st_other attribute when the symbol comes from
3982 a dynamic object. */
3984 sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3985 const Elf_Internal_Sym
*isym
,
3986 bfd_boolean definition
,
3987 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
3989 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
3991 unsigned char other
;
3993 /* Take the balance of OTHER from the definition. */
3994 other
= (definition
? isym
->st_other
: h
->other
);
3995 other
&= ~ ELF_ST_VISIBILITY (-1);
3996 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
4002 static const struct bfd_elf_special_section sh64_elf64_special_sections
[]=
4004 { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS
, 0 },
4005 { NULL
, 0, 0, 0, 0 }
4008 #define TARGET_BIG_SYM bfd_elf64_sh64_vec
4009 #define TARGET_BIG_NAME "elf64-sh64"
4010 #define TARGET_LITTLE_SYM bfd_elf64_sh64l_vec
4011 #define TARGET_LITTLE_NAME "elf64-sh64l"
4012 #define ELF_ARCH bfd_arch_sh
4013 #define ELF_MACHINE_CODE EM_SH
4014 #define ELF_MAXPAGESIZE 128
4016 #define elf_symbol_leading_char '_'
4018 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
4019 #define bfd_elf64_bfd_reloc_name_lookup \
4020 sh_elf64_reloc_name_lookup
4021 #define elf_info_to_howto sh_elf64_info_to_howto
4023 /* Note: there's no relaxation at present. */
4025 #define elf_backend_relocate_section sh_elf64_relocate_section
4026 #define bfd_elf64_bfd_get_relocated_section_contents \
4027 sh_elf64_get_relocated_section_contents
4028 #define elf_backend_object_p sh_elf64_set_mach_from_flags
4029 #define bfd_elf64_bfd_set_private_flags \
4030 sh_elf64_set_private_flags
4031 #define bfd_elf64_bfd_copy_private_bfd_data \
4032 sh_elf64_copy_private_data
4033 #define bfd_elf64_bfd_merge_private_bfd_data \
4034 sh_elf64_merge_private_data
4035 #define elf_backend_fake_sections sh64_elf64_fake_sections
4037 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
4038 #define elf_backend_check_relocs sh_elf64_check_relocs
4040 #define elf_backend_can_gc_sections 1
4042 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
4044 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
4046 #define elf_backend_link_output_symbol_hook \
4047 sh64_elf64_link_output_symbol_hook
4049 #define elf_backend_merge_symbol_attribute \
4050 sh64_elf64_merge_symbol_attribute
4052 #define elf_backend_final_write_processing \
4053 sh64_elf64_final_write_processing
4055 #define elf_backend_create_dynamic_sections \
4056 sh64_elf64_create_dynamic_sections
4057 #define bfd_elf64_bfd_link_hash_table_create \
4058 sh64_elf64_link_hash_table_create
4059 #define elf_backend_adjust_dynamic_symbol \
4060 sh64_elf64_adjust_dynamic_symbol
4061 #define elf_backend_size_dynamic_sections \
4062 sh64_elf64_size_dynamic_sections
4063 #define elf_backend_omit_section_dynsym \
4064 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4065 #define elf_backend_finish_dynamic_symbol \
4066 sh64_elf64_finish_dynamic_symbol
4067 #define elf_backend_finish_dynamic_sections \
4068 sh64_elf64_finish_dynamic_sections
4069 #define elf_backend_special_sections sh64_elf64_special_sections
4071 #define elf_backend_want_got_plt 1
4072 #define elf_backend_plt_readonly 1
4073 #define elf_backend_want_plt_sym 0
4074 #define elf_backend_got_header_size 24
4076 #include "elf64-target.h"
4078 /* NetBSD support. */
4079 #undef TARGET_BIG_SYM
4080 #define TARGET_BIG_SYM bfd_elf64_sh64nbsd_vec
4081 #undef TARGET_BIG_NAME
4082 #define TARGET_BIG_NAME "elf64-sh64-nbsd"
4083 #undef TARGET_LITTLE_SYM
4084 #define TARGET_LITTLE_SYM bfd_elf64_sh64lnbsd_vec
4085 #undef TARGET_LITTLE_NAME
4086 #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd"
4087 #undef ELF_MAXPAGESIZE
4088 #define ELF_MAXPAGESIZE 0x10000
4089 #undef elf_symbol_leading_char
4090 #define elf_symbol_leading_char 0
4092 #define elf64_bed elf64_sh64_nbsd_bed
4094 #include "elf64-target.h"
4096 /* Linux support. */
4097 #undef TARGET_BIG_SYM
4098 #define TARGET_BIG_SYM bfd_elf64_sh64blin_vec
4099 #undef TARGET_BIG_NAME
4100 #define TARGET_BIG_NAME "elf64-sh64big-linux"
4101 #undef TARGET_LITTLE_SYM
4102 #define TARGET_LITTLE_SYM bfd_elf64_sh64lin_vec
4103 #undef TARGET_LITTLE_NAME
4104 #define TARGET_LITTLE_NAME "elf64-sh64-linux"
4106 #define elf64_bed elf64_sh64_linux_bed
4108 #include "elf64-target.h"