1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
33 static reloc_howto_type *sh_elf_reloc_type_lookup
34 (bfd *, bfd_reloc_code_real_type);
35 static void sh_elf_info_to_howto
36 (bfd *, arelent *, Elf_Internal_Rela *);
37 static bfd_boolean sh_elf_set_private_flags
39 static bfd_boolean sh_elf_copy_private_data
41 static bfd_boolean sh_elf_merge_private_data
43 static bfd_boolean sh_elf_set_mach_from_flags
45 static bfd_boolean sh_elf_relax_section
46 (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
47 static bfd_boolean sh_elf_relax_delete_bytes
48 (bfd *, asection *, bfd_vma, int);
49 static bfd_boolean sh_elf_align_loads
50 (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
51 static bfd_boolean sh_elf_swap_insns
52 (bfd *, asection *, void *, bfd_byte *, bfd_vma);
53 static bfd_boolean sh_elf_relocate_section
54 (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 (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
58 bfd_boolean, asymbol **);
59 static void sh_elf_copy_indirect_symbol
60 (struct elf_backend_data *, struct elf_link_hash_entry *,
61 struct elf_link_hash_entry *);
62 static int sh_elf_optimized_tls_reloc
63 (struct bfd_link_info *, int, int);
64 static bfd_boolean sh_elf_mkobject
66 static bfd_boolean sh_elf_object_p
68 static bfd_boolean sh_elf_check_relocs
69 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
70 static struct bfd_hash_entry *sh_elf_link_hash_newfunc
71 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
72 static struct bfd_link_hash_table *sh_elf_link_hash_table_create
74 static bfd_boolean sh_elf_adjust_dynamic_symbol
75 (struct bfd_link_info *, struct elf_link_hash_entry *);
76 static bfd_boolean sh_elf_size_dynamic_sections
77 (bfd *, struct bfd_link_info *);
78 static bfd_boolean sh_elf_finish_dynamic_symbol
79 (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
81 static bfd_boolean sh_elf_finish_dynamic_sections
82 (bfd *, struct bfd_link_info *);
83 static bfd_reloc_status_type sh_elf_reloc_loop
84 (int, bfd *, asection *, bfd_byte *, bfd_vma, asection *, bfd_vma,
86 static bfd_boolean create_got_section
87 (bfd *, struct bfd_link_info *);
88 static bfd_boolean sh_elf_create_dynamic_sections
89 (bfd *, struct bfd_link_info *);
90 static bfd_vma dtpoff_base
91 (struct bfd_link_info *);
93 (struct bfd_link_info *, bfd_vma);
94 static asection * sh_elf_gc_mark_hook
95 (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
96 struct elf_link_hash_entry *, Elf_Internal_Sym *);
97 static bfd_boolean sh_elf_gc_sweep_hook
98 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
99 static bfd_boolean allocate_dynrelocs
100 (struct elf_link_hash_entry *, void *);
101 static bfd_boolean readonly_dynrelocs
102 (struct elf_link_hash_entry *, void *);
103 static enum elf_reloc_type_class sh_elf_reloc_type_class
104 (const Elf_Internal_Rela *);
105 #ifdef INCLUDE_SHMEDIA
106 inline static void movi_shori_putval (bfd *, unsigned long, char *);
108 static bfd_boolean elf32_shlin_grok_prstatus
109 (bfd *abfd, Elf_Internal_Note *note);
110 static bfd_boolean elf32_shlin_grok_psinfo
111 (bfd *abfd, Elf_Internal_Note *note);
113 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
118 static reloc_howto_type sh_elf_howto_table[] =
121 HOWTO (R_SH_NONE, /* type */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
125 FALSE, /* pc_relative */
127 complain_overflow_dont, /* complain_on_overflow */
128 sh_elf_ignore_reloc, /* special_function */
129 "R_SH_NONE", /* name */
130 FALSE, /* partial_inplace */
133 FALSE), /* pcrel_offset */
135 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
136 src_mask to a non-zero value is similar to the COFF toolchain. */
137 HOWTO (R_SH_DIR32, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE, /* pc_relative */
143 complain_overflow_bitfield, /* complain_on_overflow */
144 sh_elf_reloc, /* special_function */
145 "R_SH_DIR32", /* name */
146 TRUE, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 FALSE), /* pcrel_offset */
151 /* 32 bit PC relative relocation. */
152 HOWTO (R_SH_REL32, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 TRUE, /* pc_relative */
158 complain_overflow_signed, /* complain_on_overflow */
159 sh_elf_ignore_reloc, /* special_function */
160 "R_SH_REL32", /* name */
161 TRUE, /* partial_inplace */
162 0xffffffff, /* src_mask */
163 0xffffffff, /* dst_mask */
164 TRUE), /* pcrel_offset */
166 /* 8 bit PC relative branch divided by 2. */
167 HOWTO (R_SH_DIR8WPN, /* type */
169 1, /* size (0 = byte, 1 = short, 2 = long) */
171 TRUE, /* pc_relative */
173 complain_overflow_signed, /* complain_on_overflow */
174 sh_elf_ignore_reloc, /* special_function */
175 "R_SH_DIR8WPN", /* name */
176 TRUE, /* partial_inplace */
179 TRUE), /* pcrel_offset */
181 /* 12 bit PC relative branch divided by 2. */
182 /* This cannot be partial_inplace because relaxation can't know the
183 eventual value of a symbol. */
184 HOWTO (R_SH_IND12W, /* type */
186 1, /* size (0 = byte, 1 = short, 2 = long) */
188 TRUE, /* pc_relative */
190 complain_overflow_signed, /* complain_on_overflow */
191 NULL, /* special_function */
192 "R_SH_IND12W", /* name */
193 FALSE, /* partial_inplace */
195 0xfff, /* dst_mask */
196 TRUE), /* pcrel_offset */
198 /* 8 bit unsigned PC relative divided by 4. */
199 HOWTO (R_SH_DIR8WPL, /* type */
201 1, /* size (0 = byte, 1 = short, 2 = long) */
203 TRUE, /* pc_relative */
205 complain_overflow_unsigned, /* complain_on_overflow */
206 sh_elf_ignore_reloc, /* special_function */
207 "R_SH_DIR8WPL", /* name */
208 TRUE, /* partial_inplace */
211 TRUE), /* pcrel_offset */
213 /* 8 bit unsigned PC relative divided by 2. */
214 HOWTO (R_SH_DIR8WPZ, /* type */
216 1, /* size (0 = byte, 1 = short, 2 = long) */
218 TRUE, /* pc_relative */
220 complain_overflow_unsigned, /* complain_on_overflow */
221 sh_elf_ignore_reloc, /* special_function */
222 "R_SH_DIR8WPZ", /* name */
223 TRUE, /* partial_inplace */
226 TRUE), /* pcrel_offset */
228 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
229 special symbol for the GBR relative area, and that is not
231 HOWTO (R_SH_DIR8BP, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE, /* pc_relative */
237 complain_overflow_unsigned, /* complain_on_overflow */
238 sh_elf_ignore_reloc, /* special_function */
239 "R_SH_DIR8BP", /* name */
240 FALSE, /* partial_inplace */
243 TRUE), /* pcrel_offset */
245 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
246 we have some special symbol for the GBR relative area, and that
247 is not implemented. */
248 HOWTO (R_SH_DIR8W, /* type */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE, /* pc_relative */
254 complain_overflow_unsigned, /* complain_on_overflow */
255 sh_elf_ignore_reloc, /* special_function */
256 "R_SH_DIR8W", /* name */
257 FALSE, /* partial_inplace */
260 TRUE), /* pcrel_offset */
262 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
263 we have some special symbol for the GBR relative area, and that
264 is not implemented. */
265 HOWTO (R_SH_DIR8L, /* type */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE, /* pc_relative */
271 complain_overflow_unsigned, /* complain_on_overflow */
272 sh_elf_ignore_reloc, /* special_function */
273 "R_SH_DIR8L", /* name */
274 FALSE, /* partial_inplace */
277 TRUE), /* pcrel_offset */
295 /* The remaining relocs are a GNU extension used for relaxing. The
296 final pass of the linker never needs to do anything with any of
297 these relocs. Any required operations are handled by the
300 /* A 16 bit switch table entry. This is generated for an expression
301 such as ``.word L1 - L2''. The offset holds the difference
302 between the reloc address and L2. */
303 HOWTO (R_SH_SWITCH16, /* type */
305 1, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE, /* pc_relative */
309 complain_overflow_unsigned, /* complain_on_overflow */
310 sh_elf_ignore_reloc, /* special_function */
311 "R_SH_SWITCH16", /* name */
312 FALSE, /* partial_inplace */
315 TRUE), /* pcrel_offset */
317 /* A 32 bit switch table entry. This is generated for an expression
318 such as ``.long L1 - L2''. The offset holds the difference
319 between the reloc address and L2. */
320 HOWTO (R_SH_SWITCH32, /* type */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE, /* pc_relative */
326 complain_overflow_unsigned, /* complain_on_overflow */
327 sh_elf_ignore_reloc, /* special_function */
328 "R_SH_SWITCH32", /* name */
329 FALSE, /* partial_inplace */
332 TRUE), /* pcrel_offset */
334 /* Indicates a .uses pseudo-op. The compiler will generate .uses
335 pseudo-ops when it finds a function call which can be relaxed.
336 The offset field holds the PC relative offset to the instruction
337 which loads the register used in the function call. */
338 HOWTO (R_SH_USES, /* type */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE, /* pc_relative */
344 complain_overflow_unsigned, /* complain_on_overflow */
345 sh_elf_ignore_reloc, /* special_function */
346 "R_SH_USES", /* name */
347 FALSE, /* partial_inplace */
350 TRUE), /* pcrel_offset */
352 /* The assembler will generate this reloc for addresses referred to
353 by the register loads associated with USES relocs. The offset
354 field holds the number of times the address is referenced in the
356 HOWTO (R_SH_COUNT, /* type */
358 1, /* size (0 = byte, 1 = short, 2 = long) */
360 FALSE, /* pc_relative */
362 complain_overflow_unsigned, /* complain_on_overflow */
363 sh_elf_ignore_reloc, /* special_function */
364 "R_SH_COUNT", /* name */
365 FALSE, /* partial_inplace */
368 TRUE), /* pcrel_offset */
370 /* Indicates an alignment statement. The offset field is the power
371 of 2 to which subsequent portions of the object file must be
373 HOWTO (R_SH_ALIGN, /* type */
375 1, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE, /* pc_relative */
379 complain_overflow_unsigned, /* complain_on_overflow */
380 sh_elf_ignore_reloc, /* special_function */
381 "R_SH_ALIGN", /* name */
382 FALSE, /* partial_inplace */
385 TRUE), /* pcrel_offset */
387 /* The assembler will generate this reloc before a block of
388 instructions. A section should be processed as assumining it
389 contains data, unless this reloc is seen. */
390 HOWTO (R_SH_CODE, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 FALSE, /* pc_relative */
396 complain_overflow_unsigned, /* complain_on_overflow */
397 sh_elf_ignore_reloc, /* special_function */
398 "R_SH_CODE", /* name */
399 FALSE, /* partial_inplace */
402 TRUE), /* pcrel_offset */
404 /* The assembler will generate this reloc after a block of
405 instructions when it sees data that is not instructions. */
406 HOWTO (R_SH_DATA, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE, /* pc_relative */
412 complain_overflow_unsigned, /* complain_on_overflow */
413 sh_elf_ignore_reloc, /* special_function */
414 "R_SH_DATA", /* name */
415 FALSE, /* partial_inplace */
418 TRUE), /* pcrel_offset */
420 /* The assembler generates this reloc for each label within a block
421 of instructions. This permits the linker to avoid swapping
422 instructions which are the targets of branches. */
423 HOWTO (R_SH_LABEL, /* type */
425 1, /* size (0 = byte, 1 = short, 2 = long) */
427 FALSE, /* pc_relative */
429 complain_overflow_unsigned, /* complain_on_overflow */
430 sh_elf_ignore_reloc, /* special_function */
431 "R_SH_LABEL", /* name */
432 FALSE, /* partial_inplace */
435 TRUE), /* pcrel_offset */
437 /* An 8 bit switch table entry. This is generated for an expression
438 such as ``.word L1 - L2''. The offset holds the difference
439 between the reloc address and L2. */
440 HOWTO (R_SH_SWITCH8, /* type */
442 0, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE, /* pc_relative */
446 complain_overflow_unsigned, /* complain_on_overflow */
447 sh_elf_ignore_reloc, /* special_function */
448 "R_SH_SWITCH8", /* name */
449 FALSE, /* partial_inplace */
452 TRUE), /* pcrel_offset */
454 /* GNU extension to record C++ vtable hierarchy */
455 HOWTO (R_SH_GNU_VTINHERIT, /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 FALSE, /* pc_relative */
461 complain_overflow_dont, /* complain_on_overflow */
462 NULL, /* special_function */
463 "R_SH_GNU_VTINHERIT", /* name */
464 FALSE, /* partial_inplace */
467 FALSE), /* pcrel_offset */
469 /* GNU extension to record C++ vtable member usage */
470 HOWTO (R_SH_GNU_VTENTRY, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 FALSE, /* pc_relative */
476 complain_overflow_dont, /* complain_on_overflow */
477 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
478 "R_SH_GNU_VTENTRY", /* name */
479 FALSE, /* partial_inplace */
482 FALSE), /* pcrel_offset */
484 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
485 HOWTO (R_SH_LOOP_START, /* type */
487 1, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE, /* pc_relative */
491 complain_overflow_signed, /* complain_on_overflow */
492 sh_elf_ignore_reloc, /* special_function */
493 "R_SH_LOOP_START", /* name */
494 TRUE, /* partial_inplace */
497 TRUE), /* pcrel_offset */
499 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
500 HOWTO (R_SH_LOOP_END, /* type */
502 1, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE, /* pc_relative */
506 complain_overflow_signed, /* complain_on_overflow */
507 sh_elf_ignore_reloc, /* special_function */
508 "R_SH_LOOP_END", /* name */
509 TRUE, /* partial_inplace */
512 TRUE), /* pcrel_offset */
522 #ifdef INCLUDE_SHMEDIA
523 /* Used in SHLLI.L and SHLRI.L. */
524 HOWTO (R_SH_DIR5U, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE, /* pc_relative */
530 complain_overflow_unsigned, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_SH_DIR5U", /* name */
533 FALSE, /* partial_inplace */
535 0xfc00, /* dst_mask */
536 FALSE), /* pcrel_offset */
538 /* Used in SHARI, SHLLI et al. */
539 HOWTO (R_SH_DIR6U, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 FALSE, /* pc_relative */
545 complain_overflow_unsigned, /* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_SH_DIR6U", /* name */
548 FALSE, /* partial_inplace */
550 0xfc00, /* dst_mask */
551 FALSE), /* pcrel_offset */
553 /* Used in BxxI, LDHI.L et al. */
554 HOWTO (R_SH_DIR6S, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE, /* pc_relative */
560 complain_overflow_signed, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_SH_DIR6S", /* name */
563 FALSE, /* partial_inplace */
565 0xfc00, /* dst_mask */
566 FALSE), /* pcrel_offset */
568 /* Used in ADDI, ANDI et al. */
569 HOWTO (R_SH_DIR10S, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 FALSE, /* pc_relative */
575 complain_overflow_signed, /* complain_on_overflow */
576 bfd_elf_generic_reloc, /* special_function */
577 "R_SH_DIR10S", /* name */
578 FALSE, /* partial_inplace */
580 0xffc00, /* dst_mask */
581 FALSE), /* pcrel_offset */
583 /* Used in LD.UW, ST.W et al. */
584 HOWTO (R_SH_DIR10SW, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 FALSE, /* pc_relative */
590 complain_overflow_signed, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_SH_DIR10SW", /* name */
593 FALSE, /* partial_inplace */
595 0xffc00, /* dst_mask */
596 FALSE), /* pcrel_offset */
598 /* Used in LD.L, FLD.S et al. */
599 HOWTO (R_SH_DIR10SL, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 FALSE, /* pc_relative */
605 complain_overflow_signed, /* complain_on_overflow */
606 bfd_elf_generic_reloc, /* special_function */
607 "R_SH_DIR10SL", /* name */
608 FALSE, /* partial_inplace */
610 0xffc00, /* dst_mask */
611 FALSE), /* pcrel_offset */
613 /* Used in FLD.D, FST.P et al. */
614 HOWTO (R_SH_DIR10SQ, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 FALSE, /* pc_relative */
620 complain_overflow_signed, /* complain_on_overflow */
621 bfd_elf_generic_reloc, /* special_function */
622 "R_SH_DIR10SQ", /* name */
623 FALSE, /* partial_inplace */
625 0xffc00, /* dst_mask */
626 FALSE), /* pcrel_offset */
731 HOWTO (R_SH_TLS_GD_32, /* type */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
735 FALSE, /* pc_relative */
737 complain_overflow_bitfield, /* complain_on_overflow */
738 bfd_elf_generic_reloc, /* */
739 "R_SH_TLS_GD_32", /* name */
740 TRUE, /* partial_inplace */
741 0xffffffff, /* src_mask */
742 0xffffffff, /* dst_mask */
743 FALSE), /* pcrel_offset */
745 HOWTO (R_SH_TLS_LD_32, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE, /* pc_relative */
751 complain_overflow_bitfield, /* complain_on_overflow */
752 bfd_elf_generic_reloc, /* */
753 "R_SH_TLS_LD_32", /* name */
754 TRUE, /* partial_inplace */
755 0xffffffff, /* src_mask */
756 0xffffffff, /* dst_mask */
757 FALSE), /* pcrel_offset */
759 HOWTO (R_SH_TLS_LDO_32, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE, /* pc_relative */
765 complain_overflow_bitfield, /* complain_on_overflow */
766 bfd_elf_generic_reloc, /* */
767 "R_SH_TLS_LDO_32", /* name */
768 TRUE, /* partial_inplace */
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
771 FALSE), /* pcrel_offset */
773 HOWTO (R_SH_TLS_IE_32, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 FALSE, /* pc_relative */
779 complain_overflow_bitfield, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* */
781 "R_SH_TLS_IE_32", /* name */
782 TRUE, /* partial_inplace */
783 0xffffffff, /* src_mask */
784 0xffffffff, /* dst_mask */
785 FALSE), /* pcrel_offset */
787 HOWTO (R_SH_TLS_LE_32, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE, /* pc_relative */
793 complain_overflow_bitfield, /* complain_on_overflow */
794 bfd_elf_generic_reloc, /* */
795 "R_SH_TLS_LE_32", /* name */
796 TRUE, /* partial_inplace */
797 0xffffffff, /* src_mask */
798 0xffffffff, /* dst_mask */
799 FALSE), /* pcrel_offset */
801 HOWTO (R_SH_TLS_DTPMOD32, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 FALSE, /* pc_relative */
807 complain_overflow_bitfield, /* complain_on_overflow */
808 bfd_elf_generic_reloc, /* */
809 "R_SH_TLS_DTPMOD32", /* name */
810 TRUE, /* partial_inplace */
811 0xffffffff, /* src_mask */
812 0xffffffff, /* dst_mask */
813 FALSE), /* pcrel_offset */
815 HOWTO (R_SH_TLS_DTPOFF32, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE, /* pc_relative */
821 complain_overflow_bitfield, /* complain_on_overflow */
822 bfd_elf_generic_reloc, /* */
823 "R_SH_TLS_DTPOFF32", /* name */
824 TRUE, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 FALSE), /* pcrel_offset */
829 HOWTO (R_SH_TLS_TPOFF32, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE, /* pc_relative */
835 complain_overflow_bitfield, /* complain_on_overflow */
836 bfd_elf_generic_reloc, /* */
837 "R_SH_TLS_TPOFF32", /* name */
838 TRUE, /* partial_inplace */
839 0xffffffff, /* src_mask */
840 0xffffffff, /* dst_mask */
841 FALSE), /* pcrel_offset */
852 HOWTO (R_SH_GOT32, /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE, /* pc_relative */
858 complain_overflow_bitfield, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* */
860 "R_SH_GOT32", /* name */
861 TRUE, /* partial_inplace */
862 0xffffffff, /* src_mask */
863 0xffffffff, /* dst_mask */
864 FALSE), /* pcrel_offset */
866 HOWTO (R_SH_PLT32, /* type */
868 2, /* size (0 = byte, 1 = short, 2 = long) */
870 TRUE, /* pc_relative */
872 complain_overflow_bitfield, /* complain_on_overflow */
873 bfd_elf_generic_reloc, /* */
874 "R_SH_PLT32", /* name */
875 TRUE, /* partial_inplace */
876 0xffffffff, /* src_mask */
877 0xffffffff, /* dst_mask */
878 TRUE), /* pcrel_offset */
880 HOWTO (R_SH_COPY, /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE, /* pc_relative */
886 complain_overflow_bitfield, /* complain_on_overflow */
887 bfd_elf_generic_reloc, /* */
888 "R_SH_COPY", /* name */
889 TRUE, /* partial_inplace */
890 0xffffffff, /* src_mask */
891 0xffffffff, /* dst_mask */
892 FALSE), /* pcrel_offset */
894 HOWTO (R_SH_GLOB_DAT, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE, /* pc_relative */
900 complain_overflow_bitfield, /* complain_on_overflow */
901 bfd_elf_generic_reloc, /* */
902 "R_SH_GLOB_DAT", /* name */
903 TRUE, /* partial_inplace */
904 0xffffffff, /* src_mask */
905 0xffffffff, /* dst_mask */
906 FALSE), /* pcrel_offset */
908 HOWTO (R_SH_JMP_SLOT, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE, /* pc_relative */
914 complain_overflow_bitfield, /* complain_on_overflow */
915 bfd_elf_generic_reloc, /* */
916 "R_SH_JMP_SLOT", /* name */
917 TRUE, /* partial_inplace */
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
920 FALSE), /* pcrel_offset */
922 HOWTO (R_SH_RELATIVE, /* type */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE, /* pc_relative */
928 complain_overflow_bitfield, /* complain_on_overflow */
929 bfd_elf_generic_reloc, /* */
930 "R_SH_RELATIVE", /* name */
931 TRUE, /* partial_inplace */
932 0xffffffff, /* src_mask */
933 0xffffffff, /* dst_mask */
934 FALSE), /* pcrel_offset */
936 HOWTO (R_SH_GOTOFF, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE, /* pc_relative */
942 complain_overflow_bitfield, /* complain_on_overflow */
943 bfd_elf_generic_reloc, /* */
944 "R_SH_GOTOFF", /* name */
945 TRUE, /* partial_inplace */
946 0xffffffff, /* src_mask */
947 0xffffffff, /* dst_mask */
948 FALSE), /* pcrel_offset */
950 HOWTO (R_SH_GOTPC, /* type */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 TRUE, /* pc_relative */
956 complain_overflow_bitfield, /* complain_on_overflow */
957 bfd_elf_generic_reloc, /* */
958 "R_SH_GOTPC", /* name */
959 TRUE, /* partial_inplace */
960 0xffffffff, /* src_mask */
961 0xffffffff, /* dst_mask */
962 TRUE), /* pcrel_offset */
964 HOWTO (R_SH_GOTPLT32, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE, /* pc_relative */
970 complain_overflow_bitfield, /* complain_on_overflow */
971 bfd_elf_generic_reloc, /* */
972 "R_SH_GOTPLT32", /* name */
973 FALSE, /* partial_inplace */
974 0xffffffff, /* src_mask */
975 0xffffffff, /* dst_mask */
976 FALSE), /* pcrel_offset */
978 #ifdef INCLUDE_SHMEDIA
979 /* Used in MOVI and SHORI (x & 65536). */
980 HOWTO (R_SH_GOT_LOW16, /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE, /* pc_relative */
986 complain_overflow_dont, /* complain_on_overflow */
987 bfd_elf_generic_reloc, /* special_function */
988 "R_SH_GOT_LOW16", /* name */
989 FALSE, /* partial_inplace */
991 0x3fffc00, /* dst_mask */
992 FALSE), /* pcrel_offset */
994 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
995 HOWTO (R_SH_GOT_MEDLOW16, /* type */
997 2, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE, /* pc_relative */
1001 complain_overflow_dont, /* complain_on_overflow */
1002 bfd_elf_generic_reloc, /* special_function */
1003 "R_SH_GOT_MEDLOW16", /* name */
1004 FALSE, /* partial_inplace */
1006 0x3fffc00, /* dst_mask */
1007 FALSE), /* pcrel_offset */
1009 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1010 HOWTO (R_SH_GOT_MEDHI16, /* type */
1011 32, /* rightshift */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE, /* pc_relative */
1016 complain_overflow_dont, /* complain_on_overflow */
1017 bfd_elf_generic_reloc, /* special_function */
1018 "R_SH_GOT_MEDHI16", /* name */
1019 FALSE, /* partial_inplace */
1021 0x3fffc00, /* dst_mask */
1022 FALSE), /* pcrel_offset */
1024 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1025 HOWTO (R_SH_GOT_HI16, /* type */
1026 48, /* rightshift */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE, /* pc_relative */
1031 complain_overflow_dont, /* complain_on_overflow */
1032 bfd_elf_generic_reloc, /* special_function */
1033 "R_SH_GOT_HI16", /* name */
1034 FALSE, /* partial_inplace */
1036 0x3fffc00, /* dst_mask */
1037 FALSE), /* pcrel_offset */
1039 /* Used in MOVI and SHORI (x & 65536). */
1040 HOWTO (R_SH_GOTPLT_LOW16, /* type */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1044 FALSE, /* pc_relative */
1046 complain_overflow_dont, /* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_SH_GOTPLT_LOW16", /* name */
1049 FALSE, /* partial_inplace */
1051 0x3fffc00, /* dst_mask */
1052 FALSE), /* pcrel_offset */
1054 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1055 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
1056 16, /* rightshift */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE, /* pc_relative */
1061 complain_overflow_dont, /* complain_on_overflow */
1062 bfd_elf_generic_reloc, /* special_function */
1063 "R_SH_GOTPLT_MEDLOW16", /* name */
1064 FALSE, /* partial_inplace */
1066 0x3fffc00, /* dst_mask */
1067 FALSE), /* pcrel_offset */
1069 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1070 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
1071 32, /* rightshift */
1072 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 FALSE, /* pc_relative */
1076 complain_overflow_dont, /* complain_on_overflow */
1077 bfd_elf_generic_reloc, /* special_function */
1078 "R_SH_GOTPLT_MEDHI16", /* name */
1079 FALSE, /* partial_inplace */
1081 0x3fffc00, /* dst_mask */
1082 FALSE), /* pcrel_offset */
1084 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1085 HOWTO (R_SH_GOTPLT_HI16, /* type */
1086 48, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE, /* pc_relative */
1091 complain_overflow_dont, /* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
1093 "R_SH_GOTPLT_HI16", /* name */
1094 FALSE, /* partial_inplace */
1096 0x3fffc00, /* dst_mask */
1097 FALSE), /* pcrel_offset */
1099 /* Used in MOVI and SHORI (x & 65536). */
1100 HOWTO (R_SH_PLT_LOW16, /* type */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1104 TRUE, /* pc_relative */
1106 complain_overflow_dont, /* complain_on_overflow */
1107 bfd_elf_generic_reloc, /* special_function */
1108 "R_SH_PLT_LOW16", /* name */
1109 FALSE, /* partial_inplace */
1111 0x3fffc00, /* dst_mask */
1112 TRUE), /* pcrel_offset */
1114 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1115 HOWTO (R_SH_PLT_MEDLOW16, /* type */
1116 16, /* rightshift */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 TRUE, /* pc_relative */
1121 complain_overflow_dont, /* complain_on_overflow */
1122 bfd_elf_generic_reloc, /* special_function */
1123 "R_SH_PLT_MEDLOW16", /* name */
1124 FALSE, /* partial_inplace */
1126 0x3fffc00, /* dst_mask */
1127 TRUE), /* pcrel_offset */
1129 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1130 HOWTO (R_SH_PLT_MEDHI16, /* type */
1131 32, /* rightshift */
1132 2, /* size (0 = byte, 1 = short, 2 = long) */
1134 TRUE, /* pc_relative */
1136 complain_overflow_dont, /* complain_on_overflow */
1137 bfd_elf_generic_reloc, /* special_function */
1138 "R_SH_PLT_MEDHI16", /* name */
1139 FALSE, /* partial_inplace */
1141 0x3fffc00, /* dst_mask */
1142 TRUE), /* pcrel_offset */
1144 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1145 HOWTO (R_SH_PLT_HI16, /* type */
1146 48, /* rightshift */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1149 TRUE, /* pc_relative */
1151 complain_overflow_dont, /* complain_on_overflow */
1152 bfd_elf_generic_reloc, /* special_function */
1153 "R_SH_PLT_HI16", /* name */
1154 FALSE, /* partial_inplace */
1156 0x3fffc00, /* dst_mask */
1157 TRUE), /* pcrel_offset */
1159 /* Used in MOVI and SHORI (x & 65536). */
1160 HOWTO (R_SH_GOTOFF_LOW16, /* type */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE, /* pc_relative */
1166 complain_overflow_dont, /* complain_on_overflow */
1167 bfd_elf_generic_reloc, /* special_function */
1168 "R_SH_GOTOFF_LOW16", /* name */
1169 FALSE, /* partial_inplace */
1171 0x3fffc00, /* dst_mask */
1172 FALSE), /* pcrel_offset */
1174 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1175 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
1176 16, /* rightshift */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE, /* pc_relative */
1181 complain_overflow_dont, /* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 "R_SH_GOTOFF_MEDLOW16", /* name */
1184 FALSE, /* partial_inplace */
1186 0x3fffc00, /* dst_mask */
1187 FALSE), /* pcrel_offset */
1189 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1190 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
1191 32, /* rightshift */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE, /* pc_relative */
1196 complain_overflow_dont, /* complain_on_overflow */
1197 bfd_elf_generic_reloc, /* special_function */
1198 "R_SH_GOTOFF_MEDHI16", /* name */
1199 FALSE, /* partial_inplace */
1201 0x3fffc00, /* dst_mask */
1202 FALSE), /* pcrel_offset */
1204 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1205 HOWTO (R_SH_GOTOFF_HI16, /* type */
1206 48, /* rightshift */
1207 2, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE, /* pc_relative */
1211 complain_overflow_dont, /* complain_on_overflow */
1212 bfd_elf_generic_reloc, /* special_function */
1213 "R_SH_GOTOFF_HI16", /* name */
1214 FALSE, /* partial_inplace */
1216 0x3fffc00, /* dst_mask */
1217 FALSE), /* pcrel_offset */
1219 /* Used in MOVI and SHORI (x & 65536). */
1220 HOWTO (R_SH_GOTPC_LOW16, /* type */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 TRUE, /* pc_relative */
1226 complain_overflow_dont, /* complain_on_overflow */
1227 bfd_elf_generic_reloc, /* special_function */
1228 "R_SH_GOTPC_LOW16", /* name */
1229 FALSE, /* partial_inplace */
1231 0x3fffc00, /* dst_mask */
1232 TRUE), /* pcrel_offset */
1234 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1235 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
1236 16, /* rightshift */
1237 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 TRUE, /* pc_relative */
1241 complain_overflow_dont, /* complain_on_overflow */
1242 bfd_elf_generic_reloc, /* special_function */
1243 "R_SH_GOTPC_MEDLOW16", /* name */
1244 FALSE, /* partial_inplace */
1246 0x3fffc00, /* dst_mask */
1247 TRUE), /* pcrel_offset */
1249 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1250 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
1251 32, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 TRUE, /* pc_relative */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_SH_GOTPC_MEDHI16", /* name */
1259 FALSE, /* partial_inplace */
1261 0x3fffc00, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1264 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1265 HOWTO (R_SH_GOTPC_HI16, /* type */
1266 48, /* rightshift */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 TRUE, /* pc_relative */
1271 complain_overflow_dont, /* complain_on_overflow */
1272 bfd_elf_generic_reloc, /* special_function */
1273 "R_SH_GOTPC_HI16", /* name */
1274 FALSE, /* partial_inplace */
1276 0x3fffc00, /* dst_mask */
1277 TRUE), /* pcrel_offset */
1279 /* Used in LD.L, FLD.S et al. */
1280 HOWTO (R_SH_GOT10BY4, /* type */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1284 FALSE, /* pc_relative */
1286 complain_overflow_signed, /* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_SH_GOT10BY4", /* name */
1289 FALSE, /* partial_inplace */
1291 0xffc00, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1294 /* Used in LD.L, FLD.S et al. */
1295 HOWTO (R_SH_GOTPLT10BY4, /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE, /* pc_relative */
1301 complain_overflow_signed, /* complain_on_overflow */
1302 bfd_elf_generic_reloc, /* special_function */
1303 "R_SH_GOTPLT10BY4", /* name */
1304 FALSE, /* partial_inplace */
1306 0xffc00, /* dst_mask */
1307 FALSE), /* pcrel_offset */
1309 /* Used in FLD.D, FST.P et al. */
1310 HOWTO (R_SH_GOT10BY8, /* type */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 FALSE, /* pc_relative */
1316 complain_overflow_signed, /* complain_on_overflow */
1317 bfd_elf_generic_reloc, /* special_function */
1318 "R_SH_GOT10BY8", /* name */
1319 FALSE, /* partial_inplace */
1321 0xffc00, /* dst_mask */
1322 FALSE), /* pcrel_offset */
1324 /* Used in FLD.D, FST.P et al. */
1325 HOWTO (R_SH_GOTPLT10BY8, /* type */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 FALSE, /* pc_relative */
1331 complain_overflow_signed, /* complain_on_overflow */
1332 bfd_elf_generic_reloc, /* special_function */
1333 "R_SH_GOTPLT10BY8", /* name */
1334 FALSE, /* partial_inplace */
1336 0xffc00, /* dst_mask */
1337 FALSE), /* pcrel_offset */
1339 HOWTO (R_SH_COPY64, /* type */
1341 4, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE, /* pc_relative */
1345 complain_overflow_dont, /* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
1347 "R_SH_COPY64", /* name */
1348 FALSE, /* partial_inplace */
1350 ((bfd_vma) 0) - 1, /* dst_mask */
1351 FALSE), /* pcrel_offset */
1353 HOWTO (R_SH_GLOB_DAT64, /* type */
1355 4, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE, /* pc_relative */
1359 complain_overflow_dont, /* complain_on_overflow */
1360 bfd_elf_generic_reloc, /* special_function */
1361 "R_SH_GLOB_DAT64", /* name */
1362 FALSE, /* partial_inplace */
1364 ((bfd_vma) 0) - 1, /* dst_mask */
1365 FALSE), /* pcrel_offset */
1367 HOWTO (R_SH_JMP_SLOT64, /* type */
1369 4, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE, /* pc_relative */
1373 complain_overflow_dont, /* complain_on_overflow */
1374 bfd_elf_generic_reloc, /* special_function */
1375 "R_SH_JMP_SLOT64", /* name */
1376 FALSE, /* partial_inplace */
1378 ((bfd_vma) 0) - 1, /* dst_mask */
1379 FALSE), /* pcrel_offset */
1381 HOWTO (R_SH_RELATIVE64, /* type */
1383 4, /* 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_RELATIVE64", /* name */
1390 FALSE, /* partial_inplace */
1392 ((bfd_vma) 0) - 1, /* dst_mask */
1393 FALSE), /* pcrel_offset */
1441 /* Relocations for SHmedia code. None of these are partial_inplace or
1442 use the field being relocated (except R_SH_PT_16). */
1444 /* The assembler will generate this reloc before a block of SHmedia
1445 instructions. A section should be processed as assuming it contains
1446 data, unless this reloc is seen. Note that a block of SHcompact
1447 instructions are instead preceded by R_SH_CODE.
1448 This is currently not implemented, but should be used for SHmedia
1449 linker relaxation. */
1450 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1452 1, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE, /* pc_relative */
1456 complain_overflow_unsigned, /* complain_on_overflow */
1457 sh_elf_ignore_reloc, /* special_function */
1458 "R_SH_SHMEDIA_CODE", /* name */
1459 FALSE, /* partial_inplace */
1462 FALSE), /* pcrel_offset */
1464 /* The assembler will generate this reloc at a PTA or PTB instruction,
1465 and the linker checks the right type of target, or changes a PTA to a
1466 PTB, if the original insn was PT. */
1467 HOWTO (R_SH_PT_16, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 TRUE, /* pc_relative */
1473 complain_overflow_signed, /* complain_on_overflow */
1474 bfd_elf_generic_reloc, /* special_function */
1475 "R_SH_PT_16", /* name */
1476 FALSE, /* partial_inplace */
1478 0x3fffc00, /* dst_mask */
1479 TRUE), /* pcrel_offset */
1481 /* Used in unexpanded MOVI. */
1482 HOWTO (R_SH_IMMS16, /* type */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE, /* pc_relative */
1488 complain_overflow_signed, /* complain_on_overflow */
1489 bfd_elf_generic_reloc, /* special_function */
1490 "R_SH_IMMS16", /* name */
1491 FALSE, /* partial_inplace */
1493 0x3fffc00, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1496 /* Used in SHORI. */
1497 HOWTO (R_SH_IMMU16, /* type */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1501 FALSE, /* pc_relative */
1503 complain_overflow_unsigned, /* complain_on_overflow */
1504 bfd_elf_generic_reloc, /* special_function */
1505 "R_SH_IMMU16", /* name */
1506 FALSE, /* partial_inplace */
1508 0x3fffc00, /* dst_mask */
1509 FALSE), /* pcrel_offset */
1511 /* Used in MOVI and SHORI (x & 65536). */
1512 HOWTO (R_SH_IMM_LOW16, /* type */
1514 2, /* size (0 = byte, 1 = short, 2 = long) */
1516 FALSE, /* pc_relative */
1518 complain_overflow_dont, /* complain_on_overflow */
1519 bfd_elf_generic_reloc, /* special_function */
1520 "R_SH_IMM_LOW16", /* name */
1521 FALSE, /* partial_inplace */
1523 0x3fffc00, /* dst_mask */
1524 FALSE), /* pcrel_offset */
1526 /* Used in MOVI and SHORI ((x - $) & 65536). */
1527 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 TRUE, /* pc_relative */
1533 complain_overflow_dont, /* complain_on_overflow */
1534 bfd_elf_generic_reloc, /* special_function */
1535 "R_SH_IMM_LOW16_PCREL", /* name */
1536 FALSE, /* partial_inplace */
1538 0x3fffc00, /* dst_mask */
1539 TRUE), /* pcrel_offset */
1541 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1542 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1543 16, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE, /* pc_relative */
1548 complain_overflow_dont, /* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_SH_IMM_MEDLOW16", /* name */
1551 FALSE, /* partial_inplace */
1553 0x3fffc00, /* dst_mask */
1554 FALSE), /* pcrel_offset */
1556 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1557 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1558 16, /* rightshift */
1559 2, /* size (0 = byte, 1 = short, 2 = long) */
1561 TRUE, /* pc_relative */
1563 complain_overflow_dont, /* complain_on_overflow */
1564 bfd_elf_generic_reloc, /* special_function */
1565 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1566 FALSE, /* partial_inplace */
1568 0x3fffc00, /* dst_mask */
1569 TRUE), /* pcrel_offset */
1571 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1572 HOWTO (R_SH_IMM_MEDHI16, /* type */
1573 32, /* rightshift */
1574 2, /* size (0 = byte, 1 = short, 2 = long) */
1576 FALSE, /* pc_relative */
1578 complain_overflow_dont, /* complain_on_overflow */
1579 bfd_elf_generic_reloc, /* special_function */
1580 "R_SH_IMM_MEDHI16", /* name */
1581 FALSE, /* partial_inplace */
1583 0x3fffc00, /* dst_mask */
1584 FALSE), /* pcrel_offset */
1586 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1587 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1588 32, /* rightshift */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1591 TRUE, /* pc_relative */
1593 complain_overflow_dont, /* complain_on_overflow */
1594 bfd_elf_generic_reloc, /* special_function */
1595 "R_SH_IMM_MEDHI16_PCREL", /* name */
1596 FALSE, /* partial_inplace */
1598 0x3fffc00, /* dst_mask */
1599 TRUE), /* pcrel_offset */
1601 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1602 HOWTO (R_SH_IMM_HI16, /* type */
1603 48, /* rightshift */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE, /* pc_relative */
1608 complain_overflow_dont, /* complain_on_overflow */
1609 bfd_elf_generic_reloc, /* special_function */
1610 "R_SH_IMM_HI16", /* name */
1611 FALSE, /* partial_inplace */
1613 0x3fffc00, /* dst_mask */
1614 FALSE), /* pcrel_offset */
1616 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1617 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1618 48, /* rightshift */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1621 TRUE, /* pc_relative */
1623 complain_overflow_dont, /* complain_on_overflow */
1624 bfd_elf_generic_reloc, /* special_function */
1625 "R_SH_IMM_HI16_PCREL", /* name */
1626 FALSE, /* partial_inplace */
1628 0x3fffc00, /* dst_mask */
1629 TRUE), /* pcrel_offset */
1631 /* For the .uaquad pseudo. */
1632 HOWTO (R_SH_64, /* type */
1634 4, /* size (0 = byte, 1 = short, 2 = long) */
1636 FALSE, /* pc_relative */
1638 complain_overflow_dont, /* complain_on_overflow */
1639 bfd_elf_generic_reloc, /* special_function */
1640 "R_SH_64", /* name */
1641 FALSE, /* partial_inplace */
1643 ((bfd_vma) 0) - 1, /* dst_mask */
1644 FALSE), /* pcrel_offset */
1646 /* For the .uaquad pseudo, (x - $). */
1647 HOWTO (R_SH_64_PCREL, /* type */
1648 48, /* rightshift */
1649 2, /* size (0 = byte, 1 = short, 2 = long) */
1651 TRUE, /* pc_relative */
1653 complain_overflow_dont, /* complain_on_overflow */
1654 bfd_elf_generic_reloc, /* special_function */
1655 "R_SH_64_PCREL", /* name */
1656 FALSE, /* partial_inplace */
1658 ((bfd_vma) 0) - 1, /* dst_mask */
1659 TRUE), /* pcrel_offset */
1664 static bfd_reloc_status_type
1665 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
1666 asection *input_section, bfd_byte *contents,
1667 bfd_vma addr, asection *symbol_section,
1668 bfd_vma start, bfd_vma end)
1670 static bfd_vma last_addr;
1671 static asection *last_symbol_section;
1672 bfd_byte *start_ptr, *ptr, *last_ptr;
1677 /* Sanity check the address. */
1678 if (addr > input_section->_raw_size)
1679 return bfd_reloc_outofrange;
1681 /* We require the start and end relocations to be processed consecutively -
1682 although we allow then to be processed forwards or backwards. */
1686 last_symbol_section = symbol_section;
1687 return bfd_reloc_ok;
1689 if (last_addr != addr)
1693 if (! symbol_section || last_symbol_section != symbol_section || end < start)
1694 return bfd_reloc_outofrange;
1696 /* Get the symbol_section contents. */
1697 if (symbol_section != input_section)
1699 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
1700 contents = elf_section_data (symbol_section)->this_hdr.contents;
1703 contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
1704 if (contents == NULL)
1705 return bfd_reloc_outofrange;
1706 if (! bfd_get_section_contents (input_bfd, symbol_section, contents,
1708 symbol_section->_raw_size))
1711 return bfd_reloc_outofrange;
1715 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1716 start_ptr = contents + start;
1717 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
1719 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
1722 diff = (last_ptr - ptr) >> 1;
1723 cum_diff += diff & 1;
1726 /* Calculate the start / end values to load into rs / re minus four -
1727 so that will cancel out the four we would otherwise have to add to
1728 addr to get the value to subtract in order to get relative addressing. */
1732 end = (ptr + cum_diff * 2) - contents;
1736 bfd_vma start0 = start - 4;
1738 while (start0 && IS_PPI (contents + start0))
1740 start0 = start - 2 - ((start - start0) & 2);
1741 start = start0 - cum_diff - 2;
1745 if (contents != NULL
1746 && elf_section_data (symbol_section)->this_hdr.contents != contents)
1749 insn = bfd_get_16 (input_bfd, contents + addr);
1751 x = (insn & 0x200 ? end : start) - addr;
1752 if (input_section != symbol_section)
1753 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
1754 - (input_section->output_section->vma
1755 + input_section->output_offset));
1757 if (x < -128 || x > 127)
1758 return bfd_reloc_overflow;
1760 x = (insn & ~0xff) | (x & 0xff);
1761 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
1763 return bfd_reloc_ok;
1766 /* This function is used for normal relocs. This used to be like the COFF
1767 function, and is almost certainly incorrect for other ELF targets. */
1769 static bfd_reloc_status_type
1770 sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1771 void *data, asection *input_section, bfd *output_bfd,
1772 char **error_message ATTRIBUTE_UNUSED)
1776 enum elf_sh_reloc_type r_type;
1777 bfd_vma addr = reloc_entry->address;
1778 bfd_byte *hit_data = addr + (bfd_byte *) data;
1780 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1782 if (output_bfd != NULL)
1784 /* Partial linking--do nothing. */
1785 reloc_entry->address += input_section->output_offset;
1786 return bfd_reloc_ok;
1789 /* Almost all relocs have to do with relaxing. If any work must be
1790 done for them, it has been done in sh_relax_section. */
1791 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
1792 return bfd_reloc_ok;
1794 if (symbol_in != NULL
1795 && bfd_is_und_section (symbol_in->section))
1796 return bfd_reloc_undefined;
1798 if (bfd_is_com_section (symbol_in->section))
1801 sym_value = (symbol_in->value +
1802 symbol_in->section->output_section->vma +
1803 symbol_in->section->output_offset);
1808 insn = bfd_get_32 (abfd, hit_data);
1809 insn += sym_value + reloc_entry->addend;
1810 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
1813 insn = bfd_get_16 (abfd, hit_data);
1814 sym_value += reloc_entry->addend;
1815 sym_value -= (input_section->output_section->vma
1816 + input_section->output_offset
1819 sym_value += (insn & 0xfff) << 1;
1821 sym_value -= 0x1000;
1822 insn = (insn & 0xf000) | (sym_value & 0xfff);
1823 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
1824 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
1825 return bfd_reloc_overflow;
1832 return bfd_reloc_ok;
1835 /* This function is used for relocs which are only used for relaxing,
1836 which the linker should otherwise ignore. */
1838 static bfd_reloc_status_type
1839 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1840 asymbol *symbol ATTRIBUTE_UNUSED,
1841 void *data ATTRIBUTE_UNUSED, asection *input_section,
1843 char **error_message ATTRIBUTE_UNUSED)
1845 if (output_bfd != NULL)
1846 reloc_entry->address += input_section->output_offset;
1847 return bfd_reloc_ok;
1850 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1852 struct elf_reloc_map
1854 bfd_reloc_code_real_type bfd_reloc_val;
1855 unsigned char elf_reloc_val;
1858 /* An array mapping BFD reloc codes to SH ELF relocs. */
1860 static const struct elf_reloc_map sh_reloc_map[] =
1862 { BFD_RELOC_NONE, R_SH_NONE },
1863 { BFD_RELOC_32, R_SH_DIR32 },
1864 { BFD_RELOC_CTOR, R_SH_DIR32 },
1865 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1866 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
1867 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
1868 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
1869 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
1870 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1871 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1872 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1873 { BFD_RELOC_SH_USES, R_SH_USES },
1874 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
1875 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
1876 { BFD_RELOC_SH_CODE, R_SH_CODE },
1877 { BFD_RELOC_SH_DATA, R_SH_DATA },
1878 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
1879 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1880 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1881 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
1882 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
1883 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
1884 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
1885 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
1886 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
1887 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
1888 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
1889 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
1890 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
1891 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
1892 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
1893 { BFD_RELOC_SH_COPY, R_SH_COPY },
1894 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
1895 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
1896 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
1897 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
1898 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
1899 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
1900 #ifdef INCLUDE_SHMEDIA
1901 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1902 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1903 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1904 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1905 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1906 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1907 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1908 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1909 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1910 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1911 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1912 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1913 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1914 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1915 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1916 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1917 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1918 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1919 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1920 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1921 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1922 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1923 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1924 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1925 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1926 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1927 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1928 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1929 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1930 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1931 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1932 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1933 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1934 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1935 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1936 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1937 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1938 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1939 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1940 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1941 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1942 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1943 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1944 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1945 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1946 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1947 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1948 { BFD_RELOC_64, R_SH_64 },
1949 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1950 #endif /* not INCLUDE_SHMEDIA */
1953 /* Given a BFD reloc code, return the howto structure for the
1954 corresponding SH ELf reloc. */
1956 static reloc_howto_type *
1957 sh_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1958 bfd_reloc_code_real_type code)
1962 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
1964 if (sh_reloc_map[i].bfd_reloc_val == code)
1965 return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val];
1971 /* Given an ELF reloc, fill in the howto field of a relent. */
1974 sh_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
1975 Elf_Internal_Rela *dst)
1979 r = ELF32_R_TYPE (dst->r_info);
1981 BFD_ASSERT (r < (unsigned int) R_SH_max);
1982 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1983 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
1984 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
1985 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1986 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
1988 cache_ptr->howto = &sh_elf_howto_table[r];
1991 /* This function handles relaxing for SH ELF. See the corresponding
1992 function in coff-sh.c for a description of what this does. FIXME:
1993 There is a lot of duplication here between this code and the COFF
1994 specific code. The format of relocs and symbols is wound deeply
1995 into this code, but it would still be better if the duplication
1996 could be eliminated somehow. Note in particular that although both
1997 functions use symbols like R_SH_CODE, those symbols have different
1998 values; in coff-sh.c they come from include/coff/sh.h, whereas here
1999 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2002 sh_elf_relax_section (bfd *abfd, asection *sec,
2003 struct bfd_link_info *link_info, bfd_boolean *again)
2005 Elf_Internal_Shdr *symtab_hdr;
2006 Elf_Internal_Rela *internal_relocs;
2007 bfd_boolean have_code;
2008 Elf_Internal_Rela *irel, *irelend;
2009 bfd_byte *contents = NULL;
2010 Elf_Internal_Sym *isymbuf = NULL;
2014 if (link_info->relocatable
2015 || (sec->flags & SEC_RELOC) == 0
2016 || sec->reloc_count == 0)
2019 #ifdef INCLUDE_SHMEDIA
2020 if (elf_section_data (sec)->this_hdr.sh_flags
2021 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
2027 /* If this is the first time we have been called for this section,
2028 initialize the cooked size. */
2029 if (sec->_cooked_size == 0)
2030 sec->_cooked_size = sec->_raw_size;
2032 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2034 internal_relocs = (_bfd_elf_link_read_relocs
2035 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
2036 link_info->keep_memory));
2037 if (internal_relocs == NULL)
2042 irelend = internal_relocs + sec->reloc_count;
2043 for (irel = internal_relocs; irel < irelend; irel++)
2045 bfd_vma laddr, paddr, symval;
2046 unsigned short insn;
2047 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
2048 bfd_signed_vma foff;
2050 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
2053 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
2056 /* Get the section contents. */
2057 if (contents == NULL)
2059 if (elf_section_data (sec)->this_hdr.contents != NULL)
2060 contents = elf_section_data (sec)->this_hdr.contents;
2063 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2064 if (contents == NULL)
2067 if (! bfd_get_section_contents (abfd, sec, contents,
2068 (file_ptr) 0, sec->_raw_size))
2073 /* The r_addend field of the R_SH_USES reloc will point us to
2074 the register load. The 4 is because the r_addend field is
2075 computed as though it were a jump offset, which are based
2076 from 4 bytes after the jump instruction. */
2077 laddr = irel->r_offset + 4 + irel->r_addend;
2078 if (laddr >= sec->_raw_size)
2080 (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2081 bfd_archive_filename (abfd),
2082 (unsigned long) irel->r_offset);
2085 insn = bfd_get_16 (abfd, contents + laddr);
2087 /* If the instruction is not mov.l NN,rN, we don't know what to
2089 if ((insn & 0xf000) != 0xd000)
2091 ((*_bfd_error_handler)
2092 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2093 bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
2097 /* Get the address from which the register is being loaded. The
2098 displacement in the mov.l instruction is quadrupled. It is a
2099 displacement from four bytes after the movl instruction, but,
2100 before adding in the PC address, two least significant bits
2101 of the PC are cleared. We assume that the section is aligned
2102 on a four byte boundary. */
2103 paddr = insn & 0xff;
2105 paddr += (laddr + 4) &~ (bfd_vma) 3;
2106 if (paddr >= sec->_raw_size)
2108 ((*_bfd_error_handler)
2109 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2110 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2114 /* Get the reloc for the address from which the register is
2115 being loaded. This reloc will tell us which function is
2116 actually being called. */
2117 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2118 if (irelfn->r_offset == paddr
2119 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
2121 if (irelfn >= irelend)
2123 ((*_bfd_error_handler)
2124 (_("%s: 0x%lx: warning: could not find expected reloc"),
2125 bfd_archive_filename (abfd), (unsigned long) paddr));
2129 /* Read this BFD's symbols if we haven't done so already. */
2130 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2132 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2133 if (isymbuf == NULL)
2134 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2135 symtab_hdr->sh_info, 0,
2137 if (isymbuf == NULL)
2141 /* Get the value of the symbol referred to by the reloc. */
2142 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2144 /* A local symbol. */
2145 Elf_Internal_Sym *isym;
2147 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
2149 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
2151 ((*_bfd_error_handler)
2152 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2153 bfd_archive_filename (abfd), (unsigned long) paddr));
2157 symval = (isym->st_value
2158 + sec->output_section->vma
2159 + sec->output_offset);
2164 struct elf_link_hash_entry *h;
2166 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
2167 h = elf_sym_hashes (abfd)[indx];
2168 BFD_ASSERT (h != NULL);
2169 if (h->root.type != bfd_link_hash_defined
2170 && h->root.type != bfd_link_hash_defweak)
2172 /* This appears to be a reference to an undefined
2173 symbol. Just ignore it--it will be caught by the
2174 regular reloc processing. */
2178 symval = (h->root.u.def.value
2179 + h->root.u.def.section->output_section->vma
2180 + h->root.u.def.section->output_offset);
2183 symval += bfd_get_32 (abfd, contents + paddr);
2185 /* See if this function call can be shortened. */
2188 + sec->output_section->vma
2189 + sec->output_offset
2191 if (foff < -0x1000 || foff >= 0x1000)
2193 /* After all that work, we can't shorten this function call. */
2197 /* Shorten the function call. */
2199 /* For simplicity of coding, we are going to modify the section
2200 contents, the section relocs, and the BFD symbol table. We
2201 must tell the rest of the code not to free up this
2202 information. It would be possible to instead create a table
2203 of changes which have to be made, as is done in coff-mips.c;
2204 that would be more work, but would require less memory when
2205 the linker is run. */
2207 elf_section_data (sec)->relocs = internal_relocs;
2208 elf_section_data (sec)->this_hdr.contents = contents;
2209 symtab_hdr->contents = (unsigned char *) isymbuf;
2211 /* Replace the jsr with a bsr. */
2213 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2214 replace the jsr with a bsr. */
2215 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
2216 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2217 here, but that only checks if the symbol is an external symbol,
2218 not if the symbol is in a different section. Besides, we need
2219 a consistent meaning for the relocation, so we just assume here that
2220 the value of the symbol is not available. */
2222 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2224 /* If this needs to be changed because of future relaxing,
2225 it will be handled here like other internal IND12W
2228 (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
2229 contents + irel->r_offset);
2234 /* We can't fully resolve this yet, because the external
2235 symbol value may be changed by future relaxing. We let
2236 the final link phase handle it. */
2237 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
2239 irel->r_addend = -4;
2241 /* See if there is another R_SH_USES reloc referring to the same
2243 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2244 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2245 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
2247 if (irelscan < irelend)
2249 /* Some other function call depends upon this register load,
2250 and we have not yet converted that function call.
2251 Indeed, we may never be able to convert it. There is
2252 nothing else we can do at this point. */
2256 /* Look for a R_SH_COUNT reloc on the location where the
2257 function address is stored. Do this before deleting any
2258 bytes, to avoid confusion about the address. */
2259 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2260 if (irelcount->r_offset == paddr
2261 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
2264 /* Delete the register load. */
2265 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
2268 /* That will change things, so, just in case it permits some
2269 other function call to come within range, we should relax
2270 again. Note that this is not required, and it may be slow. */
2273 /* Now check whether we got a COUNT reloc. */
2274 if (irelcount >= irelend)
2276 ((*_bfd_error_handler)
2277 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2278 bfd_archive_filename (abfd), (unsigned long) paddr));
2282 /* The number of uses is stored in the r_addend field. We've
2283 just deleted one. */
2284 if (irelcount->r_addend == 0)
2286 ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
2287 bfd_archive_filename (abfd),
2288 (unsigned long) paddr));
2292 --irelcount->r_addend;
2294 /* If there are no more uses, we can delete the address. Reload
2295 the address from irelfn, in case it was changed by the
2296 previous call to sh_elf_relax_delete_bytes. */
2297 if (irelcount->r_addend == 0)
2299 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
2303 /* We've done all we can with that function call. */
2306 /* Look for load and store instructions that we can align on four
2308 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
2311 bfd_boolean swapped;
2313 /* Get the section contents. */
2314 if (contents == NULL)
2316 if (elf_section_data (sec)->this_hdr.contents != NULL)
2317 contents = elf_section_data (sec)->this_hdr.contents;
2320 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2321 if (contents == NULL)
2324 if (! bfd_get_section_contents (abfd, sec, contents,
2325 (file_ptr) 0, sec->_raw_size))
2330 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
2336 elf_section_data (sec)->relocs = internal_relocs;
2337 elf_section_data (sec)->this_hdr.contents = contents;
2338 symtab_hdr->contents = (unsigned char *) isymbuf;
2343 && symtab_hdr->contents != (unsigned char *) isymbuf)
2345 if (! link_info->keep_memory)
2349 /* Cache the symbols for elf_link_input_bfd. */
2350 symtab_hdr->contents = (unsigned char *) isymbuf;
2354 if (contents != NULL
2355 && elf_section_data (sec)->this_hdr.contents != contents)
2357 if (! link_info->keep_memory)
2361 /* Cache the section contents for elf_link_input_bfd. */
2362 elf_section_data (sec)->this_hdr.contents = contents;
2366 if (internal_relocs != NULL
2367 && elf_section_data (sec)->relocs != internal_relocs)
2368 free (internal_relocs);
2374 && symtab_hdr->contents != (unsigned char *) isymbuf)
2376 if (contents != NULL
2377 && elf_section_data (sec)->this_hdr.contents != contents)
2379 if (internal_relocs != NULL
2380 && elf_section_data (sec)->relocs != internal_relocs)
2381 free (internal_relocs);
2386 /* Delete some bytes from a section while relaxing. FIXME: There is a
2387 lot of duplication between this function and sh_relax_delete_bytes
2391 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
2394 Elf_Internal_Shdr *symtab_hdr;
2395 unsigned int sec_shndx;
2397 Elf_Internal_Rela *irel, *irelend;
2398 Elf_Internal_Rela *irelalign;
2400 Elf_Internal_Sym *isymbuf, *isym, *isymend;
2401 struct elf_link_hash_entry **sym_hashes;
2402 struct elf_link_hash_entry **end_hashes;
2403 unsigned int symcount;
2406 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2407 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2409 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2411 contents = elf_section_data (sec)->this_hdr.contents;
2413 /* The deletion must stop at the next ALIGN reloc for an aligment
2414 power larger than the number of bytes we are deleting. */
2417 toaddr = sec->_cooked_size;
2419 irel = elf_section_data (sec)->relocs;
2420 irelend = irel + sec->reloc_count;
2421 for (; irel < irelend; irel++)
2423 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2424 && irel->r_offset > addr
2425 && count < (1 << irel->r_addend))
2428 toaddr = irel->r_offset;
2433 /* Actually delete the bytes. */
2434 memmove (contents + addr, contents + addr + count,
2435 (size_t) (toaddr - addr - count));
2436 if (irelalign == NULL)
2437 sec->_cooked_size -= count;
2442 #define NOP_OPCODE (0x0009)
2444 BFD_ASSERT ((count & 1) == 0);
2445 for (i = 0; i < count; i += 2)
2446 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
2449 /* Adjust all the relocs. */
2450 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2452 bfd_vma nraddr, stop;
2455 int off, adjust, oinsn;
2456 bfd_signed_vma voff = 0;
2457 bfd_boolean overflow;
2459 /* Get the new reloc address. */
2460 nraddr = irel->r_offset;
2461 if ((irel->r_offset > addr
2462 && irel->r_offset < toaddr)
2463 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2464 && irel->r_offset == toaddr))
2467 /* See if this reloc was for the bytes we have deleted, in which
2468 case we no longer care about it. Don't delete relocs which
2469 represent addresses, though. */
2470 if (irel->r_offset >= addr
2471 && irel->r_offset < addr + count
2472 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
2473 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
2474 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
2475 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
2476 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2479 /* If this is a PC relative reloc, see if the range it covers
2480 includes the bytes we have deleted. */
2481 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2490 start = irel->r_offset;
2491 insn = bfd_get_16 (abfd, contents + nraddr);
2495 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2498 start = stop = addr;
2502 /* If this reloc is against a symbol defined in this
2503 section, and the symbol will not be adjusted below, we
2504 must check the addend to see it will put the value in
2505 range to be adjusted, and hence must be changed. */
2506 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2508 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2509 if (isym->st_shndx == sec_shndx
2510 && (isym->st_value <= addr
2511 || isym->st_value >= toaddr))
2515 val = bfd_get_32 (abfd, contents + nraddr);
2516 val += isym->st_value;
2517 if (val > addr && val < toaddr)
2518 bfd_put_32 (abfd, val - count, contents + nraddr);
2521 start = stop = addr;
2528 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2535 /* This has been made by previous relaxation. Since the
2536 relocation will be against an external symbol, the
2537 final relocation will just do the right thing. */
2538 start = stop = addr;
2544 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2546 /* The addend will be against the section symbol, thus
2547 for adjusting the addend, the relevant start is the
2548 start of the section.
2549 N.B. If we want to abandom in-place changes here and
2550 test directly using symbol + addend, we have to take into
2551 account that the addend has already been adjusted by -4. */
2552 if (stop > addr && stop < toaddr)
2553 irel->r_addend -= count;
2559 stop = start + 4 + off * 2;
2564 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
2570 /* These relocs types represent
2572 The r_addend field holds the difference between the reloc
2573 address and L1. That is the start of the reloc, and
2574 adding in the contents gives us the top. We must adjust
2575 both the r_offset field and the section contents.
2576 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2577 and the elf bfd r_offset is called r_vaddr. */
2579 stop = irel->r_offset;
2580 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
2584 && (stop <= addr || stop >= toaddr))
2585 irel->r_addend += count;
2586 else if (stop > addr
2588 && (start <= addr || start >= toaddr))
2589 irel->r_addend -= count;
2591 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
2592 voff = bfd_get_signed_16 (abfd, contents + nraddr);
2593 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
2594 voff = bfd_get_8 (abfd, contents + nraddr);
2596 voff = bfd_get_signed_32 (abfd, contents + nraddr);
2597 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2602 start = irel->r_offset;
2603 stop = (bfd_vma) ((bfd_signed_vma) start
2604 + (long) irel->r_addend
2611 && (stop <= addr || stop >= toaddr))
2613 else if (stop > addr
2615 && (start <= addr || start >= toaddr))
2624 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2633 if ((oinsn & 0xff00) != (insn & 0xff00))
2635 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2640 if ((oinsn & 0xf000) != (insn & 0xf000))
2642 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2646 BFD_ASSERT (adjust == count || count >= 4);
2651 if ((irel->r_offset & 3) == 0)
2654 if ((oinsn & 0xff00) != (insn & 0xff00))
2656 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2661 if (voff < 0 || voff >= 0xff)
2663 bfd_put_8 (abfd, voff, contents + nraddr);
2668 if (voff < - 0x8000 || voff >= 0x8000)
2670 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
2675 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
2679 irel->r_addend += adjust;
2685 ((*_bfd_error_handler)
2686 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2687 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2688 bfd_set_error (bfd_error_bad_value);
2693 irel->r_offset = nraddr;
2696 /* Look through all the other sections. If there contain any IMM32
2697 relocs against internal symbols which we are not going to adjust
2698 below, we may need to adjust the addends. */
2699 for (o = abfd->sections; o != NULL; o = o->next)
2701 Elf_Internal_Rela *internal_relocs;
2702 Elf_Internal_Rela *irelscan, *irelscanend;
2703 bfd_byte *ocontents;
2706 || (o->flags & SEC_RELOC) == 0
2707 || o->reloc_count == 0)
2710 /* We always cache the relocs. Perhaps, if info->keep_memory is
2711 FALSE, we should free them, if we are permitted to, when we
2712 leave sh_coff_relax_section. */
2713 internal_relocs = (_bfd_elf_link_read_relocs
2714 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
2715 if (internal_relocs == NULL)
2719 irelscanend = internal_relocs + o->reloc_count;
2720 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
2722 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2723 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
2725 bfd_vma start, stop;
2726 bfd_signed_vma voff;
2728 if (ocontents == NULL)
2730 if (elf_section_data (o)->this_hdr.contents != NULL)
2731 ocontents = elf_section_data (o)->this_hdr.contents;
2734 /* We always cache the section contents.
2735 Perhaps, if info->keep_memory is FALSE, we
2736 should free them, if we are permitted to,
2737 when we leave sh_coff_relax_section. */
2738 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2739 if (ocontents == NULL)
2741 if (! bfd_get_section_contents (abfd, o, ocontents,
2745 elf_section_data (o)->this_hdr.contents = ocontents;
2749 stop = irelscan->r_offset;
2751 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
2753 /* STOP is in a different section, so it won't change. */
2754 if (start > addr && start < toaddr)
2755 irelscan->r_addend += count;
2757 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
2758 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2762 && (stop <= addr || stop >= toaddr))
2763 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
2764 ocontents + irelscan->r_offset);
2765 else if (stop > addr
2767 && (start <= addr || start >= toaddr))
2768 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
2769 ocontents + irelscan->r_offset);
2772 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
2775 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
2779 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
2780 if (isym->st_shndx == sec_shndx
2781 && (isym->st_value <= addr
2782 || isym->st_value >= toaddr))
2786 if (ocontents == NULL)
2788 if (elf_section_data (o)->this_hdr.contents != NULL)
2789 ocontents = elf_section_data (o)->this_hdr.contents;
2792 /* We always cache the section contents.
2793 Perhaps, if info->keep_memory is FALSE, we
2794 should free them, if we are permitted to,
2795 when we leave sh_coff_relax_section. */
2796 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2797 if (ocontents == NULL)
2799 if (! bfd_get_section_contents (abfd, o, ocontents,
2803 elf_section_data (o)->this_hdr.contents = ocontents;
2807 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2808 val += isym->st_value;
2809 if (val > addr && val < toaddr)
2810 bfd_put_32 (abfd, val - count,
2811 ocontents + irelscan->r_offset);
2816 /* Adjust the local symbols defined in this section. */
2817 isymend = isymbuf + symtab_hdr->sh_info;
2818 for (isym = isymbuf; isym < isymend; isym++)
2820 if (isym->st_shndx == sec_shndx
2821 && isym->st_value > addr
2822 && isym->st_value < toaddr)
2823 isym->st_value -= count;
2826 /* Now adjust the global symbols defined in this section. */
2827 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2828 - symtab_hdr->sh_info);
2829 sym_hashes = elf_sym_hashes (abfd);
2830 end_hashes = sym_hashes + symcount;
2831 for (; sym_hashes < end_hashes; sym_hashes++)
2833 struct elf_link_hash_entry *sym_hash = *sym_hashes;
2834 if ((sym_hash->root.type == bfd_link_hash_defined
2835 || sym_hash->root.type == bfd_link_hash_defweak)
2836 && sym_hash->root.u.def.section == sec
2837 && sym_hash->root.u.def.value > addr
2838 && sym_hash->root.u.def.value < toaddr)
2840 sym_hash->root.u.def.value -= count;
2844 /* See if we can move the ALIGN reloc forward. We have adjusted
2845 r_offset for it already. */
2846 if (irelalign != NULL)
2848 bfd_vma alignto, alignaddr;
2850 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
2851 alignaddr = BFD_ALIGN (irelalign->r_offset,
2852 1 << irelalign->r_addend);
2853 if (alignto != alignaddr)
2855 /* Tail recursion. */
2856 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
2857 (int) (alignto - alignaddr));
2864 /* Look for loads and stores which we can align to four byte
2865 boundaries. This is like sh_align_loads in coff-sh.c. */
2868 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
2869 Elf_Internal_Rela *internal_relocs,
2870 bfd_byte *contents ATTRIBUTE_UNUSED,
2871 bfd_boolean *pswapped)
2873 Elf_Internal_Rela *irel, *irelend;
2874 bfd_vma *labels = NULL;
2875 bfd_vma *label, *label_end;
2880 irelend = internal_relocs + sec->reloc_count;
2882 /* Get all the addresses with labels on them. */
2883 amt = sec->reloc_count;
2884 amt *= sizeof (bfd_vma);
2885 labels = (bfd_vma *) bfd_malloc (amt);
2889 for (irel = internal_relocs; irel < irelend; irel++)
2891 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
2893 *label_end = irel->r_offset;
2898 /* Note that the assembler currently always outputs relocs in
2899 address order. If that ever changes, this code will need to sort
2900 the label values and the relocs. */
2904 for (irel = internal_relocs; irel < irelend; irel++)
2906 bfd_vma start, stop;
2908 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
2911 start = irel->r_offset;
2913 for (irel++; irel < irelend; irel++)
2914 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
2917 stop = irel->r_offset;
2919 stop = sec->_cooked_size;
2921 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
2922 internal_relocs, &label,
2923 label_end, start, stop, pswapped))
2937 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2940 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
2941 bfd_byte *contents, bfd_vma addr)
2943 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
2944 unsigned short i1, i2;
2945 Elf_Internal_Rela *irel, *irelend;
2947 /* Swap the instructions themselves. */
2948 i1 = bfd_get_16 (abfd, contents + addr);
2949 i2 = bfd_get_16 (abfd, contents + addr + 2);
2950 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2951 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
2953 /* Adjust all reloc addresses. */
2954 irelend = internal_relocs + sec->reloc_count;
2955 for (irel = internal_relocs; irel < irelend; irel++)
2957 enum elf_sh_reloc_type type;
2960 /* There are a few special types of relocs that we don't want to
2961 adjust. These relocs do not apply to the instruction itself,
2962 but are only associated with the address. */
2963 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
2964 if (type == R_SH_ALIGN
2965 || type == R_SH_CODE
2966 || type == R_SH_DATA
2967 || type == R_SH_LABEL)
2970 /* If an R_SH_USES reloc points to one of the addresses being
2971 swapped, we must adjust it. It would be incorrect to do this
2972 for a jump, though, since we want to execute both
2973 instructions after the jump. (We have avoided swapping
2974 around a label, so the jump will not wind up executing an
2975 instruction it shouldn't). */
2976 if (type == R_SH_USES)
2980 off = irel->r_offset + 4 + irel->r_addend;
2982 irel->r_offset += 2;
2983 else if (off == addr + 2)
2984 irel->r_offset -= 2;
2987 if (irel->r_offset == addr)
2989 irel->r_offset += 2;
2992 else if (irel->r_offset == addr + 2)
2994 irel->r_offset -= 2;
3003 unsigned short insn, oinsn;
3004 bfd_boolean overflow;
3006 loc = contents + irel->r_offset;
3015 insn = bfd_get_16 (abfd, loc);
3018 if ((oinsn & 0xff00) != (insn & 0xff00))
3020 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3024 insn = bfd_get_16 (abfd, loc);
3027 if ((oinsn & 0xf000) != (insn & 0xf000))
3029 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3033 /* This reloc ignores the least significant 3 bits of
3034 the program counter before adding in the offset.
3035 This means that if ADDR is at an even address, the
3036 swap will not affect the offset. If ADDR is an at an
3037 odd address, then the instruction will be crossing a
3038 four byte boundary, and must be adjusted. */
3039 if ((addr & 3) != 0)
3041 insn = bfd_get_16 (abfd, loc);
3044 if ((oinsn & 0xff00) != (insn & 0xff00))
3046 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3054 ((*_bfd_error_handler)
3055 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3056 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
3057 bfd_set_error (bfd_error_bad_value);
3066 #ifdef INCLUDE_SHMEDIA
3068 /* The size in bytes of an entry in the procedure linkage table. */
3070 #define PLT_ENTRY_SIZE 64
3072 /* First entry in an absolute procedure linkage table look like this. */
3074 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3076 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3077 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3078 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3079 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3080 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3081 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3082 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3083 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3084 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3085 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3086 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3087 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3088 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3089 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3090 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3091 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3094 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3096 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3097 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3098 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3099 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3100 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3101 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3102 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3103 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3104 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3105 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3106 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3107 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3108 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3109 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3110 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3111 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3114 /* Sebsequent entries in an absolute procedure linkage table look like
3117 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3119 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3120 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3121 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3122 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3123 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3124 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3125 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3126 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3127 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3128 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3129 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3130 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3131 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3132 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3133 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3134 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3137 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3139 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3140 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3141 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3142 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3143 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3144 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3145 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3146 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3147 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3148 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3149 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3150 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3151 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3152 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3153 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3154 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3157 /* Entries in a PIC procedure linkage table look like this. */
3159 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3161 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3162 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3163 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3164 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3165 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3166 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3167 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3168 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3169 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3170 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3171 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3172 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3173 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3174 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3175 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3176 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3179 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3181 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3182 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3183 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3184 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3185 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3186 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3187 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3188 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3189 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3190 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3191 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3192 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3193 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3194 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3195 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3196 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3199 static const bfd_byte *elf_sh_plt0_entry;
3200 static const bfd_byte *elf_sh_plt_entry;
3201 static const bfd_byte *elf_sh_pic_plt_entry;
3203 /* Return size of a PLT entry. */
3204 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3206 /* Return offset of the PLT0 address in an absolute PLT entry. */
3207 #define elf_sh_plt_plt0_offset(info) 32
3209 /* Return offset of the linker in PLT0 entry. */
3210 #define elf_sh_plt0_gotplt_offset(info) 0
3212 /* Return offset of the trampoline in PLT entry */
3213 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3215 /* Return offset of the symbol in PLT entry. */
3216 #define elf_sh_plt_symbol_offset(info) 0
3218 /* Return offset of the relocation in PLT entry. */
3219 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3222 movi_shori_putval (bfd *output_bfd, unsigned long value, char *addr)
3224 bfd_put_32 (output_bfd,
3225 bfd_get_32 (output_bfd, addr)
3226 | ((value >> 6) & 0x3fffc00),
3228 bfd_put_32 (output_bfd,
3229 bfd_get_32 (output_bfd, addr + 4)
3230 | ((value << 10) & 0x3fffc00),
3235 /* The size in bytes of an entry in the procedure linkage table. */
3237 #define PLT_ENTRY_SIZE 28
3239 /* First entry in an absolute procedure linkage table look like this. */
3242 /* Note - this code has been "optimised" not to use r2. r2 is used by
3243 GCC to return the address of large strutcures, so it should not be
3244 corrupted here. This does mean however, that this PLT does not conform
3245 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3246 and r2 contains the GOT id. This version stores the GOT id in r0 and
3247 ignores the type. Loaders can easily detect this difference however,
3248 since the type will always be 0 or 8, and the GOT ids will always be
3249 greater than or equal to 12. */
3250 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3252 0xd0, 0x05, /* mov.l 2f,r0 */
3253 0x60, 0x02, /* mov.l @r0,r0 */
3254 0x2f, 0x06, /* mov.l r0,@-r15 */
3255 0xd0, 0x03, /* mov.l 1f,r0 */
3256 0x60, 0x02, /* mov.l @r0,r0 */
3257 0x40, 0x2b, /* jmp @r0 */
3258 0x60, 0xf6, /* mov.l @r15+,r0 */
3259 0x00, 0x09, /* nop */
3260 0x00, 0x09, /* nop */
3261 0x00, 0x09, /* nop */
3262 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3263 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3266 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3268 0x05, 0xd0, /* mov.l 2f,r0 */
3269 0x02, 0x60, /* mov.l @r0,r0 */
3270 0x06, 0x2f, /* mov.l r0,@-r15 */
3271 0x03, 0xd0, /* mov.l 1f,r0 */
3272 0x02, 0x60, /* mov.l @r0,r0 */
3273 0x2b, 0x40, /* jmp @r0 */
3274 0xf6, 0x60, /* mov.l @r15+,r0 */
3275 0x09, 0x00, /* nop */
3276 0x09, 0x00, /* nop */
3277 0x09, 0x00, /* nop */
3278 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3279 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3282 /* Sebsequent entries in an absolute procedure linkage table look like
3285 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3287 0xd0, 0x04, /* mov.l 1f,r0 */
3288 0x60, 0x02, /* mov.l @r0,r0 */
3289 0xd1, 0x02, /* mov.l 0f,r1 */
3290 0x40, 0x2b, /* jmp @r0 */
3291 0x60, 0x13, /* mov r1,r0 */
3292 0xd1, 0x03, /* mov.l 2f,r1 */
3293 0x40, 0x2b, /* jmp @r0 */
3294 0x00, 0x09, /* nop */
3295 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
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 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3302 0x04, 0xd0, /* mov.l 1f,r0 */
3303 0x02, 0x60, /* mov.l @r0,r0 */
3304 0x02, 0xd1, /* mov.l 0f,r1 */
3305 0x2b, 0x40, /* jmp @r0 */
3306 0x13, 0x60, /* mov r1,r0 */
3307 0x03, 0xd1, /* mov.l 2f,r1 */
3308 0x2b, 0x40, /* jmp @r0 */
3309 0x09, 0x00, /* nop */
3310 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3311 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3312 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3315 /* Entries in a PIC procedure linkage table look like this. */
3317 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3319 0xd0, 0x04, /* mov.l 1f,r0 */
3320 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3321 0x40, 0x2b, /* jmp @r0 */
3322 0x00, 0x09, /* nop */
3323 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3324 0xd1, 0x03, /* mov.l 2f,r1 */
3325 0x40, 0x2b, /* jmp @r0 */
3326 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3327 0x00, 0x09, /* nop */
3328 0x00, 0x09, /* nop */
3329 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3330 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3333 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3335 0x04, 0xd0, /* mov.l 1f,r0 */
3336 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3337 0x2b, 0x40, /* jmp @r0 */
3338 0x09, 0x00, /* nop */
3339 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3340 0x03, 0xd1, /* mov.l 2f,r1 */
3341 0x2b, 0x40, /* jmp @r0 */
3342 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3343 0x09, 0x00, /* nop */
3344 0x09, 0x00, /* nop */
3345 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3346 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3349 #else /* These are the old style PLT entries. */
3350 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3352 0xd0, 0x04, /* mov.l 1f,r0 */
3353 0xd2, 0x05, /* mov.l 2f,r2 */
3354 0x60, 0x02, /* mov.l @r0,r0 */
3355 0x62, 0x22, /* mov.l @r2,r2 */
3356 0x40, 0x2b, /* jmp @r0 */
3357 0xe0, 0x00, /* mov #0,r0 */
3358 0x00, 0x09, /* nop */
3359 0x00, 0x09, /* nop */
3360 0x00, 0x09, /* nop */
3361 0x00, 0x09, /* nop */
3362 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3363 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3366 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3368 0x04, 0xd0, /* mov.l 1f,r0 */
3369 0x05, 0xd2, /* mov.l 2f,r2 */
3370 0x02, 0x60, /* mov.l @r0,r0 */
3371 0x22, 0x62, /* mov.l @r2,r2 */
3372 0x2b, 0x40, /* jmp @r0 */
3373 0x00, 0xe0, /* mov #0,r0 */
3374 0x09, 0x00, /* nop */
3375 0x09, 0x00, /* nop */
3376 0x09, 0x00, /* nop */
3377 0x09, 0x00, /* nop */
3378 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3379 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3382 /* Sebsequent entries in an absolute procedure linkage table look like
3385 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3387 0xd0, 0x04, /* mov.l 1f,r0 */
3388 0x60, 0x02, /* mov.l @r0,r0 */
3389 0xd2, 0x02, /* mov.l 0f,r2 */
3390 0x40, 0x2b, /* jmp @r0 */
3391 0x60, 0x23, /* mov r2,r0 */
3392 0xd1, 0x03, /* mov.l 2f,r1 */
3393 0x40, 0x2b, /* jmp @r0 */
3394 0x00, 0x09, /* nop */
3395 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
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. */
3400 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3402 0x04, 0xd0, /* mov.l 1f,r0 */
3403 0x02, 0x60, /* mov.l @r0,r0 */
3404 0x02, 0xd2, /* mov.l 0f,r2 */
3405 0x2b, 0x40, /* jmp @r0 */
3406 0x23, 0x60, /* mov r2,r0 */
3407 0x03, 0xd1, /* mov.l 2f,r1 */
3408 0x2b, 0x40, /* jmp @r0 */
3409 0x09, 0x00, /* nop */
3410 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3411 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3412 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3415 /* Entries in a PIC procedure linkage table look like this. */
3417 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3419 0xd0, 0x04, /* mov.l 1f,r0 */
3420 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3421 0x40, 0x2b, /* jmp @r0 */
3422 0x00, 0x09, /* nop */
3423 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3424 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3425 0xd1, 0x02, /* mov.l 2f,r1 */
3426 0x40, 0x2b, /* jmp @r0 */
3427 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3428 0x00, 0x09, /* nop */
3429 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3430 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3433 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3435 0x04, 0xd0, /* mov.l 1f,r0 */
3436 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3437 0x2b, 0x40, /* jmp @r0 */
3438 0x09, 0x00, /* nop */
3439 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3440 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3441 0x02, 0xd1, /* mov.l 2f,r1 */
3442 0x2b, 0x40, /* jmp @r0 */
3443 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3444 0x09, 0x00, /* nop */
3445 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3446 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3448 #endif /* old style PLT entries. */
3450 static const bfd_byte *elf_sh_plt0_entry;
3451 static const bfd_byte *elf_sh_plt_entry;
3452 static const bfd_byte *elf_sh_pic_plt_entry;
3454 /* Return size of a PLT entry. */
3455 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3457 /* Return offset of the PLT0 address in an absolute PLT entry. */
3458 #define elf_sh_plt_plt0_offset(info) 16
3460 /* Return offset of the linker in PLT0 entry. */
3461 #define elf_sh_plt0_linker_offset(info) 20
3463 /* Return offset of the GOT id in PLT0 entry. */
3464 #define elf_sh_plt0_gotid_offset(info) 24
3466 /* Return offset of the tempoline in PLT entry */
3467 #define elf_sh_plt_temp_offset(info) 8
3469 /* Return offset of the symbol in PLT entry. */
3470 #define elf_sh_plt_symbol_offset(info) 20
3472 /* Return offset of the relocation in PLT entry. */
3473 #define elf_sh_plt_reloc_offset(info) 24
3476 /* The sh linker needs to keep track of the number of relocs that it
3477 decides to copy as dynamic relocs in check_relocs for each symbol.
3478 This is so that it can later discard them if they are found to be
3479 unnecessary. We store the information in a field extending the
3480 regular ELF linker hash table. */
3482 struct elf_sh_dyn_relocs
3484 struct elf_sh_dyn_relocs *next;
3486 /* The input section of the reloc. */
3489 /* Total number of relocs copied for the input section. */
3490 bfd_size_type count;
3492 /* Number of pc-relative relocs copied for the input section. */
3493 bfd_size_type pc_count;
3496 /* sh ELF linker hash entry. */
3498 struct elf_sh_link_hash_entry
3500 struct elf_link_hash_entry root;
3502 #ifdef INCLUDE_SHMEDIA
3505 bfd_signed_vma refcount;
3510 /* Track dynamic relocs copied for this symbol. */
3511 struct elf_sh_dyn_relocs *dyn_relocs;
3513 bfd_signed_vma gotplt_refcount;
3516 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
3520 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3522 struct sh_elf_obj_tdata
3524 struct elf_obj_tdata root;
3526 /* tls_type for each local got entry. */
3527 char *local_got_tls_type;
3530 #define sh_elf_tdata(abfd) \
3531 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3533 #define sh_elf_local_got_tls_type(abfd) \
3534 (sh_elf_tdata (abfd)->local_got_tls_type)
3536 /* Override the generic function because we need to store sh_elf_obj_tdata
3537 as the specific tdata. */
3540 sh_elf_mkobject (bfd *abfd)
3542 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
3543 abfd->tdata.any = bfd_zalloc (abfd, amt);
3544 if (abfd->tdata.any == NULL)
3549 /* sh ELF linker hash table. */
3551 struct elf_sh_link_hash_table
3553 struct elf_link_hash_table root;
3555 /* Short-cuts to get to dynamic linker sections. */
3564 /* Small local sym to section mapping cache. */
3565 struct sym_sec_cache sym_sec;
3567 /* A counter or offset to track a TLS got entry. */
3570 bfd_signed_vma refcount;
3575 /* Traverse an sh ELF linker hash table. */
3577 #define sh_elf_link_hash_traverse(table, func, info) \
3578 (elf_link_hash_traverse \
3580 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3583 /* Get the sh ELF linker hash table from a link_info structure. */
3585 #define sh_elf_hash_table(p) \
3586 ((struct elf_sh_link_hash_table *) ((p)->hash))
3588 /* Create an entry in an sh ELF linker hash table. */
3590 static struct bfd_hash_entry *
3591 sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
3592 struct bfd_hash_table *table,
3595 struct elf_sh_link_hash_entry *ret =
3596 (struct elf_sh_link_hash_entry *) entry;
3598 /* Allocate the structure if it has not already been allocated by a
3600 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3601 ret = ((struct elf_sh_link_hash_entry *)
3602 bfd_hash_allocate (table,
3603 sizeof (struct elf_sh_link_hash_entry)));
3604 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3605 return (struct bfd_hash_entry *) ret;
3607 /* Call the allocation method of the superclass. */
3608 ret = ((struct elf_sh_link_hash_entry *)
3609 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3611 if (ret != (struct elf_sh_link_hash_entry *) NULL)
3613 ret->dyn_relocs = NULL;
3614 ret->gotplt_refcount = 0;
3615 #ifdef INCLUDE_SHMEDIA
3616 ret->datalabel_got.refcount = ret->root.got.refcount;
3618 ret->tls_type = GOT_UNKNOWN;
3621 return (struct bfd_hash_entry *) ret;
3624 /* Create an sh ELF linker hash table. */
3626 static struct bfd_link_hash_table *
3627 sh_elf_link_hash_table_create (bfd *abfd)
3629 struct elf_sh_link_hash_table *ret;
3630 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
3632 ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
3633 if (ret == (struct elf_sh_link_hash_table *) NULL)
3636 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3637 sh_elf_link_hash_newfunc))
3644 ret->sgotplt = NULL;
3645 ret->srelgot = NULL;
3647 ret->srelplt = NULL;
3648 ret->sdynbss = NULL;
3649 ret->srelbss = NULL;
3650 ret->sym_sec.abfd = NULL;
3651 ret->tls_ldm_got.refcount = 0;
3653 return &ret->root.root;
3656 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3657 shortcuts to them in our hash table. */
3660 create_got_section (bfd *dynobj, struct bfd_link_info *info)
3662 struct elf_sh_link_hash_table *htab;
3664 if (! _bfd_elf_create_got_section (dynobj, info))
3667 htab = sh_elf_hash_table (info);
3668 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3669 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3670 if (! htab->sgot || ! htab->sgotplt)
3673 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3674 if (htab->srelgot == NULL
3675 || ! bfd_set_section_flags (dynobj, htab->srelgot,
3680 | SEC_LINKER_CREATED
3682 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
3687 /* Create dynamic sections when linking against a dynamic object. */
3690 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3692 struct elf_sh_link_hash_table *htab;
3693 flagword flags, pltflags;
3694 register asection *s;
3695 struct elf_backend_data *bed = get_elf_backend_data (abfd);
3698 switch (bed->s->arch_size)
3709 bfd_set_error (bfd_error_bad_value);
3713 htab = sh_elf_hash_table (info);
3714 if (htab->root.dynamic_sections_created)
3717 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3718 .rel[a].bss sections. */
3720 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3721 | SEC_LINKER_CREATED);
3724 pltflags |= SEC_CODE;
3725 if (bed->plt_not_loaded)
3726 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3727 if (bed->plt_readonly)
3728 pltflags |= SEC_READONLY;
3730 s = bfd_make_section (abfd, ".plt");
3733 || ! bfd_set_section_flags (abfd, s, pltflags)
3734 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3737 if (bed->want_plt_sym)
3739 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3741 struct elf_link_hash_entry *h;
3742 struct bfd_link_hash_entry *bh = NULL;
3744 if (! (_bfd_generic_link_add_one_symbol
3745 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3746 (bfd_vma) 0, (const char *) NULL, FALSE,
3747 get_elf_backend_data (abfd)->collect, &bh)))
3750 h = (struct elf_link_hash_entry *) bh;
3751 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3752 h->type = STT_OBJECT;
3755 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
3759 s = bfd_make_section (abfd,
3760 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3763 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3764 || ! bfd_set_section_alignment (abfd, s, ptralign))
3767 if (htab->sgot == NULL
3768 && !create_got_section (abfd, info))
3772 const char *secname;
3777 for (sec = abfd->sections; sec; sec = sec->next)
3779 secflags = bfd_get_section_flags (abfd, sec);
3780 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3781 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3783 secname = bfd_get_section_name (abfd, sec);
3784 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3785 strcpy (relname, ".rela");
3786 strcat (relname, secname);
3787 if (bfd_get_section_by_name (abfd, secname))
3789 s = bfd_make_section (abfd, relname);
3791 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3792 || ! bfd_set_section_alignment (abfd, s, ptralign))
3797 if (bed->want_dynbss)
3799 /* The .dynbss section is a place to put symbols which are defined
3800 by dynamic objects, are referenced by regular objects, and are
3801 not functions. We must allocate space for them in the process
3802 image and use a R_*_COPY reloc to tell the dynamic linker to
3803 initialize them at run time. The linker script puts the .dynbss
3804 section into the .bss section of the final image. */
3805 s = bfd_make_section (abfd, ".dynbss");
3808 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3811 /* The .rel[a].bss section holds copy relocs. This section is not
3812 normally needed. We need to create it here, though, so that the
3813 linker will map it to an output section. We can't just create it
3814 only if we need it, because we will not know whether we need it
3815 until we have seen all the input files, and the first time the
3816 main linker code calls BFD after examining all the input files
3817 (size_dynamic_sections) the input sections have already been
3818 mapped to the output sections. If the section turns out not to
3819 be needed, we can discard it later. We will never need this
3820 section when generating a shared object, since they do not use
3824 s = bfd_make_section (abfd,
3825 (bed->default_use_rela_p
3826 ? ".rela.bss" : ".rel.bss"));
3829 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3830 || ! bfd_set_section_alignment (abfd, s, ptralign))
3838 /* Adjust a symbol defined by a dynamic object and referenced by a
3839 regular object. The current definition is in some section of the
3840 dynamic object, but we're not including those sections. We have to
3841 change the definition to something the rest of the link can
3845 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3846 struct elf_link_hash_entry *h)
3848 struct elf_sh_link_hash_table *htab;
3849 struct elf_sh_link_hash_entry *eh;
3850 struct elf_sh_dyn_relocs *p;
3852 unsigned int power_of_two;
3854 htab = sh_elf_hash_table (info);
3856 /* Make sure we know what is going on here. */
3857 BFD_ASSERT (htab->root.dynobj != NULL
3858 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
3859 || h->weakdef != NULL
3860 || ((h->elf_link_hash_flags
3861 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3862 && (h->elf_link_hash_flags
3863 & ELF_LINK_HASH_REF_REGULAR) != 0
3864 && (h->elf_link_hash_flags
3865 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3867 /* If this is a function, put it in the procedure linkage table. We
3868 will fill in the contents of the procedure linkage table later,
3869 when we know the address of the .got section. */
3870 if (h->type == STT_FUNC
3871 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3873 if (h->plt.refcount <= 0
3874 || SYMBOL_CALLS_LOCAL (info, h)
3875 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3876 && h->root.type == bfd_link_hash_undefweak))
3878 /* This case can occur if we saw a PLT reloc in an input
3879 file, but the symbol was never referred to by a dynamic
3880 object. In such a case, we don't actually need to build
3881 a procedure linkage table, and we can just do a REL32
3883 h->plt.offset = (bfd_vma) -1;
3884 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3890 h->plt.offset = (bfd_vma) -1;
3892 /* If this is a weak symbol, and there is a real definition, the
3893 processor independent code will have arranged for us to see the
3894 real definition first, and we can just use the same value. */
3895 if (h->weakdef != NULL)
3897 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3898 || h->weakdef->root.type == bfd_link_hash_defweak);
3899 h->root.u.def.section = h->weakdef->root.u.def.section;
3900 h->root.u.def.value = h->weakdef->root.u.def.value;
3901 if (info->nocopyreloc)
3902 h->elf_link_hash_flags
3903 = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
3904 | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
3908 /* This is a reference to a symbol defined by a dynamic object which
3909 is not a function. */
3911 /* If we are creating a shared library, we must presume that the
3912 only references to the symbol are via the global offset table.
3913 For such cases we need not do anything here; the relocations will
3914 be handled correctly by relocate_section. */
3918 /* If there are no references to this symbol that do not use the
3919 GOT, we don't need to generate a copy reloc. */
3920 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3923 /* If -z nocopyreloc was given, we won't generate them either. */
3924 if (info->nocopyreloc)
3926 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3930 eh = (struct elf_sh_link_hash_entry *) h;
3931 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3933 s = p->sec->output_section;
3934 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
3938 /* If we didn't find any dynamic relocs in sections which needs the
3939 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3943 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3947 /* We must allocate the symbol in our .dynbss section, which will
3948 become part of the .bss section of the executable. There will be
3949 an entry for this symbol in the .dynsym section. The dynamic
3950 object will contain position independent code, so all references
3951 from the dynamic object to this symbol will go through the global
3952 offset table. The dynamic linker will use the .dynsym entry to
3953 determine the address it must put in the global offset table, so
3954 both the dynamic object and the regular object will refer to the
3955 same memory location for the variable. */
3958 BFD_ASSERT (s != NULL);
3960 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3961 copy the initial value out of the dynamic object and into the
3962 runtime process image. We need to remember the offset into the
3963 .rela.bss section we are going to use. */
3964 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3968 srel = htab->srelbss;
3969 BFD_ASSERT (srel != NULL);
3970 srel->_raw_size += sizeof (Elf32_External_Rela);
3971 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3974 /* We need to figure out the alignment required for this symbol. I
3975 have no idea how ELF linkers handle this. */
3976 power_of_two = bfd_log2 (h->size);
3977 if (power_of_two > 3)
3980 /* Apply the required alignment. */
3981 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3982 if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
3984 if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
3988 /* Define the symbol as being at this point in the section. */
3989 h->root.u.def.section = s;
3990 h->root.u.def.value = s->_raw_size;
3992 /* Increment the section size to make room for the symbol. */
3993 s->_raw_size += h->size;
3998 /* This is the condition under which sh_elf_finish_dynamic_symbol
3999 will be called from elflink.h. If elflink.h doesn't call our
4000 finish_dynamic_symbol routine, we'll need to do something about
4001 initializing any .plt and .got entries in sh_elf_relocate_section. */
4002 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
4005 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4006 && ((H)->dynindx != -1 \
4007 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4009 /* Allocate space in .plt, .got and associated reloc sections for
4013 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4015 struct bfd_link_info *info;
4016 struct elf_sh_link_hash_table *htab;
4017 struct elf_sh_link_hash_entry *eh;
4018 struct elf_sh_dyn_relocs *p;
4020 if (h->root.type == bfd_link_hash_indirect)
4023 if (h->root.type == bfd_link_hash_warning)
4024 /* When warning symbols are created, they **replace** the "real"
4025 entry in the hash table, thus we never get to see the real
4026 symbol in a hash traversal. So look at it now. */
4027 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4029 info = (struct bfd_link_info *) inf;
4030 htab = sh_elf_hash_table (info);
4032 eh = (struct elf_sh_link_hash_entry *) h;
4033 if ((h->got.refcount > 0
4034 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
4035 && eh->gotplt_refcount > 0)
4037 /* The symbol has been forced local, or we have some direct got refs,
4038 so treat all the gotplt refs as got refs. */
4039 h->got.refcount += eh->gotplt_refcount;
4040 if (h->plt.refcount >= eh->gotplt_refcount)
4041 h->plt.refcount -= eh->gotplt_refcount;
4044 if (htab->root.dynamic_sections_created
4045 && h->plt.refcount > 0
4046 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4047 || h->root.type != bfd_link_hash_undefweak))
4049 /* Make sure this symbol is output as a dynamic symbol.
4050 Undefined weak syms won't yet be marked as dynamic. */
4051 if (h->dynindx == -1
4052 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4054 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4059 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
4061 asection *s = htab->splt;
4063 /* If this is the first .plt entry, make room for the special
4065 if (s->_raw_size == 0)
4066 s->_raw_size += PLT_ENTRY_SIZE;
4068 h->plt.offset = s->_raw_size;
4070 /* If this symbol is not defined in a regular file, and we are
4071 not generating a shared library, then set the symbol to this
4072 location in the .plt. This is required to make function
4073 pointers compare as equal between the normal executable and
4074 the shared library. */
4076 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4078 h->root.u.def.section = s;
4079 h->root.u.def.value = h->plt.offset;
4082 /* Make room for this entry. */
4083 s->_raw_size += PLT_ENTRY_SIZE;
4085 /* We also need to make an entry in the .got.plt section, which
4086 will be placed in the .got section by the linker script. */
4087 htab->sgotplt->_raw_size += 4;
4089 /* We also need to make an entry in the .rel.plt section. */
4090 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
4094 h->plt.offset = (bfd_vma) -1;
4095 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4100 h->plt.offset = (bfd_vma) -1;
4101 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4104 if (h->got.refcount > 0)
4108 int tls_type = sh_elf_hash_entry (h)->tls_type;
4110 /* Make sure this symbol is output as a dynamic symbol.
4111 Undefined weak syms won't yet be marked as dynamic. */
4112 if (h->dynindx == -1
4113 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4115 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4120 h->got.offset = s->_raw_size;
4122 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4123 if (tls_type == GOT_TLS_GD)
4125 dyn = htab->root.dynamic_sections_created;
4126 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4127 R_SH_TLS_GD needs one if local symbol and two if global. */
4128 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
4129 || (tls_type == GOT_TLS_IE && dyn))
4130 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4131 else if (tls_type == GOT_TLS_GD)
4132 htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
4133 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4134 || h->root.type != bfd_link_hash_undefweak)
4136 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
4137 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4140 h->got.offset = (bfd_vma) -1;
4142 #ifdef INCLUDE_SHMEDIA
4143 if (eh->datalabel_got.refcount > 0)
4148 /* Make sure this symbol is output as a dynamic symbol.
4149 Undefined weak syms won't yet be marked as dynamic. */
4150 if (h->dynindx == -1
4151 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4153 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4158 eh->datalabel_got.offset = s->_raw_size;
4160 dyn = htab->root.dynamic_sections_created;
4161 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
4162 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4165 eh->datalabel_got.offset = (bfd_vma) -1;
4168 if (eh->dyn_relocs == NULL)
4171 /* In the shared -Bsymbolic case, discard space allocated for
4172 dynamic pc-relative relocs against symbols which turn out to be
4173 defined in regular objects. For the normal shared case, discard
4174 space for pc-relative relocs that have become local due to symbol
4175 visibility changes. */
4179 if (SYMBOL_CALLS_LOCAL (info, h))
4181 struct elf_sh_dyn_relocs **pp;
4183 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4185 p->count -= p->pc_count;
4194 /* Also discard relocs on undefined weak syms with non-default
4196 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4197 && h->root.type == bfd_link_hash_undefweak)
4198 eh->dyn_relocs = NULL;
4202 /* For the non-shared case, discard space for relocs against
4203 symbols which turn out to need copy relocs or are not
4206 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
4207 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4208 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4209 || (htab->root.dynamic_sections_created
4210 && (h->root.type == bfd_link_hash_undefweak
4211 || h->root.type == bfd_link_hash_undefined))))
4213 /* Make sure this symbol is output as a dynamic symbol.
4214 Undefined weak syms won't yet be marked as dynamic. */
4215 if (h->dynindx == -1
4216 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4218 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4222 /* If that succeeded, we know we'll be keeping all the
4224 if (h->dynindx != -1)
4228 eh->dyn_relocs = NULL;
4233 /* Finally, allocate space. */
4234 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4236 asection *sreloc = elf_section_data (p->sec)->sreloc;
4237 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
4243 /* Find any dynamic relocs that apply to read-only sections. */
4246 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4248 struct elf_sh_link_hash_entry *eh;
4249 struct elf_sh_dyn_relocs *p;
4251 if (h->root.type == bfd_link_hash_warning)
4252 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4254 eh = (struct elf_sh_link_hash_entry *) h;
4255 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4257 asection *s = p->sec->output_section;
4259 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4261 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4263 info->flags |= DF_TEXTREL;
4265 /* Not an error, just cut short the traversal. */
4272 /* Set the sizes of the dynamic sections. */
4275 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4276 struct bfd_link_info *info)
4278 struct elf_sh_link_hash_table *htab;
4284 htab = sh_elf_hash_table (info);
4285 dynobj = htab->root.dynobj;
4286 BFD_ASSERT (dynobj != NULL);
4288 if (htab->root.dynamic_sections_created)
4290 /* Set the contents of the .interp section to the interpreter. */
4291 if (info->executable)
4293 s = bfd_get_section_by_name (dynobj, ".interp");
4294 BFD_ASSERT (s != NULL);
4295 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4296 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4300 /* Set up .got offsets for local syms, and space for local dynamic
4302 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4304 bfd_signed_vma *local_got;
4305 bfd_signed_vma *end_local_got;
4306 char *local_tls_type;
4307 bfd_size_type locsymcount;
4308 Elf_Internal_Shdr *symtab_hdr;
4311 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4314 for (s = ibfd->sections; s != NULL; s = s->next)
4316 struct elf_sh_dyn_relocs *p;
4318 for (p = ((struct elf_sh_dyn_relocs *)
4319 elf_section_data (s)->local_dynrel);
4323 if (! bfd_is_abs_section (p->sec)
4324 && bfd_is_abs_section (p->sec->output_section))
4326 /* Input section has been discarded, either because
4327 it is a copy of a linkonce section or due to
4328 linker script /DISCARD/, so we'll be discarding
4331 else if (p->count != 0)
4333 srel = elf_section_data (p->sec)->sreloc;
4334 srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
4335 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4336 info->flags |= DF_TEXTREL;
4341 local_got = elf_local_got_refcounts (ibfd);
4345 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4346 locsymcount = symtab_hdr->sh_info;
4347 #ifdef INCLUDE_SHMEDIA
4348 /* Count datalabel local GOT. */
4351 end_local_got = local_got + locsymcount;
4352 local_tls_type = sh_elf_local_got_tls_type (ibfd);
4354 srel = htab->srelgot;
4355 for (; local_got < end_local_got; ++local_got)
4359 *local_got = s->_raw_size;
4361 if (*local_tls_type == GOT_TLS_GD)
4364 srel->_raw_size += sizeof (Elf32_External_Rela);
4367 *local_got = (bfd_vma) -1;
4372 if (htab->tls_ldm_got.refcount > 0)
4374 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4376 htab->tls_ldm_got.offset = htab->sgot->_raw_size;
4377 htab->sgot->_raw_size += 8;
4378 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4381 htab->tls_ldm_got.offset = -1;
4383 /* Allocate global sym .plt and .got entries, and space for global
4384 sym dynamic relocs. */
4385 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
4387 /* We now have determined the sizes of the various dynamic sections.
4388 Allocate memory for them. */
4390 for (s = dynobj->sections; s != NULL; s = s->next)
4392 if ((s->flags & SEC_LINKER_CREATED) == 0)
4397 || s == htab->sgotplt)
4399 /* Strip this section if we don't need it; see the
4402 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4404 if (s->_raw_size != 0 && s != htab->srelplt)
4407 /* We use the reloc_count field as a counter if we need
4408 to copy relocs into the output file. */
4413 /* It's not one of our sections, so don't allocate space. */
4417 if (s->_raw_size == 0)
4419 /* If we don't need this section, strip it from the
4420 output file. This is mostly to handle .rela.bss and
4421 .rela.plt. We must create both sections in
4422 create_dynamic_sections, because they must be created
4423 before the linker maps input sections to output
4424 sections. The linker does that before
4425 adjust_dynamic_symbol is called, and it is that
4426 function which decides whether anything needs to go
4427 into these sections. */
4429 _bfd_strip_section_from_output (info, s);
4433 /* Allocate memory for the section contents. We use bfd_zalloc
4434 here in case unused entries are not reclaimed before the
4435 section's contents are written out. This should not happen,
4436 but this way if it does, we get a R_SH_NONE reloc instead
4438 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4439 if (s->contents == NULL)
4443 if (htab->root.dynamic_sections_created)
4445 /* Add some entries to the .dynamic section. We fill in the
4446 values later, in sh_elf_finish_dynamic_sections, but we
4447 must add the entries now so that we get the correct size for
4448 the .dynamic section. The DT_DEBUG entry is filled in by the
4449 dynamic linker and used by the debugger. */
4450 #define add_dynamic_entry(TAG, VAL) \
4451 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4453 if (info->executable)
4455 if (! add_dynamic_entry (DT_DEBUG, 0))
4459 if (htab->splt->_raw_size != 0)
4461 if (! add_dynamic_entry (DT_PLTGOT, 0)
4462 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
4463 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
4464 || ! add_dynamic_entry (DT_JMPREL, 0))
4470 if (! add_dynamic_entry (DT_RELA, 0)
4471 || ! add_dynamic_entry (DT_RELASZ, 0)
4472 || ! add_dynamic_entry (DT_RELAENT,
4473 sizeof (Elf32_External_Rela)))
4476 /* If any dynamic relocs apply to a read-only section,
4477 then we need a DT_TEXTREL entry. */
4478 if ((info->flags & DF_TEXTREL) == 0)
4479 elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
4481 if ((info->flags & DF_TEXTREL) != 0)
4483 if (! add_dynamic_entry (DT_TEXTREL, 0))
4488 #undef add_dynamic_entry
4493 /* Relocate an SH ELF section. */
4496 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
4497 bfd *input_bfd, asection *input_section,
4498 bfd_byte *contents, Elf_Internal_Rela *relocs,
4499 Elf_Internal_Sym *local_syms,
4500 asection **local_sections)
4502 struct elf_sh_link_hash_table *htab;
4503 Elf_Internal_Shdr *symtab_hdr;
4504 struct elf_link_hash_entry **sym_hashes;
4505 Elf_Internal_Rela *rel, *relend;
4507 bfd_vma *local_got_offsets;
4514 htab = sh_elf_hash_table (info);
4515 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4516 sym_hashes = elf_sym_hashes (input_bfd);
4517 dynobj = htab->root.dynobj;
4518 local_got_offsets = elf_local_got_offsets (input_bfd);
4521 sgotplt = htab->sgotplt;
4527 relend = relocs + input_section->reloc_count;
4528 for (; rel < relend; rel++)
4531 reloc_howto_type *howto;
4532 unsigned long r_symndx;
4533 Elf_Internal_Sym *sym;
4535 struct elf_link_hash_entry *h;
4537 bfd_vma addend = (bfd_vma) 0;
4538 bfd_reloc_status_type r;
4539 int seen_stt_datalabel = 0;
4543 r_symndx = ELF32_R_SYM (rel->r_info);
4545 r_type = ELF32_R_TYPE (rel->r_info);
4547 /* Many of the relocs are only used for relaxing, and are
4548 handled entirely by the relaxation code. */
4549 if (r_type > (int) R_SH_LAST_INVALID_RELOC
4550 && r_type < (int) R_SH_LOOP_START)
4552 if (r_type == (int) R_SH_NONE)
4556 || r_type >= R_SH_max
4557 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
4558 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
4559 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
4560 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4561 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4562 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
4563 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
4564 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
4565 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4566 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
4568 bfd_set_error (bfd_error_bad_value);
4572 howto = sh_elf_howto_table + r_type;
4574 /* For relocs that aren't partial_inplace, we get the addend from
4576 if (! howto->partial_inplace)
4577 addend = rel->r_addend;
4582 if (r_symndx < symtab_hdr->sh_info)
4584 sym = local_syms + r_symndx;
4585 sec = local_sections[r_symndx];
4586 relocation = (sec->output_section->vma
4587 + sec->output_offset
4589 /* A local symbol never has STO_SH5_ISA32, so we don't need
4590 datalabel processing here. Make sure this does not change
4592 if ((sym->st_other & STO_SH5_ISA32) != 0)
4593 ((*info->callbacks->reloc_dangerous)
4595 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4596 input_bfd, input_section, rel->r_offset));
4597 if (info->relocatable)
4599 /* This is a relocatable link. We don't have to change
4600 anything, unless the reloc is against a section symbol,
4601 in which case we have to adjust according to where the
4602 section symbol winds up in the output section. */
4603 sym = local_syms + r_symndx;
4604 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4606 if (! howto->partial_inplace)
4608 /* For relocations with the addend in the
4609 relocation, we need just to update the addend.
4610 All real relocs are of type partial_inplace; this
4611 code is mostly for completeness. */
4612 rel->r_addend += sec->output_offset + sym->st_value;
4617 /* Relocs of type partial_inplace need to pick up the
4618 contents in the contents and add the offset resulting
4619 from the changed location of the section symbol.
4620 Using _bfd_final_link_relocate (e.g. goto
4621 final_link_relocate) here would be wrong, because
4622 relocations marked pc_relative would get the current
4623 location subtracted, and we must only do that at the
4625 r = _bfd_relocate_contents (howto, input_bfd,
4628 contents + rel->r_offset);
4629 goto relocation_done;
4634 else if (! howto->partial_inplace)
4636 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4637 addend = rel->r_addend;
4639 else if ((sec->flags & SEC_MERGE)
4640 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4644 if (howto->rightshift || howto->src_mask != 0xffffffff)
4646 (*_bfd_error_handler)
4647 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4648 bfd_archive_filename (input_bfd),
4649 bfd_get_section_name (input_bfd, input_section),
4650 (long) rel->r_offset, howto->name);
4654 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4657 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4659 addend += msec->output_section->vma + msec->output_offset;
4660 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4666 /* Section symbol are never (?) placed in the hash table, so
4667 we can just ignore hash relocations when creating a
4668 relocatable object file. */
4669 if (info->relocatable)
4672 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4673 while (h->root.type == bfd_link_hash_indirect
4674 || h->root.type == bfd_link_hash_warning)
4676 #ifdef INCLUDE_SHMEDIA
4677 /* If the reference passes a symbol marked with
4678 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4680 seen_stt_datalabel |= h->type == STT_DATALABEL;
4682 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4684 if (h->root.type == bfd_link_hash_defined
4685 || h->root.type == bfd_link_hash_defweak)
4689 dyn = htab->root.dynamic_sections_created;
4690 sec = h->root.u.def.section;
4691 /* In these cases, we don't need the relocation value.
4692 We check specially because in some obscure cases
4693 sec->output_section will be NULL. */
4694 if (r_type == R_SH_GOTPC
4695 || r_type == R_SH_GOTPC_LOW16
4696 || r_type == R_SH_GOTPC_MEDLOW16
4697 || r_type == R_SH_GOTPC_MEDHI16
4698 || r_type == R_SH_GOTPC_HI16
4699 || ((r_type == R_SH_PLT32
4700 || r_type == R_SH_PLT_LOW16
4701 || r_type == R_SH_PLT_MEDLOW16
4702 || r_type == R_SH_PLT_MEDHI16
4703 || r_type == R_SH_PLT_HI16)
4704 && h->plt.offset != (bfd_vma) -1)
4705 || ((r_type == R_SH_GOT32
4706 || r_type == R_SH_GOT_LOW16
4707 || r_type == R_SH_GOT_MEDLOW16
4708 || r_type == R_SH_GOT_MEDHI16
4709 || r_type == R_SH_GOT_HI16)
4710 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4712 || (! info->symbolic && h->dynindx != -1)
4713 || (h->elf_link_hash_flags
4714 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4715 /* The cases above are those in which relocation is
4716 overwritten in the switch block below. The cases
4717 below are those in which we must defer relocation
4718 to run-time, because we can't resolve absolute
4719 addresses when creating a shared library. */
4721 && ((! info->symbolic && h->dynindx != -1)
4722 || (h->elf_link_hash_flags
4723 & ELF_LINK_HASH_DEF_REGULAR) == 0)
4724 && ((r_type == R_SH_DIR32
4725 && (h->elf_link_hash_flags
4726 & ELF_LINK_FORCED_LOCAL) == 0)
4727 || r_type == R_SH_REL32)
4728 && ((input_section->flags & SEC_ALLOC) != 0
4729 /* DWARF will emit R_SH_DIR32 relocations in its
4730 sections against symbols defined externally
4731 in shared libraries. We can't do anything
4733 || ((input_section->flags & SEC_DEBUGGING) != 0
4734 && (h->elf_link_hash_flags
4735 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
4736 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4737 sections because such sections are not SEC_ALLOC and
4738 thus ld.so will not process them. */
4739 || (sec->output_section == NULL
4740 && ((input_section->flags & SEC_DEBUGGING) != 0
4741 && (h->elf_link_hash_flags
4742 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
4743 || (sec->output_section == NULL
4744 && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
4745 || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
4747 else if (sec->output_section == NULL)
4749 (*_bfd_error_handler)
4750 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4751 bfd_archive_filename (input_bfd), h->root.root.string,
4752 bfd_get_section_name (input_bfd, input_section));
4756 relocation = ((h->root.u.def.value
4757 + sec->output_section->vma
4758 + sec->output_offset)
4759 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4760 symbol value, unless we've seen
4761 STT_DATALABEL on the way to it. */
4762 | ((h->other & STO_SH5_ISA32) != 0
4763 && ! seen_stt_datalabel));
4765 else if (h->root.type == bfd_link_hash_undefweak)
4767 else if (info->shared
4768 && ! info->no_undefined
4769 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4773 if (! ((*info->callbacks->undefined_symbol)
4774 (info, h->root.root.string, input_bfd,
4775 input_section, rel->r_offset,
4776 (!info->shared || info->no_undefined
4777 || ELF_ST_VISIBILITY (h->other)))))
4783 switch ((int) r_type)
4785 final_link_relocate:
4786 /* COFF relocs don't use the addend. The addend is used for
4787 R_SH_DIR32 to be compatible with other compilers. */
4788 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4789 contents, rel->r_offset,
4790 relocation, addend);
4794 goto final_link_relocate;
4799 /* If the reloc is against the start of this section, then
4800 the assembler has already taken care of it and the reloc
4801 is here only to assist in relaxing. If the reloc is not
4802 against the start of this section, then it's against an
4803 external symbol and we must deal with it ourselves. */
4804 if (input_section->output_section->vma + input_section->output_offset
4807 int disp = (relocation
4808 - input_section->output_section->vma
4809 - input_section->output_offset
4815 case R_SH_DIR8WPZ: mask = 1; break;
4816 case R_SH_DIR8WPL: mask = 3; break;
4817 default: mask = 0; break;
4821 ((*_bfd_error_handler)
4822 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4823 bfd_archive_filename (input_section->owner),
4824 (unsigned long) rel->r_offset));
4825 bfd_set_error (bfd_error_bad_value);
4829 goto final_link_relocate;
4835 #ifdef INCLUDE_SHMEDIA
4836 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4837 contents, rel, &relocation))
4838 goto final_link_relocate;
4840 bfd_set_error (bfd_error_bad_value);
4847 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4848 || h->root.type != bfd_link_hash_undefweak)
4850 && (input_section->flags & SEC_ALLOC) != 0
4851 && (r_type != R_SH_REL32
4852 || !SYMBOL_CALLS_LOCAL (info, h)))
4854 Elf_Internal_Rela outrel;
4856 bfd_boolean skip, relocate;
4858 /* When generating a shared object, these relocations
4859 are copied into the output file to be resolved at run
4866 name = (bfd_elf_string_from_elf_section
4868 elf_elfheader (input_bfd)->e_shstrndx,
4869 elf_section_data (input_section)->rel_hdr.sh_name));
4873 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4874 && strcmp (bfd_get_section_name (input_bfd,
4878 sreloc = bfd_get_section_by_name (dynobj, name);
4879 BFD_ASSERT (sreloc != NULL);
4886 _bfd_elf_section_offset (output_bfd, info, input_section,
4888 if (outrel.r_offset == (bfd_vma) -1)
4890 else if (outrel.r_offset == (bfd_vma) -2)
4891 skip = TRUE, relocate = TRUE;
4892 outrel.r_offset += (input_section->output_section->vma
4893 + input_section->output_offset);
4896 memset (&outrel, 0, sizeof outrel);
4897 else if (r_type == R_SH_REL32)
4899 BFD_ASSERT (h != NULL && h->dynindx != -1);
4900 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4902 = bfd_get_32 (input_bfd, contents + rel->r_offset);
4906 /* h->dynindx may be -1 if this symbol was marked to
4909 || ((info->symbolic || h->dynindx == -1)
4910 && (h->elf_link_hash_flags
4911 & ELF_LINK_HASH_DEF_REGULAR) != 0))
4914 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4916 = relocation + bfd_get_32 (input_bfd,
4917 contents + rel->r_offset);
4921 BFD_ASSERT (h->dynindx != -1);
4922 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4924 = relocation + bfd_get_32 (input_bfd,
4925 contents + rel->r_offset);
4929 loc = sreloc->contents;
4930 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4931 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4933 /* If this reloc is against an external symbol, we do
4934 not want to fiddle with the addend. Otherwise, we
4935 need to include the symbol value so that it becomes
4936 an addend for the dynamic reloc. */
4940 goto final_link_relocate;
4943 #ifdef INCLUDE_SHMEDIA
4944 case R_SH_GOTPLT_LOW16:
4945 case R_SH_GOTPLT_MEDLOW16:
4946 case R_SH_GOTPLT_MEDHI16:
4947 case R_SH_GOTPLT_HI16:
4948 case R_SH_GOTPLT10BY4:
4949 case R_SH_GOTPLT10BY8:
4951 /* Relocation is to the entry for this symbol in the
4952 procedure linkage table. */
4955 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
4959 || h->plt.offset == (bfd_vma) -1
4960 || h->got.offset != (bfd_vma) -1)
4963 /* Relocation is to the entry for this symbol in the global
4964 offset table extension for the procedure linkage table. */
4966 BFD_ASSERT (sgotplt != NULL);
4967 relocation = (sgotplt->output_offset
4968 + ((h->plt.offset / elf_sh_sizeof_plt (info)
4972 relocation -= GOT_BIAS;
4975 goto final_link_relocate;
4979 #ifdef INCLUDE_SHMEDIA
4980 case R_SH_GOT_LOW16:
4981 case R_SH_GOT_MEDLOW16:
4982 case R_SH_GOT_MEDHI16:
4987 /* Relocation is to the entry for this symbol in the global
4990 BFD_ASSERT (sgot != NULL);
4996 off = h->got.offset;
4997 #ifdef INCLUDE_SHMEDIA
4998 if (seen_stt_datalabel)
5000 struct elf_sh_link_hash_entry *hsh;
5002 hsh = (struct elf_sh_link_hash_entry *)h;
5003 off = hsh->datalabel_got.offset;
5006 BFD_ASSERT (off != (bfd_vma) -1);
5008 dyn = htab->root.dynamic_sections_created;
5009 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5011 && SYMBOL_REFERENCES_LOCAL (info, h))
5012 || (ELF_ST_VISIBILITY (h->other)
5013 && h->root.type == bfd_link_hash_undefweak))
5015 /* This is actually a static link, or it is a
5016 -Bsymbolic link and the symbol is defined
5017 locally, or the symbol was forced to be local
5018 because of a version file. We must initialize
5019 this entry in the global offset table. Since the
5020 offset must always be a multiple of 4, we use the
5021 least significant bit to record whether we have
5022 initialized it already.
5024 When doing a dynamic link, we create a .rela.got
5025 relocation entry to initialize the value. This
5026 is done in the finish_dynamic_symbol routine. */
5031 bfd_put_32 (output_bfd, relocation,
5032 sgot->contents + off);
5033 #ifdef INCLUDE_SHMEDIA
5034 if (seen_stt_datalabel)
5036 struct elf_sh_link_hash_entry *hsh;
5038 hsh = (struct elf_sh_link_hash_entry *)h;
5039 hsh->datalabel_got.offset |= 1;
5047 relocation = sgot->output_offset + off;
5051 #ifdef INCLUDE_SHMEDIA
5054 BFD_ASSERT (local_got_offsets != NULL
5055 && (local_got_offsets[symtab_hdr->sh_info
5059 off = local_got_offsets[symtab_hdr->sh_info
5065 BFD_ASSERT (local_got_offsets != NULL
5066 && local_got_offsets[r_symndx] != (bfd_vma) -1);
5068 off = local_got_offsets[r_symndx];
5069 #ifdef INCLUDE_SHMEDIA
5073 /* The offset must always be a multiple of 4. We use
5074 the least significant bit to record whether we have
5075 already generated the necessary reloc. */
5080 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5084 Elf_Internal_Rela outrel;
5087 if (srelgot == NULL)
5089 srelgot = bfd_get_section_by_name (dynobj,
5091 BFD_ASSERT (srelgot != NULL);
5094 outrel.r_offset = (sgot->output_section->vma
5095 + sgot->output_offset
5097 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5098 outrel.r_addend = relocation;
5099 loc = srelgot->contents;
5100 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5101 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5104 #ifdef INCLUDE_SHMEDIA
5106 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
5109 local_got_offsets[r_symndx] |= 1;
5112 relocation = sgot->output_offset + off;
5116 relocation -= GOT_BIAS;
5119 goto final_link_relocate;
5122 #ifdef INCLUDE_SHMEDIA
5123 case R_SH_GOTOFF_LOW16:
5124 case R_SH_GOTOFF_MEDLOW16:
5125 case R_SH_GOTOFF_MEDHI16:
5126 case R_SH_GOTOFF_HI16:
5128 /* Relocation is relative to the start of the global offset
5131 BFD_ASSERT (sgot != NULL);
5133 /* Note that sgot->output_offset is not involved in this
5134 calculation. We always want the start of .got. If we
5135 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5136 permitted by the ABI, we might have to change this
5138 relocation -= sgot->output_section->vma;
5141 relocation -= GOT_BIAS;
5144 addend = rel->r_addend;
5146 goto final_link_relocate;
5149 #ifdef INCLUDE_SHMEDIA
5150 case R_SH_GOTPC_LOW16:
5151 case R_SH_GOTPC_MEDLOW16:
5152 case R_SH_GOTPC_MEDHI16:
5153 case R_SH_GOTPC_HI16:
5155 /* Use global offset table as symbol value. */
5157 BFD_ASSERT (sgot != NULL);
5158 relocation = sgot->output_section->vma;
5161 relocation += GOT_BIAS;
5164 addend = rel->r_addend;
5166 goto final_link_relocate;
5169 #ifdef INCLUDE_SHMEDIA
5170 case R_SH_PLT_LOW16:
5171 case R_SH_PLT_MEDLOW16:
5172 case R_SH_PLT_MEDHI16:
5175 /* Relocation is to the entry for this symbol in the
5176 procedure linkage table. */
5178 /* Resolve a PLT reloc against a local symbol directly,
5179 without using the procedure linkage table. */
5181 goto final_link_relocate;
5183 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
5184 goto final_link_relocate;
5186 if (h->plt.offset == (bfd_vma) -1)
5188 /* We didn't make a PLT entry for this symbol. This
5189 happens when statically linking PIC code, or when
5190 using -Bsymbolic. */
5191 goto final_link_relocate;
5194 BFD_ASSERT (splt != NULL);
5195 relocation = (splt->output_section->vma
5196 + splt->output_offset
5199 #ifdef INCLUDE_SHMEDIA
5203 addend = rel->r_addend;
5205 goto final_link_relocate;
5207 case R_SH_LOOP_START:
5209 static bfd_vma start, end;
5211 start = (relocation + rel->r_addend
5212 - (sec->output_section->vma + sec->output_offset));
5213 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5214 rel->r_offset, sec, start, end);
5218 end = (relocation + rel->r_addend
5219 - (sec->output_section->vma + sec->output_offset));
5220 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5221 rel->r_offset, sec, start, end);
5225 case R_SH_TLS_GD_32:
5226 case R_SH_TLS_IE_32:
5227 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5228 tls_type = GOT_UNKNOWN;
5229 if (h == NULL && local_got_offsets)
5230 tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
5233 tls_type = sh_elf_hash_entry (h)->tls_type;
5235 && (h->dynindx == -1
5236 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5237 r_type = R_SH_TLS_LE_32;
5240 if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
5241 r_type = R_SH_TLS_IE_32;
5243 if (r_type == R_SH_TLS_LE_32)
5246 unsigned short insn;
5248 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5250 /* GD->LE transition:
5251 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5252 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5253 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5255 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5257 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5259 offset = rel->r_offset;
5260 BFD_ASSERT (offset >= 16);
5261 /* Size of GD instructions is 16 or 18. */
5263 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5264 if ((insn & 0xff00) == 0xc700)
5266 BFD_ASSERT (offset >= 2);
5268 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5271 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5272 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5273 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5274 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5275 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5276 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5277 BFD_ASSERT (insn == 0x310c);
5278 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5279 BFD_ASSERT (insn == 0x410b);
5280 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5281 BFD_ASSERT (insn == 0x34cc);
5283 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5284 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5285 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5286 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5287 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5293 /* IE->LE transition:
5294 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5295 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5297 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5300 offset = rel->r_offset;
5301 BFD_ASSERT (offset >= 16);
5302 /* Size of IE instructions is 10 or 12. */
5304 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5305 if ((insn & 0xf0ff) == 0x0012)
5307 BFD_ASSERT (offset >= 2);
5309 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5312 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5313 index = insn & 0x00ff;
5314 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5315 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5316 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5317 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5318 insn = 0xd000 | (insn & 0x0f00) | index;
5319 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5320 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5323 bfd_put_32 (output_bfd, tpoff (info, relocation),
5324 contents + rel->r_offset);
5333 off = h->got.offset;
5336 if (local_got_offsets == NULL)
5339 off = local_got_offsets[r_symndx];
5342 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5343 if (r_type == R_SH_TLS_IE_32
5344 && ! htab->root.dynamic_sections_created)
5347 bfd_put_32 (output_bfd, tpoff (info, relocation),
5348 sgot->contents + off);
5349 bfd_put_32 (output_bfd, sgot->output_offset + off,
5350 contents + rel->r_offset);
5358 Elf_Internal_Rela outrel;
5362 if (srelgot == NULL)
5364 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5365 BFD_ASSERT (srelgot != NULL);
5368 outrel.r_offset = (sgot->output_section->vma
5369 + sgot->output_offset + off);
5371 if (h == NULL || h->dynindx == -1)
5376 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5378 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5379 outrel.r_addend = relocation - dtpoff_base (info);
5381 outrel.r_addend = 0;
5382 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5383 loc = srelgot->contents;
5384 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5385 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5387 if (r_type == R_SH_TLS_GD_32)
5391 bfd_put_32 (output_bfd,
5392 relocation - dtpoff_base (info),
5393 sgot->contents + off + 4);
5397 outrel.r_info = ELF32_R_INFO (indx,
5399 outrel.r_offset += 4;
5400 outrel.r_addend = 0;
5401 srelgot->reloc_count++;
5402 loc += sizeof (Elf32_External_Rela);
5403 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5410 local_got_offsets[r_symndx] |= 1;
5413 if (off >= (bfd_vma) -2)
5416 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5417 relocation = sgot->output_offset + off;
5421 unsigned short insn;
5423 /* GD->IE transition:
5424 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5425 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5426 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5428 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5429 nop; nop; bra 3f; nop; .align 2;
5430 1: .long x@TPOFF; 2:...; 3:. */
5432 offset = rel->r_offset;
5433 BFD_ASSERT (offset >= 16);
5434 /* Size of GD instructions is 16 or 18. */
5436 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5437 if ((insn & 0xff00) == 0xc700)
5439 BFD_ASSERT (offset >= 2);
5441 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5444 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5446 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5447 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5449 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5450 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5451 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5452 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5453 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5454 BFD_ASSERT (insn == 0x310c);
5455 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5456 BFD_ASSERT (insn == 0x410b);
5457 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5458 BFD_ASSERT (insn == 0x34cc);
5460 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5461 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5462 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5463 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5464 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5466 bfd_put_32 (output_bfd, sgot->output_offset + off,
5467 contents + rel->r_offset);
5472 addend = rel->r_addend;
5474 goto final_link_relocate;
5476 case R_SH_TLS_LD_32:
5480 unsigned short insn;
5482 /* LD->LE transition:
5483 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5484 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5485 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5487 stc gbr,r0; nop; nop; nop;
5488 nop; nop; bra 3f; ...; 3:. */
5490 offset = rel->r_offset;
5491 BFD_ASSERT (offset >= 16);
5492 /* Size of LD instructions is 16 or 18. */
5494 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5495 if ((insn & 0xff00) == 0xc700)
5497 BFD_ASSERT (offset >= 2);
5499 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5502 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5503 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5504 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5505 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5506 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5507 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5508 BFD_ASSERT (insn == 0x310c);
5509 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5510 BFD_ASSERT (insn == 0x410b);
5511 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5512 BFD_ASSERT (insn == 0x34cc);
5514 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5515 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5516 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5517 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5518 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5519 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5528 off = htab->tls_ldm_got.offset;
5533 Elf_Internal_Rela outrel;
5536 srelgot = htab->srelgot;
5537 if (srelgot == NULL)
5540 outrel.r_offset = (sgot->output_section->vma
5541 + sgot->output_offset + off);
5542 outrel.r_addend = 0;
5543 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5544 loc = srelgot->contents;
5545 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5546 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5547 htab->tls_ldm_got.offset |= 1;
5550 relocation = sgot->output_offset + off;
5551 addend = rel->r_addend;
5553 goto final_link_relocate;
5555 case R_SH_TLS_LDO_32:
5557 relocation = tpoff (info, relocation);
5559 relocation -= dtpoff_base (info);
5561 addend = rel->r_addend;
5562 goto final_link_relocate;
5564 case R_SH_TLS_LE_32:
5567 Elf_Internal_Rela outrel;
5572 relocation = tpoff (info, relocation);
5573 addend = rel->r_addend;
5574 goto final_link_relocate;
5581 name = (bfd_elf_string_from_elf_section
5583 elf_elfheader (input_bfd)->e_shstrndx,
5584 elf_section_data (input_section)->rel_hdr.sh_name));
5588 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5589 && strcmp (bfd_get_section_name (input_bfd,
5593 sreloc = bfd_get_section_by_name (dynobj, name);
5594 BFD_ASSERT (sreloc != NULL);
5597 if (h == NULL || h->dynindx == -1)
5602 outrel.r_offset = (input_section->output_section->vma
5603 + input_section->output_offset
5605 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5607 outrel.r_addend = relocation - dtpoff_base (info);
5609 outrel.r_addend = 0;
5611 loc = sreloc->contents;
5612 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5613 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5619 if (r != bfd_reloc_ok)
5624 case bfd_reloc_outofrange:
5626 case bfd_reloc_overflow:
5631 name = h->root.root.string;
5634 name = (bfd_elf_string_from_elf_section
5635 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5639 name = bfd_section_name (input_bfd, sec);
5641 if (! ((*info->callbacks->reloc_overflow)
5642 (info, name, howto->name, (bfd_vma) 0,
5643 input_bfd, input_section, rel->r_offset)))
5654 /* This is a version of bfd_generic_get_relocated_section_contents
5655 which uses sh_elf_relocate_section. */
5658 sh_elf_get_relocated_section_contents (bfd *output_bfd,
5659 struct bfd_link_info *link_info,
5660 struct bfd_link_order *link_order,
5662 bfd_boolean relocatable,
5665 Elf_Internal_Shdr *symtab_hdr;
5666 asection *input_section = link_order->u.indirect.section;
5667 bfd *input_bfd = input_section->owner;
5668 asection **sections = NULL;
5669 Elf_Internal_Rela *internal_relocs = NULL;
5670 Elf_Internal_Sym *isymbuf = NULL;
5672 /* We only need to handle the case of relaxing, or of having a
5673 particular set of section contents, specially. */
5675 || elf_section_data (input_section)->this_hdr.contents == NULL)
5676 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5681 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5683 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5684 (size_t) input_section->_raw_size);
5686 if ((input_section->flags & SEC_RELOC) != 0
5687 && input_section->reloc_count > 0)
5690 Elf_Internal_Sym *isym, *isymend;
5693 internal_relocs = (_bfd_elf_link_read_relocs
5694 (input_bfd, input_section, NULL,
5695 (Elf_Internal_Rela *) NULL, FALSE));
5696 if (internal_relocs == NULL)
5699 if (symtab_hdr->sh_info != 0)
5701 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5702 if (isymbuf == NULL)
5703 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5704 symtab_hdr->sh_info, 0,
5706 if (isymbuf == NULL)
5710 amt = symtab_hdr->sh_info;
5711 amt *= sizeof (asection *);
5712 sections = (asection **) bfd_malloc (amt);
5713 if (sections == NULL && amt != 0)
5716 isymend = isymbuf + symtab_hdr->sh_info;
5717 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5721 if (isym->st_shndx == SHN_UNDEF)
5722 isec = bfd_und_section_ptr;
5723 else if (isym->st_shndx == SHN_ABS)
5724 isec = bfd_abs_section_ptr;
5725 else if (isym->st_shndx == SHN_COMMON)
5726 isec = bfd_com_section_ptr;
5728 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5733 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5734 input_section, data, internal_relocs,
5738 if (sections != NULL)
5741 && symtab_hdr->contents != (unsigned char *) isymbuf)
5743 if (elf_section_data (input_section)->relocs != internal_relocs)
5744 free (internal_relocs);
5750 if (sections != NULL)
5753 && symtab_hdr->contents != (unsigned char *) isymbuf)
5755 if (internal_relocs != NULL
5756 && elf_section_data (input_section)->relocs != internal_relocs)
5757 free (internal_relocs);
5761 /* Return the base VMA address which should be subtracted from real addresses
5762 when resolving @dtpoff relocation.
5763 This is PT_TLS segment p_vaddr. */
5766 dtpoff_base (struct bfd_link_info *info)
5768 /* If tls_segment is NULL, we should have signalled an error already. */
5769 if (elf_hash_table (info)->tls_segment == NULL)
5771 return elf_hash_table (info)->tls_segment->start;
5774 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5777 tpoff (struct bfd_link_info *info, bfd_vma address)
5779 /* If tls_segment is NULL, we should have signalled an error already. */
5780 if (elf_hash_table (info)->tls_segment == NULL)
5782 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5783 structure which has 2 pointer fields. */
5784 return (address - dtpoff_base (info) + 8);
5788 sh_elf_gc_mark_hook (asection *sec,
5789 struct bfd_link_info *info ATTRIBUTE_UNUSED,
5790 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
5791 Elf_Internal_Sym *sym)
5795 switch (ELF32_R_TYPE (rel->r_info))
5797 case R_SH_GNU_VTINHERIT:
5798 case R_SH_GNU_VTENTRY:
5802 #ifdef INCLUDE_SHMEDIA
5803 while (h->root.type == bfd_link_hash_indirect
5804 && h->root.u.i.link)
5805 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5807 switch (h->root.type)
5809 case bfd_link_hash_defined:
5810 case bfd_link_hash_defweak:
5811 return h->root.u.def.section;
5813 case bfd_link_hash_common:
5814 return h->root.u.c.p->section;
5822 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5827 /* Update the got entry reference counts for the section being removed. */
5830 sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
5831 asection *sec, const Elf_Internal_Rela *relocs)
5833 Elf_Internal_Shdr *symtab_hdr;
5834 struct elf_link_hash_entry **sym_hashes;
5835 bfd_signed_vma *local_got_refcounts;
5836 const Elf_Internal_Rela *rel, *relend;
5838 elf_section_data (sec)->local_dynrel = NULL;
5840 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5841 sym_hashes = elf_sym_hashes (abfd);
5842 local_got_refcounts = elf_local_got_refcounts (abfd);
5844 relend = relocs + sec->reloc_count;
5845 for (rel = relocs; rel < relend; rel++)
5847 unsigned long r_symndx;
5848 unsigned int r_type;
5849 struct elf_link_hash_entry *h = NULL;
5850 #ifdef INCLUDE_SHMEDIA
5851 int seen_stt_datalabel = 0;
5854 r_symndx = ELF32_R_SYM (rel->r_info);
5855 if (r_symndx >= symtab_hdr->sh_info)
5857 struct elf_sh_link_hash_entry *eh;
5858 struct elf_sh_dyn_relocs **pp;
5859 struct elf_sh_dyn_relocs *p;
5861 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5862 #ifdef INCLUDE_SHMEDIA
5863 while (h->root.type == bfd_link_hash_indirect
5864 || h->root.type == bfd_link_hash_warning)
5866 seen_stt_datalabel |= h->type == STT_DATALABEL;
5867 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5870 eh = (struct elf_sh_link_hash_entry *) h;
5871 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5874 /* Everything must go for SEC. */
5880 r_type = ELF32_R_TYPE (rel->r_info);
5881 switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
5883 case R_SH_TLS_LD_32:
5884 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
5885 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
5891 #ifdef INCLUDE_SHMEDIA
5892 case R_SH_GOT_LOW16:
5893 case R_SH_GOT_MEDLOW16:
5894 case R_SH_GOT_MEDHI16:
5898 case R_SH_GOTOFF_LOW16:
5899 case R_SH_GOTOFF_MEDLOW16:
5900 case R_SH_GOTOFF_MEDHI16:
5901 case R_SH_GOTOFF_HI16:
5902 case R_SH_GOTPC_LOW16:
5903 case R_SH_GOTPC_MEDLOW16:
5904 case R_SH_GOTPC_MEDHI16:
5905 case R_SH_GOTPC_HI16:
5907 case R_SH_TLS_GD_32:
5908 case R_SH_TLS_IE_32:
5911 #ifdef INCLUDE_SHMEDIA
5912 if (seen_stt_datalabel)
5914 struct elf_sh_link_hash_entry *eh;
5915 eh = (struct elf_sh_link_hash_entry *) h;
5916 if (eh->datalabel_got.refcount > 0)
5917 eh->datalabel_got.refcount -= 1;
5921 if (h->got.refcount > 0)
5922 h->got.refcount -= 1;
5924 else if (local_got_refcounts != NULL)
5926 #ifdef INCLUDE_SHMEDIA
5927 if (rel->r_addend & 1)
5929 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5930 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5934 if (local_got_refcounts[r_symndx] > 0)
5935 local_got_refcounts[r_symndx] -= 1;
5946 #ifdef INCLUDE_SHMEDIA
5947 case R_SH_PLT_LOW16:
5948 case R_SH_PLT_MEDLOW16:
5949 case R_SH_PLT_MEDHI16:
5954 if (h->plt.refcount > 0)
5955 h->plt.refcount -= 1;
5960 #ifdef INCLUDE_SHMEDIA
5961 case R_SH_GOTPLT_LOW16:
5962 case R_SH_GOTPLT_MEDLOW16:
5963 case R_SH_GOTPLT_MEDHI16:
5964 case R_SH_GOTPLT_HI16:
5965 case R_SH_GOTPLT10BY4:
5966 case R_SH_GOTPLT10BY8:
5970 struct elf_sh_link_hash_entry *eh;
5971 eh = (struct elf_sh_link_hash_entry *) h;
5972 if (eh->gotplt_refcount > 0)
5974 eh->gotplt_refcount -= 1;
5975 if (h->plt.refcount > 0)
5976 h->plt.refcount -= 1;
5978 #ifdef INCLUDE_SHMEDIA
5979 else if (seen_stt_datalabel)
5981 if (eh->datalabel_got.refcount > 0)
5982 eh->datalabel_got.refcount -= 1;
5985 else if (h->got.refcount > 0)
5986 h->got.refcount -= 1;
5988 else if (local_got_refcounts != NULL)
5990 #ifdef INCLUDE_SHMEDIA
5991 if (rel->r_addend & 1)
5993 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5994 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5998 if (local_got_refcounts[r_symndx] > 0)
5999 local_got_refcounts[r_symndx] -= 1;
6011 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6014 sh_elf_copy_indirect_symbol (struct elf_backend_data *bed,
6015 struct elf_link_hash_entry *dir,
6016 struct elf_link_hash_entry *ind)
6018 struct elf_sh_link_hash_entry *edir, *eind;
6019 #ifdef INCLUDE_SHMEDIA
6023 edir = (struct elf_sh_link_hash_entry *) dir;
6024 eind = (struct elf_sh_link_hash_entry *) ind;
6026 if (eind->dyn_relocs != NULL)
6028 if (edir->dyn_relocs != NULL)
6030 struct elf_sh_dyn_relocs **pp;
6031 struct elf_sh_dyn_relocs *p;
6033 BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
6035 /* Add reloc counts against the weak sym to the strong sym
6036 list. Merge any entries against the same section. */
6037 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
6039 struct elf_sh_dyn_relocs *q;
6041 for (q = edir->dyn_relocs; q != NULL; q = q->next)
6042 if (q->sec == p->sec)
6044 q->pc_count += p->pc_count;
6045 q->count += p->count;
6052 *pp = edir->dyn_relocs;
6055 edir->dyn_relocs = eind->dyn_relocs;
6056 eind->dyn_relocs = NULL;
6058 edir->gotplt_refcount = eind->gotplt_refcount;
6059 eind->gotplt_refcount = 0;
6060 #ifdef INCLUDE_SHMEDIA
6061 tmp = edir->datalabel_got.refcount;
6064 edir->datalabel_got.refcount = eind->datalabel_got.refcount;
6065 eind->datalabel_got.refcount = tmp;
6068 BFD_ASSERT (eind->datalabel_got.refcount < 1);
6071 if (ind->root.type == bfd_link_hash_indirect
6072 && dir->got.refcount <= 0)
6074 edir->tls_type = eind->tls_type;
6075 eind->tls_type = GOT_UNKNOWN;
6078 if (ind->root.type != bfd_link_hash_indirect
6079 && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
6080 /* If called to transfer flags for a weakdef during processing
6081 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
6082 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6083 dir->elf_link_hash_flags |=
6084 (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
6085 | ELF_LINK_HASH_REF_REGULAR
6086 | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
6088 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
6092 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
6100 case R_SH_TLS_GD_32:
6101 case R_SH_TLS_IE_32:
6103 return R_SH_TLS_LE_32;
6104 return R_SH_TLS_IE_32;
6105 case R_SH_TLS_LD_32:
6106 return R_SH_TLS_LE_32;
6112 /* Look through the relocs for a section during the first phase.
6113 Since we don't do .gots or .plts, we just need to consider the
6114 virtual table relocs for gc. */
6117 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
6118 const Elf_Internal_Rela *relocs)
6120 Elf_Internal_Shdr *symtab_hdr;
6121 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6122 struct elf_sh_link_hash_table *htab;
6123 const Elf_Internal_Rela *rel;
6124 const Elf_Internal_Rela *rel_end;
6125 bfd_vma *local_got_offsets;
6129 unsigned int r_type;
6130 int tls_type, old_tls_type;
6136 if (info->relocatable)
6139 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6140 sym_hashes = elf_sym_hashes (abfd);
6141 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
6142 if (!elf_bad_symtab (abfd))
6143 sym_hashes_end -= symtab_hdr->sh_info;
6145 htab = sh_elf_hash_table (info);
6146 local_got_offsets = elf_local_got_offsets (abfd);
6148 rel_end = relocs + sec->reloc_count;
6149 for (rel = relocs; rel < rel_end; rel++)
6151 struct elf_link_hash_entry *h;
6152 unsigned long r_symndx;
6153 #ifdef INCLUDE_SHMEDIA
6154 int seen_stt_datalabel = 0;
6157 r_symndx = ELF32_R_SYM (rel->r_info);
6158 r_type = ELF32_R_TYPE (rel->r_info);
6160 if (r_symndx < symtab_hdr->sh_info)
6164 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6165 #ifdef INCLUDE_SHMEDIA
6166 while (h->root.type == bfd_link_hash_indirect
6167 || h->root.type == bfd_link_hash_warning)
6169 seen_stt_datalabel |= h->type == STT_DATALABEL;
6170 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6175 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6177 && r_type == R_SH_TLS_IE_32
6179 && h->root.type != bfd_link_hash_undefined
6180 && h->root.type != bfd_link_hash_undefweak
6181 && (h->dynindx == -1
6182 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6183 r_type = R_SH_TLS_LE_32;
6185 /* Some relocs require a global offset table. */
6186 if (htab->sgot == NULL)
6194 #ifdef INCLUDE_SHMEDIA
6195 case R_SH_GOTPLT_LOW16:
6196 case R_SH_GOTPLT_MEDLOW16:
6197 case R_SH_GOTPLT_MEDHI16:
6198 case R_SH_GOTPLT_HI16:
6199 case R_SH_GOTPLT10BY4:
6200 case R_SH_GOTPLT10BY8:
6201 case R_SH_GOT_LOW16:
6202 case R_SH_GOT_MEDLOW16:
6203 case R_SH_GOT_MEDHI16:
6207 case R_SH_GOTOFF_LOW16:
6208 case R_SH_GOTOFF_MEDLOW16:
6209 case R_SH_GOTOFF_MEDHI16:
6210 case R_SH_GOTOFF_HI16:
6211 case R_SH_GOTPC_LOW16:
6212 case R_SH_GOTPC_MEDLOW16:
6213 case R_SH_GOTPC_MEDHI16:
6214 case R_SH_GOTPC_HI16:
6216 case R_SH_TLS_GD_32:
6217 case R_SH_TLS_LD_32:
6218 case R_SH_TLS_IE_32:
6219 if (htab->sgot == NULL)
6221 if (htab->root.dynobj == NULL)
6222 htab->root.dynobj = abfd;
6223 if (!create_got_section (htab->root.dynobj, info))
6235 /* This relocation describes the C++ object vtable hierarchy.
6236 Reconstruct it for later use during GC. */
6237 case R_SH_GNU_VTINHERIT:
6238 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6242 /* This relocation describes which C++ vtable entries are actually
6243 used. Record for later use during GC. */
6244 case R_SH_GNU_VTENTRY:
6245 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6249 case R_SH_TLS_IE_32:
6251 info->flags |= DF_STATIC_TLS;
6255 case R_SH_TLS_GD_32:
6257 #ifdef INCLUDE_SHMEDIA
6258 case R_SH_GOT_LOW16:
6259 case R_SH_GOT_MEDLOW16:
6260 case R_SH_GOT_MEDHI16:
6268 tls_type = GOT_NORMAL;
6270 case R_SH_TLS_GD_32:
6271 tls_type = GOT_TLS_GD;
6273 case R_SH_TLS_IE_32:
6274 tls_type = GOT_TLS_IE;
6280 #ifdef INCLUDE_SHMEDIA
6281 if (seen_stt_datalabel)
6283 struct elf_sh_link_hash_entry *eh
6284 = (struct elf_sh_link_hash_entry *) h;
6286 eh->datalabel_got.refcount += 1;
6290 h->got.refcount += 1;
6291 old_tls_type = sh_elf_hash_entry (h)->tls_type;
6295 bfd_signed_vma *local_got_refcounts;
6297 /* This is a global offset table entry for a local
6299 local_got_refcounts = elf_local_got_refcounts (abfd);
6300 if (local_got_refcounts == NULL)
6304 size = symtab_hdr->sh_info;
6305 size *= sizeof (bfd_signed_vma);
6306 #ifdef INCLUDE_SHMEDIA
6307 /* Reserve space for both the datalabel and
6308 codelabel local GOT offsets. */
6311 size += symtab_hdr->sh_info;
6312 local_got_refcounts = ((bfd_signed_vma *)
6313 bfd_zalloc (abfd, size));
6314 if (local_got_refcounts == NULL)
6316 elf_local_got_refcounts (abfd) = local_got_refcounts;
6317 #ifdef INCLUDE_SHMEDIA
6318 /* Take care of both the datalabel and codelabel local
6320 sh_elf_local_got_tls_type (abfd)
6321 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6323 sh_elf_local_got_tls_type (abfd)
6324 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6327 #ifdef INCLUDE_SHMEDIA
6328 if (rel->r_addend & 1)
6329 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6332 local_got_refcounts[r_symndx] += 1;
6333 old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
6336 /* If a TLS symbol is accessed using IE at least once,
6337 there is no point to use dynamic model for it. */
6338 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
6339 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
6341 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
6342 tls_type = GOT_TLS_IE;
6345 (*_bfd_error_handler)
6346 (_("%s: `%s' accessed both as normal and thread local symbol"),
6347 bfd_archive_filename (abfd), h->root.root.string);
6352 if (old_tls_type != tls_type)
6355 sh_elf_hash_entry (h)->tls_type = tls_type;
6357 sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
6362 case R_SH_TLS_LD_32:
6363 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6367 #ifdef INCLUDE_SHMEDIA
6368 case R_SH_GOTPLT_LOW16:
6369 case R_SH_GOTPLT_MEDLOW16:
6370 case R_SH_GOTPLT_MEDHI16:
6371 case R_SH_GOTPLT_HI16:
6372 case R_SH_GOTPLT10BY4:
6373 case R_SH_GOTPLT10BY8:
6375 /* If this is a local symbol, we resolve it directly without
6376 creating a procedure linkage table entry. */
6379 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6382 || h->dynindx == -1)
6385 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6386 h->plt.refcount += 1;
6387 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6392 #ifdef INCLUDE_SHMEDIA
6393 case R_SH_PLT_LOW16:
6394 case R_SH_PLT_MEDLOW16:
6395 case R_SH_PLT_MEDHI16:
6398 /* This symbol requires a procedure linkage table entry. We
6399 actually build the entry in adjust_dynamic_symbol,
6400 because this might be a case of linking PIC code which is
6401 never referenced by a dynamic object, in which case we
6402 don't need to generate a procedure linkage table entry
6405 /* If this is a local symbol, we resolve it directly without
6406 creating a procedure linkage table entry. */
6410 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6413 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6414 h->plt.refcount += 1;
6419 if (h != NULL && ! info->shared)
6421 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
6422 h->plt.refcount += 1;
6425 /* If we are creating a shared library, and this is a reloc
6426 against a global symbol, or a non PC relative reloc
6427 against a local symbol, then we need to copy the reloc
6428 into the shared library. However, if we are linking with
6429 -Bsymbolic, we do not need to copy a reloc against a
6430 global symbol which is defined in an object we are
6431 including in the link (i.e., DEF_REGULAR is set). At
6432 this point we have not seen all the input files, so it is
6433 possible that DEF_REGULAR is not set now but will be set
6434 later (it is never cleared). We account for that
6435 possibility below by storing information in the
6436 dyn_relocs field of the hash table entry. A similar
6437 situation occurs when creating shared libraries and symbol
6438 visibility changes render the symbol local.
6440 If on the other hand, we are creating an executable, we
6441 may need to keep relocations for symbols satisfied by a
6442 dynamic library if we manage to avoid copy relocs for the
6445 && (sec->flags & SEC_ALLOC) != 0
6446 && (r_type != R_SH_REL32
6448 && (! info->symbolic
6449 || h->root.type == bfd_link_hash_defweak
6450 || (h->elf_link_hash_flags
6451 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
6453 && (sec->flags & SEC_ALLOC) != 0
6455 && (h->root.type == bfd_link_hash_defweak
6456 || (h->elf_link_hash_flags
6457 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
6459 struct elf_sh_dyn_relocs *p;
6460 struct elf_sh_dyn_relocs **head;
6462 if (htab->root.dynobj == NULL)
6463 htab->root.dynobj = abfd;
6465 /* When creating a shared object, we must copy these
6466 reloc types into the output file. We create a reloc
6467 section in dynobj and make room for this reloc. */
6472 name = (bfd_elf_string_from_elf_section
6474 elf_elfheader (abfd)->e_shstrndx,
6475 elf_section_data (sec)->rel_hdr.sh_name));
6479 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6480 && strcmp (bfd_get_section_name (abfd, sec),
6483 sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
6488 sreloc = bfd_make_section (htab->root.dynobj, name);
6489 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6490 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6491 if ((sec->flags & SEC_ALLOC) != 0)
6492 flags |= SEC_ALLOC | SEC_LOAD;
6494 || ! bfd_set_section_flags (htab->root.dynobj,
6496 || ! bfd_set_section_alignment (htab->root.dynobj,
6500 elf_section_data (sec)->sreloc = sreloc;
6503 /* If this is a global symbol, we count the number of
6504 relocations we need for this symbol. */
6506 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6511 /* Track dynamic relocs needed for local syms too. */
6512 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6517 head = ((struct elf_sh_dyn_relocs **)
6518 &elf_section_data (s)->local_dynrel);
6522 if (p == NULL || p->sec != sec)
6524 bfd_size_type amt = sizeof (*p);
6525 p = bfd_alloc (htab->root.dynobj, amt);
6536 if (r_type == R_SH_REL32)
6542 case R_SH_TLS_LE_32:
6545 (*_bfd_error_handler) (_("%s: TLS local exec code cannot be linked into shared objects"),
6546 bfd_archive_filename (abfd));
6552 case R_SH_TLS_LDO_32:
6553 /* Nothing to do. */
6564 #ifndef sh_elf_set_mach_from_flags
6566 sh_elf_set_mach_from_flags (bfd *abfd)
6568 flagword flags = elf_elfheader (abfd)->e_flags;
6570 switch (flags & EF_SH_MACH_MASK)
6573 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh);
6576 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
6579 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2e);
6582 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);
6585 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3);
6588 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp);
6591 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e);
6595 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);
6602 #endif /* not sh_elf_set_mach_from_flags */
6604 #ifndef sh_elf_set_private_flags
6605 /* Function to keep SH specific file flags. */
6608 sh_elf_set_private_flags (bfd *abfd, flagword flags)
6610 BFD_ASSERT (! elf_flags_init (abfd)
6611 || elf_elfheader (abfd)->e_flags == flags);
6613 elf_elfheader (abfd)->e_flags = flags;
6614 elf_flags_init (abfd) = TRUE;
6615 return sh_elf_set_mach_from_flags (abfd);
6617 #endif /* not sh_elf_set_private_flags */
6619 #ifndef sh_elf_copy_private_data
6620 /* Copy backend specific data from one object module to another */
6623 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
6625 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6626 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6629 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
6631 #endif /* not sh_elf_copy_private_data */
6633 #ifndef sh_elf_merge_private_data
6634 /* This routine checks for linking big and little endian objects
6635 together, and for linking sh-dsp with sh3e / sh4 objects. */
6638 sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
6640 flagword old_flags, new_flags;
6642 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
6645 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6646 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6649 if (! elf_flags_init (obfd))
6651 /* This happens when ld starts out with a 'blank' output file. */
6652 elf_flags_init (obfd) = TRUE;
6653 elf_elfheader (obfd)->e_flags = EF_SH1;
6655 old_flags = elf_elfheader (obfd)->e_flags;
6656 new_flags = elf_elfheader (ibfd)->e_flags;
6657 if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags))
6658 || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags)))
6660 (*_bfd_error_handler)
6661 ("%s: uses %s instructions while previous modules use %s instructions",
6662 bfd_archive_filename (ibfd),
6663 EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",
6664 EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");
6665 bfd_set_error (bfd_error_bad_value);
6668 elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);
6670 return sh_elf_set_mach_from_flags (obfd);
6672 #endif /* not sh_elf_merge_private_data */
6674 /* Override the generic function because we need to store sh_elf_obj_tdata
6675 as the specific tdata. We set also the machine architecture from flags
6679 sh_elf_object_p (bfd *abfd)
6681 struct sh_elf_obj_tdata *new_tdata;
6682 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
6684 if (!sh_elf_set_mach_from_flags (abfd))
6687 /* Allocate our special target data. */
6688 new_tdata = bfd_zalloc (abfd, amt);
6689 if (new_tdata == NULL)
6691 new_tdata->root = *abfd->tdata.elf_obj_data;
6692 abfd->tdata.any = new_tdata;
6696 /* Finish up dynamic symbol handling. We set the contents of various
6697 dynamic sections here. */
6700 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6701 struct elf_link_hash_entry *h,
6702 Elf_Internal_Sym *sym)
6704 struct elf_sh_link_hash_table *htab;
6706 htab = sh_elf_hash_table (info);
6708 if (h->plt.offset != (bfd_vma) -1)
6716 Elf_Internal_Rela rel;
6719 /* This symbol has an entry in the procedure linkage table. Set
6722 BFD_ASSERT (h->dynindx != -1);
6725 sgot = htab->sgotplt;
6726 srel = htab->srelplt;
6727 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
6729 /* Get the index in the procedure linkage table which
6730 corresponds to this symbol. This is the index of this symbol
6731 in all the symbols for which we are making plt entries. The
6732 first entry in the procedure linkage table is reserved. */
6733 plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1;
6735 /* Get the offset into the .got table of the entry that
6736 corresponds to this function. Each .got entry is 4 bytes.
6737 The first three are reserved. */
6738 got_offset = (plt_index + 3) * 4;
6742 got_offset -= GOT_BIAS;
6745 /* Fill in the entry in the procedure linkage table. */
6748 if (elf_sh_plt_entry == NULL)
6750 elf_sh_plt_entry = (bfd_big_endian (output_bfd) ?
6751 elf_sh_plt_entry_be : elf_sh_plt_entry_le);
6753 memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
6754 elf_sh_sizeof_plt (info));
6755 #ifdef INCLUDE_SHMEDIA
6756 movi_shori_putval (output_bfd,
6757 (sgot->output_section->vma
6758 + sgot->output_offset
6760 (splt->contents + h->plt.offset
6761 + elf_sh_plt_symbol_offset (info)));
6763 /* Set bottom bit because its for a branch to SHmedia */
6764 movi_shori_putval (output_bfd,
6765 (splt->output_section->vma + splt->output_offset)
6767 (splt->contents + h->plt.offset
6768 + elf_sh_plt_plt0_offset (info)));
6770 bfd_put_32 (output_bfd,
6771 (sgot->output_section->vma
6772 + sgot->output_offset
6774 (splt->contents + h->plt.offset
6775 + elf_sh_plt_symbol_offset (info)));
6777 bfd_put_32 (output_bfd,
6778 (splt->output_section->vma + splt->output_offset),
6779 (splt->contents + h->plt.offset
6780 + elf_sh_plt_plt0_offset (info)));
6785 if (elf_sh_pic_plt_entry == NULL)
6787 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
6788 elf_sh_pic_plt_entry_be :
6789 elf_sh_pic_plt_entry_le);
6791 memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
6792 elf_sh_sizeof_plt (info));
6793 #ifdef INCLUDE_SHMEDIA
6794 movi_shori_putval (output_bfd, got_offset,
6795 (splt->contents + h->plt.offset
6796 + elf_sh_plt_symbol_offset (info)));
6798 bfd_put_32 (output_bfd, got_offset,
6799 (splt->contents + h->plt.offset
6800 + elf_sh_plt_symbol_offset (info)));
6806 got_offset += GOT_BIAS;
6809 #ifdef INCLUDE_SHMEDIA
6810 movi_shori_putval (output_bfd,
6811 plt_index * sizeof (Elf32_External_Rela),
6812 (splt->contents + h->plt.offset
6813 + elf_sh_plt_reloc_offset (info)));
6815 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
6816 (splt->contents + h->plt.offset
6817 + elf_sh_plt_reloc_offset (info)));
6820 /* Fill in the entry in the global offset table. */
6821 bfd_put_32 (output_bfd,
6822 (splt->output_section->vma
6823 + splt->output_offset
6825 + elf_sh_plt_temp_offset (info)),
6826 sgot->contents + got_offset);
6828 /* Fill in the entry in the .rela.plt section. */
6829 rel.r_offset = (sgot->output_section->vma
6830 + sgot->output_offset
6832 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
6835 rel.r_addend = GOT_BIAS;
6837 loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
6838 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6840 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
6842 /* Mark the symbol as undefined, rather than as defined in
6843 the .plt section. Leave the value alone. */
6844 sym->st_shndx = SHN_UNDEF;
6848 if (h->got.offset != (bfd_vma) -1
6849 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
6850 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
6854 Elf_Internal_Rela rel;
6857 /* This symbol has an entry in the global offset table. Set it
6861 srel = htab->srelgot;
6862 BFD_ASSERT (sgot != NULL && srel != NULL);
6864 rel.r_offset = (sgot->output_section->vma
6865 + sgot->output_offset
6866 + (h->got.offset &~ (bfd_vma) 1));
6868 /* If this is a static link, or it is a -Bsymbolic link and the
6869 symbol is defined locally or was forced to be local because
6870 of a version file, we just want to emit a RELATIVE reloc.
6871 The entry in the global offset table will already have been
6872 initialized in the relocate_section function. */
6874 && SYMBOL_REFERENCES_LOCAL (info, h))
6876 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6877 rel.r_addend = (h->root.u.def.value
6878 + h->root.u.def.section->output_section->vma
6879 + h->root.u.def.section->output_offset);
6883 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6884 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6888 loc = srel->contents;
6889 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
6890 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6893 #ifdef INCLUDE_SHMEDIA
6895 struct elf_sh_link_hash_entry *eh;
6897 eh = (struct elf_sh_link_hash_entry *) h;
6898 if (eh->datalabel_got.offset != (bfd_vma) -1)
6902 Elf_Internal_Rela rel;
6905 /* This symbol has a datalabel entry in the global offset table.
6909 srel = htab->srelgot;
6910 BFD_ASSERT (sgot != NULL && srel != NULL);
6912 rel.r_offset = (sgot->output_section->vma
6913 + sgot->output_offset
6914 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
6916 /* If this is a static link, or it is a -Bsymbolic link and the
6917 symbol is defined locally or was forced to be local because
6918 of a version file, we just want to emit a RELATIVE reloc.
6919 The entry in the global offset table will already have been
6920 initialized in the relocate_section function. */
6922 && SYMBOL_REFERENCES_LOCAL (info, h))
6924 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
6925 rel.r_addend = (h->root.u.def.value
6926 + h->root.u.def.section->output_section->vma
6927 + h->root.u.def.section->output_offset);
6931 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
6932 + eh->datalabel_got.offset);
6933 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
6937 loc = srel->contents;
6938 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
6939 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6944 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
6947 Elf_Internal_Rela rel;
6950 /* This symbol needs a copy reloc. Set it up. */
6952 BFD_ASSERT (h->dynindx != -1
6953 && (h->root.type == bfd_link_hash_defined
6954 || h->root.type == bfd_link_hash_defweak));
6956 s = bfd_get_section_by_name (h->root.u.def.section->owner,
6958 BFD_ASSERT (s != NULL);
6960 rel.r_offset = (h->root.u.def.value
6961 + h->root.u.def.section->output_section->vma
6962 + h->root.u.def.section->output_offset);
6963 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
6965 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
6966 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
6969 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6970 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6971 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
6972 sym->st_shndx = SHN_ABS;
6977 /* Finish up the dynamic sections. */
6980 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
6982 struct elf_sh_link_hash_table *htab;
6986 htab = sh_elf_hash_table (info);
6987 sgot = htab->sgotplt;
6988 sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
6990 if (htab->root.dynamic_sections_created)
6993 Elf32_External_Dyn *dyncon, *dynconend;
6995 BFD_ASSERT (sgot != NULL && sdyn != NULL);
6997 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6998 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
6999 for (; dyncon < dynconend; dyncon++)
7001 Elf_Internal_Dyn dyn;
7003 #ifdef INCLUDE_SHMEDIA
7007 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
7014 #ifdef INCLUDE_SHMEDIA
7016 name = info->init_function;
7020 name = info->fini_function;
7022 if (dyn.d_un.d_val != 0)
7024 struct elf_link_hash_entry *h;
7026 h = elf_link_hash_lookup (&htab->root, name,
7027 FALSE, FALSE, TRUE);
7028 if (h != NULL && (h->other & STO_SH5_ISA32))
7030 dyn.d_un.d_val |= 1;
7031 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7038 s = htab->sgot->output_section;
7042 s = htab->srelplt->output_section;
7044 BFD_ASSERT (s != NULL);
7045 dyn.d_un.d_ptr = s->vma;
7046 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7050 s = htab->srelplt->output_section;
7051 BFD_ASSERT (s != NULL);
7052 if (s->_cooked_size != 0)
7053 dyn.d_un.d_val = s->_cooked_size;
7055 dyn.d_un.d_val = s->_raw_size;
7056 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7060 /* My reading of the SVR4 ABI indicates that the
7061 procedure linkage table relocs (DT_JMPREL) should be
7062 included in the overall relocs (DT_RELA). This is
7063 what Solaris does. However, UnixWare can not handle
7064 that case. Therefore, we override the DT_RELASZ entry
7065 here to make it not include the JMPREL relocs. Since
7066 the linker script arranges for .rela.plt to follow all
7067 other relocation sections, we don't have to worry
7068 about changing the DT_RELA entry. */
7069 if (htab->srelplt != NULL)
7071 s = htab->srelplt->output_section;
7072 if (s->_cooked_size != 0)
7073 dyn.d_un.d_val -= s->_cooked_size;
7075 dyn.d_un.d_val -= s->_raw_size;
7077 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7082 /* Fill in the first entry in the procedure linkage table. */
7084 if (splt && splt->_raw_size > 0)
7088 if (elf_sh_pic_plt_entry == NULL)
7090 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
7091 elf_sh_pic_plt_entry_be :
7092 elf_sh_pic_plt_entry_le);
7094 memcpy (splt->contents, elf_sh_pic_plt_entry,
7095 elf_sh_sizeof_plt (info));
7099 if (elf_sh_plt0_entry == NULL)
7101 elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ?
7102 elf_sh_plt0_entry_be :
7103 elf_sh_plt0_entry_le);
7105 memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
7106 #ifdef INCLUDE_SHMEDIA
7107 movi_shori_putval (output_bfd,
7108 sgot->output_section->vma
7109 + sgot->output_offset,
7111 + elf_sh_plt0_gotplt_offset (info));
7113 bfd_put_32 (output_bfd,
7114 sgot->output_section->vma + sgot->output_offset + 4,
7115 splt->contents + elf_sh_plt0_gotid_offset (info));
7116 bfd_put_32 (output_bfd,
7117 sgot->output_section->vma + sgot->output_offset + 8,
7118 splt->contents + elf_sh_plt0_linker_offset (info));
7122 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7123 really seem like the right value. */
7124 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7128 /* Fill in the first three entries in the global offset table. */
7129 if (sgot && sgot->_raw_size > 0)
7132 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7134 bfd_put_32 (output_bfd,
7135 sdyn->output_section->vma + sdyn->output_offset,
7137 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7138 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7140 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7146 static enum elf_reloc_type_class
7147 sh_elf_reloc_type_class (const Elf_Internal_Rela *rela)
7149 switch ((int) ELF32_R_TYPE (rela->r_info))
7152 return reloc_class_relative;
7154 return reloc_class_plt;
7156 return reloc_class_copy;
7158 return reloc_class_normal;
7162 /* Support for Linux core dump NOTE sections. */
7164 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7167 unsigned int raw_size;
7169 switch (note->descsz)
7174 case 168: /* Linux/SH */
7176 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
7179 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
7188 /* Make a ".reg/999" section. */
7189 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7190 raw_size, note->descpos + offset);
7194 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7196 switch (note->descsz)
7201 case 124: /* Linux/SH elf_prpsinfo */
7202 elf_tdata (abfd)->core_program
7203 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7204 elf_tdata (abfd)->core_command
7205 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7208 /* Note that for some reason, a spurious space is tacked
7209 onto the end of the args in some (at least one anyway)
7210 implementations, so strip it off if it exists. */
7213 char *command = elf_tdata (abfd)->core_command;
7214 int n = strlen (command);
7216 if (0 < n && command[n - 1] == ' ')
7217 command[n - 1] = '\0';
7223 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7224 #define TARGET_BIG_NAME "elf32-sh"
7225 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7226 #define TARGET_LITTLE_NAME "elf32-shl"
7227 #define ELF_ARCH bfd_arch_sh
7228 #define ELF_MACHINE_CODE EM_SH
7229 #ifdef __QNXTARGET__
7230 #define ELF_MAXPAGESIZE 0x1000
7232 #define ELF_MAXPAGESIZE 0x80
7235 #define elf_symbol_leading_char '_'
7237 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7238 #define elf_info_to_howto sh_elf_info_to_howto
7239 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7240 #define elf_backend_relocate_section sh_elf_relocate_section
7241 #define bfd_elf32_bfd_get_relocated_section_contents \
7242 sh_elf_get_relocated_section_contents
7243 #define bfd_elf32_mkobject sh_elf_mkobject
7244 #define elf_backend_object_p sh_elf_object_p
7245 #define bfd_elf32_bfd_set_private_bfd_flags \
7246 sh_elf_set_private_flags
7247 #define bfd_elf32_bfd_copy_private_bfd_data \
7248 sh_elf_copy_private_data
7249 #define bfd_elf32_bfd_merge_private_bfd_data \
7250 sh_elf_merge_private_data
7252 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7253 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7254 #define elf_backend_check_relocs sh_elf_check_relocs
7255 #define elf_backend_copy_indirect_symbol \
7256 sh_elf_copy_indirect_symbol
7257 #define elf_backend_create_dynamic_sections \
7258 sh_elf_create_dynamic_sections
7259 #define bfd_elf32_bfd_link_hash_table_create \
7260 sh_elf_link_hash_table_create
7261 #define elf_backend_adjust_dynamic_symbol \
7262 sh_elf_adjust_dynamic_symbol
7263 #define elf_backend_size_dynamic_sections \
7264 sh_elf_size_dynamic_sections
7265 #define elf_backend_finish_dynamic_symbol \
7266 sh_elf_finish_dynamic_symbol
7267 #define elf_backend_finish_dynamic_sections \
7268 sh_elf_finish_dynamic_sections
7269 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7271 #define elf_backend_can_gc_sections 1
7272 #define elf_backend_can_refcount 1
7273 #define elf_backend_want_got_plt 1
7274 #define elf_backend_plt_readonly 1
7275 #define elf_backend_want_plt_sym 0
7276 #define elf_backend_got_header_size 12
7277 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
7279 #ifndef INCLUDE_SHMEDIA
7281 #include "elf32-target.h"
7283 /* NetBSD support. */
7284 #undef TARGET_BIG_SYM
7285 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7286 #undef TARGET_BIG_NAME
7287 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7288 #undef TARGET_LITTLE_SYM
7289 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7290 #undef TARGET_LITTLE_NAME
7291 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7292 #undef ELF_MAXPAGESIZE
7293 #define ELF_MAXPAGESIZE 0x10000
7294 #undef elf_symbol_leading_char
7295 #define elf_symbol_leading_char 0
7297 #define elf32_bed elf32_sh_nbsd_bed
7299 #include "elf32-target.h"
7302 /* Linux support. */
7303 #undef TARGET_BIG_SYM
7304 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7305 #undef TARGET_BIG_NAME
7306 #define TARGET_BIG_NAME "elf32-shbig-linux"
7307 #undef TARGET_LITTLE_SYM
7308 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7309 #undef TARGET_LITTLE_NAME
7310 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7312 #undef elf_backend_grok_prstatus
7313 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7314 #undef elf_backend_grok_psinfo
7315 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7317 #define elf32_bed elf32_sh_lin_bed
7319 #include "elf32-target.h"
7321 #endif /* INCLUDE_SHMEDIA */