1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static bfd_reloc_status_type sh_elf_reloc
30 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33 static reloc_howto_type *sh_elf_reloc_type_lookup
34 PARAMS ((bfd *, bfd_reloc_code_real_type));
35 static void sh_elf_info_to_howto
36 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
37 static boolean sh_elf_set_private_flags
38 PARAMS ((bfd *, flagword));
39 static boolean sh_elf_copy_private_data
40 PARAMS ((bfd *, bfd *));
41 static boolean sh_elf_merge_private_data
42 PARAMS ((bfd *, bfd *));
43 static boolean sh_elf_set_mach_from_flags
45 static boolean sh_elf_relax_section
46 PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
47 static boolean sh_elf_relax_delete_bytes
48 PARAMS ((bfd *, asection *, bfd_vma, int));
49 static boolean sh_elf_align_loads
50 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, boolean *));
51 static boolean sh_elf_swap_insns
52 PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
53 static boolean sh_elf_relocate_section
54 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
55 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
56 static bfd_byte *sh_elf_get_relocated_section_contents
57 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
58 bfd_byte *, boolean, asymbol **));
59 static void sh_elf_copy_indirect_symbol
60 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
61 struct elf_link_hash_entry *));
62 static int sh_elf_optimized_tls_reloc
63 PARAMS ((struct bfd_link_info *, int, int));
64 static boolean sh_elf_mkobject
66 static boolean sh_elf_object_p
68 static boolean sh_elf_check_relocs
69 PARAMS ((bfd *, struct bfd_link_info *, asection *,
70 const Elf_Internal_Rela *));
71 static struct bfd_hash_entry *sh_elf_link_hash_newfunc
72 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
73 static struct bfd_link_hash_table *sh_elf_link_hash_table_create
75 static boolean sh_elf_adjust_dynamic_symbol
76 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
77 static boolean sh_elf_size_dynamic_sections
78 PARAMS ((bfd *, struct bfd_link_info *));
79 static boolean sh_elf_finish_dynamic_symbol
80 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
82 static boolean sh_elf_finish_dynamic_sections
83 PARAMS ((bfd *, struct bfd_link_info *));
84 static bfd_reloc_status_type sh_elf_reloc_loop
85 PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,
87 static boolean create_got_section
88 PARAMS((bfd *, struct bfd_link_info *));
89 static boolean sh_elf_create_dynamic_sections
90 PARAMS ((bfd *, struct bfd_link_info *));
91 static bfd_vma dtpoff_base
92 PARAMS ((struct bfd_link_info *));
93 static asection * sh_elf_gc_mark_hook
94 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
95 struct elf_link_hash_entry *, Elf_Internal_Sym *));
96 static boolean sh_elf_gc_sweep_hook
97 PARAMS ((bfd *, struct bfd_link_info *, asection *,
98 const Elf_Internal_Rela *));
99 static boolean allocate_dynrelocs
100 PARAMS ((struct elf_link_hash_entry *, PTR));
101 static boolean readonly_dynrelocs
102 PARAMS ((struct elf_link_hash_entry *, PTR));
103 static enum elf_reloc_type_class sh_elf_reloc_type_class
104 PARAMS ((const Elf_Internal_Rela *));
105 #ifdef INCLUDE_SHMEDIA
106 inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *));
109 /* The name of the dynamic interpreter. This is put in the .interp
112 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
114 static reloc_howto_type sh_elf_howto_table[] =
117 HOWTO (R_SH_NONE, /* type */
119 0, /* size (0 = byte, 1 = short, 2 = long) */
121 false, /* pc_relative */
123 complain_overflow_dont, /* complain_on_overflow */
124 sh_elf_ignore_reloc, /* special_function */
125 "R_SH_NONE", /* name */
126 false, /* partial_inplace */
129 false), /* pcrel_offset */
131 /* 32 bit absolute relocation. Setting partial_inplace to true and
132 src_mask to a non-zero value is similar to the COFF toolchain. */
133 HOWTO (R_SH_DIR32, /* type */
135 2, /* size (0 = byte, 1 = short, 2 = long) */
137 false, /* pc_relative */
139 complain_overflow_bitfield, /* complain_on_overflow */
140 sh_elf_reloc, /* special_function */
141 "R_SH_DIR32", /* name */
142 true, /* partial_inplace */
143 0xffffffff, /* src_mask */
144 0xffffffff, /* dst_mask */
145 false), /* pcrel_offset */
147 /* 32 bit PC relative relocation. */
148 HOWTO (R_SH_REL32, /* type */
150 2, /* size (0 = byte, 1 = short, 2 = long) */
152 true, /* pc_relative */
154 complain_overflow_signed, /* complain_on_overflow */
155 sh_elf_ignore_reloc, /* special_function */
156 "R_SH_REL32", /* name */
157 true, /* partial_inplace */
158 0xffffffff, /* src_mask */
159 0xffffffff, /* dst_mask */
160 true), /* pcrel_offset */
162 /* 8 bit PC relative branch divided by 2. */
163 HOWTO (R_SH_DIR8WPN, /* type */
165 1, /* size (0 = byte, 1 = short, 2 = long) */
167 true, /* pc_relative */
169 complain_overflow_signed, /* complain_on_overflow */
170 sh_elf_ignore_reloc, /* special_function */
171 "R_SH_DIR8WPN", /* name */
172 true, /* partial_inplace */
175 true), /* pcrel_offset */
177 /* 12 bit PC relative branch divided by 2. */
178 HOWTO (R_SH_IND12W, /* type */
180 1, /* size (0 = byte, 1 = short, 2 = long) */
182 true, /* pc_relative */
184 complain_overflow_signed, /* complain_on_overflow */
185 sh_elf_reloc, /* special_function */
186 "R_SH_IND12W", /* name */
187 true, /* partial_inplace */
188 0xfff, /* src_mask */
189 0xfff, /* dst_mask */
190 true), /* pcrel_offset */
192 /* 8 bit unsigned PC relative divided by 4. */
193 HOWTO (R_SH_DIR8WPL, /* type */
195 1, /* size (0 = byte, 1 = short, 2 = long) */
197 true, /* pc_relative */
199 complain_overflow_unsigned, /* complain_on_overflow */
200 sh_elf_ignore_reloc, /* special_function */
201 "R_SH_DIR8WPL", /* name */
202 true, /* partial_inplace */
205 true), /* pcrel_offset */
207 /* 8 bit unsigned PC relative divided by 2. */
208 HOWTO (R_SH_DIR8WPZ, /* type */
210 1, /* size (0 = byte, 1 = short, 2 = long) */
212 true, /* pc_relative */
214 complain_overflow_unsigned, /* complain_on_overflow */
215 sh_elf_ignore_reloc, /* special_function */
216 "R_SH_DIR8WPZ", /* name */
217 true, /* partial_inplace */
220 true), /* pcrel_offset */
222 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
223 special symbol for the GBR relative area, and that is not
225 HOWTO (R_SH_DIR8BP, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_unsigned, /* complain_on_overflow */
232 sh_elf_ignore_reloc, /* special_function */
233 "R_SH_DIR8BP", /* name */
234 false, /* partial_inplace */
237 true), /* pcrel_offset */
239 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
240 we have some special symbol for the GBR relative area, and that
241 is not implemented. */
242 HOWTO (R_SH_DIR8W, /* type */
244 1, /* size (0 = byte, 1 = short, 2 = long) */
246 false, /* pc_relative */
248 complain_overflow_unsigned, /* complain_on_overflow */
249 sh_elf_ignore_reloc, /* special_function */
250 "R_SH_DIR8W", /* name */
251 false, /* partial_inplace */
254 true), /* pcrel_offset */
256 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
257 we have some special symbol for the GBR relative area, and that
258 is not implemented. */
259 HOWTO (R_SH_DIR8L, /* type */
261 1, /* size (0 = byte, 1 = short, 2 = long) */
263 false, /* pc_relative */
265 complain_overflow_unsigned, /* complain_on_overflow */
266 sh_elf_ignore_reloc, /* special_function */
267 "R_SH_DIR8L", /* name */
268 false, /* partial_inplace */
271 true), /* pcrel_offset */
289 /* The remaining relocs are a GNU extension used for relaxing. The
290 final pass of the linker never needs to do anything with any of
291 these relocs. Any required operations are handled by the
294 /* A 16 bit switch table entry. This is generated for an expression
295 such as ``.word L1 - L2''. The offset holds the difference
296 between the reloc address and L2. */
297 HOWTO (R_SH_SWITCH16, /* type */
299 1, /* size (0 = byte, 1 = short, 2 = long) */
301 false, /* pc_relative */
303 complain_overflow_unsigned, /* complain_on_overflow */
304 sh_elf_ignore_reloc, /* special_function */
305 "R_SH_SWITCH16", /* name */
306 false, /* partial_inplace */
309 true), /* pcrel_offset */
311 /* A 32 bit switch table entry. This is generated for an expression
312 such as ``.long L1 - L2''. The offset holds the difference
313 between the reloc address and L2. */
314 HOWTO (R_SH_SWITCH32, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 false, /* pc_relative */
320 complain_overflow_unsigned, /* complain_on_overflow */
321 sh_elf_ignore_reloc, /* special_function */
322 "R_SH_SWITCH32", /* name */
323 false, /* partial_inplace */
326 true), /* pcrel_offset */
328 /* Indicates a .uses pseudo-op. The compiler will generate .uses
329 pseudo-ops when it finds a function call which can be relaxed.
330 The offset field holds the PC relative offset to the instruction
331 which loads the register used in the function call. */
332 HOWTO (R_SH_USES, /* type */
334 1, /* size (0 = byte, 1 = short, 2 = long) */
336 false, /* pc_relative */
338 complain_overflow_unsigned, /* complain_on_overflow */
339 sh_elf_ignore_reloc, /* special_function */
340 "R_SH_USES", /* name */
341 false, /* partial_inplace */
344 true), /* pcrel_offset */
346 /* The assembler will generate this reloc for addresses referred to
347 by the register loads associated with USES relocs. The offset
348 field holds the number of times the address is referenced in the
350 HOWTO (R_SH_COUNT, /* type */
352 1, /* size (0 = byte, 1 = short, 2 = long) */
354 false, /* pc_relative */
356 complain_overflow_unsigned, /* complain_on_overflow */
357 sh_elf_ignore_reloc, /* special_function */
358 "R_SH_COUNT", /* name */
359 false, /* partial_inplace */
362 true), /* pcrel_offset */
364 /* Indicates an alignment statement. The offset field is the power
365 of 2 to which subsequent portions of the object file must be
367 HOWTO (R_SH_ALIGN, /* type */
369 1, /* size (0 = byte, 1 = short, 2 = long) */
371 false, /* pc_relative */
373 complain_overflow_unsigned, /* complain_on_overflow */
374 sh_elf_ignore_reloc, /* special_function */
375 "R_SH_ALIGN", /* name */
376 false, /* partial_inplace */
379 true), /* pcrel_offset */
381 /* The assembler will generate this reloc before a block of
382 instructions. A section should be processed as assumining it
383 contains data, unless this reloc is seen. */
384 HOWTO (R_SH_CODE, /* type */
386 1, /* size (0 = byte, 1 = short, 2 = long) */
388 false, /* pc_relative */
390 complain_overflow_unsigned, /* complain_on_overflow */
391 sh_elf_ignore_reloc, /* special_function */
392 "R_SH_CODE", /* name */
393 false, /* partial_inplace */
396 true), /* pcrel_offset */
398 /* The assembler will generate this reloc after a block of
399 instructions when it sees data that is not instructions. */
400 HOWTO (R_SH_DATA, /* type */
402 1, /* size (0 = byte, 1 = short, 2 = long) */
404 false, /* pc_relative */
406 complain_overflow_unsigned, /* complain_on_overflow */
407 sh_elf_ignore_reloc, /* special_function */
408 "R_SH_DATA", /* name */
409 false, /* partial_inplace */
412 true), /* pcrel_offset */
414 /* The assembler generates this reloc for each label within a block
415 of instructions. This permits the linker to avoid swapping
416 instructions which are the targets of branches. */
417 HOWTO (R_SH_LABEL, /* type */
419 1, /* size (0 = byte, 1 = short, 2 = long) */
421 false, /* pc_relative */
423 complain_overflow_unsigned, /* complain_on_overflow */
424 sh_elf_ignore_reloc, /* special_function */
425 "R_SH_LABEL", /* name */
426 false, /* partial_inplace */
429 true), /* pcrel_offset */
431 /* An 8 bit switch table entry. This is generated for an expression
432 such as ``.word L1 - L2''. The offset holds the difference
433 between the reloc address and L2. */
434 HOWTO (R_SH_SWITCH8, /* type */
436 0, /* size (0 = byte, 1 = short, 2 = long) */
438 false, /* pc_relative */
440 complain_overflow_unsigned, /* complain_on_overflow */
441 sh_elf_ignore_reloc, /* special_function */
442 "R_SH_SWITCH8", /* name */
443 false, /* partial_inplace */
446 true), /* pcrel_offset */
448 /* GNU extension to record C++ vtable hierarchy */
449 HOWTO (R_SH_GNU_VTINHERIT, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 false, /* pc_relative */
455 complain_overflow_dont, /* complain_on_overflow */
456 NULL, /* special_function */
457 "R_SH_GNU_VTINHERIT", /* name */
458 false, /* partial_inplace */
461 false), /* pcrel_offset */
463 /* GNU extension to record C++ vtable member usage */
464 HOWTO (R_SH_GNU_VTENTRY, /* type */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
468 false, /* pc_relative */
470 complain_overflow_dont, /* complain_on_overflow */
471 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
472 "R_SH_GNU_VTENTRY", /* name */
473 false, /* partial_inplace */
476 false), /* pcrel_offset */
478 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
479 HOWTO (R_SH_LOOP_START, /* type */
481 1, /* size (0 = byte, 1 = short, 2 = long) */
483 false, /* pc_relative */
485 complain_overflow_signed, /* complain_on_overflow */
486 sh_elf_ignore_reloc, /* special_function */
487 "R_SH_LOOP_START", /* name */
488 true, /* partial_inplace */
491 true), /* pcrel_offset */
493 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
494 HOWTO (R_SH_LOOP_END, /* type */
496 1, /* size (0 = byte, 1 = short, 2 = long) */
498 false, /* pc_relative */
500 complain_overflow_signed, /* complain_on_overflow */
501 sh_elf_ignore_reloc, /* special_function */
502 "R_SH_LOOP_END", /* name */
503 true, /* partial_inplace */
506 true), /* pcrel_offset */
516 #ifdef INCLUDE_SHMEDIA
517 /* Used in SHLLI.L and SHLRI.L. */
518 HOWTO (R_SH_DIR5U, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_unsigned, /* complain_on_overflow */
525 bfd_elf_generic_reloc, /* special_function */
526 "R_SH_DIR5U", /* name */
527 false, /* partial_inplace */
529 0xfc00, /* dst_mask */
530 false), /* pcrel_offset */
532 /* Used in SHARI, SHLLI et al. */
533 HOWTO (R_SH_DIR6U, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 false, /* pc_relative */
539 complain_overflow_unsigned, /* complain_on_overflow */
540 bfd_elf_generic_reloc, /* special_function */
541 "R_SH_DIR6U", /* name */
542 false, /* partial_inplace */
544 0xfc00, /* dst_mask */
545 false), /* pcrel_offset */
547 /* Used in BxxI, LDHI.L et al. */
548 HOWTO (R_SH_DIR6S, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 false, /* pc_relative */
554 complain_overflow_signed, /* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_SH_DIR6S", /* name */
557 false, /* partial_inplace */
559 0xfc00, /* dst_mask */
560 false), /* pcrel_offset */
562 /* Used in ADDI, ANDI et al. */
563 HOWTO (R_SH_DIR10S, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 false, /* pc_relative */
569 complain_overflow_signed, /* complain_on_overflow */
570 bfd_elf_generic_reloc, /* special_function */
571 "R_SH_DIR10S", /* name */
572 false, /* partial_inplace */
574 0xffc00, /* dst_mask */
575 false), /* pcrel_offset */
577 /* Used in LD.UW, ST.W et al. */
578 HOWTO (R_SH_DIR10SW, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 false, /* pc_relative */
584 complain_overflow_signed, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_SH_DIR10SW", /* name */
587 false, /* partial_inplace */
589 0xffc00, /* dst_mask */
590 false), /* pcrel_offset */
592 /* Used in LD.L, FLD.S et al. */
593 HOWTO (R_SH_DIR10SL, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_signed, /* complain_on_overflow */
600 bfd_elf_generic_reloc, /* special_function */
601 "R_SH_DIR10SL", /* name */
602 false, /* partial_inplace */
604 0xffc00, /* dst_mask */
605 false), /* pcrel_offset */
607 /* Used in FLD.D, FST.P et al. */
608 HOWTO (R_SH_DIR10SQ, /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 false, /* pc_relative */
614 complain_overflow_signed, /* complain_on_overflow */
615 bfd_elf_generic_reloc, /* special_function */
616 "R_SH_DIR10SQ", /* name */
617 false, /* partial_inplace */
619 0xffc00, /* dst_mask */
620 false), /* pcrel_offset */
725 HOWTO (R_SH_TLS_GD_32, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* */
733 "R_SH_TLS_GD_32", /* name */
734 true, /* partial_inplace */
735 0xffffffff, /* src_mask */
736 0xffffffff, /* dst_mask */
737 false), /* pcrel_offset */
739 HOWTO (R_SH_TLS_LD_32, /* type */
741 2, /* size (0 = byte, 1 = short, 2 = long) */
743 false, /* pc_relative */
745 complain_overflow_bitfield, /* complain_on_overflow */
746 bfd_elf_generic_reloc, /* */
747 "R_SH_TLS_LD_32", /* name */
748 true, /* partial_inplace */
749 0xffffffff, /* src_mask */
750 0xffffffff, /* dst_mask */
751 false), /* pcrel_offset */
753 HOWTO (R_SH_TLS_LDO_32, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 false, /* pc_relative */
759 complain_overflow_bitfield, /* complain_on_overflow */
760 bfd_elf_generic_reloc, /* */
761 "R_SH_TLS_LDO_32", /* name */
762 true, /* partial_inplace */
763 0xffffffff, /* src_mask */
764 0xffffffff, /* dst_mask */
765 false), /* pcrel_offset */
767 HOWTO (R_SH_TLS_IE_32, /* type */
769 2, /* size (0 = byte, 1 = short, 2 = long) */
771 false, /* pc_relative */
773 complain_overflow_bitfield, /* complain_on_overflow */
774 bfd_elf_generic_reloc, /* */
775 "R_SH_TLS_IE_32", /* name */
776 true, /* partial_inplace */
777 0xffffffff, /* src_mask */
778 0xffffffff, /* dst_mask */
779 false), /* pcrel_offset */
781 HOWTO (R_SH_TLS_LE_32, /* type */
783 2, /* size (0 = byte, 1 = short, 2 = long) */
785 false, /* pc_relative */
787 complain_overflow_bitfield, /* complain_on_overflow */
788 bfd_elf_generic_reloc, /* */
789 "R_SH_TLS_LE_32", /* name */
790 true, /* partial_inplace */
791 0xffffffff, /* src_mask */
792 0xffffffff, /* dst_mask */
793 false), /* pcrel_offset */
795 HOWTO (R_SH_TLS_DTPMOD32, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_bitfield, /* complain_on_overflow */
802 bfd_elf_generic_reloc, /* */
803 "R_SH_TLS_DTPMOD32", /* name */
804 true, /* partial_inplace */
805 0xffffffff, /* src_mask */
806 0xffffffff, /* dst_mask */
807 false), /* pcrel_offset */
809 HOWTO (R_SH_TLS_DTPOFF32, /* type */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 false, /* pc_relative */
815 complain_overflow_bitfield, /* complain_on_overflow */
816 bfd_elf_generic_reloc, /* */
817 "R_SH_TLS_DTPOFF32", /* name */
818 true, /* partial_inplace */
819 0xffffffff, /* src_mask */
820 0xffffffff, /* dst_mask */
821 false), /* pcrel_offset */
823 HOWTO (R_SH_TLS_TPOFF32, /* type */
825 2, /* size (0 = byte, 1 = short, 2 = long) */
827 false, /* pc_relative */
829 complain_overflow_bitfield, /* complain_on_overflow */
830 bfd_elf_generic_reloc, /* */
831 "R_SH_TLS_TPOFF32", /* name */
832 true, /* partial_inplace */
833 0xffffffff, /* src_mask */
834 0xffffffff, /* dst_mask */
835 false), /* pcrel_offset */
846 HOWTO (R_SH_GOT32, /* type */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
850 false, /* pc_relative */
852 complain_overflow_bitfield, /* complain_on_overflow */
853 bfd_elf_generic_reloc, /* */
854 "R_SH_GOT32", /* name */
855 true, /* partial_inplace */
856 0xffffffff, /* src_mask */
857 0xffffffff, /* dst_mask */
858 false), /* pcrel_offset */
860 HOWTO (R_SH_PLT32, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 true, /* pc_relative */
866 complain_overflow_bitfield, /* complain_on_overflow */
867 bfd_elf_generic_reloc, /* */
868 "R_SH_PLT32", /* name */
869 true, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 true), /* pcrel_offset */
874 HOWTO (R_SH_COPY, /* type */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
878 false, /* pc_relative */
880 complain_overflow_bitfield, /* complain_on_overflow */
881 bfd_elf_generic_reloc, /* */
882 "R_SH_COPY", /* name */
883 true, /* partial_inplace */
884 0xffffffff, /* src_mask */
885 0xffffffff, /* dst_mask */
886 false), /* pcrel_offset */
888 HOWTO (R_SH_GLOB_DAT, /* type */
890 2, /* size (0 = byte, 1 = short, 2 = long) */
892 false, /* pc_relative */
894 complain_overflow_bitfield, /* complain_on_overflow */
895 bfd_elf_generic_reloc, /* */
896 "R_SH_GLOB_DAT", /* name */
897 true, /* partial_inplace */
898 0xffffffff, /* src_mask */
899 0xffffffff, /* dst_mask */
900 false), /* pcrel_offset */
902 HOWTO (R_SH_JMP_SLOT, /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 false, /* pc_relative */
908 complain_overflow_bitfield, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* */
910 "R_SH_JMP_SLOT", /* name */
911 true, /* partial_inplace */
912 0xffffffff, /* src_mask */
913 0xffffffff, /* dst_mask */
914 false), /* pcrel_offset */
916 HOWTO (R_SH_RELATIVE, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 false, /* pc_relative */
922 complain_overflow_bitfield, /* complain_on_overflow */
923 bfd_elf_generic_reloc, /* */
924 "R_SH_RELATIVE", /* name */
925 true, /* partial_inplace */
926 0xffffffff, /* src_mask */
927 0xffffffff, /* dst_mask */
928 false), /* pcrel_offset */
930 HOWTO (R_SH_GOTOFF, /* type */
932 2, /* size (0 = byte, 1 = short, 2 = long) */
934 false, /* pc_relative */
936 complain_overflow_bitfield, /* complain_on_overflow */
937 bfd_elf_generic_reloc, /* */
938 "R_SH_GOTOFF", /* name */
939 true, /* partial_inplace */
940 0xffffffff, /* src_mask */
941 0xffffffff, /* dst_mask */
942 false), /* pcrel_offset */
944 HOWTO (R_SH_GOTPC, /* type */
946 2, /* size (0 = byte, 1 = short, 2 = long) */
948 true, /* pc_relative */
950 complain_overflow_bitfield, /* complain_on_overflow */
951 bfd_elf_generic_reloc, /* */
952 "R_SH_GOTPC", /* name */
953 true, /* partial_inplace */
954 0xffffffff, /* src_mask */
955 0xffffffff, /* dst_mask */
956 true), /* pcrel_offset */
958 HOWTO (R_SH_GOTPLT32, /* type */
960 2, /* size (0 = byte, 1 = short, 2 = long) */
962 false, /* pc_relative */
964 complain_overflow_bitfield, /* complain_on_overflow */
965 bfd_elf_generic_reloc, /* */
966 "R_SH_GOTPLT32", /* name */
967 false, /* partial_inplace */
968 0xffffffff, /* src_mask */
969 0xffffffff, /* dst_mask */
970 false), /* pcrel_offset */
972 #ifdef INCLUDE_SHMEDIA
973 /* Used in MOVI and SHORI (x & 65536). */
974 HOWTO (R_SH_GOT_LOW16, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 false, /* pc_relative */
980 complain_overflow_dont, /* complain_on_overflow */
981 bfd_elf_generic_reloc, /* special_function */
982 "R_SH_GOT_LOW16", /* name */
983 false, /* partial_inplace */
985 0x3fffc00, /* dst_mask */
986 false), /* pcrel_offset */
988 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
989 HOWTO (R_SH_GOT_MEDLOW16, /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 false, /* pc_relative */
995 complain_overflow_dont, /* complain_on_overflow */
996 bfd_elf_generic_reloc, /* special_function */
997 "R_SH_GOT_MEDLOW16", /* name */
998 false, /* partial_inplace */
1000 0x3fffc00, /* dst_mask */
1001 false), /* pcrel_offset */
1003 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1004 HOWTO (R_SH_GOT_MEDHI16, /* type */
1005 32, /* rightshift */
1006 2, /* size (0 = byte, 1 = short, 2 = long) */
1008 false, /* pc_relative */
1010 complain_overflow_dont, /* complain_on_overflow */
1011 bfd_elf_generic_reloc, /* special_function */
1012 "R_SH_GOT_MEDHI16", /* name */
1013 false, /* partial_inplace */
1015 0x3fffc00, /* dst_mask */
1016 false), /* pcrel_offset */
1018 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1019 HOWTO (R_SH_GOT_HI16, /* type */
1020 48, /* rightshift */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1023 false, /* pc_relative */
1025 complain_overflow_dont, /* complain_on_overflow */
1026 bfd_elf_generic_reloc, /* special_function */
1027 "R_SH_GOT_HI16", /* name */
1028 false, /* partial_inplace */
1030 0x3fffc00, /* dst_mask */
1031 false), /* pcrel_offset */
1033 /* Used in MOVI and SHORI (x & 65536). */
1034 HOWTO (R_SH_GOTPLT_LOW16, /* type */
1036 2, /* size (0 = byte, 1 = short, 2 = long) */
1038 false, /* pc_relative */
1040 complain_overflow_dont, /* complain_on_overflow */
1041 bfd_elf_generic_reloc, /* special_function */
1042 "R_SH_GOTPLT_LOW16", /* name */
1043 false, /* partial_inplace */
1045 0x3fffc00, /* dst_mask */
1046 false), /* pcrel_offset */
1048 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1049 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
1050 16, /* rightshift */
1051 2, /* size (0 = byte, 1 = short, 2 = long) */
1053 false, /* pc_relative */
1055 complain_overflow_dont, /* complain_on_overflow */
1056 bfd_elf_generic_reloc, /* special_function */
1057 "R_SH_GOTPLT_MEDLOW16", /* name */
1058 false, /* partial_inplace */
1060 0x3fffc00, /* dst_mask */
1061 false), /* pcrel_offset */
1063 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1064 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
1065 32, /* rightshift */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 false, /* pc_relative */
1070 complain_overflow_dont, /* complain_on_overflow */
1071 bfd_elf_generic_reloc, /* special_function */
1072 "R_SH_GOTPLT_MEDHI16", /* name */
1073 false, /* partial_inplace */
1075 0x3fffc00, /* dst_mask */
1076 false), /* pcrel_offset */
1078 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1079 HOWTO (R_SH_GOTPLT_HI16, /* type */
1080 48, /* rightshift */
1081 2, /* size (0 = byte, 1 = short, 2 = long) */
1083 false, /* pc_relative */
1085 complain_overflow_dont, /* complain_on_overflow */
1086 bfd_elf_generic_reloc, /* special_function */
1087 "R_SH_GOTPLT_HI16", /* name */
1088 false, /* partial_inplace */
1090 0x3fffc00, /* dst_mask */
1091 false), /* pcrel_offset */
1093 /* Used in MOVI and SHORI (x & 65536). */
1094 HOWTO (R_SH_PLT_LOW16, /* type */
1096 2, /* size (0 = byte, 1 = short, 2 = long) */
1098 true, /* pc_relative */
1100 complain_overflow_dont, /* complain_on_overflow */
1101 bfd_elf_generic_reloc, /* special_function */
1102 "R_SH_PLT_LOW16", /* name */
1103 false, /* partial_inplace */
1105 0x3fffc00, /* dst_mask */
1106 true), /* pcrel_offset */
1108 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1109 HOWTO (R_SH_PLT_MEDLOW16, /* type */
1110 16, /* rightshift */
1111 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 true, /* pc_relative */
1115 complain_overflow_dont, /* complain_on_overflow */
1116 bfd_elf_generic_reloc, /* special_function */
1117 "R_SH_PLT_MEDLOW16", /* name */
1118 false, /* partial_inplace */
1120 0x3fffc00, /* dst_mask */
1121 true), /* pcrel_offset */
1123 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1124 HOWTO (R_SH_PLT_MEDHI16, /* type */
1125 32, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1128 true, /* pc_relative */
1130 complain_overflow_dont, /* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_SH_PLT_MEDHI16", /* name */
1133 false, /* partial_inplace */
1135 0x3fffc00, /* dst_mask */
1136 true), /* pcrel_offset */
1138 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1139 HOWTO (R_SH_PLT_HI16, /* type */
1140 48, /* rightshift */
1141 2, /* size (0 = byte, 1 = short, 2 = long) */
1143 true, /* pc_relative */
1145 complain_overflow_dont, /* complain_on_overflow */
1146 bfd_elf_generic_reloc, /* special_function */
1147 "R_SH_PLT_HI16", /* name */
1148 false, /* partial_inplace */
1150 0x3fffc00, /* dst_mask */
1151 true), /* pcrel_offset */
1153 /* Used in MOVI and SHORI (x & 65536). */
1154 HOWTO (R_SH_GOTOFF_LOW16, /* type */
1156 2, /* size (0 = byte, 1 = short, 2 = long) */
1158 false, /* pc_relative */
1160 complain_overflow_dont, /* complain_on_overflow */
1161 bfd_elf_generic_reloc, /* special_function */
1162 "R_SH_GOTOFF_LOW16", /* name */
1163 false, /* partial_inplace */
1165 0x3fffc00, /* dst_mask */
1166 false), /* pcrel_offset */
1168 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1169 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
1170 16, /* rightshift */
1171 2, /* size (0 = byte, 1 = short, 2 = long) */
1173 false, /* pc_relative */
1175 complain_overflow_dont, /* complain_on_overflow */
1176 bfd_elf_generic_reloc, /* special_function */
1177 "R_SH_GOTOFF_MEDLOW16", /* name */
1178 false, /* partial_inplace */
1180 0x3fffc00, /* dst_mask */
1181 false), /* pcrel_offset */
1183 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1184 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
1185 32, /* rightshift */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1188 false, /* pc_relative */
1190 complain_overflow_dont, /* complain_on_overflow */
1191 bfd_elf_generic_reloc, /* special_function */
1192 "R_SH_GOTOFF_MEDHI16", /* name */
1193 false, /* partial_inplace */
1195 0x3fffc00, /* dst_mask */
1196 false), /* pcrel_offset */
1198 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1199 HOWTO (R_SH_GOTOFF_HI16, /* type */
1200 48, /* rightshift */
1201 2, /* size (0 = byte, 1 = short, 2 = long) */
1203 false, /* pc_relative */
1205 complain_overflow_dont, /* complain_on_overflow */
1206 bfd_elf_generic_reloc, /* special_function */
1207 "R_SH_GOTOFF_HI16", /* name */
1208 false, /* partial_inplace */
1210 0x3fffc00, /* dst_mask */
1211 false), /* pcrel_offset */
1213 /* Used in MOVI and SHORI (x & 65536). */
1214 HOWTO (R_SH_GOTPC_LOW16, /* type */
1216 2, /* size (0 = byte, 1 = short, 2 = long) */
1218 true, /* pc_relative */
1220 complain_overflow_dont, /* complain_on_overflow */
1221 bfd_elf_generic_reloc, /* special_function */
1222 "R_SH_GOTPC_LOW16", /* name */
1223 false, /* partial_inplace */
1225 0x3fffc00, /* dst_mask */
1226 true), /* pcrel_offset */
1228 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1229 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
1230 16, /* rightshift */
1231 2, /* size (0 = byte, 1 = short, 2 = long) */
1233 true, /* pc_relative */
1235 complain_overflow_dont, /* complain_on_overflow */
1236 bfd_elf_generic_reloc, /* special_function */
1237 "R_SH_GOTPC_MEDLOW16", /* name */
1238 false, /* partial_inplace */
1240 0x3fffc00, /* dst_mask */
1241 true), /* pcrel_offset */
1243 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1244 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
1245 32, /* rightshift */
1246 2, /* size (0 = byte, 1 = short, 2 = long) */
1248 true, /* pc_relative */
1250 complain_overflow_dont, /* complain_on_overflow */
1251 bfd_elf_generic_reloc, /* special_function */
1252 "R_SH_GOTPC_MEDHI16", /* name */
1253 false, /* partial_inplace */
1255 0x3fffc00, /* dst_mask */
1256 true), /* pcrel_offset */
1258 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1259 HOWTO (R_SH_GOTPC_HI16, /* type */
1260 48, /* rightshift */
1261 2, /* size (0 = byte, 1 = short, 2 = long) */
1263 true, /* pc_relative */
1265 complain_overflow_dont, /* complain_on_overflow */
1266 bfd_elf_generic_reloc, /* special_function */
1267 "R_SH_GOTPC_HI16", /* name */
1268 false, /* partial_inplace */
1270 0x3fffc00, /* dst_mask */
1271 true), /* pcrel_offset */
1273 /* Used in LD.L, FLD.S et al. */
1274 HOWTO (R_SH_GOT10BY4, /* type */
1276 2, /* size (0 = byte, 1 = short, 2 = long) */
1278 false, /* pc_relative */
1280 complain_overflow_signed, /* complain_on_overflow */
1281 bfd_elf_generic_reloc, /* special_function */
1282 "R_SH_GOT10BY4", /* name */
1283 false, /* partial_inplace */
1285 0xffc00, /* dst_mask */
1286 false), /* pcrel_offset */
1288 /* Used in LD.L, FLD.S et al. */
1289 HOWTO (R_SH_GOTPLT10BY4, /* type */
1291 2, /* size (0 = byte, 1 = short, 2 = long) */
1293 false, /* pc_relative */
1295 complain_overflow_signed, /* complain_on_overflow */
1296 bfd_elf_generic_reloc, /* special_function */
1297 "R_SH_GOTPLT10BY4", /* name */
1298 false, /* partial_inplace */
1300 0xffc00, /* dst_mask */
1301 false), /* pcrel_offset */
1303 /* Used in FLD.D, FST.P et al. */
1304 HOWTO (R_SH_GOT10BY8, /* type */
1306 2, /* size (0 = byte, 1 = short, 2 = long) */
1308 false, /* pc_relative */
1310 complain_overflow_signed, /* complain_on_overflow */
1311 bfd_elf_generic_reloc, /* special_function */
1312 "R_SH_GOT10BY8", /* name */
1313 false, /* partial_inplace */
1315 0xffc00, /* dst_mask */
1316 false), /* pcrel_offset */
1318 /* Used in FLD.D, FST.P et al. */
1319 HOWTO (R_SH_GOTPLT10BY8, /* type */
1321 2, /* size (0 = byte, 1 = short, 2 = long) */
1323 false, /* pc_relative */
1325 complain_overflow_signed, /* complain_on_overflow */
1326 bfd_elf_generic_reloc, /* special_function */
1327 "R_SH_GOTPLT10BY8", /* name */
1328 false, /* partial_inplace */
1330 0xffc00, /* dst_mask */
1331 false), /* pcrel_offset */
1333 HOWTO (R_SH_COPY64, /* type */
1335 4, /* size (0 = byte, 1 = short, 2 = long) */
1337 false, /* pc_relative */
1339 complain_overflow_dont, /* complain_on_overflow */
1340 bfd_elf_generic_reloc, /* special_function */
1341 "R_SH_COPY64", /* name */
1342 false, /* partial_inplace */
1344 ((bfd_vma) 0) - 1, /* dst_mask */
1345 false), /* pcrel_offset */
1347 HOWTO (R_SH_GLOB_DAT64, /* type */
1349 4, /* size (0 = byte, 1 = short, 2 = long) */
1351 false, /* pc_relative */
1353 complain_overflow_dont, /* complain_on_overflow */
1354 bfd_elf_generic_reloc, /* special_function */
1355 "R_SH_GLOB_DAT64", /* name */
1356 false, /* partial_inplace */
1358 ((bfd_vma) 0) - 1, /* dst_mask */
1359 false), /* pcrel_offset */
1361 HOWTO (R_SH_JMP_SLOT64, /* type */
1363 4, /* size (0 = byte, 1 = short, 2 = long) */
1365 false, /* pc_relative */
1367 complain_overflow_dont, /* complain_on_overflow */
1368 bfd_elf_generic_reloc, /* special_function */
1369 "R_SH_JMP_SLOT64", /* name */
1370 false, /* partial_inplace */
1372 ((bfd_vma) 0) - 1, /* dst_mask */
1373 false), /* pcrel_offset */
1375 HOWTO (R_SH_RELATIVE64, /* type */
1377 4, /* size (0 = byte, 1 = short, 2 = long) */
1379 false, /* pc_relative */
1381 complain_overflow_dont, /* complain_on_overflow */
1382 bfd_elf_generic_reloc, /* special_function */
1383 "R_SH_RELATIVE64", /* name */
1384 false, /* partial_inplace */
1386 ((bfd_vma) 0) - 1, /* dst_mask */
1387 false), /* pcrel_offset */
1435 /* Relocations for SHmedia code. None of these are partial_inplace or
1436 use the field being relocated (except R_SH_PT_16). */
1438 /* The assembler will generate this reloc before a block of SHmedia
1439 instructions. A section should be processed as assuming it contains
1440 data, unless this reloc is seen. Note that a block of SHcompact
1441 instructions are instead preceded by R_SH_CODE.
1442 This is currently not implemented, but should be used for SHmedia
1443 linker relaxation. */
1444 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1446 1, /* size (0 = byte, 1 = short, 2 = long) */
1448 false, /* pc_relative */
1450 complain_overflow_unsigned, /* complain_on_overflow */
1451 sh_elf_ignore_reloc, /* special_function */
1452 "R_SH_SHMEDIA_CODE", /* name */
1453 false, /* partial_inplace */
1456 false), /* pcrel_offset */
1458 /* The assembler will generate this reloc at a PTA or PTB instruction,
1459 and the linker checks the right type of target, or changes a PTA to a
1460 PTB, if the original insn was PT. */
1461 HOWTO (R_SH_PT_16, /* type */
1463 2, /* size (0 = byte, 1 = short, 2 = long) */
1465 true, /* pc_relative */
1467 complain_overflow_signed, /* complain_on_overflow */
1468 bfd_elf_generic_reloc, /* special_function */
1469 "R_SH_PT_16", /* name */
1470 false, /* partial_inplace */
1472 0x3fffc00, /* dst_mask */
1473 true), /* pcrel_offset */
1475 /* Used in unexpanded MOVI. */
1476 HOWTO (R_SH_IMMS16, /* type */
1478 2, /* size (0 = byte, 1 = short, 2 = long) */
1480 false, /* pc_relative */
1482 complain_overflow_signed, /* complain_on_overflow */
1483 bfd_elf_generic_reloc, /* special_function */
1484 "R_SH_IMMS16", /* name */
1485 false, /* partial_inplace */
1487 0x3fffc00, /* dst_mask */
1488 false), /* pcrel_offset */
1490 /* Used in SHORI. */
1491 HOWTO (R_SH_IMMU16, /* type */
1493 2, /* size (0 = byte, 1 = short, 2 = long) */
1495 false, /* pc_relative */
1497 complain_overflow_unsigned, /* complain_on_overflow */
1498 bfd_elf_generic_reloc, /* special_function */
1499 "R_SH_IMMU16", /* name */
1500 false, /* partial_inplace */
1502 0x3fffc00, /* dst_mask */
1503 false), /* pcrel_offset */
1505 /* Used in MOVI and SHORI (x & 65536). */
1506 HOWTO (R_SH_IMM_LOW16, /* type */
1508 2, /* size (0 = byte, 1 = short, 2 = long) */
1510 false, /* pc_relative */
1512 complain_overflow_dont, /* complain_on_overflow */
1513 bfd_elf_generic_reloc, /* special_function */
1514 "R_SH_IMM_LOW16", /* name */
1515 false, /* partial_inplace */
1517 0x3fffc00, /* dst_mask */
1518 false), /* pcrel_offset */
1520 /* Used in MOVI and SHORI ((x - $) & 65536). */
1521 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1523 2, /* size (0 = byte, 1 = short, 2 = long) */
1525 true, /* pc_relative */
1527 complain_overflow_dont, /* complain_on_overflow */
1528 bfd_elf_generic_reloc, /* special_function */
1529 "R_SH_IMM_LOW16_PCREL", /* name */
1530 false, /* partial_inplace */
1532 0x3fffc00, /* dst_mask */
1533 true), /* pcrel_offset */
1535 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1536 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1537 16, /* rightshift */
1538 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 false, /* pc_relative */
1542 complain_overflow_dont, /* complain_on_overflow */
1543 bfd_elf_generic_reloc, /* special_function */
1544 "R_SH_IMM_MEDLOW16", /* name */
1545 false, /* partial_inplace */
1547 0x3fffc00, /* dst_mask */
1548 false), /* pcrel_offset */
1550 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1551 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1552 16, /* rightshift */
1553 2, /* size (0 = byte, 1 = short, 2 = long) */
1555 true, /* pc_relative */
1557 complain_overflow_dont, /* complain_on_overflow */
1558 bfd_elf_generic_reloc, /* special_function */
1559 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1560 false, /* partial_inplace */
1562 0x3fffc00, /* dst_mask */
1563 true), /* pcrel_offset */
1565 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1566 HOWTO (R_SH_IMM_MEDHI16, /* type */
1567 32, /* rightshift */
1568 2, /* size (0 = byte, 1 = short, 2 = long) */
1570 false, /* pc_relative */
1572 complain_overflow_dont, /* complain_on_overflow */
1573 bfd_elf_generic_reloc, /* special_function */
1574 "R_SH_IMM_MEDHI16", /* name */
1575 false, /* partial_inplace */
1577 0x3fffc00, /* dst_mask */
1578 false), /* pcrel_offset */
1580 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1581 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1582 32, /* rightshift */
1583 2, /* size (0 = byte, 1 = short, 2 = long) */
1585 true, /* pc_relative */
1587 complain_overflow_dont, /* complain_on_overflow */
1588 bfd_elf_generic_reloc, /* special_function */
1589 "R_SH_IMM_MEDHI16_PCREL", /* name */
1590 false, /* partial_inplace */
1592 0x3fffc00, /* dst_mask */
1593 true), /* pcrel_offset */
1595 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1596 HOWTO (R_SH_IMM_HI16, /* type */
1597 48, /* rightshift */
1598 2, /* size (0 = byte, 1 = short, 2 = long) */
1600 false, /* pc_relative */
1602 complain_overflow_dont, /* complain_on_overflow */
1603 bfd_elf_generic_reloc, /* special_function */
1604 "R_SH_IMM_HI16", /* name */
1605 false, /* partial_inplace */
1607 0x3fffc00, /* dst_mask */
1608 false), /* pcrel_offset */
1610 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1611 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1612 48, /* rightshift */
1613 2, /* size (0 = byte, 1 = short, 2 = long) */
1615 true, /* pc_relative */
1617 complain_overflow_dont, /* complain_on_overflow */
1618 bfd_elf_generic_reloc, /* special_function */
1619 "R_SH_IMM_HI16_PCREL", /* name */
1620 false, /* partial_inplace */
1622 0x3fffc00, /* dst_mask */
1623 true), /* pcrel_offset */
1625 /* For the .uaquad pseudo. */
1626 HOWTO (R_SH_64, /* type */
1628 4, /* size (0 = byte, 1 = short, 2 = long) */
1630 false, /* pc_relative */
1632 complain_overflow_dont, /* complain_on_overflow */
1633 bfd_elf_generic_reloc, /* special_function */
1634 "R_SH_64", /* name */
1635 false, /* partial_inplace */
1637 ((bfd_vma) 0) - 1, /* dst_mask */
1638 false), /* pcrel_offset */
1640 /* For the .uaquad pseudo, (x - $). */
1641 HOWTO (R_SH_64_PCREL, /* type */
1642 48, /* rightshift */
1643 2, /* size (0 = byte, 1 = short, 2 = long) */
1645 true, /* pc_relative */
1647 complain_overflow_dont, /* complain_on_overflow */
1648 bfd_elf_generic_reloc, /* special_function */
1649 "R_SH_64_PCREL", /* name */
1650 false, /* partial_inplace */
1652 ((bfd_vma) 0) - 1, /* dst_mask */
1653 true), /* pcrel_offset */
1658 static bfd_reloc_status_type
1659 sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,
1660 symbol_section, start, end)
1661 int r_type ATTRIBUTE_UNUSED;
1663 asection *input_section;
1666 asection *symbol_section;
1669 static bfd_vma last_addr;
1670 static asection *last_symbol_section;
1671 bfd_byte *start_ptr, *ptr, *last_ptr;
1676 /* Sanity check the address. */
1677 if (addr > input_section->_raw_size)
1678 return bfd_reloc_outofrange;
1680 /* We require the start and end relocations to be processed consecutively -
1681 although we allow then to be processed forwards or backwards. */
1685 last_symbol_section = symbol_section;
1686 return bfd_reloc_ok;
1688 if (last_addr != addr)
1692 if (! symbol_section || last_symbol_section != symbol_section || end < start)
1693 return bfd_reloc_outofrange;
1695 /* Get the symbol_section contents. */
1696 if (symbol_section != input_section)
1698 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
1699 contents = elf_section_data (symbol_section)->this_hdr.contents;
1702 contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size);
1703 if (contents == NULL)
1704 return bfd_reloc_outofrange;
1705 if (! bfd_get_section_contents (input_bfd, symbol_section, contents,
1707 symbol_section->_raw_size))
1710 return bfd_reloc_outofrange;
1714 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1715 start_ptr = contents + start;
1716 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
1718 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
1721 diff = (last_ptr - ptr) >> 1;
1722 cum_diff += diff & 1;
1725 /* Calculate the start / end values to load into rs / re minus four -
1726 so that will cancel out the four we would otherwise have to add to
1727 addr to get the value to subtract in order to get relative addressing. */
1731 end = (ptr + cum_diff * 2) - contents;
1735 bfd_vma start0 = start - 4;
1737 while (start0 && IS_PPI (contents + start0))
1739 start0 = start - 2 - ((start - start0) & 2);
1740 start = start0 - cum_diff - 2;
1744 if (contents != NULL
1745 && elf_section_data (symbol_section)->this_hdr.contents != contents)
1748 insn = bfd_get_16 (input_bfd, contents + addr);
1750 x = (insn & 0x200 ? end : start) - addr;
1751 if (input_section != symbol_section)
1752 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
1753 - (input_section->output_section->vma
1754 + input_section->output_offset));
1756 if (x < -128 || x > 127)
1757 return bfd_reloc_overflow;
1759 x = (insn & ~0xff) | (x & 0xff);
1760 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
1762 return bfd_reloc_ok;
1765 /* This function is used for normal relocs. This used to be like the COFF
1766 function, and is almost certainly incorrect for other ELF targets. */
1768 static bfd_reloc_status_type
1769 sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
1772 arelent *reloc_entry;
1775 asection *input_section;
1777 char **error_message ATTRIBUTE_UNUSED;
1781 enum elf_sh_reloc_type r_type;
1782 bfd_vma addr = reloc_entry->address;
1783 bfd_byte *hit_data = addr + (bfd_byte *) data;
1785 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1787 if (output_bfd != NULL)
1789 /* Partial linking--do nothing. */
1790 reloc_entry->address += input_section->output_offset;
1791 return bfd_reloc_ok;
1794 /* Almost all relocs have to do with relaxing. If any work must be
1795 done for them, it has been done in sh_relax_section. */
1796 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
1797 return bfd_reloc_ok;
1799 if (symbol_in != NULL
1800 && bfd_is_und_section (symbol_in->section))
1801 return bfd_reloc_undefined;
1803 if (bfd_is_com_section (symbol_in->section))
1806 sym_value = (symbol_in->value +
1807 symbol_in->section->output_section->vma +
1808 symbol_in->section->output_offset);
1813 insn = bfd_get_32 (abfd, hit_data);
1814 insn += sym_value + reloc_entry->addend;
1815 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
1818 insn = bfd_get_16 (abfd, hit_data);
1819 sym_value += reloc_entry->addend;
1820 sym_value -= (input_section->output_section->vma
1821 + input_section->output_offset
1824 sym_value += (insn & 0xfff) << 1;
1826 sym_value -= 0x1000;
1827 insn = (insn & 0xf000) | (sym_value & 0xfff);
1828 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
1829 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
1830 return bfd_reloc_overflow;
1837 return bfd_reloc_ok;
1840 /* This function is used for relocs which are only used for relaxing,
1841 which the linker should otherwise ignore. */
1843 static bfd_reloc_status_type
1844 sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
1845 output_bfd, error_message)
1846 bfd *abfd ATTRIBUTE_UNUSED;
1847 arelent *reloc_entry;
1848 asymbol *symbol ATTRIBUTE_UNUSED;
1849 PTR data ATTRIBUTE_UNUSED;
1850 asection *input_section;
1852 char **error_message ATTRIBUTE_UNUSED;
1854 if (output_bfd != NULL)
1855 reloc_entry->address += input_section->output_offset;
1856 return bfd_reloc_ok;
1859 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1861 struct elf_reloc_map
1863 bfd_reloc_code_real_type bfd_reloc_val;
1864 unsigned char elf_reloc_val;
1867 /* An array mapping BFD reloc codes to SH ELF relocs. */
1869 static const struct elf_reloc_map sh_reloc_map[] =
1871 { BFD_RELOC_NONE, R_SH_NONE },
1872 { BFD_RELOC_32, R_SH_DIR32 },
1873 { BFD_RELOC_CTOR, R_SH_DIR32 },
1874 { BFD_RELOC_32_PCREL, R_SH_REL32 },
1875 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
1876 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
1877 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
1878 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
1879 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
1880 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
1881 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
1882 { BFD_RELOC_SH_USES, R_SH_USES },
1883 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
1884 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
1885 { BFD_RELOC_SH_CODE, R_SH_CODE },
1886 { BFD_RELOC_SH_DATA, R_SH_DATA },
1887 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
1888 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
1889 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
1890 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
1891 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
1892 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
1893 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
1894 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
1895 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
1896 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
1897 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
1898 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
1899 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
1900 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
1901 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
1902 { BFD_RELOC_SH_COPY, R_SH_COPY },
1903 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
1904 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
1905 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
1906 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
1907 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
1908 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
1909 #ifdef INCLUDE_SHMEDIA
1910 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
1911 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
1912 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
1913 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
1914 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
1915 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
1916 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
1917 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
1918 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
1919 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
1920 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
1921 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
1922 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
1923 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
1924 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
1925 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
1926 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
1927 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
1928 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
1929 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
1930 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
1931 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
1932 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
1933 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
1934 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
1935 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
1936 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
1937 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
1938 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
1939 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
1940 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
1941 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
1942 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
1943 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
1944 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
1945 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
1946 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
1947 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
1948 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
1949 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
1950 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
1951 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
1952 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
1953 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
1954 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
1955 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
1956 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
1957 { BFD_RELOC_64, R_SH_64 },
1958 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
1959 #endif /* not INCLUDE_SHMEDIA */
1962 /* Given a BFD reloc code, return the howto structure for the
1963 corresponding SH ELf reloc. */
1965 static reloc_howto_type *
1966 sh_elf_reloc_type_lookup (abfd, code)
1967 bfd *abfd ATTRIBUTE_UNUSED;
1968 bfd_reloc_code_real_type code;
1972 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
1974 if (sh_reloc_map[i].bfd_reloc_val == code)
1975 return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val];
1981 /* Given an ELF reloc, fill in the howto field of a relent. */
1984 sh_elf_info_to_howto (abfd, cache_ptr, dst)
1985 bfd *abfd ATTRIBUTE_UNUSED;
1987 Elf_Internal_Rela *dst;
1991 r = ELF32_R_TYPE (dst->r_info);
1993 BFD_ASSERT (r < (unsigned int) R_SH_max);
1994 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
1995 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
1996 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
1997 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
1998 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
2000 cache_ptr->howto = &sh_elf_howto_table[r];
2003 /* This function handles relaxing for SH ELF. See the corresponding
2004 function in coff-sh.c for a description of what this does. FIXME:
2005 There is a lot of duplication here between this code and the COFF
2006 specific code. The format of relocs and symbols is wound deeply
2007 into this code, but it would still be better if the duplication
2008 could be eliminated somehow. Note in particular that although both
2009 functions use symbols like R_SH_CODE, those symbols have different
2010 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2011 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2014 sh_elf_relax_section (abfd, sec, link_info, again)
2017 struct bfd_link_info *link_info;
2020 Elf_Internal_Shdr *symtab_hdr;
2021 Elf_Internal_Rela *internal_relocs;
2023 Elf_Internal_Rela *irel, *irelend;
2024 bfd_byte *contents = NULL;
2025 Elf_Internal_Sym *isymbuf = NULL;
2029 if (link_info->relocateable
2030 || (sec->flags & SEC_RELOC) == 0
2031 || sec->reloc_count == 0)
2034 #ifdef INCLUDE_SHMEDIA
2035 if (elf_section_data (sec)->this_hdr.sh_flags
2036 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
2042 /* If this is the first time we have been called for this section,
2043 initialize the cooked size. */
2044 if (sec->_cooked_size == 0)
2045 sec->_cooked_size = sec->_raw_size;
2047 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2049 internal_relocs = (_bfd_elf32_link_read_relocs
2050 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2051 link_info->keep_memory));
2052 if (internal_relocs == NULL)
2057 irelend = internal_relocs + sec->reloc_count;
2058 for (irel = internal_relocs; irel < irelend; irel++)
2060 bfd_vma laddr, paddr, symval;
2061 unsigned short insn;
2062 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
2063 bfd_signed_vma foff;
2065 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
2068 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
2071 /* Get the section contents. */
2072 if (contents == NULL)
2074 if (elf_section_data (sec)->this_hdr.contents != NULL)
2075 contents = elf_section_data (sec)->this_hdr.contents;
2078 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2079 if (contents == NULL)
2082 if (! bfd_get_section_contents (abfd, sec, contents,
2083 (file_ptr) 0, sec->_raw_size))
2088 /* The r_addend field of the R_SH_USES reloc will point us to
2089 the register load. The 4 is because the r_addend field is
2090 computed as though it were a jump offset, which are based
2091 from 4 bytes after the jump instruction. */
2092 laddr = irel->r_offset + 4 + irel->r_addend;
2093 if (laddr >= sec->_raw_size)
2095 (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2096 bfd_archive_filename (abfd),
2097 (unsigned long) irel->r_offset);
2100 insn = bfd_get_16 (abfd, contents + laddr);
2102 /* If the instruction is not mov.l NN,rN, we don't know what to
2104 if ((insn & 0xf000) != 0xd000)
2106 ((*_bfd_error_handler)
2107 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2108 bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
2112 /* Get the address from which the register is being loaded. The
2113 displacement in the mov.l instruction is quadrupled. It is a
2114 displacement from four bytes after the movl instruction, but,
2115 before adding in the PC address, two least significant bits
2116 of the PC are cleared. We assume that the section is aligned
2117 on a four byte boundary. */
2118 paddr = insn & 0xff;
2120 paddr += (laddr + 4) &~ (bfd_vma) 3;
2121 if (paddr >= sec->_raw_size)
2123 ((*_bfd_error_handler)
2124 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2125 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2129 /* Get the reloc for the address from which the register is
2130 being loaded. This reloc will tell us which function is
2131 actually being called. */
2132 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2133 if (irelfn->r_offset == paddr
2134 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
2136 if (irelfn >= irelend)
2138 ((*_bfd_error_handler)
2139 (_("%s: 0x%lx: warning: could not find expected reloc"),
2140 bfd_archive_filename (abfd), (unsigned long) paddr));
2144 /* Read this BFD's symbols if we haven't done so already. */
2145 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2147 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2148 if (isymbuf == NULL)
2149 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2150 symtab_hdr->sh_info, 0,
2152 if (isymbuf == NULL)
2156 /* Get the value of the symbol referred to by the reloc. */
2157 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2159 /* A local symbol. */
2160 Elf_Internal_Sym *isym;
2162 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
2164 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
2166 ((*_bfd_error_handler)
2167 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2168 bfd_archive_filename (abfd), (unsigned long) paddr));
2172 symval = (isym->st_value
2173 + sec->output_section->vma
2174 + sec->output_offset);
2179 struct elf_link_hash_entry *h;
2181 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
2182 h = elf_sym_hashes (abfd)[indx];
2183 BFD_ASSERT (h != NULL);
2184 if (h->root.type != bfd_link_hash_defined
2185 && h->root.type != bfd_link_hash_defweak)
2187 /* This appears to be a reference to an undefined
2188 symbol. Just ignore it--it will be caught by the
2189 regular reloc processing. */
2193 symval = (h->root.u.def.value
2194 + h->root.u.def.section->output_section->vma
2195 + h->root.u.def.section->output_offset);
2198 symval += bfd_get_32 (abfd, contents + paddr);
2200 /* See if this function call can be shortened. */
2203 + sec->output_section->vma
2204 + sec->output_offset
2206 if (foff < -0x1000 || foff >= 0x1000)
2208 /* After all that work, we can't shorten this function call. */
2212 /* Shorten the function call. */
2214 /* For simplicity of coding, we are going to modify the section
2215 contents, the section relocs, and the BFD symbol table. We
2216 must tell the rest of the code not to free up this
2217 information. It would be possible to instead create a table
2218 of changes which have to be made, as is done in coff-mips.c;
2219 that would be more work, but would require less memory when
2220 the linker is run. */
2222 elf_section_data (sec)->relocs = internal_relocs;
2223 elf_section_data (sec)->this_hdr.contents = contents;
2224 symtab_hdr->contents = (unsigned char *) isymbuf;
2226 /* Replace the jsr with a bsr. */
2228 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2229 replace the jsr with a bsr. */
2230 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
2231 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2233 /* If this needs to be changed because of future relaxing,
2234 it will be handled here like other internal IND12W
2237 (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
2238 contents + irel->r_offset);
2242 /* We can't fully resolve this yet, because the external
2243 symbol value may be changed by future relaxing. We let
2244 the final link phase handle it. */
2245 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
2248 /* See if there is another R_SH_USES reloc referring to the same
2250 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2251 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2252 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
2254 if (irelscan < irelend)
2256 /* Some other function call depends upon this register load,
2257 and we have not yet converted that function call.
2258 Indeed, we may never be able to convert it. There is
2259 nothing else we can do at this point. */
2263 /* Look for a R_SH_COUNT reloc on the location where the
2264 function address is stored. Do this before deleting any
2265 bytes, to avoid confusion about the address. */
2266 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2267 if (irelcount->r_offset == paddr
2268 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
2271 /* Delete the register load. */
2272 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
2275 /* That will change things, so, just in case it permits some
2276 other function call to come within range, we should relax
2277 again. Note that this is not required, and it may be slow. */
2280 /* Now check whether we got a COUNT reloc. */
2281 if (irelcount >= irelend)
2283 ((*_bfd_error_handler)
2284 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2285 bfd_archive_filename (abfd), (unsigned long) paddr));
2289 /* The number of uses is stored in the r_addend field. We've
2290 just deleted one. */
2291 if (irelcount->r_addend == 0)
2293 ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
2294 bfd_archive_filename (abfd),
2295 (unsigned long) paddr));
2299 --irelcount->r_addend;
2301 /* If there are no more uses, we can delete the address. Reload
2302 the address from irelfn, in case it was changed by the
2303 previous call to sh_elf_relax_delete_bytes. */
2304 if (irelcount->r_addend == 0)
2306 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
2310 /* We've done all we can with that function call. */
2313 /* Look for load and store instructions that we can align on four
2319 /* Get the section contents. */
2320 if (contents == NULL)
2322 if (elf_section_data (sec)->this_hdr.contents != NULL)
2323 contents = elf_section_data (sec)->this_hdr.contents;
2326 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2327 if (contents == NULL)
2330 if (! bfd_get_section_contents (abfd, sec, contents,
2331 (file_ptr) 0, sec->_raw_size))
2336 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
2342 elf_section_data (sec)->relocs = internal_relocs;
2343 elf_section_data (sec)->this_hdr.contents = contents;
2344 symtab_hdr->contents = (unsigned char *) isymbuf;
2349 && symtab_hdr->contents != (unsigned char *) isymbuf)
2351 if (! link_info->keep_memory)
2355 /* Cache the symbols for elf_link_input_bfd. */
2356 symtab_hdr->contents = (unsigned char *) isymbuf;
2360 if (contents != NULL
2361 && elf_section_data (sec)->this_hdr.contents != contents)
2363 if (! link_info->keep_memory)
2367 /* Cache the section contents for elf_link_input_bfd. */
2368 elf_section_data (sec)->this_hdr.contents = contents;
2372 if (internal_relocs != NULL
2373 && elf_section_data (sec)->relocs != internal_relocs)
2374 free (internal_relocs);
2380 && symtab_hdr->contents != (unsigned char *) isymbuf)
2382 if (contents != NULL
2383 && elf_section_data (sec)->this_hdr.contents != contents)
2385 if (internal_relocs != NULL
2386 && elf_section_data (sec)->relocs != internal_relocs)
2387 free (internal_relocs);
2392 /* Delete some bytes from a section while relaxing. FIXME: There is a
2393 lot of duplication between this function and sh_relax_delete_bytes
2397 sh_elf_relax_delete_bytes (abfd, sec, addr, count)
2403 Elf_Internal_Shdr *symtab_hdr;
2404 unsigned int sec_shndx;
2406 Elf_Internal_Rela *irel, *irelend;
2407 Elf_Internal_Rela *irelalign;
2409 Elf_Internal_Sym *isymbuf, *isym, *isymend;
2410 struct elf_link_hash_entry **sym_hashes;
2411 struct elf_link_hash_entry **end_hashes;
2412 unsigned int symcount;
2415 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2416 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2418 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2420 contents = elf_section_data (sec)->this_hdr.contents;
2422 /* The deletion must stop at the next ALIGN reloc for an aligment
2423 power larger than the number of bytes we are deleting. */
2426 toaddr = sec->_cooked_size;
2428 irel = elf_section_data (sec)->relocs;
2429 irelend = irel + sec->reloc_count;
2430 for (; irel < irelend; irel++)
2432 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2433 && irel->r_offset > addr
2434 && count < (1 << irel->r_addend))
2437 toaddr = irel->r_offset;
2442 /* Actually delete the bytes. */
2443 memmove (contents + addr, contents + addr + count,
2444 (size_t) (toaddr - addr - count));
2445 if (irelalign == NULL)
2446 sec->_cooked_size -= count;
2451 #define NOP_OPCODE (0x0009)
2453 BFD_ASSERT ((count & 1) == 0);
2454 for (i = 0; i < count; i += 2)
2455 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
2458 /* Adjust all the relocs. */
2459 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2461 bfd_vma nraddr, stop;
2464 int off, adjust, oinsn;
2465 bfd_signed_vma voff = 0;
2468 /* Get the new reloc address. */
2469 nraddr = irel->r_offset;
2470 if ((irel->r_offset > addr
2471 && irel->r_offset < toaddr)
2472 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2473 && irel->r_offset == toaddr))
2476 /* See if this reloc was for the bytes we have deleted, in which
2477 case we no longer care about it. Don't delete relocs which
2478 represent addresses, though. */
2479 if (irel->r_offset >= addr
2480 && irel->r_offset < addr + count
2481 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
2482 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
2483 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
2484 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
2485 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2488 /* If this is a PC relative reloc, see if the range it covers
2489 includes the bytes we have deleted. */
2490 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2499 start = irel->r_offset;
2500 insn = bfd_get_16 (abfd, contents + nraddr);
2504 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2507 start = stop = addr;
2511 /* If this reloc is against a symbol defined in this
2512 section, and the symbol will not be adjusted below, we
2513 must check the addend to see it will put the value in
2514 range to be adjusted, and hence must be changed. */
2515 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2517 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2518 if (isym->st_shndx == sec_shndx
2519 && (isym->st_value <= addr
2520 || isym->st_value >= toaddr))
2524 val = bfd_get_32 (abfd, contents + nraddr);
2525 val += isym->st_value;
2526 if (val > addr && val < toaddr)
2527 bfd_put_32 (abfd, val - count, contents + nraddr);
2530 start = stop = addr;
2537 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2541 if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
2542 start = stop = addr;
2548 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2554 stop = start + 4 + off * 2;
2559 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
2565 /* These relocs types represent
2567 The r_addend field holds the difference between the reloc
2568 address and L1. That is the start of the reloc, and
2569 adding in the contents gives us the top. We must adjust
2570 both the r_offset field and the section contents.
2571 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2572 and the elf bfd r_offset is called r_vaddr. */
2574 stop = irel->r_offset;
2575 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
2579 && (stop <= addr || stop >= toaddr))
2580 irel->r_addend += count;
2581 else if (stop > addr
2583 && (start <= addr || start >= toaddr))
2584 irel->r_addend -= count;
2586 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
2587 voff = bfd_get_signed_16 (abfd, contents + nraddr);
2588 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
2589 voff = bfd_get_8 (abfd, contents + nraddr);
2591 voff = bfd_get_signed_32 (abfd, contents + nraddr);
2592 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2597 start = irel->r_offset;
2598 stop = (bfd_vma) ((bfd_signed_vma) start
2599 + (long) irel->r_addend
2606 && (stop <= addr || stop >= toaddr))
2608 else if (stop > addr
2610 && (start <= addr || start >= toaddr))
2619 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2628 if ((oinsn & 0xff00) != (insn & 0xff00))
2630 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2635 if ((oinsn & 0xf000) != (insn & 0xf000))
2637 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2641 BFD_ASSERT (adjust == count || count >= 4);
2646 if ((irel->r_offset & 3) == 0)
2649 if ((oinsn & 0xff00) != (insn & 0xff00))
2651 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2656 if (voff < 0 || voff >= 0xff)
2658 bfd_put_8 (abfd, voff, contents + nraddr);
2663 if (voff < - 0x8000 || voff >= 0x8000)
2665 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
2670 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
2674 irel->r_addend += adjust;
2680 ((*_bfd_error_handler)
2681 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2682 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2683 bfd_set_error (bfd_error_bad_value);
2688 irel->r_offset = nraddr;
2691 /* Look through all the other sections. If there contain any IMM32
2692 relocs against internal symbols which we are not going to adjust
2693 below, we may need to adjust the addends. */
2694 for (o = abfd->sections; o != NULL; o = o->next)
2696 Elf_Internal_Rela *internal_relocs;
2697 Elf_Internal_Rela *irelscan, *irelscanend;
2698 bfd_byte *ocontents;
2701 || (o->flags & SEC_RELOC) == 0
2702 || o->reloc_count == 0)
2705 /* We always cache the relocs. Perhaps, if info->keep_memory is
2706 false, we should free them, if we are permitted to, when we
2707 leave sh_coff_relax_section. */
2708 internal_relocs = (_bfd_elf32_link_read_relocs
2709 (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2711 if (internal_relocs == NULL)
2715 irelscanend = internal_relocs + o->reloc_count;
2716 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
2718 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2719 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
2721 bfd_vma start, stop;
2722 bfd_signed_vma voff;
2724 if (ocontents == NULL)
2726 if (elf_section_data (o)->this_hdr.contents != NULL)
2727 ocontents = elf_section_data (o)->this_hdr.contents;
2730 /* We always cache the section contents.
2731 Perhaps, if info->keep_memory is false, we
2732 should free them, if we are permitted to,
2733 when we leave sh_coff_relax_section. */
2734 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2735 if (ocontents == NULL)
2737 if (! bfd_get_section_contents (abfd, o, ocontents,
2741 elf_section_data (o)->this_hdr.contents = ocontents;
2745 stop = irelscan->r_offset;
2747 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
2749 /* STOP is in a different section, so it won't change. */
2750 if (start > addr && start < toaddr)
2751 irelscan->r_addend += count;
2753 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
2754 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2758 && (stop <= addr || stop >= toaddr))
2759 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
2760 ocontents + irelscan->r_offset);
2761 else if (stop > addr
2763 && (start <= addr || start >= toaddr))
2764 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
2765 ocontents + irelscan->r_offset);
2768 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
2771 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
2775 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
2776 if (isym->st_shndx == sec_shndx
2777 && (isym->st_value <= addr
2778 || isym->st_value >= toaddr))
2782 if (ocontents == NULL)
2784 if (elf_section_data (o)->this_hdr.contents != NULL)
2785 ocontents = elf_section_data (o)->this_hdr.contents;
2788 /* We always cache the section contents.
2789 Perhaps, if info->keep_memory is false, we
2790 should free them, if we are permitted to,
2791 when we leave sh_coff_relax_section. */
2792 ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
2793 if (ocontents == NULL)
2795 if (! bfd_get_section_contents (abfd, o, ocontents,
2799 elf_section_data (o)->this_hdr.contents = ocontents;
2803 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2804 val += isym->st_value;
2805 if (val > addr && val < toaddr)
2806 bfd_put_32 (abfd, val - count,
2807 ocontents + irelscan->r_offset);
2812 /* Adjust the local symbols defined in this section. */
2813 isymend = isymbuf + symtab_hdr->sh_info;
2814 for (isym = isymbuf; isym < isymend; isym++)
2816 if (isym->st_shndx == sec_shndx
2817 && isym->st_value > addr
2818 && isym->st_value < toaddr)
2819 isym->st_value -= count;
2822 /* Now adjust the global symbols defined in this section. */
2823 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2824 - symtab_hdr->sh_info);
2825 sym_hashes = elf_sym_hashes (abfd);
2826 end_hashes = sym_hashes + symcount;
2827 for (; sym_hashes < end_hashes; sym_hashes++)
2829 struct elf_link_hash_entry *sym_hash = *sym_hashes;
2830 if ((sym_hash->root.type == bfd_link_hash_defined
2831 || sym_hash->root.type == bfd_link_hash_defweak)
2832 && sym_hash->root.u.def.section == sec
2833 && sym_hash->root.u.def.value > addr
2834 && sym_hash->root.u.def.value < toaddr)
2836 sym_hash->root.u.def.value -= count;
2840 /* See if we can move the ALIGN reloc forward. We have adjusted
2841 r_offset for it already. */
2842 if (irelalign != NULL)
2844 bfd_vma alignto, alignaddr;
2846 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
2847 alignaddr = BFD_ALIGN (irelalign->r_offset,
2848 1 << irelalign->r_addend);
2849 if (alignto != alignaddr)
2851 /* Tail recursion. */
2852 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
2853 (int) (alignto - alignaddr));
2860 /* Look for loads and stores which we can align to four byte
2861 boundaries. This is like sh_align_loads in coff-sh.c. */
2864 sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
2865 bfd *abfd ATTRIBUTE_UNUSED;
2867 Elf_Internal_Rela *internal_relocs;
2868 bfd_byte *contents ATTRIBUTE_UNUSED;
2871 Elf_Internal_Rela *irel, *irelend;
2872 bfd_vma *labels = NULL;
2873 bfd_vma *label, *label_end;
2878 irelend = internal_relocs + sec->reloc_count;
2880 /* Get all the addresses with labels on them. */
2881 amt = sec->reloc_count;
2882 amt *= sizeof (bfd_vma);
2883 labels = (bfd_vma *) bfd_malloc (amt);
2887 for (irel = internal_relocs; irel < irelend; irel++)
2889 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
2891 *label_end = irel->r_offset;
2896 /* Note that the assembler currently always outputs relocs in
2897 address order. If that ever changes, this code will need to sort
2898 the label values and the relocs. */
2902 for (irel = internal_relocs; irel < irelend; irel++)
2904 bfd_vma start, stop;
2906 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
2909 start = irel->r_offset;
2911 for (irel++; irel < irelend; irel++)
2912 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
2915 stop = irel->r_offset;
2917 stop = sec->_cooked_size;
2919 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
2920 (PTR) internal_relocs, &label,
2921 label_end, start, stop, pswapped))
2935 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2938 sh_elf_swap_insns (abfd, sec, relocs, contents, addr)
2945 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
2946 unsigned short i1, i2;
2947 Elf_Internal_Rela *irel, *irelend;
2949 /* Swap the instructions themselves. */
2950 i1 = bfd_get_16 (abfd, contents + addr);
2951 i2 = bfd_get_16 (abfd, contents + addr + 2);
2952 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2953 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
2955 /* Adjust all reloc addresses. */
2956 irelend = internal_relocs + sec->reloc_count;
2957 for (irel = internal_relocs; irel < irelend; irel++)
2959 enum elf_sh_reloc_type type;
2962 /* There are a few special types of relocs that we don't want to
2963 adjust. These relocs do not apply to the instruction itself,
2964 but are only associated with the address. */
2965 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
2966 if (type == R_SH_ALIGN
2967 || type == R_SH_CODE
2968 || type == R_SH_DATA
2969 || type == R_SH_LABEL)
2972 /* If an R_SH_USES reloc points to one of the addresses being
2973 swapped, we must adjust it. It would be incorrect to do this
2974 for a jump, though, since we want to execute both
2975 instructions after the jump. (We have avoided swapping
2976 around a label, so the jump will not wind up executing an
2977 instruction it shouldn't). */
2978 if (type == R_SH_USES)
2982 off = irel->r_offset + 4 + irel->r_addend;
2984 irel->r_offset += 2;
2985 else if (off == addr + 2)
2986 irel->r_offset -= 2;
2989 if (irel->r_offset == addr)
2991 irel->r_offset += 2;
2994 else if (irel->r_offset == addr + 2)
2996 irel->r_offset -= 2;
3005 unsigned short insn, oinsn;
3008 loc = contents + irel->r_offset;
3017 insn = bfd_get_16 (abfd, loc);
3020 if ((oinsn & 0xff00) != (insn & 0xff00))
3022 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3026 insn = bfd_get_16 (abfd, loc);
3029 if ((oinsn & 0xf000) != (insn & 0xf000))
3031 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3035 /* This reloc ignores the least significant 3 bits of
3036 the program counter before adding in the offset.
3037 This means that if ADDR is at an even address, the
3038 swap will not affect the offset. If ADDR is an at an
3039 odd address, then the instruction will be crossing a
3040 four byte boundary, and must be adjusted. */
3041 if ((addr & 3) != 0)
3043 insn = bfd_get_16 (abfd, loc);
3046 if ((oinsn & 0xff00) != (insn & 0xff00))
3048 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3056 ((*_bfd_error_handler)
3057 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3058 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
3059 bfd_set_error (bfd_error_bad_value);
3068 #ifdef INCLUDE_SHMEDIA
3070 /* The size in bytes of an entry in the procedure linkage table. */
3072 #define PLT_ENTRY_SIZE 64
3074 /* First entry in an absolute procedure linkage table look like this. */
3076 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3078 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3079 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3080 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3081 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3082 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3083 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
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 */
3092 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3093 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3096 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3098 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3099 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3100 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3101 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3102 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3103 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
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 */
3112 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3113 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3116 /* Sebsequent entries in an absolute procedure linkage table look like
3119 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3121 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3122 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3123 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3124 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3125 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3126 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3127 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3128 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3129 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3130 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3131 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3132 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3133 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3134 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3135 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3136 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3139 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3141 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3142 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3143 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3144 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3145 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3146 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3147 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3148 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3149 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3150 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3151 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3152 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3153 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3154 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3155 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3156 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3159 /* Entries in a PIC procedure linkage table look like this. */
3161 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3163 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3164 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3165 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3166 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3167 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3168 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3169 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3170 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3171 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3172 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3173 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3174 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3175 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3176 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3177 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3178 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3181 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3183 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3184 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3185 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3186 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3187 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3188 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3189 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3190 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3191 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3192 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3193 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3194 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3195 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3196 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3197 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3198 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3201 static const bfd_byte *elf_sh_plt0_entry;
3202 static const bfd_byte *elf_sh_plt_entry;
3203 static const bfd_byte *elf_sh_pic_plt_entry;
3205 /* Return size of a PLT entry. */
3206 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3208 /* Return offset of the PLT0 address in an absolute PLT entry. */
3209 #define elf_sh_plt_plt0_offset(info) 32
3211 /* Return offset of the linker in PLT0 entry. */
3212 #define elf_sh_plt0_gotplt_offset(info) 0
3214 /* Return offset of the trampoline in PLT entry */
3215 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3217 /* Return offset of the symbol in PLT entry. */
3218 #define elf_sh_plt_symbol_offset(info) 0
3220 /* Return offset of the relocation in PLT entry. */
3221 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3224 movi_shori_putval (output_bfd, value, addr)
3226 unsigned long value;
3229 bfd_put_32 (output_bfd,
3230 bfd_get_32 (output_bfd, addr)
3231 | ((value >> 6) & 0x3fffc00),
3233 bfd_put_32 (output_bfd,
3234 bfd_get_32 (output_bfd, addr + 4)
3235 | ((value << 10) & 0x3fffc00),
3240 /* The size in bytes of an entry in the procedure linkage table. */
3242 #define PLT_ENTRY_SIZE 28
3244 /* First entry in an absolute procedure linkage table look like this. */
3247 /* Note - this code has been "optimised" not to use r2. r2 is used by
3248 GCC to return the address of large strutcures, so it should not be
3249 corrupted here. This does mean however, that this PLT does not conform
3250 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3251 and r2 contains the GOT id. This version stores the GOT id in r0 and
3252 ignores the type. Loaders can easily detect this difference however,
3253 since the type will always be 0 or 8, and the GOT ids will always be
3254 greater than or equal to 12. */
3255 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3257 0xd0, 0x05, /* mov.l 2f,r0 */
3258 0x60, 0x02, /* mov.l @r0,r0 */
3259 0x2f, 0x06, /* mov.l r0,@-r15 */
3260 0xd0, 0x03, /* mov.l 1f,r0 */
3261 0x60, 0x02, /* mov.l @r0,r0 */
3262 0x40, 0x2b, /* jmp @r0 */
3263 0x60, 0xf6, /* mov.l @r15+,r0 */
3264 0x00, 0x09, /* nop */
3265 0x00, 0x09, /* nop */
3266 0x00, 0x09, /* nop */
3267 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3268 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3271 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3273 0x05, 0xd0, /* mov.l 2f,r0 */
3274 0x02, 0x60, /* mov.l @r0,r0 */
3275 0x06, 0x2f, /* mov.l r0,@-r15 */
3276 0x03, 0xd0, /* mov.l 1f,r0 */
3277 0x02, 0x60, /* mov.l @r0,r0 */
3278 0x2b, 0x40, /* jmp @r0 */
3279 0xf6, 0x60, /* mov.l @r15+,r0 */
3280 0x09, 0x00, /* nop */
3281 0x09, 0x00, /* nop */
3282 0x09, 0x00, /* nop */
3283 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3284 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3287 /* Sebsequent entries in an absolute procedure linkage table look like
3290 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3292 0xd0, 0x04, /* mov.l 1f,r0 */
3293 0x60, 0x02, /* mov.l @r0,r0 */
3294 0xd1, 0x02, /* mov.l 0f,r1 */
3295 0x40, 0x2b, /* jmp @r0 */
3296 0x60, 0x13, /* mov r1,r0 */
3297 0xd1, 0x03, /* mov.l 2f,r1 */
3298 0x40, 0x2b, /* jmp @r0 */
3299 0x00, 0x09, /* nop */
3300 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3301 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3302 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3305 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3307 0x04, 0xd0, /* mov.l 1f,r0 */
3308 0x02, 0x60, /* mov.l @r0,r0 */
3309 0x02, 0xd1, /* mov.l 0f,r1 */
3310 0x2b, 0x40, /* jmp @r0 */
3311 0x13, 0x60, /* mov r1,r0 */
3312 0x03, 0xd1, /* mov.l 2f,r1 */
3313 0x2b, 0x40, /* jmp @r0 */
3314 0x09, 0x00, /* nop */
3315 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3316 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3317 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3320 /* Entries in a PIC procedure linkage table look like this. */
3322 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3324 0xd0, 0x04, /* mov.l 1f,r0 */
3325 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3326 0x40, 0x2b, /* jmp @r0 */
3327 0x00, 0x09, /* nop */
3328 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3329 0xd1, 0x03, /* mov.l 2f,r1 */
3330 0x40, 0x2b, /* jmp @r0 */
3331 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3332 0x00, 0x09, /* nop */
3333 0x00, 0x09, /* nop */
3334 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3335 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3338 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3340 0x04, 0xd0, /* mov.l 1f,r0 */
3341 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3342 0x2b, 0x40, /* jmp @r0 */
3343 0x09, 0x00, /* nop */
3344 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3345 0x03, 0xd1, /* mov.l 2f,r1 */
3346 0x2b, 0x40, /* jmp @r0 */
3347 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3348 0x09, 0x00, /* nop */
3349 0x09, 0x00, /* nop */
3350 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3351 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3354 #else /* These are the old style PLT entries. */
3355 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3357 0xd0, 0x04, /* mov.l 1f,r0 */
3358 0xd2, 0x05, /* mov.l 2f,r2 */
3359 0x60, 0x02, /* mov.l @r0,r0 */
3360 0x62, 0x22, /* mov.l @r2,r2 */
3361 0x40, 0x2b, /* jmp @r0 */
3362 0xe0, 0x00, /* mov #0,r0 */
3363 0x00, 0x09, /* nop */
3364 0x00, 0x09, /* nop */
3365 0x00, 0x09, /* nop */
3366 0x00, 0x09, /* nop */
3367 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3368 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3371 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3373 0x04, 0xd0, /* mov.l 1f,r0 */
3374 0x05, 0xd2, /* mov.l 2f,r2 */
3375 0x02, 0x60, /* mov.l @r0,r0 */
3376 0x22, 0x62, /* mov.l @r2,r2 */
3377 0x2b, 0x40, /* jmp @r0 */
3378 0x00, 0xe0, /* mov #0,r0 */
3379 0x09, 0x00, /* nop */
3380 0x09, 0x00, /* nop */
3381 0x09, 0x00, /* nop */
3382 0x09, 0x00, /* nop */
3383 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3384 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3387 /* Sebsequent entries in an absolute procedure linkage table look like
3390 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3392 0xd0, 0x04, /* mov.l 1f,r0 */
3393 0x60, 0x02, /* mov.l @r0,r0 */
3394 0xd2, 0x02, /* mov.l 0f,r2 */
3395 0x40, 0x2b, /* jmp @r0 */
3396 0x60, 0x23, /* mov r2,r0 */
3397 0xd1, 0x03, /* mov.l 2f,r1 */
3398 0x40, 0x2b, /* jmp @r0 */
3399 0x00, 0x09, /* nop */
3400 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3401 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3402 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3405 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3407 0x04, 0xd0, /* mov.l 1f,r0 */
3408 0x02, 0x60, /* mov.l @r0,r0 */
3409 0x02, 0xd2, /* mov.l 0f,r2 */
3410 0x2b, 0x40, /* jmp @r0 */
3411 0x23, 0x60, /* mov r2,r0 */
3412 0x03, 0xd1, /* mov.l 2f,r1 */
3413 0x2b, 0x40, /* jmp @r0 */
3414 0x09, 0x00, /* nop */
3415 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3416 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3417 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3420 /* Entries in a PIC procedure linkage table look like this. */
3422 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3424 0xd0, 0x04, /* mov.l 1f,r0 */
3425 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3426 0x40, 0x2b, /* jmp @r0 */
3427 0x00, 0x09, /* nop */
3428 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3429 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3430 0xd1, 0x02, /* mov.l 2f,r1 */
3431 0x40, 0x2b, /* jmp @r0 */
3432 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3433 0x00, 0x09, /* nop */
3434 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3435 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3438 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3440 0x04, 0xd0, /* mov.l 1f,r0 */
3441 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3442 0x2b, 0x40, /* jmp @r0 */
3443 0x09, 0x00, /* nop */
3444 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3445 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3446 0x02, 0xd1, /* mov.l 2f,r1 */
3447 0x2b, 0x40, /* jmp @r0 */
3448 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3449 0x09, 0x00, /* nop */
3450 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3451 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3453 #endif /* old style PLT entries. */
3455 static const bfd_byte *elf_sh_plt0_entry;
3456 static const bfd_byte *elf_sh_plt_entry;
3457 static const bfd_byte *elf_sh_pic_plt_entry;
3459 /* Return size of a PLT entry. */
3460 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3462 /* Return offset of the PLT0 address in an absolute PLT entry. */
3463 #define elf_sh_plt_plt0_offset(info) 16
3465 /* Return offset of the linker in PLT0 entry. */
3466 #define elf_sh_plt0_linker_offset(info) 20
3468 /* Return offset of the GOT id in PLT0 entry. */
3469 #define elf_sh_plt0_gotid_offset(info) 24
3471 /* Return offset of the tempoline in PLT entry */
3472 #define elf_sh_plt_temp_offset(info) 8
3474 /* Return offset of the symbol in PLT entry. */
3475 #define elf_sh_plt_symbol_offset(info) 20
3477 /* Return offset of the relocation in PLT entry. */
3478 #define elf_sh_plt_reloc_offset(info) 24
3481 /* The sh linker needs to keep track of the number of relocs that it
3482 decides to copy as dynamic relocs in check_relocs for each symbol.
3483 This is so that it can later discard them if they are found to be
3484 unnecessary. We store the information in a field extending the
3485 regular ELF linker hash table. */
3487 struct elf_sh_dyn_relocs
3489 struct elf_sh_dyn_relocs *next;
3491 /* The input section of the reloc. */
3494 /* Total number of relocs copied for the input section. */
3495 bfd_size_type count;
3497 /* Number of pc-relative relocs copied for the input section. */
3498 bfd_size_type pc_count;
3501 /* sh ELF linker hash entry. */
3503 struct elf_sh_link_hash_entry
3505 struct elf_link_hash_entry root;
3507 #ifdef INCLUDE_SHMEDIA
3510 bfd_signed_vma refcount;
3515 /* Track dynamic relocs copied for this symbol. */
3516 struct elf_sh_dyn_relocs *dyn_relocs;
3518 bfd_signed_vma gotplt_refcount;
3521 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
3524 /* If true, R_SH_TLS_TPOFF32 relocation is generated. */
3525 boolean tls_tpoff32;
3528 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3530 struct sh_elf_obj_tdata
3532 struct elf_obj_tdata root;
3534 /* tls_type for each local got entry. */
3535 char *local_got_tls_type;
3538 #define sh_elf_tdata(abfd) \
3539 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3541 #define sh_elf_local_got_tls_type(abfd) \
3542 (sh_elf_tdata (abfd)->local_got_tls_type)
3544 /* Override the generic function because we need to store sh_elf_obj_tdata
3545 as the specific tdata. */
3548 sh_elf_mkobject (abfd)
3551 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
3552 abfd->tdata.any = bfd_zalloc (abfd, amt);
3553 if (abfd->tdata.any == NULL)
3558 /* sh ELF linker hash table. */
3560 struct elf_sh_link_hash_table
3562 struct elf_link_hash_table root;
3564 /* Short-cuts to get to dynamic linker sections. */
3573 /* Small local sym to section mapping cache. */
3574 struct sym_sec_cache sym_sec;
3576 /* A counter or offset to track a TLS got entry. */
3579 bfd_signed_vma refcount;
3584 /* Traverse an sh ELF linker hash table. */
3586 #define sh_elf_link_hash_traverse(table, func, info) \
3587 (elf_link_hash_traverse \
3589 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3592 /* Get the sh ELF linker hash table from a link_info structure. */
3594 #define sh_elf_hash_table(p) \
3595 ((struct elf_sh_link_hash_table *) ((p)->hash))
3597 /* Create an entry in an sh ELF linker hash table. */
3599 static struct bfd_hash_entry *
3600 sh_elf_link_hash_newfunc (entry, table, string)
3601 struct bfd_hash_entry *entry;
3602 struct bfd_hash_table *table;
3605 struct elf_sh_link_hash_entry *ret =
3606 (struct elf_sh_link_hash_entry *) entry;
3608 /* Allocate the structure if it has not already been allocated by a
3610 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3611 ret = ((struct elf_sh_link_hash_entry *)
3612 bfd_hash_allocate (table,
3613 sizeof (struct elf_sh_link_hash_entry)));
3614 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3615 return (struct bfd_hash_entry *) ret;
3617 /* Call the allocation method of the superclass. */
3618 ret = ((struct elf_sh_link_hash_entry *)
3619 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3621 if (ret != (struct elf_sh_link_hash_entry *) NULL)
3623 ret->dyn_relocs = NULL;
3624 ret->gotplt_refcount = 0;
3625 #ifdef INCLUDE_SHMEDIA
3626 ret->datalabel_got.refcount = ret->root.got.refcount;
3628 ret->tls_type = GOT_UNKNOWN;
3629 ret->tls_tpoff32 = false;
3632 return (struct bfd_hash_entry *) ret;
3635 /* Create an sh ELF linker hash table. */
3637 static struct bfd_link_hash_table *
3638 sh_elf_link_hash_table_create (abfd)
3641 struct elf_sh_link_hash_table *ret;
3642 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
3644 ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
3645 if (ret == (struct elf_sh_link_hash_table *) NULL)
3648 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3649 sh_elf_link_hash_newfunc))
3656 ret->sgotplt = NULL;
3657 ret->srelgot = NULL;
3659 ret->srelplt = NULL;
3660 ret->sdynbss = NULL;
3661 ret->srelbss = NULL;
3662 ret->sym_sec.abfd = NULL;
3663 ret->tls_ldm_got.refcount = 0;
3665 return &ret->root.root;
3668 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3669 shortcuts to them in our hash table. */
3672 create_got_section (dynobj, info)
3674 struct bfd_link_info *info;
3676 struct elf_sh_link_hash_table *htab;
3678 if (! _bfd_elf_create_got_section (dynobj, info))
3681 htab = sh_elf_hash_table (info);
3682 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3683 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3684 if (! htab->sgot || ! htab->sgotplt)
3687 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3688 if (htab->srelgot == NULL
3689 || ! bfd_set_section_flags (dynobj, htab->srelgot,
3694 | SEC_LINKER_CREATED
3696 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
3701 /* Create dynamic sections when linking against a dynamic object. */
3704 sh_elf_create_dynamic_sections (abfd, info)
3706 struct bfd_link_info *info;
3708 struct elf_sh_link_hash_table *htab;
3709 flagword flags, pltflags;
3710 register asection *s;
3711 struct elf_backend_data *bed = get_elf_backend_data (abfd);
3714 switch (bed->s->arch_size)
3725 bfd_set_error (bfd_error_bad_value);
3729 htab = sh_elf_hash_table (info);
3731 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3732 .rel[a].bss sections. */
3734 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3735 | SEC_LINKER_CREATED);
3738 pltflags |= SEC_CODE;
3739 if (bed->plt_not_loaded)
3740 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3741 if (bed->plt_readonly)
3742 pltflags |= SEC_READONLY;
3744 s = bfd_make_section (abfd, ".plt");
3747 || ! bfd_set_section_flags (abfd, s, pltflags)
3748 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3751 if (bed->want_plt_sym)
3753 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3755 struct elf_link_hash_entry *h;
3756 struct bfd_link_hash_entry *bh = NULL;
3758 if (! (_bfd_generic_link_add_one_symbol
3759 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3760 (bfd_vma) 0, (const char *) NULL, false,
3761 get_elf_backend_data (abfd)->collect, &bh)))
3764 h = (struct elf_link_hash_entry *) bh;
3765 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3766 h->type = STT_OBJECT;
3769 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
3773 s = bfd_make_section (abfd,
3774 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3777 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3778 || ! bfd_set_section_alignment (abfd, s, ptralign))
3781 if (! create_got_section (abfd, info))
3785 const char *secname;
3790 for (sec = abfd->sections; sec; sec = sec->next)
3792 secflags = bfd_get_section_flags (abfd, sec);
3793 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3794 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3796 secname = bfd_get_section_name (abfd, sec);
3797 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3798 strcpy (relname, ".rela");
3799 strcat (relname, secname);
3800 s = bfd_make_section (abfd, relname);
3802 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3803 || ! bfd_set_section_alignment (abfd, s, ptralign))
3808 if (bed->want_dynbss)
3810 /* The .dynbss section is a place to put symbols which are defined
3811 by dynamic objects, are referenced by regular objects, and are
3812 not functions. We must allocate space for them in the process
3813 image and use a R_*_COPY reloc to tell the dynamic linker to
3814 initialize them at run time. The linker script puts the .dynbss
3815 section into the .bss section of the final image. */
3816 s = bfd_make_section (abfd, ".dynbss");
3819 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3822 /* The .rel[a].bss section holds copy relocs. This section is not
3823 normally needed. We need to create it here, though, so that the
3824 linker will map it to an output section. We can't just create it
3825 only if we need it, because we will not know whether we need it
3826 until we have seen all the input files, and the first time the
3827 main linker code calls BFD after examining all the input files
3828 (size_dynamic_sections) the input sections have already been
3829 mapped to the output sections. If the section turns out not to
3830 be needed, we can discard it later. We will never need this
3831 section when generating a shared object, since they do not use
3835 s = bfd_make_section (abfd,
3836 (bed->default_use_rela_p
3837 ? ".rela.bss" : ".rel.bss"));
3840 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3841 || ! bfd_set_section_alignment (abfd, s, ptralign))
3849 /* Adjust a symbol defined by a dynamic object and referenced by a
3850 regular object. The current definition is in some section of the
3851 dynamic object, but we're not including those sections. We have to
3852 change the definition to something the rest of the link can
3856 sh_elf_adjust_dynamic_symbol (info, h)
3857 struct bfd_link_info *info;
3858 struct elf_link_hash_entry *h;
3860 struct elf_sh_link_hash_table *htab;
3861 struct elf_sh_link_hash_entry *eh;
3862 struct elf_sh_dyn_relocs *p;
3865 unsigned int power_of_two;
3867 dynobj = elf_hash_table (info)->dynobj;
3869 /* Make sure we know what is going on here. */
3870 BFD_ASSERT (dynobj != NULL
3871 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
3872 || h->weakdef != NULL
3873 || ((h->elf_link_hash_flags
3874 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3875 && (h->elf_link_hash_flags
3876 & ELF_LINK_HASH_REF_REGULAR) != 0
3877 && (h->elf_link_hash_flags
3878 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
3880 /* If this is a function, put it in the procedure linkage table. We
3881 will fill in the contents of the procedure linkage table later,
3882 when we know the address of the .got section. */
3883 if (h->type == STT_FUNC
3884 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3886 if (h->plt.refcount <= 0
3888 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3889 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
3890 && h->root.type != bfd_link_hash_undefweak
3891 && h->root.type != bfd_link_hash_undefined))
3893 /* This case can occur if we saw a PLT reloc in an input
3894 file, but the symbol was never referred to by a dynamic
3895 object. In such a case, we don't actually need to build
3896 a procedure linkage table, and we can just do a REL32
3898 h->plt.offset = (bfd_vma) -1;
3899 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3905 h->plt.offset = (bfd_vma) -1;
3907 /* If this is a weak symbol, and there is a real definition, the
3908 processor independent code will have arranged for us to see the
3909 real definition first, and we can just use the same value. */
3910 if (h->weakdef != NULL)
3912 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3913 || h->weakdef->root.type == bfd_link_hash_defweak);
3914 h->root.u.def.section = h->weakdef->root.u.def.section;
3915 h->root.u.def.value = h->weakdef->root.u.def.value;
3919 /* This is a reference to a symbol defined by a dynamic object which
3920 is not a function. */
3922 /* If we are creating a shared library, we must presume that the
3923 only references to the symbol are via the global offset table.
3924 For such cases we need not do anything here; the relocations will
3925 be handled correctly by relocate_section. */
3929 /* If there are no references to this symbol that do not use the
3930 GOT, we don't need to generate a copy reloc. */
3931 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3934 /* If -z nocopyreloc was given, we won't generate them either. */
3935 if (info->nocopyreloc)
3937 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3941 eh = (struct elf_sh_link_hash_entry *) h;
3942 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3944 s = p->sec->output_section;
3945 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
3949 /* If we didn't find any dynamic relocs in sections which needs the
3950 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3954 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3958 /* We must allocate the symbol in our .dynbss section, which will
3959 become part of the .bss section of the executable. There will be
3960 an entry for this symbol in the .dynsym section. The dynamic
3961 object will contain position independent code, so all references
3962 from the dynamic object to this symbol will go through the global
3963 offset table. The dynamic linker will use the .dynsym entry to
3964 determine the address it must put in the global offset table, so
3965 both the dynamic object and the regular object will refer to the
3966 same memory location for the variable. */
3968 htab = sh_elf_hash_table (info);
3970 BFD_ASSERT (s != NULL);
3972 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3973 copy the initial value out of the dynamic object and into the
3974 runtime process image. We need to remember the offset into the
3975 .rela.bss section we are going to use. */
3976 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3980 srel = htab->srelbss;
3981 BFD_ASSERT (srel != NULL);
3982 srel->_raw_size += sizeof (Elf32_External_Rela);
3983 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3986 /* We need to figure out the alignment required for this symbol. I
3987 have no idea how ELF linkers handle this. */
3988 power_of_two = bfd_log2 (h->size);
3989 if (power_of_two > 3)
3992 /* Apply the required alignment. */
3993 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3994 if (power_of_two > bfd_get_section_alignment (dynobj, s))
3996 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
4000 /* Define the symbol as being at this point in the section. */
4001 h->root.u.def.section = s;
4002 h->root.u.def.value = s->_raw_size;
4004 /* Increment the section size to make room for the symbol. */
4005 s->_raw_size += h->size;
4010 /* This is the condition under which sh_elf_finish_dynamic_symbol
4011 will be called from elflink.h. If elflink.h doesn't call our
4012 finish_dynamic_symbol routine, we'll need to do something about
4013 initializing any .plt and .got entries in sh_elf_relocate_section. */
4014 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
4016 && ((INFO)->shared \
4017 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4018 && ((H)->dynindx != -1 \
4019 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4021 /* Allocate space in .plt, .got and associated reloc sections for
4025 allocate_dynrelocs (h, inf)
4026 struct elf_link_hash_entry *h;
4029 struct bfd_link_info *info;
4030 struct elf_sh_link_hash_table *htab;
4031 struct elf_sh_link_hash_entry *eh;
4032 struct elf_sh_dyn_relocs *p;
4034 if (h->root.type == bfd_link_hash_indirect)
4037 if (h->root.type == bfd_link_hash_warning)
4038 /* When warning symbols are created, they **replace** the "real"
4039 entry in the hash table, thus we never get to see the real
4040 symbol in a hash traversal. So look at it now. */
4041 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4043 info = (struct bfd_link_info *) inf;
4044 htab = sh_elf_hash_table (info);
4046 eh = (struct elf_sh_link_hash_entry *) h;
4047 if ((h->got.refcount > 0
4048 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
4049 && eh->gotplt_refcount > 0)
4051 /* The symbol has been forced local, or we have some direct got refs,
4052 so treat all the gotplt refs as got refs. */
4053 h->got.refcount += eh->gotplt_refcount;
4054 if (h->plt.refcount >= eh->gotplt_refcount)
4055 h->plt.refcount -= eh->gotplt_refcount;
4058 if (htab->root.dynamic_sections_created
4059 && h->plt.refcount > 0)
4061 /* Make sure this symbol is output as a dynamic symbol.
4062 Undefined weak syms won't yet be marked as dynamic. */
4063 if (h->dynindx == -1
4064 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4066 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4070 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
4072 asection *s = htab->splt;
4074 /* If this is the first .plt entry, make room for the special
4076 if (s->_raw_size == 0)
4077 s->_raw_size += PLT_ENTRY_SIZE;
4079 h->plt.offset = s->_raw_size;
4081 /* If this symbol is not defined in a regular file, and we are
4082 not generating a shared library, then set the symbol to this
4083 location in the .plt. This is required to make function
4084 pointers compare as equal between the normal executable and
4085 the shared library. */
4087 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4089 h->root.u.def.section = s;
4090 h->root.u.def.value = h->plt.offset;
4093 /* Make room for this entry. */
4094 s->_raw_size += PLT_ENTRY_SIZE;
4096 /* We also need to make an entry in the .got.plt section, which
4097 will be placed in the .got section by the linker script. */
4098 htab->sgotplt->_raw_size += 4;
4100 /* We also need to make an entry in the .rel.plt section. */
4101 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
4105 h->plt.offset = (bfd_vma) -1;
4106 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4111 h->plt.offset = (bfd_vma) -1;
4112 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4115 if (h->got.refcount > 0)
4119 int tls_type = sh_elf_hash_entry (h)->tls_type;
4121 /* Make sure this symbol is output as a dynamic symbol.
4122 Undefined weak syms won't yet be marked as dynamic. */
4123 if (h->dynindx == -1
4124 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4126 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4131 h->got.offset = s->_raw_size;
4133 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4134 if (tls_type == GOT_TLS_GD)
4136 dyn = htab->root.dynamic_sections_created;
4137 /* R_SH_TLS_IE_32 needs one dynamic relocation,
4138 R_SH_TLS_GD needs one if local symbol and two if global. */
4139 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
4140 || tls_type == GOT_TLS_IE)
4141 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4142 else if (tls_type == GOT_TLS_GD)
4143 htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
4144 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
4145 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4148 h->got.offset = (bfd_vma) -1;
4150 #ifdef INCLUDE_SHMEDIA
4151 if (eh->datalabel_got.refcount > 0)
4156 /* Make sure this symbol is output as a dynamic symbol.
4157 Undefined weak syms won't yet be marked as dynamic. */
4158 if (h->dynindx == -1
4159 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4161 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4166 eh->datalabel_got.offset = s->_raw_size;
4168 dyn = htab->root.dynamic_sections_created;
4169 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
4170 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4173 eh->datalabel_got.offset = (bfd_vma) -1;
4176 if (eh->dyn_relocs == NULL)
4179 /* In the shared -Bsymbolic case, discard space allocated for
4180 dynamic pc-relative relocs against symbols which turn out to be
4181 defined in regular objects. For the normal shared case, discard
4182 space for pc-relative relocs that have become local due to symbol
4183 visibility changes. */
4187 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
4188 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
4191 struct elf_sh_dyn_relocs **pp;
4193 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4195 p->count -= p->pc_count;
4206 if (sh_elf_hash_entry (h)->tls_tpoff32)
4209 /* For the non-shared case, discard space for relocs against
4210 symbols which turn out to need copy relocs or are not
4213 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
4214 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4215 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4216 || (htab->root.dynamic_sections_created
4217 && (h->root.type == bfd_link_hash_undefweak
4218 || h->root.type == bfd_link_hash_undefined))))
4220 /* Make sure this symbol is output as a dynamic symbol.
4221 Undefined weak syms won't yet be marked as dynamic. */
4222 if (h->dynindx == -1
4223 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4225 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
4229 /* If that succeeded, we know we'll be keeping all the
4231 if (h->dynindx != -1)
4235 eh->dyn_relocs = NULL;
4240 /* Finally, allocate space. */
4241 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4243 asection *sreloc = elf_section_data (p->sec)->sreloc;
4244 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
4250 /* Find any dynamic relocs that apply to read-only sections. */
4253 readonly_dynrelocs (h, inf)
4254 struct elf_link_hash_entry *h;
4257 struct elf_sh_link_hash_entry *eh;
4258 struct elf_sh_dyn_relocs *p;
4260 if (h->root.type == bfd_link_hash_warning)
4261 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4263 eh = (struct elf_sh_link_hash_entry *) h;
4264 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4266 asection *s = p->sec->output_section;
4268 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4270 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4272 info->flags |= DF_TEXTREL;
4274 /* Not an error, just cut short the traversal. */
4281 /* Set the sizes of the dynamic sections. */
4284 sh_elf_size_dynamic_sections (output_bfd, info)
4285 bfd *output_bfd ATTRIBUTE_UNUSED;
4286 struct bfd_link_info *info;
4288 struct elf_sh_link_hash_table *htab;
4294 htab = sh_elf_hash_table (info);
4295 dynobj = htab->root.dynobj;
4296 BFD_ASSERT (dynobj != NULL);
4298 if (htab->root.dynamic_sections_created)
4300 /* Set the contents of the .interp section to the interpreter. */
4303 s = bfd_get_section_by_name (dynobj, ".interp");
4304 BFD_ASSERT (s != NULL);
4305 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4306 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4310 /* Set up .got offsets for local syms, and space for local dynamic
4312 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4314 bfd_signed_vma *local_got;
4315 bfd_signed_vma *end_local_got;
4316 char *local_tls_type;
4317 bfd_size_type locsymcount;
4318 Elf_Internal_Shdr *symtab_hdr;
4321 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4324 for (s = ibfd->sections; s != NULL; s = s->next)
4326 struct elf_sh_dyn_relocs *p;
4328 for (p = ((struct elf_sh_dyn_relocs *)
4329 elf_section_data (s)->local_dynrel);
4333 if (! bfd_is_abs_section (p->sec)
4334 && bfd_is_abs_section (p->sec->output_section))
4336 /* Input section has been discarded, either because
4337 it is a copy of a linkonce section or due to
4338 linker script /DISCARD/, so we'll be discarding
4341 else if (p->count != 0)
4343 srel = elf_section_data (p->sec)->sreloc;
4344 srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
4345 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4346 info->flags |= DF_TEXTREL;
4351 local_got = elf_local_got_refcounts (ibfd);
4355 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4356 locsymcount = symtab_hdr->sh_info;
4357 #ifdef INCLUDE_SHMEDIA
4358 /* Count datalabel local GOT. */
4361 end_local_got = local_got + locsymcount;
4362 local_tls_type = sh_elf_local_got_tls_type (ibfd);
4364 srel = htab->srelgot;
4365 for (; local_got < end_local_got; ++local_got)
4369 *local_got = s->_raw_size;
4371 if (*local_tls_type == GOT_TLS_GD)
4374 srel->_raw_size += sizeof (Elf32_External_Rela);
4377 *local_got = (bfd_vma) -1;
4382 if (htab->tls_ldm_got.refcount > 0)
4384 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4386 htab->tls_ldm_got.offset = htab->sgot->_raw_size;
4387 htab->sgot->_raw_size += 8;
4388 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
4391 htab->tls_ldm_got.offset = -1;
4393 /* Allocate global sym .plt and .got entries, and space for global
4394 sym dynamic relocs. */
4395 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (PTR) info);
4397 /* We now have determined the sizes of the various dynamic sections.
4398 Allocate memory for them. */
4400 for (s = dynobj->sections; s != NULL; s = s->next)
4402 if ((s->flags & SEC_LINKER_CREATED) == 0)
4407 || s == htab->sgotplt)
4409 /* Strip this section if we don't need it; see the
4412 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4414 if (s->_raw_size != 0 && s != htab->srelplt)
4417 /* We use the reloc_count field as a counter if we need
4418 to copy relocs into the output file. */
4423 /* It's not one of our sections, so don't allocate space. */
4427 if (s->_raw_size == 0)
4429 /* If we don't need this section, strip it from the
4430 output file. This is mostly to handle .rela.bss and
4431 .rela.plt. We must create both sections in
4432 create_dynamic_sections, because they must be created
4433 before the linker maps input sections to output
4434 sections. The linker does that before
4435 adjust_dynamic_symbol is called, and it is that
4436 function which decides whether anything needs to go
4437 into these sections. */
4439 _bfd_strip_section_from_output (info, s);
4443 /* Allocate memory for the section contents. We use bfd_zalloc
4444 here in case unused entries are not reclaimed before the
4445 section's contents are written out. This should not happen,
4446 but this way if it does, we get a R_SH_NONE reloc instead
4448 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4449 if (s->contents == NULL)
4453 if (htab->root.dynamic_sections_created)
4455 /* Add some entries to the .dynamic section. We fill in the
4456 values later, in sh_elf_finish_dynamic_sections, but we
4457 must add the entries now so that we get the correct size for
4458 the .dynamic section. The DT_DEBUG entry is filled in by the
4459 dynamic linker and used by the debugger. */
4460 #define add_dynamic_entry(TAG, VAL) \
4461 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4465 if (! add_dynamic_entry (DT_DEBUG, 0))
4469 if (htab->splt->_raw_size != 0)
4471 if (! add_dynamic_entry (DT_PLTGOT, 0)
4472 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
4473 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
4474 || ! add_dynamic_entry (DT_JMPREL, 0))
4480 if (! add_dynamic_entry (DT_RELA, 0)
4481 || ! add_dynamic_entry (DT_RELASZ, 0)
4482 || ! add_dynamic_entry (DT_RELAENT,
4483 sizeof (Elf32_External_Rela)))
4486 /* If any dynamic relocs apply to a read-only section,
4487 then we need a DT_TEXTREL entry. */
4488 if ((info->flags & DF_TEXTREL) == 0)
4489 elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
4492 if ((info->flags & DF_TEXTREL) != 0)
4494 if (! add_dynamic_entry (DT_TEXTREL, 0))
4499 #undef add_dynamic_entry
4504 /* Relocate an SH ELF section. */
4507 sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4508 contents, relocs, local_syms, local_sections)
4510 struct bfd_link_info *info;
4512 asection *input_section;
4514 Elf_Internal_Rela *relocs;
4515 Elf_Internal_Sym *local_syms;
4516 asection **local_sections;
4518 struct elf_sh_link_hash_table *htab;
4519 Elf_Internal_Shdr *symtab_hdr;
4520 struct elf_link_hash_entry **sym_hashes;
4521 Elf_Internal_Rela *rel, *relend;
4523 bfd_vma *local_got_offsets;
4530 htab = sh_elf_hash_table (info);
4531 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4532 sym_hashes = elf_sym_hashes (input_bfd);
4533 dynobj = htab->root.dynobj;
4534 local_got_offsets = elf_local_got_offsets (input_bfd);
4537 sgotplt = htab->sgotplt;
4543 relend = relocs + input_section->reloc_count;
4544 for (; rel < relend; rel++)
4547 reloc_howto_type *howto;
4548 unsigned long r_symndx;
4549 Elf_Internal_Sym *sym;
4551 struct elf_link_hash_entry *h;
4553 bfd_vma addend = (bfd_vma) 0;
4554 bfd_reloc_status_type r;
4555 int seen_stt_datalabel = 0;
4559 r_symndx = ELF32_R_SYM (rel->r_info);
4561 r_type = ELF32_R_TYPE (rel->r_info);
4563 /* Many of the relocs are only used for relaxing, and are
4564 handled entirely by the relaxation code. */
4565 if (r_type > (int) R_SH_LAST_INVALID_RELOC
4566 && r_type < (int) R_SH_LOOP_START)
4568 if (r_type == (int) R_SH_NONE)
4572 || r_type >= R_SH_max
4573 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
4574 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
4575 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
4576 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4577 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4578 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
4579 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
4580 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
4581 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4582 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
4584 bfd_set_error (bfd_error_bad_value);
4588 howto = sh_elf_howto_table + r_type;
4590 /* For relocs that aren't partial_inplace, we get the addend from
4592 if (! howto->partial_inplace)
4593 addend = rel->r_addend;
4598 if (r_symndx < symtab_hdr->sh_info)
4600 sym = local_syms + r_symndx;
4601 sec = local_sections[r_symndx];
4602 relocation = (sec->output_section->vma
4603 + sec->output_offset
4605 /* A local symbol never has STO_SH5_ISA32, so we don't need
4606 datalabel processing here. Make sure this does not change
4608 if ((sym->st_other & STO_SH5_ISA32) != 0)
4609 ((*info->callbacks->reloc_dangerous)
4611 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4612 input_bfd, input_section, rel->r_offset));
4613 if (info->relocateable)
4615 /* This is a relocateable link. We don't have to change
4616 anything, unless the reloc is against a section symbol,
4617 in which case we have to adjust according to where the
4618 section symbol winds up in the output section. */
4619 sym = local_syms + r_symndx;
4620 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4622 if (! howto->partial_inplace)
4624 /* For relocations with the addend in the
4625 relocation, we need just to update the addend.
4626 All real relocs are of type partial_inplace; this
4627 code is mostly for completeness. */
4628 rel->r_addend += sec->output_offset + sym->st_value;
4633 /* Relocs of type partial_inplace need to pick up the
4634 contents in the contents and add the offset resulting
4635 from the changed location of the section symbol.
4636 Using _bfd_final_link_relocate (e.g. goto
4637 final_link_relocate) here would be wrong, because
4638 relocations marked pc_relative would get the current
4639 location subtracted, and we must only do that at the
4641 r = _bfd_relocate_contents (howto, input_bfd,
4644 contents + rel->r_offset);
4645 goto relocation_done;
4650 else if (! howto->partial_inplace)
4652 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4653 addend = rel->r_addend;
4655 else if ((sec->flags & SEC_MERGE)
4656 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4660 if (howto->rightshift || howto->src_mask != 0xffffffff)
4662 (*_bfd_error_handler)
4663 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4664 bfd_archive_filename (input_bfd),
4665 bfd_get_section_name (input_bfd, input_section),
4666 (long) rel->r_offset, howto->name);
4670 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4673 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4675 addend += msec->output_section->vma + msec->output_offset;
4676 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4682 /* Section symbol are never (?) placed in the hash table, so
4683 we can just ignore hash relocations when creating a
4684 relocateable object file. */
4685 if (info->relocateable)
4688 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4689 while (h->root.type == bfd_link_hash_indirect
4690 || h->root.type == bfd_link_hash_warning)
4692 #ifdef INCLUDE_SHMEDIA
4693 /* If the reference passes a symbol marked with
4694 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4696 seen_stt_datalabel |= h->type == STT_DATALABEL;
4698 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4700 if (h->root.type == bfd_link_hash_defined
4701 || h->root.type == bfd_link_hash_defweak)
4705 dyn = htab->root.dynamic_sections_created;
4706 sec = h->root.u.def.section;
4707 /* In these cases, we don't need the relocation value.
4708 We check specially because in some obscure cases
4709 sec->output_section will be NULL. */
4710 if (r_type == R_SH_GOTPC
4711 || r_type == R_SH_GOTPC_LOW16
4712 || r_type == R_SH_GOTPC_MEDLOW16
4713 || r_type == R_SH_GOTPC_MEDHI16
4714 || r_type == R_SH_GOTPC_HI16
4715 || ((r_type == R_SH_PLT32
4716 || r_type == R_SH_PLT_LOW16
4717 || r_type == R_SH_PLT_MEDLOW16
4718 || r_type == R_SH_PLT_MEDHI16
4719 || r_type == R_SH_PLT_HI16)
4720 && h->plt.offset != (bfd_vma) -1)
4721 || ((r_type == R_SH_GOT32
4722 || r_type == R_SH_GOT_LOW16
4723 || r_type == R_SH_GOT_MEDLOW16
4724 || r_type == R_SH_GOT_MEDHI16
4725 || r_type == R_SH_GOT_HI16)
4726 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
4728 || (! info->symbolic && h->dynindx != -1)
4729 || (h->elf_link_hash_flags
4730 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4731 /* The cases above are those in which relocation is
4732 overwritten in the switch block below. The cases
4733 below are those in which we must defer relocation
4734 to run-time, because we can't resolve absolute
4735 addresses when creating a shared library. */
4737 && ((! info->symbolic && h->dynindx != -1)
4738 || (h->elf_link_hash_flags
4739 & ELF_LINK_HASH_DEF_REGULAR) == 0)
4740 && ((r_type == R_SH_DIR32
4741 && (h->elf_link_hash_flags
4742 & ELF_LINK_FORCED_LOCAL) == 0)
4743 || r_type == R_SH_REL32)
4744 && ((input_section->flags & SEC_ALLOC) != 0
4745 /* DWARF will emit R_SH_DIR32 relocations in its
4746 sections against symbols defined externally
4747 in shared libraries. We can't do anything
4749 || ((input_section->flags & SEC_DEBUGGING) != 0
4750 && (h->elf_link_hash_flags
4751 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
4752 || (sec->output_section == NULL
4753 && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
4754 || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
4756 else if (sec->output_section == NULL)
4758 (*_bfd_error_handler)
4759 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4760 bfd_archive_filename (input_bfd), h->root.root.string,
4761 bfd_get_section_name (input_bfd, input_section));
4765 relocation = ((h->root.u.def.value
4766 + sec->output_section->vma
4767 + sec->output_offset)
4768 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4769 symbol value, unless we've seen
4770 STT_DATALABEL on the way to it. */
4771 | ((h->other & STO_SH5_ISA32) != 0
4772 && ! seen_stt_datalabel));
4774 else if (h->root.type == bfd_link_hash_undefweak)
4776 else if (info->shared
4777 && (! info->symbolic || info->allow_shlib_undefined)
4778 && ! info->no_undefined
4779 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4783 if (! ((*info->callbacks->undefined_symbol)
4784 (info, h->root.root.string, input_bfd,
4785 input_section, rel->r_offset,
4786 (!info->shared || info->no_undefined
4787 || ELF_ST_VISIBILITY (h->other)))))
4793 switch ((int) r_type)
4795 final_link_relocate:
4796 /* COFF relocs don't use the addend. The addend is used for
4797 R_SH_DIR32 to be compatible with other compilers. */
4798 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4799 contents, rel->r_offset,
4800 relocation, addend);
4805 goto final_link_relocate;
4810 /* If the reloc is against the start of this section, then
4811 the assembler has already taken care of it and the reloc
4812 is here only to assist in relaxing. If the reloc is not
4813 against the start of this section, then it's against an
4814 external symbol and we must deal with it ourselves. */
4815 if (input_section->output_section->vma + input_section->output_offset
4818 int disp = (relocation
4819 - input_section->output_section->vma
4820 - input_section->output_offset
4826 case R_SH_DIR8WPZ: mask = 1; break;
4827 case R_SH_DIR8WPL: mask = 3; break;
4828 default: mask = 0; break;
4832 ((*_bfd_error_handler)
4833 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4834 bfd_archive_filename (input_section->owner),
4835 (unsigned long) rel->r_offset));
4836 bfd_set_error (bfd_error_bad_value);
4840 goto final_link_relocate;
4846 #ifdef INCLUDE_SHMEDIA
4847 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4848 contents, rel, &relocation))
4849 goto final_link_relocate;
4851 bfd_set_error (bfd_error_bad_value);
4858 && (input_section->flags & SEC_ALLOC) != 0
4859 && (r_type != R_SH_REL32
4862 && (! info->symbolic
4863 || (h->elf_link_hash_flags
4864 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
4866 Elf_Internal_Rela outrel;
4867 boolean skip, relocate;
4869 /* When generating a shared object, these relocations
4870 are copied into the output file to be resolved at run
4877 name = (bfd_elf_string_from_elf_section
4879 elf_elfheader (input_bfd)->e_shstrndx,
4880 elf_section_data (input_section)->rel_hdr.sh_name));
4884 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4885 && strcmp (bfd_get_section_name (input_bfd,
4889 sreloc = bfd_get_section_by_name (dynobj, name);
4890 BFD_ASSERT (sreloc != NULL);
4897 _bfd_elf_section_offset (output_bfd, info, input_section,
4899 if (outrel.r_offset == (bfd_vma) -1)
4901 else if (outrel.r_offset == (bfd_vma) -2)
4902 skip = true, relocate = true;
4903 outrel.r_offset += (input_section->output_section->vma
4904 + input_section->output_offset);
4907 memset (&outrel, 0, sizeof outrel);
4908 else if (r_type == R_SH_REL32)
4910 BFD_ASSERT (h != NULL && h->dynindx != -1);
4911 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
4913 = bfd_get_32 (input_bfd, contents + rel->r_offset);
4917 /* h->dynindx may be -1 if this symbol was marked to
4920 || ((info->symbolic || h->dynindx == -1)
4921 && (h->elf_link_hash_flags
4922 & ELF_LINK_HASH_DEF_REGULAR) != 0))
4925 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
4927 = relocation + bfd_get_32 (input_bfd,
4928 contents + rel->r_offset);
4932 BFD_ASSERT (h->dynindx != -1);
4933 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
4935 = relocation + bfd_get_32 (input_bfd,
4936 contents + rel->r_offset);
4940 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
4941 (((Elf32_External_Rela *)
4943 + sreloc->reloc_count));
4944 ++sreloc->reloc_count;
4946 /* If this reloc is against an external symbol, we do
4947 not want to fiddle with the addend. Otherwise, we
4948 need to include the symbol value so that it becomes
4949 an addend for the dynamic reloc. */
4953 goto final_link_relocate;
4956 #ifdef INCLUDE_SHMEDIA
4957 case R_SH_GOTPLT_LOW16:
4958 case R_SH_GOTPLT_MEDLOW16:
4959 case R_SH_GOTPLT_MEDHI16:
4960 case R_SH_GOTPLT_HI16:
4961 case R_SH_GOTPLT10BY4:
4962 case R_SH_GOTPLT10BY8:
4964 /* Relocation is to the entry for this symbol in the
4965 procedure linkage table. */
4968 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
4972 || h->plt.offset == (bfd_vma) -1
4973 || h->got.offset != (bfd_vma) -1)
4976 /* Relocation is to the entry for this symbol in the global
4977 offset table extension for the procedure linkage table. */
4979 BFD_ASSERT (sgotplt != NULL);
4980 relocation = (sgotplt->output_offset
4981 + ((h->plt.offset / elf_sh_sizeof_plt (info)
4985 relocation -= GOT_BIAS;
4988 goto final_link_relocate;
4992 #ifdef INCLUDE_SHMEDIA
4993 case R_SH_GOT_LOW16:
4994 case R_SH_GOT_MEDLOW16:
4995 case R_SH_GOT_MEDHI16:
5000 /* Relocation is to the entry for this symbol in the global
5003 BFD_ASSERT (sgot != NULL);
5009 off = h->got.offset;
5010 #ifdef INCLUDE_SHMEDIA
5011 if (seen_stt_datalabel)
5013 struct elf_sh_link_hash_entry *hsh;
5015 hsh = (struct elf_sh_link_hash_entry *)h;
5016 off = hsh->datalabel_got.offset;
5019 BFD_ASSERT (off != (bfd_vma) -1);
5021 dyn = htab->root.dynamic_sections_created;
5022 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5024 && (info->symbolic || h->dynindx == -1
5025 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
5026 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5028 /* This is actually a static link, or it is a
5029 -Bsymbolic link and the symbol is defined
5030 locally, or the symbol was forced to be local
5031 because of a version file. We must initialize
5032 this entry in the global offset table. Since the
5033 offset must always be a multiple of 4, we use the
5034 least significant bit to record whether we have
5035 initialized it already.
5037 When doing a dynamic link, we create a .rela.got
5038 relocation entry to initialize the value. This
5039 is done in the finish_dynamic_symbol routine. */
5044 bfd_put_32 (output_bfd, relocation,
5045 sgot->contents + off);
5046 #ifdef INCLUDE_SHMEDIA
5047 if (seen_stt_datalabel)
5049 struct elf_sh_link_hash_entry *hsh;
5051 hsh = (struct elf_sh_link_hash_entry *)h;
5052 hsh->datalabel_got.offset |= 1;
5060 relocation = sgot->output_offset + off;
5064 #ifdef INCLUDE_SHMEDIA
5067 BFD_ASSERT (local_got_offsets != NULL
5068 && (local_got_offsets[symtab_hdr->sh_info
5072 off = local_got_offsets[symtab_hdr->sh_info
5078 BFD_ASSERT (local_got_offsets != NULL
5079 && local_got_offsets[r_symndx] != (bfd_vma) -1);
5081 off = local_got_offsets[r_symndx];
5082 #ifdef INCLUDE_SHMEDIA
5086 /* The offset must always be a multiple of 4. We use
5087 the least significant bit to record whether we have
5088 already generated the necessary reloc. */
5093 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5097 Elf_Internal_Rela outrel;
5099 if (srelgot == NULL)
5101 srelgot = bfd_get_section_by_name (dynobj,
5103 BFD_ASSERT (srelgot != NULL);
5106 outrel.r_offset = (sgot->output_section->vma
5107 + sgot->output_offset
5109 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5110 outrel.r_addend = relocation;
5111 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
5112 (((Elf32_External_Rela *)
5114 + srelgot->reloc_count));
5115 ++srelgot->reloc_count;
5118 #ifdef INCLUDE_SHMEDIA
5120 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
5123 local_got_offsets[r_symndx] |= 1;
5126 relocation = sgot->output_offset + off;
5130 relocation -= GOT_BIAS;
5133 goto final_link_relocate;
5136 #ifdef INCLUDE_SHMEDIA
5137 case R_SH_GOTOFF_LOW16:
5138 case R_SH_GOTOFF_MEDLOW16:
5139 case R_SH_GOTOFF_MEDHI16:
5140 case R_SH_GOTOFF_HI16:
5142 /* Relocation is relative to the start of the global offset
5145 BFD_ASSERT (sgot != NULL);
5147 /* Note that sgot->output_offset is not involved in this
5148 calculation. We always want the start of .got. If we
5149 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5150 permitted by the ABI, we might have to change this
5152 relocation -= sgot->output_section->vma;
5155 relocation -= GOT_BIAS;
5158 addend = rel->r_addend;
5160 goto final_link_relocate;
5163 #ifdef INCLUDE_SHMEDIA
5164 case R_SH_GOTPC_LOW16:
5165 case R_SH_GOTPC_MEDLOW16:
5166 case R_SH_GOTPC_MEDHI16:
5167 case R_SH_GOTPC_HI16:
5169 /* Use global offset table as symbol value. */
5171 BFD_ASSERT (sgot != NULL);
5172 relocation = sgot->output_section->vma;
5175 relocation += GOT_BIAS;
5178 addend = rel->r_addend;
5180 goto final_link_relocate;
5183 #ifdef INCLUDE_SHMEDIA
5184 case R_SH_PLT_LOW16:
5185 case R_SH_PLT_MEDLOW16:
5186 case R_SH_PLT_MEDHI16:
5189 /* Relocation is to the entry for this symbol in the
5190 procedure linkage table. */
5192 /* Resolve a PLT reloc against a local symbol directly,
5193 without using the procedure linkage table. */
5195 goto final_link_relocate;
5197 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
5198 goto final_link_relocate;
5200 if (h->plt.offset == (bfd_vma) -1)
5202 /* We didn't make a PLT entry for this symbol. This
5203 happens when statically linking PIC code, or when
5204 using -Bsymbolic. */
5205 goto final_link_relocate;
5208 BFD_ASSERT (splt != NULL);
5209 relocation = (splt->output_section->vma
5210 + splt->output_offset
5213 #ifdef INCLUDE_SHMEDIA
5217 addend = rel->r_addend;
5219 goto final_link_relocate;
5221 case R_SH_LOOP_START:
5223 static bfd_vma start, end;
5225 start = (relocation + rel->r_addend
5226 - (sec->output_section->vma + sec->output_offset));
5227 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5228 rel->r_offset, sec, start, end);
5232 end = (relocation + rel->r_addend
5233 - (sec->output_section->vma + sec->output_offset));
5234 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5235 rel->r_offset, sec, start, end);
5239 case R_SH_TLS_GD_32:
5240 case R_SH_TLS_IE_32:
5241 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5242 tls_type = GOT_UNKNOWN;
5243 if (h == NULL && local_got_offsets)
5244 tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
5247 tls_type = sh_elf_hash_entry (h)->tls_type;
5249 && (h->dynindx == -1
5250 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5251 && (tls_type == GOT_TLS_IE
5252 || sh_elf_hash_entry (h)->tls_tpoff32))
5253 r_type = R_SH_TLS_LE_32;
5256 if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
5257 r_type = R_SH_TLS_IE_32;
5259 if (r_type == R_SH_TLS_LE_32)
5262 unsigned short insn;
5264 Elf_Internal_Rela outrel;
5266 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5268 /* GD->LE transition:
5269 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5270 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5271 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5273 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5275 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5277 offset = rel->r_offset;
5278 BFD_ASSERT (offset >= 16);
5279 /* Size of GD instructions is 16 or 18. */
5281 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5282 if ((insn & 0xff00) == 0xc700)
5284 BFD_ASSERT (offset >= 2);
5286 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5289 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5290 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5291 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5292 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5293 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5294 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5295 BFD_ASSERT (insn == 0x310c);
5296 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5297 BFD_ASSERT (insn == 0x410b);
5298 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5299 BFD_ASSERT (insn == 0x34cc);
5301 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5302 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5303 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5304 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5305 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5311 /* IE->LE transition:
5312 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5313 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5315 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5318 offset = rel->r_offset;
5319 BFD_ASSERT (offset >= 16);
5320 /* Size of IE instructions is 10 or 12. */
5322 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5323 if ((insn & 0xf0ff) == 0x0012)
5325 BFD_ASSERT (offset >= 2);
5327 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5330 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5331 index = insn & 0x00ff;
5332 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5333 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5334 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5335 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5336 insn = 0xd000 | (insn & 0x0f00) | index;
5337 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5338 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5345 name = (bfd_elf_string_from_elf_section
5347 elf_elfheader (input_bfd)->e_shstrndx,
5348 elf_section_data (input_section)->rel_hdr.sh_name));
5352 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5353 && strcmp (bfd_get_section_name (input_bfd,
5357 sreloc = bfd_get_section_by_name (dynobj, name);
5358 BFD_ASSERT (sreloc != NULL);
5361 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5362 outrel.r_offset = (input_section->output_section->vma
5363 + input_section->output_offset
5365 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5367 outrel.r_addend = relocation - dtpoff_base (info);
5369 outrel.r_addend = 0;
5370 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
5371 (((Elf32_External_Rela *)
5373 + sreloc->reloc_count));
5374 ++sreloc->reloc_count;
5384 off = h->got.offset;
5387 if (local_got_offsets == NULL)
5390 off = local_got_offsets[r_symndx];
5397 Elf_Internal_Rela outrel;
5398 Elf32_External_Rela *loc;
5401 if (srelgot == NULL)
5403 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5404 BFD_ASSERT (srelgot != NULL);
5407 outrel.r_offset = (sgot->output_section->vma
5408 + sgot->output_offset + off);
5410 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5411 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5413 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5414 outrel.r_addend = relocation - dtpoff_base (info);
5416 outrel.r_addend = 0;
5417 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5418 loc = (Elf32_External_Rela *) srelgot->contents;
5419 loc += srelgot->reloc_count++;
5420 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5422 if (r_type == R_SH_TLS_GD_32)
5426 bfd_put_32 (output_bfd,
5427 relocation - dtpoff_base (info),
5428 sgot->contents + off + 4);
5432 outrel.r_info = ELF32_R_INFO (indx,
5434 outrel.r_offset += 4;
5435 outrel.r_addend = 0;
5436 srelgot->reloc_count++;
5438 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
5446 local_got_offsets[r_symndx] |= 1;
5449 if (off >= (bfd_vma) -2)
5452 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5453 relocation = sgot->output_offset + off;
5457 unsigned short insn;
5459 /* GD->IE transition:
5460 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5461 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5462 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5464 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5465 nop; nop; bra 3f; nop; .align 2;
5466 1: .long x@TPOFF; 2:...; 3:. */
5468 offset = rel->r_offset;
5469 BFD_ASSERT (offset >= 16);
5470 /* Size of GD instructions is 16 or 18. */
5472 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5473 if ((insn & 0xff00) == 0xc700)
5475 BFD_ASSERT (offset >= 2);
5477 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5480 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5482 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5483 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5485 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5486 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5487 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5488 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5489 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5490 BFD_ASSERT (insn == 0x310c);
5491 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5492 BFD_ASSERT (insn == 0x410b);
5493 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5494 BFD_ASSERT (insn == 0x34cc);
5496 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5497 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5498 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5499 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5500 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5502 bfd_put_32 (output_bfd, sgot->output_offset + off,
5503 contents + rel->r_offset);
5508 addend = rel->r_addend;
5510 goto final_link_relocate;
5512 case R_SH_TLS_LD_32:
5516 unsigned short insn;
5518 /* LD->LE transition:
5519 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5520 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5521 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5523 stc gbr,r0; nop; nop; nop;
5524 nop; nop; bra 3f; ...; 3:. */
5526 offset = rel->r_offset;
5527 BFD_ASSERT (offset >= 16);
5528 /* Size of LD instructions is 16 or 18. */
5530 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5531 if ((insn & 0xff00) == 0xc700)
5533 BFD_ASSERT (offset >= 2);
5535 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5538 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5539 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5540 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5541 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5542 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5543 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5544 BFD_ASSERT (insn == 0x310c);
5545 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5546 BFD_ASSERT (insn == 0x410b);
5547 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5548 BFD_ASSERT (insn == 0x34cc);
5550 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5551 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5552 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5553 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5554 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5555 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5564 off = htab->tls_ldm_got.offset;
5569 Elf_Internal_Rela outrel;
5570 Elf32_External_Rela *loc;
5572 srelgot = htab->srelgot;
5573 if (srelgot == NULL)
5576 outrel.r_offset = (sgot->output_section->vma
5577 + sgot->output_offset + off);
5578 outrel.r_addend = 0;
5579 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5580 loc = (Elf32_External_Rela *) srelgot->contents;
5581 loc += srelgot->reloc_count++;
5582 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5583 htab->tls_ldm_got.offset |= 1;
5586 relocation = sgot->output_offset + off;
5587 addend = rel->r_addend;
5589 goto final_link_relocate;
5591 case R_SH_TLS_LDO_32:
5595 Elf_Internal_Rela outrel;
5601 name = (bfd_elf_string_from_elf_section
5603 elf_elfheader (input_bfd)->e_shstrndx,
5604 elf_section_data (input_section)->rel_hdr.sh_name));
5608 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5609 && strcmp (bfd_get_section_name (input_bfd,
5613 sreloc = bfd_get_section_by_name (dynobj, name);
5614 BFD_ASSERT (sreloc != NULL);
5617 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5618 outrel.r_offset = (input_section->output_section->vma
5619 + input_section->output_offset
5621 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5623 outrel.r_addend = relocation - dtpoff_base (info);
5625 outrel.r_addend = 0;
5626 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
5627 (((Elf32_External_Rela *)
5629 + sreloc->reloc_count));
5630 ++sreloc->reloc_count;
5635 relocation -= dtpoff_base (info);
5637 addend = rel->r_addend;
5638 goto final_link_relocate;
5640 case R_SH_TLS_LE_32:
5643 Elf_Internal_Rela outrel;
5649 name = (bfd_elf_string_from_elf_section
5651 elf_elfheader (input_bfd)->e_shstrndx,
5652 elf_section_data (input_section)->rel_hdr.sh_name));
5656 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5657 && strcmp (bfd_get_section_name (input_bfd,
5661 sreloc = bfd_get_section_by_name (dynobj, name);
5662 BFD_ASSERT (sreloc != NULL);
5665 indx = (h && h->dynindx != -1) ? h->dynindx : 0;
5666 outrel.r_offset = (input_section->output_section->vma
5667 + input_section->output_offset
5669 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5671 outrel.r_addend = relocation - dtpoff_base (info);
5673 outrel.r_addend = 0;
5674 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
5675 (((Elf32_External_Rela *)
5677 + sreloc->reloc_count));
5678 ++sreloc->reloc_count;
5685 if (r != bfd_reloc_ok)
5690 case bfd_reloc_outofrange:
5692 case bfd_reloc_overflow:
5697 name = h->root.root.string;
5700 name = (bfd_elf_string_from_elf_section
5701 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5705 name = bfd_section_name (input_bfd, sec);
5707 if (! ((*info->callbacks->reloc_overflow)
5708 (info, name, howto->name, (bfd_vma) 0,
5709 input_bfd, input_section, rel->r_offset)))
5720 /* This is a version of bfd_generic_get_relocated_section_contents
5721 which uses sh_elf_relocate_section. */
5724 sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
5725 data, relocateable, symbols)
5727 struct bfd_link_info *link_info;
5728 struct bfd_link_order *link_order;
5730 boolean relocateable;
5733 Elf_Internal_Shdr *symtab_hdr;
5734 asection *input_section = link_order->u.indirect.section;
5735 bfd *input_bfd = input_section->owner;
5736 asection **sections = NULL;
5737 Elf_Internal_Rela *internal_relocs = NULL;
5738 Elf_Internal_Sym *isymbuf = NULL;
5740 /* We only need to handle the case of relaxing, or of having a
5741 particular set of section contents, specially. */
5743 || elf_section_data (input_section)->this_hdr.contents == NULL)
5744 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5749 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5751 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5752 (size_t) input_section->_raw_size);
5754 if ((input_section->flags & SEC_RELOC) != 0
5755 && input_section->reloc_count > 0)
5758 Elf_Internal_Sym *isym, *isymend;
5761 internal_relocs = (_bfd_elf32_link_read_relocs
5762 (input_bfd, input_section, (PTR) NULL,
5763 (Elf_Internal_Rela *) NULL, false));
5764 if (internal_relocs == NULL)
5767 if (symtab_hdr->sh_info != 0)
5769 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5770 if (isymbuf == NULL)
5771 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5772 symtab_hdr->sh_info, 0,
5774 if (isymbuf == NULL)
5778 amt = symtab_hdr->sh_info;
5779 amt *= sizeof (asection *);
5780 sections = (asection **) bfd_malloc (amt);
5781 if (sections == NULL && amt != 0)
5784 isymend = isymbuf + symtab_hdr->sh_info;
5785 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5789 if (isym->st_shndx == SHN_UNDEF)
5790 isec = bfd_und_section_ptr;
5791 else if (isym->st_shndx == SHN_ABS)
5792 isec = bfd_abs_section_ptr;
5793 else if (isym->st_shndx == SHN_COMMON)
5794 isec = bfd_com_section_ptr;
5796 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5801 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5802 input_section, data, internal_relocs,
5806 if (sections != NULL)
5809 && symtab_hdr->contents != (unsigned char *) isymbuf)
5811 if (elf_section_data (input_section)->relocs != internal_relocs)
5812 free (internal_relocs);
5818 if (sections != NULL)
5821 && symtab_hdr->contents != (unsigned char *) isymbuf)
5823 if (internal_relocs != NULL
5824 && elf_section_data (input_section)->relocs != internal_relocs)
5825 free (internal_relocs);
5829 /* Return the base VMA address which should be subtracted from real addresses
5830 when resolving @dtpoff relocation.
5831 This is PT_TLS segment p_vaddr. */
5835 struct bfd_link_info *info;
5837 /* If tls_segment is NULL, we should have signalled an error already. */
5838 if (elf_hash_table (info)->tls_segment == NULL)
5840 return elf_hash_table (info)->tls_segment->start;
5844 sh_elf_gc_mark_hook (sec, info, rel, h, sym)
5846 struct bfd_link_info *info ATTRIBUTE_UNUSED;
5847 Elf_Internal_Rela *rel;
5848 struct elf_link_hash_entry *h;
5849 Elf_Internal_Sym *sym;
5853 switch (ELF32_R_TYPE (rel->r_info))
5855 case R_SH_GNU_VTINHERIT:
5856 case R_SH_GNU_VTENTRY:
5860 #ifdef INCLUDE_SHMEDIA
5861 while (h->root.type == bfd_link_hash_indirect
5862 && h->root.u.i.link)
5863 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5865 switch (h->root.type)
5867 case bfd_link_hash_defined:
5868 case bfd_link_hash_defweak:
5869 return h->root.u.def.section;
5871 case bfd_link_hash_common:
5872 return h->root.u.c.p->section;
5880 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5885 /* Update the got entry reference counts for the section being removed. */
5888 sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
5890 struct bfd_link_info *info;
5892 const Elf_Internal_Rela *relocs;
5894 Elf_Internal_Shdr *symtab_hdr;
5895 struct elf_link_hash_entry **sym_hashes;
5896 bfd_signed_vma *local_got_refcounts;
5897 const Elf_Internal_Rela *rel, *relend;
5898 unsigned long r_symndx;
5899 struct elf_link_hash_entry *h;
5900 struct elf_sh_link_hash_entry *eh;
5902 elf_section_data (sec)->local_dynrel = NULL;
5904 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5905 sym_hashes = elf_sym_hashes (abfd);
5906 local_got_refcounts = elf_local_got_refcounts (abfd);
5908 relend = relocs + sec->reloc_count;
5909 for (rel = relocs; rel < relend; rel++)
5911 #ifdef INCLUDE_SHMEDIA
5912 int seen_stt_datalabel = 0;
5915 r_symndx = ELF32_R_SYM (rel->r_info);
5916 if (r_symndx < symtab_hdr->sh_info)
5920 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5921 #ifdef INCLUDE_SHMEDIA
5922 while (h->root.type == bfd_link_hash_indirect
5923 || h->root.type == bfd_link_hash_warning)
5925 seen_stt_datalabel |= h->type == STT_DATALABEL;
5926 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5930 eh = (struct elf_sh_link_hash_entry *) h;
5932 switch (sh_elf_optimized_tls_reloc (info, ELF32_R_TYPE (rel->r_info),
5933 ELF32_R_SYM (rel->r_info)
5934 >= symtab_hdr->sh_info))
5936 case R_SH_TLS_LD_32:
5937 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
5938 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
5944 #ifdef INCLUDE_SHMEDIA
5945 case R_SH_GOT_LOW16:
5946 case R_SH_GOT_MEDLOW16:
5947 case R_SH_GOT_MEDHI16:
5951 case R_SH_GOTOFF_LOW16:
5952 case R_SH_GOTOFF_MEDLOW16:
5953 case R_SH_GOTOFF_MEDHI16:
5954 case R_SH_GOTOFF_HI16:
5955 case R_SH_GOTPC_LOW16:
5956 case R_SH_GOTPC_MEDLOW16:
5957 case R_SH_GOTPC_MEDHI16:
5958 case R_SH_GOTPC_HI16:
5960 case R_SH_TLS_GD_32:
5961 case R_SH_TLS_IE_32:
5964 #ifdef INCLUDE_SHMEDIA
5965 if (seen_stt_datalabel)
5967 if (eh->datalabel_got.refcount > 0)
5968 eh->datalabel_got.refcount -= 1;
5972 if (h->got.refcount > 0)
5973 h->got.refcount -= 1;
5975 else if (local_got_refcounts != NULL)
5977 #ifdef INCLUDE_SHMEDIA
5978 if (rel->r_addend & 1)
5980 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
5981 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
5985 if (local_got_refcounts[r_symndx] > 0)
5986 local_got_refcounts[r_symndx] -= 1;
5994 struct elf_sh_dyn_relocs **pp;
5995 struct elf_sh_dyn_relocs *p;
5998 if (!info->shared && h->plt.refcount > 0)
5999 h->plt.refcount -= 1;
6001 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6004 if (ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
6015 #ifdef INCLUDE_SHMEDIA
6016 case R_SH_PLT_LOW16:
6017 case R_SH_PLT_MEDLOW16:
6018 case R_SH_PLT_MEDHI16:
6023 if (h->plt.refcount > 0)
6024 h->plt.refcount -= 1;
6029 #ifdef INCLUDE_SHMEDIA
6030 case R_SH_GOTPLT_LOW16:
6031 case R_SH_GOTPLT_MEDLOW16:
6032 case R_SH_GOTPLT_MEDHI16:
6033 case R_SH_GOTPLT_HI16:
6034 case R_SH_GOTPLT10BY4:
6035 case R_SH_GOTPLT10BY8:
6039 if (eh->gotplt_refcount > 0)
6041 eh->gotplt_refcount -= 1;
6042 if (h->plt.refcount > 0)
6043 h->plt.refcount -= 1;
6045 #ifdef INCLUDE_SHMEDIA
6046 else if (seen_stt_datalabel)
6048 if (eh->datalabel_got.refcount > 0)
6049 eh->datalabel_got.refcount -= 1;
6052 else if (h->got.refcount > 0)
6053 h->got.refcount -= 1;
6055 else if (local_got_refcounts != NULL)
6057 #ifdef INCLUDE_SHMEDIA
6058 if (rel->r_addend & 1)
6060 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6061 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6065 if (local_got_refcounts[r_symndx] > 0)
6066 local_got_refcounts[r_symndx] -= 1;
6078 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6081 sh_elf_copy_indirect_symbol (bed, dir, ind)
6082 struct elf_backend_data *bed;
6083 struct elf_link_hash_entry *dir, *ind;
6085 struct elf_sh_link_hash_entry *edir, *eind;
6086 #ifdef INCLUDE_SHMEDIA
6090 edir = (struct elf_sh_link_hash_entry *) dir;
6091 eind = (struct elf_sh_link_hash_entry *) ind;
6093 if (eind->dyn_relocs != NULL)
6095 if (edir->dyn_relocs != NULL)
6097 struct elf_sh_dyn_relocs **pp;
6098 struct elf_sh_dyn_relocs *p;
6100 BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
6102 /* Add reloc counts against the weak sym to the strong sym
6103 list. Merge any entries against the same section. */
6104 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
6106 struct elf_sh_dyn_relocs *q;
6108 for (q = edir->dyn_relocs; q != NULL; q = q->next)
6109 if (q->sec == p->sec)
6111 q->pc_count += p->pc_count;
6112 q->count += p->count;
6119 *pp = edir->dyn_relocs;
6122 edir->dyn_relocs = eind->dyn_relocs;
6123 eind->dyn_relocs = NULL;
6125 edir->gotplt_refcount = eind->gotplt_refcount;
6126 eind->gotplt_refcount = 0;
6127 #ifdef INCLUDE_SHMEDIA
6128 tmp = edir->datalabel_got.refcount;
6131 edir->datalabel_got.refcount = eind->datalabel_got.refcount;
6132 eind->datalabel_got.refcount = tmp;
6135 BFD_ASSERT (eind->datalabel_got.refcount < 1);
6138 if (ind->root.type == bfd_link_hash_indirect
6139 && dir->got.refcount <= 0)
6141 edir->tls_type = eind->tls_type;
6142 eind->tls_type = GOT_UNKNOWN;
6145 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
6149 sh_elf_optimized_tls_reloc (info, r_type, is_local)
6150 struct bfd_link_info *info;
6159 case R_SH_TLS_GD_32:
6160 case R_SH_TLS_IE_32:
6162 return R_SH_TLS_LE_32;
6163 return R_SH_TLS_IE_32;
6164 case R_SH_TLS_LD_32:
6165 return R_SH_TLS_LE_32;
6171 /* Look through the relocs for a section during the first phase.
6172 Since we don't do .gots or .plts, we just need to consider the
6173 virtual table relocs for gc. */
6176 sh_elf_check_relocs (abfd, info, sec, relocs)
6178 struct bfd_link_info *info;
6180 const Elf_Internal_Rela *relocs;
6182 Elf_Internal_Shdr *symtab_hdr;
6183 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6184 struct elf_sh_link_hash_table *htab;
6185 const Elf_Internal_Rela *rel;
6186 const Elf_Internal_Rela *rel_end;
6188 bfd_vma *local_got_offsets;
6192 unsigned int r_type;
6193 int tls_type, old_tls_type;
6199 if (info->relocateable)
6202 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6203 sym_hashes = elf_sym_hashes (abfd);
6204 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
6205 if (!elf_bad_symtab (abfd))
6206 sym_hashes_end -= symtab_hdr->sh_info;
6208 htab = sh_elf_hash_table (info);
6209 dynobj = htab->root.dynobj;
6210 local_got_offsets = elf_local_got_offsets (abfd);
6212 rel_end = relocs + sec->reloc_count;
6213 for (rel = relocs; rel < rel_end; rel++)
6215 struct elf_link_hash_entry *h;
6216 unsigned long r_symndx;
6217 #ifdef INCLUDE_SHMEDIA
6218 int seen_stt_datalabel = 0;
6221 r_symndx = ELF32_R_SYM (rel->r_info);
6222 r_type = ELF32_R_TYPE (rel->r_info);
6224 if (r_symndx < symtab_hdr->sh_info)
6228 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6229 #ifdef INCLUDE_SHMEDIA
6230 while (h->root.type == bfd_link_hash_indirect
6231 || h->root.type == bfd_link_hash_warning)
6233 seen_stt_datalabel |= h->type == STT_DATALABEL;
6234 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6239 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6241 && r_type == R_SH_TLS_IE_32
6243 && h->root.type != bfd_link_hash_undefined
6244 && h->root.type != bfd_link_hash_undefweak
6245 && (h->dynindx == -1
6246 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6247 r_type = R_SH_TLS_LE_32;
6249 /* Some relocs require a global offset table. */
6250 if (htab->sgot == NULL)
6258 #ifdef INCLUDE_SHMEDIA
6259 case R_SH_GOTPLT_LOW16:
6260 case R_SH_GOTPLT_MEDLOW16:
6261 case R_SH_GOTPLT_MEDHI16:
6262 case R_SH_GOTPLT_HI16:
6263 case R_SH_GOTPLT10BY4:
6264 case R_SH_GOTPLT10BY8:
6265 case R_SH_GOT_LOW16:
6266 case R_SH_GOT_MEDLOW16:
6267 case R_SH_GOT_MEDHI16:
6271 case R_SH_GOTOFF_LOW16:
6272 case R_SH_GOTOFF_MEDLOW16:
6273 case R_SH_GOTOFF_MEDHI16:
6274 case R_SH_GOTOFF_HI16:
6275 case R_SH_GOTPC_LOW16:
6276 case R_SH_GOTPC_MEDLOW16:
6277 case R_SH_GOTPC_MEDHI16:
6278 case R_SH_GOTPC_HI16:
6280 case R_SH_TLS_GD_32:
6281 case R_SH_TLS_LD_32:
6282 case R_SH_TLS_IE_32:
6284 htab->root.dynobj = dynobj = abfd;
6285 if (! create_got_section (dynobj, info))
6296 /* This relocation describes the C++ object vtable hierarchy.
6297 Reconstruct it for later use during GC. */
6298 case R_SH_GNU_VTINHERIT:
6299 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6303 /* This relocation describes which C++ vtable entries are actually
6304 used. Record for later use during GC. */
6305 case R_SH_GNU_VTENTRY:
6306 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6311 case R_SH_TLS_IE_32:
6313 info->flags |= DF_STATIC_TLS;
6316 case R_SH_TLS_GD_32:
6318 #ifdef INCLUDE_SHMEDIA
6319 case R_SH_GOT_LOW16:
6320 case R_SH_GOT_MEDLOW16:
6321 case R_SH_GOT_MEDHI16:
6329 tls_type = GOT_NORMAL;
6331 case R_SH_TLS_GD_32:
6332 tls_type = GOT_TLS_GD;
6334 case R_SH_TLS_IE_32:
6335 tls_type = GOT_TLS_IE;
6341 #ifdef INCLUDE_SHMEDIA
6342 if (seen_stt_datalabel)
6344 struct elf_sh_link_hash_entry *eh =
6345 (struct elf_sh_link_hash_entry *)h;
6347 eh->datalabel_got.refcount += 1;
6351 h->got.refcount += 1;
6352 old_tls_type = sh_elf_hash_entry (h)->tls_type;
6356 bfd_signed_vma *local_got_refcounts;
6358 /* This is a global offset table entry for a local
6360 local_got_refcounts = elf_local_got_refcounts (abfd);
6361 if (local_got_refcounts == NULL)
6365 size = symtab_hdr->sh_info;
6366 size *= sizeof (bfd_signed_vma);
6367 #ifdef INCLUDE_SHMEDIA
6368 /* Reserve space for both the datalabel and
6369 codelabel local GOT offsets. */
6372 size += symtab_hdr->sh_info;
6373 local_got_refcounts = ((bfd_signed_vma *)
6374 bfd_zalloc (abfd, size));
6375 if (local_got_refcounts == NULL)
6377 elf_local_got_refcounts (abfd) = local_got_refcounts;
6378 #ifdef INCLUDE_SHMEDIA
6379 /* Take care of both the datalabel and codelabel local
6381 sh_elf_local_got_tls_type (abfd)
6382 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6384 sh_elf_local_got_tls_type (abfd)
6385 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6388 #ifdef INCLUDE_SHMEDIA
6389 if (rel->r_addend & 1)
6390 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6393 local_got_refcounts[r_symndx] += 1;
6394 old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
6397 /* If a TLS symbol is accessed using IE at least once,
6398 there is no point to use dynamic model for it. */
6399 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
6400 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
6402 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
6403 tls_type = GOT_TLS_IE;
6406 (*_bfd_error_handler)
6407 (_("%s: `%s' accessed both as normal and thread local symbol"),
6408 bfd_archive_filename (abfd), h->root.root.string);
6413 if (old_tls_type != tls_type)
6416 sh_elf_hash_entry (h)->tls_type = tls_type;
6418 sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
6423 case R_SH_TLS_LD_32:
6424 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6428 #ifdef INCLUDE_SHMEDIA
6429 case R_SH_GOTPLT_LOW16:
6430 case R_SH_GOTPLT_MEDLOW16:
6431 case R_SH_GOTPLT_MEDHI16:
6432 case R_SH_GOTPLT_HI16:
6433 case R_SH_GOTPLT10BY4:
6434 case R_SH_GOTPLT10BY8:
6436 /* If this is a local symbol, we resolve it directly without
6437 creating a procedure linkage table entry. */
6440 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6443 || h->dynindx == -1)
6446 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6447 h->plt.refcount += 1;
6448 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6453 #ifdef INCLUDE_SHMEDIA
6454 case R_SH_PLT_LOW16:
6455 case R_SH_PLT_MEDLOW16:
6456 case R_SH_PLT_MEDHI16:
6459 /* This symbol requires a procedure linkage table entry. We
6460 actually build the entry in adjust_dynamic_symbol,
6461 because this might be a case of linking PIC code which is
6462 never referenced by a dynamic object, in which case we
6463 don't need to generate a procedure linkage table entry
6466 /* If this is a local symbol, we resolve it directly without
6467 creating a procedure linkage table entry. */
6471 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6474 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6475 h->plt.refcount += 1;
6480 if (h != NULL && ! info->shared)
6482 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
6483 h->plt.refcount += 1;
6486 /* If we are creating a shared library, and this is a reloc
6487 against a global symbol, or a non PC relative reloc
6488 against a local symbol, then we need to copy the reloc
6489 into the shared library. However, if we are linking with
6490 -Bsymbolic, we do not need to copy a reloc against a
6491 global symbol which is defined in an object we are
6492 including in the link (i.e., DEF_REGULAR is set). At
6493 this point we have not seen all the input files, so it is
6494 possible that DEF_REGULAR is not set now but will be set
6495 later (it is never cleared). We account for that
6496 possibility below by storing information in the
6497 dyn_relocs field of the hash table entry. A similar
6498 situation occurs when creating shared libraries and symbol
6499 visibility changes render the symbol local.
6501 If on the other hand, we are creating an executable, we
6502 may need to keep relocations for symbols satisfied by a
6503 dynamic library if we manage to avoid copy relocs for the
6506 && (sec->flags & SEC_ALLOC) != 0
6507 && (r_type != R_SH_REL32
6509 && (! info->symbolic
6510 || h->root.type == bfd_link_hash_defweak
6511 || (h->elf_link_hash_flags
6512 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
6514 && (sec->flags & SEC_ALLOC) != 0
6516 && (h->root.type == bfd_link_hash_defweak
6517 || (h->elf_link_hash_flags
6518 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
6520 struct elf_sh_dyn_relocs *p;
6521 struct elf_sh_dyn_relocs **head;
6524 htab->root.dynobj = dynobj = abfd;
6526 /* When creating a shared object, we must copy these
6527 reloc types into the output file. We create a reloc
6528 section in dynobj and make room for this reloc. */
6533 name = (bfd_elf_string_from_elf_section
6535 elf_elfheader (abfd)->e_shstrndx,
6536 elf_section_data (sec)->rel_hdr.sh_name));
6540 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6541 && strcmp (bfd_get_section_name (abfd, sec),
6544 sreloc = bfd_get_section_by_name (dynobj, name);
6549 sreloc = bfd_make_section (dynobj, name);
6550 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6551 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6552 if ((sec->flags & SEC_ALLOC) != 0)
6553 flags |= SEC_ALLOC | SEC_LOAD;
6555 || ! bfd_set_section_flags (dynobj, sreloc, flags)
6556 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
6559 if (sec->flags & SEC_READONLY)
6560 info->flags |= DF_TEXTREL;
6561 elf_section_data (sec)->sreloc = sreloc;
6564 /* If this is a global symbol, we count the number of
6565 relocations we need for this symbol. */
6567 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6572 /* Track dynamic relocs needed for local syms too. */
6573 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6578 head = ((struct elf_sh_dyn_relocs **)
6579 &elf_section_data (s)->local_dynrel);
6583 if (p == NULL || p->sec != sec)
6585 bfd_size_type amt = sizeof (*p);
6586 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
6597 if (r_type == R_SH_REL32)
6603 case R_SH_TLS_LE_32:
6606 (*_bfd_error_handler) (_("%s: TLS local exec code cannot be linked into shared objects"),
6607 bfd_archive_filename (abfd));
6611 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_LD_32)
6615 case R_SH_TLS_LDO_32:
6616 /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
6620 struct elf_sh_dyn_relocs *p;
6621 struct elf_sh_dyn_relocs **head;
6624 htab->root.dynobj = dynobj = abfd;
6630 name = (bfd_elf_string_from_elf_section
6632 elf_elfheader (abfd)->e_shstrndx,
6633 elf_section_data (sec)->rel_hdr.sh_name));
6637 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6638 && strcmp (bfd_get_section_name (abfd, sec),
6641 sreloc = bfd_get_section_by_name (dynobj, name);
6646 sreloc = bfd_make_section (dynobj, name);
6647 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6648 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6649 if ((sec->flags & SEC_ALLOC) != 0)
6650 flags |= SEC_ALLOC | SEC_LOAD;
6652 || ! bfd_set_section_flags (dynobj, sreloc, flags)
6653 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
6656 elf_section_data (sec)->sreloc = sreloc;
6657 if (sec->flags & SEC_READONLY)
6658 info->flags |= DF_TEXTREL;
6661 /* If this is a global symbol, we count the number of
6662 relocations we need for this symbol. */
6664 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6669 /* Track dynamic relocs needed for local syms too. */
6670 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6675 head = ((struct elf_sh_dyn_relocs **)
6676 &elf_section_data (s)->local_dynrel);
6680 if (p == NULL || p->sec != sec)
6682 bfd_size_type amt = sizeof (*p);
6683 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
6695 sh_elf_hash_entry (h)->tls_tpoff32 = true;
6707 #ifndef sh_elf_set_mach_from_flags
6709 sh_elf_set_mach_from_flags (abfd)
6712 flagword flags = elf_elfheader (abfd)->e_flags;
6714 switch (flags & EF_SH_MACH_MASK)
6717 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh);
6720 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
6723 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);
6726 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3);
6729 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp);
6732 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e);
6736 bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);
6743 #endif /* not sh_elf_set_mach_from_flags */
6745 #ifndef sh_elf_set_private_flags
6746 /* Function to keep SH specific file flags. */
6749 sh_elf_set_private_flags (abfd, flags)
6753 BFD_ASSERT (! elf_flags_init (abfd)
6754 || elf_elfheader (abfd)->e_flags == flags);
6756 elf_elfheader (abfd)->e_flags = flags;
6757 elf_flags_init (abfd) = true;
6758 return sh_elf_set_mach_from_flags (abfd);
6760 #endif /* not sh_elf_set_private_flags */
6762 #ifndef sh_elf_copy_private_data
6763 /* Copy backend specific data from one object module to another */
6766 sh_elf_copy_private_data (ibfd, obfd)
6770 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6771 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6774 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
6776 #endif /* not sh_elf_copy_private_data */
6778 #ifndef sh_elf_merge_private_data
6779 /* This routine checks for linking big and little endian objects
6780 together, and for linking sh-dsp with sh3e / sh4 objects. */
6783 sh_elf_merge_private_data (ibfd, obfd)
6787 flagword old_flags, new_flags;
6789 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
6792 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6793 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6796 if (! elf_flags_init (obfd))
6798 /* This happens when ld starts out with a 'blank' output file. */
6799 elf_flags_init (obfd) = true;
6800 elf_elfheader (obfd)->e_flags = EF_SH1;
6802 old_flags = elf_elfheader (obfd)->e_flags;
6803 new_flags = elf_elfheader (ibfd)->e_flags;
6804 if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags))
6805 || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags)))
6807 (*_bfd_error_handler)
6808 ("%s: uses %s instructions while previous modules use %s instructions",
6809 bfd_archive_filename (ibfd),
6810 EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point",
6811 EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp");
6812 bfd_set_error (bfd_error_bad_value);
6815 elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags);
6817 return sh_elf_set_mach_from_flags (obfd);
6819 #endif /* not sh_elf_merge_private_data */
6821 /* Override the generic function because we need to store sh_elf_obj_tdata
6822 as the specific tdata. We set also the machine architecture from flags
6826 sh_elf_object_p (abfd)
6829 struct sh_elf_obj_tdata *new_tdata;
6830 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
6832 if (sh_elf_set_mach_from_flags (abfd) == false)
6835 /* Allocate our special target data. */
6836 new_tdata = bfd_zalloc (abfd, amt);
6837 if (new_tdata == NULL)
6839 new_tdata->root = *abfd->tdata.elf_obj_data;
6840 abfd->tdata.any = new_tdata;
6844 /* Finish up dynamic symbol handling. We set the contents of various
6845 dynamic sections here. */
6848 sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
6850 struct bfd_link_info *info;
6851 struct elf_link_hash_entry *h;
6852 Elf_Internal_Sym *sym;
6854 struct elf_sh_link_hash_table *htab;
6857 htab = sh_elf_hash_table (info);
6858 dynobj = htab->root.dynobj;
6860 if (h->plt.offset != (bfd_vma) -1)
6868 Elf_Internal_Rela rel;
6870 /* This symbol has an entry in the procedure linkage table. Set
6873 BFD_ASSERT (h->dynindx != -1);
6876 sgot = htab->sgotplt;
6877 srel = htab->srelplt;
6878 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
6880 /* Get the index in the procedure linkage table which
6881 corresponds to this symbol. This is the index of this symbol
6882 in all the symbols for which we are making plt entries. The
6883 first entry in the procedure linkage table is reserved. */
6884 plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1;
6886 /* Get the offset into the .got table of the entry that
6887 corresponds to this function. Each .got entry is 4 bytes.
6888 The first three are reserved. */
6889 got_offset = (plt_index + 3) * 4;
6893 got_offset -= GOT_BIAS;
6896 /* Fill in the entry in the procedure linkage table. */
6899 if (elf_sh_plt_entry == NULL)
6901 elf_sh_plt_entry = (bfd_big_endian (output_bfd) ?
6902 elf_sh_plt_entry_be : elf_sh_plt_entry_le);
6904 memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
6905 elf_sh_sizeof_plt (info));
6906 #ifdef INCLUDE_SHMEDIA
6907 movi_shori_putval (output_bfd,
6908 (sgot->output_section->vma
6909 + sgot->output_offset
6911 (splt->contents + h->plt.offset
6912 + elf_sh_plt_symbol_offset (info)));
6914 /* Set bottom bit because its for a branch to SHmedia */
6915 movi_shori_putval (output_bfd,
6916 (splt->output_section->vma + splt->output_offset)
6918 (splt->contents + h->plt.offset
6919 + elf_sh_plt_plt0_offset (info)));
6921 bfd_put_32 (output_bfd,
6922 (sgot->output_section->vma
6923 + sgot->output_offset
6925 (splt->contents + h->plt.offset
6926 + elf_sh_plt_symbol_offset (info)));
6928 bfd_put_32 (output_bfd,
6929 (splt->output_section->vma + splt->output_offset),
6930 (splt->contents + h->plt.offset
6931 + elf_sh_plt_plt0_offset (info)));
6936 if (elf_sh_pic_plt_entry == NULL)
6938 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
6939 elf_sh_pic_plt_entry_be :
6940 elf_sh_pic_plt_entry_le);
6942 memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
6943 elf_sh_sizeof_plt (info));
6944 #ifdef INCLUDE_SHMEDIA
6945 movi_shori_putval (output_bfd, got_offset,
6946 (splt->contents + h->plt.offset
6947 + elf_sh_plt_symbol_offset (info)));
6949 bfd_put_32 (output_bfd, got_offset,
6950 (splt->contents + h->plt.offset
6951 + elf_sh_plt_symbol_offset (info)));
6957 got_offset += GOT_BIAS;
6960 #ifdef INCLUDE_SHMEDIA
6961 movi_shori_putval (output_bfd,
6962 plt_index * sizeof (Elf32_External_Rela),
6963 (splt->contents + h->plt.offset
6964 + elf_sh_plt_reloc_offset (info)));
6966 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
6967 (splt->contents + h->plt.offset
6968 + elf_sh_plt_reloc_offset (info)));
6971 /* Fill in the entry in the global offset table. */
6972 bfd_put_32 (output_bfd,
6973 (splt->output_section->vma
6974 + splt->output_offset
6976 + elf_sh_plt_temp_offset (info)),
6977 sgot->contents + got_offset);
6979 /* Fill in the entry in the .rela.plt section. */
6980 rel.r_offset = (sgot->output_section->vma
6981 + sgot->output_offset
6983 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
6986 rel.r_addend = GOT_BIAS;
6988 bfd_elf32_swap_reloca_out (output_bfd, &rel,
6989 ((Elf32_External_Rela *) srel->contents
6992 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
6994 /* Mark the symbol as undefined, rather than as defined in
6995 the .plt section. Leave the value alone. */
6996 sym->st_shndx = SHN_UNDEF;
7000 if (h->got.offset != (bfd_vma) -1
7001 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
7002 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
7006 Elf_Internal_Rela rel;
7008 /* This symbol has an entry in the global offset table. Set it
7012 srel = htab->srelgot;
7013 BFD_ASSERT (sgot != NULL && srel != NULL);
7015 rel.r_offset = (sgot->output_section->vma
7016 + sgot->output_offset
7017 + (h->got.offset &~ (bfd_vma) 1));
7019 /* If this is a static link, or it is a -Bsymbolic link and the
7020 symbol is defined locally or was forced to be local because
7021 of a version file, we just want to emit a RELATIVE reloc.
7022 The entry in the global offset table will already have been
7023 initialized in the relocate_section function. */
7027 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
7028 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
7030 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7031 rel.r_addend = (h->root.u.def.value
7032 + h->root.u.def.section->output_section->vma
7033 + h->root.u.def.section->output_offset);
7037 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
7038 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7042 bfd_elf32_swap_reloca_out (output_bfd, &rel,
7043 ((Elf32_External_Rela *) srel->contents
7044 + srel->reloc_count));
7045 ++srel->reloc_count;
7048 #ifdef INCLUDE_SHMEDIA
7050 struct elf_sh_link_hash_entry *eh;
7052 eh = (struct elf_sh_link_hash_entry *) h;
7053 if (eh->datalabel_got.offset != (bfd_vma) -1)
7057 Elf_Internal_Rela rel;
7059 /* This symbol has a datalabel entry in the global offset table.
7063 srel = htab->srelgot;
7064 BFD_ASSERT (sgot != NULL && srel != NULL);
7066 rel.r_offset = (sgot->output_section->vma
7067 + sgot->output_offset
7068 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
7070 /* If this is a static link, or it is a -Bsymbolic link and the
7071 symbol is defined locally or was forced to be local because
7072 of a version file, we just want to emit a RELATIVE reloc.
7073 The entry in the global offset table will already have been
7074 initialized in the relocate_section function. */
7078 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
7079 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
7081 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7082 rel.r_addend = (h->root.u.def.value
7083 + h->root.u.def.section->output_section->vma
7084 + h->root.u.def.section->output_offset);
7088 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
7089 + eh->datalabel_got.offset);
7090 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7094 bfd_elf32_swap_reloca_out (output_bfd, &rel,
7095 ((Elf32_External_Rela *) srel->contents
7096 + srel->reloc_count));
7097 ++srel->reloc_count;
7102 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
7105 Elf_Internal_Rela rel;
7107 /* This symbol needs a copy reloc. Set it up. */
7109 BFD_ASSERT (h->dynindx != -1
7110 && (h->root.type == bfd_link_hash_defined
7111 || h->root.type == bfd_link_hash_defweak));
7113 s = bfd_get_section_by_name (h->root.u.def.section->owner,
7115 BFD_ASSERT (s != NULL);
7117 rel.r_offset = (h->root.u.def.value
7118 + h->root.u.def.section->output_section->vma
7119 + h->root.u.def.section->output_offset);
7120 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
7122 bfd_elf32_swap_reloca_out (output_bfd, &rel,
7123 ((Elf32_External_Rela *) s->contents
7128 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7129 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
7130 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7131 sym->st_shndx = SHN_ABS;
7136 /* Finish up the dynamic sections. */
7139 sh_elf_finish_dynamic_sections (output_bfd, info)
7141 struct bfd_link_info *info;
7143 struct elf_sh_link_hash_table *htab;
7148 htab = sh_elf_hash_table (info);
7149 dynobj = htab->root.dynobj;
7151 sgot = htab->sgotplt;
7152 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
7154 if (htab->root.dynamic_sections_created)
7157 Elf32_External_Dyn *dyncon, *dynconend;
7159 BFD_ASSERT (sgot != NULL && sdyn != NULL);
7161 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7162 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
7163 for (; dyncon < dynconend; dyncon++)
7165 Elf_Internal_Dyn dyn;
7167 #ifdef INCLUDE_SHMEDIA
7171 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
7178 #ifdef INCLUDE_SHMEDIA
7180 name = info->init_function;
7184 name = info->fini_function;
7186 if (dyn.d_un.d_val != 0)
7188 struct elf_link_hash_entry *h;
7190 h = elf_link_hash_lookup (&htab->root, name,
7191 false, false, true);
7192 if (h != NULL && (h->other & STO_SH5_ISA32))
7194 dyn.d_un.d_val |= 1;
7195 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7202 s = htab->sgot->output_section;
7206 s = htab->srelplt->output_section;
7208 BFD_ASSERT (s != NULL);
7209 dyn.d_un.d_ptr = s->vma;
7210 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7214 s = htab->srelplt->output_section;
7215 BFD_ASSERT (s != NULL);
7216 if (s->_cooked_size != 0)
7217 dyn.d_un.d_val = s->_cooked_size;
7219 dyn.d_un.d_val = s->_raw_size;
7220 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7224 /* My reading of the SVR4 ABI indicates that the
7225 procedure linkage table relocs (DT_JMPREL) should be
7226 included in the overall relocs (DT_RELA). This is
7227 what Solaris does. However, UnixWare can not handle
7228 that case. Therefore, we override the DT_RELASZ entry
7229 here to make it not include the JMPREL relocs. Since
7230 the linker script arranges for .rela.plt to follow all
7231 other relocation sections, we don't have to worry
7232 about changing the DT_RELA entry. */
7233 if (htab->srelplt != NULL)
7235 s = htab->srelplt->output_section;
7236 if (s->_cooked_size != 0)
7237 dyn.d_un.d_val -= s->_cooked_size;
7239 dyn.d_un.d_val -= s->_raw_size;
7241 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7246 /* Fill in the first entry in the procedure linkage table. */
7248 if (splt && splt->_raw_size > 0)
7252 if (elf_sh_pic_plt_entry == NULL)
7254 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
7255 elf_sh_pic_plt_entry_be :
7256 elf_sh_pic_plt_entry_le);
7258 memcpy (splt->contents, elf_sh_pic_plt_entry,
7259 elf_sh_sizeof_plt (info));
7263 if (elf_sh_plt0_entry == NULL)
7265 elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ?
7266 elf_sh_plt0_entry_be :
7267 elf_sh_plt0_entry_le);
7269 memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
7270 #ifdef INCLUDE_SHMEDIA
7271 movi_shori_putval (output_bfd,
7272 sgot->output_section->vma
7273 + sgot->output_offset,
7275 + elf_sh_plt0_gotplt_offset (info));
7277 bfd_put_32 (output_bfd,
7278 sgot->output_section->vma + sgot->output_offset + 4,
7279 splt->contents + elf_sh_plt0_gotid_offset (info));
7280 bfd_put_32 (output_bfd,
7281 sgot->output_section->vma + sgot->output_offset + 8,
7282 splt->contents + elf_sh_plt0_linker_offset (info));
7286 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7287 really seem like the right value. */
7288 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7292 /* Fill in the first three entries in the global offset table. */
7293 if (sgot && sgot->_raw_size > 0)
7296 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7298 bfd_put_32 (output_bfd,
7299 sdyn->output_section->vma + sdyn->output_offset,
7301 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7302 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7304 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7310 static enum elf_reloc_type_class
7311 sh_elf_reloc_type_class (rela)
7312 const Elf_Internal_Rela *rela;
7314 switch ((int) ELF32_R_TYPE (rela->r_info))
7317 return reloc_class_relative;
7319 return reloc_class_plt;
7321 return reloc_class_copy;
7323 return reloc_class_normal;
7328 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7329 #define TARGET_BIG_NAME "elf32-sh"
7330 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7331 #define TARGET_LITTLE_NAME "elf32-shl"
7332 #define ELF_ARCH bfd_arch_sh
7333 #define ELF_MACHINE_CODE EM_SH
7334 #define ELF_MAXPAGESIZE 128
7336 #define elf_symbol_leading_char '_'
7337 #endif /* ELF_ARCH */
7339 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7340 #define elf_info_to_howto sh_elf_info_to_howto
7341 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7342 #define elf_backend_relocate_section sh_elf_relocate_section
7343 #define bfd_elf32_bfd_get_relocated_section_contents \
7344 sh_elf_get_relocated_section_contents
7345 #define bfd_elf32_mkobject sh_elf_mkobject
7346 #define elf_backend_object_p sh_elf_object_p
7347 #define bfd_elf32_bfd_set_private_bfd_flags \
7348 sh_elf_set_private_flags
7349 #define bfd_elf32_bfd_copy_private_bfd_data \
7350 sh_elf_copy_private_data
7351 #define bfd_elf32_bfd_merge_private_bfd_data \
7352 sh_elf_merge_private_data
7354 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7355 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7356 #define elf_backend_check_relocs sh_elf_check_relocs
7357 #define elf_backend_copy_indirect_symbol \
7358 sh_elf_copy_indirect_symbol
7359 #define elf_backend_create_dynamic_sections \
7360 sh_elf_create_dynamic_sections
7361 #define bfd_elf32_bfd_link_hash_table_create \
7362 sh_elf_link_hash_table_create
7363 #define elf_backend_adjust_dynamic_symbol \
7364 sh_elf_adjust_dynamic_symbol
7365 #define elf_backend_size_dynamic_sections \
7366 sh_elf_size_dynamic_sections
7367 #define elf_backend_finish_dynamic_symbol \
7368 sh_elf_finish_dynamic_symbol
7369 #define elf_backend_finish_dynamic_sections \
7370 sh_elf_finish_dynamic_sections
7371 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7373 #define elf_backend_can_gc_sections 1
7374 #define elf_backend_can_refcount 1
7375 #define elf_backend_want_got_plt 1
7376 #define elf_backend_plt_readonly 1
7377 #define elf_backend_want_plt_sym 0
7378 #define elf_backend_got_header_size 12
7379 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
7381 #ifndef ELF32_SH_C_INCLUDED
7382 #include "elf32-target.h"