1 /* Renesas SH64-specific support for 64-bit ELF
2 Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 /* Add a suffix for datalabel indirection symbols. It must not match any
30 other symbols; user symbols with or without version or other
31 decoration. It must only be used internally and not emitted by any
33 #define DATALABEL_SUFFIX " DL"
35 #define GOT_BIAS (-((long)-32768))
37 #define PLT_ENTRY_SIZE 64
39 /* Return size of a PLT entry. */
40 #define elf_sh64_sizeof_plt(info) PLT_ENTRY_SIZE
42 /* Return offset of the PLT0 address in an absolute PLT entry. */
43 #define elf_sh64_plt_plt0_offset(info) 32
45 /* Return offset of the linker in PLT0 entry. */
46 #define elf_sh64_plt0_gotplt_offset(info) 0
48 /* Return offset of the trampoline in PLT entry */
49 #define elf_sh64_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
51 /* Return offset of the symbol in PLT entry. */
52 #define elf_sh64_plt_symbol_offset(info) 0
54 /* Return offset of the relocation in PLT entry. */
55 #define elf_sh64_plt_reloc_offset(info) (info->shared ? 52 : 44)
57 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
59 /* The sh linker needs to keep track of the number of relocs that it
60 decides to copy in check_relocs for each symbol. This is so that
61 it can discard PC relative relocs if it doesn't need them when
62 linking with -Bsymbolic. We store the information in a field
63 extending the regular ELF linker hash table. */
65 /* This structure keeps track of the number of PC relative relocs we
66 have copied for a given symbol. */
68 struct elf_sh64_pcrel_relocs_copied
71 struct elf_sh64_pcrel_relocs_copied
*next
;
72 /* A section in dynobj. */
74 /* Number of relocs copied in this section. */
78 /* sh ELF linker hash entry. */
80 struct elf_sh64_link_hash_entry
82 struct elf_link_hash_entry root
;
84 bfd_vma datalabel_got_offset
;
86 /* Number of PC relative relocs copied for this symbol. */
87 struct elf_sh64_pcrel_relocs_copied
*pcrel_relocs_copied
;
90 /* sh ELF linker hash table. */
92 struct elf_sh64_link_hash_table
94 struct elf_link_hash_table root
;
97 /* Traverse an sh ELF linker hash table. */
99 #define sh64_elf64_link_hash_traverse(table, func, info) \
100 (elf_link_hash_traverse \
102 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
105 /* Get the sh ELF linker hash table from a link_info structure. */
107 #define sh64_elf64_hash_table(p) \
108 ((struct elf_sh64_link_hash_table *) ((p)->hash))
110 static bfd_boolean sh_elf64_copy_private_data
111 PARAMS ((bfd
*, bfd
*));
112 static bfd_boolean sh_elf64_copy_private_data_internal
113 PARAMS ((bfd
*, bfd
*));
114 static bfd_boolean sh_elf64_merge_private_data
115 PARAMS ((bfd
*, bfd
*));
116 static bfd_reloc_status_type sh_elf64_ignore_reloc
117 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
118 static bfd_reloc_status_type sh_elf64_reloc
119 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
120 static reloc_howto_type
*sh_elf64_reloc_type_lookup
121 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
122 static void sh_elf64_info_to_howto
123 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
124 static bfd_boolean sh_elf64_relocate_section
125 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
126 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
127 static bfd_byte
*sh_elf64_get_relocated_section_contents
128 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
129 bfd_byte
*, bfd_boolean
, asymbol
**));
130 static bfd_boolean sh_elf64_set_mach_from_flags
132 static bfd_boolean sh_elf64_set_private_flags
133 PARAMS ((bfd
*, flagword
));
134 static asection
*sh_elf64_gc_mark_hook
135 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
136 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
137 static bfd_boolean sh_elf64_gc_sweep_hook
138 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
139 const Elf_Internal_Rela
*));
140 static bfd_boolean sh_elf64_check_relocs
141 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
142 const Elf_Internal_Rela
*));
143 static int sh64_elf64_get_symbol_type
144 PARAMS ((Elf_Internal_Sym
*, int));
145 static bfd_boolean sh64_elf64_add_symbol_hook
146 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
147 const char **, flagword
*, asection
**, bfd_vma
*));
148 static bfd_boolean sh64_elf64_link_output_symbol_hook
149 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
151 static bfd_boolean sh64_elf64_fake_sections
152 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
153 static void sh64_elf64_final_write_processing
154 PARAMS ((bfd
*, bfd_boolean
));
155 static struct bfd_hash_entry
*sh64_elf64_link_hash_newfunc
156 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
157 static struct bfd_link_hash_table
*sh64_elf64_link_hash_table_create
159 inline static void movi_shori_putval
160 PARAMS ((bfd
*, unsigned long, char *));
161 inline static void movi_3shori_putval
162 PARAMS ((bfd
*, bfd_vma
, char *));
163 static bfd_boolean sh64_elf64_create_dynamic_sections
164 PARAMS ((bfd
*, struct bfd_link_info
*));
165 static bfd_boolean sh64_elf64_adjust_dynamic_symbol
166 PARAMS ((struct bfd_link_info
*info
, struct elf_link_hash_entry
*));
167 static bfd_boolean sh64_elf64_discard_copies
168 PARAMS ((struct elf_sh64_link_hash_entry
*, PTR
));
169 static bfd_boolean sh64_elf64_size_dynamic_sections
170 PARAMS ((bfd
*, struct bfd_link_info
*));
171 static bfd_boolean sh64_elf64_finish_dynamic_symbol
172 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
173 Elf_Internal_Sym
*));
174 static bfd_boolean sh64_elf64_finish_dynamic_sections
175 PARAMS ((bfd
*, struct bfd_link_info
*));
177 static reloc_howto_type sh_elf64_howto_table
[] = {
179 HOWTO (R_SH_NONE
, /* type */
181 0, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_dont
, /* complain_on_overflow */
186 sh_elf64_ignore_reloc
, /* special_function */
187 "R_SH_NONE", /* name */
188 FALSE
, /* partial_inplace */
191 FALSE
), /* pcrel_offset */
193 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
194 src_mask to a non-zero value is similar to the COFF toolchain. */
195 HOWTO (R_SH_DIR32
, /* type */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
199 FALSE
, /* pc_relative */
201 complain_overflow_bitfield
, /* complain_on_overflow */
202 sh_elf64_reloc
, /* special_function */
203 "R_SH_DIR32", /* name */
204 TRUE
, /* partial_inplace */
205 0xffffffff, /* src_mask */
206 0xffffffff, /* dst_mask */
207 FALSE
), /* pcrel_offset */
209 /* 32 bit PC relative relocation. */
210 HOWTO (R_SH_REL32
, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 TRUE
, /* pc_relative */
216 complain_overflow_signed
, /* complain_on_overflow */
217 sh_elf64_ignore_reloc
, /* special_function */
218 "R_SH_REL32", /* name */
219 FALSE
, /* partial_inplace */
221 0xffffffff, /* dst_mask */
222 TRUE
), /* pcrel_offset */
224 /* For 32-bit sh, this is R_SH_DIR8WPN. */
227 /* For 32-bit sh, this is R_SH_IND12W. */
230 /* For 32-bit sh, this is R_SH_DIR8WPL. */
233 /* For 32-bit sh, this is R_SH_DIR8WPZ. */
236 /* For 32-bit sh, this is R_SH_DIR8BP. */
239 /* For 32-bit sh, this is R_SH_DIR8W. */
242 /* For 32-bit sh, this is R_SH_DIR8L. */
261 /* The remaining relocs are a GNU extension used for relaxing. The
262 final pass of the linker never needs to do anything with any of
263 these relocs. Any required operations are handled by the
266 /* A 16 bit switch table entry. This is generated for an expression
267 such as ``.word L1 - L2''. The offset holds the difference
268 between the reloc address and L2. */
269 HOWTO (R_SH_SWITCH16
, /* type */
271 1, /* size (0 = byte, 1 = short, 2 = long) */
273 FALSE
, /* pc_relative */
275 complain_overflow_unsigned
, /* complain_on_overflow */
276 sh_elf64_ignore_reloc
, /* special_function */
277 "R_SH_SWITCH16", /* name */
278 FALSE
, /* partial_inplace */
281 TRUE
), /* pcrel_offset */
283 /* A 32 bit switch table entry. This is generated for an expression
284 such as ``.long L1 - L2''. The offset holds the difference
285 between the reloc address and L2. */
286 HOWTO (R_SH_SWITCH32
, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 FALSE
, /* pc_relative */
292 complain_overflow_unsigned
, /* complain_on_overflow */
293 sh_elf64_ignore_reloc
, /* special_function */
294 "R_SH_SWITCH32", /* name */
295 FALSE
, /* partial_inplace */
298 TRUE
), /* pcrel_offset */
300 /* For 32-bit sh, this is R_SH_USES. */
303 /* For 32-bit sh, this is R_SH_COUNT. */
306 /* For 32-bit sh, this is R_SH_ALIGN. FIXME: For linker relaxation,
307 this might be emitted. When linker relaxation is implemented, we
308 might want to use it. */
311 /* For 32-bit sh, this is R_SH_CODE. FIXME: For linker relaxation,
312 this might be emitted. When linker relaxation is implemented, we
313 might want to use it. */
316 /* For 32-bit sh, this is R_SH_DATA. FIXME: For linker relaxation,
317 this might be emitted. When linker relaxation is implemented, we
318 might want to use it. */
321 /* For 32-bit sh, this is R_SH_LABEL. FIXME: For linker relaxation,
322 this might be emitted. When linker relaxation is implemented, we
323 might want to use it. */
326 /* An 8 bit switch table entry. This is generated for an expression
327 such as ``.word L1 - L2''. The offset holds the difference
328 between the reloc address and L2. */
329 HOWTO (R_SH_SWITCH8
, /* type */
331 0, /* size (0 = byte, 1 = short, 2 = long) */
333 FALSE
, /* pc_relative */
335 complain_overflow_unsigned
, /* complain_on_overflow */
336 sh_elf64_ignore_reloc
, /* special_function */
337 "R_SH_SWITCH8", /* name */
338 FALSE
, /* partial_inplace */
341 TRUE
), /* pcrel_offset */
343 /* GNU extension to record C++ vtable hierarchy */
344 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
350 complain_overflow_dont
, /* complain_on_overflow */
351 NULL
, /* special_function */
352 "R_SH_GNU_VTINHERIT", /* name */
353 FALSE
, /* partial_inplace */
356 FALSE
), /* pcrel_offset */
358 /* GNU extension to record C++ vtable member usage */
359 HOWTO (R_SH_GNU_VTENTRY
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
365 complain_overflow_dont
, /* complain_on_overflow */
366 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
367 "R_SH_GNU_VTENTRY", /* name */
368 FALSE
, /* partial_inplace */
371 FALSE
), /* pcrel_offset */
373 /* For 32-bit sh, this is R_SH_LOOP_START. */
376 /* For 32-bit sh, this is R_SH_LOOP_END. */
387 /* Used in SHLLI.L and SHLRI.L. */
388 HOWTO (R_SH_DIR5U
, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE
, /* pc_relative */
394 complain_overflow_unsigned
, /* complain_on_overflow */
395 bfd_elf_generic_reloc
, /* special_function */
396 "R_SH_DIR5U", /* name */
397 FALSE
, /* partial_inplace */
399 0xfc00, /* dst_mask */
400 FALSE
), /* pcrel_offset */
402 /* Used in SHARI, SHLLI et al. */
403 HOWTO (R_SH_DIR6U
, /* type */
405 2, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE
, /* pc_relative */
409 complain_overflow_unsigned
, /* complain_on_overflow */
410 bfd_elf_generic_reloc
, /* special_function */
411 "R_SH_DIR6U", /* name */
412 FALSE
, /* partial_inplace */
414 0xfc00, /* dst_mask */
415 FALSE
), /* pcrel_offset */
417 /* Used in BxxI, LDHI.L et al. */
418 HOWTO (R_SH_DIR6S
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_SH_DIR6S", /* name */
427 FALSE
, /* partial_inplace */
429 0xfc00, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* Used in ADDI, ANDI et al. */
433 HOWTO (R_SH_DIR10S
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE
, /* pc_relative */
439 complain_overflow_signed
, /* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_SH_DIR10S", /* name */
442 FALSE
, /* partial_inplace */
444 0xffc00, /* dst_mask */
445 FALSE
), /* pcrel_offset */
447 /* Used in LD.UW, ST.W et al. */
448 HOWTO (R_SH_DIR10SW
, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE
, /* pc_relative */
454 complain_overflow_signed
, /* complain_on_overflow */
455 bfd_elf_generic_reloc
, /* special_function */
456 "R_SH_DIR10SW", /* name */
457 FALSE
, /* partial_inplace */
459 0xffc00, /* dst_mask */
460 FALSE
), /* pcrel_offset */
462 /* Used in LD.L, FLD.S et al. */
463 HOWTO (R_SH_DIR10SL
, /* type */
465 2, /* size (0 = byte, 1 = short, 2 = long) */
467 FALSE
, /* pc_relative */
469 complain_overflow_signed
, /* complain_on_overflow */
470 bfd_elf_generic_reloc
, /* special_function */
471 "R_SH_DIR10SL", /* name */
472 FALSE
, /* partial_inplace */
474 0xffc00, /* dst_mask */
475 FALSE
), /* pcrel_offset */
477 /* Used in FLD.D, FST.P et al. */
478 HOWTO (R_SH_DIR10SQ
, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 FALSE
, /* pc_relative */
484 complain_overflow_signed
, /* complain_on_overflow */
485 bfd_elf_generic_reloc
, /* special_function */
486 "R_SH_DIR10SQ", /* name */
487 FALSE
, /* partial_inplace */
489 0xffc00, /* dst_mask */
490 FALSE
), /* pcrel_offset */
601 /* Relocs for dynamic linking for 32-bit SH would follow. We don't have
602 any dynamic linking support for 64-bit SH at present. */
614 /* Back to SH5 relocations. */
615 /* Used in MOVI and SHORI (x & 65536). */
616 HOWTO (R_SH_GOT_LOW16
, /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 FALSE
, /* pc_relative */
622 complain_overflow_dont
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_SH_GOT_LOW16", /* name */
625 FALSE
, /* partial_inplace */
627 0x3fffc00, /* dst_mask */
628 FALSE
), /* pcrel_offset */
630 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
631 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 FALSE
, /* pc_relative */
637 complain_overflow_dont
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_SH_GOT_MEDLOW16", /* name */
640 FALSE
, /* partial_inplace */
642 0x3fffc00, /* dst_mask */
643 FALSE
), /* pcrel_offset */
645 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
646 HOWTO (R_SH_GOT_MEDHI16
, /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 FALSE
, /* pc_relative */
652 complain_overflow_dont
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 "R_SH_GOT_MEDHI16", /* name */
655 FALSE
, /* partial_inplace */
657 0x3fffc00, /* dst_mask */
658 FALSE
), /* pcrel_offset */
660 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
661 HOWTO (R_SH_GOT_HI16
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 FALSE
, /* pc_relative */
667 complain_overflow_dont
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_SH_GOT_HI16", /* name */
670 FALSE
, /* partial_inplace */
672 0x3fffc00, /* dst_mask */
673 FALSE
), /* pcrel_offset */
675 /* Used in MOVI and SHORI (x & 65536). */
676 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_SH_GOTPLT_LOW16", /* name */
685 FALSE
, /* partial_inplace */
687 0x3fffc00, /* dst_mask */
688 FALSE
), /* pcrel_offset */
690 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
691 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE
, /* pc_relative */
697 complain_overflow_dont
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 "R_SH_GOTPLT_MEDLOW16", /* name */
700 FALSE
, /* partial_inplace */
702 0x3fffc00, /* dst_mask */
703 FALSE
), /* pcrel_offset */
705 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
706 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_SH_GOTPLT_MEDHI16", /* name */
715 FALSE
, /* partial_inplace */
717 0x3fffc00, /* dst_mask */
718 FALSE
), /* pcrel_offset */
720 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
721 HOWTO (R_SH_GOTPLT_HI16
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 FALSE
, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_SH_GOTPLT_HI16", /* name */
730 FALSE
, /* partial_inplace */
732 0x3fffc00, /* dst_mask */
733 FALSE
), /* pcrel_offset */
735 /* Used in MOVI and SHORI (x & 65536). */
736 HOWTO (R_SH_PLT_LOW16
, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 TRUE
, /* pc_relative */
742 complain_overflow_dont
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_SH_PLT_LOW16", /* name */
745 FALSE
, /* partial_inplace */
747 0x3fffc00, /* dst_mask */
748 TRUE
), /* pcrel_offset */
750 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
751 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
753 2, /* size (0 = byte, 1 = short, 2 = long) */
755 TRUE
, /* pc_relative */
757 complain_overflow_dont
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_SH_PLT_MEDLOW16", /* name */
760 FALSE
, /* partial_inplace */
762 0x3fffc00, /* dst_mask */
763 TRUE
), /* pcrel_offset */
765 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
766 HOWTO (R_SH_PLT_MEDHI16
, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 TRUE
, /* pc_relative */
772 complain_overflow_dont
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* special_function */
774 "R_SH_PLT_MEDHI16", /* name */
775 FALSE
, /* partial_inplace */
777 0x3fffc00, /* dst_mask */
778 TRUE
), /* pcrel_offset */
780 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
781 HOWTO (R_SH_PLT_HI16
, /* type */
783 2, /* size (0 = byte, 1 = short, 2 = long) */
785 TRUE
, /* pc_relative */
787 complain_overflow_dont
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_SH_PLT_HI16", /* name */
790 FALSE
, /* partial_inplace */
792 0x3fffc00, /* dst_mask */
793 TRUE
), /* pcrel_offset */
795 /* Used in MOVI and SHORI (x & 65536). */
796 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE
, /* pc_relative */
802 complain_overflow_dont
, /* complain_on_overflow */
803 bfd_elf_generic_reloc
, /* special_function */
804 "R_SH_GOTOFF_LOW16", /* name */
805 FALSE
, /* partial_inplace */
807 0x3fffc00, /* dst_mask */
808 FALSE
), /* pcrel_offset */
810 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
811 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE
, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_SH_GOTOFF_MEDLOW16", /* name */
820 FALSE
, /* partial_inplace */
822 0x3fffc00, /* dst_mask */
823 FALSE
), /* pcrel_offset */
825 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
826 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE
, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_SH_GOTOFF_MEDHI16", /* name */
835 FALSE
, /* partial_inplace */
837 0x3fffc00, /* dst_mask */
838 FALSE
), /* pcrel_offset */
840 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
841 HOWTO (R_SH_GOTOFF_HI16
, /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 bfd_elf_generic_reloc
, /* special_function */
849 "R_SH_GOTOFF_HI16", /* name */
850 FALSE
, /* partial_inplace */
852 0x3fffc00, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* Used in MOVI and SHORI (x & 65536). */
856 HOWTO (R_SH_GOTPC_LOW16
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 TRUE
, /* pc_relative */
862 complain_overflow_dont
, /* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_SH_GOTPC_LOW16", /* name */
865 FALSE
, /* partial_inplace */
867 0x3fffc00, /* dst_mask */
868 TRUE
), /* pcrel_offset */
870 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
871 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 TRUE
, /* pc_relative */
877 complain_overflow_dont
, /* complain_on_overflow */
878 bfd_elf_generic_reloc
, /* special_function */
879 "R_SH_GOTPC_MEDLOW16", /* name */
880 FALSE
, /* partial_inplace */
882 0x3fffc00, /* dst_mask */
883 TRUE
), /* pcrel_offset */
885 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
886 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 TRUE
, /* pc_relative */
892 complain_overflow_dont
, /* complain_on_overflow */
893 bfd_elf_generic_reloc
, /* special_function */
894 "R_SH_GOTPC_MEDHI16", /* name */
895 FALSE
, /* partial_inplace */
897 0x3fffc00, /* dst_mask */
898 TRUE
), /* pcrel_offset */
900 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
901 HOWTO (R_SH_GOTPC_HI16
, /* type */
903 2, /* size (0 = byte, 1 = short, 2 = long) */
905 TRUE
, /* pc_relative */
907 complain_overflow_dont
, /* complain_on_overflow */
908 bfd_elf_generic_reloc
, /* special_function */
909 "R_SH_GOTPC_HI16", /* name */
910 FALSE
, /* partial_inplace */
912 0x3fffc00, /* dst_mask */
913 TRUE
), /* pcrel_offset */
915 /* Used in LD.L, FLD.S et al. */
916 HOWTO (R_SH_GOT10BY4
, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE
, /* pc_relative */
922 complain_overflow_signed
, /* complain_on_overflow */
923 bfd_elf_generic_reloc
, /* special_function */
924 "R_SH_GOT10BY4", /* name */
925 FALSE
, /* partial_inplace */
927 0xffc00, /* dst_mask */
928 FALSE
), /* pcrel_offset */
930 /* Used in LD.L, FLD.S et al. */
931 HOWTO (R_SH_GOTPLT10BY4
, /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE
, /* pc_relative */
937 complain_overflow_signed
, /* complain_on_overflow */
938 bfd_elf_generic_reloc
, /* special_function */
939 "R_SH_GOTPLT10BY4", /* name */
940 FALSE
, /* partial_inplace */
942 0xffc00, /* dst_mask */
943 FALSE
), /* pcrel_offset */
945 /* Used in FLD.D, FST.P et al. */
946 HOWTO (R_SH_GOT10BY8
, /* type */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
950 FALSE
, /* pc_relative */
952 complain_overflow_signed
, /* complain_on_overflow */
953 bfd_elf_generic_reloc
, /* special_function */
954 "R_SH_GOT10BY8", /* name */
955 FALSE
, /* partial_inplace */
957 0xffc00, /* dst_mask */
958 FALSE
), /* pcrel_offset */
960 /* Used in FLD.D, FST.P et al. */
961 HOWTO (R_SH_GOTPLT10BY8
, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE
, /* pc_relative */
967 complain_overflow_signed
, /* complain_on_overflow */
968 bfd_elf_generic_reloc
, /* special_function */
969 "R_SH_GOTPLT10BY8", /* name */
970 FALSE
, /* partial_inplace */
972 0xffc00, /* dst_mask */
973 FALSE
), /* pcrel_offset */
975 HOWTO (R_SH_COPY64
, /* type */
977 4, /* size (0 = byte, 1 = short, 2 = long) */
979 FALSE
, /* pc_relative */
981 complain_overflow_dont
, /* complain_on_overflow */
982 bfd_elf_generic_reloc
, /* special_function */
983 "R_SH_COPY64", /* name */
984 FALSE
, /* partial_inplace */
986 ((bfd_vma
) 0) - 1, /* dst_mask */
987 FALSE
), /* pcrel_offset */
989 HOWTO (R_SH_GLOB_DAT64
, /* type */
991 4, /* size (0 = byte, 1 = short, 2 = long) */
993 FALSE
, /* pc_relative */
995 complain_overflow_dont
, /* complain_on_overflow */
996 bfd_elf_generic_reloc
, /* special_function */
997 "R_SH_GLOB_DAT64", /* name */
998 FALSE
, /* partial_inplace */
1000 ((bfd_vma
) 0) - 1, /* dst_mask */
1001 FALSE
), /* pcrel_offset */
1003 HOWTO (R_SH_JMP_SLOT64
, /* type */
1005 4, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE
, /* pc_relative */
1009 complain_overflow_dont
, /* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_SH_JMP_SLOT64", /* name */
1012 FALSE
, /* partial_inplace */
1014 ((bfd_vma
) 0) - 1, /* dst_mask */
1015 FALSE
), /* pcrel_offset */
1017 HOWTO (R_SH_RELATIVE64
, /* type */
1019 4, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_dont
, /* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_SH_RELATIVE64", /* name */
1026 FALSE
, /* partial_inplace */
1028 ((bfd_vma
) 0) - 1, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1077 /* Relocations for SHmedia code. None of these are partial_inplace or
1078 use the field being relocated. */
1080 /* The assembler will generate this reloc before a block of SHmedia
1081 instructions. A section should be processed as assuming it contains
1082 data, unless this reloc is seen. Note that a block of SHcompact
1083 instructions are instead preceded by R_SH_CODE.
1084 This is currently not implemented, but should be used for SHmedia
1085 linker relaxation. */
1086 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1088 1, /* size (0 = byte, 1 = short, 2 = long) */
1090 FALSE
, /* pc_relative */
1092 complain_overflow_unsigned
, /* complain_on_overflow */
1093 sh_elf64_ignore_reloc
, /* special_function */
1094 "R_SH_SHMEDIA_CODE", /* name */
1095 FALSE
, /* partial_inplace */
1098 FALSE
), /* pcrel_offset */
1100 /* The assembler will generate this reloc at a PTA or PTB instruction,
1101 and the linker checks the right type of target, or changes a PTA to a
1102 PTB, if the original insn was PT. */
1103 HOWTO (R_SH_PT_16
, /* type */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 TRUE
, /* pc_relative */
1109 complain_overflow_signed
, /* complain_on_overflow */
1110 bfd_elf_generic_reloc
, /* special_function */
1111 "R_SH_PT_16", /* name */
1112 FALSE
, /* partial_inplace */
1114 0x3fffc00, /* dst_mask */
1115 TRUE
), /* pcrel_offset */
1117 /* Used in unexpanded MOVI. */
1118 HOWTO (R_SH_IMMS16
, /* type */
1120 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE
, /* pc_relative */
1124 complain_overflow_signed
, /* complain_on_overflow */
1125 bfd_elf_generic_reloc
, /* special_function */
1126 "R_SH_IMMS16", /* name */
1127 FALSE
, /* partial_inplace */
1129 0x3fffc00, /* dst_mask */
1130 FALSE
), /* pcrel_offset */
1132 /* Used in SHORI. */
1133 HOWTO (R_SH_IMMU16
, /* type */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE
, /* pc_relative */
1139 complain_overflow_unsigned
, /* complain_on_overflow */
1140 bfd_elf_generic_reloc
, /* special_function */
1141 "R_SH_IMMU16", /* name */
1142 FALSE
, /* partial_inplace */
1144 0x3fffc00, /* dst_mask */
1145 FALSE
), /* pcrel_offset */
1147 /* Used in MOVI and SHORI (x & 65536). */
1148 HOWTO (R_SH_IMM_LOW16
, /* type */
1150 2, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_dont
, /* complain_on_overflow */
1155 bfd_elf_generic_reloc
, /* special_function */
1156 "R_SH_IMM_LOW16", /* name */
1157 FALSE
, /* partial_inplace */
1159 0x3fffc00, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* Used in MOVI and SHORI ((x - $) & 65536). */
1163 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1165 2, /* size (0 = byte, 1 = short, 2 = long) */
1167 TRUE
, /* pc_relative */
1169 complain_overflow_dont
, /* complain_on_overflow */
1170 bfd_elf_generic_reloc
, /* special_function */
1171 "R_SH_IMM_LOW16_PCREL", /* name */
1172 FALSE
, /* partial_inplace */
1174 0x3fffc00, /* dst_mask */
1175 TRUE
), /* pcrel_offset */
1177 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1178 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1179 16, /* rightshift */
1180 2, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE
, /* pc_relative */
1184 complain_overflow_dont
, /* complain_on_overflow */
1185 bfd_elf_generic_reloc
, /* special_function */
1186 "R_SH_IMM_MEDLOW16", /* name */
1187 FALSE
, /* partial_inplace */
1189 0x3fffc00, /* dst_mask */
1190 FALSE
), /* pcrel_offset */
1192 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1193 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1194 16, /* rightshift */
1195 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 TRUE
, /* pc_relative */
1199 complain_overflow_dont
, /* complain_on_overflow */
1200 bfd_elf_generic_reloc
, /* special_function */
1201 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1202 FALSE
, /* partial_inplace */
1204 0x3fffc00, /* dst_mask */
1205 TRUE
), /* pcrel_offset */
1207 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1208 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1209 32, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_dont
, /* complain_on_overflow */
1215 bfd_elf_generic_reloc
, /* special_function */
1216 "R_SH_IMM_MEDHI16", /* name */
1217 FALSE
, /* partial_inplace */
1219 0x3fffc00, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1223 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1224 32, /* rightshift */
1225 2, /* size (0 = byte, 1 = short, 2 = long) */
1227 TRUE
, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 bfd_elf_generic_reloc
, /* special_function */
1231 "R_SH_IMM_MEDHI16_PCREL", /* name */
1232 FALSE
, /* partial_inplace */
1234 0x3fffc00, /* dst_mask */
1235 TRUE
), /* pcrel_offset */
1237 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1238 HOWTO (R_SH_IMM_HI16
, /* type */
1239 48, /* rightshift */
1240 2, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE
, /* pc_relative */
1244 complain_overflow_dont
, /* complain_on_overflow */
1245 bfd_elf_generic_reloc
, /* special_function */
1246 "R_SH_IMM_HI16", /* name */
1247 FALSE
, /* partial_inplace */
1249 0x3fffc00, /* dst_mask */
1250 FALSE
), /* pcrel_offset */
1252 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1253 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1254 48, /* rightshift */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 TRUE
, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 bfd_elf_generic_reloc
, /* special_function */
1261 "R_SH_IMM_HI16_PCREL", /* name */
1262 FALSE
, /* partial_inplace */
1264 0x3fffc00, /* dst_mask */
1265 TRUE
), /* pcrel_offset */
1267 /* For the .uaquad pseudo. */
1268 HOWTO (R_SH_64
, /* type */
1270 4, /* size (0 = byte, 1 = short, 2 = long) */
1272 FALSE
, /* pc_relative */
1274 complain_overflow_dont
, /* complain_on_overflow */
1275 bfd_elf_generic_reloc
, /* special_function */
1276 "R_SH_64", /* name */
1277 FALSE
, /* partial_inplace */
1279 ((bfd_vma
) 0) - 1, /* dst_mask */
1280 FALSE
), /* pcrel_offset */
1282 /* For the .uaquad pseudo, (x - $). */
1283 HOWTO (R_SH_64_PCREL
, /* type */
1284 48, /* rightshift */
1285 2, /* size (0 = byte, 1 = short, 2 = long) */
1287 TRUE
, /* pc_relative */
1289 complain_overflow_dont
, /* complain_on_overflow */
1290 bfd_elf_generic_reloc
, /* special_function */
1291 "R_SH_64_PCREL", /* name */
1292 FALSE
, /* partial_inplace */
1294 ((bfd_vma
) 0) - 1, /* dst_mask */
1295 TRUE
), /* pcrel_offset */
1299 /* This function is used for relocs which are only used for relaxing,
1300 which the linker should otherwise ignore. */
1302 static bfd_reloc_status_type
1303 sh_elf64_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1304 output_bfd
, error_message
)
1305 bfd
*abfd ATTRIBUTE_UNUSED
;
1306 arelent
*reloc_entry
;
1307 asymbol
*symbol ATTRIBUTE_UNUSED
;
1308 PTR data ATTRIBUTE_UNUSED
;
1309 asection
*input_section
;
1311 char **error_message ATTRIBUTE_UNUSED
;
1313 if (output_bfd
!= NULL
)
1314 reloc_entry
->address
+= input_section
->output_offset
;
1315 return bfd_reloc_ok
;
1318 /* This function is used for normal relocs. This used to be like the COFF
1319 function, and is almost certainly incorrect for other ELF targets.
1321 See sh_elf_reloc in elf32-sh.c for the original. */
1323 static bfd_reloc_status_type
1324 sh_elf64_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1327 arelent
*reloc_entry
;
1330 asection
*input_section
;
1332 char **error_message ATTRIBUTE_UNUSED
;
1336 enum elf_sh_reloc_type r_type
;
1337 bfd_vma addr
= reloc_entry
->address
;
1338 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1340 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1342 if (output_bfd
!= NULL
)
1344 /* Partial linking--do nothing. */
1345 reloc_entry
->address
+= input_section
->output_offset
;
1346 return bfd_reloc_ok
;
1349 if (symbol_in
!= NULL
1350 && bfd_is_und_section (symbol_in
->section
))
1351 return bfd_reloc_undefined
;
1353 if (bfd_is_com_section (symbol_in
->section
))
1356 sym_value
= (symbol_in
->value
+
1357 symbol_in
->section
->output_section
->vma
+
1358 symbol_in
->section
->output_offset
);
1363 insn
= bfd_get_32 (abfd
, hit_data
);
1364 insn
+= sym_value
+ reloc_entry
->addend
;
1365 bfd_put_32 (abfd
, insn
, hit_data
);
1373 return bfd_reloc_ok
;
1376 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1378 struct elf_reloc_map
1380 bfd_reloc_code_real_type bfd_reloc_val
;
1381 unsigned char elf_reloc_val
;
1384 /* An array mapping BFD reloc codes to SH ELF relocs. */
1386 static const struct elf_reloc_map sh64_reloc_map
[] =
1388 { BFD_RELOC_NONE
, R_SH_NONE
},
1389 { BFD_RELOC_32
, R_SH_DIR32
},
1390 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1391 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1392 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1393 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1394 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1395 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1396 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1397 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1398 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1399 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1400 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1401 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1402 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1403 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1404 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1405 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1406 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1407 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1408 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1409 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1410 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1411 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1412 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1413 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1414 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1415 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1416 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1417 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1418 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1419 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1420 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1421 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1422 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1423 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1424 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1425 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1426 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1427 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1428 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1429 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1430 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1431 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1432 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1433 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1434 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1435 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1436 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1437 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1438 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1439 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1440 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1441 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1442 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1443 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1444 { BFD_RELOC_64
, R_SH_64
},
1445 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1448 /* Given a BFD reloc code, return the howto structure for the
1449 corresponding SH ELf reloc. */
1451 static reloc_howto_type
*
1452 sh_elf64_reloc_type_lookup (abfd
, code
)
1453 bfd
*abfd ATTRIBUTE_UNUSED
;
1454 bfd_reloc_code_real_type code
;
1458 for (i
= 0; i
< sizeof (sh64_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1460 if (sh64_reloc_map
[i
].bfd_reloc_val
== code
)
1461 return &sh_elf64_howto_table
[(int) sh64_reloc_map
[i
].elf_reloc_val
];
1467 /* Given an ELF reloc, fill in the howto field of a relent.
1469 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1472 sh_elf64_info_to_howto (abfd
, cache_ptr
, dst
)
1473 bfd
*abfd ATTRIBUTE_UNUSED
;
1475 Elf_Internal_Rela
*dst
;
1479 r
= ELF64_R_TYPE (dst
->r_info
);
1481 BFD_ASSERT (r
<= (unsigned int) R_SH_64_PCREL
);
1482 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1483 BFD_ASSERT (r
< R_SH_DIR8WPN
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1484 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_GOTPLT32
);
1485 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1487 cache_ptr
->howto
= &sh_elf64_howto_table
[r
];
1490 /* Relocate an SH ELF section.
1492 See sh_elf_info_to_howto in elf32-sh.c for the original. */
1495 sh_elf64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1496 contents
, relocs
, local_syms
, local_sections
)
1497 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1498 struct bfd_link_info
*info
;
1500 asection
*input_section
;
1502 Elf_Internal_Rela
*relocs
;
1503 Elf_Internal_Sym
*local_syms
;
1504 asection
**local_sections
;
1506 Elf_Internal_Shdr
*symtab_hdr
;
1507 struct elf_link_hash_entry
**sym_hashes
;
1508 Elf_Internal_Rela
*rel
, *relend
;
1510 bfd_vma
*local_got_offsets
;
1515 bfd_vma disp
, dropped
;
1517 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1518 sym_hashes
= elf_sym_hashes (input_bfd
);
1519 dynobj
= elf_hash_table (info
)->dynobj
;
1520 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1528 relend
= relocs
+ input_section
->reloc_count
;
1529 for (; rel
< relend
; rel
++)
1532 reloc_howto_type
*howto
;
1533 unsigned long r_symndx
;
1534 Elf_Internal_Sym
*sym
;
1536 struct elf_link_hash_entry
*h
;
1538 bfd_vma addend
= (bfd_vma
)0;
1539 bfd_reloc_status_type r
;
1540 int seen_stt_datalabel
= 0;
1542 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1544 r_type
= ELF64_R_TYPE (rel
->r_info
);
1546 if (r_type
== (int) R_SH_NONE
)
1550 || r_type
> R_SH_64_PCREL
1551 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1552 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
1553 || (r_type
>= (int) R_SH_DIR8WPN
1554 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
)
1555 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
1556 && r_type
<= R_SH_GOTPLT32
)
1557 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
1558 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
))
1560 bfd_set_error (bfd_error_bad_value
);
1564 howto
= sh_elf64_howto_table
+ r_type
;
1566 /* This is a final link. */
1570 if (r_symndx
< symtab_hdr
->sh_info
)
1572 sym
= local_syms
+ r_symndx
;
1573 sec
= local_sections
[r_symndx
];
1574 relocation
= ((sec
->output_section
->vma
1575 + sec
->output_offset
1577 | ((sym
->st_other
& STO_SH5_ISA32
) != 0));
1579 /* A local symbol never has STO_SH5_ISA32, so we don't need
1580 datalabel processing here. Make sure this does not change
1582 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
1583 ((*info
->callbacks
->reloc_dangerous
)
1585 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
1586 input_bfd
, input_section
, rel
->r_offset
));
1588 if (info
->relocateable
)
1590 /* This is a relocateable link. We don't have to change
1591 anything, unless the reloc is against a section symbol,
1592 in which case we have to adjust according to where the
1593 section symbol winds up in the output section. */
1594 sym
= local_syms
+ r_symndx
;
1595 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1596 goto final_link_relocate
;
1600 else if (! howto
->partial_inplace
)
1602 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
1603 relocation
|= ((sym
->st_other
& STO_SH5_ISA32
) != 0);
1605 else if ((sec
->flags
& SEC_MERGE
)
1606 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1610 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
1612 (*_bfd_error_handler
)
1613 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
1614 bfd_archive_filename (input_bfd
),
1615 bfd_get_section_name (input_bfd
, input_section
),
1616 (long) rel
->r_offset
, howto
->name
);
1620 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1623 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
1625 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
1626 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
1632 /* Section symbols are never (?) placed in the hash table, so
1633 we can just ignore hash relocations when creating a
1634 relocateable object file. */
1635 if (info
->relocateable
)
1638 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1639 while (h
->root
.type
== bfd_link_hash_indirect
1640 || h
->root
.type
== bfd_link_hash_warning
)
1642 /* If the reference passes a symbol marked with
1643 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
1645 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
1646 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1649 if (h
->root
.type
== bfd_link_hash_defined
1650 || h
->root
.type
== bfd_link_hash_defweak
)
1652 sec
= h
->root
.u
.def
.section
;
1653 /* In these cases, we don't need the relocation value.
1654 We check specially because in some obscure cases
1655 sec->output_section will be NULL. */
1656 if (r_type
== R_SH_GOTPC_LOW16
1657 || r_type
== R_SH_GOTPC_MEDLOW16
1658 || r_type
== R_SH_GOTPC_MEDHI16
1659 || r_type
== R_SH_GOTPC_HI16
1660 || ((r_type
== R_SH_PLT_LOW16
1661 || r_type
== R_SH_PLT_MEDLOW16
1662 || r_type
== R_SH_PLT_MEDHI16
1663 || r_type
== R_SH_PLT_HI16
)
1664 && h
->plt
.offset
!= (bfd_vma
) -1)
1665 || ((r_type
== R_SH_GOT_LOW16
1666 || r_type
== R_SH_GOT_MEDLOW16
1667 || r_type
== R_SH_GOT_MEDHI16
1668 || r_type
== R_SH_GOT_HI16
)
1669 && elf_hash_table (info
)->dynamic_sections_created
1671 || (! info
->symbolic
&& h
->dynindx
!= -1)
1672 || (h
->elf_link_hash_flags
1673 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1674 /* The cases above are those in which relocation is
1675 overwritten in the switch block below. The cases
1676 below are those in which we must defer relocation
1677 to run-time, because we can't resolve absolute
1678 addresses when creating a shared library. */
1680 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1681 || (h
->elf_link_hash_flags
1682 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1683 && ((r_type
== R_SH_64
1684 && !(ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1685 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
))
1686 || r_type
== R_SH_64_PCREL
)
1687 && ((input_section
->flags
& SEC_ALLOC
) != 0
1688 /* DWARF will emit R_SH_DIR32 relocations in its
1689 sections against symbols defined externally
1690 in shared libraries. We can't do anything
1692 || (input_section
->flags
& SEC_DEBUGGING
) != 0))
1693 /* Dynamic relocs are not propagated for SEC_DEBUGGING
1694 sections because such sections are not SEC_ALLOC and
1695 thus ld.so will not process them. */
1696 || (sec
->output_section
== NULL
1697 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
1698 && (h
->elf_link_hash_flags
1699 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
1701 else if (sec
->output_section
== NULL
)
1703 (*_bfd_error_handler
)
1704 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
1705 bfd_get_filename (input_bfd
), h
->root
.root
.string
,
1706 bfd_get_section_name (input_bfd
, input_section
));
1710 relocation
= ((h
->root
.u
.def
.value
1711 + sec
->output_section
->vma
1712 + sec
->output_offset
)
1713 /* A STO_SH5_ISA32 causes a "bitor 1" to the
1714 symbol value, unless we've seen
1715 STT_DATALABEL on the way to it. */
1716 | ((h
->other
& STO_SH5_ISA32
) != 0
1717 && ! seen_stt_datalabel
));
1719 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1721 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
1725 if (! ((*info
->callbacks
->undefined_symbol
)
1726 (info
, h
->root
.root
.string
, input_bfd
,
1727 input_section
, rel
->r_offset
, TRUE
)))
1734 - input_section
->output_section
->vma
1735 - input_section
->output_offset
1738 switch ((int)r_type
)
1740 case R_SH_PT_16
: dropped
= disp
& 2; break;
1741 case R_SH_DIR10SW
: dropped
= disp
& 1; break;
1742 case R_SH_DIR10SL
: dropped
= disp
& 3; break;
1743 case R_SH_DIR10SQ
: dropped
= disp
& 7; break;
1747 (*_bfd_error_handler
)
1748 (_("%s: error: unaligned relocation type %d at %08x reloc %08x\n"),
1749 bfd_get_filename (input_bfd
), (int)r_type
, (unsigned)rel
->r_offset
, (unsigned)relocation
);
1750 bfd_set_error (bfd_error_bad_value
);
1753 switch ((int)r_type
)
1758 && (input_section
->flags
& SEC_ALLOC
) != 0
1759 && (r_type
!= R_SH_64_PCREL
1762 && (! info
->symbolic
1763 || (h
->elf_link_hash_flags
1764 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1766 Elf_Internal_Rela outrel
;
1768 bfd_boolean skip
, relocate
;
1770 /* When generating a shared object, these relocations
1771 are copied into the output file to be resolved at run
1778 name
= (bfd_elf_string_from_elf_section
1780 elf_elfheader (input_bfd
)->e_shstrndx
,
1781 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1785 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1786 && strcmp (bfd_get_section_name (input_bfd
,
1790 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1791 BFD_ASSERT (sreloc
!= NULL
);
1798 = _bfd_elf_section_offset (output_bfd
, info
,
1799 input_section
, rel
->r_offset
);
1801 if (outrel
.r_offset
== (bfd_vma
) -1)
1803 else if (outrel
.r_offset
== (bfd_vma
) -2)
1804 skip
= TRUE
, relocate
= TRUE
;
1806 outrel
.r_offset
+= (input_section
->output_section
->vma
1807 + input_section
->output_offset
);
1810 memset (&outrel
, 0, sizeof outrel
);
1811 else if (r_type
== R_SH_64_PCREL
)
1813 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
1814 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64_PCREL
);
1815 outrel
.r_addend
= rel
->r_addend
;
1819 /* h->dynindx may be -1 if this symbol was marked to
1822 || ((info
->symbolic
|| h
->dynindx
== -1)
1823 && (h
->elf_link_hash_flags
1824 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
1827 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
1828 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1832 BFD_ASSERT (h
->dynindx
!= -1);
1833 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_64
);
1834 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1838 loc
= sreloc
->contents
;
1839 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1840 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
1842 /* If this reloc is against an external symbol, we do
1843 not want to fiddle with the addend. Otherwise, we
1844 need to include the symbol value so that it becomes
1845 an addend for the dynamic reloc. */
1849 else if (r_type
== R_SH_64
)
1850 addend
= rel
->r_addend
;
1851 goto final_link_relocate
;
1853 case R_SH_GOTPLT_LOW16
:
1854 case R_SH_GOTPLT_MEDLOW16
:
1855 case R_SH_GOTPLT_MEDHI16
:
1856 case R_SH_GOTPLT_HI16
:
1857 case R_SH_GOTPLT10BY4
:
1858 case R_SH_GOTPLT10BY8
:
1859 /* Relocation is to the entry for this symbol in the
1860 procedure linkage table. */
1863 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1864 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
1868 || h
->plt
.offset
== (bfd_vma
) -1
1869 || h
->got
.offset
!= (bfd_vma
) -1)
1872 /* Relocation is to the entry for this symbol in the global
1873 offset table extension for the procedure linkage table. */
1874 if (sgotplt
== NULL
)
1876 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1877 BFD_ASSERT (sgotplt
!= NULL
);
1880 relocation
= (sgotplt
->output_offset
1881 + ((h
->plt
.offset
/ elf_sh64_sizeof_plt (info
)
1884 relocation
-= GOT_BIAS
;
1886 goto final_link_relocate
;
1889 case R_SH_GOT_LOW16
:
1890 case R_SH_GOT_MEDLOW16
:
1891 case R_SH_GOT_MEDHI16
:
1895 /* Relocation is to the entry for this symbol in the global
1899 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1900 BFD_ASSERT (sgot
!= NULL
);
1907 off
= h
->got
.offset
;
1908 if (seen_stt_datalabel
)
1910 struct elf_sh64_link_hash_entry
*hsh
;
1912 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1913 off
= hsh
->datalabel_got_offset
;
1915 BFD_ASSERT (off
!= (bfd_vma
) -1);
1917 if (! elf_hash_table (info
)->dynamic_sections_created
1919 && (info
->symbolic
|| h
->dynindx
== -1
1920 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
1921 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
1922 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1924 /* This is actually a static link, or it is a
1925 -Bsymbolic link and the symbol is defined
1926 locally, or the symbol was forced to be local
1927 because of a version file. We must initialize
1928 this entry in the global offset table. Since the
1929 offset must always be a multiple of 4, we use the
1930 least significant bit to record whether we have
1931 initialized it already.
1933 When doing a dynamic link, we create a .rela.got
1934 relocation entry to initialize the value. This
1935 is done in the finish_dynamic_symbol routine. */
1940 bfd_put_64 (output_bfd
, relocation
,
1941 sgot
->contents
+ off
);
1942 if (seen_stt_datalabel
)
1944 struct elf_sh64_link_hash_entry
*hsh
;
1946 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
1947 hsh
->datalabel_got_offset
|= 1;
1954 relocation
= sgot
->output_offset
+ off
;
1962 BFD_ASSERT (local_got_offsets
!= NULL
1963 && (local_got_offsets
[symtab_hdr
->sh_info
1967 off
= local_got_offsets
[symtab_hdr
->sh_info
1972 BFD_ASSERT (local_got_offsets
!= NULL
1973 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1975 off
= local_got_offsets
[r_symndx
];
1978 /* The offset must always be a multiple of 8. We use
1979 the least significant bit to record whether we have
1980 already generated the necessary reloc. */
1985 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1990 Elf_Internal_Rela outrel
;
1993 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1994 BFD_ASSERT (s
!= NULL
);
1996 outrel
.r_offset
= (sgot
->output_section
->vma
1997 + sgot
->output_offset
1999 outrel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
2000 outrel
.r_addend
= relocation
;
2002 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2003 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
2007 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
2009 local_got_offsets
[r_symndx
] |= 1;
2012 relocation
= sgot
->output_offset
+ off
;
2015 relocation
-= GOT_BIAS
;
2017 goto final_link_relocate
;
2019 case R_SH_GOTOFF_LOW16
:
2020 case R_SH_GOTOFF_MEDLOW16
:
2021 case R_SH_GOTOFF_MEDHI16
:
2022 case R_SH_GOTOFF_HI16
:
2023 /* Relocation is relative to the start of the global offset
2028 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2029 BFD_ASSERT (sgot
!= NULL
);
2032 /* Note that sgot->output_offset is not involved in this
2033 calculation. We always want the start of .got. If we
2034 defined _GLOBAL_OFFSET_TABLE in a different way, as is
2035 permitted by the ABI, we might have to change this
2037 relocation
-= sgot
->output_section
->vma
;
2039 relocation
-= GOT_BIAS
;
2041 addend
= rel
->r_addend
;
2043 goto final_link_relocate
;
2045 case R_SH_GOTPC_LOW16
:
2046 case R_SH_GOTPC_MEDLOW16
:
2047 case R_SH_GOTPC_MEDHI16
:
2048 case R_SH_GOTPC_HI16
:
2049 /* Use global offset table as symbol value. */
2053 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2054 BFD_ASSERT (sgot
!= NULL
);
2057 relocation
= sgot
->output_section
->vma
;
2059 relocation
+= GOT_BIAS
;
2061 addend
= rel
->r_addend
;
2063 goto final_link_relocate
;
2065 case R_SH_PLT_LOW16
:
2066 case R_SH_PLT_MEDLOW16
:
2067 case R_SH_PLT_MEDHI16
:
2069 /* Relocation is to the entry for this symbol in the
2070 procedure linkage table. */
2072 /* Resolve a PLT reloc against a local symbol directly,
2073 without using the procedure linkage table. */
2075 goto final_link_relocate
;
2077 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2078 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2079 goto final_link_relocate
;
2081 if (h
->plt
.offset
== (bfd_vma
) -1)
2083 /* We didn't make a PLT entry for this symbol. This
2084 happens when statically linking PIC code, or when
2085 using -Bsymbolic. */
2086 goto final_link_relocate
;
2091 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2092 BFD_ASSERT (splt
!= NULL
);
2095 relocation
= (splt
->output_section
->vma
2096 + splt
->output_offset
2100 addend
= rel
->r_addend
;
2102 goto final_link_relocate
;
2105 case R_SH_SHMEDIA_CODE
:
2116 case R_SH_IMM_LOW16
:
2117 case R_SH_IMM_LOW16_PCREL
:
2118 case R_SH_IMM_MEDLOW16
:
2119 case R_SH_IMM_MEDLOW16_PCREL
:
2120 case R_SH_IMM_MEDHI16
:
2121 case R_SH_IMM_MEDHI16_PCREL
:
2123 case R_SH_IMM_HI16_PCREL
:
2124 addend
= rel
->r_addend
;
2127 final_link_relocate
:
2128 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2129 contents
, rel
->r_offset
,
2130 relocation
, addend
);
2134 bfd_set_error (bfd_error_bad_value
);
2139 if (r
!= bfd_reloc_ok
)
2144 case bfd_reloc_outofrange
:
2146 case bfd_reloc_overflow
:
2151 name
= h
->root
.root
.string
;
2154 name
= (bfd_elf_string_from_elf_section
2155 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2159 name
= bfd_section_name (input_bfd
, sec
);
2161 if (! ((*info
->callbacks
->reloc_overflow
)
2162 (info
, name
, howto
->name
, (bfd_vma
) 0,
2163 input_bfd
, input_section
, rel
->r_offset
)))
2174 /* This is a version of bfd_generic_get_relocated_section_contents
2175 that uses sh_elf64_relocate_section.
2177 See sh_elf_relocate_section in elf32-sh.c for the original. */
2180 sh_elf64_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
2181 data
, relocateable
, symbols
)
2183 struct bfd_link_info
*link_info
;
2184 struct bfd_link_order
*link_order
;
2186 bfd_boolean relocateable
;
2189 Elf_Internal_Shdr
*symtab_hdr
;
2190 asection
*input_section
= link_order
->u
.indirect
.section
;
2191 bfd
*input_bfd
= input_section
->owner
;
2192 asection
**sections
= NULL
;
2193 Elf_Internal_Rela
*internal_relocs
= NULL
;
2194 Elf_Internal_Sym
*isymbuf
= NULL
;
2196 /* We only need to handle the case of relaxing, or of having a
2197 particular set of section contents, specially. */
2199 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2200 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2205 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2207 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2208 input_section
->_raw_size
);
2210 if ((input_section
->flags
& SEC_RELOC
) != 0
2211 && input_section
->reloc_count
> 0)
2213 Elf_Internal_Sym
*isymp
;
2214 Elf_Internal_Sym
*isymend
;
2217 /* Read this BFD's local symbols. */
2218 if (symtab_hdr
->sh_info
!= 0)
2220 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2221 if (isymbuf
== NULL
)
2222 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2223 symtab_hdr
->sh_info
, 0,
2225 if (isymbuf
== NULL
)
2229 internal_relocs
= (_bfd_elf64_link_read_relocs
2230 (input_bfd
, input_section
, (PTR
) NULL
,
2231 (Elf_Internal_Rela
*) NULL
, FALSE
));
2232 if (internal_relocs
== NULL
)
2235 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2236 * sizeof (asection
*));
2237 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2241 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2242 for (isymp
= isymbuf
; isymp
< isymend
; ++isymp
, ++secpp
)
2246 if (isymp
->st_shndx
== SHN_UNDEF
)
2247 isec
= bfd_und_section_ptr
;
2248 else if (isymp
->st_shndx
> 0 && isymp
->st_shndx
< SHN_LORESERVE
)
2249 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
2250 else if (isymp
->st_shndx
== SHN_ABS
)
2251 isec
= bfd_abs_section_ptr
;
2252 else if (isymp
->st_shndx
== SHN_COMMON
)
2253 isec
= bfd_com_section_ptr
;
2263 if (! sh_elf64_relocate_section (output_bfd
, link_info
, input_bfd
,
2264 input_section
, data
, internal_relocs
,
2268 if (sections
!= NULL
)
2270 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
2271 free (internal_relocs
);
2273 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2280 if (sections
!= NULL
)
2282 if (internal_relocs
!= NULL
2283 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
2284 free (internal_relocs
);
2286 && (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2291 /* Set the SHF_SH5_ISA32 flag for ISA SHmedia code sections. */
2294 sh64_elf64_fake_sections (output_bfd
, elf_section_hdr
, asect
)
2295 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2296 Elf_Internal_Shdr
*elf_section_hdr
;
2299 /* Code sections can only contain SH64 code, so mark them as such. */
2300 if (bfd_get_section_flags (output_bfd
, asect
) & SEC_CODE
)
2301 elf_section_hdr
->sh_flags
|= SHF_SH5_ISA32
;
2307 sh_elf64_set_mach_from_flags (abfd
)
2310 flagword flags
= elf_elfheader (abfd
)->e_flags
;
2312 switch (flags
& EF_SH_MACH_MASK
)
2315 /* Just one, but keep the switch construct to make additions easy. */
2316 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh5
);
2320 bfd_set_error (bfd_error_wrong_format
);
2326 /* Function to keep SH64 specific file flags.
2328 See sh64_elf_set_private_flags in elf32-sh64.c for the original. */
2331 sh_elf64_set_private_flags (abfd
, flags
)
2335 BFD_ASSERT (! elf_flags_init (abfd
)
2336 || elf_elfheader (abfd
)->e_flags
== flags
);
2338 elf_elfheader (abfd
)->e_flags
= flags
;
2339 elf_flags_init (abfd
) = TRUE
;
2340 return sh_elf64_set_mach_from_flags (abfd
);
2343 /* Copy the SHF_SH5_ISA32 attribute that we keep on all sections with
2344 code, to keep attributes the same as for SHmedia in 32-bit ELF. */
2347 sh_elf64_copy_private_data_internal (ibfd
, obfd
)
2351 Elf_Internal_Shdr
**o_shdrp
;
2355 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2356 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2359 o_shdrp
= elf_elfsections (obfd
);
2360 for (osec
= obfd
->sections
; osec
; osec
= osec
->next
)
2362 int oIndex
= ((struct bfd_elf_section_data
*) elf_section_data (osec
))->this_idx
;
2363 for (isec
= ibfd
->sections
; isec
; isec
= isec
->next
)
2365 if (strcmp (osec
->name
, isec
->name
) == 0)
2367 /* Note that we're not disallowing mixing data and code. */
2368 if ((elf_section_data (isec
)->this_hdr
.sh_flags
2369 & SHF_SH5_ISA32
) != 0)
2370 o_shdrp
[oIndex
]->sh_flags
|= SHF_SH5_ISA32
;
2376 return sh_elf64_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2380 sh_elf64_copy_private_data (ibfd
, obfd
)
2384 return sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2388 sh_elf64_merge_private_data (ibfd
, obfd
)
2392 flagword old_flags
, new_flags
;
2394 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2397 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2398 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2401 if (bfd_get_arch_size (ibfd
) != bfd_get_arch_size (obfd
))
2405 if (bfd_get_arch_size (ibfd
) == 32
2406 && bfd_get_arch_size (obfd
) == 64)
2407 msg
= _("%s: compiled as 32-bit object and %s is 64-bit");
2408 else if (bfd_get_arch_size (ibfd
) == 64
2409 && bfd_get_arch_size (obfd
) == 32)
2410 msg
= _("%s: compiled as 64-bit object and %s is 32-bit");
2412 msg
= _("%s: object size does not match that of target %s");
2414 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
),
2415 bfd_get_filename (obfd
));
2416 bfd_set_error (bfd_error_wrong_format
);
2420 old_flags
= elf_elfheader (obfd
)->e_flags
;
2421 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2422 if (! elf_flags_init (obfd
))
2424 /* This happens when ld starts out with a 'blank' output file. */
2425 elf_flags_init (obfd
) = TRUE
;
2426 elf_elfheader (obfd
)->e_flags
= old_flags
= new_flags
;
2428 /* We don't allow linking in anything else than SH64 code, and since
2429 this is a 64-bit ELF, we assume the 64-bit ABI is used. Add code
2430 here as things change. */
2431 else if ((new_flags
& EF_SH_MACH_MASK
) != EF_SH5
)
2433 (*_bfd_error_handler
)
2434 ("%s: does not use the SH64 64-bit ABI as previous modules do",
2435 bfd_get_filename (ibfd
));
2436 bfd_set_error (bfd_error_bad_value
);
2440 sh_elf64_copy_private_data_internal (ibfd
, obfd
);
2442 /* I can't think of anything sane other than old_flags being EF_SH5 and
2443 that we need to preserve that. */
2444 elf_elfheader (obfd
)->e_flags
= old_flags
;
2446 return sh_elf64_set_mach_from_flags (obfd
);
2449 /* Return the section that should be marked against GC for a given
2453 sh_elf64_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2455 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2456 Elf_Internal_Rela
*rel
;
2457 struct elf_link_hash_entry
*h
;
2458 Elf_Internal_Sym
*sym
;
2462 switch (ELF64_R_TYPE (rel
->r_info
))
2464 case R_SH_GNU_VTINHERIT
:
2465 case R_SH_GNU_VTENTRY
:
2469 while (h
->root
.type
== bfd_link_hash_indirect
2470 && h
->root
.u
.i
.link
)
2471 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2472 switch (h
->root
.type
)
2474 case bfd_link_hash_defined
:
2475 case bfd_link_hash_defweak
:
2476 return h
->root
.u
.def
.section
;
2478 case bfd_link_hash_common
:
2479 return h
->root
.u
.c
.p
->section
;
2487 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2492 /* Update the got entry reference counts for the section being removed. */
2495 sh_elf64_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2496 bfd
*abfd ATTRIBUTE_UNUSED
;
2497 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2498 asection
*sec ATTRIBUTE_UNUSED
;
2499 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2501 /* No got and plt entries for 64-bit SH at present. */
2505 /* Look through the relocs for a section during the first phase.
2506 Since we don't do .gots or .plts, we just need to consider the
2507 virtual table relocs for gc. */
2510 sh_elf64_check_relocs (abfd
, info
, sec
, relocs
)
2512 struct bfd_link_info
*info
;
2514 const Elf_Internal_Rela
*relocs
;
2516 Elf_Internal_Shdr
*symtab_hdr
;
2517 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2518 const Elf_Internal_Rela
*rel
;
2519 const Elf_Internal_Rela
*rel_end
;
2521 bfd_vma
*local_got_offsets
;
2530 if (info
->relocateable
)
2533 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2534 sym_hashes
= elf_sym_hashes (abfd
);
2535 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf64_External_Sym
);
2536 if (!elf_bad_symtab (abfd
))
2537 sym_hashes_end
-= symtab_hdr
->sh_info
;
2539 dynobj
= elf_hash_table (info
)->dynobj
;
2540 local_got_offsets
= elf_local_got_offsets (abfd
);
2542 rel_end
= relocs
+ sec
->reloc_count
;
2543 for (rel
= relocs
; rel
< rel_end
; rel
++)
2545 struct elf_link_hash_entry
*h
;
2546 unsigned long r_symndx
;
2548 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2549 if (r_symndx
< symtab_hdr
->sh_info
)
2552 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2554 /* Some relocs require a global offset table. */
2557 switch (ELF64_R_TYPE (rel
->r_info
))
2559 case R_SH_GOTPLT_LOW16
:
2560 case R_SH_GOTPLT_MEDLOW16
:
2561 case R_SH_GOTPLT_MEDHI16
:
2562 case R_SH_GOTPLT_HI16
:
2563 case R_SH_GOTPLT10BY4
:
2564 case R_SH_GOTPLT10BY8
:
2565 case R_SH_GOT_LOW16
:
2566 case R_SH_GOT_MEDLOW16
:
2567 case R_SH_GOT_MEDHI16
:
2571 case R_SH_GOTOFF_LOW16
:
2572 case R_SH_GOTOFF_MEDLOW16
:
2573 case R_SH_GOTOFF_MEDHI16
:
2574 case R_SH_GOTOFF_HI16
:
2575 case R_SH_GOTPC_LOW16
:
2576 case R_SH_GOTPC_MEDLOW16
:
2577 case R_SH_GOTPC_MEDHI16
:
2578 case R_SH_GOTPC_HI16
:
2579 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2580 if (! _bfd_elf_create_got_section (dynobj
, info
))
2589 switch (ELF64_R_TYPE (rel
->r_info
))
2591 /* This relocation describes the C++ object vtable hierarchy.
2592 Reconstruct it for later use during GC. */
2593 case R_SH_GNU_VTINHERIT
:
2594 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2598 /* This relocation describes which C++ vtable entries are actually
2599 used. Record for later use during GC. */
2600 case R_SH_GNU_VTENTRY
:
2601 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2606 case R_SH_GOT_LOW16
:
2607 case R_SH_GOT_MEDLOW16
:
2608 case R_SH_GOT_MEDHI16
:
2612 /* This symbol requires a global offset table entry. */
2616 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2617 BFD_ASSERT (sgot
!= NULL
);
2621 && (h
!= NULL
|| info
->shared
))
2623 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2624 if (srelgot
== NULL
)
2626 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2628 || ! bfd_set_section_flags (dynobj
, srelgot
,
2633 | SEC_LINKER_CREATED
2635 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2642 if (h
->type
== STT_DATALABEL
)
2644 struct elf_sh64_link_hash_entry
*hsh
;
2646 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2647 hsh
= (struct elf_sh64_link_hash_entry
*)h
;
2648 if (hsh
->datalabel_got_offset
!= (bfd_vma
) -1)
2651 hsh
->datalabel_got_offset
= sgot
->_raw_size
;
2655 if (h
->got
.offset
!= (bfd_vma
) -1)
2657 /* We have already allocated space in the .got. */
2660 h
->got
.offset
= sgot
->_raw_size
;
2663 /* Make sure this symbol is output as a dynamic symbol. */
2664 if (h
->dynindx
== -1)
2666 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2670 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
2674 /* This is a global offset table entry for a local
2676 if (local_got_offsets
== NULL
)
2679 register unsigned int i
;
2681 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
2682 /* Reserve space for both the datalabel and
2683 codelabel local GOT offsets. */
2685 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
2686 if (local_got_offsets
== NULL
)
2688 elf_local_got_offsets (abfd
) = local_got_offsets
;
2689 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
2690 local_got_offsets
[i
] = (bfd_vma
) -1;
2691 for (; i
< 2 * symtab_hdr
->sh_info
; i
++)
2692 local_got_offsets
[i
] = (bfd_vma
) -1;
2694 if ((rel
->r_addend
& 1) != 0)
2696 if (local_got_offsets
[symtab_hdr
->sh_info
2697 + r_symndx
] != (bfd_vma
) -1)
2699 /* We have already allocated space in the .got. */
2702 local_got_offsets
[symtab_hdr
->sh_info
2703 + r_symndx
] = sgot
->_raw_size
;
2707 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
2709 /* We have already allocated space in the .got. */
2712 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
2717 /* If we are generating a shared object, we need to
2718 output a R_SH_RELATIVE reloc so that the dynamic
2719 linker can adjust this GOT entry. */
2720 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
2724 sgot
->_raw_size
+= 8;
2728 case R_SH_GOTPLT_LOW16
:
2729 case R_SH_GOTPLT_MEDLOW16
:
2730 case R_SH_GOTPLT_MEDHI16
:
2731 case R_SH_GOTPLT_HI16
:
2732 case R_SH_GOTPLT10BY4
:
2733 case R_SH_GOTPLT10BY8
:
2734 /* If this is a local symbol, we resolve it directly without
2735 creating a procedure linkage table entry. */
2738 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2739 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
2743 || h
->got
.offset
!= (bfd_vma
) -1)
2746 /* Make sure this symbol is output as a dynamic symbol. */
2747 if (h
->dynindx
== -1)
2749 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2753 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2757 case R_SH_PLT_LOW16
:
2758 case R_SH_PLT_MEDLOW16
:
2759 case R_SH_PLT_MEDHI16
:
2761 /* This symbol requires a procedure linkage table entry. We
2762 actually build the entry in adjust_dynamic_symbol,
2763 because this might be a case of linking PIC code which is
2764 never referenced by a dynamic object, in which case we
2765 don't need to generate a procedure linkage table entry
2768 /* If this is a local symbol, we resolve it directly without
2769 creating a procedure linkage table entry. */
2773 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2774 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
2777 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2784 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
2786 /* If we are creating a shared library, and this is a reloc
2787 against a global symbol, or a non PC relative reloc
2788 against a local symbol, then we need to copy the reloc
2789 into the shared library. However, if we are linking with
2790 -Bsymbolic, we do not need to copy a reloc against a
2791 global symbol which is defined in an object we are
2792 including in the link (i.e., DEF_REGULAR is set). At
2793 this point we have not seen all the input files, so it is
2794 possible that DEF_REGULAR is not set now but will be set
2795 later (it is never cleared). We account for that
2796 possibility below by storing information in the
2797 pcrel_relocs_copied field of the hash table entry. */
2799 && (sec
->flags
& SEC_ALLOC
) != 0
2800 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_64_PCREL
2802 && (! info
->symbolic
2803 || (h
->elf_link_hash_flags
2804 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2806 /* When creating a shared object, we must copy these
2807 reloc types into the output file. We create a reloc
2808 section in dynobj and make room for this reloc. */
2813 name
= (bfd_elf_string_from_elf_section
2815 elf_elfheader (abfd
)->e_shstrndx
,
2816 elf_section_data (sec
)->rel_hdr
.sh_name
));
2820 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2821 && strcmp (bfd_get_section_name (abfd
, sec
),
2824 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2829 sreloc
= bfd_make_section (dynobj
, name
);
2830 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2831 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2832 if ((sec
->flags
& SEC_ALLOC
) != 0)
2833 flags
|= SEC_ALLOC
| SEC_LOAD
;
2835 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2836 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2841 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
2843 /* If we are linking with -Bsymbolic, and this is a
2844 global symbol, we count the number of PC relative
2845 relocations we have entered for this symbol, so that
2846 we can discard them again if the symbol is later
2847 defined by a regular object. Note that this function
2848 is only called if we are using an elf_sh linker
2849 hash table, which means that h is really a pointer to
2850 an elf_sh_link_hash_entry. */
2851 if (h
!= NULL
&& info
->symbolic
2852 && ELF64_R_TYPE (rel
->r_info
) == R_SH_64_PCREL
)
2854 struct elf_sh64_link_hash_entry
*eh
;
2855 struct elf_sh64_pcrel_relocs_copied
*p
;
2857 eh
= (struct elf_sh64_link_hash_entry
*) h
;
2859 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
2860 if (p
->section
== sreloc
)
2865 p
= ((struct elf_sh64_pcrel_relocs_copied
*)
2866 bfd_alloc (dynobj
, sizeof *p
));
2869 p
->next
= eh
->pcrel_relocs_copied
;
2870 eh
->pcrel_relocs_copied
= p
;
2871 p
->section
= sreloc
;
2887 sh64_elf64_get_symbol_type (elf_sym
, type
)
2888 Elf_Internal_Sym
* elf_sym
;
2891 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_DATALABEL
)
2892 return STT_DATALABEL
;
2897 /* FIXME: This is a copy of sh64_elf_add_symbol_hook in elf32-sh64.c.
2898 Either file can presumably exist without the other, but do not differ
2899 in elf-size-ness. How to share?
2901 Hook called by the linker routine which adds symbols from an object
2902 file. We must make indirect symbols for undefined symbols marked with
2903 STT_DATALABEL, so relocations passing them will pick up that attribute
2904 and neutralize STO_SH5_ISA32 found on the symbol definition.
2906 There is a problem, though: We want to fill in the hash-table entry for
2907 this symbol and signal to the caller that no further processing is
2908 needed. But we don't have the index for this hash-table entry. We
2909 rely here on that the current entry is the first hash-entry with NULL,
2910 which seems brittle. Also, iterating over the hash-table to find that
2911 entry is a linear operation on the number of symbols in this input
2912 file, and this function should take constant time, so that's not good
2913 too. Only comfort is that DataLabel references should only be found in
2914 hand-written assembly code and thus be rare. FIXME: Talk maintainers
2915 into adding an option to elf_add_symbol_hook (preferably) for the index
2916 or the hash entry, alternatively adding the index to Elf_Internal_Sym
2920 sh64_elf64_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2922 struct bfd_link_info
*info
;
2923 const Elf_Internal_Sym
*sym
;
2925 flagword
*flagsp ATTRIBUTE_UNUSED
;
2929 /* We want to do this for relocatable as well as final linking. */
2930 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
2931 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
2933 struct elf_link_hash_entry
*h
;
2935 /* For relocateable links, we register the DataLabel sym in its own
2936 right, and tweak the name when it's output. Otherwise, we make
2937 an indirect symbol of it. */
2939 = info
->relocateable
|| info
->emitrelocations
2940 ? BSF_GLOBAL
: BSF_GLOBAL
| BSF_INDIRECT
;
2943 = bfd_malloc (strlen (*namep
) + sizeof (DATALABEL_SUFFIX
));
2944 struct elf_link_hash_entry
** sym_hash
= elf_sym_hashes (abfd
);
2946 BFD_ASSERT (sym_hash
!= NULL
);
2948 /* Allocation may fail. */
2949 if (dl_name
== NULL
)
2952 strcpy (dl_name
, *namep
);
2953 strcat (dl_name
, DATALABEL_SUFFIX
);
2955 h
= (struct elf_link_hash_entry
*)
2956 bfd_link_hash_lookup (info
->hash
, dl_name
, FALSE
, FALSE
, FALSE
);
2960 /* No previous datalabel symbol. Make one. */
2961 struct bfd_link_hash_entry
*bh
= NULL
;
2962 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2964 if (! _bfd_generic_link_add_one_symbol (info
, abfd
, dl_name
,
2965 flags
, *secp
, *valp
,
2973 h
= (struct elf_link_hash_entry
*) bh
;
2974 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
2975 h
->type
= STT_DATALABEL
;
2978 /* If a new symbol was created, it holds the allocated name.
2979 Otherwise, we don't need it anymore and should deallocate it. */
2982 if (h
->type
!= STT_DATALABEL
2983 || ((info
->relocateable
|| info
->emitrelocations
)
2984 && h
->root
.type
!= bfd_link_hash_undefined
)
2985 || (! info
->relocateable
&& !info
->emitrelocations
2986 && h
->root
.type
!= bfd_link_hash_indirect
))
2988 /* Make sure we don't get confused on invalid input. */
2989 (*_bfd_error_handler
)
2990 (_("%s: encountered datalabel symbol in input"),
2991 bfd_get_filename (abfd
));
2992 bfd_set_error (bfd_error_bad_value
);
2996 /* Now find the hash-table slot for this entry and fill it in. */
2997 while (*sym_hash
!= NULL
)
3001 /* Signal to caller to skip this symbol - we've handled it. */
3008 /* This hook function is called before the linker writes out a global
3009 symbol. For relocatable links, DataLabel symbols will be present in
3010 linker output. We cut off the special suffix on those symbols, so the
3011 right name appears in the output.
3013 When linking and emitting relocations, there can appear global symbols
3014 that are not referenced by relocs, but rather only implicitly through
3015 DataLabel references, a relation that is not visible to the linker.
3016 Since no stripping of global symbols in done when doing such linking,
3017 we don't need to look up and make sure to emit the main symbol for each
3018 DataLabel symbol. */
3021 sh64_elf64_link_output_symbol_hook (abfd
, info
, cname
, sym
, input_sec
)
3022 bfd
*abfd ATTRIBUTE_UNUSED
;
3023 struct bfd_link_info
*info
;
3025 Elf_Internal_Sym
*sym
;
3026 asection
*input_sec ATTRIBUTE_UNUSED
;
3028 char *name
= (char *) cname
;
3030 if (info
->relocateable
|| info
->emitrelocations
)
3032 if (ELF_ST_TYPE (sym
->st_info
) == STT_DATALABEL
)
3033 name
[strlen (name
) - strlen (DATALABEL_SUFFIX
)] = 0;
3039 /* Set bit 0 on the entry address; it always points to SHmedia code. This
3040 is mostly for symmetry with the 32-bit format, where code can be
3041 SHcompact and we need to make a distinction to make sure execution
3042 starts in the right ISA mode. It is also convenient for a loader,
3043 which would otherwise have to set this bit when loading a TR register
3044 before jumping to the program entry. */
3047 sh64_elf64_final_write_processing (abfd
, linker
)
3049 bfd_boolean linker ATTRIBUTE_UNUSED
;
3051 /* FIXME: Perhaps we shouldn't do this if the entry address was supplied
3052 numerically, but we currently lack the infrastructure to recognize
3053 that: The entry symbol, and info whether it is numeric or a symbol
3054 name is kept private in the linker. */
3055 if (elf_elfheader (abfd
)->e_type
== ET_EXEC
)
3056 elf_elfheader (abfd
)->e_entry
|= 1;
3059 /* First entry in an absolute procedure linkage table look like this. */
3061 static const bfd_byte elf_sh64_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3063 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 48, r17 */
3064 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 32) & 65535, r17 */
3065 0xc8, 0x00, 0x01, 0x10, /* shori (.got.plt >> 16) & 65535, r17 */
3066 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3067 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3068 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3069 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3070 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3071 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3072 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3073 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3074 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3075 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3076 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3077 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3078 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3081 static const bfd_byte elf_sh64_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3083 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3084 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 32) & 65535, r17 */
3085 0x10, 0x01, 0x00, 0xc8, /* shori (.got.plt >> 16) & 65535, r17 */
3086 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3087 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3088 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3089 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3090 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3091 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3092 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3093 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3094 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3095 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3096 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3097 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3098 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3101 /* Sebsequent entries in an absolute procedure linkage table look like
3104 static const bfd_byte elf_sh64_plt_entry_be
[PLT_ENTRY_SIZE
] =
3106 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 48, r25 */
3107 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 32) & 65535, r25 */
3108 0xc8, 0x00, 0x01, 0x90, /* shori (nameN-in-GOT >> 16) & 65535, r25 */
3109 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3110 0x8d, 0x90, 0x01, 0x90, /* ld.q r25, 0, r25 */
3111 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3112 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3113 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3114 0xcc, 0x00, 0x01, 0x90, /* movi (.+8-.PLT0) >> 16, r25 */
3115 0xc8, 0x00, 0x01, 0x90, /* shori (.+4-.PLT0) & 65535, r25 */
3116 0x6b, 0xf5, 0x66, 0x00, /* ptrel r25, tr0 */
3117 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3118 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3119 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3120 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3121 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3124 static const bfd_byte elf_sh64_plt_entry_le
[PLT_ENTRY_SIZE
] =
3126 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3127 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3128 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3129 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3130 0x90, 0x01, 0x90, 0x8d, /* ld.q r25, 0, r25 */
3131 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3132 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3133 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3134 0x90, 0x01, 0x00, 0xcc, /* movi (.+8-.PLT0) >> 16, r25 */
3135 0x90, 0x01, 0x00, 0xc8, /* shori (.+4-.PLT0) & 65535, r25 */
3136 0x00, 0x66, 0xf5, 0x6b, /* ptrel r25, tr0 */
3137 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3138 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3139 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3140 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3141 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3144 /* Entries in a PIC procedure linkage table look like this. */
3146 static const bfd_byte elf_sh64_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3148 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3149 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3150 0x40, 0xc3, 0x65, 0x90, /* ldx.q r12, r25, r25 */
3151 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3152 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3153 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3154 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3155 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3156 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3157 0x00, 0xc9, 0x45, 0x10, /* add r12, r17, r17 */
3158 0x8d, 0x10, 0x09, 0x90, /* ld.q r17, 16, r25 */
3159 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3160 0x8d, 0x10, 0x05, 0x10, /* ld.q r17, 8, r17 */
3161 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3162 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3163 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3166 static const bfd_byte elf_sh64_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3168 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3169 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3170 0x90, 0x65, 0xc3, 0x40, /* ldx.q r12, r25, r25 */
3171 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3172 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3173 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3174 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3175 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3176 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3177 0x10, 0x45, 0xc9, 0x00, /* add r12, r17, r17 */
3178 0x90, 0x09, 0x10, 0x8d, /* ld.q r17, 16, r25 */
3179 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3180 0x10, 0x05, 0x10, 0x8d, /* ld.q r17, 8, r17 */
3181 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3182 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3183 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3186 static const bfd_byte
*elf_sh64_plt0_entry
;
3187 static const bfd_byte
*elf_sh64_plt_entry
;
3188 static const bfd_byte
*elf_sh64_pic_plt_entry
;
3190 /* Create an entry in an sh ELF linker hash table. */
3192 static struct bfd_hash_entry
*
3193 sh64_elf64_link_hash_newfunc (entry
, table
, string
)
3194 struct bfd_hash_entry
*entry
;
3195 struct bfd_hash_table
*table
;
3198 struct elf_sh64_link_hash_entry
*ret
=
3199 (struct elf_sh64_link_hash_entry
*) entry
;
3201 /* Allocate the structure if it has not already been allocated by a
3203 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3204 ret
= ((struct elf_sh64_link_hash_entry
*)
3205 bfd_hash_allocate (table
,
3206 sizeof (struct elf_sh64_link_hash_entry
)));
3207 if (ret
== (struct elf_sh64_link_hash_entry
*) NULL
)
3208 return (struct bfd_hash_entry
*) ret
;
3210 /* Call the allocation method of the superclass. */
3211 ret
= ((struct elf_sh64_link_hash_entry
*)
3212 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3214 if (ret
!= (struct elf_sh64_link_hash_entry
*) NULL
)
3216 ret
->pcrel_relocs_copied
= NULL
;
3217 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3220 return (struct bfd_hash_entry
*) ret
;
3223 /* Create an sh64 ELF linker hash table. */
3225 static struct bfd_link_hash_table
*
3226 sh64_elf64_link_hash_table_create (abfd
)
3229 struct elf_sh64_link_hash_table
*ret
;
3231 ret
= ((struct elf_sh64_link_hash_table
*)
3232 bfd_malloc (sizeof (struct elf_sh64_link_hash_table
)));
3233 if (ret
== (struct elf_sh64_link_hash_table
*) NULL
)
3236 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3237 sh64_elf64_link_hash_newfunc
))
3243 return &ret
->root
.root
;
3247 movi_shori_putval (output_bfd
, value
, addr
)
3249 unsigned long value
;
3252 bfd_put_32 (output_bfd
,
3253 bfd_get_32 (output_bfd
, addr
)
3254 | ((value
>> 6) & 0x3fffc00),
3256 bfd_put_32 (output_bfd
,
3257 bfd_get_32 (output_bfd
, addr
+ 4)
3258 | ((value
<< 10) & 0x3fffc00),
3263 movi_3shori_putval (output_bfd
, value
, addr
)
3268 bfd_put_32 (output_bfd
,
3269 bfd_get_32 (output_bfd
, addr
)
3270 | ((value
>> 38) & 0x3fffc00),
3272 bfd_put_32 (output_bfd
,
3273 bfd_get_32 (output_bfd
, addr
+ 4)
3274 | ((value
>> 22) & 0x3fffc00),
3276 bfd_put_32 (output_bfd
,
3277 bfd_get_32 (output_bfd
, addr
+ 8)
3278 | ((value
>> 6) & 0x3fffc00),
3280 bfd_put_32 (output_bfd
,
3281 bfd_get_32 (output_bfd
, addr
+ 12)
3282 | ((value
<< 10) & 0x3fffc00),
3286 /* Create dynamic sections when linking against a dynamic object. */
3289 sh64_elf64_create_dynamic_sections (abfd
, info
)
3291 struct bfd_link_info
*info
;
3293 flagword flags
, pltflags
;
3294 register asection
*s
;
3295 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3298 switch (bed
->s
->arch_size
)
3309 bfd_set_error (bfd_error_bad_value
);
3313 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3314 .rel[a].bss sections. */
3316 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3317 | SEC_LINKER_CREATED
);
3320 pltflags
|= SEC_CODE
;
3321 if (bed
->plt_not_loaded
)
3322 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3323 if (bed
->plt_readonly
)
3324 pltflags
|= SEC_READONLY
;
3326 s
= bfd_make_section (abfd
, ".plt");
3328 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3329 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3332 if (bed
->want_plt_sym
)
3334 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3336 struct elf_link_hash_entry
*h
;
3337 struct bfd_link_hash_entry
*bh
= NULL
;
3339 if (! (_bfd_generic_link_add_one_symbol
3340 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3341 (bfd_vma
) 0, (const char *) NULL
, FALSE
, bed
->collect
, &bh
)))
3344 h
= (struct elf_link_hash_entry
*) bh
;
3345 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3346 h
->type
= STT_OBJECT
;
3349 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3353 s
= bfd_make_section (abfd
,
3354 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3356 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3357 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3360 if (! _bfd_elf_create_got_section (abfd
, info
))
3364 const char *secname
;
3369 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3371 secflags
= bfd_get_section_flags (abfd
, sec
);
3372 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3373 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3375 secname
= bfd_get_section_name (abfd
, sec
);
3376 relname
= (char *) bfd_malloc (strlen (secname
) + 6);
3377 strcpy (relname
, ".rela");
3378 strcat (relname
, secname
);
3379 s
= bfd_make_section (abfd
, relname
);
3381 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3382 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3387 if (bed
->want_dynbss
)
3389 /* The .dynbss section is a place to put symbols which are defined
3390 by dynamic objects, are referenced by regular objects, and are
3391 not functions. We must allocate space for them in the process
3392 image and use a R_*_COPY reloc to tell the dynamic linker to
3393 initialize them at run time. The linker script puts the .dynbss
3394 section into the .bss section of the final image. */
3395 s
= bfd_make_section (abfd
, ".dynbss");
3397 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3400 /* The .rel[a].bss section holds copy relocs. This section is not
3401 normally needed. We need to create it here, though, so that the
3402 linker will map it to an output section. We can't just create it
3403 only if we need it, because we will not know whether we need it
3404 until we have seen all the input files, and the first time the
3405 main linker code calls BFD after examining all the input files
3406 (size_dynamic_sections) the input sections have already been
3407 mapped to the output sections. If the section turns out not to
3408 be needed, we can discard it later. We will never need this
3409 section when generating a shared object, since they do not use
3413 s
= bfd_make_section (abfd
,
3414 (bed
->default_use_rela_p
3415 ? ".rela.bss" : ".rel.bss"));
3417 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3418 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3426 /* Adjust a symbol defined by a dynamic object and referenced by a
3427 regular object. The current definition is in some section of the
3428 dynamic object, but we're not including those sections. We have to
3429 change the definition to something the rest of the link can
3433 sh64_elf64_adjust_dynamic_symbol (info
, h
)
3434 struct bfd_link_info
*info
;
3435 struct elf_link_hash_entry
*h
;
3439 unsigned int power_of_two
;
3441 dynobj
= elf_hash_table (info
)->dynobj
;
3443 /* Make sure we know what is going on here. */
3444 BFD_ASSERT (dynobj
!= NULL
3445 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3446 || h
->weakdef
!= NULL
3447 || ((h
->elf_link_hash_flags
3448 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3449 && (h
->elf_link_hash_flags
3450 & ELF_LINK_HASH_REF_REGULAR
) != 0
3451 && (h
->elf_link_hash_flags
3452 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3454 /* If this is a function, put it in the procedure linkage table. We
3455 will fill in the contents of the procedure linkage table later,
3456 when we know the address of the .got section. */
3457 if (h
->type
== STT_FUNC
3458 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3461 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3462 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
3464 /* This case can occur if we saw a PLT reloc in an input
3465 file, but the symbol was never referred to by a dynamic
3466 object. In such a case, we don't actually need to build
3467 a procedure linkage table, and we can just do a REL64
3469 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
3473 /* Make sure this symbol is output as a dynamic symbol. */
3474 if (h
->dynindx
== -1)
3476 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3480 s
= bfd_get_section_by_name (dynobj
, ".plt");
3481 BFD_ASSERT (s
!= NULL
);
3483 /* If this is the first .plt entry, make room for the special
3485 if (s
->_raw_size
== 0)
3486 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3488 /* If this symbol is not defined in a regular file, and we are
3489 not generating a shared library, then set the symbol to this
3490 location in the .plt. This is required to make function
3491 pointers compare as equal between the normal executable and
3492 the shared library. */
3494 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3496 h
->root
.u
.def
.section
= s
;
3497 h
->root
.u
.def
.value
= s
->_raw_size
;
3500 h
->plt
.offset
= s
->_raw_size
;
3502 /* Make room for this entry. */
3503 s
->_raw_size
+= elf_sh64_sizeof_plt (info
);
3505 /* We also need to make an entry in the .got.plt section, which
3506 will be placed in the .got section by the linker script. */
3508 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3509 BFD_ASSERT (s
!= NULL
);
3512 /* We also need to make an entry in the .rela.plt section. */
3514 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3515 BFD_ASSERT (s
!= NULL
);
3516 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3521 /* If this is a weak symbol, and there is a real definition, the
3522 processor independent code will have arranged for us to see the
3523 real definition first, and we can just use the same value. */
3524 if (h
->weakdef
!= NULL
)
3526 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3527 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3528 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3529 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3533 /* This is a reference to a symbol defined by a dynamic object which
3534 is not a function. */
3536 /* If we are creating a shared library, we must presume that the
3537 only references to the symbol are via the global offset table.
3538 For such cases we need not do anything here; the relocations will
3539 be handled correctly by relocate_section. */
3543 /* If there are no references to this symbol that do not use the
3544 GOT, we don't need to generate a copy reloc. */
3545 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3548 /* We must allocate the symbol in our .dynbss section, which will
3549 become part of the .bss section of the executable. There will be
3550 an entry for this symbol in the .dynsym section. The dynamic
3551 object will contain position independent code, so all references
3552 from the dynamic object to this symbol will go through the global
3553 offset table. The dynamic linker will use the .dynsym entry to
3554 determine the address it must put in the global offset table, so
3555 both the dynamic object and the regular object will refer to the
3556 same memory location for the variable. */
3558 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3559 BFD_ASSERT (s
!= NULL
);
3561 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3562 copy the initial value out of the dynamic object and into the
3563 runtime process image. We need to remember the offset into the
3564 .rela.bss section we are going to use. */
3565 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3569 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3570 BFD_ASSERT (srel
!= NULL
);
3571 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
3572 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3575 /* We need to figure out the alignment required for this symbol. I
3576 have no idea how ELF linkers handle this. */
3577 power_of_two
= bfd_log2 (h
->size
);
3578 if (power_of_two
> 3)
3581 /* Apply the required alignment. */
3582 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3583 (bfd_size_type
) (1 << power_of_two
));
3584 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3586 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3590 /* Define the symbol as being at this point in the section. */
3591 h
->root
.u
.def
.section
= s
;
3592 h
->root
.u
.def
.value
= s
->_raw_size
;
3594 /* Increment the section size to make room for the symbol. */
3595 s
->_raw_size
+= h
->size
;
3600 /* This function is called via sh_elf_link_hash_traverse if we are
3601 creating a shared object with -Bsymbolic. It discards the space
3602 allocated to copy PC relative relocs against symbols which are
3603 defined in regular objects. We allocated space for them in the
3604 check_relocs routine, but we won't fill them in in the
3605 relocate_section routine. */
3608 sh64_elf64_discard_copies (h
, ignore
)
3609 struct elf_sh64_link_hash_entry
*h
;
3610 PTR ignore ATTRIBUTE_UNUSED
;
3612 struct elf_sh64_pcrel_relocs_copied
*s
;
3614 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3615 h
= (struct elf_sh64_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3617 /* We only discard relocs for symbols defined in a regular object. */
3618 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3621 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3622 s
->section
->_raw_size
-= s
->count
* sizeof (Elf64_External_Rela
);
3627 /* Set the sizes of the dynamic sections. */
3630 sh64_elf64_size_dynamic_sections (output_bfd
, info
)
3632 struct bfd_link_info
*info
;
3638 bfd_boolean reltext
;
3640 dynobj
= elf_hash_table (info
)->dynobj
;
3641 BFD_ASSERT (dynobj
!= NULL
);
3643 if (elf_hash_table (info
)->dynamic_sections_created
)
3645 /* Set the contents of the .interp section to the interpreter. */
3648 s
= bfd_get_section_by_name (dynobj
, ".interp");
3649 BFD_ASSERT (s
!= NULL
);
3650 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3651 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3656 /* We may have created entries in the .rela.got section.
3657 However, if we are not creating the dynamic sections, we will
3658 not actually use these entries. Reset the size of .rela.got,
3659 which will cause it to get stripped from the output file
3661 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
3666 /* If this is a -Bsymbolic shared link, then we need to discard all
3667 PC relative relocs against symbols defined in a regular object.
3668 We allocated space for them in the check_relocs routine, but we
3669 will not fill them in in the relocate_section routine. */
3670 if (info
->shared
&& info
->symbolic
)
3671 sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info
),
3672 sh64_elf64_discard_copies
,
3675 /* The check_relocs and adjust_dynamic_symbol entry points have
3676 determined the sizes of the various dynamic sections. Allocate
3681 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3686 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3689 /* It's OK to base decisions on the section name, because none
3690 of the dynobj section names depend upon the input files. */
3691 name
= bfd_get_section_name (dynobj
, s
);
3695 if (strcmp (name
, ".plt") == 0)
3697 if (s
->_raw_size
== 0)
3699 /* Strip this section if we don't need it; see the
3705 /* Remember whether there is a PLT. */
3709 else if (strncmp (name
, ".rela", 5) == 0)
3711 if (s
->_raw_size
== 0)
3713 /* If we don't need this section, strip it from the
3714 output file. This is mostly to handle .rela.bss and
3715 .rela.plt. We must create both sections in
3716 create_dynamic_sections, because they must be created
3717 before the linker maps input sections to output
3718 sections. The linker does that before
3719 adjust_dynamic_symbol is called, and it is that
3720 function which decides whether anything needs to go
3721 into these sections. */
3728 /* Remember whether there are any reloc sections other
3730 if (strcmp (name
, ".rela.plt") != 0)
3732 const char *outname
;
3736 /* If this relocation section applies to a read only
3737 section, then we probably need a DT_TEXTREL
3738 entry. The entries in the .rela.plt section
3739 really apply to the .got section, which we
3740 created ourselves and so know is not readonly. */
3741 outname
= bfd_get_section_name (output_bfd
,
3743 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3745 && (target
->flags
& SEC_READONLY
) != 0
3746 && (target
->flags
& SEC_ALLOC
) != 0)
3750 /* We use the reloc_count field as a counter if we need
3751 to copy relocs into the output file. */
3755 else if (strncmp (name
, ".got", 4) != 0)
3757 /* It's not one of our sections, so don't allocate space. */
3763 _bfd_strip_section_from_output (info
, s
);
3767 /* Allocate memory for the section contents. */
3768 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3769 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3773 if (elf_hash_table (info
)->dynamic_sections_created
)
3775 /* Add some entries to the .dynamic section. We fill in the
3776 values later, in sh64_elf64_finish_dynamic_sections, but we
3777 must add the entries now so that we get the correct size for
3778 the .dynamic section. The DT_DEBUG entry is filled in by the
3779 dynamic linker and used by the debugger. */
3782 if (! bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
3788 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0)
3789 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3790 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3791 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
3797 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
3798 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
3799 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
3800 sizeof (Elf64_External_Rela
)))
3806 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3814 /* Finish up dynamic symbol handling. We set the contents of various
3815 dynamic sections here. */
3818 sh64_elf64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3820 struct bfd_link_info
*info
;
3821 struct elf_link_hash_entry
*h
;
3822 Elf_Internal_Sym
*sym
;
3826 dynobj
= elf_hash_table (info
)->dynobj
;
3828 if (h
->plt
.offset
!= (bfd_vma
) -1)
3836 Elf_Internal_Rela rel
;
3839 /* This symbol has an entry in the procedure linkage table. Set
3842 BFD_ASSERT (h
->dynindx
!= -1);
3844 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3845 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3846 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3847 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3849 /* Get the index in the procedure linkage table which
3850 corresponds to this symbol. This is the index of this symbol
3851 in all the symbols for which we are making plt entries. The
3852 first entry in the procedure linkage table is reserved. */
3853 plt_index
= h
->plt
.offset
/ elf_sh64_sizeof_plt (info
) - 1;
3855 /* Get the offset into the .got table of the entry that
3856 corresponds to this function. Each .got entry is 8 bytes.
3857 The first three are reserved. */
3858 got_offset
= (plt_index
+ 3) * 8;
3861 got_offset
-= GOT_BIAS
;
3863 /* Fill in the entry in the procedure linkage table. */
3866 if (elf_sh64_plt_entry
== NULL
)
3868 elf_sh64_plt_entry
= (bfd_big_endian (output_bfd
) ?
3869 elf_sh64_plt_entry_be
: elf_sh64_plt_entry_le
);
3871 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_plt_entry
,
3872 elf_sh64_sizeof_plt (info
));
3873 movi_3shori_putval (output_bfd
,
3874 (sgot
->output_section
->vma
3875 + sgot
->output_offset
3877 (splt
->contents
+ h
->plt
.offset
3878 + elf_sh64_plt_symbol_offset (info
)));
3880 /* Set bottom bit because its for a branch to SHmedia */
3881 movi_shori_putval (output_bfd
,
3883 + elf_sh64_plt_plt0_offset (info
) + 8)
3885 (splt
->contents
+ h
->plt
.offset
3886 + elf_sh64_plt_plt0_offset (info
)));
3890 if (elf_sh64_pic_plt_entry
== NULL
)
3892 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
3893 elf_sh64_pic_plt_entry_be
:
3894 elf_sh64_pic_plt_entry_le
);
3896 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh64_pic_plt_entry
,
3897 elf_sh64_sizeof_plt (info
));
3898 movi_shori_putval (output_bfd
, got_offset
,
3899 (splt
->contents
+ h
->plt
.offset
3900 + elf_sh64_plt_symbol_offset (info
)));
3904 got_offset
+= GOT_BIAS
;
3906 movi_shori_putval (output_bfd
,
3907 plt_index
* sizeof (Elf64_External_Rela
),
3908 (splt
->contents
+ h
->plt
.offset
3909 + elf_sh64_plt_reloc_offset (info
)));
3911 /* Fill in the entry in the global offset table. */
3912 bfd_put_64 (output_bfd
,
3913 (splt
->output_section
->vma
3914 + splt
->output_offset
3916 + elf_sh64_plt_temp_offset (info
)),
3917 sgot
->contents
+ got_offset
);
3919 /* Fill in the entry in the .rela.plt section. */
3920 rel
.r_offset
= (sgot
->output_section
->vma
3921 + sgot
->output_offset
3923 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_JMP_SLOT64
);
3925 rel
.r_addend
= GOT_BIAS
;
3926 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
3927 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3929 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3931 /* Mark the symbol as undefined, rather than as defined in
3932 the .plt section. Leave the value alone. */
3933 sym
->st_shndx
= SHN_UNDEF
;
3937 if (h
->got
.offset
!= (bfd_vma
) -1)
3941 Elf_Internal_Rela rel
;
3944 /* This symbol has an entry in the global offset table. Set it
3947 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3948 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3949 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3951 rel
.r_offset
= (sgot
->output_section
->vma
3952 + sgot
->output_offset
3953 + (h
->got
.offset
&~ 1));
3955 /* If this is a -Bsymbolic link, and the symbol is defined
3956 locally, we just want to emit a RELATIVE reloc. Likewise if
3957 the symbol was forced to be local because of a version file.
3958 The entry in the global offset table will already have been
3959 initialized in the relocate_section function. */
3961 && (info
->symbolic
|| h
->dynindx
== -1)
3962 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3964 rel
.r_info
= ELF64_R_INFO (0, R_SH_RELATIVE64
);
3965 rel
.r_addend
= (h
->root
.u
.def
.value
3966 + h
->root
.u
.def
.section
->output_section
->vma
3967 + h
->root
.u
.def
.section
->output_offset
);
3971 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3972 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_GLOB_DAT64
);
3976 loc
= srel
->contents
;
3977 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3978 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
3981 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3984 Elf_Internal_Rela rel
;
3987 /* This symbol needs a copy reloc. Set it up. */
3989 BFD_ASSERT (h
->dynindx
!= -1
3990 && (h
->root
.type
== bfd_link_hash_defined
3991 || h
->root
.type
== bfd_link_hash_defweak
));
3993 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3995 BFD_ASSERT (s
!= NULL
);
3997 rel
.r_offset
= (h
->root
.u
.def
.value
3998 + h
->root
.u
.def
.section
->output_section
->vma
3999 + h
->root
.u
.def
.section
->output_offset
);
4000 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SH_COPY64
);
4003 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4004 bfd_elf64_swap_reloca_out (output_bfd
, &rel
, loc
);
4007 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4008 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4009 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4010 sym
->st_shndx
= SHN_ABS
;
4015 /* Finish up the dynamic sections. */
4018 sh64_elf64_finish_dynamic_sections (output_bfd
, info
)
4020 struct bfd_link_info
*info
;
4026 dynobj
= elf_hash_table (info
)->dynobj
;
4028 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4029 BFD_ASSERT (sgot
!= NULL
);
4030 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4032 if (elf_hash_table (info
)->dynamic_sections_created
)
4035 Elf64_External_Dyn
*dyncon
, *dynconend
;
4037 BFD_ASSERT (sdyn
!= NULL
);
4039 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4040 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4041 for (; dyncon
< dynconend
; dyncon
++)
4043 Elf_Internal_Dyn dyn
;
4046 struct elf_link_hash_entry
*h
;
4048 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4056 name
= info
->init_function
;
4060 name
= info
->fini_function
;
4062 if (dyn
.d_un
.d_val
!= 0)
4064 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
4065 FALSE
, FALSE
, TRUE
);
4066 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
4068 dyn
.d_un
.d_val
|= 1;
4069 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4081 s
= bfd_get_section_by_name (output_bfd
, name
);
4082 BFD_ASSERT (s
!= NULL
);
4083 dyn
.d_un
.d_ptr
= s
->vma
;
4084 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4088 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4089 BFD_ASSERT (s
!= NULL
);
4090 if (s
->_cooked_size
!= 0)
4091 dyn
.d_un
.d_val
= s
->_cooked_size
;
4093 dyn
.d_un
.d_val
= s
->_raw_size
;
4094 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4098 /* My reading of the SVR4 ABI indicates that the
4099 procedure linkage table relocs (DT_JMPREL) should be
4100 included in the overall relocs (DT_RELA). This is
4101 what Solaris does. However, UnixWare can not handle
4102 that case. Therefore, we override the DT_RELASZ entry
4103 here to make it not include the JMPREL relocs. Since
4104 the linker script arranges for .rela.plt to follow all
4105 other relocation sections, we don't have to worry
4106 about changing the DT_RELA entry. */
4107 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4110 if (s
->_cooked_size
!= 0)
4111 dyn
.d_un
.d_val
-= s
->_cooked_size
;
4113 dyn
.d_un
.d_val
-= s
->_raw_size
;
4115 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4120 /* Fill in the first entry in the procedure linkage table. */
4121 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4122 if (splt
&& splt
->_raw_size
> 0)
4126 if (elf_sh64_pic_plt_entry
== NULL
)
4128 elf_sh64_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
4129 elf_sh64_pic_plt_entry_be
:
4130 elf_sh64_pic_plt_entry_le
);
4132 memcpy (splt
->contents
, elf_sh64_pic_plt_entry
,
4133 elf_sh64_sizeof_plt (info
));
4137 if (elf_sh64_plt0_entry
== NULL
)
4139 elf_sh64_plt0_entry
= (bfd_big_endian (output_bfd
) ?
4140 elf_sh64_plt0_entry_be
:
4141 elf_sh64_plt0_entry_le
);
4143 memcpy (splt
->contents
, elf_sh64_plt0_entry
, PLT_ENTRY_SIZE
);
4144 movi_3shori_putval (output_bfd
,
4145 sgot
->output_section
->vma
4146 + sgot
->output_offset
,
4148 + elf_sh64_plt0_gotplt_offset (info
));
4151 /* UnixWare sets the entsize of .plt to 8, although that doesn't
4152 really seem like the right value. */
4153 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 8;
4157 /* Fill in the first three entries in the global offset table. */
4158 if (sgot
->_raw_size
> 0)
4161 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4163 bfd_put_64 (output_bfd
,
4164 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4166 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4167 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 16);
4170 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
4175 #define TARGET_BIG_SYM bfd_elf64_sh64_vec
4176 #define TARGET_BIG_NAME "elf64-sh64"
4177 #define TARGET_LITTLE_SYM bfd_elf64_sh64l_vec
4178 #define TARGET_LITTLE_NAME "elf64-sh64l"
4179 #define ELF_ARCH bfd_arch_sh
4180 #define ELF_MACHINE_CODE EM_SH
4181 #define ELF_MAXPAGESIZE 128
4183 #define elf_symbol_leading_char '_'
4185 #define bfd_elf64_bfd_reloc_type_lookup sh_elf64_reloc_type_lookup
4186 #define elf_info_to_howto sh_elf64_info_to_howto
4188 /* Note: there's no relaxation at present. */
4190 #define elf_backend_relocate_section sh_elf64_relocate_section
4191 #define bfd_elf64_bfd_get_relocated_section_contents \
4192 sh_elf64_get_relocated_section_contents
4193 #define elf_backend_object_p sh_elf64_set_mach_from_flags
4194 #define bfd_elf64_bfd_set_private_flags \
4195 sh_elf64_set_private_flags
4196 #define bfd_elf64_bfd_copy_private_bfd_data \
4197 sh_elf64_copy_private_data
4198 #define bfd_elf64_bfd_merge_private_bfd_data \
4199 sh_elf64_merge_private_data
4200 #define elf_backend_fake_sections sh64_elf64_fake_sections
4202 #define elf_backend_gc_mark_hook sh_elf64_gc_mark_hook
4203 #define elf_backend_gc_sweep_hook sh_elf64_gc_sweep_hook
4204 #define elf_backend_check_relocs sh_elf64_check_relocs
4206 #define elf_backend_can_gc_sections 1
4208 #define elf_backend_get_symbol_type sh64_elf64_get_symbol_type
4210 #define elf_backend_add_symbol_hook sh64_elf64_add_symbol_hook
4212 #define elf_backend_link_output_symbol_hook \
4213 sh64_elf64_link_output_symbol_hook
4215 #define elf_backend_final_write_processing \
4216 sh64_elf64_final_write_processing
4218 #define elf_backend_create_dynamic_sections \
4219 sh64_elf64_create_dynamic_sections
4220 #define bfd_elf64_bfd_link_hash_table_create \
4221 sh64_elf64_link_hash_table_create
4222 #define elf_backend_adjust_dynamic_symbol \
4223 sh64_elf64_adjust_dynamic_symbol
4224 #define elf_backend_size_dynamic_sections \
4225 sh64_elf64_size_dynamic_sections
4226 #define elf_backend_finish_dynamic_symbol \
4227 sh64_elf64_finish_dynamic_symbol
4228 #define elf_backend_finish_dynamic_sections \
4229 sh64_elf64_finish_dynamic_sections
4231 #define elf_backend_want_got_plt 1
4232 #define elf_backend_plt_readonly 1
4233 #define elf_backend_want_plt_sym 0
4234 #define elf_backend_got_header_size 24
4235 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
4237 #include "elf64-target.h"
4239 /* NetBSD support. */
4240 #undef TARGET_BIG_SYM
4241 #define TARGET_BIG_SYM bfd_elf64_sh64nbsd_vec
4242 #undef TARGET_BIG_NAME
4243 #define TARGET_BIG_NAME "elf64-sh64-nbsd"
4244 #undef TARGET_LITTLE_SYM
4245 #define TARGET_LITTLE_SYM bfd_elf64_sh64lnbsd_vec
4246 #undef TARGET_LITTLE_NAME
4247 #define TARGET_LITTLE_NAME "elf64-sh64l-nbsd"
4248 #undef ELF_MAXPAGESIZE
4249 #define ELF_MAXPAGESIZE 0x10000
4250 #undef elf_symbol_leading_char
4251 #define elf_symbol_leading_char 0
4253 #define elf64_bed elf64_sh64_nbsd_bed
4255 #include "elf64-target.h"
4257 /* Linux support. */
4258 #undef TARGET_BIG_SYM
4259 #define TARGET_BIG_SYM bfd_elf64_sh64blin_vec
4260 #undef TARGET_BIG_NAME
4261 #define TARGET_BIG_NAME "elf64-sh64big-linux"
4262 #undef TARGET_LITTLE_SYM
4263 #define TARGET_LITTLE_SYM bfd_elf64_sh64lin_vec
4264 #undef TARGET_LITTLE_NAME
4265 #define TARGET_LITTLE_NAME "elf64-sh64-linux"
4267 #define INCLUDED_TARGET_FILE
4268 #include "elf64-target.h"