1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static bfd_reloc_status_type sh_elf_reloc
30 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33 static reloc_howto_type *sh_elf_reloc_type_lookup
34 PARAMS ((bfd *, bfd_reloc_code_real_type));
35 static void sh_elf_info_to_howto
36 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
37 static boolean sh_elf_set_private_flags
38 PARAMS ((bfd *, flagword));
39 static boolean sh_elf_copy_private_data
40 PARAMS ((bfd *, bfd *));
41 static boolean sh_elf_merge_private_data
42 PARAMS ((bfd *, bfd *));
43 static boolean sh_elf_set_mach_from_flags
45 static boolean sh_elf_relax_section
46 PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
47 static boolean sh_elf_relax_delete_bytes
48 PARAMS ((bfd *, asection *, bfd_vma, int));
49 static boolean sh_elf_align_loads
50 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, boolean *));
51 static boolean sh_elf_swap_insns
52 PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
53 static boolean sh_elf_relocate_section
54 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
55 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
56 static bfd_byte *sh_elf_get_relocated_section_contents
57 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
58 bfd_byte *, boolean, asymbol **));
59 static boolean sh_elf_check_relocs
60 PARAMS ((bfd *, struct bfd_link_info *, asection *,
61 const Elf_Internal_Rela *));
62 static struct bfd_hash_entry *sh_elf_link_hash_newfunc
63 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
64 static struct bfd_link_hash_table *sh_elf_link_hash_table_create
66 static boolean sh_elf_adjust_dynamic_symbol
67 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
68 static boolean sh_elf_size_dynamic_sections
69 PARAMS ((bfd *, struct bfd_link_info *));
70 static boolean sh_elf_finish_dynamic_symbol
71 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
73 static boolean sh_elf_finish_dynamic_sections
74 PARAMS ((bfd *, struct bfd_link_info *));
75 static bfd_reloc_status_type sh_elf_reloc_loop
76 PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,
78 static boolean sh_elf_create_dynamic_sections
79 PARAMS ((bfd *, struct bfd_link_info *));
80 static asection * sh_elf_gc_mark_hook
81 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
82 struct elf_link_hash_entry *, Elf_Internal_Sym *));
83 static boolean sh_elf_gc_sweep_hook
84 PARAMS ((bfd *, struct bfd_link_info *, asection *,
85 const Elf_Internal_Rela *));
86 static enum elf_reloc_type_class sh_elf_reloc_type_class
87 PARAMS ((const Elf_Internal_Rela *));
89 /* The name of the dynamic interpreter. This is put in the .interp
92 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
94 static reloc_howto_type sh_elf_howto_table[] =
97 HOWTO (R_SH_NONE, /* type */
99 0, /* size (0 = byte, 1 = short, 2 = long) */
101 false, /* pc_relative */
103 complain_overflow_dont, /* complain_on_overflow */
104 sh_elf_ignore_reloc, /* special_function */
105 "R_SH_NONE", /* name */
106 false, /* partial_inplace */
109 false), /* pcrel_offset */
111 /* 32 bit absolute relocation. Setting partial_inplace to true and
112 src_mask to a non-zero value is similar to the COFF toolchain. */
113 HOWTO (R_SH_DIR32, /* type */
115 2, /* size (0 = byte, 1 = short, 2 = long) */
117 false, /* pc_relative */
119 complain_overflow_bitfield, /* complain_on_overflow */
120 sh_elf_reloc, /* special_function */
121 "R_SH_DIR32", /* name */
122 true, /* partial_inplace */
123 0xffffffff, /* src_mask */
124 0xffffffff, /* dst_mask */
125 false), /* pcrel_offset */
127 /* 32 bit PC relative relocation. */
128 HOWTO (R_SH_REL32, /* type */
130 2, /* size (0 = byte, 1 = short, 2 = long) */
132 true, /* pc_relative */
134 complain_overflow_signed, /* complain_on_overflow */
135 sh_elf_ignore_reloc, /* special_function */
136 "R_SH_REL32", /* name */
137 true, /* partial_inplace */
138 0xffffffff, /* src_mask */
139 0xffffffff, /* dst_mask */
140 true), /* pcrel_offset */
142 /* 8 bit PC relative branch divided by 2. */
143 HOWTO (R_SH_DIR8WPN, /* type */
145 1, /* size (0 = byte, 1 = short, 2 = long) */
147 true, /* pc_relative */
149 complain_overflow_signed, /* complain_on_overflow */
150 sh_elf_ignore_reloc, /* special_function */
151 "R_SH_DIR8WPN", /* name */
152 true, /* partial_inplace */
155 true), /* pcrel_offset */
157 /* 12 bit PC relative branch divided by 2. */
158 HOWTO (R_SH_IND12W, /* type */
160 1, /* size (0 = byte, 1 = short, 2 = long) */
162 true, /* pc_relative */
164 complain_overflow_signed, /* complain_on_overflow */
165 sh_elf_reloc, /* special_function */
166 "R_SH_IND12W", /* name */
167 true, /* partial_inplace */
168 0xfff, /* src_mask */
169 0xfff, /* dst_mask */
170 true), /* pcrel_offset */
172 /* 8 bit unsigned PC relative divided by 4. */
173 HOWTO (R_SH_DIR8WPL, /* type */
175 1, /* size (0 = byte, 1 = short, 2 = long) */
177 true, /* pc_relative */
179 complain_overflow_unsigned, /* complain_on_overflow */
180 sh_elf_ignore_reloc, /* special_function */
181 "R_SH_DIR8WPL", /* name */
182 true, /* partial_inplace */
185 true), /* pcrel_offset */
187 /* 8 bit unsigned PC relative divided by 2. */
188 HOWTO (R_SH_DIR8WPZ, /* type */
190 1, /* size (0 = byte, 1 = short, 2 = long) */
192 true, /* pc_relative */
194 complain_overflow_unsigned, /* complain_on_overflow */
195 sh_elf_ignore_reloc, /* special_function */
196 "R_SH_DIR8WPZ", /* name */
197 true, /* partial_inplace */
200 true), /* pcrel_offset */
202 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
203 special symbol for the GBR relative area, and that is not
205 HOWTO (R_SH_DIR8BP, /* type */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
209 false, /* pc_relative */
211 complain_overflow_unsigned, /* complain_on_overflow */
212 sh_elf_ignore_reloc, /* special_function */
213 "R_SH_DIR8BP", /* name */
214 false, /* partial_inplace */
217 true), /* pcrel_offset */
219 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
220 we have some special symbol for the GBR relative area, and that
221 is not implemented. */
222 HOWTO (R_SH_DIR8W, /* type */
224 1, /* size (0 = byte, 1 = short, 2 = long) */
226 false, /* pc_relative */
228 complain_overflow_unsigned, /* complain_on_overflow */
229 sh_elf_ignore_reloc, /* special_function */
230 "R_SH_DIR8W", /* name */
231 false, /* partial_inplace */
234 true), /* pcrel_offset */
236 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
237 we have some special symbol for the GBR relative area, and that
238 is not implemented. */
239 HOWTO (R_SH_DIR8L, /* type */
241 1, /* size (0 = byte, 1 = short, 2 = long) */
243 false, /* pc_relative */
245 complain_overflow_unsigned, /* complain_on_overflow */
246 sh_elf_ignore_reloc, /* special_function */
247 "R_SH_DIR8L", /* name */
248 false, /* partial_inplace */
251 true), /* pcrel_offset */
269 /* The remaining relocs are a GNU extension used for relaxing. The
270 final pass of the linker never needs to do anything with any of
271 these relocs. Any required operations are handled by the
274 /* A 16 bit switch table entry. This is generated for an expression
275 such as ``.word L1 - L2''. The offset holds the difference
276 between the reloc address and L2. */
277 HOWTO (R_SH_SWITCH16, /* type */
279 1, /* size (0 = byte, 1 = short, 2 = long) */
281 false, /* pc_relative */
283 complain_overflow_unsigned, /* complain_on_overflow */
284 sh_elf_ignore_reloc, /* special_function */
285 "R_SH_SWITCH16", /* name */
286 false, /* partial_inplace */
289 true), /* pcrel_offset */
291 /* A 32 bit switch table entry. This is generated for an expression
292 such as ``.long L1 - L2''. The offset holds the difference
293 between the reloc address and L2. */
294 HOWTO (R_SH_SWITCH32, /* type */
296 2, /* size (0 = byte, 1 = short, 2 = long) */
298 false, /* pc_relative */
300 complain_overflow_unsigned, /* complain_on_overflow */
301 sh_elf_ignore_reloc, /* special_function */
302 "R_SH_SWITCH32", /* name */
303 false, /* partial_inplace */
306 true), /* pcrel_offset */
308 /* Indicates a .uses pseudo-op. The compiler will generate .uses
309 pseudo-ops when it finds a function call which can be relaxed.
310 The offset field holds the PC relative offset to the instruction
311 which loads the register used in the function call. */
312 HOWTO (R_SH_USES, /* type */
314 1, /* size (0 = byte, 1 = short, 2 = long) */
316 false, /* pc_relative */
318 complain_overflow_unsigned, /* complain_on_overflow */
319 sh_elf_ignore_reloc, /* special_function */
320 "R_SH_USES", /* name */
321 false, /* partial_inplace */
324 true), /* pcrel_offset */
326 /* The assembler will generate this reloc for addresses referred to
327 by the register loads associated with USES relocs. The offset
328 field holds the number of times the address is referenced in the
330 HOWTO (R_SH_COUNT, /* type */
332 1, /* size (0 = byte, 1 = short, 2 = long) */
334 false, /* pc_relative */
336 complain_overflow_unsigned, /* complain_on_overflow */
337 sh_elf_ignore_reloc, /* special_function */
338 "R_SH_COUNT", /* name */
339 false, /* partial_inplace */
342 true), /* pcrel_offset */
344 /* Indicates an alignment statement. The offset field is the power
345 of 2 to which subsequent portions of the object file must be
347 HOWTO (R_SH_ALIGN, /* type */
349 1, /* size (0 = byte, 1 = short, 2 = long) */
351 false, /* pc_relative */
353 complain_overflow_unsigned, /* complain_on_overflow */
354 sh_elf_ignore_reloc, /* special_function */
355 "R_SH_ALIGN", /* name */
356 false, /* partial_inplace */
359 true), /* pcrel_offset */
361 /* The assembler will generate this reloc before a block of
362 instructions. A section should be processed as assumining it
363 contains data, unless this reloc is seen. */
364 HOWTO (R_SH_CODE, /* type */
366 1, /* size (0 = byte, 1 = short, 2 = long) */
368 false, /* pc_relative */
370 complain_overflow_unsigned, /* complain_on_overflow */
371 sh_elf_ignore_reloc, /* special_function */
372 "R_SH_CODE", /* name */
373 false, /* partial_inplace */
376 true), /* pcrel_offset */
378 /* The assembler will generate this reloc after a block of
379 instructions when it sees data that is not instructions. */
380 HOWTO (R_SH_DATA, /* type */
382 1, /* size (0 = byte, 1 = short, 2 = long) */
384 false, /* pc_relative */
386 complain_overflow_unsigned, /* complain_on_overflow */
387 sh_elf_ignore_reloc, /* special_function */
388 "R_SH_DATA", /* name */
389 false, /* partial_inplace */
392 true), /* pcrel_offset */
394 /* The assembler generates this reloc for each label within a block
395 of instructions. This permits the linker to avoid swapping
396 instructions which are the targets of branches. */
397 HOWTO (R_SH_LABEL, /* type */
399 1, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_unsigned, /* complain_on_overflow */
404 sh_elf_ignore_reloc, /* special_function */
405 "R_SH_LABEL", /* name */
406 false, /* partial_inplace */
409 true), /* pcrel_offset */
411 /* An 8 bit switch table entry. This is generated for an expression
412 such as ``.word L1 - L2''. The offset holds the difference
413 between the reloc address and L2. */
414 HOWTO (R_SH_SWITCH8, /* type */
416 0, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_unsigned, /* complain_on_overflow */
421 sh_elf_ignore_reloc, /* special_function */
422 "R_SH_SWITCH8", /* name */
423 false, /* partial_inplace */
426 true), /* pcrel_offset */
428 /* GNU extension to record C++ vtable hierarchy */
429 HOWTO (R_SH_GNU_VTINHERIT, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_dont, /* complain_on_overflow */
436 NULL, /* special_function */
437 "R_SH_GNU_VTINHERIT", /* name */
438 false, /* partial_inplace */
441 false), /* pcrel_offset */
443 /* GNU extension to record C++ vtable member usage */
444 HOWTO (R_SH_GNU_VTENTRY, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 false, /* pc_relative */
450 complain_overflow_dont, /* complain_on_overflow */
451 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
452 "R_SH_GNU_VTENTRY", /* name */
453 false, /* partial_inplace */
456 false), /* pcrel_offset */
458 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
459 HOWTO (R_SH_LOOP_START, /* type */
461 1, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_signed, /* complain_on_overflow */
466 sh_elf_ignore_reloc, /* special_function */
467 "R_SH_LOOP_START", /* name */
468 true, /* partial_inplace */
471 true), /* pcrel_offset */
473 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
474 HOWTO (R_SH_LOOP_END, /* type */
476 1, /* size (0 = byte, 1 = short, 2 = long) */
478 false, /* pc_relative */
480 complain_overflow_signed, /* complain_on_overflow */
481 sh_elf_ignore_reloc, /* special_function */
482 "R_SH_LOOP_END", /* name */
483 true, /* partial_inplace */
486 true), /* pcrel_offset */
496 #ifdef INCLUDE_SHMEDIA
497 /* Used in SHLLI.L and SHLRI.L. */
498 HOWTO (R_SH_DIR5U, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 false, /* pc_relative */
504 complain_overflow_unsigned, /* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 "R_SH_DIR5U", /* name */
507 false, /* partial_inplace */
509 0xfc00, /* dst_mask */
510 false), /* pcrel_offset */
512 /* Used in SHARI, SHLLI et al. */
513 HOWTO (R_SH_DIR6U, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 false, /* pc_relative */
519 complain_overflow_unsigned, /* complain_on_overflow */
520 bfd_elf_generic_reloc, /* special_function */
521 "R_SH_DIR6U", /* name */
522 false, /* partial_inplace */
524 0xfc00, /* dst_mask */
525 false), /* pcrel_offset */
527 /* Used in BxxI, LDHI.L et al. */
528 HOWTO (R_SH_DIR6S, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 false, /* pc_relative */
534 complain_overflow_signed, /* complain_on_overflow */
535 bfd_elf_generic_reloc, /* special_function */
536 "R_SH_DIR6S", /* name */
537 false, /* partial_inplace */
539 0xfc00, /* dst_mask */
540 false), /* pcrel_offset */
542 /* Used in ADDI, ANDI et al. */
543 HOWTO (R_SH_DIR10S, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 false, /* pc_relative */
549 complain_overflow_signed, /* complain_on_overflow */
550 bfd_elf_generic_reloc, /* special_function */
551 "R_SH_DIR10S", /* name */
552 false, /* partial_inplace */
554 0xffc00, /* dst_mask */
555 false), /* pcrel_offset */
557 /* Used in LD.UW, ST.W et al. */
558 HOWTO (R_SH_DIR10SW, /* type */
560 2, /* size (0 = byte, 1 = short, 2 = long) */
562 false, /* pc_relative */
564 complain_overflow_signed, /* complain_on_overflow */
565 bfd_elf_generic_reloc, /* special_function */
566 "R_SH_DIR10SW", /* name */
567 false, /* partial_inplace */
569 0xffc00, /* dst_mask */
570 false), /* pcrel_offset */
572 /* Used in LD.L, FLD.S et al. */
573 HOWTO (R_SH_DIR10SL, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 false, /* pc_relative */
579 complain_overflow_signed, /* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_SH_DIR10SL", /* name */
582 false, /* partial_inplace */
584 0xffc00, /* dst_mask */
585 false), /* pcrel_offset */
587 /* Used in FLD.D, FST.P et al. */
588 HOWTO (R_SH_DIR10SQ, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 false, /* pc_relative */
594 complain_overflow_signed, /* complain_on_overflow */
595 bfd_elf_generic_reloc, /* special_function */
596 "R_SH_DIR10SQ", /* name */
597 false, /* partial_inplace */
599 0xffc00, /* dst_mask */
600 false), /* pcrel_offset */
721 HOWTO (R_SH_GOT32, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 false, /* pc_relative */
727 complain_overflow_bitfield, /* complain_on_overflow */
728 bfd_elf_generic_reloc, /* */
729 "R_SH_GOT32", /* name */
730 true, /* partial_inplace */
731 0xffffffff, /* src_mask */
732 0xffffffff, /* dst_mask */
733 false), /* pcrel_offset */
735 HOWTO (R_SH_PLT32, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 true, /* pc_relative */
741 complain_overflow_bitfield, /* complain_on_overflow */
742 bfd_elf_generic_reloc, /* */
743 "R_SH_PLT32", /* name */
744 true, /* partial_inplace */
745 0xffffffff, /* src_mask */
746 0xffffffff, /* dst_mask */
747 true), /* pcrel_offset */
749 HOWTO (R_SH_COPY, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_bitfield, /* complain_on_overflow */
756 bfd_elf_generic_reloc, /* */
757 "R_SH_COPY", /* name */
758 true, /* partial_inplace */
759 0xffffffff, /* src_mask */
760 0xffffffff, /* dst_mask */
761 false), /* pcrel_offset */
763 HOWTO (R_SH_GLOB_DAT, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 false, /* pc_relative */
769 complain_overflow_bitfield, /* complain_on_overflow */
770 bfd_elf_generic_reloc, /* */
771 "R_SH_GLOB_DAT", /* name */
772 true, /* partial_inplace */
773 0xffffffff, /* src_mask */
774 0xffffffff, /* dst_mask */
775 false), /* pcrel_offset */
777 HOWTO (R_SH_JMP_SLOT, /* type */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 false, /* pc_relative */
783 complain_overflow_bitfield, /* complain_on_overflow */
784 bfd_elf_generic_reloc, /* */
785 "R_SH_JMP_SLOT", /* name */
786 true, /* partial_inplace */
787 0xffffffff, /* src_mask */
788 0xffffffff, /* dst_mask */
789 false), /* pcrel_offset */
791 HOWTO (R_SH_RELATIVE, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 false, /* pc_relative */
797 complain_overflow_bitfield, /* complain_on_overflow */
798 bfd_elf_generic_reloc, /* */
799 "R_SH_RELATIVE", /* name */
800 true, /* partial_inplace */
801 0xffffffff, /* src_mask */
802 0xffffffff, /* dst_mask */
803 false), /* pcrel_offset */
805 HOWTO (R_SH_GOTOFF, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 false, /* pc_relative */
811 complain_overflow_bitfield, /* complain_on_overflow */
812 bfd_elf_generic_reloc, /* */
813 "R_SH_GOTOFF", /* name */
814 true, /* partial_inplace */
815 0xffffffff, /* src_mask */
816 0xffffffff, /* dst_mask */
817 false), /* pcrel_offset */
819 HOWTO (R_SH_GOTPC, /* type */
821 2, /* size (0 = byte, 1 = short, 2 = long) */
823 true, /* pc_relative */
825 complain_overflow_bitfield, /* complain_on_overflow */
826 bfd_elf_generic_reloc, /* */
827 "R_SH_GOTPC", /* name */
828 true, /* partial_inplace */
829 0xffffffff, /* src_mask */
830 0xffffffff, /* dst_mask */
831 true), /* pcrel_offset */
833 HOWTO (R_SH_GOTPLT32, /* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_bitfield, /* complain_on_overflow */
840 bfd_elf_generic_reloc, /* */
841 "R_SH_GOTPLT32", /* name */
842 false, /* partial_inplace */
843 0xffffffff, /* src_mask */
844 0xffffffff, /* dst_mask */
845 false), /* pcrel_offset */
847 #ifdef INCLUDE_SHMEDIA
848 /* Used in MOVI and SHORI (x & 65536). */
849 HOWTO (R_SH_GOT_LOW16, /* type */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
853 false, /* pc_relative */
855 complain_overflow_dont, /* complain_on_overflow */
856 bfd_elf_generic_reloc, /* special_function */
857 "R_SH_GOT_LOW16", /* name */
858 false, /* partial_inplace */
860 0x3fffc00, /* dst_mask */
861 false), /* pcrel_offset */
863 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
864 HOWTO (R_SH_GOT_MEDLOW16, /* type */
866 2, /* size (0 = byte, 1 = short, 2 = long) */
868 false, /* pc_relative */
870 complain_overflow_dont, /* complain_on_overflow */
871 bfd_elf_generic_reloc, /* special_function */
872 "R_SH_GOT_MEDLOW16", /* name */
873 false, /* partial_inplace */
875 0x3fffc00, /* dst_mask */
876 false), /* pcrel_offset */
878 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
879 HOWTO (R_SH_GOT_MEDHI16, /* type */
881 2, /* size (0 = byte, 1 = short, 2 = long) */
883 false, /* pc_relative */
885 complain_overflow_dont, /* complain_on_overflow */
886 bfd_elf_generic_reloc, /* special_function */
887 "R_SH_GOT_MEDHI16", /* name */
888 false, /* partial_inplace */
890 0x3fffc00, /* dst_mask */
891 false), /* pcrel_offset */
893 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
894 HOWTO (R_SH_GOT_HI16, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 false, /* pc_relative */
900 complain_overflow_dont, /* complain_on_overflow */
901 bfd_elf_generic_reloc, /* special_function */
902 "R_SH_GOT_HI16", /* name */
903 false, /* partial_inplace */
905 0x3fffc00, /* dst_mask */
906 false), /* pcrel_offset */
908 /* Used in MOVI and SHORI (x & 65536). */
909 HOWTO (R_SH_GOTPLT_LOW16, /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 false, /* pc_relative */
915 complain_overflow_dont, /* complain_on_overflow */
916 bfd_elf_generic_reloc, /* special_function */
917 "R_SH_GOTPLT_LOW16", /* name */
918 false, /* partial_inplace */
920 0x3fffc00, /* dst_mask */
921 false), /* pcrel_offset */
923 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
924 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
926 2, /* size (0 = byte, 1 = short, 2 = long) */
928 false, /* pc_relative */
930 complain_overflow_dont, /* complain_on_overflow */
931 bfd_elf_generic_reloc, /* special_function */
932 "R_SH_GOTPLT_MEDLOW16", /* name */
933 false, /* partial_inplace */
935 0x3fffc00, /* dst_mask */
936 false), /* pcrel_offset */
938 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
939 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
941 2, /* size (0 = byte, 1 = short, 2 = long) */
943 false, /* pc_relative */
945 complain_overflow_dont, /* complain_on_overflow */
946 bfd_elf_generic_reloc, /* special_function */
947 "R_SH_GOTPLT_MEDHI16", /* name */
948 false, /* partial_inplace */
950 0x3fffc00, /* dst_mask */
951 false), /* pcrel_offset */
953 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
954 HOWTO (R_SH_GOTPLT_HI16, /* type */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
958 false, /* pc_relative */
960 complain_overflow_dont, /* complain_on_overflow */
961 bfd_elf_generic_reloc, /* special_function */
962 "R_SH_GOTPLT_HI16", /* name */
963 false, /* partial_inplace */
965 0x3fffc00, /* dst_mask */
966 false), /* pcrel_offset */
968 /* Used in MOVI and SHORI (x & 65536). */
969 HOWTO (R_SH_PLT_LOW16, /* type */
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 true, /* pc_relative */
975 complain_overflow_dont, /* complain_on_overflow */
976 bfd_elf_generic_reloc, /* special_function */
977 "R_SH_PLT_LOW16", /* name */
978 false, /* partial_inplace */
980 0x3fffc00, /* dst_mask */
981 true), /* pcrel_offset */
983 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
984 HOWTO (R_SH_PLT_MEDLOW16, /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 true, /* pc_relative */
990 complain_overflow_dont, /* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_SH_PLT_MEDLOW16", /* name */
993 false, /* partial_inplace */
995 0x3fffc00, /* dst_mask */
996 true), /* pcrel_offset */
998 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
999 HOWTO (R_SH_PLT_MEDHI16, /* type */
1000 32, /* rightshift */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 true, /* pc_relative */
1005 complain_overflow_dont, /* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
1007 "R_SH_PLT_MEDHI16", /* name */
1008 false, /* partial_inplace */
1010 0x3fffc00, /* dst_mask */
1011 true), /* pcrel_offset */
1013 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1014 HOWTO (R_SH_PLT_HI16, /* type */
1015 48, /* rightshift */
1016 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 true, /* pc_relative */
1020 complain_overflow_dont, /* complain_on_overflow */
1021 bfd_elf_generic_reloc, /* special_function */
1022 "R_SH_PLT_HI16", /* name */
1023 false, /* partial_inplace */
1025 0x3fffc00, /* dst_mask */
1026 true), /* pcrel_offset */
1028 /* Used in MOVI and SHORI (x & 65536). */
1029 HOWTO (R_SH_GOTOFF_LOW16, /* type */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 false, /* pc_relative */
1035 complain_overflow_dont, /* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_SH_GOTOFF_LOW16", /* name */
1038 false, /* partial_inplace */
1040 0x3fffc00, /* dst_mask */
1041 false), /* pcrel_offset */
1043 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1044 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
1045 16, /* rightshift */
1046 2, /* size (0 = byte, 1 = short, 2 = long) */
1048 false, /* pc_relative */
1050 complain_overflow_dont, /* complain_on_overflow */
1051 bfd_elf_generic_reloc, /* special_function */
1052 "R_SH_GOTOFF_MEDLOW16", /* name */
1053 false, /* partial_inplace */
1055 0x3fffc00, /* dst_mask */
1056 false), /* pcrel_offset */
1058 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1059 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
1060 32, /* rightshift */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 false, /* pc_relative */
1065 complain_overflow_dont, /* complain_on_overflow */
1066 bfd_elf_generic_reloc, /* special_function */
1067 "R_SH_GOTOFF_MEDHI16", /* name */
1068 false, /* partial_inplace */
1070 0x3fffc00, /* dst_mask */
1071 false), /* pcrel_offset */
1073 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1074 HOWTO (R_SH_GOTOFF_HI16, /* type */
1075 48, /* rightshift */
1076 2, /* size (0 = byte, 1 = short, 2 = long) */
1078 false, /* pc_relative */
1080 complain_overflow_dont, /* complain_on_overflow */
1081 bfd_elf_generic_reloc, /* special_function */
1082 "R_SH_GOTOFF_HI16", /* name */
1083 false, /* partial_inplace */
1085 0x3fffc00, /* dst_mask */
1086 false), /* pcrel_offset */
1088 /* Used in MOVI and SHORI (x & 65536). */
1089 HOWTO (R_SH_GOTPC_LOW16, /* type */
1091 2, /* size (0 = byte, 1 = short, 2 = long) */
1093 true, /* pc_relative */
1095 complain_overflow_dont, /* complain_on_overflow */
1096 bfd_elf_generic_reloc, /* special_function */
1097 "R_SH_GOTPC_LOW16", /* name */
1098 false, /* partial_inplace */
1100 0x3fffc00, /* dst_mask */
1101 true), /* pcrel_offset */
1103 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1104 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
1105 16, /* rightshift */
1106 2, /* size (0 = byte, 1 = short, 2 = long) */
1108 true, /* pc_relative */
1110 complain_overflow_dont, /* complain_on_overflow */
1111 bfd_elf_generic_reloc, /* special_function */
1112 "R_SH_GOTPC_MEDLOW16", /* name */
1113 false, /* partial_inplace */
1115 0x3fffc00, /* dst_mask */
1116 true), /* pcrel_offset */
1118 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1119 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
1120 32, /* rightshift */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 true, /* pc_relative */
1125 complain_overflow_dont, /* complain_on_overflow */
1126 bfd_elf_generic_reloc, /* special_function */
1127 "R_SH_GOTPC_MEDHI16", /* name */
1128 false, /* partial_inplace */
1130 0x3fffc00, /* dst_mask */
1131 true), /* pcrel_offset */
1133 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1134 HOWTO (R_SH_GOTPC_HI16, /* type */
1135 48, /* rightshift */
1136 2, /* size (0 = byte, 1 = short, 2 = long) */
1138 true, /* pc_relative */
1140 complain_overflow_dont, /* complain_on_overflow */
1141 bfd_elf_generic_reloc, /* special_function */
1142 "R_SH_GOTPC_HI16", /* name */
1143 false, /* partial_inplace */
1145 0x3fffc00, /* dst_mask */
1146 true), /* pcrel_offset */
1148 /* Used in LD.L, FLD.S et al. */
1149 HOWTO (R_SH_GOT10BY4, /* type */
1151 2, /* size (0 = byte, 1 = short, 2 = long) */
1153 false, /* pc_relative */
1155 complain_overflow_signed, /* complain_on_overflow */
1156 bfd_elf_generic_reloc, /* special_function */
1157 "R_SH_GOT10BY4", /* name */
1158 false, /* partial_inplace */
1160 0xffc00, /* dst_mask */
1161 false), /* pcrel_offset */
1163 /* Used in LD.L, FLD.S et al. */
1164 HOWTO (R_SH_GOTPLT10BY4, /* type */
1166 2, /* size (0 = byte, 1 = short, 2 = long) */
1168 false, /* pc_relative */
1170 complain_overflow_signed, /* complain_on_overflow */
1171 bfd_elf_generic_reloc, /* special_function */
1172 "R_SH_GOTPLT10BY4", /* name */
1173 false, /* partial_inplace */
1175 0xffc00, /* dst_mask */
1176 false), /* pcrel_offset */
1178 /* Used in FLD.D, FST.P et al. */
1179 HOWTO (R_SH_GOT10BY8, /* type */
1181 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 false, /* pc_relative */
1185 complain_overflow_signed, /* complain_on_overflow */
1186 bfd_elf_generic_reloc, /* special_function */
1187 "R_SH_GOT10BY8", /* name */
1188 false, /* partial_inplace */
1190 0xffc00, /* dst_mask */
1191 false), /* pcrel_offset */
1193 /* Used in FLD.D, FST.P et al. */
1194 HOWTO (R_SH_GOTPLT10BY8, /* type */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1198 false, /* pc_relative */
1200 complain_overflow_signed, /* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_SH_GOTPLT10BY8", /* name */
1203 false, /* partial_inplace */
1205 0xffc00, /* dst_mask */
1206 false), /* pcrel_offset */
1208 HOWTO (R_SH_COPY64, /* type */
1210 4, /* size (0 = byte, 1 = short, 2 = long) */
1212 false, /* pc_relative */
1214 complain_overflow_dont, /* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_SH_COPY64", /* name */
1217 false, /* partial_inplace */
1219 ((bfd_vma) 0) - 1, /* dst_mask */
1220 false), /* pcrel_offset */
1222 HOWTO (R_SH_GLOB_DAT64, /* type */
1224 4, /* size (0 = byte, 1 = short, 2 = long) */
1226 false, /* pc_relative */
1228 complain_overflow_dont, /* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_SH_GLOB_DAT64", /* name */
1231 false, /* partial_inplace */
1233 ((bfd_vma) 0) - 1, /* dst_mask */
1234 false), /* pcrel_offset */
1236 HOWTO (R_SH_JMP_SLOT64, /* type */
1238 4, /* size (0 = byte, 1 = short, 2 = long) */
1240 false, /* pc_relative */
1242 complain_overflow_dont, /* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_SH_JMP_SLOT64", /* name */
1245 false, /* partial_inplace */
1247 ((bfd_vma) 0) - 1, /* dst_mask */
1248 false), /* pcrel_offset */
1250 HOWTO (R_SH_RELATIVE64, /* type */
1252 4, /* size (0 = byte, 1 = short, 2 = long) */
1254 false, /* pc_relative */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_SH_RELATIVE64", /* name */
1259 false, /* partial_inplace */
1261 ((bfd_vma) 0) - 1, /* dst_mask */
1262 false), /* pcrel_offset */
1310 /* Relocations for SHmedia code. None of these are partial_inplace or
1311 use the field being relocated (except R_SH_PT_16). */
1313 /* The assembler will generate this reloc before a block of SHmedia
1314 instructions. A section should be processed as assuming it contains
1315 data, unless this reloc is seen. Note that a block of SHcompact
1316 instructions are instead preceded by R_SH_CODE.
1317 This is currently not implemented, but should be used for SHmedia
1318 linker relaxation. */
1319 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1321 1, /* size (0 = byte, 1 = short, 2 = long) */
1323 false, /* pc_relative */
1325 complain_overflow_unsigned, /* complain_on_overflow */
1326 sh_elf_ignore_reloc, /* special_function */
1327 "R_SH_SHMEDIA_CODE", /* name */
1328 false, /* partial_inplace */
1331 false), /* pcrel_offset */
1333 /* The assembler will generate this reloc at a PTA or PTB instruction,
1334 and the linker checks the right type of target, or changes a PTA to a
1335 PTB, if the original insn was PT. */
1336 HOWTO (R_SH_PT_16, /* type */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1340 true, /* pc_relative */
1342 complain_overflow_signed, /* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_SH_PT_16", /* name */
1345 false, /* partial_inplace */
1347 0x3fffc00, /* dst_mask */
1348 true), /* pcrel_offset */
1350 /* Used in unexpanded MOVI. */
1351 HOWTO (R_SH_IMMS16, /* type */
1353 2, /* size (0 = byte, 1 = short, 2 = long) */
1355 false, /* pc_relative */
1357 complain_overflow_signed, /* complain_on_overflow */
1358 bfd_elf_generic_reloc, /* special_function */
1359 "R_SH_IMMS16", /* name */
1360 false, /* partial_inplace */
1362 0x3fffc00, /* dst_mask */
1363 false), /* pcrel_offset */
1365 /* Used in SHORI. */
1366 HOWTO (R_SH_IMMU16, /* type */
1368 2, /* size (0 = byte, 1 = short, 2 = long) */
1370 false, /* pc_relative */
1372 complain_overflow_unsigned, /* complain_on_overflow */
1373 bfd_elf_generic_reloc, /* special_function */
1374 "R_SH_IMMU16", /* name */
1375 false, /* partial_inplace */
1377 0x3fffc00, /* dst_mask */
1378 false), /* pcrel_offset */
1380 /* Used in MOVI and SHORI (x & 65536). */
1381 HOWTO (R_SH_IMM_LOW16, /* type */
1383 2, /* size (0 = byte, 1 = short, 2 = long) */
1385 false, /* pc_relative */
1387 complain_overflow_dont, /* complain_on_overflow */
1388 bfd_elf_generic_reloc, /* special_function */
1389 "R_SH_IMM_LOW16", /* name */
1390 false, /* partial_inplace */
1392 0x3fffc00, /* dst_mask */
1393 false), /* pcrel_offset */
1395 /* Used in MOVI and SHORI ((x - $) & 65536). */
1396 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1398 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 true, /* pc_relative */
1402 complain_overflow_dont, /* complain_on_overflow */
1403 bfd_elf_generic_reloc, /* special_function */
1404 "R_SH_IMM_LOW16_PCREL", /* name */
1405 false, /* partial_inplace */
1407 0x3fffc00, /* dst_mask */
1408 true), /* pcrel_offset */
1410 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1411 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1412 16, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1415 false, /* pc_relative */
1417 complain_overflow_dont, /* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_SH_IMM_MEDLOW16", /* name */
1420 false, /* partial_inplace */
1422 0x3fffc00, /* dst_mask */
1423 false), /* pcrel_offset */
1425 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1426 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1427 16, /* rightshift */
1428 2, /* size (0 = byte, 1 = short, 2 = long) */
1430 true, /* pc_relative */
1432 complain_overflow_dont, /* complain_on_overflow */
1433 bfd_elf_generic_reloc, /* special_function */
1434 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1435 false, /* partial_inplace */
1437 0x3fffc00, /* dst_mask */
1438 true), /* pcrel_offset */
1440 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1441 HOWTO (R_SH_IMM_MEDHI16, /* type */
1442 32, /* rightshift */
1443 2, /* size (0 = byte, 1 = short, 2 = long) */
1445 false, /* pc_relative */
1447 complain_overflow_dont, /* complain_on_overflow */
1448 bfd_elf_generic_reloc, /* special_function */
1449 "R_SH_IMM_MEDHI16", /* name */
1450 false, /* partial_inplace */
1452 0x3fffc00, /* dst_mask */
1453 false), /* pcrel_offset */
1455 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1456 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1457 32, /* rightshift */
1458 2, /* size (0 = byte, 1 = short, 2 = long) */
1460 true, /* pc_relative */
1462 complain_overflow_dont, /* complain_on_overflow */
1463 bfd_elf_generic_reloc, /* special_function */
1464 "R_SH_IMM_MEDHI16_PCREL", /* name */
1465 false, /* partial_inplace */
1467 0x3fffc00, /* dst_mask */
1468 true), /* pcrel_offset */
1470 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1471 HOWTO (R_SH_IMM_HI16, /* type */
1472 48, /* rightshift */
1473 2, /* size (0 = byte, 1 = short, 2 = long) */
1475 false, /* pc_relative */
1477 complain_overflow_dont, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_SH_IMM_HI16", /* name */
1480 false, /* partial_inplace */
1482 0x3fffc00, /* dst_mask */
1483 false), /* pcrel_offset */
1485 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1486 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1487 48, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1490 true, /* pc_relative */
1492 complain_overflow_dont, /* complain_on_overflow */
1493 bfd_elf_generic_reloc, /* special_function */
1494 "R_SH_IMM_HI16_PCREL", /* name */
1495 false, /* partial_inplace */
1497 0x3fffc00, /* dst_mask */
1498 true), /* pcrel_offset */
1500 /* For the .uaquad pseudo. */
1501 HOWTO (R_SH_64, /* type */
1503 4, /* size (0 = byte, 1 = short, 2 = long) */
1505 false, /* pc_relative */
1507 complain_overflow_dont, /* complain_on_overflow */
1508 bfd_elf_generic_reloc, /* special_function */
1509 "R_SH_64", /* name */
1510 false, /* partial_inplace */
1512 ((bfd_vma) 0) - 1, /* dst_mask */
1513 false), /* pcrel_offset */
1515 /* For the .uaquad pseudo, (x - $). */
1516 HOWTO (R_SH_64_PCREL, /* type */
1517 48, /* rightshift */
1518 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 true, /* pc_relative */
1522 complain_overflow_dont, /* complain_on_overflow */
1523 bfd_elf_generic_reloc, /* special_function */
1524 "R_SH_64_PCREL", /* name */
1525 false, /* partial_inplace */
1527 ((bfd_vma) 0) - 1, /* dst_mask */
1528 true), /* pcrel_offset */
1533 static bfd_reloc_status_type
1534 sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,
1535 symbol_section, start, end)
1536 int r_type ATTRIBUTE_UNUSED;
1538 asection *input_section;
1541 asection *symbol_section;
1544 static bfd_vma last_addr;
1545 static asection *last_symbol_section;
1546 bfd_byte *free_contents = NULL;
1547 bfd_byte *start_ptr, *ptr, *last_ptr;
1552 /* Sanity check the address. */
1553 if (addr > input_section->_raw_size)
1554 return bfd_reloc_outofrange;
1556 /* We require the start and end relocations to be processed consecutively -
1557 although we allow then to be processed forwards or backwards. */
1561 last_symbol_section = symbol_section;
1562 return bfd_reloc_ok;
1564 if (last_addr != addr)
1568 if (! symbol_section || last_symbol_section != symbol_section || end < start)
1569 return bfd_reloc_outofrange;
1571 /* Get the symbol_section contents. */
1572 if (symbol_section != input_section)
1574 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
1575 contents = elf_section_data (symbol_section)->this_hdr.contents;
1578 contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
1579 if (contents == NULL)
1580 return bfd_reloc_outofrange;
1581 free_contents = contents;
1582 if (! bfd_get_section_contents (input_bfd, symbol_section, contents,
1584 symbol_section->_raw_size))
1587 return bfd_reloc_outofrange;
1591 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1592 start_ptr = contents + start;
1593 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
1595 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
1598 diff = (last_ptr - ptr) >> 1;
1599 cum_diff += diff & 1;
1602 /* Calculate the start / end values to load into rs / re minus four -
1603 so that will cancel out the four we would otherwise have to add to
1604 addr to get the value to subtract in order to get relative addressing. */
1608 end = (ptr + cum_diff * 2) - contents;
1612 bfd_vma start0 = start - 4;
1614 while (start0 && IS_PPI (contents + start0))
1616 start0 = start - 2 - ((start - start0) & 2);
1617 start = start0 - cum_diff - 2;
1622 free (free_contents);
1624 insn = bfd_get_16 (input_bfd, contents + addr);
1626 x = (insn & 0x200 ? end : start) - addr;
1627 if (input_section != symbol_section)
1628 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
1629 - (input_section->output_section->vma
1630 + input_section->output_offset));
1632 if (x < -128 || x > 127)
1633 return bfd_reloc_overflow;
1635 x = (insn & ~0xff) | (x & 0xff);
1636 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
1638 return bfd_reloc_ok;
1641 /* This function is used for normal relocs. This used to be like the COFF
1642 function, and is almost certainly incorrect for other ELF targets. */
1644 static bfd_reloc_status_type
1645 sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
1648 arelent *reloc_entry;
1651 asection *input_section;
1653 char **error_message ATTRIBUTE_UNUSED;
1657 enum elf_sh_reloc_type r_type;
1658 bfd_vma addr = reloc_entry->address;
1659 bfd_byte *hit_data = addr + (bfd_byte *) data;
1661 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1663 if (output_bfd != NULL)
1665 /* Partial linking--do nothing. */
1666 reloc_entry->address += input_section->output_offset;
1667 return bfd_reloc_ok;
1670 /* Almost all relocs have to do with relaxing. If any work must be
1671 done for them, it has been done in sh_relax_section. */
1672 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
1673 return bfd_reloc_ok;
1675 if (symbol_in != NULL
1676 && bfd_is_und_section (symbol_in->section))
1677 return bfd_reloc_undefined;
1679 if (bfd_is_com_section (symbol_in->section))
1682 sym_value = (symbol_in->value +
1683 symbol_in->section->output_section->vma +
1684 symbol_in->section->output_offset);
1689 insn = bfd_get_32 (abfd, hit_data);
1690 insn += sym_value + reloc_entry->addend;
1691 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
1694 insn = bfd_get_16 (abfd, hit_data);
1695 sym_value += reloc_entry->addend;
1696 sym_value -= (input_section->output_section->vma
1697 + input_section->output_offset
1700 sym_value += (insn & 0xfff) << 1;
1702 sym_value -= 0x1000;
1703 insn = (insn & 0xf000) | (sym_value & 0xfff);
1704 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
1705 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
1706 return bfd_reloc_overflow;
1713 return bfd_reloc_ok;
1716 /* This function is used for relocs which are only used for relaxing,
1717 which the linker should otherwise ignore. */
1719 static bfd_reloc_status_type
1720 sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
1721 output_bfd, error_message)
1722 bfd *abfd ATTRIBUTE_UNUSED;
1723 arelent *reloc_entry;
1724 asymbol *symbol ATTRIBUTE_UNUSED;
1725 PTR data ATTRIBUTE_UNUSED;
1726 asection *input_section;
1728 char **error_message ATTRIBUTE_UNUSED;
1730 if (output_bfd != NULL)
1731 reloc_entry->address += input_section->output_offset;
1732 return bfd_reloc_ok;
1735 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1737 struct elf_reloc_map
1739 bfd_reloc_code_real_type bfd_reloc_val;
1740 unsigned char elf_reloc_val;
1743 /* An array mapping BFD reloc codes to SH ELF relocs. */
1745 static const struct elf_reloc_map sh_reloc_map[] =
1747 { BFD_RELOC_NONE, R_SH_NONE },
1748 { BFD_RELOC_32, R_SH_DIR32 },
1749 { BFD_RELOC_CTOR, R_SH_DIR32 },
1750 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1751 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
1752 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
1753 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
1754 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
1755 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1756 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1757 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1758 { BFD_RELOC_SH_USES, R_SH_USES },
1759 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
1760 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
1761 { BFD_RELOC_SH_CODE, R_SH_CODE },
1762 { BFD_RELOC_SH_DATA, R_SH_DATA },
1763 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
1764 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1765 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1766 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
1767 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
1768 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
1769 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
1770 { BFD_RELOC_SH_COPY, R_SH_COPY },
1771 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
1772 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
1773 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
1774 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
1775 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
1776 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
1777 #ifdef INCLUDE_SHMEDIA
1778 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1779 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1780 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1781 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1782 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1783 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1784 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1785 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1786 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1787 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1788 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1789 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1790 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1791 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1792 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1793 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1794 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1795 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1796 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1797 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1798 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1799 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1800 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1801 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1802 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1803 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1804 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1805 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1806 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1807 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1808 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1809 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1810 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1811 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1812 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1813 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1814 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1815 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1816 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1817 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1818 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1819 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1820 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1821 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1822 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1823 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1824 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1825 { BFD_RELOC_64, R_SH_64 },
1826 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1827 #endif /* not INCLUDE_SHMEDIA */
1830 /* Given a BFD reloc code, return the howto structure for the
1831 corresponding SH ELf reloc. */
1833 static reloc_howto_type *
1834 sh_elf_reloc_type_lookup (abfd, code)
1835 bfd *abfd ATTRIBUTE_UNUSED;
1836 bfd_reloc_code_real_type code;
1840 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
1842 if (sh_reloc_map[i].bfd_reloc_val == code)
1843 return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val];
1849 /* Given an ELF reloc, fill in the howto field of a relent. */
1852 sh_elf_info_to_howto (abfd, cache_ptr, dst)
1853 bfd *abfd ATTRIBUTE_UNUSED;
1855 Elf_Internal_Rela *dst;
1859 r = ELF32_R_TYPE (dst->r_info);
1861 BFD_ASSERT (r < (unsigned int) R_SH_max);
1862 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1863 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
1864 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
1865 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1867 cache_ptr->howto = &sh_elf_howto_table[r];
1870 /* This function handles relaxing for SH ELF. See the corresponding
1871 function in coff-sh.c for a description of what this does. FIXME:
1872 There is a lot of duplication here between this code and the COFF
1873 specific code. The format of relocs and symbols is wound deeply
1874 into this code, but it would still be better if the duplication
1875 could be eliminated somehow. Note in particular that although both
1876 functions use symbols like R_SH_CODE, those symbols have different
1877 values; in coff-sh.c they come from include/coff/sh.h, whereas here
1878 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
1881 sh_elf_relax_section (abfd, sec, link_info, again)
1884 struct bfd_link_info *link_info;
1887 Elf_Internal_Shdr *symtab_hdr;
1888 Elf_Internal_Shdr *shndx_hdr;
1889 Elf_Internal_Rela *internal_relocs;
1890 Elf_Internal_Rela *free_relocs = NULL;
1892 Elf_Internal_Rela *irel, *irelend;
1893 bfd_byte *contents = NULL;
1894 bfd_byte *free_contents = NULL;
1895 Elf32_External_Sym *extsyms = NULL;
1896 Elf32_External_Sym *free_extsyms = NULL;
1897 Elf_External_Sym_Shndx *shndx_buf = NULL;
1901 if (link_info->relocateable
1902 || (sec->flags & SEC_RELOC) == 0
1903 || sec->reloc_count == 0)
1906 #ifdef INCLUDE_SHMEDIA
1907 if (elf_section_data (sec)->this_hdr.sh_flags
1908 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
1914 /* If this is the first time we have been called for this section,
1915 initialize the cooked size. */
1916 if (sec->_cooked_size == 0)
1917 sec->_cooked_size = sec->_raw_size;
1919 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1920 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
1922 internal_relocs = (_bfd_elf32_link_read_relocs
1923 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1924 link_info->keep_memory));
1925 if (internal_relocs == NULL)
1927 if (! link_info->keep_memory)
1928 free_relocs = internal_relocs;
1932 irelend = internal_relocs + sec->reloc_count;
1933 for (irel = internal_relocs; irel < irelend; irel++)
1935 bfd_vma laddr, paddr, symval;
1936 unsigned short insn;
1937 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
1938 bfd_signed_vma foff;
1940 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
1943 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
1946 /* Get the section contents. */
1947 if (contents == NULL)
1949 if (elf_section_data (sec)->this_hdr.contents != NULL)
1950 contents = elf_section_data (sec)->this_hdr.contents;
1953 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
1954 if (contents == NULL)
1956 free_contents = contents;
1958 if (! bfd_get_section_contents (abfd, sec, contents,
1959 (file_ptr) 0, sec->_raw_size))
1964 /* The r_addend field of the R_SH_USES reloc will point us to
1965 the register load. The 4 is because the r_addend field is
1966 computed as though it were a jump offset, which are based
1967 from 4 bytes after the jump instruction. */
1968 laddr = irel->r_offset + 4 + irel->r_addend;
1969 if (laddr >= sec->_raw_size)
1971 (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
1972 bfd_archive_filename (abfd),
1973 (unsigned long) irel->r_offset);
1976 insn = bfd_get_16 (abfd, contents + laddr);
1978 /* If the instruction is not mov.l NN,rN, we don't know what to
1980 if ((insn & 0xf000) != 0xd000)
1982 ((*_bfd_error_handler)
1983 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
1984 bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
1988 /* Get the address from which the register is being loaded. The
1989 displacement in the mov.l instruction is quadrupled. It is a
1990 displacement from four bytes after the movl instruction, but,
1991 before adding in the PC address, two least significant bits
1992 of the PC are cleared. We assume that the section is aligned
1993 on a four byte boundary. */
1994 paddr = insn & 0xff;
1996 paddr += (laddr + 4) &~ (bfd_vma) 3;
1997 if (paddr >= sec->_raw_size)
1999 ((*_bfd_error_handler)
2000 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2001 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2005 /* Get the reloc for the address from which the register is
2006 being loaded. This reloc will tell us which function is
2007 actually being called. */
2008 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2009 if (irelfn->r_offset == paddr
2010 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
2012 if (irelfn >= irelend)
2014 ((*_bfd_error_handler)
2015 (_("%s: 0x%lx: warning: could not find expected reloc"),
2016 bfd_archive_filename (abfd), (unsigned long) paddr));
2020 /* Read this BFD's symbols if we haven't done so already. */
2021 if (extsyms == NULL)
2023 if (symtab_hdr->contents != NULL)
2024 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
2029 amt = symtab_hdr->sh_info;
2030 amt *= sizeof (Elf32_External_Sym);
2031 extsyms = (Elf32_External_Sym *) bfd_malloc (amt);
2032 if (extsyms == NULL)
2034 free_extsyms = extsyms;
2035 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
2036 || bfd_bread ((PTR) extsyms, amt, abfd) != amt)
2038 symtab_hdr->contents = (bfd_byte *) extsyms;
2041 if (shndx_hdr->sh_size != 0)
2045 amt = symtab_hdr->sh_info;
2046 amt *= sizeof (Elf_External_Sym_Shndx);
2047 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
2048 if (shndx_buf == NULL)
2050 if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
2051 || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt)
2053 shndx_hdr->contents = (bfd_byte *) shndx_buf;
2057 /* Get the value of the symbol referred to by the reloc. */
2058 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2060 /* A local symbol. */
2061 Elf32_External_Sym *esym;
2062 Elf_External_Sym_Shndx *shndx;
2063 Elf_Internal_Sym isym;
2065 esym = extsyms + ELF32_R_SYM (irelfn->r_info);
2066 shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irelfn->r_info) : 0);
2067 bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym);
2070 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
2072 ((*_bfd_error_handler)
2073 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2074 bfd_archive_filename (abfd), (unsigned long) paddr));
2078 symval = (isym.st_value
2079 + sec->output_section->vma
2080 + sec->output_offset);
2085 struct elf_link_hash_entry *h;
2087 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
2088 h = elf_sym_hashes (abfd)[indx];
2089 BFD_ASSERT (h != NULL);
2090 if (h->root.type != bfd_link_hash_defined
2091 && h->root.type != bfd_link_hash_defweak)
2093 /* This appears to be a reference to an undefined
2094 symbol. Just ignore it--it will be caught by the
2095 regular reloc processing. */
2099 symval = (h->root.u.def.value
2100 + h->root.u.def.section->output_section->vma
2101 + h->root.u.def.section->output_offset);
2104 symval += bfd_get_32 (abfd, contents + paddr);
2106 /* See if this function call can be shortened. */
2109 + sec->output_section->vma
2110 + sec->output_offset
2112 if (foff < -0x1000 || foff >= 0x1000)
2114 /* After all that work, we can't shorten this function call. */
2118 /* Shorten the function call. */
2120 /* For simplicity of coding, we are going to modify the section
2121 contents, the section relocs, and the BFD symbol table. We
2122 must tell the rest of the code not to free up this
2123 information. It would be possible to instead create a table
2124 of changes which have to be made, as is done in coff-mips.c;
2125 that would be more work, but would require less memory when
2126 the linker is run. */
2128 elf_section_data (sec)->relocs = internal_relocs;
2131 elf_section_data (sec)->this_hdr.contents = contents;
2132 free_contents = NULL;
2134 free_extsyms = NULL;
2136 /* Replace the jsr with a bsr. */
2138 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2139 replace the jsr with a bsr. */
2140 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
2141 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2143 /* If this needs to be changed because of future relaxing,
2144 it will be handled here like other internal IND12W
2147 (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
2148 contents + irel->r_offset);
2152 /* We can't fully resolve this yet, because the external
2153 symbol value may be changed by future relaxing. We let
2154 the final link phase handle it. */
2155 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
2158 /* See if there is another R_SH_USES reloc referring to the same
2160 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2161 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2162 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
2164 if (irelscan < irelend)
2166 /* Some other function call depends upon this register load,
2167 and we have not yet converted that function call.
2168 Indeed, we may never be able to convert it. There is
2169 nothing else we can do at this point. */
2173 /* Look for a R_SH_COUNT reloc on the location where the
2174 function address is stored. Do this before deleting any
2175 bytes, to avoid confusion about the address. */
2176 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2177 if (irelcount->r_offset == paddr
2178 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
2181 /* Delete the register load. */
2182 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
2185 /* That will change things, so, just in case it permits some
2186 other function call to come within range, we should relax
2187 again. Note that this is not required, and it may be slow. */
2190 /* Now check whether we got a COUNT reloc. */
2191 if (irelcount >= irelend)
2193 ((*_bfd_error_handler)
2194 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2195 bfd_archive_filename (abfd), (unsigned long) paddr));
2199 /* The number of uses is stored in the r_addend field. We've
2200 just deleted one. */
2201 if (irelcount->r_addend == 0)
2203 ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
2204 bfd_archive_filename (abfd),
2205 (unsigned long) paddr));
2209 --irelcount->r_addend;
2211 /* If there are no more uses, we can delete the address. Reload
2212 the address from irelfn, in case it was changed by the
2213 previous call to sh_elf_relax_delete_bytes. */
2214 if (irelcount->r_addend == 0)
2216 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
2220 /* We've done all we can with that function call. */
2223 /* Look for load and store instructions that we can align on four
2229 /* Get the section contents. */
2230 if (contents == NULL)
2232 if (elf_section_data (sec)->this_hdr.contents != NULL)
2233 contents = elf_section_data (sec)->this_hdr.contents;
2236 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2237 if (contents == NULL)
2239 free_contents = contents;
2241 if (! bfd_get_section_contents (abfd, sec, contents,
2242 (file_ptr) 0, sec->_raw_size))
2247 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
2253 elf_section_data (sec)->relocs = internal_relocs;
2256 elf_section_data (sec)->this_hdr.contents = contents;
2257 free_contents = NULL;
2259 free_extsyms = NULL;
2263 if (free_relocs != NULL)
2266 if (free_contents != NULL)
2268 if (! link_info->keep_memory)
2269 free (free_contents);
2272 /* Cache the section contents for elf_link_input_bfd. */
2273 elf_section_data (sec)->this_hdr.contents = contents;
2277 if (shndx_buf != NULL)
2279 shndx_hdr->contents = NULL;
2283 if (free_extsyms != NULL)
2285 if (! link_info->keep_memory)
2287 symtab_hdr->contents = NULL;
2288 free (free_extsyms);
2295 if (free_relocs != NULL)
2297 if (free_contents != NULL)
2298 free (free_contents);
2299 if (shndx_buf != NULL)
2301 shndx_hdr->contents = NULL;
2304 if (free_extsyms != NULL)
2306 symtab_hdr->contents = NULL;
2307 free (free_extsyms);
2313 /* Delete some bytes from a section while relaxing. FIXME: There is a
2314 lot of duplication between this function and sh_relax_delete_bytes
2318 sh_elf_relax_delete_bytes (abfd, sec, addr, count)
2324 Elf_Internal_Shdr *symtab_hdr;
2325 Elf_Internal_Shdr *shndx_hdr;
2326 Elf32_External_Sym *extsyms;
2327 unsigned int sec_shndx;
2329 Elf_Internal_Rela *irel, *irelend;
2330 Elf_Internal_Rela *irelalign;
2332 Elf32_External_Sym *esym, *esymend;
2333 Elf_External_Sym_Shndx *shndx_buf, *shndx;
2334 struct elf_link_hash_entry **sym_hashes;
2335 struct elf_link_hash_entry **end_hashes;
2336 unsigned int symcount;
2339 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2340 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
2342 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
2343 shndx_buf = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
2345 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2347 contents = elf_section_data (sec)->this_hdr.contents;
2349 /* The deletion must stop at the next ALIGN reloc for an aligment
2350 power larger than the number of bytes we are deleting. */
2353 toaddr = sec->_cooked_size;
2355 irel = elf_section_data (sec)->relocs;
2356 irelend = irel + sec->reloc_count;
2357 for (; irel < irelend; irel++)
2359 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2360 && irel->r_offset > addr
2361 && count < (1 << irel->r_addend))
2364 toaddr = irel->r_offset;
2369 /* Actually delete the bytes. */
2370 memmove (contents + addr, contents + addr + count,
2371 (size_t) (toaddr - addr - count));
2372 if (irelalign == NULL)
2373 sec->_cooked_size -= count;
2378 #define NOP_OPCODE (0x0009)
2380 BFD_ASSERT ((count & 1) == 0);
2381 for (i = 0; i < count; i += 2)
2382 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
2385 /* Adjust all the relocs. */
2386 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2388 bfd_vma nraddr, stop;
2391 Elf_Internal_Sym sym;
2392 int off, adjust, oinsn;
2393 bfd_signed_vma voff = 0;
2396 /* Get the new reloc address. */
2397 nraddr = irel->r_offset;
2398 if ((irel->r_offset > addr
2399 && irel->r_offset < toaddr)
2400 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2401 && irel->r_offset == toaddr))
2404 /* See if this reloc was for the bytes we have deleted, in which
2405 case we no longer care about it. Don't delete relocs which
2406 represent addresses, though. */
2407 if (irel->r_offset >= addr
2408 && irel->r_offset < addr + count
2409 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
2410 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
2411 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
2412 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
2413 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2416 /* If this is a PC relative reloc, see if the range it covers
2417 includes the bytes we have deleted. */
2418 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2427 start = irel->r_offset;
2428 insn = bfd_get_16 (abfd, contents + nraddr);
2432 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2435 start = stop = addr;
2439 /* If this reloc is against a symbol defined in this
2440 section, and the symbol will not be adjusted below, we
2441 must check the addend to see it will put the value in
2442 range to be adjusted, and hence must be changed. */
2443 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2445 esym = extsyms + ELF32_R_SYM (irel->r_info);
2446 shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irel->r_info) : 0);
2447 bfd_elf32_swap_symbol_in (abfd, esym, shndx, &sym);
2449 if (sym.st_shndx == sec_shndx
2450 && (sym.st_value <= addr
2451 || sym.st_value >= toaddr))
2455 val = bfd_get_32 (abfd, contents + nraddr);
2456 val += sym.st_value;
2457 if (val > addr && val < toaddr)
2458 bfd_put_32 (abfd, val - count, contents + nraddr);
2461 start = stop = addr;
2468 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2472 if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
2473 start = stop = addr;
2479 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2485 stop = start + 4 + off * 2;
2490 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
2496 /* These relocs types represent
2498 The r_addend field holds the difference between the reloc
2499 address and L1. That is the start of the reloc, and
2500 adding in the contents gives us the top. We must adjust
2501 both the r_offset field and the section contents.
2502 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2503 and the elf bfd r_offset is called r_vaddr. */
2505 stop = irel->r_offset;
2506 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
2510 && (stop <= addr || stop >= toaddr))
2511 irel->r_addend += count;
2512 else if (stop > addr
2514 && (start <= addr || start >= toaddr))
2515 irel->r_addend -= count;
2517 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
2518 voff = bfd_get_signed_16 (abfd, contents + nraddr);
2519 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
2520 voff = bfd_get_8 (abfd, contents + nraddr);
2522 voff = bfd_get_signed_32 (abfd, contents + nraddr);
2523 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2528 start = irel->r_offset;
2529 stop = (bfd_vma) ((bfd_signed_vma) start
2530 + (long) irel->r_addend
2537 && (stop <= addr || stop >= toaddr))
2539 else if (stop > addr
2541 && (start <= addr || start >= toaddr))
2550 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2559 if ((oinsn & 0xff00) != (insn & 0xff00))
2561 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2566 if ((oinsn & 0xf000) != (insn & 0xf000))
2568 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2572 BFD_ASSERT (adjust == count || count >= 4);
2577 if ((irel->r_offset & 3) == 0)
2580 if ((oinsn & 0xff00) != (insn & 0xff00))
2582 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2587 if (voff < 0 || voff >= 0xff)
2589 bfd_put_8 (abfd, voff, contents + nraddr);
2594 if (voff < - 0x8000 || voff >= 0x8000)
2596 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
2601 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
2605 irel->r_addend += adjust;
2611 ((*_bfd_error_handler)
2612 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2613 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2614 bfd_set_error (bfd_error_bad_value);
2619 irel->r_offset = nraddr;
2622 /* Look through all the other sections. If there contain any IMM32
2623 relocs against internal symbols which we are not going to adjust
2624 below, we may need to adjust the addends. */
2625 for (o = abfd->sections; o != NULL; o = o->next)
2627 Elf_Internal_Rela *internal_relocs;
2628 Elf_Internal_Rela *irelscan, *irelscanend;
2629 bfd_byte *ocontents;
2632 || (o->flags & SEC_RELOC) == 0
2633 || o->reloc_count == 0)
2636 /* We always cache the relocs. Perhaps, if info->keep_memory is
2637 false, we should free them, if we are permitted to, when we
2638 leave sh_coff_relax_section. */
2639 internal_relocs = (_bfd_elf32_link_read_relocs
2640 (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2642 if (internal_relocs == NULL)
2646 irelscanend = internal_relocs + o->reloc_count;
2647 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
2649 Elf_Internal_Sym sym;
2651 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2652 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
2654 bfd_vma start, stop;
2655 bfd_signed_vma voff;
2657 if (ocontents == NULL)
2659 if (elf_section_data (o)->this_hdr.contents != NULL)
2660 ocontents = elf_section_data (o)->this_hdr.contents;
2663 /* We always cache the section contents.
2664 Perhaps, if info->keep_memory is false, we
2665 should free them, if we are permitted to,
2666 when we leave sh_coff_relax_section. */
2667 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2668 if (ocontents == NULL)
2670 if (! bfd_get_section_contents (abfd, o, ocontents,
2674 elf_section_data (o)->this_hdr.contents = ocontents;
2678 stop = irelscan->r_offset;
2680 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
2682 /* STOP is in a different section, so it won't change. */
2683 if (start > addr && start < toaddr)
2684 irelscan->r_addend += count;
2686 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
2687 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2691 && (stop <= addr || stop >= toaddr))
2692 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
2693 ocontents + irelscan->r_offset);
2694 else if (stop > addr
2696 && (start <= addr || start >= toaddr))
2697 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
2698 ocontents + irelscan->r_offset);
2701 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
2704 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
2708 esym = extsyms + ELF32_R_SYM (irelscan->r_info);
2709 shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irelscan->r_info) : 0);
2710 bfd_elf32_swap_symbol_in (abfd, esym, shndx, &sym);
2712 if (sym.st_shndx == sec_shndx
2713 && (sym.st_value <= addr
2714 || sym.st_value >= toaddr))
2718 if (ocontents == NULL)
2720 if (elf_section_data (o)->this_hdr.contents != NULL)
2721 ocontents = elf_section_data (o)->this_hdr.contents;
2724 /* We always cache the section contents.
2725 Perhaps, if info->keep_memory is false, we
2726 should free them, if we are permitted to,
2727 when we leave sh_coff_relax_section. */
2728 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2729 if (ocontents == NULL)
2731 if (! bfd_get_section_contents (abfd, o, ocontents,
2735 elf_section_data (o)->this_hdr.contents = ocontents;
2739 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2740 val += sym.st_value;
2741 if (val > addr && val < toaddr)
2742 bfd_put_32 (abfd, val - count,
2743 ocontents + irelscan->r_offset);
2748 /* Adjust the local symbols defined in this section. */
2751 esymend = esym + symtab_hdr->sh_info;
2752 for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
2754 Elf_Internal_Sym isym;
2755 Elf_External_Sym_Shndx dummy;
2757 bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym);
2759 if (isym.st_shndx == sec_shndx
2760 && isym.st_value > addr
2761 && isym.st_value < toaddr)
2763 isym.st_value -= count;
2764 bfd_elf32_swap_symbol_out (abfd, &isym, (PTR) esym, (PTR) &dummy);
2768 /* Now adjust the global symbols defined in this section. */
2769 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2770 - symtab_hdr->sh_info);
2771 sym_hashes = elf_sym_hashes (abfd);
2772 end_hashes = sym_hashes + symcount;
2773 for (; sym_hashes < end_hashes; sym_hashes++)
2775 struct elf_link_hash_entry *sym_hash = *sym_hashes;
2776 if ((sym_hash->root.type == bfd_link_hash_defined
2777 || sym_hash->root.type == bfd_link_hash_defweak)
2778 && sym_hash->root.u.def.section == sec
2779 && sym_hash->root.u.def.value > addr
2780 && sym_hash->root.u.def.value < toaddr)
2782 sym_hash->root.u.def.value -= count;
2786 /* See if we can move the ALIGN reloc forward. We have adjusted
2787 r_offset for it already. */
2788 if (irelalign != NULL)
2790 bfd_vma alignto, alignaddr;
2792 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
2793 alignaddr = BFD_ALIGN (irelalign->r_offset,
2794 1 << irelalign->r_addend);
2795 if (alignto != alignaddr)
2797 /* Tail recursion. */
2798 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
2799 (int) (alignto - alignaddr));
2806 /* Look for loads and stores which we can align to four byte
2807 boundaries. This is like sh_align_loads in coff-sh.c. */
2810 sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
2813 Elf_Internal_Rela *internal_relocs;
2817 Elf_Internal_Rela *irel, *irelend;
2818 bfd_vma *labels = NULL;
2819 bfd_vma *label, *label_end;
2824 irelend = internal_relocs + sec->reloc_count;
2826 /* Get all the addresses with labels on them. */
2827 amt = sec->reloc_count;
2828 amt *= sizeof (bfd_vma);
2829 labels = (bfd_vma *) bfd_malloc (amt);
2833 for (irel = internal_relocs; irel < irelend; irel++)
2835 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
2837 *label_end = irel->r_offset;
2842 /* Note that the assembler currently always outputs relocs in
2843 address order. If that ever changes, this code will need to sort
2844 the label values and the relocs. */
2848 for (irel = internal_relocs; irel < irelend; irel++)
2850 bfd_vma start, stop;
2852 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
2855 start = irel->r_offset;
2857 for (irel++; irel < irelend; irel++)
2858 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
2861 stop = irel->r_offset;
2863 stop = sec->_cooked_size;
2865 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
2866 (PTR) internal_relocs, &label,
2867 label_end, start, stop, pswapped))
2881 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2884 sh_elf_swap_insns (abfd, sec, relocs, contents, addr)
2891 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
2892 unsigned short i1, i2;
2893 Elf_Internal_Rela *irel, *irelend;
2895 /* Swap the instructions themselves. */
2896 i1 = bfd_get_16 (abfd, contents + addr);
2897 i2 = bfd_get_16 (abfd, contents + addr + 2);
2898 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2899 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
2901 /* Adjust all reloc addresses. */
2902 irelend = internal_relocs + sec->reloc_count;
2903 for (irel = internal_relocs; irel < irelend; irel++)
2905 enum elf_sh_reloc_type type;
2908 /* There are a few special types of relocs that we don't want to
2909 adjust. These relocs do not apply to the instruction itself,
2910 but are only associated with the address. */
2911 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
2912 if (type == R_SH_ALIGN
2913 || type == R_SH_CODE
2914 || type == R_SH_DATA
2915 || type == R_SH_LABEL)
2918 /* If an R_SH_USES reloc points to one of the addresses being
2919 swapped, we must adjust it. It would be incorrect to do this
2920 for a jump, though, since we want to execute both
2921 instructions after the jump. (We have avoided swapping
2922 around a label, so the jump will not wind up executing an
2923 instruction it shouldn't). */
2924 if (type == R_SH_USES)
2928 off = irel->r_offset + 4 + irel->r_addend;
2930 irel->r_offset += 2;
2931 else if (off == addr + 2)
2932 irel->r_offset -= 2;
2935 if (irel->r_offset == addr)
2937 irel->r_offset += 2;
2940 else if (irel->r_offset == addr + 2)
2942 irel->r_offset -= 2;
2951 unsigned short insn, oinsn;
2954 loc = contents + irel->r_offset;
2963 insn = bfd_get_16 (abfd, loc);
2966 if ((oinsn & 0xff00) != (insn & 0xff00))
2968 bfd_put_16 (abfd, (bfd_vma) insn, loc);
2972 insn = bfd_get_16 (abfd, loc);
2975 if ((oinsn & 0xf000) != (insn & 0xf000))
2977 bfd_put_16 (abfd, (bfd_vma) insn, loc);
2981 /* This reloc ignores the least significant 3 bits of
2982 the program counter before adding in the offset.
2983 This means that if ADDR is at an even address, the
2984 swap will not affect the offset. If ADDR is an at an
2985 odd address, then the instruction will be crossing a
2986 four byte boundary, and must be adjusted. */
2987 if ((addr & 3) != 0)
2989 insn = bfd_get_16 (abfd, loc);
2992 if ((oinsn & 0xff00) != (insn & 0xff00))
2994 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3002 ((*_bfd_error_handler)
3003 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3004 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
3005 bfd_set_error (bfd_error_bad_value);
3014 #ifdef INCLUDE_SHMEDIA
3016 /* The size in bytes of an entry in the procedure linkage table. */
3018 #define PLT_ENTRY_SIZE 64
3020 /* First entry in an absolute procedure linkage table look like this. */
3022 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3024 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3025 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3026 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3027 0x6b, 0xf1, 0x46, 0x00, /* ptabs r17, tr0 */
3028 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3029 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3030 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3031 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3032 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3033 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3034 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3035 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3036 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3037 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3038 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3039 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3042 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3044 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3045 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3046 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3047 0x00, 0x46, 0xf1, 0x6b, /* ptabs r17, tr0 */
3048 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3049 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3050 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3051 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3052 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3053 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3054 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3055 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3056 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3057 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3058 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3059 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3062 /* Sebsequent entries in an absolute procedure linkage table look like
3065 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3067 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3068 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3069 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3070 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3071 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3072 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3073 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3074 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3075 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3076 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3077 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3078 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3079 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3080 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3081 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3082 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3085 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3087 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3088 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3089 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3090 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3091 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3092 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3093 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3094 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3095 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3096 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3097 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3098 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3099 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3100 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3101 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3102 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3105 /* Entries in a PIC procedure linkage table look like this. */
3107 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3109 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3110 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3111 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3112 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3113 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3114 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3115 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3116 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3117 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3118 0x00, 0xca, 0x45, 0x10, /* sub.l r12, r17, r17 */
3119 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3120 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3121 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3122 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3123 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3124 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3127 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3129 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3130 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3131 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3132 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3133 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3134 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3135 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3136 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3137 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3138 0x10, 0x45, 0xca, 0x00, /* sub.l r12, r17, r17 */
3139 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3140 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3141 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3142 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3143 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3144 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3147 static const bfd_byte *elf_sh_plt0_entry;
3148 static const bfd_byte *elf_sh_plt_entry;
3149 static const bfd_byte *elf_sh_pic_plt_entry;
3151 /* Return size of a PLT entry. */
3152 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3154 /* Return offset of the PLT0 address in an absolute PLT entry. */
3155 #define elf_sh_plt_plt0_offset(info) 32
3157 /* Return offset of the linker in PLT0 entry. */
3158 #define elf_sh_plt0_gotplt_offset(info) 0
3160 /* Return offset of the trampoline in PLT entry */
3161 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3163 /* Return offset of the symbol in PLT entry. */
3164 #define elf_sh_plt_symbol_offset(info) 0
3166 /* Return offset of the relocation in PLT entry. */
3167 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3170 movi_shori_putval (output_bfd, value, addr)
3172 unsigned long value;
3175 bfd_put_32 (output_bfd,
3176 bfd_get_32 (output_bfd, addr)
3177 | ((value >> 6) & 0x3fffc00),
3179 bfd_put_32 (output_bfd,
3180 bfd_get_32 (output_bfd, addr + 4)
3181 | ((value << 10) & 0x3fffc00),
3186 /* The size in bytes of an entry in the procedure linkage table. */
3188 #define PLT_ENTRY_SIZE 28
3190 /* First entry in an absolute procedure linkage table look like this. */
3193 /* Note - this code has been "optimised" not to use r2. r2 is used by
3194 GCC to return the address of large strutcures, so it should not be
3195 corrupted here. This does mean however, that this PLT does not conform
3196 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3197 and r2 contains the GOT id. This version stores the GOT id in r0 and
3198 ignores the type. Loaders can easily detect this difference however,
3199 since the type will always be 0 or 8, and the GOT ids will always be
3200 greater than or equal to 12. */
3201 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3203 0xd0, 0x05, /* mov.l 2f,r0 */
3204 0x60, 0x02, /* mov.l @r0,r0 */
3205 0x2f, 0x06, /* mov.l r0,@-r15 */
3206 0xd0, 0x03, /* mov.l 1f,r0 */
3207 0x60, 0x02, /* mov.l @r0,r0 */
3208 0x40, 0x2b, /* jmp @r0 */
3209 0x60, 0xf6, /* mov.l @r15+,r0 */
3210 0x00, 0x09, /* nop */
3211 0x00, 0x09, /* nop */
3212 0x00, 0x09, /* nop */
3213 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3214 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3217 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3219 0x05, 0xd0, /* mov.l 2f,r0 */
3220 0x02, 0x60, /* mov.l @r0,r0 */
3221 0x06, 0x2f, /* mov.l r0,@-r15 */
3222 0x03, 0xd0, /* mov.l 1f,r0 */
3223 0x02, 0x60, /* mov.l @r0,r0 */
3224 0x2b, 0x40, /* jmp @r0 */
3225 0xf6, 0x60, /* mov.l @r15+,r0 */
3226 0x09, 0x00, /* nop */
3227 0x09, 0x00, /* nop */
3228 0x09, 0x00, /* nop */
3229 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3230 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3233 /* Sebsequent entries in an absolute procedure linkage table look like
3236 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3238 0xd0, 0x04, /* mov.l 1f,r0 */
3239 0x60, 0x02, /* mov.l @r0,r0 */
3240 0xd1, 0x02, /* mov.l 0f,r1 */
3241 0x40, 0x2b, /* jmp @r0 */
3242 0x60, 0x13, /* mov r1,r0 */
3243 0xd1, 0x03, /* mov.l 2f,r1 */
3244 0x40, 0x2b, /* jmp @r0 */
3245 0x00, 0x09, /* nop */
3246 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3247 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3248 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3251 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3253 0x04, 0xd0, /* mov.l 1f,r0 */
3254 0x02, 0x60, /* mov.l @r0,r0 */
3255 0x02, 0xd1, /* mov.l 0f,r1 */
3256 0x2b, 0x40, /* jmp @r0 */
3257 0x13, 0x60, /* mov r1,r0 */
3258 0x03, 0xd1, /* mov.l 2f,r1 */
3259 0x2b, 0x40, /* jmp @r0 */
3260 0x09, 0x00, /* nop */
3261 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3262 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3263 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3266 /* Entries in a PIC procedure linkage table look like this. */
3268 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3270 0xd0, 0x04, /* mov.l 1f,r0 */
3271 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3272 0x40, 0x2b, /* jmp @r0 */
3273 0x00, 0x09, /* nop */
3274 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3275 0xd1, 0x03, /* mov.l 2f,r1 */
3276 0x40, 0x2b, /* jmp @r0 */
3277 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3278 0x00, 0x09, /* nop */
3279 0x00, 0x09, /* nop */
3280 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3281 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3284 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3286 0x04, 0xd0, /* mov.l 1f,r0 */
3287 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3288 0x2b, 0x40, /* jmp @r0 */
3289 0x09, 0x00, /* nop */
3290 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3291 0x03, 0xd1, /* mov.l 2f,r1 */
3292 0x2b, 0x40, /* jmp @r0 */
3293 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3294 0x09, 0x00, /* nop */
3295 0x09, 0x00, /* nop */
3296 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3297 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3300 #else /* These are the old style PLT entries. */
3301 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3303 0xd0, 0x04, /* mov.l 1f,r0 */
3304 0xd2, 0x05, /* mov.l 2f,r2 */
3305 0x60, 0x02, /* mov.l @r0,r0 */
3306 0x62, 0x22, /* mov.l @r2,r2 */
3307 0x40, 0x2b, /* jmp @r0 */
3308 0xe0, 0x00, /* mov #0,r0 */
3309 0x00, 0x09, /* nop */
3310 0x00, 0x09, /* nop */
3311 0x00, 0x09, /* nop */
3312 0x00, 0x09, /* nop */
3313 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3314 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3317 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3319 0x04, 0xd0, /* mov.l 1f,r0 */
3320 0x05, 0xd2, /* mov.l 2f,r2 */
3321 0x02, 0x60, /* mov.l @r0,r0 */
3322 0x22, 0x62, /* mov.l @r2,r2 */
3323 0x2b, 0x40, /* jmp @r0 */
3324 0x00, 0xe0, /* mov #0,r0 */
3325 0x09, 0x00, /* nop */
3326 0x09, 0x00, /* nop */
3327 0x09, 0x00, /* nop */
3328 0x09, 0x00, /* nop */
3329 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3330 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3333 /* Sebsequent entries in an absolute procedure linkage table look like
3336 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3338 0xd0, 0x04, /* mov.l 1f,r0 */
3339 0x60, 0x02, /* mov.l @r0,r0 */
3340 0xd2, 0x02, /* mov.l 0f,r2 */
3341 0x40, 0x2b, /* jmp @r0 */
3342 0x60, 0x23, /* mov r2,r0 */
3343 0xd1, 0x03, /* mov.l 2f,r1 */
3344 0x40, 0x2b, /* jmp @r0 */
3345 0x00, 0x09, /* nop */
3346 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3347 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3348 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3351 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3353 0x04, 0xd0, /* mov.l 1f,r0 */
3354 0x02, 0x60, /* mov.l @r0,r0 */
3355 0x02, 0xd2, /* mov.l 0f,r2 */
3356 0x2b, 0x40, /* jmp @r0 */
3357 0x23, 0x60, /* mov r2,r0 */
3358 0x03, 0xd1, /* mov.l 2f,r1 */
3359 0x2b, 0x40, /* jmp @r0 */
3360 0x09, 0x00, /* nop */
3361 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3362 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3363 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3366 /* Entries in a PIC procedure linkage table look like this. */
3368 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3370 0xd0, 0x04, /* mov.l 1f,r0 */
3371 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3372 0x40, 0x2b, /* jmp @r0 */
3373 0x00, 0x09, /* nop */
3374 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3375 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3376 0xd1, 0x02, /* mov.l 2f,r1 */
3377 0x40, 0x2b, /* jmp @r0 */
3378 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3379 0x00, 0x09, /* nop */
3380 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3381 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3384 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3386 0x04, 0xd0, /* mov.l 1f,r0 */
3387 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3388 0x2b, 0x40, /* jmp @r0 */
3389 0x09, 0x00, /* nop */
3390 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3391 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3392 0x02, 0xd1, /* mov.l 2f,r1 */
3393 0x2b, 0x40, /* jmp @r0 */
3394 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3395 0x09, 0x00, /* nop */
3396 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3397 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3399 #endif /* old style PLT entries. */
3401 static const bfd_byte *elf_sh_plt0_entry;
3402 static const bfd_byte *elf_sh_plt_entry;
3403 static const bfd_byte *elf_sh_pic_plt_entry;
3405 /* Return size of a PLT entry. */
3406 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3408 /* Return offset of the PLT0 address in an absolute PLT entry. */
3409 #define elf_sh_plt_plt0_offset(info) 16
3411 /* Return offset of the linker in PLT0 entry. */
3412 #define elf_sh_plt0_linker_offset(info) 20
3414 /* Return offset of the GOT id in PLT0 entry. */
3415 #define elf_sh_plt0_gotid_offset(info) 24
3417 /* Return offset of the tempoline in PLT entry */
3418 #define elf_sh_plt_temp_offset(info) 8
3420 /* Return offset of the symbol in PLT entry. */
3421 #define elf_sh_plt_symbol_offset(info) 20
3423 /* Return offset of the relocation in PLT entry. */
3424 #define elf_sh_plt_reloc_offset(info) 24
3427 /* The sh linker needs to keep track of the number of relocs that it
3428 decides to copy in check_relocs for each symbol. This is so that
3429 it can discard PC relative relocs if it doesn't need them when
3430 linking with -Bsymbolic. We store the information in a field
3431 extending the regular ELF linker hash table. */
3433 /* This structure keeps track of the number of PC relative relocs we
3434 have copied for a given symbol. */
3436 struct elf_sh_pcrel_relocs_copied
3439 struct elf_sh_pcrel_relocs_copied *next;
3440 /* A section in dynobj. */
3442 /* Number of relocs copied in this section. */
3443 bfd_size_type count;
3446 /* sh ELF linker hash entry. */
3448 struct elf_sh_link_hash_entry
3450 struct elf_link_hash_entry root;
3452 #ifdef INCLUDE_SHMEDIA
3453 bfd_vma datalabel_got_offset;
3456 /* Number of PC relative relocs copied for this symbol. */
3457 struct elf_sh_pcrel_relocs_copied *pcrel_relocs_copied;
3460 /* sh ELF linker hash table. */
3462 struct elf_sh_link_hash_table
3464 struct elf_link_hash_table root;
3467 /* Declare this now that the above structures are defined. */
3469 static boolean sh_elf_discard_copies
3470 PARAMS ((struct elf_sh_link_hash_entry *, PTR));
3472 /* Traverse an sh ELF linker hash table. */
3474 #define sh_elf_link_hash_traverse(table, func, info) \
3475 (elf_link_hash_traverse \
3477 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3480 /* Get the sh ELF linker hash table from a link_info structure. */
3482 #define sh_elf_hash_table(p) \
3483 ((struct elf_sh_link_hash_table *) ((p)->hash))
3485 /* Create an entry in an sh ELF linker hash table. */
3487 static struct bfd_hash_entry *
3488 sh_elf_link_hash_newfunc (entry, table, string)
3489 struct bfd_hash_entry *entry;
3490 struct bfd_hash_table *table;
3493 struct elf_sh_link_hash_entry *ret =
3494 (struct elf_sh_link_hash_entry *) entry;
3496 /* Allocate the structure if it has not already been allocated by a
3498 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3499 ret = ((struct elf_sh_link_hash_entry *)
3500 bfd_hash_allocate (table,
3501 sizeof (struct elf_sh_link_hash_entry)));
3502 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3503 return (struct bfd_hash_entry *) ret;
3505 /* Call the allocation method of the superclass. */
3506 ret = ((struct elf_sh_link_hash_entry *)
3507 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3509 if (ret != (struct elf_sh_link_hash_entry *) NULL)
3511 ret->pcrel_relocs_copied = NULL;
3512 #ifdef INCLUDE_SHMEDIA
3513 ret->datalabel_got_offset = (bfd_vma) -1;
3517 return (struct bfd_hash_entry *) ret;
3520 /* Create an sh ELF linker hash table. */
3522 static struct bfd_link_hash_table *
3523 sh_elf_link_hash_table_create (abfd)
3526 struct elf_sh_link_hash_table *ret;
3527 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
3529 ret = (struct elf_sh_link_hash_table *) bfd_alloc (abfd, amt);
3530 if (ret == (struct elf_sh_link_hash_table *) NULL)
3533 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3534 sh_elf_link_hash_newfunc))
3536 bfd_release (abfd, ret);
3540 return &ret->root.root;
3543 /* Create dynamic sections when linking against a dynamic object. */
3546 sh_elf_create_dynamic_sections (abfd, info)
3548 struct bfd_link_info *info;
3550 flagword flags, pltflags;
3551 register asection *s;
3552 struct elf_backend_data *bed = get_elf_backend_data (abfd);
3555 switch (bed->s->arch_size)
3566 bfd_set_error (bfd_error_bad_value);
3570 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3571 .rel[a].bss sections. */
3573 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3574 | SEC_LINKER_CREATED);
3577 pltflags |= SEC_CODE;
3578 if (bed->plt_not_loaded)
3579 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3580 if (bed->plt_readonly)
3581 pltflags |= SEC_READONLY;
3583 s = bfd_make_section (abfd, ".plt");
3585 || ! bfd_set_section_flags (abfd, s, pltflags)
3586 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3589 if (bed->want_plt_sym)
3591 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3593 struct elf_link_hash_entry *h = NULL;
3594 if (! (_bfd_generic_link_add_one_symbol
3595 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3596 (bfd_vma) 0, (const char *) NULL, false,
3597 get_elf_backend_data (abfd)->collect,
3598 (struct bfd_link_hash_entry **) &h)))
3600 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3601 h->type = STT_OBJECT;
3604 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
3608 s = bfd_make_section (abfd,
3609 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3611 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3612 || ! bfd_set_section_alignment (abfd, s, ptralign))
3615 if (! _bfd_elf_create_got_section (abfd, info))
3619 const char *secname;
3624 for (sec = abfd->sections; sec; sec = sec->next)
3626 secflags = bfd_get_section_flags (abfd, sec);
3627 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3628 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3630 secname = bfd_get_section_name (abfd, sec);
3631 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3632 strcpy (relname, ".rela");
3633 strcat (relname, secname);
3634 s = bfd_make_section (abfd, relname);
3636 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3637 || ! bfd_set_section_alignment (abfd, s, ptralign))
3642 if (bed->want_dynbss)
3644 /* The .dynbss section is a place to put symbols which are defined
3645 by dynamic objects, are referenced by regular objects, and are
3646 not functions. We must allocate space for them in the process
3647 image and use a R_*_COPY reloc to tell the dynamic linker to
3648 initialize them at run time. The linker script puts the .dynbss
3649 section into the .bss section of the final image. */
3650 s = bfd_make_section (abfd, ".dynbss");
3652 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3655 /* The .rel[a].bss section holds copy relocs. This section is not
3656 normally needed. We need to create it here, though, so that the
3657 linker will map it to an output section. We can't just create it
3658 only if we need it, because we will not know whether we need it
3659 until we have seen all the input files, and the first time the
3660 main linker code calls BFD after examining all the input files
3661 (size_dynamic_sections) the input sections have already been
3662 mapped to the output sections. If the section turns out not to
3663 be needed, we can discard it later. We will never need this
3664 section when generating a shared object, since they do not use
3668 s = bfd_make_section (abfd,
3669 (bed->default_use_rela_p
3670 ? ".rela.bss" : ".rel.bss"));
3672 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3673 || ! bfd_set_section_alignment (abfd, s, ptralign))
3681 /* Adjust a symbol defined by a dynamic object and referenced by a
3682 regular object. The current definition is in some section of the
3683 dynamic object, but we're not including those sections. We have to
3684 change the definition to something the rest of the link can
3688 sh_elf_adjust_dynamic_symbol (info, h)
3689 struct bfd_link_info *info;
3690 struct elf_link_hash_entry *h;
3694 unsigned int power_of_two;
3696 dynobj = elf_hash_table (info)->dynobj;
3698 /* Make sure we know what is going on here. */
3699 BFD_ASSERT (dynobj != NULL
3700 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
3701 || h->weakdef != NULL
3702 || ((h->elf_link_hash_flags
3703 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3704 && (h->elf_link_hash_flags
3705 & ELF_LINK_HASH_REF_REGULAR) != 0
3706 && (h->elf_link_hash_flags
3707 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3709 /* If this is a function, put it in the procedure linkage table. We
3710 will fill in the contents of the procedure linkage table later,
3711 when we know the address of the .got section. */
3712 if (h->type == STT_FUNC
3713 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3716 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3717 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
3719 /* This case can occur if we saw a PLT reloc in an input
3720 file, but the symbol was never referred to by a dynamic
3721 object. In such a case, we don't actually need to build
3722 a procedure linkage table, and we can just do a REL32
3724 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
3728 /* Make sure this symbol is output as a dynamic symbol. */
3729 if (h->dynindx == -1)
3731 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
3735 s = bfd_get_section_by_name (dynobj, ".plt");
3736 BFD_ASSERT (s != NULL);
3738 /* If this is the first .plt entry, make room for the special
3740 if (s->_raw_size == 0)
3741 s->_raw_size += PLT_ENTRY_SIZE;
3743 /* If this symbol is not defined in a regular file, and we are
3744 not generating a shared library, then set the symbol to this
3745 location in the .plt. This is required to make function
3746 pointers compare as equal between the normal executable and
3747 the shared library. */
3749 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3751 h->root.u.def.section = s;
3752 h->root.u.def.value = s->_raw_size;
3755 h->plt.offset = s->_raw_size;
3757 /* Make room for this entry. */
3758 s->_raw_size += elf_sh_sizeof_plt (info);
3760 /* We also need to make an entry in the .got.plt section, which
3761 will be placed in the .got section by the linker script. */
3763 s = bfd_get_section_by_name (dynobj, ".got.plt");
3764 BFD_ASSERT (s != NULL);
3767 /* We also need to make an entry in the .rela.plt section. */
3769 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3770 BFD_ASSERT (s != NULL);
3771 s->_raw_size += sizeof (Elf32_External_Rela);
3776 /* If this is a weak symbol, and there is a real definition, the
3777 processor independent code will have arranged for us to see the
3778 real definition first, and we can just use the same value. */
3779 if (h->weakdef != NULL)
3781 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3782 || h->weakdef->root.type == bfd_link_hash_defweak);
3783 h->root.u.def.section = h->weakdef->root.u.def.section;
3784 h->root.u.def.value = h->weakdef->root.u.def.value;
3788 /* This is a reference to a symbol defined by a dynamic object which
3789 is not a function. */
3791 /* If we are creating a shared library, we must presume that the
3792 only references to the symbol are via the global offset table.
3793 For such cases we need not do anything here; the relocations will
3794 be handled correctly by relocate_section. */
3798 /* If there are no references to this symbol that do not use the
3799 GOT, we don't need to generate a copy reloc. */
3800 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3803 /* We must allocate the symbol in our .dynbss section, which will
3804 become part of the .bss section of the executable. There will be
3805 an entry for this symbol in the .dynsym section. The dynamic
3806 object will contain position independent code, so all references
3807 from the dynamic object to this symbol will go through the global
3808 offset table. The dynamic linker will use the .dynsym entry to
3809 determine the address it must put in the global offset table, so
3810 both the dynamic object and the regular object will refer to the
3811 same memory location for the variable. */
3813 s = bfd_get_section_by_name (dynobj, ".dynbss");
3814 BFD_ASSERT (s != NULL);
3816 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3817 copy the initial value out of the dynamic object and into the
3818 runtime process image. We need to remember the offset into the
3819 .rela.bss section we are going to use. */
3820 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3824 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
3825 BFD_ASSERT (srel != NULL);
3826 srel->_raw_size += sizeof (Elf32_External_Rela);
3827 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3830 /* We need to figure out the alignment required for this symbol. I
3831 have no idea how ELF linkers handle this. */
3832 power_of_two = bfd_log2 (h->size);
3833 if (power_of_two > 3)
3836 /* Apply the required alignment. */
3837 s->_raw_size = BFD_ALIGN (s->_raw_size,
3838 (bfd_size_type) (1 << power_of_two));
3839 if (power_of_two > bfd_get_section_alignment (dynobj, s))
3841 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
3845 /* Define the symbol as being at this point in the section. */
3846 h->root.u.def.section = s;
3847 h->root.u.def.value = s->_raw_size;
3849 /* Increment the section size to make room for the symbol. */
3850 s->_raw_size += h->size;
3855 /* Set the sizes of the dynamic sections. */
3858 sh_elf_size_dynamic_sections (output_bfd, info)
3859 bfd *output_bfd ATTRIBUTE_UNUSED;
3860 struct bfd_link_info *info;
3867 dynobj = elf_hash_table (info)->dynobj;
3868 BFD_ASSERT (dynobj != NULL);
3870 if (elf_hash_table (info)->dynamic_sections_created)
3872 /* Set the contents of the .interp section to the interpreter. */
3875 s = bfd_get_section_by_name (dynobj, ".interp");
3876 BFD_ASSERT (s != NULL);
3877 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3878 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3883 /* We may have created entries in the .rela.got section.
3884 However, if we are not creating the dynamic sections, we will
3885 not actually use these entries. Reset the size of .rela.got,
3886 which will cause it to get stripped from the output file
3888 s = bfd_get_section_by_name (dynobj, ".rela.got");
3893 /* If this is a -Bsymbolic shared link, then we need to discard all
3894 PC relative relocs against symbols defined in a regular object.
3895 We allocated space for them in the check_relocs routine, but we
3896 will not fill them in in the relocate_section routine. */
3897 if (info->shared && info->symbolic)
3898 sh_elf_link_hash_traverse (sh_elf_hash_table (info),
3899 sh_elf_discard_copies,
3902 /* The check_relocs and adjust_dynamic_symbol entry points have
3903 determined the sizes of the various dynamic sections. Allocate
3907 for (s = dynobj->sections; s != NULL; s = s->next)
3912 if ((s->flags & SEC_LINKER_CREATED) == 0)
3915 /* It's OK to base decisions on the section name, because none
3916 of the dynobj section names depend upon the input files. */
3917 name = bfd_get_section_name (dynobj, s);
3921 if (strcmp (name, ".plt") == 0)
3923 if (s->_raw_size == 0)
3925 /* Strip this section if we don't need it; see the
3931 /* Remember whether there is a PLT. */
3935 else if (strncmp (name, ".rela", 5) == 0)
3937 if (s->_raw_size == 0)
3939 /* If we don't need this section, strip it from the
3940 output file. This is mostly to handle .rela.bss and
3941 .rela.plt. We must create both sections in
3942 create_dynamic_sections, because they must be created
3943 before the linker maps input sections to output
3944 sections. The linker does that before
3945 adjust_dynamic_symbol is called, and it is that
3946 function which decides whether anything needs to go
3947 into these sections. */
3952 /* Remember whether there are any reloc sections other
3954 if (strcmp (name, ".rela.plt") != 0)
3957 /* We use the reloc_count field as a counter if we need
3958 to copy relocs into the output file. */
3962 else if (strncmp (name, ".got", 4) != 0)
3964 /* It's not one of our sections, so don't allocate space. */
3970 _bfd_strip_section_from_output (info, s);
3974 /* Allocate memory for the section contents. */
3975 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
3976 if (s->contents == NULL && s->_raw_size != 0)
3980 if (elf_hash_table (info)->dynamic_sections_created)
3982 /* Add some entries to the .dynamic section. We fill in the
3983 values later, in sh_elf_finish_dynamic_sections, but we
3984 must add the entries now so that we get the correct size for
3985 the .dynamic section. The DT_DEBUG entry is filled in by the
3986 dynamic linker and used by the debugger. */
3987 #define add_dynamic_entry(TAG, VAL) \
3988 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3992 if (!add_dynamic_entry (DT_DEBUG, 0))
3998 if (!add_dynamic_entry (DT_PLTGOT, 0)
3999 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4000 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4001 || !add_dynamic_entry (DT_JMPREL, 0))
4007 if (!add_dynamic_entry (DT_RELA, 0)
4008 || !add_dynamic_entry (DT_RELASZ, 0)
4009 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
4013 if ((info->flags & DF_TEXTREL) != 0)
4015 if (!add_dynamic_entry (DT_TEXTREL, 0))
4019 #undef add_dynamic_entry
4024 /* This function is called via sh_elf_link_hash_traverse if we are
4025 creating a shared object with -Bsymbolic. It discards the space
4026 allocated to copy PC relative relocs against symbols which are
4027 defined in regular objects. We allocated space for them in the
4028 check_relocs routine, but we won't fill them in in the
4029 relocate_section routine. */
4032 sh_elf_discard_copies (h, ignore)
4033 struct elf_sh_link_hash_entry *h;
4034 PTR ignore ATTRIBUTE_UNUSED;
4036 struct elf_sh_pcrel_relocs_copied *s;
4038 /* We only discard relocs for symbols defined in a regular object. */
4039 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4042 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
4043 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
4048 /* Relocate an SH ELF section. */
4051 sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4052 contents, relocs, local_syms, local_sections)
4054 struct bfd_link_info *info;
4056 asection *input_section;
4058 Elf_Internal_Rela *relocs;
4059 Elf_Internal_Sym *local_syms;
4060 asection **local_sections;
4062 Elf_Internal_Shdr *symtab_hdr;
4063 struct elf_link_hash_entry **sym_hashes;
4064 Elf_Internal_Rela *rel, *relend;
4066 bfd_vma *local_got_offsets;
4072 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4073 sym_hashes = elf_sym_hashes (input_bfd);
4074 dynobj = elf_hash_table (info)->dynobj;
4075 local_got_offsets = elf_local_got_offsets (input_bfd);
4083 relend = relocs + input_section->reloc_count;
4084 for (; rel < relend; rel++)
4087 reloc_howto_type *howto;
4088 unsigned long r_symndx;
4089 Elf_Internal_Sym *sym;
4091 struct elf_link_hash_entry *h;
4093 bfd_vma addend = (bfd_vma) 0;
4094 bfd_reloc_status_type r;
4095 int seen_stt_datalabel = 0;
4097 r_symndx = ELF32_R_SYM (rel->r_info);
4099 r_type = ELF32_R_TYPE (rel->r_info);
4101 /* Many of the relocs are only used for relaxing, and are
4102 handled entirely by the relaxation code. */
4103 if (r_type > (int) R_SH_LAST_INVALID_RELOC
4104 && r_type < (int) R_SH_LOOP_START)
4106 if (r_type == (int) R_SH_NONE)
4110 || r_type >= R_SH_max
4111 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
4112 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
4113 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
4114 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4115 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4116 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
4117 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4118 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
4120 bfd_set_error (bfd_error_bad_value);
4124 howto = sh_elf_howto_table + r_type;
4126 /* For relocs that aren't partial_inplace, we get the addend from
4128 if (! howto->partial_inplace)
4129 addend = rel->r_addend;
4134 if (r_symndx < symtab_hdr->sh_info)
4136 sym = local_syms + r_symndx;
4137 sec = local_sections[r_symndx];
4138 relocation = (sec->output_section->vma
4139 + sec->output_offset
4141 /* A local symbol never has STO_SH5_ISA32, so we don't need
4142 datalabel processing here. Make sure this does not change
4144 if ((sym->st_other & STO_SH5_ISA32) != 0)
4145 ((*info->callbacks->reloc_dangerous)
4147 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4148 input_bfd, input_section, rel->r_offset));
4149 if (info->relocateable)
4151 /* This is a relocateable link. We don't have to change
4152 anything, unless the reloc is against a section symbol,
4153 in which case we have to adjust according to where the
4154 section symbol winds up in the output section. */
4155 sym = local_syms + r_symndx;
4156 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4158 if (! howto->partial_inplace)
4160 /* For relocations with the addend in the
4161 relocation, we need just to update the addend.
4162 All real relocs are of type partial_inplace; this
4163 code is mostly for completeness. */
4164 rel->r_addend += sec->output_offset + sym->st_value;
4169 /* Relocs of type partial_inplace need to pick up the
4170 contents in the contents and add the offset resulting
4171 from the changed location of the section symbol.
4172 Using _bfd_final_link_relocate (e.g. goto
4173 final_link_relocate) here would be wrong, because
4174 relocations marked pc_relative would get the current
4175 location subtracted, and we must only do that at the
4177 r = _bfd_relocate_contents (howto, input_bfd,
4180 contents + rel->r_offset);
4181 goto relocation_done;
4186 else if (! howto->partial_inplace)
4188 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4189 addend = rel->r_addend;
4191 else if ((sec->flags & SEC_MERGE)
4192 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4196 if (howto->rightshift || howto->src_mask != 0xffffffff)
4198 (*_bfd_error_handler)
4199 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4200 bfd_archive_filename (input_bfd),
4201 bfd_get_section_name (input_bfd, input_section),
4202 (long) rel->r_offset, howto->name);
4206 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4209 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4211 addend += msec->output_section->vma + msec->output_offset;
4212 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4218 /* Section symbol are never (?) placed in the hash table, so
4219 we can just ignore hash relocations when creating a
4220 relocateable object file. */
4221 if (info->relocateable)
4224 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4225 while (h->root.type == bfd_link_hash_indirect
4226 || h->root.type == bfd_link_hash_warning)
4228 #ifdef INCLUDE_SHMEDIA
4229 /* If the reference passes a symbol marked with
4230 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4232 seen_stt_datalabel |= h->type == STT_DATALABEL;
4234 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4236 if (h->root.type == bfd_link_hash_defined
4237 || h->root.type == bfd_link_hash_defweak)
4239 sec = h->root.u.def.section;
4240 /* In these cases, we don't need the relocation value.
4241 We check specially because in some obscure cases
4242 sec->output_section will be NULL. */
4243 if (r_type == R_SH_GOTPC
4244 || r_type == R_SH_GOTPC_LOW16
4245 || r_type == R_SH_GOTPC_MEDLOW16
4246 || r_type == R_SH_GOTPC_MEDHI16
4247 || r_type == R_SH_GOTPC_HI16
4248 || ((r_type == R_SH_PLT32
4249 || r_type == R_SH_PLT_LOW16
4250 || r_type == R_SH_PLT_MEDLOW16
4251 || r_type == R_SH_PLT_MEDHI16
4252 || r_type == R_SH_PLT_HI16)
4253 && h->plt.offset != (bfd_vma) -1)
4254 || ((r_type == R_SH_GOT32
4255 || r_type == R_SH_GOT_LOW16
4256 || r_type == R_SH_GOT_MEDLOW16
4257 || r_type == R_SH_GOT_MEDHI16
4258 || r_type == R_SH_GOT_HI16)
4259 && elf_hash_table (info)->dynamic_sections_created
4261 || (! info->symbolic && h->dynindx != -1)
4262 || (h->elf_link_hash_flags
4263 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4264 /* The cases above are those in which relocation is
4265 overwritten in the switch block below. The cases
4266 below are those in which we must defer relocation
4267 to run-time, because we can't resolve absolute
4268 addresses when creating a shared library. */
4270 && ((! info->symbolic && h->dynindx != -1)
4271 || (h->elf_link_hash_flags
4272 & ELF_LINK_HASH_DEF_REGULAR) == 0)
4273 && ((r_type == R_SH_DIR32
4274 && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
4275 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
4276 || r_type == R_SH_REL32)
4277 && ((input_section->flags & SEC_ALLOC) != 0
4278 /* DWARF will emit R_SH_DIR32 relocations in its
4279 sections against symbols defined externally
4280 in shared libraries. We can't do anything
4282 || (input_section->flags & SEC_DEBUGGING) != 0)))
4284 else if (sec->output_section == NULL)
4286 (*_bfd_error_handler)
4287 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
4288 bfd_archive_filename (input_bfd), h->root.root.string,
4289 bfd_get_section_name (input_bfd, input_section));
4293 relocation = ((h->root.u.def.value
4294 + sec->output_section->vma
4295 + sec->output_offset)
4296 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4297 symbol value, unless we've seen
4298 STT_DATALABEL on the way to it. */
4299 | ((h->other & STO_SH5_ISA32) != 0
4300 && ! seen_stt_datalabel));
4302 else if (h->root.type == bfd_link_hash_undefweak)
4304 else if (info->shared
4305 && (!info->symbolic || info->allow_shlib_undefined)
4306 && !info->no_undefined)
4310 if (! ((*info->callbacks->undefined_symbol)
4311 (info, h->root.root.string, input_bfd,
4312 input_section, rel->r_offset, true)))
4318 switch ((int) r_type)
4320 final_link_relocate:
4321 /* COFF relocs don't use the addend. The addend is used for
4322 R_SH_DIR32 to be compatible with other compilers. */
4323 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4324 contents, rel->r_offset,
4325 relocation, addend);
4330 goto final_link_relocate;
4335 /* If the reloc is against the start of this section, then
4336 the assembler has already taken care of it and the reloc
4337 is here only to assist in relaxing. If the reloc is not
4338 against the start of this section, then it's against an
4339 external symbol and we must deal with it ourselves. */
4340 if (input_section->output_section->vma + input_section->output_offset
4343 int disp = (relocation
4344 - input_section->output_section->vma
4345 - input_section->output_offset
4351 case R_SH_DIR8WPZ: mask = 1; break;
4352 case R_SH_DIR8WPL: mask = 3; break;
4353 default: mask = 0; break;
4357 ((*_bfd_error_handler)
4358 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4359 bfd_archive_filename (input_section->owner),
4360 (unsigned long) rel->r_offset));
4361 bfd_set_error (bfd_error_bad_value);
4365 goto final_link_relocate;
4371 #ifdef INCLUDE_SHMEDIA
4372 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4373 contents, rel, &relocation))
4374 goto final_link_relocate;
4376 bfd_set_error (bfd_error_bad_value);
4383 && (input_section->flags & SEC_ALLOC) != 0
4384 && (r_type != R_SH_REL32
4387 && (! info->symbolic
4388 || (h->elf_link_hash_flags
4389 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
4391 Elf_Internal_Rela outrel;
4392 boolean skip, relocate;
4394 /* When generating a shared object, these relocations
4395 are copied into the output file to be resolved at run
4402 name = (bfd_elf_string_from_elf_section
4404 elf_elfheader (input_bfd)->e_shstrndx,
4405 elf_section_data (input_section)->rel_hdr.sh_name));
4409 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4410 && strcmp (bfd_get_section_name (input_bfd,
4414 sreloc = bfd_get_section_by_name (dynobj, name);
4415 BFD_ASSERT (sreloc != NULL);
4421 _bfd_elf_section_offset (output_bfd, info, input_section,
4423 if (outrel.r_offset == (bfd_vma) -1)
4425 outrel.r_offset += (input_section->output_section->vma
4426 + input_section->output_offset);
4430 memset (&outrel, 0, sizeof outrel);
4433 else if (r_type == R_SH_REL32)
4435 BFD_ASSERT (h != NULL && h->dynindx != -1);
4437 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4439 = bfd_get_32 (input_bfd, contents + rel->r_offset);
4443 /* h->dynindx may be -1 if this symbol was marked to
4446 || ((info->symbolic || h->dynindx == -1)
4447 && (h->elf_link_hash_flags
4448 & ELF_LINK_HASH_DEF_REGULAR) != 0))
4451 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4453 = relocation + bfd_get_32 (input_bfd,
4454 contents + rel->r_offset);
4458 BFD_ASSERT (h->dynindx != -1);
4460 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4462 = relocation + bfd_get_32 (input_bfd,
4463 contents + rel->r_offset);
4467 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
4468 (((Elf32_External_Rela *)
4470 + sreloc->reloc_count));
4471 ++sreloc->reloc_count;
4473 /* If this reloc is against an external symbol, we do
4474 not want to fiddle with the addend. Otherwise, we
4475 need to include the symbol value so that it becomes
4476 an addend for the dynamic reloc. */
4480 goto final_link_relocate;
4483 #ifdef INCLUDE_SHMEDIA
4484 case R_SH_GOTPLT_LOW16:
4485 case R_SH_GOTPLT_MEDLOW16:
4486 case R_SH_GOTPLT_MEDHI16:
4487 case R_SH_GOTPLT_HI16:
4488 case R_SH_GOTPLT10BY4:
4489 case R_SH_GOTPLT10BY8:
4491 /* Relocation is to the entry for this symbol in the
4492 procedure linkage table. */
4495 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
4496 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
4500 || h->plt.offset == (bfd_vma) -1
4501 || h->got.offset != (bfd_vma) -1)
4504 /* Relocation is to the entry for this symbol in the global
4505 offset table extension for the procedure linkage table. */
4506 if (sgotplt == NULL)
4508 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
4509 BFD_ASSERT (sgotplt != NULL);
4512 relocation = (sgotplt->output_offset
4513 + ((h->plt.offset / elf_sh_sizeof_plt (info)
4517 relocation -= GOT_BIAS;
4520 goto final_link_relocate;
4524 #ifdef INCLUDE_SHMEDIA
4525 case R_SH_GOT_LOW16:
4526 case R_SH_GOT_MEDLOW16:
4527 case R_SH_GOT_MEDHI16:
4532 /* Relocation is to the entry for this symbol in the global
4536 sgot = bfd_get_section_by_name (dynobj, ".got");
4537 BFD_ASSERT (sgot != NULL);
4544 off = h->got.offset;
4545 #ifdef INCLUDE_SHMEDIA
4546 if (seen_stt_datalabel)
4548 struct elf_sh_link_hash_entry *hsh;
4550 hsh = (struct elf_sh_link_hash_entry *)h;
4551 off = hsh->datalabel_got_offset;
4554 BFD_ASSERT (off != (bfd_vma) -1);
4556 if (! elf_hash_table (info)->dynamic_sections_created
4558 && (info->symbolic || h->dynindx == -1
4559 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
4560 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
4561 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
4563 /* This is actually a static link, or it is a
4564 -Bsymbolic link and the symbol is defined
4565 locally, or the symbol was forced to be local
4566 because of a version file. We must initialize
4567 this entry in the global offset table. Since the
4568 offset must always be a multiple of 4, we use the
4569 least significant bit to record whether we have
4570 initialized it already.
4572 When doing a dynamic link, we create a .rela.got
4573 relocation entry to initialize the value. This
4574 is done in the finish_dynamic_symbol routine. */
4579 bfd_put_32 (output_bfd, relocation,
4580 sgot->contents + off);
4581 #ifdef INCLUDE_SHMEDIA
4582 if (seen_stt_datalabel)
4584 struct elf_sh_link_hash_entry *hsh;
4586 hsh = (struct elf_sh_link_hash_entry *)h;
4587 hsh->datalabel_got_offset |= 1;
4595 relocation = sgot->output_offset + off;
4601 #ifdef INCLUDE_SHMEDIA
4604 BFD_ASSERT (local_got_offsets != NULL
4605 && (local_got_offsets[symtab_hdr->sh_info
4609 off = local_got_offsets[symtab_hdr->sh_info
4615 BFD_ASSERT (local_got_offsets != NULL
4616 && local_got_offsets[r_symndx] != (bfd_vma) -1);
4618 off = local_got_offsets[r_symndx];
4619 #ifdef INCLUDE_SHMEDIA
4623 /* The offset must always be a multiple of 4. We use
4624 the least significant bit to record whether we have
4625 already generated the necessary reloc. */
4630 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
4635 Elf_Internal_Rela outrel;
4637 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
4638 BFD_ASSERT (srelgot != NULL);
4640 outrel.r_offset = (sgot->output_section->vma
4641 + sgot->output_offset
4643 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4644 outrel.r_addend = relocation;
4645 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
4646 (((Elf32_External_Rela *)
4648 + srelgot->reloc_count));
4649 ++srelgot->reloc_count;
4652 #ifdef INCLUDE_SHMEDIA
4654 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
4657 local_got_offsets[r_symndx] |= 1;
4660 relocation = sgot->output_offset + off;
4664 relocation -= GOT_BIAS;
4667 goto final_link_relocate;
4670 #ifdef INCLUDE_SHMEDIA
4671 case R_SH_GOTOFF_LOW16:
4672 case R_SH_GOTOFF_MEDLOW16:
4673 case R_SH_GOTOFF_MEDHI16:
4674 case R_SH_GOTOFF_HI16:
4676 /* Relocation is relative to the start of the global offset
4681 sgot = bfd_get_section_by_name (dynobj, ".got");
4682 BFD_ASSERT (sgot != NULL);
4685 /* Note that sgot->output_offset is not involved in this
4686 calculation. We always want the start of .got. If we
4687 defined _GLOBAL_OFFSET_TABLE in a different way, as is
4688 permitted by the ABI, we might have to change this
4690 relocation -= sgot->output_section->vma;
4693 relocation -= GOT_BIAS;
4696 addend = rel->r_addend;
4698 goto final_link_relocate;
4701 #ifdef INCLUDE_SHMEDIA
4702 case R_SH_GOTPC_LOW16:
4703 case R_SH_GOTPC_MEDLOW16:
4704 case R_SH_GOTPC_MEDHI16:
4705 case R_SH_GOTPC_HI16:
4707 /* Use global offset table as symbol value. */
4711 sgot = bfd_get_section_by_name (dynobj, ".got");
4712 BFD_ASSERT (sgot != NULL);
4715 relocation = sgot->output_section->vma;
4718 relocation += GOT_BIAS;
4721 addend = rel->r_addend;
4723 goto final_link_relocate;
4726 #ifdef INCLUDE_SHMEDIA
4727 case R_SH_PLT_LOW16:
4728 case R_SH_PLT_MEDLOW16:
4729 case R_SH_PLT_MEDHI16:
4732 /* Relocation is to the entry for this symbol in the
4733 procedure linkage table. */
4735 /* Resolve a PLT reloc against a local symbol directly,
4736 without using the procedure linkage table. */
4738 goto final_link_relocate;
4740 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
4741 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
4742 goto final_link_relocate;
4744 if (h->plt.offset == (bfd_vma) -1)
4746 /* We didn't make a PLT entry for this symbol. This
4747 happens when statically linking PIC code, or when
4748 using -Bsymbolic. */
4749 goto final_link_relocate;
4754 splt = bfd_get_section_by_name (dynobj, ".plt");
4755 BFD_ASSERT (splt != NULL);
4758 relocation = (splt->output_section->vma
4759 + splt->output_offset
4762 #ifdef INCLUDE_SHMEDIA
4766 addend = rel->r_addend;
4768 goto final_link_relocate;
4770 case R_SH_LOOP_START:
4772 static bfd_vma start, end;
4774 start = (relocation + rel->r_addend
4775 - (sec->output_section->vma + sec->output_offset));
4776 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
4777 rel->r_offset, sec, start, end);
4781 end = (relocation + rel->r_addend
4782 - (sec->output_section->vma + sec->output_offset));
4783 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
4784 rel->r_offset, sec, start, end);
4790 if (r != bfd_reloc_ok)
4795 case bfd_reloc_outofrange:
4797 case bfd_reloc_overflow:
4802 name = h->root.root.string;
4805 name = (bfd_elf_string_from_elf_section
4806 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4810 name = bfd_section_name (input_bfd, sec);
4812 if (! ((*info->callbacks->reloc_overflow)
4813 (info, name, howto->name, (bfd_vma) 0,
4814 input_bfd, input_section, rel->r_offset)))
4825 /* This is a version of bfd_generic_get_relocated_section_contents
4826 which uses sh_elf_relocate_section. */
4829 sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
4830 data, relocateable, symbols)
4832 struct bfd_link_info *link_info;
4833 struct bfd_link_order *link_order;
4835 boolean relocateable;
4838 Elf_Internal_Shdr *symtab_hdr;
4839 Elf_Internal_Shdr *shndx_hdr;
4840 asection *input_section = link_order->u.indirect.section;
4841 bfd *input_bfd = input_section->owner;
4842 asection **sections = NULL;
4843 Elf_Internal_Rela *internal_relocs = NULL;
4844 Elf32_External_Sym *external_syms = NULL;
4845 Elf_External_Sym_Shndx *shndx_buf = NULL;
4846 Elf_External_Sym_Shndx *shndx;
4847 Elf_Internal_Sym *internal_syms = NULL;
4849 /* We only need to handle the case of relaxing, or of having a
4850 particular set of section contents, specially. */
4852 || elf_section_data (input_section)->this_hdr.contents == NULL)
4853 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
4858 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4859 shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
4861 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
4862 (size_t) input_section->_raw_size);
4864 if ((input_section->flags & SEC_RELOC) != 0
4865 && input_section->reloc_count > 0)
4867 Elf_Internal_Sym *isymp;
4869 Elf32_External_Sym *esym, *esymend;
4872 if (symtab_hdr->contents != NULL)
4873 external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
4874 else if (symtab_hdr->sh_info != 0)
4876 amt = symtab_hdr->sh_info;
4877 amt *= sizeof (Elf32_External_Sym);
4878 external_syms = (Elf32_External_Sym *) bfd_malloc (amt);
4879 if (external_syms == NULL)
4881 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
4882 || bfd_bread ((PTR) external_syms, amt, input_bfd) != amt)
4886 if (symtab_hdr->sh_info != 0 && shndx_hdr->sh_size != 0)
4888 amt = symtab_hdr->sh_info;
4889 amt *= sizeof (Elf_External_Sym_Shndx);
4890 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
4891 if (shndx_buf == NULL)
4893 if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
4894 || bfd_bread ((PTR) shndx_buf, amt, input_bfd) != amt)
4898 internal_relocs = (_bfd_elf32_link_read_relocs
4899 (input_bfd, input_section, (PTR) NULL,
4900 (Elf_Internal_Rela *) NULL, false));
4901 if (internal_relocs == NULL)
4904 amt = symtab_hdr->sh_info;
4905 amt *= sizeof (Elf_Internal_Sym);
4906 internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
4907 if (internal_syms == NULL && amt != 0)
4910 amt = symtab_hdr->sh_info;
4911 amt *= sizeof (asection *);
4912 sections = (asection **) bfd_malloc (amt);
4913 if (sections == NULL && amt != 0)
4916 for (isymp = internal_syms, secpp = sections, shndx = shndx_buf,
4917 esym = external_syms, esymend = esym + symtab_hdr->sh_info;
4919 ++esym, ++isymp, ++secpp, shndx = (shndx ? shndx + 1 : NULL))
4923 bfd_elf32_swap_symbol_in (input_bfd, esym, shndx, isymp);
4925 if (isymp->st_shndx == SHN_UNDEF)
4926 isec = bfd_und_section_ptr;
4927 else if (isymp->st_shndx == SHN_ABS)
4928 isec = bfd_abs_section_ptr;
4929 else if (isymp->st_shndx == SHN_COMMON)
4930 isec = bfd_com_section_ptr;
4932 isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
4937 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
4938 input_section, data, internal_relocs,
4939 internal_syms, sections))
4942 if (sections != NULL)
4944 if (internal_syms != NULL)
4945 free (internal_syms);
4946 if (shndx_buf != NULL)
4948 if (external_syms != NULL && symtab_hdr->contents == NULL)
4949 free (external_syms);
4950 if (internal_relocs != elf_section_data (input_section)->relocs)
4951 free (internal_relocs);
4957 if (internal_relocs != NULL
4958 && internal_relocs != elf_section_data (input_section)->relocs)
4959 free (internal_relocs);
4960 if (shndx_buf != NULL)
4962 if (external_syms != NULL && symtab_hdr->contents == NULL)
4963 free (external_syms);
4964 if (internal_syms != NULL)
4965 free (internal_syms);
4966 if (sections != NULL)
4972 sh_elf_gc_mark_hook (abfd, info, rel, h, sym)
4974 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4975 Elf_Internal_Rela *rel;
4976 struct elf_link_hash_entry *h;
4977 Elf_Internal_Sym *sym;
4981 switch (ELF32_R_TYPE (rel->r_info))
4983 case R_SH_GNU_VTINHERIT:
4984 case R_SH_GNU_VTENTRY:
4988 switch (h->root.type)
4990 case bfd_link_hash_defined:
4991 case bfd_link_hash_defweak:
4992 return h->root.u.def.section;
4994 case bfd_link_hash_common:
4995 return h->root.u.c.p->section;
5004 return bfd_section_from_elf_index (abfd, sym->st_shndx);
5010 /* Update the got entry reference counts for the section being removed. */
5013 sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
5014 bfd *abfd ATTRIBUTE_UNUSED;
5015 struct bfd_link_info *info ATTRIBUTE_UNUSED;
5016 asection *sec ATTRIBUTE_UNUSED;
5017 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
5019 /* We use got and plt entries for sh, but it would seem that the
5020 existing SH code does no sort of reference counting or whatnot on
5021 its GOT and PLT entries, so it is not possible to garbage collect
5022 them at this time. */
5026 /* Look through the relocs for a section during the first phase.
5027 Since we don't do .gots or .plts, we just need to consider the
5028 virtual table relocs for gc. */
5031 sh_elf_check_relocs (abfd, info, sec, relocs)
5033 struct bfd_link_info *info;
5035 const Elf_Internal_Rela *relocs;
5037 Elf_Internal_Shdr *symtab_hdr;
5038 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
5039 const Elf_Internal_Rela *rel;
5040 const Elf_Internal_Rela *rel_end;
5042 bfd_vma *local_got_offsets;
5051 if (info->relocateable)
5054 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5055 sym_hashes = elf_sym_hashes (abfd);
5056 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
5057 if (!elf_bad_symtab (abfd))
5058 sym_hashes_end -= symtab_hdr->sh_info;
5060 dynobj = elf_hash_table (info)->dynobj;
5061 local_got_offsets = elf_local_got_offsets (abfd);
5063 rel_end = relocs + sec->reloc_count;
5064 for (rel = relocs; rel < rel_end; rel++)
5066 struct elf_link_hash_entry *h;
5067 unsigned long r_symndx;
5069 r_symndx = ELF32_R_SYM (rel->r_info);
5070 if (r_symndx < symtab_hdr->sh_info)
5073 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5075 /* Some relocs require a global offset table. */
5078 switch (ELF32_R_TYPE (rel->r_info))
5084 #ifdef INCLUDE_SHMEDIA
5085 case R_SH_GOTPLT_LOW16:
5086 case R_SH_GOTPLT_MEDLOW16:
5087 case R_SH_GOTPLT_MEDHI16:
5088 case R_SH_GOTPLT_HI16:
5089 case R_SH_GOTPLT10BY4:
5090 case R_SH_GOTPLT10BY8:
5091 case R_SH_GOT_LOW16:
5092 case R_SH_GOT_MEDLOW16:
5093 case R_SH_GOT_MEDHI16:
5097 case R_SH_GOTOFF_LOW16:
5098 case R_SH_GOTOFF_MEDLOW16:
5099 case R_SH_GOTOFF_MEDHI16:
5100 case R_SH_GOTOFF_HI16:
5101 case R_SH_GOTPC_LOW16:
5102 case R_SH_GOTPC_MEDLOW16:
5103 case R_SH_GOTPC_MEDHI16:
5104 case R_SH_GOTPC_HI16:
5106 elf_hash_table (info)->dynobj = dynobj = abfd;
5107 if (! _bfd_elf_create_got_section (dynobj, info))
5116 switch (ELF32_R_TYPE (rel->r_info))
5118 /* This relocation describes the C++ object vtable hierarchy.
5119 Reconstruct it for later use during GC. */
5120 case R_SH_GNU_VTINHERIT:
5121 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5125 /* This relocation describes which C++ vtable entries are actually
5126 used. Record for later use during GC. */
5127 case R_SH_GNU_VTENTRY:
5128 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5134 #ifdef INCLUDE_SHMEDIA
5135 case R_SH_GOT_LOW16:
5136 case R_SH_GOT_MEDLOW16:
5137 case R_SH_GOT_MEDHI16:
5142 /* This symbol requires a global offset table entry. */
5146 sgot = bfd_get_section_by_name (dynobj, ".got");
5147 BFD_ASSERT (sgot != NULL);
5151 && (h != NULL || info->shared))
5153 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5154 if (srelgot == NULL)
5156 srelgot = bfd_make_section (dynobj, ".rela.got");
5158 || ! bfd_set_section_flags (dynobj, srelgot,
5163 | SEC_LINKER_CREATED
5165 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
5172 #ifdef INCLUDE_SHMEDIA
5173 if (h->type == STT_DATALABEL)
5175 struct elf_sh_link_hash_entry *hsh;
5177 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5178 hsh = (struct elf_sh_link_hash_entry *)h;
5179 if (hsh->datalabel_got_offset != (bfd_vma) -1)
5182 hsh->datalabel_got_offset = sgot->_raw_size;
5187 if (h->got.offset != (bfd_vma) -1)
5189 /* We have already allocated space in the .got. */
5192 h->got.offset = sgot->_raw_size;
5193 #ifdef INCLUDE_SHMEDIA
5197 /* Make sure this symbol is output as a dynamic symbol. */
5198 if (h->dynindx == -1)
5200 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
5204 srelgot->_raw_size += sizeof (Elf32_External_Rela);
5208 /* This is a global offset table entry for a local
5210 if (local_got_offsets == NULL)
5213 register unsigned int i;
5215 size = symtab_hdr->sh_info;
5216 size *= sizeof (bfd_vma);
5217 #ifdef INCLUDE_SHMEDIA
5218 /* Reserve space for both the datalabel and
5219 codelabel local GOT offsets. */
5222 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
5223 if (local_got_offsets == NULL)
5225 elf_local_got_offsets (abfd) = local_got_offsets;
5226 for (i = 0; i < symtab_hdr->sh_info; i++)
5227 local_got_offsets[i] = (bfd_vma) -1;
5228 #ifdef INCLUDE_SHMEDIA
5229 for (; i < 2 * symtab_hdr->sh_info; i++)
5230 local_got_offsets[i] = (bfd_vma) -1;
5233 #ifdef INCLUDE_SHMEDIA
5234 if ((rel->r_addend & 1) != 0)
5236 if (local_got_offsets[symtab_hdr->sh_info
5237 + r_symndx] != (bfd_vma) -1)
5239 /* We have already allocated space in the .got. */
5242 local_got_offsets[symtab_hdr->sh_info
5243 + r_symndx] = sgot->_raw_size;
5248 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
5250 /* We have already allocated space in the .got. */
5253 local_got_offsets[r_symndx] = sgot->_raw_size;
5254 #ifdef INCLUDE_SHMEDIA
5260 /* If we are generating a shared object, we need to
5261 output a R_SH_RELATIVE reloc so that the dynamic
5262 linker can adjust this GOT entry. */
5263 srelgot->_raw_size += sizeof (Elf32_External_Rela);
5267 sgot->_raw_size += 4;
5272 #ifdef INCLUDE_SHMEDIA
5273 case R_SH_GOTPLT_LOW16:
5274 case R_SH_GOTPLT_MEDLOW16:
5275 case R_SH_GOTPLT_MEDHI16:
5276 case R_SH_GOTPLT_HI16:
5277 case R_SH_GOTPLT10BY4:
5278 case R_SH_GOTPLT10BY8:
5280 /* If this is a local symbol, we resolve it directly without
5281 creating a procedure linkage table entry. */
5284 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
5285 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
5289 || h->got.offset != (bfd_vma) -1)
5292 /* Make sure this symbol is output as a dynamic symbol. */
5293 if (h->dynindx == -1)
5295 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
5299 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
5304 #ifdef INCLUDE_SHMEDIA
5305 case R_SH_PLT_LOW16:
5306 case R_SH_PLT_MEDLOW16:
5307 case R_SH_PLT_MEDHI16:
5310 /* This symbol requires a procedure linkage table entry. We
5311 actually build the entry in adjust_dynamic_symbol,
5312 because this might be a case of linking PIC code which is
5313 never referenced by a dynamic object, in which case we
5314 don't need to generate a procedure linkage table entry
5317 /* If this is a local symbol, we resolve it directly without
5318 creating a procedure linkage table entry. */
5322 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
5323 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
5326 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
5333 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
5335 /* If we are creating a shared library, and this is a reloc
5336 against a global symbol, or a non PC relative reloc
5337 against a local symbol, then we need to copy the reloc
5338 into the shared library. However, if we are linking with
5339 -Bsymbolic, we do not need to copy a reloc against a
5340 global symbol which is defined in an object we are
5341 including in the link (i.e., DEF_REGULAR is set). At
5342 this point we have not seen all the input files, so it is
5343 possible that DEF_REGULAR is not set now but will be set
5344 later (it is never cleared). We account for that
5345 possibility below by storing information in the
5346 pcrel_relocs_copied field of the hash table entry. */
5348 && (sec->flags & SEC_ALLOC) != 0
5349 && (ELF32_R_TYPE (rel->r_info) != R_SH_REL32
5351 && (! info->symbolic
5352 || (h->elf_link_hash_flags
5353 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
5355 /* When creating a shared object, we must copy these
5356 reloc types into the output file. We create a reloc
5357 section in dynobj and make room for this reloc. */
5362 name = (bfd_elf_string_from_elf_section
5364 elf_elfheader (abfd)->e_shstrndx,
5365 elf_section_data (sec)->rel_hdr.sh_name));
5369 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5370 && strcmp (bfd_get_section_name (abfd, sec),
5373 sreloc = bfd_get_section_by_name (dynobj, name);
5378 sreloc = bfd_make_section (dynobj, name);
5379 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5380 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5381 if ((sec->flags & SEC_ALLOC) != 0)
5382 flags |= SEC_ALLOC | SEC_LOAD;
5384 || ! bfd_set_section_flags (dynobj, sreloc, flags)
5385 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
5388 if (sec->flags & SEC_READONLY)
5389 info->flags |= DF_TEXTREL;
5392 sreloc->_raw_size += sizeof (Elf32_External_Rela);
5394 /* If we are linking with -Bsymbolic, and this is a
5395 global symbol, we count the number of PC relative
5396 relocations we have entered for this symbol, so that
5397 we can discard them again if the symbol is later
5398 defined by a regular object. Note that this function
5399 is only called if we are using an elf_sh linker
5400 hash table, which means that h is really a pointer to
5401 an elf_sh_link_hash_entry. */
5402 if (h != NULL && info->symbolic
5403 && ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
5405 struct elf_sh_link_hash_entry *eh;
5406 struct elf_sh_pcrel_relocs_copied *p;
5408 eh = (struct elf_sh_link_hash_entry *) h;
5410 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
5411 if (p->section == sreloc)
5416 p = ((struct elf_sh_pcrel_relocs_copied *)
5417 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
5420 p->next = eh->pcrel_relocs_copied;
5421 eh->pcrel_relocs_copied = p;
5422 p->section = sreloc;
5437 #ifndef sh_elf_set_mach_from_flags
5439 sh_elf_set_mach_from_flags (abfd)
5442 flagword flags = elf_elfheader (abfd)->e_flags;
5444 switch (flags & EF_SH_MACH_MASK)
5447 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh);
5450 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
5453 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);
5456 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3);
5459 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp);
5462 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e);
5466 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);
5473 #endif /* not sh_elf_set_mach_from_flags */
5475 #ifndef sh_elf_set_private_flags
5476 /* Function to keep SH specific file flags. */
5479 sh_elf_set_private_flags (abfd, flags)
5483 BFD_ASSERT (! elf_flags_init (abfd)
5484 || elf_elfheader (abfd)->e_flags == flags);
5486 elf_elfheader (abfd)->e_flags = flags;
5487 elf_flags_init (abfd) = true;
5488 return sh_elf_set_mach_from_flags (abfd);
5490 #endif /* not sh_elf_set_private_flags */
5492 #ifndef sh_elf_copy_private_data
5493 /* Copy backend specific data from one object module to another */
5496 sh_elf_copy_private_data (ibfd, obfd)
5500 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5501 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5504 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
5506 #endif /* not sh_elf_copy_private_data */
5508 #ifndef sh_elf_merge_private_data
5509 /* This routine checks for linking big and little endian objects
5510 together, and for linking sh-dsp with sh3e / sh4 objects. */
5513 sh_elf_merge_private_data (ibfd, obfd)
5517 flagword old_flags, new_flags;
5519 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
5522 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5523 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5526 if (! elf_flags_init (obfd))
5528 /* This happens when ld starts out with a 'blank' output file. */
5529 elf_flags_init (obfd) = true;
5530 elf_elfheader (obfd)->e_flags = EF_SH1;
5532 old_flags = elf_elfheader (obfd)->e_flags;
5533 new_flags = elf_elfheader (ibfd)->e_flags;
5534 if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags))
5535 || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags)))
5537 (*_bfd_error_handler)
5538 ("%s: uses %s instructions while previous modules use %s instructions",
5539 bfd_archive_filename (ibfd),
5540 EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",
5541 EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");
5542 bfd_set_error (bfd_error_bad_value);
5545 elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);
5547 return sh_elf_set_mach_from_flags (obfd);
5549 #endif /* not sh_elf_merge_private_data */
5551 /* Finish up dynamic symbol handling. We set the contents of various
5552 dynamic sections here. */
5555 sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5557 struct bfd_link_info *info;
5558 struct elf_link_hash_entry *h;
5559 Elf_Internal_Sym *sym;
5563 dynobj = elf_hash_table (info)->dynobj;
5565 if (h->plt.offset != (bfd_vma) -1)
5573 Elf_Internal_Rela rel;
5575 /* This symbol has an entry in the procedure linkage table. Set
5578 BFD_ASSERT (h->dynindx != -1);
5580 splt = bfd_get_section_by_name (dynobj, ".plt");
5581 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
5582 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
5583 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
5585 /* Get the index in the procedure linkage table which
5586 corresponds to this symbol. This is the index of this symbol
5587 in all the symbols for which we are making plt entries. The
5588 first entry in the procedure linkage table is reserved. */
5589 plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1;
5591 /* Get the offset into the .got table of the entry that
5592 corresponds to this function. Each .got entry is 4 bytes.
5593 The first three are reserved. */
5594 got_offset = (plt_index + 3) * 4;
5597 got_offset -= GOT_BIAS;
5600 /* Fill in the entry in the procedure linkage table. */
5603 if (elf_sh_plt_entry == NULL)
5605 elf_sh_plt_entry = (bfd_big_endian (output_bfd) ?
5606 elf_sh_plt_entry_be : elf_sh_plt_entry_le);
5608 memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
5609 elf_sh_sizeof_plt (info));
5610 #ifdef INCLUDE_SHMEDIA
5611 movi_shori_putval (output_bfd,
5612 (sgot->output_section->vma
5613 + sgot->output_offset
5615 (splt->contents + h->plt.offset
5616 + elf_sh_plt_symbol_offset (info)));
5618 movi_shori_putval (output_bfd,
5619 (splt->output_section->vma + splt->output_offset),
5620 (splt->contents + h->plt.offset
5621 + elf_sh_plt_plt0_offset (info)));
5623 bfd_put_32 (output_bfd,
5624 (sgot->output_section->vma
5625 + sgot->output_offset
5627 (splt->contents + h->plt.offset
5628 + elf_sh_plt_symbol_offset (info)));
5630 bfd_put_32 (output_bfd,
5631 (splt->output_section->vma + splt->output_offset),
5632 (splt->contents + h->plt.offset
5633 + elf_sh_plt_plt0_offset (info)));
5638 if (elf_sh_pic_plt_entry == NULL)
5640 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
5641 elf_sh_pic_plt_entry_be :
5642 elf_sh_pic_plt_entry_le);
5644 memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
5645 elf_sh_sizeof_plt (info));
5646 #ifdef INCLUDE_SHMEDIA
5647 movi_shori_putval (output_bfd, got_offset,
5648 (splt->contents + h->plt.offset
5649 + elf_sh_plt_symbol_offset (info)));
5651 bfd_put_32 (output_bfd, got_offset,
5652 (splt->contents + h->plt.offset
5653 + elf_sh_plt_symbol_offset (info)));
5658 got_offset += GOT_BIAS;
5661 #ifdef INCLUDE_SHMEDIA
5662 movi_shori_putval (output_bfd,
5663 plt_index * sizeof (Elf32_External_Rela),
5664 (splt->contents + h->plt.offset
5665 + elf_sh_plt_reloc_offset (info)));
5667 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
5668 (splt->contents + h->plt.offset
5669 + elf_sh_plt_reloc_offset (info)));
5672 /* Fill in the entry in the global offset table. */
5673 bfd_put_32 (output_bfd,
5674 (splt->output_section->vma
5675 + splt->output_offset
5677 + elf_sh_plt_temp_offset (info)),
5678 sgot->contents + got_offset);
5680 /* Fill in the entry in the .rela.plt section. */
5681 rel.r_offset = (sgot->output_section->vma
5682 + sgot->output_offset
5684 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
5687 rel.r_addend = GOT_BIAS;
5689 bfd_elf32_swap_reloca_out (output_bfd, &rel,
5690 ((Elf32_External_Rela *) srel->contents
5693 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
5695 /* Mark the symbol as undefined, rather than as defined in
5696 the .plt section. Leave the value alone. */
5697 sym->st_shndx = SHN_UNDEF;
5701 if (h->got.offset != (bfd_vma) -1)
5705 Elf_Internal_Rela rel;
5707 /* This symbol has an entry in the global offset table. Set it
5710 sgot = bfd_get_section_by_name (dynobj, ".got");
5711 srel = bfd_get_section_by_name (dynobj, ".rela.got");
5712 BFD_ASSERT (sgot != NULL && srel != NULL);
5714 rel.r_offset = (sgot->output_section->vma
5715 + sgot->output_offset
5716 + (h->got.offset &~ (bfd_vma) 1));
5718 /* If this is a -Bsymbolic link, and the symbol is defined
5719 locally, we just want to emit a RELATIVE reloc. Likewise if
5720 the symbol was forced to be local because of a version file.
5721 The entry in the global offset table will already have been
5722 initialized in the relocate_section function. */
5724 && (info->symbolic || h->dynindx == -1)
5725 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5727 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5728 rel.r_addend = (h->root.u.def.value
5729 + h->root.u.def.section->output_section->vma
5730 + h->root.u.def.section->output_offset);
5734 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
5735 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
5739 bfd_elf32_swap_reloca_out (output_bfd, &rel,
5740 ((Elf32_External_Rela *) srel->contents
5741 + srel->reloc_count));
5742 ++srel->reloc_count;
5745 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
5748 Elf_Internal_Rela rel;
5750 /* This symbol needs a copy reloc. Set it up. */
5752 BFD_ASSERT (h->dynindx != -1
5753 && (h->root.type == bfd_link_hash_defined
5754 || h->root.type == bfd_link_hash_defweak));
5756 s = bfd_get_section_by_name (h->root.u.def.section->owner,
5758 BFD_ASSERT (s != NULL);
5760 rel.r_offset = (h->root.u.def.value
5761 + h->root.u.def.section->output_section->vma
5762 + h->root.u.def.section->output_offset);
5763 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
5765 bfd_elf32_swap_reloca_out (output_bfd, &rel,
5766 ((Elf32_External_Rela *) s->contents
5771 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5772 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5773 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
5774 sym->st_shndx = SHN_ABS;
5779 /* Finish up the dynamic sections. */
5782 sh_elf_finish_dynamic_sections (output_bfd, info)
5784 struct bfd_link_info *info;
5790 dynobj = elf_hash_table (info)->dynobj;
5792 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
5793 BFD_ASSERT (sgot != NULL);
5794 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5796 if (elf_hash_table (info)->dynamic_sections_created)
5799 Elf32_External_Dyn *dyncon, *dynconend;
5801 BFD_ASSERT (sdyn != NULL);
5803 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5804 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5805 for (; dyncon < dynconend; dyncon++)
5807 Elf_Internal_Dyn dyn;
5811 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5825 s = bfd_get_section_by_name (output_bfd, name);
5826 BFD_ASSERT (s != NULL);
5827 dyn.d_un.d_ptr = s->vma;
5828 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5832 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
5833 BFD_ASSERT (s != NULL);
5834 if (s->_cooked_size != 0)
5835 dyn.d_un.d_val = s->_cooked_size;
5837 dyn.d_un.d_val = s->_raw_size;
5838 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5842 /* My reading of the SVR4 ABI indicates that the
5843 procedure linkage table relocs (DT_JMPREL) should be
5844 included in the overall relocs (DT_RELA). This is
5845 what Solaris does. However, UnixWare can not handle
5846 that case. Therefore, we override the DT_RELASZ entry
5847 here to make it not include the JMPREL relocs. Since
5848 the linker script arranges for .rela.plt to follow all
5849 other relocation sections, we don't have to worry
5850 about changing the DT_RELA entry. */
5851 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
5854 if (s->_cooked_size != 0)
5855 dyn.d_un.d_val -= s->_cooked_size;
5857 dyn.d_un.d_val -= s->_raw_size;
5859 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5864 /* Fill in the first entry in the procedure linkage table. */
5865 splt = bfd_get_section_by_name (dynobj, ".plt");
5866 if (splt && splt->_raw_size > 0)
5870 if (elf_sh_pic_plt_entry == NULL)
5872 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
5873 elf_sh_pic_plt_entry_be :
5874 elf_sh_pic_plt_entry_le);
5876 memcpy (splt->contents, elf_sh_pic_plt_entry,
5877 elf_sh_sizeof_plt (info));
5881 if (elf_sh_plt0_entry == NULL)
5883 elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ?
5884 elf_sh_plt0_entry_be :
5885 elf_sh_plt0_entry_le);
5887 memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
5888 #ifdef INCLUDE_SHMEDIA
5889 movi_shori_putval (output_bfd,
5890 sgot->output_section->vma
5891 + sgot->output_offset,
5893 + elf_sh_plt0_gotplt_offset (info));
5895 bfd_put_32 (output_bfd,
5896 sgot->output_section->vma + sgot->output_offset + 4,
5897 splt->contents + elf_sh_plt0_gotid_offset (info));
5898 bfd_put_32 (output_bfd,
5899 sgot->output_section->vma + sgot->output_offset + 8,
5900 splt->contents + elf_sh_plt0_linker_offset (info));
5904 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5905 really seem like the right value. */
5906 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
5910 /* Fill in the first three entries in the global offset table. */
5911 if (sgot->_raw_size > 0)
5914 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5916 bfd_put_32 (output_bfd,
5917 sdyn->output_section->vma + sdyn->output_offset,
5919 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
5920 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
5923 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5928 static enum elf_reloc_type_class
5929 sh_elf_reloc_type_class (rela)
5930 const Elf_Internal_Rela *rela;
5932 switch ((int) ELF32_R_TYPE (rela->r_info))
5935 return reloc_class_relative;
5937 return reloc_class_plt;
5939 return reloc_class_copy;
5941 return reloc_class_normal;
5946 #define TARGET_BIG_SYM bfd_elf32_sh_vec
5947 #define TARGET_BIG_NAME "elf32-sh"
5948 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
5949 #define TARGET_LITTLE_NAME "elf32-shl"
5950 #define ELF_ARCH bfd_arch_sh
5951 #define ELF_MACHINE_CODE EM_SH
5952 #define ELF_MAXPAGESIZE 128
5954 #define elf_symbol_leading_char '_'
5955 #endif /* ELF_ARCH */
5957 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
5958 #define elf_info_to_howto sh_elf_info_to_howto
5959 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
5960 #define elf_backend_relocate_section sh_elf_relocate_section
5961 #define bfd_elf32_bfd_get_relocated_section_contents \
5962 sh_elf_get_relocated_section_contents
5963 #define elf_backend_object_p sh_elf_set_mach_from_flags
5964 #define bfd_elf32_bfd_set_private_bfd_flags \
5965 sh_elf_set_private_flags
5966 #define bfd_elf32_bfd_copy_private_bfd_data \
5967 sh_elf_copy_private_data
5968 #define bfd_elf32_bfd_merge_private_bfd_data \
5969 sh_elf_merge_private_data
5971 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
5972 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
5973 #define elf_backend_check_relocs sh_elf_check_relocs
5975 #define elf_backend_can_gc_sections 1
5976 #define elf_backend_create_dynamic_sections \
5977 sh_elf_create_dynamic_sections
5978 #define bfd_elf32_bfd_link_hash_table_create \
5979 sh_elf_link_hash_table_create
5980 #define elf_backend_adjust_dynamic_symbol \
5981 sh_elf_adjust_dynamic_symbol
5982 #define elf_backend_size_dynamic_sections \
5983 sh_elf_size_dynamic_sections
5984 #define elf_backend_finish_dynamic_symbol \
5985 sh_elf_finish_dynamic_symbol
5986 #define elf_backend_finish_dynamic_sections \
5987 sh_elf_finish_dynamic_sections
5988 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
5990 #define elf_backend_want_got_plt 1
5991 #define elf_backend_plt_readonly 1
5992 #define elf_backend_want_plt_sym 0
5993 #define elf_backend_got_header_size 12
5994 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
5995 #include "elf32-target.h"