1 /* SuperH SH64-specific support for 64-bit ELF
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
30 /* Add a suffix for datalabel indirection symbols. It must not match any
31 other symbols; user symbols with or without version or other
32 decoration. It must only be used internally and not emitted by any
34 #define DATALABEL_SUFFIX " DL"
36 #define GOT_BIAS (-((long)-32768))
38 #define PLT_ENTRY_SIZE 64
40 /* Return size of a PLT entry. */
41 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
43 /* Return offset of the PLT0 address in an absolute PLT entry. */
44 #define elf_sh64_plt_plt0_offset(info) 32
46 /* Return offset of the linker in PLT0 entry. */
47 #define elf_sh64_plt0_gotplt_offset(info) 0
49 /* Return offset of the trampoline in PLT entry */
50 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
52 /* Return offset of the symbol in PLT entry. */
53 #define elf_sh64_plt_symbol_offset(info) 0
55 /* Return offset of the relocation in PLT entry. */
56 #define elf_sh64_plt_reloc_offset(info) (bfd_link_pic (info) ? 52 : 44)
58 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
60 /* The sh linker needs to keep track of the number of relocs that it
61 decides to copy in check_relocs for each symbol. This is so that
62 it can discard PC relative relocs if it doesn't need them when
63 linking with -Bsymbolic. We store the information in a field
64 extending the regular ELF linker hash table. */
66 /* This structure keeps track of the number of PC relative relocs we
67 have copied for a given symbol. */
69 struct elf_sh64_pcrel_relocs_copied
72 struct elf_sh64_pcrel_relocs_copied
*next
;
73 /* A section in dynobj. */
75 /* Number of relocs copied in this section. */
79 /* sh ELF linker hash entry. */
81 struct elf_sh64_link_hash_entry
83 struct elf_link_hash_entry root
;
85 bfd_vma datalabel_got_offset
;
87 /* Number of PC relative relocs copied for this symbol. */
88 struct elf_sh64_pcrel_relocs_copied
*pcrel_relocs_copied
;
91 /* Traverse an sh ELF linker hash table. */
93 #define sh64_elf64_link_hash_traverse(table, func, info) \
94 (elf_link_hash_traverse \
96 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
99 static bfd_reloc_status_type sh_elf64_ignore_reloc
100 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
101 static bfd_reloc_status_type sh_elf64_reloc
102 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
104 static reloc_howto_type sh_elf64_howto_table
[] = {
106 HOWTO (R_SH_NONE
, /* type */
108 3, /* size (0 = byte, 1 = short, 2 = long) */
110 FALSE
, /* pc_relative */
112 complain_overflow_dont
, /* complain_on_overflow */
113 sh_elf64_ignore_reloc
, /* special_function */
114 "R_SH_NONE", /* name */
115 FALSE
, /* partial_inplace */
118 FALSE
), /* pcrel_offset */
120 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
121 src_mask to a non-zero value is similar to the COFF toolchain. */
122 HOWTO (R_SH_DIR32
, /* type */
124 2, /* size (0 = byte, 1 = short, 2 = long) */
126 FALSE
, /* pc_relative */
128 complain_overflow_bitfield
, /* complain_on_overflow */
129 sh_elf64_reloc
, /* special_function */
130 "R_SH_DIR32", /* name */
131 TRUE
, /* partial_inplace */
132 0xffffffff, /* src_mask */
133 0xffffffff, /* dst_mask */
134 FALSE
), /* pcrel_offset */
136 /* 32 bit PC relative relocation. */
137 HOWTO (R_SH_REL32
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 TRUE
, /* pc_relative */
143 complain_overflow_signed
, /* complain_on_overflow */
144 sh_elf64_ignore_reloc
, /* special_function */
145 "R_SH_REL32", /* name */
146 FALSE
, /* partial_inplace */
148 0xffffffff, /* dst_mask */
149 TRUE
), /* pcrel_offset */
151 /* For 32-bit sh, this is R_SH_DIR8WPN. */
154 /* For 32-bit sh, this is R_SH_IND12W. */
157 /* For 32-bit sh, this is R_SH_DIR8WPL. */
160 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
163 /* For 32-bit sh, this is R_SH_DIR8BP. */
166 /* For 32-bit sh, this is R_SH_DIR8W. */
169 /* For 32-bit sh, this is R_SH_DIR8L. */
188 /* The remaining relocs are a GNU extension used for relaxing. The
189 final pass of the linker never needs to do anything with any of
190 these relocs. Any required operations are handled by the
193 /* A 16 bit switch table entry. This is generated for an expression
194 such as ``.word L1 - L2''. The offset holds the difference
195 between the reloc address and L2. */
196 HOWTO (R_SH_SWITCH16
, /* type */
198 1, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE
, /* pc_relative */
202 complain_overflow_unsigned
, /* complain_on_overflow */
203 sh_elf64_ignore_reloc
, /* special_function */
204 "R_SH_SWITCH16", /* name */
205 FALSE
, /* partial_inplace */
208 TRUE
), /* pcrel_offset */
210 /* A 32 bit switch table entry. This is generated for an expression
211 such as ``.long L1 - L2''. The offset holds the difference
212 between the reloc address and L2. */
213 HOWTO (R_SH_SWITCH32
, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE
, /* pc_relative */
219 complain_overflow_unsigned
, /* complain_on_overflow */
220 sh_elf64_ignore_reloc
, /* special_function */
221 "R_SH_SWITCH32", /* name */
222 FALSE
, /* partial_inplace */
225 TRUE
), /* pcrel_offset */
227 /* For 32-bit sh, this is R_SH_USES. */
230 /* For 32-bit sh, this is R_SH_COUNT. */
233 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
234 this might be emitted. When linker relaxation is implemented, we
235 might want to use it. */
238 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
239 this might be emitted. When linker relaxation is implemented, we
240 might want to use it. */
243 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
244 this might be emitted. When linker relaxation is implemented, we
245 might want to use it. */
248 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
249 this might be emitted. When linker relaxation is implemented, we
250 might want to use it. */
253 /* An 8 bit switch table entry. This is generated for an expression
254 such as ``.word L1 - L2''. The offset holds the difference
255 between the reloc address and L2. */
256 HOWTO (R_SH_SWITCH8
, /* type */
258 0, /* size (0 = byte, 1 = short, 2 = long) */
260 FALSE
, /* pc_relative */
262 complain_overflow_unsigned
, /* complain_on_overflow */
263 sh_elf64_ignore_reloc
, /* special_function */
264 "R_SH_SWITCH8", /* name */
265 FALSE
, /* partial_inplace */
268 TRUE
), /* pcrel_offset */
270 /* GNU extension to record C++ vtable hierarchy */
271 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 FALSE
, /* pc_relative */
277 complain_overflow_dont
, /* complain_on_overflow */
278 NULL
, /* special_function */
279 "R_SH_GNU_VTINHERIT", /* name */
280 FALSE
, /* partial_inplace */
283 FALSE
), /* pcrel_offset */
285 /* GNU extension to record C++ vtable member usage */
286 HOWTO (R_SH_GNU_VTENTRY
, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 FALSE
, /* pc_relative */
292 complain_overflow_dont
, /* complain_on_overflow */
293 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
294 "R_SH_GNU_VTENTRY", /* name */
295 FALSE
, /* partial_inplace */
298 FALSE
), /* pcrel_offset */
300 /* For 32-bit sh, this is R_SH_LOOP_START. */
303 /* For 32-bit sh, this is R_SH_LOOP_END. */
314 /* Used in SHLLI.L and SHLRI.L. */
315 HOWTO (R_SH_DIR5U
, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 FALSE
, /* pc_relative */
321 complain_overflow_unsigned
, /* complain_on_overflow */
322 bfd_elf_generic_reloc
, /* special_function */
323 "R_SH_DIR5U", /* name */
324 FALSE
, /* partial_inplace */
326 0xfc00, /* dst_mask */
327 FALSE
), /* pcrel_offset */
329 /* Used in SHARI, SHLLI et al. */
330 HOWTO (R_SH_DIR6U
, /* type */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
334 FALSE
, /* pc_relative */
336 complain_overflow_unsigned
, /* complain_on_overflow */
337 bfd_elf_generic_reloc
, /* special_function */
338 "R_SH_DIR6U", /* name */
339 FALSE
, /* partial_inplace */
341 0xfc00, /* dst_mask */
342 FALSE
), /* pcrel_offset */
344 /* Used in BxxI, LDHI.L et al. */
345 HOWTO (R_SH_DIR6S
, /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 FALSE
, /* pc_relative */
351 complain_overflow_signed
, /* complain_on_overflow */
352 bfd_elf_generic_reloc
, /* special_function */
353 "R_SH_DIR6S", /* name */
354 FALSE
, /* partial_inplace */
356 0xfc00, /* dst_mask */
357 FALSE
), /* pcrel_offset */
359 /* Used in ADDI, ANDI et al. */
360 HOWTO (R_SH_DIR10S
, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 FALSE
, /* pc_relative */
366 complain_overflow_signed
, /* complain_on_overflow */
367 bfd_elf_generic_reloc
, /* special_function */
368 "R_SH_DIR10S", /* name */
369 FALSE
, /* partial_inplace */
371 0xffc00, /* dst_mask */
372 FALSE
), /* pcrel_offset */
374 /* Used in LD.UW, ST.W et al. */
375 HOWTO (R_SH_DIR10SW
, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 FALSE
, /* pc_relative */
381 complain_overflow_signed
, /* complain_on_overflow */
382 bfd_elf_generic_reloc
, /* special_function */
383 "R_SH_DIR10SW", /* name */
384 FALSE
, /* partial_inplace */
386 0xffc00, /* dst_mask */
387 FALSE
), /* pcrel_offset */
389 /* Used in LD.L, FLD.S et al. */
390 HOWTO (R_SH_DIR10SL
, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 FALSE
, /* pc_relative */
396 complain_overflow_signed
, /* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_SH_DIR10SL", /* name */
399 FALSE
, /* partial_inplace */
401 0xffc00, /* dst_mask */
402 FALSE
), /* pcrel_offset */
404 /* Used in FLD.D, FST.P et al. */
405 HOWTO (R_SH_DIR10SQ
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 FALSE
, /* pc_relative */
411 complain_overflow_signed
, /* complain_on_overflow */
412 bfd_elf_generic_reloc
, /* special_function */
413 "R_SH_DIR10SQ", /* name */
414 FALSE
, /* partial_inplace */
416 0xffc00, /* dst_mask */
417 FALSE
), /* pcrel_offset */
528 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
529 any dynamic linking support for 64-bit SH at present. */
541 /* Back to SH5 relocations. */
542 /* Used in MOVI and SHORI (x & 65536). */
543 HOWTO (R_SH_GOT_LOW16
, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 FALSE
, /* pc_relative */
549 complain_overflow_dont
, /* complain_on_overflow */
550 bfd_elf_generic_reloc
, /* special_function */
551 "R_SH_GOT_LOW16", /* name */
552 FALSE
, /* partial_inplace */
554 0x3fffc00, /* dst_mask */
555 FALSE
), /* pcrel_offset */
557 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
558 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
560 2, /* size (0 = byte, 1 = short, 2 = long) */
562 FALSE
, /* pc_relative */
564 complain_overflow_dont
, /* complain_on_overflow */
565 bfd_elf_generic_reloc
, /* special_function */
566 "R_SH_GOT_MEDLOW16", /* name */
567 FALSE
, /* partial_inplace */
569 0x3fffc00, /* dst_mask */
570 FALSE
), /* pcrel_offset */
572 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
573 HOWTO (R_SH_GOT_MEDHI16
, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_dont
, /* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 "R_SH_GOT_MEDHI16", /* name */
582 FALSE
, /* partial_inplace */
584 0x3fffc00, /* dst_mask */
585 FALSE
), /* pcrel_offset */
587 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
588 HOWTO (R_SH_GOT_HI16
, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 bfd_elf_generic_reloc
, /* special_function */
596 "R_SH_GOT_HI16", /* name */
597 FALSE
, /* partial_inplace */
599 0x3fffc00, /* dst_mask */
600 FALSE
), /* pcrel_offset */
602 /* Used in MOVI and SHORI (x & 65536). */
603 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 FALSE
, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_SH_GOTPLT_LOW16", /* name */
612 FALSE
, /* partial_inplace */
614 0x3fffc00, /* dst_mask */
615 FALSE
), /* pcrel_offset */
617 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
618 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 FALSE
, /* pc_relative */
624 complain_overflow_dont
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_SH_GOTPLT_MEDLOW16", /* name */
627 FALSE
, /* partial_inplace */
629 0x3fffc00, /* dst_mask */
630 FALSE
), /* pcrel_offset */
632 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
633 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 FALSE
, /* pc_relative */
639 complain_overflow_dont
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_SH_GOTPLT_MEDHI16", /* name */
642 FALSE
, /* partial_inplace */
644 0x3fffc00, /* dst_mask */
645 FALSE
), /* pcrel_offset */
647 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
648 HOWTO (R_SH_GOTPLT_HI16
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 FALSE
, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_SH_GOTPLT_HI16", /* name */
657 FALSE
, /* partial_inplace */
659 0x3fffc00, /* dst_mask */
660 FALSE
), /* pcrel_offset */
662 /* Used in MOVI and SHORI (x & 65536). */
663 HOWTO (R_SH_PLT_LOW16
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE
, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_SH_PLT_LOW16", /* name */
672 FALSE
, /* partial_inplace */
674 0x3fffc00, /* dst_mask */
675 TRUE
), /* pcrel_offset */
677 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
678 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 TRUE
, /* pc_relative */
684 complain_overflow_dont
, /* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 "R_SH_PLT_MEDLOW16", /* name */
687 FALSE
, /* partial_inplace */
689 0x3fffc00, /* dst_mask */
690 TRUE
), /* pcrel_offset */
692 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
693 HOWTO (R_SH_PLT_MEDHI16
, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 TRUE
, /* pc_relative */
699 complain_overflow_dont
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_SH_PLT_MEDHI16", /* name */
702 FALSE
, /* partial_inplace */
704 0x3fffc00, /* dst_mask */
705 TRUE
), /* pcrel_offset */
707 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
708 HOWTO (R_SH_PLT_HI16
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 TRUE
, /* pc_relative */
714 complain_overflow_dont
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_SH_PLT_HI16", /* name */
717 FALSE
, /* partial_inplace */
719 0x3fffc00, /* dst_mask */
720 TRUE
), /* pcrel_offset */
722 /* Used in MOVI and SHORI (x & 65536). */
723 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 FALSE
, /* pc_relative */
729 complain_overflow_dont
, /* complain_on_overflow */
730 bfd_elf_generic_reloc
, /* special_function */
731 "R_SH_GOTOFF_LOW16", /* name */
732 FALSE
, /* partial_inplace */
734 0x3fffc00, /* dst_mask */
735 FALSE
), /* pcrel_offset */
737 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
738 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 FALSE
, /* pc_relative */
744 complain_overflow_dont
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* special_function */
746 "R_SH_GOTOFF_MEDLOW16", /* name */
747 FALSE
, /* partial_inplace */
749 0x3fffc00, /* dst_mask */
750 FALSE
), /* pcrel_offset */
752 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
753 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 FALSE
, /* pc_relative */
759 complain_overflow_dont
, /* complain_on_overflow */
760 bfd_elf_generic_reloc
, /* special_function */
761 "R_SH_GOTOFF_MEDHI16", /* name */
762 FALSE
, /* partial_inplace */
764 0x3fffc00, /* dst_mask */
765 FALSE
), /* pcrel_offset */
767 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
768 HOWTO (R_SH_GOTOFF_HI16
, /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 FALSE
, /* pc_relative */
774 complain_overflow_dont
, /* complain_on_overflow */
775 bfd_elf_generic_reloc
, /* special_function */
776 "R_SH_GOTOFF_HI16", /* name */
777 FALSE
, /* partial_inplace */
779 0x3fffc00, /* dst_mask */
780 FALSE
), /* pcrel_offset */
782 /* Used in MOVI and SHORI (x & 65536). */
783 HOWTO (R_SH_GOTPC_LOW16
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 TRUE
, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_SH_GOTPC_LOW16", /* name */
792 FALSE
, /* partial_inplace */
794 0x3fffc00, /* dst_mask */
795 TRUE
), /* pcrel_offset */
797 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
798 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 TRUE
, /* pc_relative */
804 complain_overflow_dont
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 "R_SH_GOTPC_MEDLOW16", /* name */
807 FALSE
, /* partial_inplace */
809 0x3fffc00, /* dst_mask */
810 TRUE
), /* pcrel_offset */
812 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
813 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 TRUE
, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 "R_SH_GOTPC_MEDHI16", /* name */
822 FALSE
, /* partial_inplace */
824 0x3fffc00, /* dst_mask */
825 TRUE
), /* pcrel_offset */
827 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
828 HOWTO (R_SH_GOTPC_HI16
, /* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 TRUE
, /* pc_relative */
834 complain_overflow_dont
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_SH_GOTPC_HI16", /* name */
837 FALSE
, /* partial_inplace */
839 0x3fffc00, /* dst_mask */
840 TRUE
), /* pcrel_offset */
842 /* Used in LD.L, FLD.S et al. */
843 HOWTO (R_SH_GOT10BY4
, /* type */
845 2, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_signed
, /* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 "R_SH_GOT10BY4", /* name */
852 FALSE
, /* partial_inplace */
854 0xffc00, /* dst_mask */
855 FALSE
), /* pcrel_offset */
857 /* Used in LD.L, FLD.S et al. */
858 HOWTO (R_SH_GOTPLT10BY4
, /* type */
860 2, /* size (0 = byte, 1 = short, 2 = long) */
862 FALSE
, /* pc_relative */
864 complain_overflow_signed
, /* complain_on_overflow */
865 bfd_elf_generic_reloc
, /* special_function */
866 "R_SH_GOTPLT10BY4", /* name */
867 FALSE
, /* partial_inplace */
869 0xffc00, /* dst_mask */
870 FALSE
), /* pcrel_offset */
872 /* Used in FLD.D, FST.P et al. */
873 HOWTO (R_SH_GOT10BY8
, /* type */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
877 FALSE
, /* pc_relative */
879 complain_overflow_signed
, /* complain_on_overflow */
880 bfd_elf_generic_reloc
, /* special_function */
881 "R_SH_GOT10BY8", /* name */
882 FALSE
, /* partial_inplace */
884 0xffc00, /* dst_mask */
885 FALSE
), /* pcrel_offset */
887 /* Used in FLD.D, FST.P et al. */
888 HOWTO (R_SH_GOTPLT10BY8
, /* type */
890 2, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_signed
, /* complain_on_overflow */
895 bfd_elf_generic_reloc
, /* special_function */
896 "R_SH_GOTPLT10BY8", /* name */
897 FALSE
, /* partial_inplace */
899 0xffc00, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 HOWTO (R_SH_COPY64
, /* type */
904 4, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE
, /* pc_relative */
908 complain_overflow_dont
, /* complain_on_overflow */
909 bfd_elf_generic_reloc
, /* special_function */
910 "R_SH_COPY64", /* name */
911 FALSE
, /* partial_inplace */
913 ((bfd_vma
) 0) - 1, /* dst_mask */
914 FALSE
), /* pcrel_offset */
916 HOWTO (R_SH_GLOB_DAT64
, /* type */
918 4, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE
, /* pc_relative */
922 complain_overflow_dont
, /* complain_on_overflow */
923 bfd_elf_generic_reloc
, /* special_function */
924 "R_SH_GLOB_DAT64", /* name */
925 FALSE
, /* partial_inplace */
927 ((bfd_vma
) 0) - 1, /* dst_mask */
928 FALSE
), /* pcrel_offset */
930 HOWTO (R_SH_JMP_SLOT64
, /* type */
932 4, /* size (0 = byte, 1 = short, 2 = long) */
934 FALSE
, /* pc_relative */
936 complain_overflow_dont
, /* complain_on_overflow */
937 bfd_elf_generic_reloc
, /* special_function */
938 "R_SH_JMP_SLOT64", /* name */
939 FALSE
, /* partial_inplace */
941 ((bfd_vma
) 0) - 1, /* dst_mask */
942 FALSE
), /* pcrel_offset */
944 HOWTO (R_SH_RELATIVE64
, /* type */
946 4, /* size (0 = byte, 1 = short, 2 = long) */
948 FALSE
, /* pc_relative */
950 complain_overflow_dont
, /* complain_on_overflow */
951 bfd_elf_generic_reloc
, /* special_function */
952 "R_SH_RELATIVE64", /* name */
953 FALSE
, /* partial_inplace */
955 ((bfd_vma
) 0) - 1, /* dst_mask */
956 FALSE
), /* pcrel_offset */
1004 /* Relocations for SHmedia code. None of these are partial_inplace or
1005 use the field being relocated. */
1007 /* The assembler will generate this reloc before a block of SHmedia
1008 instructions. A section should be processed as assuming it contains
1009 data, unless this reloc is seen. Note that a block of SHcompact
1010 instructions are instead preceded by R_SH_CODE.
1011 This is currently not implemented, but should be used for SHmedia
1012 linker relaxation. */
1013 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_unsigned
, /* complain_on_overflow */
1020 sh_elf64_ignore_reloc
, /* special_function */
1021 "R_SH_SHMEDIA_CODE", /* name */
1022 FALSE
, /* partial_inplace */
1025 FALSE
), /* pcrel_offset */
1027 /* The assembler will generate this reloc at a PTA or PTB instruction,
1028 and the linker checks the right type of target, or changes a PTA to a
1029 PTB, if the original insn was PT. */
1030 HOWTO (R_SH_PT_16
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 TRUE
, /* pc_relative */
1036 complain_overflow_signed
, /* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_SH_PT_16", /* name */
1039 FALSE
, /* partial_inplace */
1041 0x3fffc00, /* dst_mask */
1042 TRUE
), /* pcrel_offset */
1044 /* Used in unexpanded MOVI. */
1045 HOWTO (R_SH_IMMS16
, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 FALSE
, /* pc_relative */
1051 complain_overflow_signed
, /* complain_on_overflow */
1052 bfd_elf_generic_reloc
, /* special_function */
1053 "R_SH_IMMS16", /* name */
1054 FALSE
, /* partial_inplace */
1056 0x3fffc00, /* dst_mask */
1057 FALSE
), /* pcrel_offset */
1059 /* Used in SHORI. */
1060 HOWTO (R_SH_IMMU16
, /* type */
1062 2, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE
, /* pc_relative */
1066 complain_overflow_unsigned
, /* complain_on_overflow */
1067 bfd_elf_generic_reloc
, /* special_function */
1068 "R_SH_IMMU16", /* name */
1069 FALSE
, /* partial_inplace */
1071 0x3fffc00, /* dst_mask */
1072 FALSE
), /* pcrel_offset */
1074 /* Used in MOVI and SHORI (x & 65536). */
1075 HOWTO (R_SH_IMM_LOW16
, /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE
, /* pc_relative */
1081 complain_overflow_dont
, /* complain_on_overflow */
1082 bfd_elf_generic_reloc
, /* special_function */
1083 "R_SH_IMM_LOW16", /* name */
1084 FALSE
, /* partial_inplace */
1086 0x3fffc00, /* dst_mask */
1087 FALSE
), /* pcrel_offset */
1089 /* Used in MOVI and SHORI ((x - $) & 65536). */
1090 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1092 2, /* size (0 = byte, 1 = short, 2 = long) */
1094 TRUE
, /* pc_relative */
1096 complain_overflow_dont
, /* complain_on_overflow */
1097 bfd_elf_generic_reloc
, /* special_function */
1098 "R_SH_IMM_LOW16_PCREL", /* name */
1099 FALSE
, /* partial_inplace */
1101 0x3fffc00, /* dst_mask */
1102 TRUE
), /* pcrel_offset */
1104 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1105 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1106 16, /* rightshift */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_dont
, /* complain_on_overflow */
1112 bfd_elf_generic_reloc
, /* special_function */
1113 "R_SH_IMM_MEDLOW16", /* name */
1114 FALSE
, /* partial_inplace */
1116 0x3fffc00, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1120 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1121 16, /* rightshift */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 TRUE
, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* special_function */
1128 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1129 FALSE
, /* partial_inplace */
1131 0x3fffc00, /* dst_mask */
1132 TRUE
), /* pcrel_offset */
1134 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1135 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1136 32, /* rightshift */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 bfd_elf_generic_reloc
, /* special_function */
1143 "R_SH_IMM_MEDHI16", /* name */
1144 FALSE
, /* partial_inplace */
1146 0x3fffc00, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1150 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1151 32, /* rightshift */
1152 2, /* size (0 = byte, 1 = short, 2 = long) */
1154 TRUE
, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 "R_SH_IMM_MEDHI16_PCREL", /* name */
1159 FALSE
, /* partial_inplace */
1161 0x3fffc00, /* dst_mask */
1162 TRUE
), /* pcrel_offset */
1164 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1165 HOWTO (R_SH_IMM_HI16
, /* type */
1166 48, /* rightshift */
1167 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 bfd_elf_generic_reloc
, /* special_function */
1173 "R_SH_IMM_HI16", /* name */
1174 FALSE
, /* partial_inplace */
1176 0x3fffc00, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1180 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1181 48, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 TRUE
, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 bfd_elf_generic_reloc
, /* special_function */
1188 "R_SH_IMM_HI16_PCREL", /* name */
1189 FALSE
, /* partial_inplace */
1191 0x3fffc00, /* dst_mask */
1192 TRUE
), /* pcrel_offset */
1194 /* For the .uaquad pseudo. */
1195 HOWTO (R_SH_64
, /* type */
1197 4, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 bfd_elf_generic_reloc
, /* special_function */
1203 "R_SH_64", /* name */
1204 FALSE
, /* partial_inplace */
1206 ((bfd_vma
) 0) - 1, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* For the .uaquad pseudo, (x - $). */
1210 HOWTO (R_SH_64_PCREL
, /* type */
1211 48, /* rightshift */
1212 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 TRUE
, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 bfd_elf_generic_reloc
, /* special_function */
1218 "R_SH_64_PCREL", /* name */
1219 FALSE
, /* partial_inplace */
1221 ((bfd_vma
) 0) - 1, /* dst_mask */
1222 TRUE
), /* pcrel_offset */
1226 /* This function is used for relocs which are only used for relaxing,
1227 which the linker should otherwise ignore. */
1229 static bfd_reloc_status_type
1230 sh_elf64_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1231 asymbol
*symbol ATTRIBUTE_UNUSED
,
1232 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
1234 char **error_message ATTRIBUTE_UNUSED
)
1236 if (output_bfd
!= NULL
)
1237 reloc_entry
->address
+= input_section
->output_offset
;
1238 return bfd_reloc_ok
;
1241 /* This function is used for normal relocs. This used to be like the COFF
1242 function, and is almost certainly incorrect for other ELF targets.
1244 See sh_elf_reloc in elf32-sh.c for the original. */
1246 static bfd_reloc_status_type
1247 sh_elf64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
1248 void *data
, asection
*input_section
, bfd
*output_bfd
,
1249 char **error_message ATTRIBUTE_UNUSED
)
1253 enum elf_sh_reloc_type r_type
;
1254 bfd_vma addr
= reloc_entry
->address
;
1255 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1257 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1259 if (output_bfd
!= NULL
)
1261 /* Partial linking--do nothing. */
1262 reloc_entry
->address
+= input_section
->output_offset
;
1263 return bfd_reloc_ok
;
1266 if (symbol_in
!= NULL
1267 && bfd_is_und_section (symbol_in
->section
))
1268 return bfd_reloc_undefined
;
1270 if (bfd_is_com_section (symbol_in
->section
))
1273 sym_value
= (symbol_in
->value
+
1274 symbol_in
->section
->output_section
->vma
+
1275 symbol_in
->section
->output_offset
);
1280 insn
= bfd_get_32 (abfd
, hit_data
);
1281 insn
+= sym_value
+ reloc_entry
->addend
;
1282 bfd_put_32 (abfd
, insn
, hit_data
);
1290 return bfd_reloc_ok
;
1293 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1295 struct elf_reloc_map
1297 bfd_reloc_code_real_type bfd_reloc_val
;
1298 unsigned char elf_reloc_val
;
1301 /* An array mapping BFD reloc codes to SH ELF relocs. */
1303 static const struct elf_reloc_map sh64_reloc_map
[] =
1305 { BFD_RELOC_NONE
, R_SH_NONE
},
1306 { BFD_RELOC_32
, R_SH_DIR32
},
1307 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1308 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1309 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1310 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1311 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1312 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1313 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1314 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1315 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1316 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1317 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1318 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1319 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1320 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1321 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1322 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1323 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1324 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1325 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1326 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1327 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1328 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1329 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1330 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1331 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1332 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1333 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1334 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1335 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1336 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1337 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1338 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1339 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1340 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1341 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1342 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1343 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1344 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1345 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1346 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1347 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1348 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1349 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1350 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1351 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1352 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1353 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1354 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1355 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1356 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1357 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1358 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1359 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1360 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1361 { BFD_RELOC_64
, R_SH_64
},
1362 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1365 /* Given a BFD reloc code, return the howto structure for the
1366 corresponding SH ELf reloc. */
1368 static reloc_howto_type
*
1369 sh_elf64_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1370 bfd_reloc_code_real_type code
)
1374 for (i
= 0; i
< sizeof (sh64_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1376 if (sh64_reloc_map
[i
].bfd_reloc_val
== code
)
1377 return &sh_elf64_howto_table
[(int) sh64_reloc_map
[i
].elf_reloc_val
];
1383 static reloc_howto_type
*
1384 sh_elf64_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1390 i
< sizeof (sh_elf64_howto_table
) / sizeof (sh_elf64_howto_table
[0]);
1392 if (sh_elf64_howto_table
[i
].name
!= NULL
1393 && strcasecmp (sh_elf64_howto_table
[i
].name
, r_name
) == 0)
1394 return &sh_elf64_howto_table
[i
];
1399 /* Given an ELF reloc, fill in the howto field of a relent.
1401 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1404 sh_elf64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
1405 Elf_Internal_Rela
*dst
)
1409 r
= ELF64_R_TYPE (dst
->r_info
);
1411 if (r
> (unsigned int) R_SH_64_PCREL
)
1413 /* xgettext:c-format */
1414 _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd
, r
);
1415 bfd_set_error (bfd_error_bad_value
);
1419 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1420 BFD_ASSERT (r
< R_SH_DIR8WPN
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1421 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_GOTPLT32
);
1422 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1424 cache_ptr
->howto
= &sh_elf64_howto_table
[r
];
1425 return cache_ptr
->howto
!= NULL
;
1428 /* Relocate an SH ELF section.
1430 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1433 sh_elf64_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1434 struct bfd_link_info
*info
, bfd
*input_bfd
,
1435 asection
*input_section
, bfd_byte
*contents
,
1436 Elf_Internal_Rela
*relocs
,
1437 Elf_Internal_Sym
*local_syms
,
1438 asection
**local_sections
)
1440 Elf_Internal_Shdr
*symtab_hdr
;
1441 struct elf_link_hash_entry
**sym_hashes
;
1442 Elf_Internal_Rela
*rel
, *relend
;
1443 bfd_vma
*local_got_offsets
;
1448 bfd_vma disp
, dropped
;
1450 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1451 sym_hashes
= elf_sym_hashes (input_bfd
);
1452 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1457 relend
= relocs
+ input_section
->reloc_count
;
1458 for (; rel
< relend
; rel
++)
1461 reloc_howto_type
*howto
;
1462 unsigned long r_symndx
;
1463 Elf_Internal_Sym
*sym
;
1465 struct elf_link_hash_entry
*h
;
1467 bfd_vma addend
= (bfd_vma
)0;
1468 bfd_reloc_status_type r
;
1469 int seen_stt_datalabel
= 0;
1471 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1473 r_type
= ELF64_R_TYPE (rel
->r_info
);
1475 if (r_type
== (int) R_SH_NONE
)
1479 || r_type
> R_SH_64_PCREL
1480 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1481 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1482 || (r_type
>= (int) R_SH_DIR8WPN
1483 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1484 || (r_type
>= (int) R_SH_GNU_VTINHERIT
1485 && r_type
<= (int) R_SH_PSHL
)
1486 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
1487 && r_type
<= R_SH_GOTPLT32
)
1488 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
1489 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
))
1491 bfd_set_error (bfd_error_bad_value
);
1495 howto
= sh_elf64_howto_table
+ r_type
;
1501 if (r_symndx
< symtab_hdr
->sh_info
)
1503 sym
= local_syms
+ r_symndx
;
1504 sec
= local_sections
[r_symndx
];
1505 relocation
= ((sec
->output_section
->vma
1506 + sec
->output_offset
1508 | ((sym
->st_other
& STO_SH5_ISA32
) != 0));
1510 /* A local symbol never has STO_SH5_ISA32, so we don't need
1511 datalabel processing here. Make sure this does not change
1513 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
1514 (*info
->callbacks
->reloc_dangerous
)
1516 _("unexpected STO_SH5_ISA32 on local symbol is not handled"),
1517 input_bfd
, input_section
, rel
->r_offset
);
1519 if (sec
!= NULL
&& discarded_section (sec
))
1520 /* Handled below. */
1522 else if (bfd_link_relocatable (info
))
1524 /* This is a relocatable link. We don't have to change
1525 anything, unless the reloc is against a section symbol,
1526 in which case we have to adjust according to where the
1527 section symbol winds up in the output section. */
1528 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1529 goto final_link_relocate
;
1533 else if (! howto
->partial_inplace
)
1535 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1536 relocation
|= ((sym
->st_other
& STO_SH5_ISA32
) != 0);
1538 else if ((sec
->flags
& SEC_MERGE
)
1539 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1543 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
1546 /* xgettext:c-format */
1547 (_("%pB(%pA+%#" PRIx64
"): "
1548 "%s relocation against SEC_MERGE section"),
1549 input_bfd
, input_section
,
1550 (uint64_t) rel
->r_offset
, howto
->name
);
1554 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1557 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
1559 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
1560 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
1566 /* ??? Could we use the RELOC_FOR_GLOBAL_SYMBOL macro here ? */
1568 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1569 while (h
->root
.type
== bfd_link_hash_indirect
1570 || h
->root
.type
== bfd_link_hash_warning
)
1572 /* If the reference passes a symbol marked with
1573 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1575 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
1576 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1579 if (h
->root
.type
== bfd_link_hash_defined
1580 || h
->root
.type
== bfd_link_hash_defweak
)
1582 sec
= h
->root
.u
.def
.section
;
1583 /* In these cases, we don't need the relocation value.
1584 We check specially because in some obscure cases
1585 sec->output_section will be NULL. */
1586 if (r_type
== R_SH_GOTPC_LOW16
1587 || r_type
== R_SH_GOTPC_MEDLOW16
1588 || r_type
== R_SH_GOTPC_MEDHI16
1589 || r_type
== R_SH_GOTPC_HI16
1590 || ((r_type
== R_SH_PLT_LOW16
1591 || r_type
== R_SH_PLT_MEDLOW16
1592 || r_type
== R_SH_PLT_MEDHI16
1593 || r_type
== R_SH_PLT_HI16
)
1594 && h
->plt
.offset
!= (bfd_vma
) -1)
1595 || ((r_type
== R_SH_GOT_LOW16
1596 || r_type
== R_SH_GOT_MEDLOW16
1597 || r_type
== R_SH_GOT_MEDHI16
1598 || r_type
== R_SH_GOT_HI16
)
1599 && elf_hash_table (info
)->dynamic_sections_created
1600 && (! bfd_link_pic (info
)
1601 || (! info
->symbolic
&& h
->dynindx
!= -1)
1602 || !h
->def_regular
))
1603 /* The cases above are those in which relocation is
1604 overwritten in the switch block below. The cases
1605 below are those in which we must defer relocation
1606 to run-time, because we can't resolve absolute
1607 addresses when creating a shared library. */
1608 || (bfd_link_pic (info
)
1609 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1611 && ((r_type
== R_SH_64
1612 && !(ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1613 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
))
1614 || r_type
== R_SH_64_PCREL
)
1615 && ((input_section
->flags
& SEC_ALLOC
) != 0
1616 /* DWARF will emit R_SH_DIR32 relocations in its
1617 sections against symbols defined externally
1618 in shared libraries. We can't do anything
1620 || (input_section
->flags
& SEC_DEBUGGING
) != 0))
1621 /* Dynamic relocs are not propagated for SEC_DEBUGGING
1622 sections because such sections are not SEC_ALLOC and
1623 thus ld.so will not process them. */
1624 || (sec
->output_section
== NULL
1625 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
1626 && h
->def_dynamic
)))
1628 else if (sec
->output_section
!= NULL
)
1629 relocation
= ((h
->root
.u
.def
.value
1630 + sec
->output_section
->vma
1631 + sec
->output_offset
)
1632 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1633 symbol value, unless we've seen
1634 STT_DATALABEL on the way to it. */
1635 | ((h
->other
& STO_SH5_ISA32
) != 0
1636 && ! seen_stt_datalabel
));
1637 else if (!bfd_link_relocatable (info
)
1638 && (_bfd_elf_section_offset (output_bfd
, info
,
1644 /* xgettext:c-format */
1645 (_("%pB(%pA+%#" PRIx64
"): "
1646 "unresolvable %s relocation against symbol `%s'"),
1649 (uint64_t) rel
->r_offset
,
1651 h
->root
.root
.string
);
1654 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1656 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
1657 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
1659 else if (!bfd_link_relocatable (info
))
1660 (*info
->callbacks
->undefined_symbol
)
1661 (info
, h
->root
.root
.string
, input_bfd
,
1662 input_section
, rel
->r_offset
,
1663 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
1664 || ELF_ST_VISIBILITY (h
->other
)));
1667 if (sec
!= NULL
&& discarded_section (sec
))
1668 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
1669 rel
, 1, relend
, howto
, 0, contents
);
1671 if (bfd_link_relocatable (info
))
1675 - input_section
->output_section
->vma
1676 - input_section
->output_offset
1679 switch ((int)r_type
)
1681 case R_SH_PT_16
: dropped
= disp
& 2; break;
1682 case R_SH_DIR10SW
: dropped
= disp
& 1; break;
1683 case R_SH_DIR10SL
: dropped
= disp
& 3; break;
1684 case R_SH_DIR10SQ
: dropped
= disp
& 7; break;
1689 /* xgettext:c-format */
1690 (_("%pB: error: unaligned relocation type %d at "
1691 "%08" PRIx64
" reloc %08" PRIx64
""),
1692 input_bfd
, (int) r_type
,
1693 (uint64_t) rel
->r_offset
, (uint64_t) relocation
);
1694 bfd_set_error (bfd_error_bad_value
);
1697 switch ((int)r_type
)
1701 if (bfd_link_pic (info
)
1702 && (input_section
->flags
& SEC_ALLOC
) != 0
1703 && (r_type
!= R_SH_64_PCREL
1706 && (! info
->symbolic
1707 || !h
->def_regular
))))
1709 Elf_Internal_Rela outrel
;
1711 bfd_boolean skip
, relocate
;
1713 /* When generating a shared object, these relocations
1714 are copied into the output file to be resolved at run
1719 sreloc
= _bfd_elf_get_dynamic_reloc_section
1720 (input_bfd
, input_section
, /*rela?*/ TRUE
);
1729 = _bfd_elf_section_offset (output_bfd
, info
,
1730 input_section
, rel
->r_offset
);
1732 if (outrel
.r_offset
== (bfd_vma
) -1)
1734 else if (outrel
.r_offset
== (bfd_vma
) -2)
1735 skip
= TRUE
, relocate
= TRUE
;
1737 outrel
.r_offset
+= (input_section
->output_section
->vma
1738 + input_section
->output_offset
);
1741 memset (&outrel
, 0, sizeof outrel
);
1742 else if (r_type
== R_SH_64_PCREL
)
1744 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
1745 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64_PCREL
);
1746 outrel
.r_addend
= rel
->r_addend
;
1750 /* h->dynindx may be -1 if this symbol was marked to
1753 || ((info
->symbolic
|| h
->dynindx
== -1)
1757 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1758 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1762 BFD_ASSERT (h
->dynindx
!= -1);
1763 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64
);
1764 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1768 loc
= sreloc
->contents
;
1769 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1770 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1772 /* If this reloc is against an external symbol, we do
1773 not want to fiddle with the addend. Otherwise, we
1774 need to include the symbol value so that it becomes
1775 an addend for the dynamic reloc. */
1779 else if (r_type
== R_SH_64
)
1780 addend
= rel
->r_addend
;
1781 goto final_link_relocate
;
1783 case R_SH_GOTPLT_LOW16
:
1784 case R_SH_GOTPLT_MEDLOW16
:
1785 case R_SH_GOTPLT_MEDHI16
:
1786 case R_SH_GOTPLT_HI16
:
1787 case R_SH_GOTPLT10BY4
:
1788 case R_SH_GOTPLT10BY8
:
1789 /* Relocation is to the entry for this symbol in the
1790 procedure linkage table. */
1793 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1794 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
1795 || ! bfd_link_pic (info
)
1798 || h
->plt
.offset
== (bfd_vma
) -1
1799 || h
->got
.offset
!= (bfd_vma
) -1)
1802 /* Relocation is to the entry for this symbol in the global
1803 offset table extension for the procedure linkage table. */
1804 sgotplt
= elf_hash_table (info
)->sgotplt
;
1805 BFD_ASSERT (sgotplt
!= NULL
);
1807 relocation
= (sgotplt
->output_offset
1808 + ((h
->plt
.offset
/ elf_sh64_sizeof_plt (info
)
1811 relocation
-= GOT_BIAS
;
1813 goto final_link_relocate
;
1816 case R_SH_GOT_LOW16
:
1817 case R_SH_GOT_MEDLOW16
:
1818 case R_SH_GOT_MEDHI16
:
1822 /* Relocation is to the entry for this symbol in the global
1824 sgot
= elf_hash_table (info
)->sgot
;
1825 BFD_ASSERT (sgot
!= NULL
);
1831 off
= h
->got
.offset
;
1832 if (seen_stt_datalabel
)
1834 struct elf_sh64_link_hash_entry
*hsh
;
1836 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1837 off
= hsh
->datalabel_got_offset
;
1839 BFD_ASSERT (off
!= (bfd_vma
) -1);
1841 if (! elf_hash_table (info
)->dynamic_sections_created
1842 || (bfd_link_pic (info
)
1843 && (info
->symbolic
|| h
->dynindx
== -1
1844 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1845 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
1848 /* This is actually a static link, or it is a
1849 -Bsymbolic link and the symbol is defined
1850 locally, or the symbol was forced to be local
1851 because of a version file. We must initialize
1852 this entry in the global offset table. Since the
1853 offset must always be a multiple of 4, we use the
1854 least significant bit to record whether we have
1855 initialized it already.
1857 When doing a dynamic link, we create a .rela.got
1858 relocation entry to initialize the value. This
1859 is done in the finish_dynamic_symbol routine. */
1864 bfd_put_64 (output_bfd
, relocation
,
1865 sgot
->contents
+ off
);
1866 if (seen_stt_datalabel
)
1868 struct elf_sh64_link_hash_entry
*hsh
;
1870 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1871 hsh
->datalabel_got_offset
|= 1;
1878 relocation
= sgot
->output_offset
+ off
;
1886 BFD_ASSERT (local_got_offsets
!= NULL
1887 && (local_got_offsets
[symtab_hdr
->sh_info
1891 off
= local_got_offsets
[symtab_hdr
->sh_info
1896 BFD_ASSERT (local_got_offsets
!= NULL
1897 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1899 off
= local_got_offsets
[r_symndx
];
1902 /* The offset must always be a multiple of 8. We use
1903 the least significant bit to record whether we have
1904 already generated the necessary reloc. */
1909 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1911 if (bfd_link_pic (info
))
1914 Elf_Internal_Rela outrel
;
1917 s
= elf_hash_table (info
)->srelgot
;
1918 BFD_ASSERT (s
!= NULL
);
1920 outrel
.r_offset
= (sgot
->output_section
->vma
1921 + sgot
->output_offset
1923 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1924 outrel
.r_addend
= relocation
;
1926 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1927 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1931 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
1933 local_got_offsets
[r_symndx
] |= 1;
1936 relocation
= sgot
->output_offset
+ off
;
1939 relocation
-= GOT_BIAS
;
1941 goto final_link_relocate
;
1943 case R_SH_GOTOFF_LOW16
:
1944 case R_SH_GOTOFF_MEDLOW16
:
1945 case R_SH_GOTOFF_MEDHI16
:
1946 case R_SH_GOTOFF_HI16
:
1947 /* Relocation is relative to the start of the global offset
1950 sgot
= elf_hash_table (info
)->sgot
;
1951 BFD_ASSERT (sgot
!= NULL
);
1953 /* Note that sgot->output_offset is not involved in this
1954 calculation. We always want the start of .got. If we
1955 defined _GLOBAL_OFFSET_TABLE in a different way, as is
1956 permitted by the ABI, we might have to change this
1958 relocation
-= sgot
->output_section
->vma
;
1960 relocation
-= GOT_BIAS
;
1962 addend
= rel
->r_addend
;
1964 goto final_link_relocate
;
1966 case R_SH_GOTPC_LOW16
:
1967 case R_SH_GOTPC_MEDLOW16
:
1968 case R_SH_GOTPC_MEDHI16
:
1969 case R_SH_GOTPC_HI16
:
1970 /* Use global offset table as symbol value. */
1972 sgot
= elf_hash_table (info
)->sgot
;
1973 BFD_ASSERT (sgot
!= NULL
);
1975 relocation
= sgot
->output_section
->vma
;
1977 relocation
+= GOT_BIAS
;
1979 addend
= rel
->r_addend
;
1981 goto final_link_relocate
;
1983 case R_SH_PLT_LOW16
:
1984 case R_SH_PLT_MEDLOW16
:
1985 case R_SH_PLT_MEDHI16
:
1987 /* Relocation is to the entry for this symbol in the
1988 procedure linkage table. */
1990 /* Resolve a PLT reloc against a local symbol directly,
1991 without using the procedure linkage table. */
1993 goto final_link_relocate
;
1995 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1996 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
1997 goto final_link_relocate
;
1999 if (h
->plt
.offset
== (bfd_vma
) -1)
2001 /* We didn't make a PLT entry for this symbol. This
2002 happens when statically linking PIC code, or when
2003 using -Bsymbolic. */
2004 goto final_link_relocate
;
2007 splt
= elf_hash_table (info
)->splt
;
2008 BFD_ASSERT (splt
!= NULL
);
2010 relocation
= (splt
->output_section
->vma
2011 + splt
->output_offset
2015 addend
= rel
->r_addend
;
2017 goto final_link_relocate
;
2020 case R_SH_SHMEDIA_CODE
:
2031 case R_SH_IMM_LOW16
:
2032 case R_SH_IMM_LOW16_PCREL
:
2033 case R_SH_IMM_MEDLOW16
:
2034 case R_SH_IMM_MEDLOW16_PCREL
:
2035 case R_SH_IMM_MEDHI16
:
2036 case R_SH_IMM_MEDHI16_PCREL
:
2038 case R_SH_IMM_HI16_PCREL
:
2039 addend
= rel
->r_addend
;
2042 final_link_relocate
:
2043 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2044 contents
, rel
->r_offset
,
2045 relocation
, addend
);
2049 bfd_set_error (bfd_error_bad_value
);
2054 if (r
!= bfd_reloc_ok
)
2059 case bfd_reloc_outofrange
:
2061 case bfd_reloc_overflow
:
2069 name
= (bfd_elf_string_from_elf_section
2070 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2074 name
= bfd_section_name (input_bfd
, sec
);
2076 (*info
->callbacks
->reloc_overflow
)
2077 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2078 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
2088 /* This is a version of bfd_generic_get_relocated_section_contents
2089 that uses sh_elf64_relocate_section.
2091 See sh_elf_relocate_section in elf32-sh.c for the original. */
2094 sh_elf64_get_relocated_section_contents (bfd
*output_bfd
,
2095 struct bfd_link_info
*link_info
,
2096 struct bfd_link_order
*link_order
,
2098 bfd_boolean relocatable
,
2101 Elf_Internal_Shdr
*symtab_hdr
;
2102 asection
*input_section
= link_order
->u
.indirect
.section
;
2103 bfd
*input_bfd
= input_section
->owner
;
2104 asection
**sections
= NULL
;
2105 Elf_Internal_Rela
*internal_relocs
= NULL
;
2106 Elf_Internal_Sym
*isymbuf
= NULL
;
2108 /* We only need to handle the case of relaxing, or of having a
2109 particular set of section contents, specially. */
2111 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2112 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2117 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2119 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2120 input_section
->size
);
2122 if ((input_section
->flags
& SEC_RELOC
) != 0
2123 && input_section
->reloc_count
> 0)
2125 Elf_Internal_Sym
*isymp
;
2126 Elf_Internal_Sym
*isymend
;
2129 /* Read this BFD's local symbols. */
2130 if (symtab_hdr
->sh_info
!= 0)
2132 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2133 if (isymbuf
== NULL
)
2134 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2135 symtab_hdr
->sh_info
, 0,
2137 if (isymbuf
== NULL
)
2141 internal_relocs
= (_bfd_elf_link_read_relocs
2142 (input_bfd
, input_section
, NULL
,
2143 (Elf_Internal_Rela
*) NULL
, FALSE
));
2144 if (internal_relocs
== NULL
)
2147 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2148 * sizeof (asection
*));
2149 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2153 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2154 for (isymp
= isymbuf
; isymp
< isymend
; ++isymp
, ++secpp
)
2158 if (isymp
->st_shndx
== SHN_UNDEF
)
2159 isec
= bfd_und_section_ptr
;
2160 else if (isymp
->st_shndx
== SHN_ABS
)
2161 isec
= bfd_abs_section_ptr
;
2162 else if (isymp
->st_shndx
== SHN_COMMON
)
2163 isec
= bfd_com_section_ptr
;
2165 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
2170 if (! sh_elf64_relocate_section (output_bfd
, link_info
, input_bfd
,
2171 input_section
, data
, internal_relocs
,
2175 if (sections
!= NULL
)
2177 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
2178 free (internal_relocs
);
2180 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2187 if (sections
!= NULL
)
2189 if (internal_relocs
!= NULL
2190 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
2191 free (internal_relocs
);
2193 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2198 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */
2201 sh64_elf64_fake_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2202 Elf_Internal_Shdr
*elf_section_hdr
,
2205 /* Code sections can only contain SH64 code, so mark them as such. */
2206 if (bfd_get_section_flags (output_bfd
, asect
) & SEC_CODE
)
2207 elf_section_hdr
->sh_flags
|= SHF_SH5_ISA32
;
2213 sh_elf64_set_mach_from_flags (bfd
*abfd
)
2215 flagword flags
= elf_elfheader (abfd
)->e_flags
;
2217 switch (flags
& EF_SH_MACH_MASK
)
2220 /* Just one, but keep the switch construct to make additions easy. */
2221 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh5
);
2225 bfd_set_error (bfd_error_wrong_format
);
2231 /* Function to keep SH64 specific file flags.
2233 See sh64_elf_set_private_flags in elf32-sh64.c for the original. */
2236 sh_elf64_set_private_flags (bfd
*abfd
, flagword flags
)
2238 BFD_ASSERT (! elf_flags_init (abfd
)
2239 || elf_elfheader (abfd
)->e_flags
== flags
);
2241 elf_elfheader (abfd
)->e_flags
= flags
;
2242 elf_flags_init (abfd
) = TRUE
;
2243 return sh_elf64_set_mach_from_flags (abfd
);
2246 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2247 code, to keep attributes the same as for SHmedia in 32-bit ELF. */
2250 sh_elf64_copy_private_data_internal (bfd
*ibfd
, bfd
*obfd
)
2252 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2253 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2256 /* Copy object attributes. */
2257 _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
2259 return sh_elf64_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2263 sh_elf64_copy_private_data (bfd
*ibfd
, bfd
*obfd
)
2265 return sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2269 sh_elf64_merge_private_data (bfd
*ibfd
, struct bfd_link_info
*info
)
2271 bfd
*obfd
= info
->output_bfd
;
2272 flagword old_flags
, new_flags
;
2274 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
2277 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2278 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2281 if (bfd_get_arch_size (ibfd
) != bfd_get_arch_size (obfd
))
2285 if (bfd_get_arch_size (ibfd
) == 32
2286 && bfd_get_arch_size (obfd
) == 64)
2287 /* xgettext:c-format */
2288 msg
= _("%pB: compiled as 32-bit object and %pB is 64-bit");
2289 else if (bfd_get_arch_size (ibfd
) == 64
2290 && bfd_get_arch_size (obfd
) == 32)
2291 /* xgettext:c-format */
2292 msg
= _("%pB: compiled as 64-bit object and %pB is 32-bit");
2294 /* xgettext:c-format */
2295 msg
= _("%pB: object size does not match that of target %pB");
2297 _bfd_error_handler (msg
, ibfd
, obfd
);
2298 bfd_set_error (bfd_error_wrong_format
);
2302 old_flags
= elf_elfheader (obfd
)->e_flags
;
2303 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2304 if (! elf_flags_init (obfd
))
2306 /* This happens when ld starts out with a 'blank' output file. */
2307 elf_flags_init (obfd
) = TRUE
;
2308 elf_elfheader (obfd
)->e_flags
= old_flags
= new_flags
;
2310 /* We don't allow linking in anything else than SH64 code, and since
2311 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2312 here as things change. */
2313 else if ((new_flags
& EF_SH_MACH_MASK
) != EF_SH5
)
2316 ("%pB: does not use the SH64 64-bit ABI as previous modules do", ibfd
);
2317 bfd_set_error (bfd_error_bad_value
);
2321 sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2323 /* I can't think of anything sane other than old_flags being EF_SH5 and
2324 that we need to preserve that. */
2325 elf_elfheader (obfd
)->e_flags
= old_flags
;
2327 return sh_elf64_set_mach_from_flags (obfd
);
2330 /* Return the section that should be marked against GC for a given
2334 sh_elf64_gc_mark_hook (asection
*sec
,
2335 struct bfd_link_info
*info
,
2336 Elf_Internal_Rela
*rel
,
2337 struct elf_link_hash_entry
*h
,
2338 Elf_Internal_Sym
*sym
)
2341 switch (ELF64_R_TYPE (rel
->r_info
))
2343 case R_SH_GNU_VTINHERIT
:
2344 case R_SH_GNU_VTENTRY
:
2348 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2351 /* Look through the relocs for a section during the first phase.
2352 Since we don't do .gots or .plts, we just need to consider the
2353 virtual table relocs for gc. */
2356 sh_elf64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2357 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2359 Elf_Internal_Shdr
*symtab_hdr
;
2360 struct elf_link_hash_entry
**sym_hashes
;
2361 const Elf_Internal_Rela
*rel
;
2362 const Elf_Internal_Rela
*rel_end
;
2364 bfd_vma
*local_got_offsets
;
2371 if (bfd_link_relocatable (info
))
2374 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2375 sym_hashes
= elf_sym_hashes (abfd
);
2377 dynobj
= elf_hash_table (info
)->dynobj
;
2378 local_got_offsets
= elf_local_got_offsets (abfd
);
2380 rel_end
= relocs
+ sec
->reloc_count
;
2381 for (rel
= relocs
; rel
< rel_end
; rel
++)
2383 struct elf_link_hash_entry
*h
;
2384 unsigned long r_symndx
;
2386 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2387 if (r_symndx
< symtab_hdr
->sh_info
)
2391 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2392 while (h
->root
.type
== bfd_link_hash_indirect
2393 || h
->root
.type
== bfd_link_hash_warning
)
2394 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2397 /* Some relocs require a global offset table. */
2400 switch (ELF64_R_TYPE (rel
->r_info
))
2402 case R_SH_GOTPLT_LOW16
:
2403 case R_SH_GOTPLT_MEDLOW16
:
2404 case R_SH_GOTPLT_MEDHI16
:
2405 case R_SH_GOTPLT_HI16
:
2406 case R_SH_GOTPLT10BY4
:
2407 case R_SH_GOTPLT10BY8
:
2408 case R_SH_GOT_LOW16
:
2409 case R_SH_GOT_MEDLOW16
:
2410 case R_SH_GOT_MEDHI16
:
2414 case R_SH_GOTOFF_LOW16
:
2415 case R_SH_GOTOFF_MEDLOW16
:
2416 case R_SH_GOTOFF_MEDHI16
:
2417 case R_SH_GOTOFF_HI16
:
2418 case R_SH_GOTPC_LOW16
:
2419 case R_SH_GOTPC_MEDLOW16
:
2420 case R_SH_GOTPC_MEDHI16
:
2421 case R_SH_GOTPC_HI16
:
2422 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2423 if (! _bfd_elf_create_got_section (dynobj
, info
))
2432 switch (ELF64_R_TYPE (rel
->r_info
))
2434 /* This relocation describes the C++ object vtable hierarchy.
2435 Reconstruct it for later use during GC. */
2436 case R_SH_GNU_VTINHERIT
:
2437 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2441 /* This relocation describes which C++ vtable entries are actually
2442 used. Record for later use during GC. */
2443 case R_SH_GNU_VTENTRY
:
2444 BFD_ASSERT (h
!= NULL
);
2446 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2451 case R_SH_GOT_LOW16
:
2452 case R_SH_GOT_MEDLOW16
:
2453 case R_SH_GOT_MEDHI16
:
2457 /* This symbol requires a global offset table entry. */
2459 sgot
= elf_hash_table (info
)->sgot
;
2460 srelgot
= elf_hash_table (info
)->srelgot
;
2461 BFD_ASSERT (sgot
!= NULL
&& srelgot
!= NULL
);
2465 if (h
->type
== STT_DATALABEL
)
2467 struct elf_sh64_link_hash_entry
*hsh
;
2469 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2470 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
2471 if (hsh
->datalabel_got_offset
!= (bfd_vma
) -1)
2474 hsh
->datalabel_got_offset
= sgot
->size
;
2478 if (h
->got
.offset
!= (bfd_vma
) -1)
2480 /* We have already allocated space in the .got. */
2483 h
->got
.offset
= sgot
->size
;
2486 /* Make sure this symbol is output as a dynamic symbol. */
2487 if (h
->dynindx
== -1)
2489 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2493 srelgot
->size
+= sizeof (Elf64_External_Rela
);
2497 /* This is a global offset table entry for a local
2499 if (local_got_offsets
== NULL
)
2502 register unsigned int i
;
2504 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
2505 /* Reserve space for both the datalabel and
2506 codelabel local GOT offsets. */
2508 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
2509 if (local_got_offsets
== NULL
)
2511 elf_local_got_offsets (abfd
) = local_got_offsets
;
2512 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
2513 local_got_offsets
[i
] = (bfd_vma
) -1;
2514 for (; i
< 2 * symtab_hdr
->sh_info
; i
++)
2515 local_got_offsets
[i
] = (bfd_vma
) -1;
2517 if ((rel
->r_addend
& 1) != 0)
2519 if (local_got_offsets
[symtab_hdr
->sh_info
2520 + r_symndx
] != (bfd_vma
) -1)
2522 /* We have already allocated space in the .got. */
2525 local_got_offsets
[symtab_hdr
->sh_info
2526 + r_symndx
] = sgot
->size
;
2530 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
2532 /* We have already allocated space in the .got. */
2535 local_got_offsets
[r_symndx
] = sgot
->size
;
2538 if (bfd_link_pic (info
))
2540 /* If we are generating a shared object, we need to
2541 output a R_SH_RELATIVE reloc so that the dynamic
2542 linker can adjust this GOT entry. */
2543 srelgot
->size
+= sizeof (Elf64_External_Rela
);
2551 case R_SH_GOTPLT_LOW16
:
2552 case R_SH_GOTPLT_MEDLOW16
:
2553 case R_SH_GOTPLT_MEDHI16
:
2554 case R_SH_GOTPLT_HI16
:
2555 case R_SH_GOTPLT10BY4
:
2556 case R_SH_GOTPLT10BY8
:
2557 /* If this is a local symbol, we resolve it directly without
2558 creating a procedure linkage table entry. */
2561 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2562 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
2563 || ! bfd_link_pic (info
)
2566 || h
->got
.offset
!= (bfd_vma
) -1)
2569 /* Make sure this symbol is output as a dynamic symbol. */
2570 if (h
->dynindx
== -1)
2572 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2580 case R_SH_PLT_LOW16
:
2581 case R_SH_PLT_MEDLOW16
:
2582 case R_SH_PLT_MEDHI16
:
2584 /* This symbol requires a procedure linkage table entry. We
2585 actually build the entry in adjust_dynamic_symbol,
2586 because this might be a case of linking PIC code which is
2587 never referenced by a dynamic object, in which case we
2588 don't need to generate a procedure linkage table entry
2591 /* If this is a local symbol, we resolve it directly without
2592 creating a procedure linkage table entry. */
2596 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2597 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2609 /* If we are creating a shared library, and this is a reloc
2610 against a global symbol, or a non PC relative reloc
2611 against a local symbol, then we need to copy the reloc
2612 into the shared library. However, if we are linking with
2613 -Bsymbolic, we do not need to copy a reloc against a
2614 global symbol which is defined in an object we are
2615 including in the link (i.e., DEF_REGULAR is set). At
2616 this point we have not seen all the input files, so it is
2617 possible that DEF_REGULAR is not set now but will be set
2618 later (it is never cleared). We account for that
2619 possibility below by storing information in the
2620 pcrel_relocs_copied field of the hash table entry. */
2621 if (bfd_link_pic (info
)
2622 && (sec
->flags
& SEC_ALLOC
) != 0
2623 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_64_PCREL
2625 && (! info
->symbolic
2626 || !h
->def_regular
))))
2628 /* When creating a shared object, we must copy these
2629 reloc types into the output file. We create a reloc
2630 section in dynobj and make room for this reloc. */
2633 sreloc
= _bfd_elf_make_dynamic_reloc_section
2634 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
2640 sreloc
->size
+= sizeof (Elf64_External_Rela
);
2642 /* If we are linking with -Bsymbolic, and this is a
2643 global symbol, we count the number of PC relative
2644 relocations we have entered for this symbol, so that
2645 we can discard them again if the symbol is later
2646 defined by a regular object. Note that this function
2647 is only called if we are using an elf_sh linker
2648 hash table, which means that h is really a pointer to
2649 an elf_sh_link_hash_entry. */
2650 if (h
!= NULL
&& info
->symbolic
2651 && ELF64_R_TYPE (rel
->r_info
) == R_SH_64_PCREL
)
2653 struct elf_sh64_link_hash_entry
*eh
;
2654 struct elf_sh64_pcrel_relocs_copied
*p
;
2656 eh
= (struct elf_sh64_link_hash_entry
*) h
;
2658 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
2659 if (p
->section
== sreloc
)
2664 p
= ((struct elf_sh64_pcrel_relocs_copied
*)
2665 bfd_alloc (dynobj
, sizeof *p
));
2668 p
->next
= eh
->pcrel_relocs_copied
;
2669 eh
->pcrel_relocs_copied
= p
;
2670 p
->section
= sreloc
;
2686 sh64_elf64_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
2688 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_DATALABEL
)
2689 return STT_DATALABEL
;
2694 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2695 Either file can presumably exist without the other, but do not differ
2696 in elf-size-ness. How to share?
2698 Hook called by the linker routine which adds symbols from an object
2699 file. We must make indirect symbols for undefined symbols marked with
2700 STT_DATALABEL, so relocations passing them will pick up that attribute
2701 and neutralize STO_SH5_ISA32 found on the symbol definition.
2703 There is a problem, though: We want to fill in the hash-table entry for
2704 this symbol and signal to the caller that no further processing is
2705 needed. But we don't have the index for this hash-table entry. We
2706 rely here on that the current entry is the first hash-entry with NULL,
2707 which seems brittle. Also, iterating over the hash-table to find that
2708 entry is a linear operation on the number of symbols in this input
2709 file, and this function should take constant time, so that's not good
2710 too. Only comfort is that DataLabel references should only be found in
2711 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2712 into adding an option to elf_add_symbol_hook (preferably) for the index
2713 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2717 sh64_elf64_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
2718 Elf_Internal_Sym
*sym
, const char **namep
,
2719 flagword
*flagsp ATTRIBUTE_UNUSED
,
2720 asection
**secp
, bfd_vma
*valp
)
2722 /* We want to do this for relocatable as well as final linking. */
2723 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
2724 && is_elf_hash_table (info
->hash
))
2726 struct elf_link_hash_entry
*h
;
2728 /* For relocatable links, we register the DataLabel sym in its own
2729 right, and tweak the name when it's output. Otherwise, we make
2730 an indirect symbol of it. */
2732 = bfd_link_relocatable (info
) || info
->emitrelocations
2733 ? BSF_GLOBAL
: BSF_GLOBAL
| BSF_INDIRECT
;
2736 = bfd_malloc (strlen (*namep
) + sizeof (DATALABEL_SUFFIX
));
2737 struct elf_link_hash_entry
** sym_hash
= elf_sym_hashes (abfd
);
2739 BFD_ASSERT (sym_hash
!= NULL
);
2741 /* Allocation may fail. */
2742 if (dl_name
== NULL
)
2745 strcpy (dl_name
, *namep
);
2746 strcat (dl_name
, DATALABEL_SUFFIX
);
2748 h
= (struct elf_link_hash_entry
*)
2749 bfd_link_hash_lookup (info
->hash
, dl_name
, FALSE
, FALSE
, FALSE
);
2753 /* No previous datalabel symbol. Make one. */
2754 struct bfd_link_hash_entry
*bh
= NULL
;
2755 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2757 if (! _bfd_generic_link_add_one_symbol (info
, abfd
, dl_name
,
2758 flags
, *secp
, *valp
,
2766 h
= (struct elf_link_hash_entry
*) bh
;
2768 h
->type
= STT_DATALABEL
;
2771 /* If a new symbol was created, it holds the allocated name.
2772 Otherwise, we don't need it anymore and should deallocate it. */
2775 if (h
->type
!= STT_DATALABEL
2776 || ((bfd_link_relocatable (info
) || info
->emitrelocations
)
2777 && h
->root
.type
!= bfd_link_hash_undefined
)
2778 || (! bfd_link_relocatable (info
) && !info
->emitrelocations
2779 && h
->root
.type
!= bfd_link_hash_indirect
))
2781 /* Make sure we don't get confused on invalid input. */
2783 (_("%pB: encountered datalabel symbol in input"), abfd
);
2784 bfd_set_error (bfd_error_bad_value
);
2788 /* Now find the hash-table slot for this entry and fill it in. */
2789 while (*sym_hash
!= NULL
)
2793 /* Signal to caller to skip this symbol - we've handled it. */
2800 /* This hook function is called before the linker writes out a global
2801 symbol. For relocatable links, DataLabel symbols will be present in
2802 linker output. We cut off the special suffix on those symbols, so the
2803 right name appears in the output.
2805 When linking and emitting relocations, there can appear global symbols
2806 that are not referenced by relocs, but rather only implicitly through
2807 DataLabel references, a relation that is not visible to the linker.
2808 Since no stripping of global symbols in done when doing such linking,
2809 we don't need to look up and make sure to emit the main symbol for each
2810 DataLabel symbol. */
2813 sh64_elf64_link_output_symbol_hook (struct bfd_link_info
*info
,
2815 Elf_Internal_Sym
*sym
,
2816 asection
*input_sec ATTRIBUTE_UNUSED
,
2817 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2819 char *name
= (char *) cname
;
2821 if (bfd_link_relocatable (info
) || info
->emitrelocations
)
2823 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
)
2824 name
[strlen (name
) - strlen (DATALABEL_SUFFIX
)] = 0;
2830 /* Set bit 0 on the entry address; it always points to SHmedia code. This
2831 is mostly for symmetry with the 32-bit format, where code can be
2832 SHcompact and we need to make a distinction to make sure execution
2833 starts in the right ISA mode. It is also convenient for a loader,
2834 which would otherwise have to set this bit when loading a TR register
2835 before jumping to the program entry. */
2838 sh64_elf64_final_write_processing (bfd
*abfd
,
2839 bfd_boolean linker ATTRIBUTE_UNUSED
)
2841 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
2842 numerically, but we currently lack the infrastructure to recognize
2843 that: The entry symbol, and info whether it is numeric or a symbol
2844 name is kept private in the linker. */
2845 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
)
2846 elf_elfheader (abfd
)->e_entry
|= 1;
2849 /* First entry in an absolute procedure linkage table look like this. */
2851 static const bfd_byte elf_sh64_plt0_entry_be
[PLT_ENTRY_SIZE
] =
2853 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
2854 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
2855 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
2856 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2857 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
2858 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2859 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
2860 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2861 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2862 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2863 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2864 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2865 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2866 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2867 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2868 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2871 static const bfd_byte elf_sh64_plt0_entry_le
[PLT_ENTRY_SIZE
] =
2873 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
2874 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
2875 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
2876 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2877 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
2878 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2879 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
2880 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2881 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2882 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2883 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2884 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2885 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2886 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2887 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2888 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2891 /* Sebsequent entries in an absolute procedure linkage table look like
2894 static const bfd_byte elf_sh64_plt_entry_be
[PLT_ENTRY_SIZE
] =
2896 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
2897 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
2898 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
2899 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
2900 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
2901 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2902 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2903 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2904 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */
2905 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
2906 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
2907 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
2908 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
2909 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2910 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2911 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2914 static const bfd_byte elf_sh64_plt_entry_le
[PLT_ENTRY_SIZE
] =
2916 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
2917 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2918 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2919 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
2920 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
2921 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2922 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2923 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2924 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */
2925 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
2926 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
2927 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
2928 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
2929 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2930 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2931 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2934 /* Entries in a PIC procedure linkage table look like this. */
2936 static const bfd_byte elf_sh64_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
2938 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
2939 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
2940 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
2941 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2942 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2943 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2944 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2945 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2946 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
2947 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */
2948 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
2949 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2950 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
2951 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
2952 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
2953 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2956 static const bfd_byte elf_sh64_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
2958 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
2959 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
2960 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
2961 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2962 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2963 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2964 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2965 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2966 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
2967 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */
2968 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
2969 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2970 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
2971 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
2972 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
2973 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2976 static const bfd_byte
*elf_sh64_plt0_entry
;
2977 static const bfd_byte
*elf_sh64_plt_entry
;
2978 static const bfd_byte
*elf_sh64_pic_plt_entry
;
2980 /* Create an entry in an sh ELF linker hash table. */
2982 static struct bfd_hash_entry
*
2983 sh64_elf64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2984 struct bfd_hash_table
*table
,
2987 struct elf_sh64_link_hash_entry
*ret
=
2988 (struct elf_sh64_link_hash_entry
*) entry
;
2990 /* Allocate the structure if it has not already been allocated by a
2992 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
2993 ret
= ((struct elf_sh64_link_hash_entry
*)
2994 bfd_hash_allocate (table
,
2995 sizeof (struct elf_sh64_link_hash_entry
)));
2996 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
2997 return (struct bfd_hash_entry
*) ret
;
2999 /* Call the allocation method of the superclass. */
3000 ret
= ((struct elf_sh64_link_hash_entry
*)
3001 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3003 if (ret
!= (struct elf_sh64_link_hash_entry
*) NULL
)
3005 ret
->pcrel_relocs_copied
= NULL
;
3006 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3009 return (struct bfd_hash_entry
*) ret
;
3012 /* Create an sh64 ELF linker hash table. */
3014 static struct bfd_link_hash_table
*
3015 sh64_elf64_link_hash_table_create (bfd
*abfd
)
3017 struct elf_link_hash_table
*ret
;
3019 ret
= (struct elf_link_hash_table
*) bfd_zmalloc (sizeof (* ret
));
3020 if (ret
== (struct elf_link_hash_table
*) NULL
)
3023 if (!_bfd_elf_link_hash_table_init (ret
, abfd
,
3024 sh64_elf64_link_hash_newfunc
,
3025 sizeof (struct elf_sh64_link_hash_entry
),
3036 movi_shori_putval (bfd
*output_bfd
, unsigned long value
, bfd_byte
*addr
)
3038 bfd_put_32 (output_bfd
,
3039 bfd_get_32 (output_bfd
, addr
)
3040 | ((value
>> 6) & 0x3fffc00),
3042 bfd_put_32 (output_bfd
,
3043 bfd_get_32 (output_bfd
, addr
+ 4)
3044 | ((value
<< 10) & 0x3fffc00),
3049 movi_3shori_putval (bfd
*output_bfd
, bfd_vma value
, bfd_byte
*addr
)
3051 bfd_put_32 (output_bfd
,
3052 bfd_get_32 (output_bfd
, addr
)
3053 | ((value
>> 38) & 0x3fffc00),
3055 bfd_put_32 (output_bfd
,
3056 bfd_get_32 (output_bfd
, addr
+ 4)
3057 | ((value
>> 22) & 0x3fffc00),
3059 bfd_put_32 (output_bfd
,
3060 bfd_get_32 (output_bfd
, addr
+ 8)
3061 | ((value
>> 6) & 0x3fffc00),
3063 bfd_put_32 (output_bfd
,
3064 bfd_get_32 (output_bfd
, addr
+ 12)
3065 | ((value
<< 10) & 0x3fffc00),
3069 /* Create dynamic sections when linking against a dynamic object. */
3072 sh64_elf64_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3074 flagword flags
, pltflags
;
3075 register asection
*s
;
3076 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3079 switch (bed
->s
->arch_size
)
3090 bfd_set_error (bfd_error_bad_value
);
3094 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3095 .rel[a].bss sections. */
3097 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3098 | SEC_LINKER_CREATED
);
3101 pltflags
|= SEC_CODE
;
3102 if (bed
->plt_not_loaded
)
3103 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3104 if (bed
->plt_readonly
)
3105 pltflags
|= SEC_READONLY
;
3107 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
3109 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3112 if (bed
->want_plt_sym
)
3114 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3116 struct elf_link_hash_entry
*h
;
3117 struct bfd_link_hash_entry
*bh
= NULL
;
3119 if (! (_bfd_generic_link_add_one_symbol
3120 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3121 (bfd_vma
) 0, (const char *) NULL
, FALSE
, bed
->collect
, &bh
)))
3124 h
= (struct elf_link_hash_entry
*) bh
;
3126 h
->type
= STT_OBJECT
;
3127 elf_hash_table (info
)->hplt
= h
;
3129 if (bfd_link_pic (info
)
3130 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3134 s
= bfd_make_section_anyway_with_flags (abfd
,
3135 bed
->default_use_rela_p
3136 ? ".rela.plt" : ".rel.plt",
3137 flags
| SEC_READONLY
);
3139 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3142 if (! _bfd_elf_create_got_section (abfd
, info
))
3145 if (bed
->want_dynbss
)
3147 /* The .dynbss section is a place to put symbols which are defined
3148 by dynamic objects, are referenced by regular objects, and are
3149 not functions. We must allocate space for them in the process
3150 image and use a R_*_COPY reloc to tell the dynamic linker to
3151 initialize them at run time. The linker script puts the .dynbss
3152 section into the .bss section of the final image. */
3153 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
3154 SEC_ALLOC
| SEC_LINKER_CREATED
);
3158 /* The .rel[a].bss section holds copy relocs. This section is not
3159 normally needed. We need to create it here, though, so that the
3160 linker will map it to an output section. We can't just create it
3161 only if we need it, because we will not know whether we need it
3162 until we have seen all the input files, and the first time the
3163 main linker code calls BFD after examining all the input files
3164 (size_dynamic_sections) the input sections have already been
3165 mapped to the output sections. If the section turns out not to
3166 be needed, we can discard it later. We will never need this
3167 section when generating a shared object, since they do not use
3169 if (! bfd_link_pic (info
))
3171 s
= bfd_make_section_anyway_with_flags (abfd
,
3172 (bed
->default_use_rela_p
3173 ? ".rela.bss" : ".rel.bss"),
3174 flags
| SEC_READONLY
);
3176 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3184 /* Adjust a symbol defined by a dynamic object and referenced by a
3185 regular object. The current definition is in some section of the
3186 dynamic object, but we're not including those sections. We have to
3187 change the definition to something the rest of the link can
3191 sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3192 struct elf_link_hash_entry
*h
)
3197 dynobj
= elf_hash_table (info
)->dynobj
;
3199 /* Make sure we know what is going on here. */
3200 BFD_ASSERT (dynobj
!= NULL
3205 && !h
->def_regular
)));
3207 /* If this is a function, put it in the procedure linkage table. We
3208 will fill in the contents of the procedure linkage table later,
3209 when we know the address of the .got section. */
3210 if (h
->type
== STT_FUNC
3213 if (! bfd_link_pic (info
)
3217 /* This case can occur if we saw a PLT reloc in an input
3218 file, but the symbol was never referred to by a dynamic
3219 object. In such a case, we don't actually need to build
3220 a procedure linkage table, and we can just do a REL64
3222 BFD_ASSERT (h
->needs_plt
);
3226 /* Make sure this symbol is output as a dynamic symbol. */
3227 if (h
->dynindx
== -1)
3229 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3233 s
= elf_hash_table (info
)->splt
;
3234 BFD_ASSERT (s
!= NULL
);
3236 /* If this is the first .plt entry, make room for the special
3239 s
->size
+= PLT_ENTRY_SIZE
;
3241 /* If this symbol is not defined in a regular file, and we are
3242 not generating a shared library, then set the symbol to this
3243 location in the .plt. This is required to make function
3244 pointers compare as equal between the normal executable and
3245 the shared library. */
3246 if (! bfd_link_pic (info
)
3249 h
->root
.u
.def
.section
= s
;
3250 h
->root
.u
.def
.value
= s
->size
;
3253 h
->plt
.offset
= s
->size
;
3255 /* Make room for this entry. */
3256 s
->size
+= elf_sh64_sizeof_plt (info
);
3258 /* We also need to make an entry in the .got.plt section, which
3259 will be placed in the .got section by the linker script. */
3261 s
= elf_hash_table (info
)->sgotplt
;
3262 BFD_ASSERT (s
!= NULL
);
3265 /* We also need to make an entry in the .rela.plt section. */
3267 s
= elf_hash_table (info
)->srelplt
;
3268 BFD_ASSERT (s
!= NULL
);
3269 s
->size
+= sizeof (Elf64_External_Rela
);
3274 /* If this is a weak symbol, and there is a real definition, the
3275 processor independent code will have arranged for us to see the
3276 real definition first, and we can just use the same value. */
3277 if (h
->is_weakalias
)
3279 struct elf_link_hash_entry
*def
= weakdef (h
);
3280 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3281 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3282 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3286 /* This is a reference to a symbol defined by a dynamic object which
3287 is not a function. */
3289 /* If we are creating a shared library, we must presume that the
3290 only references to the symbol are via the global offset table.
3291 For such cases we need not do anything here; the relocations will
3292 be handled correctly by relocate_section. */
3293 if (bfd_link_pic (info
))
3296 /* If there are no references to this symbol that do not use the
3297 GOT, we don't need to generate a copy reloc. */
3298 if (!h
->non_got_ref
)
3301 /* We must allocate the symbol in our .dynbss section, which will
3302 become part of the .bss section of the executable. There will be
3303 an entry for this symbol in the .dynsym section. The dynamic
3304 object will contain position independent code, so all references
3305 from the dynamic object to this symbol will go through the global
3306 offset table. The dynamic linker will use the .dynsym entry to
3307 determine the address it must put in the global offset table, so
3308 both the dynamic object and the regular object will refer to the
3309 same memory location for the variable. */
3311 s
= bfd_get_linker_section (dynobj
, ".dynbss");
3312 BFD_ASSERT (s
!= NULL
);
3314 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3315 copy the initial value out of the dynamic object and into the
3316 runtime process image. We need to remember the offset into the
3317 .rela.bss section we are going to use. */
3318 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3322 srel
= bfd_get_linker_section (dynobj
, ".rela.bss");
3323 BFD_ASSERT (srel
!= NULL
);
3324 srel
->size
+= sizeof (Elf64_External_Rela
);
3328 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3331 /* This function is called via sh_elf_link_hash_traverse if we are
3332 creating a shared object with -Bsymbolic. It discards the space
3333 allocated to copy PC relative relocs against symbols which are
3334 defined in regular objects. We allocated space for them in the
3335 check_relocs routine, but we won't fill them in in the
3336 relocate_section routine. */
3339 sh64_elf64_discard_copies (struct elf_sh64_link_hash_entry
*h
,
3340 void *ignore ATTRIBUTE_UNUSED
)
3342 struct elf_sh64_pcrel_relocs_copied
*s
;
3344 /* We only discard relocs for symbols defined in a regular object. */
3345 if (!h
->root
.def_regular
)
3348 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3349 s
->section
->size
-= s
->count
* sizeof (Elf64_External_Rela
);
3354 /* Set the sizes of the dynamic sections. */
3357 sh64_elf64_size_dynamic_sections (bfd
*output_bfd
,
3358 struct bfd_link_info
*info
)
3364 bfd_boolean reltext
;
3366 dynobj
= elf_hash_table (info
)->dynobj
;
3367 BFD_ASSERT (dynobj
!= NULL
);
3369 if (elf_hash_table (info
)->dynamic_sections_created
)
3371 /* Set the contents of the .interp section to the interpreter. */
3372 if (bfd_link_executable (info
) && !info
->nointerp
)
3374 s
= bfd_get_linker_section (dynobj
, ".interp");
3375 BFD_ASSERT (s
!= NULL
);
3376 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3377 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3382 /* We may have created entries in the .rela.got section.
3383 However, if we are not creating the dynamic sections, we will
3384 not actually use these entries. Reset the size of .rela.got,
3385 which will cause it to get stripped from the output file
3387 s
= elf_hash_table (info
)->srelgot
;
3392 /* If this is a -Bsymbolic shared link, then we need to discard all
3393 PC relative relocs against symbols defined in a regular object.
3394 We allocated space for them in the check_relocs routine, but we
3395 will not fill them in in the relocate_section routine. */
3396 if (bfd_link_pic (info
) && info
->symbolic
)
3397 sh64_elf64_link_hash_traverse (elf_hash_table (info
),
3398 sh64_elf64_discard_copies
, NULL
);
3400 /* The check_relocs and adjust_dynamic_symbol entry points have
3401 determined the sizes of the various dynamic sections. Allocate
3406 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3410 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3413 /* It's OK to base decisions on the section name, because none
3414 of the dynobj section names depend upon the input files. */
3415 name
= bfd_get_section_name (dynobj
, s
);
3417 if (strcmp (name
, ".plt") == 0)
3419 /* Remember whether there is a PLT. */
3422 else if (CONST_STRNEQ (name
, ".rela"))
3428 /* Remember whether there are any reloc sections other
3430 if (strcmp (name
, ".rela.plt") != 0)
3432 const char *outname
;
3436 /* If this relocation section applies to a read only
3437 section, then we probably need a DT_TEXTREL
3438 entry. The entries in the .rela.plt section
3439 really apply to the .got section, which we
3440 created ourselves and so know is not readonly. */
3441 outname
= bfd_get_section_name (output_bfd
,
3443 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3445 && (target
->flags
& SEC_READONLY
) != 0
3446 && (target
->flags
& SEC_ALLOC
) != 0)
3450 /* We use the reloc_count field as a counter if we need
3451 to copy relocs into the output file. */
3455 else if (! CONST_STRNEQ (name
, ".got")
3456 && strcmp (name
, ".dynbss") != 0)
3458 /* It's not one of our sections, so don't allocate space. */
3464 /* If we don't need this section, strip it from the
3465 output file. This is mostly to handle .rela.bss and
3466 .rela.plt. We must create both sections in
3467 create_dynamic_sections, because they must be created
3468 before the linker maps input sections to output
3469 sections. The linker does that before
3470 adjust_dynamic_symbol is called, and it is that
3471 function which decides whether anything needs to go
3472 into these sections. */
3473 s
->flags
|= SEC_EXCLUDE
;
3477 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
3480 /* Allocate memory for the section contents. */
3481 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3482 if (s
->contents
== NULL
)
3486 if (elf_hash_table (info
)->dynamic_sections_created
)
3488 /* Add some entries to the .dynamic section. We fill in the
3489 values later, in sh64_elf64_finish_dynamic_sections, but we
3490 must add the entries now so that we get the correct size for
3491 the .dynamic section. The DT_DEBUG entry is filled in by the
3492 dynamic linker and used by the debugger. */
3493 if (bfd_link_executable (info
))
3495 if (!_bfd_elf_add_dynamic_entry (info
, DT_DEBUG
, 0))
3501 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0)
3502 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3503 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3504 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
3510 if (!_bfd_elf_add_dynamic_entry (info
, DT_RELA
, 0)
3511 || !_bfd_elf_add_dynamic_entry (info
, DT_RELASZ
, 0)
3512 || !_bfd_elf_add_dynamic_entry (info
, DT_RELAENT
,
3513 sizeof (Elf64_External_Rela
)))
3519 if (!_bfd_elf_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3527 /* Finish up dynamic symbol handling. We set the contents of various
3528 dynamic sections here. */
3531 sh64_elf64_finish_dynamic_symbol (bfd
*output_bfd
,
3532 struct bfd_link_info
*info
,
3533 struct elf_link_hash_entry
*h
,
3534 Elf_Internal_Sym
*sym
)
3538 dynobj
= elf_hash_table (info
)->dynobj
;
3540 if (h
->plt
.offset
!= (bfd_vma
) -1)
3548 Elf_Internal_Rela rel
;
3551 /* This symbol has an entry in the procedure linkage table. Set
3554 BFD_ASSERT (h
->dynindx
!= -1);
3556 splt
= elf_hash_table (info
)->splt
;
3557 sgot
= elf_hash_table (info
)->sgotplt
;
3558 srel
= elf_hash_table (info
)->srelplt
;
3559 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3561 /* Get the index in the procedure linkage table which
3562 corresponds to this symbol. This is the index of this symbol
3563 in all the symbols for which we are making plt entries. The
3564 first entry in the procedure linkage table is reserved. */
3565 plt_index
= h
->plt
.offset
/ elf_sh64_sizeof_plt (info
) - 1;
3567 /* Get the offset into the .got table of the entry that
3568 corresponds to this function. Each .got entry is 8 bytes.
3569 The first three are reserved. */
3570 got_offset
= (plt_index
+ 3) * 8;
3572 if (bfd_link_pic (info
))
3573 got_offset
-= GOT_BIAS
;
3575 /* Fill in the entry in the procedure linkage table. */
3576 if (! bfd_link_pic (info
))
3578 if (elf_sh64_plt_entry
== NULL
)
3580 elf_sh64_plt_entry
= (bfd_big_endian (output_bfd
) ?
3581 elf_sh64_plt_entry_be
: elf_sh64_plt_entry_le
);
3583 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_plt_entry
,
3584 elf_sh64_sizeof_plt (info
));
3585 movi_3shori_putval (output_bfd
,
3586 (sgot
->output_section
->vma
3587 + sgot
->output_offset
3589 (splt
->contents
+ h
->plt
.offset
3590 + elf_sh64_plt_symbol_offset (info
)));
3592 /* Set bottom bit because its for a branch to SHmedia */
3593 movi_shori_putval (output_bfd
,
3595 + elf_sh64_plt_plt0_offset (info
) + 8)
3597 (splt
->contents
+ h
->plt
.offset
3598 + elf_sh64_plt_plt0_offset (info
)));
3602 if (elf_sh64_pic_plt_entry
== NULL
)
3604 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3605 elf_sh64_pic_plt_entry_be
:
3606 elf_sh64_pic_plt_entry_le
);
3608 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_pic_plt_entry
,
3609 elf_sh64_sizeof_plt (info
));
3610 movi_shori_putval (output_bfd
, got_offset
,
3611 (splt
->contents
+ h
->plt
.offset
3612 + elf_sh64_plt_symbol_offset (info
)));
3615 if (bfd_link_pic (info
))
3616 got_offset
+= GOT_BIAS
;
3618 movi_shori_putval (output_bfd
,
3619 plt_index
* sizeof (Elf64_External_Rela
),
3620 (splt
->contents
+ h
->plt
.offset
3621 + elf_sh64_plt_reloc_offset (info
)));
3623 /* Fill in the entry in the global offset table. */
3624 bfd_put_64 (output_bfd
,
3625 (splt
->output_section
->vma
3626 + splt
->output_offset
3628 + elf_sh64_plt_temp_offset (info
)),
3629 sgot
->contents
+ got_offset
);
3631 /* Fill in the entry in the .rela.plt section. */
3632 rel
.r_offset
= (sgot
->output_section
->vma
3633 + sgot
->output_offset
3635 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_JMP_SLOT64
);
3637 rel
.r_addend
= GOT_BIAS
;
3638 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3639 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3641 if (!h
->def_regular
)
3643 /* Mark the symbol as undefined, rather than as defined in
3644 the .plt section. Leave the value alone. */
3645 sym
->st_shndx
= SHN_UNDEF
;
3649 if (h
->got
.offset
!= (bfd_vma
) -1)
3653 Elf_Internal_Rela rel
;
3656 /* This symbol has an entry in the global offset table. Set it
3659 sgot
= elf_hash_table (info
)->sgot
;
3660 srel
= elf_hash_table (info
)->srelgot
;
3661 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3663 rel
.r_offset
= (sgot
->output_section
->vma
3664 + sgot
->output_offset
3665 + (h
->got
.offset
&~ 1));
3667 /* If this is a -Bsymbolic link, and the symbol is defined
3668 locally, we just want to emit a RELATIVE reloc. Likewise if
3669 the symbol was forced to be local because of a version file.
3670 The entry in the global offset table will already have been
3671 initialized in the relocate_section function. */
3672 if (bfd_link_pic (info
)
3673 && (info
->symbolic
|| h
->dynindx
== -1)
3676 rel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
3677 rel
.r_addend
= (h
->root
.u
.def
.value
3678 + h
->root
.u
.def
.section
->output_section
->vma
3679 + h
->root
.u
.def
.section
->output_offset
);
3683 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3684 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_GLOB_DAT64
);
3688 loc
= srel
->contents
;
3689 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3690 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3696 Elf_Internal_Rela rel
;
3699 /* This symbol needs a copy reloc. Set it up. */
3701 BFD_ASSERT (h
->dynindx
!= -1
3702 && (h
->root
.type
== bfd_link_hash_defined
3703 || h
->root
.type
== bfd_link_hash_defweak
));
3705 s
= bfd_get_linker_section (dynobj
, ".rela.bss");
3706 BFD_ASSERT (s
!= NULL
);
3708 rel
.r_offset
= (h
->root
.u
.def
.value
3709 + h
->root
.u
.def
.section
->output_section
->vma
3710 + h
->root
.u
.def
.section
->output_offset
);
3711 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_COPY64
);
3714 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3715 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3718 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3719 if (h
== elf_hash_table (info
)->hdynamic
3720 || h
== elf_hash_table (info
)->hgot
)
3721 sym
->st_shndx
= SHN_ABS
;
3726 /* Finish up the dynamic sections. */
3729 sh64_elf64_finish_dynamic_sections (bfd
*output_bfd
,
3730 struct bfd_link_info
*info
)
3736 dynobj
= elf_hash_table (info
)->dynobj
;
3738 sgot
= elf_hash_table (info
)->sgotplt
;
3739 BFD_ASSERT (sgot
!= NULL
);
3740 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
3742 if (elf_hash_table (info
)->dynamic_sections_created
)
3745 Elf64_External_Dyn
*dyncon
, *dynconend
;
3747 BFD_ASSERT (sdyn
!= NULL
);
3749 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3750 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3751 for (; dyncon
< dynconend
; dyncon
++)
3753 Elf_Internal_Dyn dyn
;
3756 struct elf_link_hash_entry
*h
;
3758 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3766 name
= info
->init_function
;
3770 name
= info
->fini_function
;
3772 if (dyn
.d_un
.d_val
!= 0)
3774 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
3775 FALSE
, FALSE
, TRUE
);
3776 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
3778 dyn
.d_un
.d_val
|= 1;
3779 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3785 s
= elf_hash_table (info
)->sgotplt
;
3789 s
= elf_hash_table (info
)->srelplt
;
3791 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3792 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3796 s
= elf_hash_table (info
)->srelplt
;
3797 dyn
.d_un
.d_val
= s
->size
;
3798 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3803 /* Fill in the first entry in the procedure linkage table. */
3804 splt
= elf_hash_table (info
)->splt
;
3805 if (splt
&& splt
->size
> 0)
3807 if (bfd_link_pic (info
))
3809 if (elf_sh64_pic_plt_entry
== NULL
)
3811 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3812 elf_sh64_pic_plt_entry_be
:
3813 elf_sh64_pic_plt_entry_le
);
3815 memcpy (splt
->contents
, elf_sh64_pic_plt_entry
,
3816 elf_sh64_sizeof_plt (info
));
3820 if (elf_sh64_plt0_entry
== NULL
)
3822 elf_sh64_plt0_entry
= (bfd_big_endian (output_bfd
) ?
3823 elf_sh64_plt0_entry_be
:
3824 elf_sh64_plt0_entry_le
);
3826 memcpy (splt
->contents
, elf_sh64_plt0_entry
, PLT_ENTRY_SIZE
);
3827 movi_3shori_putval (output_bfd
,
3828 sgot
->output_section
->vma
3829 + sgot
->output_offset
,
3831 + elf_sh64_plt0_gotplt_offset (info
));
3834 /* UnixWare sets the entsize of .plt to 8, although that doesn't
3835 really seem like the right value. */
3836 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 8;
3840 /* Fill in the first three entries in the global offset table. */
3844 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
3846 bfd_put_64 (output_bfd
,
3847 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3849 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
3850 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 16);
3853 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
3858 /* Merge non visibility st_other attribute when the symbol comes from
3859 a dynamic object. */
3861 sh64_elf64_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3862 const Elf_Internal_Sym
*isym
,
3863 bfd_boolean definition
,
3864 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
3866 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
3868 unsigned char other
;
3870 /* Take the balance of OTHER from the definition. */
3871 other
= (definition
? isym
->st_other
: h
->other
);
3872 other
&= ~ ELF_ST_VISIBILITY (-1);
3873 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
3879 static const struct bfd_elf_special_section sh64_elf64_special_sections
[]=
3881 { STRING_COMMA_LEN (".cranges"), 0, SHT_PROGBITS
, 0 },
3882 { NULL
, 0, 0, 0, 0 }
3885 #define TARGET_BIG_SYM sh64_elf64_vec
3886 #define TARGET_BIG_NAME "elf64-sh64"
3887 #define TARGET_LITTLE_SYM sh64_elf64_le_vec
3888 #define TARGET_LITTLE_NAME "elf64-sh64l"
3889 #define ELF_ARCH bfd_arch_sh
3890 #define ELF_MACHINE_CODE EM_SH
3891 #define ELF_MAXPAGESIZE 128
3893 #define elf_symbol_leading_char '_'
3895 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
3896 #define bfd_elf64_bfd_reloc_name_lookup \
3897 sh_elf64_reloc_name_lookup
3898 #define elf_info_to_howto sh_elf64_info_to_howto
3900 /* Note: there's no relaxation at present. */
3902 #define elf_backend_relocate_section sh_elf64_relocate_section
3903 #define bfd_elf64_bfd_get_relocated_section_contents \
3904 sh_elf64_get_relocated_section_contents
3905 #define elf_backend_object_p sh_elf64_set_mach_from_flags
3906 #define bfd_elf64_bfd_set_private_flags \
3907 sh_elf64_set_private_flags
3908 #define bfd_elf64_bfd_copy_private_bfd_data \
3909 sh_elf64_copy_private_data
3910 #define bfd_elf64_bfd_merge_private_bfd_data \
3911 sh_elf64_merge_private_data
3912 #define elf_backend_fake_sections sh64_elf64_fake_sections
3914 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
3915 #define elf_backend_check_relocs sh_elf64_check_relocs
3917 #define elf_backend_can_gc_sections 1
3919 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
3921 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
3923 #define elf_backend_link_output_symbol_hook \
3924 sh64_elf64_link_output_symbol_hook
3926 #define elf_backend_merge_symbol_attribute \
3927 sh64_elf64_merge_symbol_attribute
3929 #define elf_backend_final_write_processing \
3930 sh64_elf64_final_write_processing
3932 #define elf_backend_create_dynamic_sections \
3933 sh64_elf64_create_dynamic_sections
3934 #define bfd_elf64_bfd_link_hash_table_create \
3935 sh64_elf64_link_hash_table_create
3936 #define elf_backend_adjust_dynamic_symbol \
3937 sh64_elf64_adjust_dynamic_symbol
3938 #define elf_backend_size_dynamic_sections \
3939 sh64_elf64_size_dynamic_sections
3940 #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
3941 #define elf_backend_finish_dynamic_symbol \
3942 sh64_elf64_finish_dynamic_symbol
3943 #define elf_backend_finish_dynamic_sections \
3944 sh64_elf64_finish_dynamic_sections
3945 #define elf_backend_special_sections sh64_elf64_special_sections
3947 #define elf_backend_want_got_plt 1
3948 #define elf_backend_plt_readonly 1
3949 #define elf_backend_want_plt_sym 0
3950 #define elf_backend_got_header_size 24
3951 #define elf_backend_dtrel_excludes_plt 1
3953 #define elf_backend_linux_prpsinfo64_ugid16 TRUE
3955 #include "elf64-target.h"
3957 /* NetBSD support. */
3958 #undef TARGET_BIG_SYM
3959 #define TARGET_BIG_SYM sh64_elf64_nbsd_vec
3960 #undef TARGET_BIG_NAME
3961 #define TARGET_BIG_NAME "elf64-sh64-nbsd"
3962 #undef TARGET_LITTLE_SYM
3963 #define TARGET_LITTLE_SYM sh64_elf64_nbsd_le_vec
3964 #undef TARGET_LITTLE_NAME
3965 #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd"
3966 #undef ELF_MAXPAGESIZE
3967 #define ELF_MAXPAGESIZE 0x10000
3968 #undef elf_symbol_leading_char
3969 #define elf_symbol_leading_char 0
3971 #define elf64_bed elf64_sh64_nbsd_bed
3973 #include "elf64-target.h"
3975 /* Linux support. */
3976 #undef TARGET_BIG_SYM
3977 #define TARGET_BIG_SYM sh64_elf64_linux_be_vec
3978 #undef TARGET_BIG_NAME
3979 #define TARGET_BIG_NAME "elf64-sh64big-linux"
3980 #undef TARGET_LITTLE_SYM
3981 #define TARGET_LITTLE_SYM sh64_elf64_linux_vec
3982 #undef TARGET_LITTLE_NAME
3983 #define TARGET_LITTLE_NAME "elf64-sh64-linux"
3985 #define elf64_bed elf64_sh64_linux_bed
3987 #include "elf64-target.h"