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
3508 bfd_vma datalabel_got_offset
;
3511 /* Track dynamic relocs copied for this symbol. */
3512 struct elf_sh_dyn_relocs
*dyn_relocs
;
3514 bfd_signed_vma gotplt_refcount
;
3517 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3520 /* If true, R_SH_TLS_TPOFF32 relocation is generated. */
3521 boolean tls_tpoff32
;
3524 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3526 struct sh_elf_obj_tdata
3528 struct elf_obj_tdata root
;
3530 /* tls_type for each local got entry. */
3531 char *local_got_tls_type
;
3534 #define sh_elf_tdata(abfd) \
3535 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3537 #define sh_elf_local_got_tls_type(abfd) \
3538 (sh_elf_tdata (abfd)->local_got_tls_type)
3540 /* Override the generic function because we need to store sh_elf_obj_tdata
3541 as the specific tdata. */
3544 sh_elf_mkobject (abfd
)
3547 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3548 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3549 if (abfd
->tdata
.any
== NULL
)
3554 /* sh ELF linker hash table. */
3556 struct elf_sh_link_hash_table
3558 struct elf_link_hash_table root
;
3560 /* Short-cuts to get to dynamic linker sections. */
3569 /* Small local sym to section mapping cache. */
3570 struct sym_sec_cache sym_sec
;
3572 /* A counter or offset to track a TLS got entry. */
3575 bfd_signed_vma refcount
;
3580 /* Traverse an sh ELF linker hash table. */
3582 #define sh_elf_link_hash_traverse(table, func, info) \
3583 (elf_link_hash_traverse \
3585 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3588 /* Get the sh ELF linker hash table from a link_info structure. */
3590 #define sh_elf_hash_table(p) \
3591 ((struct elf_sh_link_hash_table *) ((p)->hash))
3593 /* Create an entry in an sh ELF linker hash table. */
3595 static struct bfd_hash_entry
*
3596 sh_elf_link_hash_newfunc (entry
, table
, string
)
3597 struct bfd_hash_entry
*entry
;
3598 struct bfd_hash_table
*table
;
3601 struct elf_sh_link_hash_entry
*ret
=
3602 (struct elf_sh_link_hash_entry
*) entry
;
3604 /* Allocate the structure if it has not already been allocated by a
3606 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3607 ret
= ((struct elf_sh_link_hash_entry
*)
3608 bfd_hash_allocate (table
,
3609 sizeof (struct elf_sh_link_hash_entry
)));
3610 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3611 return (struct bfd_hash_entry
*) ret
;
3613 /* Call the allocation method of the superclass. */
3614 ret
= ((struct elf_sh_link_hash_entry
*)
3615 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3617 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3619 struct elf_sh_link_hash_entry
*eh
;
3621 eh
= (struct elf_sh_link_hash_entry
*) ret
;
3622 eh
->dyn_relocs
= NULL
;
3623 eh
->gotplt_refcount
= 0;
3624 #ifdef INCLUDE_SHMEDIA
3625 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3627 ret
->tls_type
= GOT_UNKNOWN
;
3628 ret
->tls_tpoff32
= false;
3631 return (struct bfd_hash_entry
*) ret
;
3634 /* Create an sh ELF linker hash table. */
3636 static struct bfd_link_hash_table
*
3637 sh_elf_link_hash_table_create (abfd
)
3640 struct elf_sh_link_hash_table
*ret
;
3641 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3643 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3644 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3647 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3648 sh_elf_link_hash_newfunc
))
3655 ret
->sgotplt
= NULL
;
3656 ret
->srelgot
= NULL
;
3658 ret
->srelplt
= NULL
;
3659 ret
->sdynbss
= NULL
;
3660 ret
->srelbss
= NULL
;
3661 ret
->sym_sec
.abfd
= NULL
;
3662 ret
->tls_ldm_got
.refcount
= 0;
3664 return &ret
->root
.root
;
3667 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3668 shortcuts to them in our hash table. */
3671 create_got_section (dynobj
, info
)
3673 struct bfd_link_info
*info
;
3675 struct elf_sh_link_hash_table
*htab
;
3677 if (! _bfd_elf_create_got_section (dynobj
, info
))
3680 htab
= sh_elf_hash_table (info
);
3681 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3682 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3683 if (! htab
->sgot
|| ! htab
->sgotplt
)
3686 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3687 if (htab
->srelgot
== NULL
3688 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3693 | SEC_LINKER_CREATED
3695 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3700 /* Create dynamic sections when linking against a dynamic object. */
3703 sh_elf_create_dynamic_sections (abfd
, info
)
3705 struct bfd_link_info
*info
;
3707 struct elf_sh_link_hash_table
*htab
;
3708 flagword flags
, pltflags
;
3709 register asection
*s
;
3710 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3713 switch (bed
->s
->arch_size
)
3724 bfd_set_error (bfd_error_bad_value
);
3728 htab
= sh_elf_hash_table (info
);
3730 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3731 .rel[a].bss sections. */
3733 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3734 | SEC_LINKER_CREATED
);
3737 pltflags
|= SEC_CODE
;
3738 if (bed
->plt_not_loaded
)
3739 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3740 if (bed
->plt_readonly
)
3741 pltflags
|= SEC_READONLY
;
3743 s
= bfd_make_section (abfd
, ".plt");
3746 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3747 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3750 if (bed
->want_plt_sym
)
3752 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3754 struct elf_link_hash_entry
*h
;
3755 struct bfd_link_hash_entry
*bh
= NULL
;
3757 if (! (_bfd_generic_link_add_one_symbol
3758 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3759 (bfd_vma
) 0, (const char *) NULL
, false,
3760 get_elf_backend_data (abfd
)->collect
, &bh
)))
3763 h
= (struct elf_link_hash_entry
*) bh
;
3764 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3765 h
->type
= STT_OBJECT
;
3768 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3772 s
= bfd_make_section (abfd
,
3773 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3776 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3777 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3780 if (! create_got_section (abfd
, info
))
3784 const char *secname
;
3789 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3791 secflags
= bfd_get_section_flags (abfd
, sec
);
3792 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3793 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3795 secname
= bfd_get_section_name (abfd
, sec
);
3796 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3797 strcpy (relname
, ".rela");
3798 strcat (relname
, secname
);
3799 s
= bfd_make_section (abfd
, relname
);
3801 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3802 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3807 if (bed
->want_dynbss
)
3809 /* The .dynbss section is a place to put symbols which are defined
3810 by dynamic objects, are referenced by regular objects, and are
3811 not functions. We must allocate space for them in the process
3812 image and use a R_*_COPY reloc to tell the dynamic linker to
3813 initialize them at run time. The linker script puts the .dynbss
3814 section into the .bss section of the final image. */
3815 s
= bfd_make_section (abfd
, ".dynbss");
3818 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3821 /* The .rel[a].bss section holds copy relocs. This section is not
3822 normally needed. We need to create it here, though, so that the
3823 linker will map it to an output section. We can't just create it
3824 only if we need it, because we will not know whether we need it
3825 until we have seen all the input files, and the first time the
3826 main linker code calls BFD after examining all the input files
3827 (size_dynamic_sections) the input sections have already been
3828 mapped to the output sections. If the section turns out not to
3829 be needed, we can discard it later. We will never need this
3830 section when generating a shared object, since they do not use
3834 s
= bfd_make_section (abfd
,
3835 (bed
->default_use_rela_p
3836 ? ".rela.bss" : ".rel.bss"));
3839 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3840 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3848 /* Adjust a symbol defined by a dynamic object and referenced by a
3849 regular object. The current definition is in some section of the
3850 dynamic object, but we're not including those sections. We have to
3851 change the definition to something the rest of the link can
3855 sh_elf_adjust_dynamic_symbol (info
, h
)
3856 struct bfd_link_info
*info
;
3857 struct elf_link_hash_entry
*h
;
3859 struct elf_sh_link_hash_table
*htab
;
3860 struct elf_sh_link_hash_entry
*eh
;
3861 struct elf_sh_dyn_relocs
*p
;
3864 unsigned int power_of_two
;
3866 dynobj
= elf_hash_table (info
)->dynobj
;
3868 /* Make sure we know what is going on here. */
3869 BFD_ASSERT (dynobj
!= NULL
3870 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3871 || h
->weakdef
!= NULL
3872 || ((h
->elf_link_hash_flags
3873 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3874 && (h
->elf_link_hash_flags
3875 & ELF_LINK_HASH_REF_REGULAR
) != 0
3876 && (h
->elf_link_hash_flags
3877 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3879 /* If this is a function, put it in the procedure linkage table. We
3880 will fill in the contents of the procedure linkage table later,
3881 when we know the address of the .got section. */
3882 if (h
->type
== STT_FUNC
3883 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3885 if (h
->plt
.refcount
<= 0
3887 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3888 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
3889 && h
->root
.type
!= bfd_link_hash_undefweak
3890 && h
->root
.type
!= bfd_link_hash_undefined
))
3892 /* This case can occur if we saw a PLT reloc in an input
3893 file, but the symbol was never referred to by a dynamic
3894 object. In such a case, we don't actually need to build
3895 a procedure linkage table, and we can just do a REL32
3897 h
->plt
.offset
= (bfd_vma
) -1;
3898 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3904 h
->plt
.offset
= (bfd_vma
) -1;
3906 /* If this is a weak symbol, and there is a real definition, the
3907 processor independent code will have arranged for us to see the
3908 real definition first, and we can just use the same value. */
3909 if (h
->weakdef
!= NULL
)
3911 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3912 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3913 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3914 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3918 /* This is a reference to a symbol defined by a dynamic object which
3919 is not a function. */
3921 /* If we are creating a shared library, we must presume that the
3922 only references to the symbol are via the global offset table.
3923 For such cases we need not do anything here; the relocations will
3924 be handled correctly by relocate_section. */
3928 /* If there are no references to this symbol that do not use the
3929 GOT, we don't need to generate a copy reloc. */
3930 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3933 /* If -z nocopyreloc was given, we won't generate them either. */
3934 if (info
->nocopyreloc
)
3936 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3940 eh
= (struct elf_sh_link_hash_entry
*) h
;
3941 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3943 s
= p
->sec
->output_section
;
3944 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3948 /* If we didn't find any dynamic relocs in sections which needs the
3949 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3953 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3957 /* We must allocate the symbol in our .dynbss section, which will
3958 become part of the .bss section of the executable. There will be
3959 an entry for this symbol in the .dynsym section. The dynamic
3960 object will contain position independent code, so all references
3961 from the dynamic object to this symbol will go through the global
3962 offset table. The dynamic linker will use the .dynsym entry to
3963 determine the address it must put in the global offset table, so
3964 both the dynamic object and the regular object will refer to the
3965 same memory location for the variable. */
3967 htab
= sh_elf_hash_table (info
);
3969 BFD_ASSERT (s
!= NULL
);
3971 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3972 copy the initial value out of the dynamic object and into the
3973 runtime process image. We need to remember the offset into the
3974 .rela.bss section we are going to use. */
3975 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3979 srel
= htab
->srelbss
;
3980 BFD_ASSERT (srel
!= NULL
);
3981 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3982 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3985 /* We need to figure out the alignment required for this symbol. I
3986 have no idea how ELF linkers handle this. */
3987 power_of_two
= bfd_log2 (h
->size
);
3988 if (power_of_two
> 3)
3991 /* Apply the required alignment. */
3992 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3993 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3995 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3999 /* Define the symbol as being at this point in the section. */
4000 h
->root
.u
.def
.section
= s
;
4001 h
->root
.u
.def
.value
= s
->_raw_size
;
4003 /* Increment the section size to make room for the symbol. */
4004 s
->_raw_size
+= h
->size
;
4009 /* This is the condition under which sh_elf_finish_dynamic_symbol
4010 will be called from elflink.h. If elflink.h doesn't call our
4011 finish_dynamic_symbol routine, we'll need to do something about
4012 initializing any .plt and .got entries in sh_elf_relocate_section. */
4013 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
4015 && ((INFO)->shared \
4016 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4017 && ((H)->dynindx != -1 \
4018 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4020 /* Allocate space in .plt, .got and associated reloc sections for
4024 allocate_dynrelocs (h
, inf
)
4025 struct elf_link_hash_entry
*h
;
4028 struct bfd_link_info
*info
;
4029 struct elf_sh_link_hash_table
*htab
;
4030 struct elf_sh_link_hash_entry
*eh
;
4031 struct elf_sh_dyn_relocs
*p
;
4033 if (h
->root
.type
== bfd_link_hash_indirect
)
4036 if (h
->root
.type
== bfd_link_hash_warning
)
4037 /* When warning symbols are created, they **replace** the "real"
4038 entry in the hash table, thus we never get to see the real
4039 symbol in a hash traversal. So look at it now. */
4040 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4042 info
= (struct bfd_link_info
*) inf
;
4043 htab
= sh_elf_hash_table (info
);
4045 eh
= (struct elf_sh_link_hash_entry
*) h
;
4046 if ((h
->got
.refcount
> 0
4047 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4048 && eh
->gotplt_refcount
> 0)
4050 /* The symbol has been forced local, or we have some direct got refs,
4051 so treat all the gotplt refs as got refs. */
4052 h
->got
.refcount
+= eh
->gotplt_refcount
;
4053 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4054 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4057 if (htab
->root
.dynamic_sections_created
4058 && h
->plt
.refcount
> 0)
4060 /* Make sure this symbol is output as a dynamic symbol.
4061 Undefined weak syms won't yet be marked as dynamic. */
4062 if (h
->dynindx
== -1
4063 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4065 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4069 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
4071 asection
*s
= htab
->splt
;
4073 /* If this is the first .plt entry, make room for the special
4075 if (s
->_raw_size
== 0)
4076 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4078 h
->plt
.offset
= s
->_raw_size
;
4080 /* If this symbol is not defined in a regular file, and we are
4081 not generating a shared library, then set the symbol to this
4082 location in the .plt. This is required to make function
4083 pointers compare as equal between the normal executable and
4084 the shared library. */
4086 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4088 h
->root
.u
.def
.section
= s
;
4089 h
->root
.u
.def
.value
= h
->plt
.offset
;
4092 /* Make room for this entry. */
4093 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4095 /* We also need to make an entry in the .got.plt section, which
4096 will be placed in the .got section by the linker script. */
4097 htab
->sgotplt
->_raw_size
+= 4;
4099 /* We also need to make an entry in the .rel.plt section. */
4100 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
4104 h
->plt
.offset
= (bfd_vma
) -1;
4105 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4110 h
->plt
.offset
= (bfd_vma
) -1;
4111 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4114 if (h
->got
.refcount
> 0)
4118 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4120 /* Make sure this symbol is output as a dynamic symbol.
4121 Undefined weak syms won't yet be marked as dynamic. */
4122 if (h
->dynindx
== -1
4123 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4125 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4130 #ifdef INCLUDE_SHMEDIA
4131 if (h
->type
== STT_DATALABEL
)
4133 struct elf_sh_link_hash_entry
*hsh
;
4135 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4136 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4137 hsh
->datalabel_got_offset
= s
->_raw_size
;
4140 h
->got
.offset
= s
->_raw_size
;
4142 h
->got
.offset
= s
->_raw_size
;
4145 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4146 if (tls_type
== GOT_TLS_GD
)
4148 dyn
= htab
->root
.dynamic_sections_created
;
4149 /* R_SH_TLS_IE_32 needs one dynamic relocation,
4150 R_SH_TLS_GD needs one if local symbol and two if global. */
4151 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4152 || tls_type
== GOT_TLS_IE
)
4153 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4154 else if (tls_type
== GOT_TLS_GD
)
4155 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
4156 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4157 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4160 h
->got
.offset
= (bfd_vma
) -1;
4162 if (eh
->dyn_relocs
== NULL
)
4165 /* In the shared -Bsymbolic case, discard space allocated for
4166 dynamic pc-relative relocs against symbols which turn out to be
4167 defined in regular objects. For the normal shared case, discard
4168 space for pc-relative relocs that have become local due to symbol
4169 visibility changes. */
4173 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4174 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4177 struct elf_sh_dyn_relocs
**pp
;
4179 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4181 p
->count
-= p
->pc_count
;
4192 if (sh_elf_hash_entry (h
)->tls_tpoff32
)
4195 /* For the non-shared case, discard space for relocs against
4196 symbols which turn out to need copy relocs or are not
4199 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4200 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4201 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4202 || (htab
->root
.dynamic_sections_created
4203 && (h
->root
.type
== bfd_link_hash_undefweak
4204 || h
->root
.type
== bfd_link_hash_undefined
))))
4206 /* Make sure this symbol is output as a dynamic symbol.
4207 Undefined weak syms won't yet be marked as dynamic. */
4208 if (h
->dynindx
== -1
4209 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4211 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4215 /* If that succeeded, we know we'll be keeping all the
4217 if (h
->dynindx
!= -1)
4221 eh
->dyn_relocs
= NULL
;
4226 /* Finally, allocate space. */
4227 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4229 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4230 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4236 /* Find any dynamic relocs that apply to read-only sections. */
4239 readonly_dynrelocs (h
, inf
)
4240 struct elf_link_hash_entry
*h
;
4243 struct elf_sh_link_hash_entry
*eh
;
4244 struct elf_sh_dyn_relocs
*p
;
4246 if (h
->root
.type
== bfd_link_hash_warning
)
4247 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4249 eh
= (struct elf_sh_link_hash_entry
*) h
;
4250 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4252 asection
*s
= p
->sec
->output_section
;
4254 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4256 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4258 info
->flags
|= DF_TEXTREL
;
4260 /* Not an error, just cut short the traversal. */
4267 /* Set the sizes of the dynamic sections. */
4270 sh_elf_size_dynamic_sections (output_bfd
, info
)
4271 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4272 struct bfd_link_info
*info
;
4274 struct elf_sh_link_hash_table
*htab
;
4280 htab
= sh_elf_hash_table (info
);
4281 dynobj
= htab
->root
.dynobj
;
4282 BFD_ASSERT (dynobj
!= NULL
);
4284 if (htab
->root
.dynamic_sections_created
)
4286 /* Set the contents of the .interp section to the interpreter. */
4289 s
= bfd_get_section_by_name (dynobj
, ".interp");
4290 BFD_ASSERT (s
!= NULL
);
4291 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4292 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4296 /* Set up .got offsets for local syms, and space for local dynamic
4298 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4300 bfd_signed_vma
*local_got
;
4301 bfd_signed_vma
*end_local_got
;
4302 char *local_tls_type
;
4303 bfd_size_type locsymcount
;
4304 Elf_Internal_Shdr
*symtab_hdr
;
4307 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4310 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4312 struct elf_sh_dyn_relocs
*p
;
4314 for (p
= ((struct elf_sh_dyn_relocs
*)
4315 elf_section_data (s
)->local_dynrel
);
4319 if (! bfd_is_abs_section (p
->sec
)
4320 && bfd_is_abs_section (p
->sec
->output_section
))
4322 /* Input section has been discarded, either because
4323 it is a copy of a linkonce section or due to
4324 linker script /DISCARD/, so we'll be discarding
4327 else if (p
->count
!= 0)
4329 srel
= elf_section_data (p
->sec
)->sreloc
;
4330 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4331 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4332 info
->flags
|= DF_TEXTREL
;
4337 local_got
= elf_local_got_refcounts (ibfd
);
4341 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4342 locsymcount
= symtab_hdr
->sh_info
;
4343 #ifdef INCLUDE_SHMEDIA
4344 /* Count datalabel local GOT. */
4347 end_local_got
= local_got
+ locsymcount
;
4348 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4350 srel
= htab
->srelgot
;
4351 for (; local_got
< end_local_got
; ++local_got
)
4355 *local_got
= s
->_raw_size
;
4357 if (*local_tls_type
== GOT_TLS_GD
)
4360 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4363 *local_got
= (bfd_vma
) -1;
4368 if (htab
->tls_ldm_got
.refcount
> 0)
4370 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4372 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
4373 htab
->sgot
->_raw_size
+= 8;
4374 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4377 htab
->tls_ldm_got
.offset
= -1;
4379 /* Allocate global sym .plt and .got entries, and space for global
4380 sym dynamic relocs. */
4381 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
4383 /* We now have determined the sizes of the various dynamic sections.
4384 Allocate memory for them. */
4386 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4388 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4393 || s
== htab
->sgotplt
)
4395 /* Strip this section if we don't need it; see the
4398 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4400 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4403 /* We use the reloc_count field as a counter if we need
4404 to copy relocs into the output file. */
4409 /* It's not one of our sections, so don't allocate space. */
4413 if (s
->_raw_size
== 0)
4415 /* If we don't need this section, strip it from the
4416 output file. This is mostly to handle .rela.bss and
4417 .rela.plt. We must create both sections in
4418 create_dynamic_sections, because they must be created
4419 before the linker maps input sections to output
4420 sections. The linker does that before
4421 adjust_dynamic_symbol is called, and it is that
4422 function which decides whether anything needs to go
4423 into these sections. */
4425 _bfd_strip_section_from_output (info
, s
);
4429 /* Allocate memory for the section contents. We use bfd_zalloc
4430 here in case unused entries are not reclaimed before the
4431 section's contents are written out. This should not happen,
4432 but this way if it does, we get a R_SH_NONE reloc instead
4434 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4435 if (s
->contents
== NULL
)
4439 if (htab
->root
.dynamic_sections_created
)
4441 /* Add some entries to the .dynamic section. We fill in the
4442 values later, in sh_elf_finish_dynamic_sections, but we
4443 must add the entries now so that we get the correct size for
4444 the .dynamic section. The DT_DEBUG entry is filled in by the
4445 dynamic linker and used by the debugger. */
4446 #define add_dynamic_entry(TAG, VAL) \
4447 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4451 if (! add_dynamic_entry (DT_DEBUG
, 0))
4455 if (htab
->splt
->_raw_size
!= 0)
4457 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4458 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4459 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4460 || ! add_dynamic_entry (DT_JMPREL
, 0))
4466 if (! add_dynamic_entry (DT_RELA
, 0)
4467 || ! add_dynamic_entry (DT_RELASZ
, 0)
4468 || ! add_dynamic_entry (DT_RELAENT
,
4469 sizeof (Elf32_External_Rela
)))
4472 /* If any dynamic relocs apply to a read-only section,
4473 then we need a DT_TEXTREL entry. */
4474 if ((info
->flags
& DF_TEXTREL
) == 0)
4475 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
4478 if ((info
->flags
& DF_TEXTREL
) != 0)
4480 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4485 #undef add_dynamic_entry
4490 /* Relocate an SH ELF section. */
4493 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4494 contents
, relocs
, local_syms
, local_sections
)
4496 struct bfd_link_info
*info
;
4498 asection
*input_section
;
4500 Elf_Internal_Rela
*relocs
;
4501 Elf_Internal_Sym
*local_syms
;
4502 asection
**local_sections
;
4504 struct elf_sh_link_hash_table
*htab
;
4505 Elf_Internal_Shdr
*symtab_hdr
;
4506 struct elf_link_hash_entry
**sym_hashes
;
4507 Elf_Internal_Rela
*rel
, *relend
;
4509 bfd_vma
*local_got_offsets
;
4516 htab
= sh_elf_hash_table (info
);
4517 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4518 sym_hashes
= elf_sym_hashes (input_bfd
);
4519 dynobj
= htab
->root
.dynobj
;
4520 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4523 sgotplt
= htab
->sgotplt
;
4529 relend
= relocs
+ input_section
->reloc_count
;
4530 for (; rel
< relend
; rel
++)
4533 reloc_howto_type
*howto
;
4534 unsigned long r_symndx
;
4535 Elf_Internal_Sym
*sym
;
4537 struct elf_link_hash_entry
*h
;
4539 bfd_vma addend
= (bfd_vma
) 0;
4540 bfd_reloc_status_type r
;
4541 int seen_stt_datalabel
= 0;
4545 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4547 r_type
= ELF32_R_TYPE (rel
->r_info
);
4549 /* Many of the relocs are only used for relaxing, and are
4550 handled entirely by the relaxation code. */
4551 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
4552 && r_type
< (int) R_SH_LOOP_START
)
4554 if (r_type
== (int) R_SH_NONE
)
4558 || r_type
>= R_SH_max
4559 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4560 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4561 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4562 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4563 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4564 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4565 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4566 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4567 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4568 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4570 bfd_set_error (bfd_error_bad_value
);
4574 howto
= sh_elf_howto_table
+ r_type
;
4576 /* For relocs that aren't partial_inplace, we get the addend from
4578 if (! howto
->partial_inplace
)
4579 addend
= rel
->r_addend
;
4584 if (r_symndx
< symtab_hdr
->sh_info
)
4586 sym
= local_syms
+ r_symndx
;
4587 sec
= local_sections
[r_symndx
];
4588 relocation
= (sec
->output_section
->vma
4589 + sec
->output_offset
4591 /* A local symbol never has STO_SH5_ISA32, so we don't need
4592 datalabel processing here. Make sure this does not change
4594 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4595 ((*info
->callbacks
->reloc_dangerous
)
4597 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4598 input_bfd
, input_section
, rel
->r_offset
));
4599 if (info
->relocateable
)
4601 /* This is a relocateable link. We don't have to change
4602 anything, unless the reloc is against a section symbol,
4603 in which case we have to adjust according to where the
4604 section symbol winds up in the output section. */
4605 sym
= local_syms
+ r_symndx
;
4606 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4608 if (! howto
->partial_inplace
)
4610 /* For relocations with the addend in the
4611 relocation, we need just to update the addend.
4612 All real relocs are of type partial_inplace; this
4613 code is mostly for completeness. */
4614 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4619 /* Relocs of type partial_inplace need to pick up the
4620 contents in the contents and add the offset resulting
4621 from the changed location of the section symbol.
4622 Using _bfd_final_link_relocate (e.g. goto
4623 final_link_relocate) here would be wrong, because
4624 relocations marked pc_relative would get the current
4625 location subtracted, and we must only do that at the
4627 r
= _bfd_relocate_contents (howto
, input_bfd
,
4630 contents
+ rel
->r_offset
);
4631 goto relocation_done
;
4636 else if (! howto
->partial_inplace
)
4638 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4639 addend
= rel
->r_addend
;
4641 else if ((sec
->flags
& SEC_MERGE
)
4642 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4646 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4648 (*_bfd_error_handler
)
4649 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4650 bfd_archive_filename (input_bfd
),
4651 bfd_get_section_name (input_bfd
, input_section
),
4652 (long) rel
->r_offset
, howto
->name
);
4656 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4659 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4661 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4662 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4668 /* Section symbol are never (?) placed in the hash table, so
4669 we can just ignore hash relocations when creating a
4670 relocateable object file. */
4671 if (info
->relocateable
)
4674 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4675 while (h
->root
.type
== bfd_link_hash_indirect
4676 || h
->root
.type
== bfd_link_hash_warning
)
4678 #ifdef INCLUDE_SHMEDIA
4679 /* If the reference passes a symbol marked with
4680 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4682 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4684 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4686 if (h
->root
.type
== bfd_link_hash_defined
4687 || h
->root
.type
== bfd_link_hash_defweak
)
4691 dyn
= htab
->root
.dynamic_sections_created
;
4692 sec
= h
->root
.u
.def
.section
;
4693 /* In these cases, we don't need the relocation value.
4694 We check specially because in some obscure cases
4695 sec->output_section will be NULL. */
4696 if (r_type
== R_SH_GOTPC
4697 || r_type
== R_SH_GOTPC_LOW16
4698 || r_type
== R_SH_GOTPC_MEDLOW16
4699 || r_type
== R_SH_GOTPC_MEDHI16
4700 || r_type
== R_SH_GOTPC_HI16
4701 || ((r_type
== R_SH_PLT32
4702 || r_type
== R_SH_PLT_LOW16
4703 || r_type
== R_SH_PLT_MEDLOW16
4704 || r_type
== R_SH_PLT_MEDHI16
4705 || r_type
== R_SH_PLT_HI16
)
4706 && h
->plt
.offset
!= (bfd_vma
) -1)
4707 || ((r_type
== R_SH_GOT32
4708 || r_type
== R_SH_GOT_LOW16
4709 || r_type
== R_SH_GOT_MEDLOW16
4710 || r_type
== R_SH_GOT_MEDHI16
4711 || r_type
== R_SH_GOT_HI16
)
4712 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
4714 || (! info
->symbolic
&& h
->dynindx
!= -1)
4715 || (h
->elf_link_hash_flags
4716 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4717 /* The cases above are those in which relocation is
4718 overwritten in the switch block below. The cases
4719 below are those in which we must defer relocation
4720 to run-time, because we can't resolve absolute
4721 addresses when creating a shared library. */
4723 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4724 || (h
->elf_link_hash_flags
4725 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4726 && ((r_type
== R_SH_DIR32
4727 && (h
->elf_link_hash_flags
4728 & ELF_LINK_FORCED_LOCAL
) == 0)
4729 || r_type
== R_SH_REL32
)
4730 && ((input_section
->flags
& SEC_ALLOC
) != 0
4731 /* DWARF will emit R_SH_DIR32 relocations in its
4732 sections against symbols defined externally
4733 in shared libraries. We can't do anything
4735 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4736 && (h
->elf_link_hash_flags
4737 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
4738 || (sec
->output_section
== NULL
4739 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4740 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4742 else if (sec
->output_section
== NULL
)
4744 (*_bfd_error_handler
)
4745 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4746 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4747 bfd_get_section_name (input_bfd
, input_section
));
4751 relocation
= ((h
->root
.u
.def
.value
4752 + sec
->output_section
->vma
4753 + sec
->output_offset
)
4754 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4755 symbol value, unless we've seen
4756 STT_DATALABEL on the way to it. */
4757 | ((h
->other
& STO_SH5_ISA32
) != 0
4758 && ! seen_stt_datalabel
));
4760 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4762 else if (info
->shared
4763 && (! info
->symbolic
|| info
->allow_shlib_undefined
)
4764 && ! info
->no_undefined
4765 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4769 if (! ((*info
->callbacks
->undefined_symbol
)
4770 (info
, h
->root
.root
.string
, input_bfd
,
4771 input_section
, rel
->r_offset
,
4772 (!info
->shared
|| info
->no_undefined
4773 || ELF_ST_VISIBILITY (h
->other
)))))
4779 switch ((int) r_type
)
4781 final_link_relocate
:
4782 /* COFF relocs don't use the addend. The addend is used for
4783 R_SH_DIR32 to be compatible with other compilers. */
4784 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4785 contents
, rel
->r_offset
,
4786 relocation
, addend
);
4791 goto final_link_relocate
;
4796 /* If the reloc is against the start of this section, then
4797 the assembler has already taken care of it and the reloc
4798 is here only to assist in relaxing. If the reloc is not
4799 against the start of this section, then it's against an
4800 external symbol and we must deal with it ourselves. */
4801 if (input_section
->output_section
->vma
+ input_section
->output_offset
4804 int disp
= (relocation
4805 - input_section
->output_section
->vma
4806 - input_section
->output_offset
4812 case R_SH_DIR8WPZ
: mask
= 1; break;
4813 case R_SH_DIR8WPL
: mask
= 3; break;
4814 default: mask
= 0; break;
4818 ((*_bfd_error_handler
)
4819 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4820 bfd_archive_filename (input_section
->owner
),
4821 (unsigned long) rel
->r_offset
));
4822 bfd_set_error (bfd_error_bad_value
);
4826 goto final_link_relocate
;
4832 #ifdef INCLUDE_SHMEDIA
4833 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4834 contents
, rel
, &relocation
))
4835 goto final_link_relocate
;
4837 bfd_set_error (bfd_error_bad_value
);
4844 && (input_section
->flags
& SEC_ALLOC
) != 0
4845 && (r_type
!= R_SH_REL32
4848 && (! info
->symbolic
4849 || (h
->elf_link_hash_flags
4850 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
4852 Elf_Internal_Rela outrel
;
4853 boolean skip
, relocate
;
4855 /* When generating a shared object, these relocations
4856 are copied into the output file to be resolved at run
4863 name
= (bfd_elf_string_from_elf_section
4865 elf_elfheader (input_bfd
)->e_shstrndx
,
4866 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4870 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4871 && strcmp (bfd_get_section_name (input_bfd
,
4875 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4876 BFD_ASSERT (sreloc
!= NULL
);
4883 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4885 if (outrel
.r_offset
== (bfd_vma
) -1)
4887 else if (outrel
.r_offset
== (bfd_vma
) -2)
4888 skip
= true, relocate
= true;
4889 outrel
.r_offset
+= (input_section
->output_section
->vma
4890 + input_section
->output_offset
);
4893 memset (&outrel
, 0, sizeof outrel
);
4894 else if (r_type
== R_SH_REL32
)
4896 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4897 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4899 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4903 /* h->dynindx may be -1 if this symbol was marked to
4906 || ((info
->symbolic
|| h
->dynindx
== -1)
4907 && (h
->elf_link_hash_flags
4908 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
4911 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4913 = relocation
+ bfd_get_32 (input_bfd
,
4914 contents
+ rel
->r_offset
);
4918 BFD_ASSERT (h
->dynindx
!= -1);
4919 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4921 = relocation
+ bfd_get_32 (input_bfd
,
4922 contents
+ rel
->r_offset
);
4926 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
4927 (((Elf32_External_Rela
*)
4929 + sreloc
->reloc_count
));
4930 ++sreloc
->reloc_count
;
4932 /* If this reloc is against an external symbol, we do
4933 not want to fiddle with the addend. Otherwise, we
4934 need to include the symbol value so that it becomes
4935 an addend for the dynamic reloc. */
4939 goto final_link_relocate
;
4942 #ifdef INCLUDE_SHMEDIA
4943 case R_SH_GOTPLT_LOW16
:
4944 case R_SH_GOTPLT_MEDLOW16
:
4945 case R_SH_GOTPLT_MEDHI16
:
4946 case R_SH_GOTPLT_HI16
:
4947 case R_SH_GOTPLT10BY4
:
4948 case R_SH_GOTPLT10BY8
:
4950 /* Relocation is to the entry for this symbol in the
4951 procedure linkage table. */
4954 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
4958 || h
->plt
.offset
== (bfd_vma
) -1
4959 || h
->got
.offset
!= (bfd_vma
) -1)
4962 /* Relocation is to the entry for this symbol in the global
4963 offset table extension for the procedure linkage table. */
4965 BFD_ASSERT (sgotplt
!= NULL
);
4966 relocation
= (sgotplt
->output_offset
4967 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
4971 relocation
-= GOT_BIAS
;
4974 goto final_link_relocate
;
4978 #ifdef INCLUDE_SHMEDIA
4979 case R_SH_GOT_LOW16
:
4980 case R_SH_GOT_MEDLOW16
:
4981 case R_SH_GOT_MEDHI16
:
4986 /* Relocation is to the entry for this symbol in the global
4989 BFD_ASSERT (sgot
!= NULL
);
4995 off
= h
->got
.offset
;
4996 #ifdef INCLUDE_SHMEDIA
4997 if (seen_stt_datalabel
)
4999 struct elf_sh_link_hash_entry
*hsh
;
5001 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5002 off
= hsh
->datalabel_got_offset
;
5005 BFD_ASSERT (off
!= (bfd_vma
) -1);
5007 dyn
= htab
->root
.dynamic_sections_created
;
5008 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5010 && (info
->symbolic
|| h
->dynindx
== -1
5011 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
5012 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5014 /* This is actually a static link, or it is a
5015 -Bsymbolic link and the symbol is defined
5016 locally, or the symbol was forced to be local
5017 because of a version file. We must initialize
5018 this entry in the global offset table. Since the
5019 offset must always be a multiple of 4, we use the
5020 least significant bit to record whether we have
5021 initialized it already.
5023 When doing a dynamic link, we create a .rela.got
5024 relocation entry to initialize the value. This
5025 is done in the finish_dynamic_symbol routine. */
5030 bfd_put_32 (output_bfd
, relocation
,
5031 sgot
->contents
+ off
);
5032 #ifdef INCLUDE_SHMEDIA
5033 if (seen_stt_datalabel
)
5035 struct elf_sh_link_hash_entry
*hsh
;
5037 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5038 hsh
->datalabel_got_offset
|= 1;
5046 relocation
= sgot
->output_offset
+ off
;
5050 #ifdef INCLUDE_SHMEDIA
5053 BFD_ASSERT (local_got_offsets
!= NULL
5054 && (local_got_offsets
[symtab_hdr
->sh_info
5058 off
= local_got_offsets
[symtab_hdr
->sh_info
5064 BFD_ASSERT (local_got_offsets
!= NULL
5065 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5067 off
= local_got_offsets
[r_symndx
];
5068 #ifdef INCLUDE_SHMEDIA
5072 /* The offset must always be a multiple of 4. We use
5073 the least significant bit to record whether we have
5074 already generated the necessary reloc. */
5079 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5083 Elf_Internal_Rela outrel
;
5085 if (srelgot
== NULL
)
5087 srelgot
= bfd_get_section_by_name (dynobj
,
5089 BFD_ASSERT (srelgot
!= NULL
);
5092 outrel
.r_offset
= (sgot
->output_section
->vma
5093 + sgot
->output_offset
5095 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5096 outrel
.r_addend
= relocation
;
5097 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
5098 (((Elf32_External_Rela
*)
5100 + srelgot
->reloc_count
));
5101 ++srelgot
->reloc_count
;
5104 #ifdef INCLUDE_SHMEDIA
5106 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5109 local_got_offsets
[r_symndx
] |= 1;
5112 relocation
= sgot
->output_offset
+ off
;
5116 relocation
-= GOT_BIAS
;
5119 goto final_link_relocate
;
5122 #ifdef INCLUDE_SHMEDIA
5123 case R_SH_GOTOFF_LOW16
:
5124 case R_SH_GOTOFF_MEDLOW16
:
5125 case R_SH_GOTOFF_MEDHI16
:
5126 case R_SH_GOTOFF_HI16
:
5128 /* Relocation is relative to the start of the global offset
5131 BFD_ASSERT (sgot
!= NULL
);
5133 /* Note that sgot->output_offset is not involved in this
5134 calculation. We always want the start of .got. If we
5135 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5136 permitted by the ABI, we might have to change this
5138 relocation
-= sgot
->output_section
->vma
;
5141 relocation
-= GOT_BIAS
;
5144 addend
= rel
->r_addend
;
5146 goto final_link_relocate
;
5149 #ifdef INCLUDE_SHMEDIA
5150 case R_SH_GOTPC_LOW16
:
5151 case R_SH_GOTPC_MEDLOW16
:
5152 case R_SH_GOTPC_MEDHI16
:
5153 case R_SH_GOTPC_HI16
:
5155 /* Use global offset table as symbol value. */
5157 BFD_ASSERT (sgot
!= NULL
);
5158 relocation
= sgot
->output_section
->vma
;
5161 relocation
+= GOT_BIAS
;
5164 addend
= rel
->r_addend
;
5166 goto final_link_relocate
;
5169 #ifdef INCLUDE_SHMEDIA
5170 case R_SH_PLT_LOW16
:
5171 case R_SH_PLT_MEDLOW16
:
5172 case R_SH_PLT_MEDHI16
:
5175 /* Relocation is to the entry for this symbol in the
5176 procedure linkage table. */
5178 /* Resolve a PLT reloc against a local symbol directly,
5179 without using the procedure linkage table. */
5181 goto final_link_relocate
;
5183 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5184 goto final_link_relocate
;
5186 if (h
->plt
.offset
== (bfd_vma
) -1)
5188 /* We didn't make a PLT entry for this symbol. This
5189 happens when statically linking PIC code, or when
5190 using -Bsymbolic. */
5191 goto final_link_relocate
;
5194 BFD_ASSERT (splt
!= NULL
);
5195 relocation
= (splt
->output_section
->vma
5196 + splt
->output_offset
5199 #ifdef INCLUDE_SHMEDIA
5203 addend
= rel
->r_addend
;
5205 goto final_link_relocate
;
5207 case R_SH_LOOP_START
:
5209 static bfd_vma start
, end
;
5211 start
= (relocation
+ rel
->r_addend
5212 - (sec
->output_section
->vma
+ sec
->output_offset
));
5213 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5214 rel
->r_offset
, sec
, start
, end
);
5218 end
= (relocation
+ rel
->r_addend
5219 - (sec
->output_section
->vma
+ sec
->output_offset
));
5220 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5221 rel
->r_offset
, sec
, start
, end
);
5225 case R_SH_TLS_GD_32
:
5226 case R_SH_TLS_IE_32
:
5227 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5228 tls_type
= GOT_UNKNOWN
;
5229 if (h
== NULL
&& local_got_offsets
)
5230 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5233 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5235 && (h
->dynindx
== -1
5236 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5237 && (tls_type
== GOT_TLS_IE
5238 || sh_elf_hash_entry (h
)->tls_tpoff32
))
5239 r_type
= R_SH_TLS_LE_32
;
5242 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5243 r_type
= R_SH_TLS_IE_32
;
5245 if (r_type
== R_SH_TLS_LE_32
)
5248 unsigned short insn
;
5250 Elf_Internal_Rela outrel
;
5252 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5254 /* GD->LE transition:
5255 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5256 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5257 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5259 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5261 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5263 offset
= rel
->r_offset
;
5264 BFD_ASSERT (offset
>= 16);
5265 /* Size of GD instructions is 16 or 18. */
5267 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5268 if ((insn
& 0xff00) == 0xc700)
5270 BFD_ASSERT (offset
>= 2);
5272 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5275 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5276 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5277 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5278 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5279 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5280 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5281 BFD_ASSERT (insn
== 0x310c);
5282 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5283 BFD_ASSERT (insn
== 0x410b);
5284 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5285 BFD_ASSERT (insn
== 0x34cc);
5287 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5288 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5289 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5290 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5291 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5297 /* IE->LE transition:
5298 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5299 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5301 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5304 offset
= rel
->r_offset
;
5305 BFD_ASSERT (offset
>= 16);
5306 /* Size of IE instructions is 10 or 12. */
5308 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5309 if ((insn
& 0xf0ff) == 0x0012)
5311 BFD_ASSERT (offset
>= 2);
5313 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5316 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5317 index
= insn
& 0x00ff;
5318 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5319 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5320 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5321 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5322 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5323 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5324 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5331 name
= (bfd_elf_string_from_elf_section
5333 elf_elfheader (input_bfd
)->e_shstrndx
,
5334 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5338 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5339 && strcmp (bfd_get_section_name (input_bfd
,
5343 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5344 BFD_ASSERT (sreloc
!= NULL
);
5347 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5348 outrel
.r_offset
= (input_section
->output_section
->vma
5349 + input_section
->output_offset
5351 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5353 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5355 outrel
.r_addend
= 0;
5356 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
5357 (((Elf32_External_Rela
*)
5359 + sreloc
->reloc_count
));
5360 ++sreloc
->reloc_count
;
5370 off
= h
->got
.offset
;
5373 if (local_got_offsets
== NULL
)
5376 off
= local_got_offsets
[r_symndx
];
5383 Elf_Internal_Rela outrel
;
5384 Elf32_External_Rela
*loc
;
5387 if (srelgot
== NULL
)
5389 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5390 BFD_ASSERT (srelgot
!= NULL
);
5393 outrel
.r_offset
= (sgot
->output_section
->vma
5394 + sgot
->output_offset
+ off
);
5396 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5397 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5399 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5400 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5402 outrel
.r_addend
= 0;
5403 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5404 loc
= (Elf32_External_Rela
*) srelgot
->contents
;
5405 loc
+= srelgot
->reloc_count
++;
5406 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5408 if (r_type
== R_SH_TLS_GD_32
)
5412 bfd_put_32 (output_bfd
,
5413 relocation
- dtpoff_base (info
),
5414 sgot
->contents
+ off
+ 4);
5418 outrel
.r_info
= ELF32_R_INFO (indx
,
5420 outrel
.r_offset
+= 4;
5421 outrel
.r_addend
= 0;
5422 srelgot
->reloc_count
++;
5424 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
5432 local_got_offsets
[r_symndx
] |= 1;
5435 if (off
>= (bfd_vma
) -2)
5438 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5439 relocation
= sgot
->output_offset
+ off
;
5443 unsigned short insn
;
5445 /* GD->IE transition:
5446 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5447 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5448 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5450 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5451 nop; nop; bra 3f; nop; .align 2;
5452 1: .long x@TPOFF; 2:...; 3:. */
5454 offset
= rel
->r_offset
;
5455 BFD_ASSERT (offset
>= 16);
5456 /* Size of GD instructions is 16 or 18. */
5458 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5459 if ((insn
& 0xff00) == 0xc700)
5461 BFD_ASSERT (offset
>= 2);
5463 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5466 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5468 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5469 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5471 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5472 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5473 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5474 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5475 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5476 BFD_ASSERT (insn
== 0x310c);
5477 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5478 BFD_ASSERT (insn
== 0x410b);
5479 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5480 BFD_ASSERT (insn
== 0x34cc);
5482 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5483 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5484 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5485 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5486 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5488 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5489 contents
+ rel
->r_offset
);
5494 addend
= rel
->r_addend
;
5496 goto final_link_relocate
;
5498 case R_SH_TLS_LD_32
:
5502 unsigned short insn
;
5504 /* LD->LE transition:
5505 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5506 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5507 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5509 stc gbr,r0; nop; nop; nop;
5510 nop; nop; bra 3f; ...; 3:. */
5512 offset
= rel
->r_offset
;
5513 BFD_ASSERT (offset
>= 16);
5514 /* Size of LD instructions is 16 or 18. */
5516 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5517 if ((insn
& 0xff00) == 0xc700)
5519 BFD_ASSERT (offset
>= 2);
5521 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5524 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5525 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5526 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5527 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5528 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5529 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5530 BFD_ASSERT (insn
== 0x310c);
5531 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5532 BFD_ASSERT (insn
== 0x410b);
5533 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5534 BFD_ASSERT (insn
== 0x34cc);
5536 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5537 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5538 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5539 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5540 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5541 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5550 off
= htab
->tls_ldm_got
.offset
;
5555 Elf_Internal_Rela outrel
;
5556 Elf32_External_Rela
*loc
;
5558 srelgot
= htab
->srelgot
;
5559 if (srelgot
== NULL
)
5562 outrel
.r_offset
= (sgot
->output_section
->vma
5563 + sgot
->output_offset
+ off
);
5564 outrel
.r_addend
= 0;
5565 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5566 loc
= (Elf32_External_Rela
*) srelgot
->contents
;
5567 loc
+= srelgot
->reloc_count
++;
5568 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5569 htab
->tls_ldm_got
.offset
|= 1;
5572 relocation
= sgot
->output_offset
+ off
;
5573 addend
= rel
->r_addend
;
5575 goto final_link_relocate
;
5577 case R_SH_TLS_LDO_32
:
5581 Elf_Internal_Rela outrel
;
5587 name
= (bfd_elf_string_from_elf_section
5589 elf_elfheader (input_bfd
)->e_shstrndx
,
5590 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5594 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5595 && strcmp (bfd_get_section_name (input_bfd
,
5599 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5600 BFD_ASSERT (sreloc
!= NULL
);
5603 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5604 outrel
.r_offset
= (input_section
->output_section
->vma
5605 + input_section
->output_offset
5607 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5609 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5611 outrel
.r_addend
= 0;
5612 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
5613 (((Elf32_External_Rela
*)
5615 + sreloc
->reloc_count
));
5616 ++sreloc
->reloc_count
;
5621 relocation
-= dtpoff_base (info
);
5623 addend
= rel
->r_addend
;
5624 goto final_link_relocate
;
5626 case R_SH_TLS_LE_32
:
5629 Elf_Internal_Rela outrel
;
5635 name
= (bfd_elf_string_from_elf_section
5637 elf_elfheader (input_bfd
)->e_shstrndx
,
5638 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5642 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5643 && strcmp (bfd_get_section_name (input_bfd
,
5647 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5648 BFD_ASSERT (sreloc
!= NULL
);
5651 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5652 outrel
.r_offset
= (input_section
->output_section
->vma
5653 + input_section
->output_offset
5655 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5657 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5659 outrel
.r_addend
= 0;
5660 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
5661 (((Elf32_External_Rela
*)
5663 + sreloc
->reloc_count
));
5664 ++sreloc
->reloc_count
;
5671 if (r
!= bfd_reloc_ok
)
5676 case bfd_reloc_outofrange
:
5678 case bfd_reloc_overflow
:
5683 name
= h
->root
.root
.string
;
5686 name
= (bfd_elf_string_from_elf_section
5687 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5691 name
= bfd_section_name (input_bfd
, sec
);
5693 if (! ((*info
->callbacks
->reloc_overflow
)
5694 (info
, name
, howto
->name
, (bfd_vma
) 0,
5695 input_bfd
, input_section
, rel
->r_offset
)))
5706 /* This is a version of bfd_generic_get_relocated_section_contents
5707 which uses sh_elf_relocate_section. */
5710 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
5711 data
, relocateable
, symbols
)
5713 struct bfd_link_info
*link_info
;
5714 struct bfd_link_order
*link_order
;
5716 boolean relocateable
;
5719 Elf_Internal_Shdr
*symtab_hdr
;
5720 asection
*input_section
= link_order
->u
.indirect
.section
;
5721 bfd
*input_bfd
= input_section
->owner
;
5722 asection
**sections
= NULL
;
5723 Elf_Internal_Rela
*internal_relocs
= NULL
;
5724 Elf_Internal_Sym
*isymbuf
= NULL
;
5726 /* We only need to handle the case of relaxing, or of having a
5727 particular set of section contents, specially. */
5729 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5730 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5735 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5737 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5738 (size_t) input_section
->_raw_size
);
5740 if ((input_section
->flags
& SEC_RELOC
) != 0
5741 && input_section
->reloc_count
> 0)
5744 Elf_Internal_Sym
*isym
, *isymend
;
5747 internal_relocs
= (_bfd_elf32_link_read_relocs
5748 (input_bfd
, input_section
, (PTR
) NULL
,
5749 (Elf_Internal_Rela
*) NULL
, false));
5750 if (internal_relocs
== NULL
)
5753 if (symtab_hdr
->sh_info
!= 0)
5755 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5756 if (isymbuf
== NULL
)
5757 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5758 symtab_hdr
->sh_info
, 0,
5760 if (isymbuf
== NULL
)
5764 amt
= symtab_hdr
->sh_info
;
5765 amt
*= sizeof (asection
*);
5766 sections
= (asection
**) bfd_malloc (amt
);
5767 if (sections
== NULL
&& amt
!= 0)
5770 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5771 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5775 if (isym
->st_shndx
== SHN_UNDEF
)
5776 isec
= bfd_und_section_ptr
;
5777 else if (isym
->st_shndx
== SHN_ABS
)
5778 isec
= bfd_abs_section_ptr
;
5779 else if (isym
->st_shndx
== SHN_COMMON
)
5780 isec
= bfd_com_section_ptr
;
5782 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5787 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5788 input_section
, data
, internal_relocs
,
5792 if (sections
!= NULL
)
5795 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5797 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5798 free (internal_relocs
);
5804 if (sections
!= NULL
)
5807 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5809 if (internal_relocs
!= NULL
5810 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5811 free (internal_relocs
);
5815 /* Return the base VMA address which should be subtracted from real addresses
5816 when resolving @dtpoff relocation.
5817 This is PT_TLS segment p_vaddr. */
5821 struct bfd_link_info
*info
;
5823 /* If tls_segment is NULL, we should have signalled an error already. */
5824 if (elf_hash_table (info
)->tls_segment
== NULL
)
5826 return elf_hash_table (info
)->tls_segment
->start
;
5830 sh_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
5832 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5833 Elf_Internal_Rela
*rel
;
5834 struct elf_link_hash_entry
*h
;
5835 Elf_Internal_Sym
*sym
;
5839 switch (ELF32_R_TYPE (rel
->r_info
))
5841 case R_SH_GNU_VTINHERIT
:
5842 case R_SH_GNU_VTENTRY
:
5846 #ifdef INCLUDE_SHMEDIA
5847 while (h
->root
.type
== bfd_link_hash_indirect
5848 && h
->root
.u
.i
.link
)
5849 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5851 switch (h
->root
.type
)
5853 case bfd_link_hash_defined
:
5854 case bfd_link_hash_defweak
:
5855 return h
->root
.u
.def
.section
;
5857 case bfd_link_hash_common
:
5858 return h
->root
.u
.c
.p
->section
;
5866 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5871 /* Update the got entry reference counts for the section being removed. */
5874 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5876 struct bfd_link_info
*info
;
5878 const Elf_Internal_Rela
*relocs
;
5880 Elf_Internal_Shdr
*symtab_hdr
;
5881 struct elf_link_hash_entry
**sym_hashes
;
5882 bfd_signed_vma
*local_got_refcounts
;
5883 const Elf_Internal_Rela
*rel
, *relend
;
5884 unsigned long r_symndx
;
5885 struct elf_link_hash_entry
*h
;
5886 struct elf_sh_link_hash_entry
*eh
;
5888 elf_section_data (sec
)->local_dynrel
= NULL
;
5890 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5891 sym_hashes
= elf_sym_hashes (abfd
);
5892 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5894 relend
= relocs
+ sec
->reloc_count
;
5895 for (rel
= relocs
; rel
< relend
; rel
++)
5896 switch (sh_elf_optimized_tls_reloc (info
, ELF32_R_TYPE (rel
->r_info
),
5897 ELF32_R_SYM (rel
->r_info
)
5898 >= symtab_hdr
->sh_info
))
5900 case R_SH_TLS_LD_32
:
5901 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
5902 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
5908 #ifdef INCLUDE_SHMEDIA
5909 case R_SH_GOT_LOW16
:
5910 case R_SH_GOT_MEDLOW16
:
5911 case R_SH_GOT_MEDHI16
:
5915 case R_SH_GOTOFF_LOW16
:
5916 case R_SH_GOTOFF_MEDLOW16
:
5917 case R_SH_GOTOFF_MEDHI16
:
5918 case R_SH_GOTOFF_HI16
:
5919 case R_SH_GOTPC_LOW16
:
5920 case R_SH_GOTPC_MEDLOW16
:
5921 case R_SH_GOTPC_MEDHI16
:
5922 case R_SH_GOTPC_HI16
:
5924 case R_SH_TLS_GD_32
:
5925 case R_SH_TLS_IE_32
:
5926 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5927 if (r_symndx
>= symtab_hdr
->sh_info
)
5929 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5930 if (h
->got
.refcount
> 0)
5931 h
->got
.refcount
-= 1;
5933 else if (local_got_refcounts
!= NULL
)
5935 if (local_got_refcounts
[r_symndx
] > 0)
5936 local_got_refcounts
[r_symndx
] -= 1;
5942 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5943 if (r_symndx
>= symtab_hdr
->sh_info
)
5945 struct elf_sh_link_hash_entry
*eh
;
5946 struct elf_sh_dyn_relocs
**pp
;
5947 struct elf_sh_dyn_relocs
*p
;
5949 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5951 if (!info
->shared
&& h
->plt
.refcount
> 0)
5952 h
->plt
.refcount
-= 1;
5954 eh
= (struct elf_sh_link_hash_entry
*) h
;
5956 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5959 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_REL32
)
5970 #ifdef INCLUDE_SHMEDIA
5971 case R_SH_PLT_LOW16
:
5972 case R_SH_PLT_MEDLOW16
:
5973 case R_SH_PLT_MEDHI16
:
5976 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5977 if (r_symndx
>= symtab_hdr
->sh_info
)
5979 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5980 if (h
->plt
.refcount
> 0)
5981 h
->plt
.refcount
-= 1;
5986 #ifdef INCLUDE_SHMEDIA
5987 case R_SH_GOTPLT_LOW16
:
5988 case R_SH_GOTPLT_MEDLOW16
:
5989 case R_SH_GOTPLT_MEDHI16
:
5990 case R_SH_GOTPLT_HI16
:
5991 case R_SH_GOTPLT10BY4
:
5992 case R_SH_GOTPLT10BY8
:
5994 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5995 if (r_symndx
>= symtab_hdr
->sh_info
)
5997 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5998 eh
= (struct elf_sh_link_hash_entry
*) h
;
5999 if (eh
->gotplt_refcount
> 0)
6001 eh
->gotplt_refcount
-= 1;
6002 if (h
->plt
.refcount
> 0)
6003 h
->plt
.refcount
-= 1;
6005 else if (h
->got
.refcount
> 0)
6006 h
->got
.refcount
-= 1;
6008 else if (local_got_refcounts
!= NULL
)
6010 if (local_got_refcounts
[r_symndx
] > 0)
6011 local_got_refcounts
[r_symndx
] -= 1;
6022 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6025 sh_elf_copy_indirect_symbol (bed
, dir
, ind
)
6026 struct elf_backend_data
*bed
;
6027 struct elf_link_hash_entry
*dir
, *ind
;
6029 struct elf_sh_link_hash_entry
*edir
, *eind
;
6031 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6032 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6034 if (eind
->dyn_relocs
!= NULL
)
6036 if (edir
->dyn_relocs
!= NULL
)
6038 struct elf_sh_dyn_relocs
**pp
;
6039 struct elf_sh_dyn_relocs
*p
;
6041 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
6043 /* Add reloc counts against the weak sym to the strong sym
6044 list. Merge any entries against the same section. */
6045 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6047 struct elf_sh_dyn_relocs
*q
;
6049 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6050 if (q
->sec
== p
->sec
)
6052 q
->pc_count
+= p
->pc_count
;
6053 q
->count
+= p
->count
;
6060 *pp
= edir
->dyn_relocs
;
6063 edir
->dyn_relocs
= eind
->dyn_relocs
;
6064 eind
->dyn_relocs
= NULL
;
6066 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6067 eind
->gotplt_refcount
= 0;
6069 if (ind
->root
.type
== bfd_link_hash_indirect
6070 && dir
->got
.refcount
<= 0)
6072 edir
->tls_type
= eind
->tls_type
;
6073 eind
->tls_type
= GOT_UNKNOWN
;
6076 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6080 sh_elf_optimized_tls_reloc (info
, r_type
, is_local
)
6081 struct bfd_link_info
*info
;
6090 case R_SH_TLS_GD_32
:
6091 case R_SH_TLS_IE_32
:
6093 return R_SH_TLS_LE_32
;
6094 return R_SH_TLS_IE_32
;
6095 case R_SH_TLS_LD_32
:
6096 return R_SH_TLS_LE_32
;
6102 /* Look through the relocs for a section during the first phase.
6103 Since we don't do .gots or .plts, we just need to consider the
6104 virtual table relocs for gc. */
6107 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
6109 struct bfd_link_info
*info
;
6111 const Elf_Internal_Rela
*relocs
;
6113 Elf_Internal_Shdr
*symtab_hdr
;
6114 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6115 struct elf_sh_link_hash_table
*htab
;
6116 const Elf_Internal_Rela
*rel
;
6117 const Elf_Internal_Rela
*rel_end
;
6119 bfd_vma
*local_got_offsets
;
6123 unsigned int r_type
;
6124 int tls_type
, old_tls_type
;
6130 if (info
->relocateable
)
6133 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6134 sym_hashes
= elf_sym_hashes (abfd
);
6135 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6136 if (!elf_bad_symtab (abfd
))
6137 sym_hashes_end
-= symtab_hdr
->sh_info
;
6139 htab
= sh_elf_hash_table (info
);
6140 dynobj
= htab
->root
.dynobj
;
6141 local_got_offsets
= elf_local_got_offsets (abfd
);
6143 rel_end
= relocs
+ sec
->reloc_count
;
6144 for (rel
= relocs
; rel
< rel_end
; rel
++)
6146 struct elf_link_hash_entry
*h
;
6147 unsigned long r_symndx
;
6149 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6150 r_type
= ELF32_R_TYPE (rel
->r_info
);
6152 if (r_symndx
< symtab_hdr
->sh_info
)
6155 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6157 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6159 && r_type
== R_SH_TLS_IE_32
6161 && h
->root
.type
!= bfd_link_hash_undefined
6162 && h
->root
.type
!= bfd_link_hash_undefweak
6163 && (h
->dynindx
== -1
6164 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6165 r_type
= R_SH_TLS_LE_32
;
6167 /* Some relocs require a global offset table. */
6168 if (htab
->sgot
== NULL
)
6176 #ifdef INCLUDE_SHMEDIA
6177 case R_SH_GOTPLT_LOW16
:
6178 case R_SH_GOTPLT_MEDLOW16
:
6179 case R_SH_GOTPLT_MEDHI16
:
6180 case R_SH_GOTPLT_HI16
:
6181 case R_SH_GOTPLT10BY4
:
6182 case R_SH_GOTPLT10BY8
:
6183 case R_SH_GOT_LOW16
:
6184 case R_SH_GOT_MEDLOW16
:
6185 case R_SH_GOT_MEDHI16
:
6189 case R_SH_GOTOFF_LOW16
:
6190 case R_SH_GOTOFF_MEDLOW16
:
6191 case R_SH_GOTOFF_MEDHI16
:
6192 case R_SH_GOTOFF_HI16
:
6193 case R_SH_GOTPC_LOW16
:
6194 case R_SH_GOTPC_MEDLOW16
:
6195 case R_SH_GOTPC_MEDHI16
:
6196 case R_SH_GOTPC_HI16
:
6198 case R_SH_TLS_GD_32
:
6199 case R_SH_TLS_LD_32
:
6200 case R_SH_TLS_IE_32
:
6202 htab
->root
.dynobj
= dynobj
= abfd
;
6203 if (! create_got_section (dynobj
, info
))
6214 /* This relocation describes the C++ object vtable hierarchy.
6215 Reconstruct it for later use during GC. */
6216 case R_SH_GNU_VTINHERIT
:
6217 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6221 /* This relocation describes which C++ vtable entries are actually
6222 used. Record for later use during GC. */
6223 case R_SH_GNU_VTENTRY
:
6224 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6229 case R_SH_TLS_IE_32
:
6231 info
->flags
|= DF_STATIC_TLS
;
6234 case R_SH_TLS_GD_32
:
6236 #ifdef INCLUDE_SHMEDIA
6237 case R_SH_GOT_LOW16
:
6238 case R_SH_GOT_MEDLOW16
:
6239 case R_SH_GOT_MEDHI16
:
6247 tls_type
= GOT_NORMAL
;
6249 case R_SH_TLS_GD_32
:
6250 tls_type
= GOT_TLS_GD
;
6252 case R_SH_TLS_IE_32
:
6253 tls_type
= GOT_TLS_IE
;
6259 h
->got
.refcount
+= 1;
6260 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6264 bfd_signed_vma
*local_got_refcounts
;
6266 /* This is a global offset table entry for a local
6268 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6269 if (local_got_refcounts
== NULL
)
6273 size
= symtab_hdr
->sh_info
;
6274 size
*= sizeof (bfd_signed_vma
);
6275 #ifdef INCLUDE_SHMEDIA
6276 /* Reserve space for both the datalabel and
6277 codelabel local GOT offsets. */
6280 size
+= symtab_hdr
->sh_info
;
6281 local_got_refcounts
= ((bfd_signed_vma
*)
6282 bfd_zalloc (abfd
, size
));
6283 if (local_got_refcounts
== NULL
)
6285 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6286 #ifdef INCLUDE_SHMEDIA
6287 /* Take care of both the datalabel and codelabel local
6289 sh_elf_local_got_tls_type (abfd
)
6290 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6292 sh_elf_local_got_tls_type (abfd
)
6293 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6296 local_got_refcounts
[r_symndx
] += 1;
6297 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6300 /* If a TLS symbol is accessed using IE at least once,
6301 there is no point to use dynamic model for it. */
6302 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6303 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6305 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6306 tls_type
= GOT_TLS_IE
;
6309 (*_bfd_error_handler
)
6310 (_("%s: `%s' accessed both as normal and thread local symbol"),
6311 bfd_archive_filename (abfd
), h
->root
.root
.string
);
6316 if (old_tls_type
!= tls_type
)
6319 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6321 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6326 case R_SH_TLS_LD_32
:
6327 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6331 #ifdef INCLUDE_SHMEDIA
6332 case R_SH_GOTPLT_LOW16
:
6333 case R_SH_GOTPLT_MEDLOW16
:
6334 case R_SH_GOTPLT_MEDHI16
:
6335 case R_SH_GOTPLT_HI16
:
6336 case R_SH_GOTPLT10BY4
:
6337 case R_SH_GOTPLT10BY8
:
6339 /* If this is a local symbol, we resolve it directly without
6340 creating a procedure linkage table entry. */
6343 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6346 || h
->dynindx
== -1)
6349 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6350 h
->plt
.refcount
+= 1;
6351 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6356 #ifdef INCLUDE_SHMEDIA
6357 case R_SH_PLT_LOW16
:
6358 case R_SH_PLT_MEDLOW16
:
6359 case R_SH_PLT_MEDHI16
:
6362 /* This symbol requires a procedure linkage table entry. We
6363 actually build the entry in adjust_dynamic_symbol,
6364 because this might be a case of linking PIC code which is
6365 never referenced by a dynamic object, in which case we
6366 don't need to generate a procedure linkage table entry
6369 /* If this is a local symbol, we resolve it directly without
6370 creating a procedure linkage table entry. */
6374 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6377 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6378 h
->plt
.refcount
+= 1;
6383 if (h
!= NULL
&& ! info
->shared
)
6385 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
6386 h
->plt
.refcount
+= 1;
6389 /* If we are creating a shared library, and this is a reloc
6390 against a global symbol, or a non PC relative reloc
6391 against a local symbol, then we need to copy the reloc
6392 into the shared library. However, if we are linking with
6393 -Bsymbolic, we do not need to copy a reloc against a
6394 global symbol which is defined in an object we are
6395 including in the link (i.e., DEF_REGULAR is set). At
6396 this point we have not seen all the input files, so it is
6397 possible that DEF_REGULAR is not set now but will be set
6398 later (it is never cleared). We account for that
6399 possibility below by storing information in the
6400 dyn_relocs field of the hash table entry. A similar
6401 situation occurs when creating shared libraries and symbol
6402 visibility changes render the symbol local.
6404 If on the other hand, we are creating an executable, we
6405 may need to keep relocations for symbols satisfied by a
6406 dynamic library if we manage to avoid copy relocs for the
6409 && (sec
->flags
& SEC_ALLOC
) != 0
6410 && (r_type
!= R_SH_REL32
6412 && (! info
->symbolic
6413 || h
->root
.type
== bfd_link_hash_defweak
6414 || (h
->elf_link_hash_flags
6415 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
6417 && (sec
->flags
& SEC_ALLOC
) != 0
6419 && (h
->root
.type
== bfd_link_hash_defweak
6420 || (h
->elf_link_hash_flags
6421 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6423 struct elf_sh_dyn_relocs
*p
;
6424 struct elf_sh_dyn_relocs
**head
;
6427 htab
->root
.dynobj
= dynobj
= abfd
;
6429 /* When creating a shared object, we must copy these
6430 reloc types into the output file. We create a reloc
6431 section in dynobj and make room for this reloc. */
6436 name
= (bfd_elf_string_from_elf_section
6438 elf_elfheader (abfd
)->e_shstrndx
,
6439 elf_section_data (sec
)->rel_hdr
.sh_name
));
6443 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6444 && strcmp (bfd_get_section_name (abfd
, sec
),
6447 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6452 sreloc
= bfd_make_section (dynobj
, name
);
6453 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6454 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6455 if ((sec
->flags
& SEC_ALLOC
) != 0)
6456 flags
|= SEC_ALLOC
| SEC_LOAD
;
6458 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
6459 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
6462 if (sec
->flags
& SEC_READONLY
)
6463 info
->flags
|= DF_TEXTREL
;
6464 elf_section_data (sec
)->sreloc
= sreloc
;
6467 /* If this is a global symbol, we count the number of
6468 relocations we need for this symbol. */
6470 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6475 /* Track dynamic relocs needed for local syms too. */
6476 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6481 head
= ((struct elf_sh_dyn_relocs
**)
6482 &elf_section_data (s
)->local_dynrel
);
6486 if (p
== NULL
|| p
->sec
!= sec
)
6488 bfd_size_type amt
= sizeof (*p
);
6489 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
6500 if (r_type
== R_SH_REL32
)
6506 case R_SH_TLS_LE_32
:
6509 (*_bfd_error_handler
) (_("%s: TLS local exec code cannot be linked into shared objects"),
6510 bfd_archive_filename (abfd
));
6514 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_LD_32
)
6518 case R_SH_TLS_LDO_32
:
6519 /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
6523 struct elf_sh_dyn_relocs
*p
;
6524 struct elf_sh_dyn_relocs
**head
;
6527 htab
->root
.dynobj
= dynobj
= abfd
;
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 elf_section_data (sec
)->sreloc
= sreloc
;
6560 if (sec
->flags
& SEC_READONLY
)
6561 info
->flags
|= DF_TEXTREL
;
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
));
6598 sh_elf_hash_entry (h
)->tls_tpoff32
= true;
6610 #ifndef sh_elf_set_mach_from_flags
6612 sh_elf_set_mach_from_flags (abfd
)
6615 flagword flags
= elf_elfheader (abfd
)->e_flags
;
6617 switch (flags
& EF_SH_MACH_MASK
)
6620 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
6623 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
6626 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
6629 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
6632 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
6635 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
6639 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
6646 #endif /* not sh_elf_set_mach_from_flags */
6648 #ifndef sh_elf_set_private_flags
6649 /* Function to keep SH specific file flags. */
6652 sh_elf_set_private_flags (abfd
, flags
)
6656 BFD_ASSERT (! elf_flags_init (abfd
)
6657 || elf_elfheader (abfd
)->e_flags
== flags
);
6659 elf_elfheader (abfd
)->e_flags
= flags
;
6660 elf_flags_init (abfd
) = true;
6661 return sh_elf_set_mach_from_flags (abfd
);
6663 #endif /* not sh_elf_set_private_flags */
6665 #ifndef sh_elf_copy_private_data
6666 /* Copy backend specific data from one object module to another */
6669 sh_elf_copy_private_data (ibfd
, obfd
)
6673 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6674 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6677 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6679 #endif /* not sh_elf_copy_private_data */
6681 #ifndef sh_elf_merge_private_data
6682 /* This routine checks for linking big and little endian objects
6683 together, and for linking sh-dsp with sh3e / sh4 objects. */
6686 sh_elf_merge_private_data (ibfd
, obfd
)
6690 flagword old_flags
, new_flags
;
6692 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
6695 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6696 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6699 if (! elf_flags_init (obfd
))
6701 /* This happens when ld starts out with a 'blank' output file. */
6702 elf_flags_init (obfd
) = true;
6703 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6705 old_flags
= elf_elfheader (obfd
)->e_flags
;
6706 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6707 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
6708 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
6710 (*_bfd_error_handler
)
6711 ("%s: uses %s instructions while previous modules use %s instructions",
6712 bfd_archive_filename (ibfd
),
6713 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
6714 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
6715 bfd_set_error (bfd_error_bad_value
);
6718 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
6720 return sh_elf_set_mach_from_flags (obfd
);
6722 #endif /* not sh_elf_merge_private_data */
6724 /* Override the generic function because we need to store sh_elf_obj_tdata
6725 as the specific tdata. We set also the machine architecture from flags
6729 sh_elf_object_p (abfd
)
6732 struct sh_elf_obj_tdata
*new_tdata
;
6733 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
6735 if (sh_elf_set_mach_from_flags (abfd
) == false)
6738 /* Allocate our special target data. */
6739 new_tdata
= bfd_zalloc (abfd
, amt
);
6740 if (new_tdata
== NULL
)
6742 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
6743 abfd
->tdata
.any
= new_tdata
;
6747 /* Finish up dynamic symbol handling. We set the contents of various
6748 dynamic sections here. */
6751 sh_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6753 struct bfd_link_info
*info
;
6754 struct elf_link_hash_entry
*h
;
6755 Elf_Internal_Sym
*sym
;
6757 struct elf_sh_link_hash_table
*htab
;
6760 htab
= sh_elf_hash_table (info
);
6761 dynobj
= htab
->root
.dynobj
;
6763 if (h
->plt
.offset
!= (bfd_vma
) -1)
6771 Elf_Internal_Rela rel
;
6773 /* This symbol has an entry in the procedure linkage table. Set
6776 BFD_ASSERT (h
->dynindx
!= -1);
6779 sgot
= htab
->sgotplt
;
6780 srel
= htab
->srelplt
;
6781 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6783 /* Get the index in the procedure linkage table which
6784 corresponds to this symbol. This is the index of this symbol
6785 in all the symbols for which we are making plt entries. The
6786 first entry in the procedure linkage table is reserved. */
6787 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6789 /* Get the offset into the .got table of the entry that
6790 corresponds to this function. Each .got entry is 4 bytes.
6791 The first three are reserved. */
6792 got_offset
= (plt_index
+ 3) * 4;
6796 got_offset
-= GOT_BIAS
;
6799 /* Fill in the entry in the procedure linkage table. */
6802 if (elf_sh_plt_entry
== NULL
)
6804 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
6805 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
6807 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
6808 elf_sh_sizeof_plt (info
));
6809 #ifdef INCLUDE_SHMEDIA
6810 movi_shori_putval (output_bfd
,
6811 (sgot
->output_section
->vma
6812 + sgot
->output_offset
6814 (splt
->contents
+ h
->plt
.offset
6815 + elf_sh_plt_symbol_offset (info
)));
6817 /* Set bottom bit because its for a branch to SHmedia */
6818 movi_shori_putval (output_bfd
,
6819 (splt
->output_section
->vma
+ splt
->output_offset
)
6821 (splt
->contents
+ h
->plt
.offset
6822 + elf_sh_plt_plt0_offset (info
)));
6824 bfd_put_32 (output_bfd
,
6825 (sgot
->output_section
->vma
6826 + sgot
->output_offset
6828 (splt
->contents
+ h
->plt
.offset
6829 + elf_sh_plt_symbol_offset (info
)));
6831 bfd_put_32 (output_bfd
,
6832 (splt
->output_section
->vma
+ splt
->output_offset
),
6833 (splt
->contents
+ h
->plt
.offset
6834 + elf_sh_plt_plt0_offset (info
)));
6839 if (elf_sh_pic_plt_entry
== NULL
)
6841 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
6842 elf_sh_pic_plt_entry_be
:
6843 elf_sh_pic_plt_entry_le
);
6845 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
6846 elf_sh_sizeof_plt (info
));
6847 #ifdef INCLUDE_SHMEDIA
6848 movi_shori_putval (output_bfd
, got_offset
,
6849 (splt
->contents
+ h
->plt
.offset
6850 + elf_sh_plt_symbol_offset (info
)));
6852 bfd_put_32 (output_bfd
, got_offset
,
6853 (splt
->contents
+ h
->plt
.offset
6854 + elf_sh_plt_symbol_offset (info
)));
6860 got_offset
+= GOT_BIAS
;
6863 #ifdef INCLUDE_SHMEDIA
6864 movi_shori_putval (output_bfd
,
6865 plt_index
* sizeof (Elf32_External_Rela
),
6866 (splt
->contents
+ h
->plt
.offset
6867 + elf_sh_plt_reloc_offset (info
)));
6869 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
6870 (splt
->contents
+ h
->plt
.offset
6871 + elf_sh_plt_reloc_offset (info
)));
6874 /* Fill in the entry in the global offset table. */
6875 bfd_put_32 (output_bfd
,
6876 (splt
->output_section
->vma
6877 + splt
->output_offset
6879 + elf_sh_plt_temp_offset (info
)),
6880 sgot
->contents
+ got_offset
);
6882 /* Fill in the entry in the .rela.plt section. */
6883 rel
.r_offset
= (sgot
->output_section
->vma
6884 + sgot
->output_offset
6886 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
6889 rel
.r_addend
= GOT_BIAS
;
6891 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
6892 ((Elf32_External_Rela
*) srel
->contents
6895 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
6897 /* Mark the symbol as undefined, rather than as defined in
6898 the .plt section. Leave the value alone. */
6899 sym
->st_shndx
= SHN_UNDEF
;
6903 if (h
->got
.offset
!= (bfd_vma
) -1
6904 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
6905 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
6909 Elf_Internal_Rela rel
;
6911 /* This symbol has an entry in the global offset table. Set it
6915 srel
= htab
->srelgot
;
6916 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
6918 rel
.r_offset
= (sgot
->output_section
->vma
6919 + sgot
->output_offset
6920 + (h
->got
.offset
&~ (bfd_vma
) 1));
6922 /* If this is a static link, or it is a -Bsymbolic link and the
6923 symbol is defined locally or was forced to be local because
6924 of a version file, we just want to emit a RELATIVE reloc.
6925 The entry in the global offset table will already have been
6926 initialized in the relocate_section function. */
6930 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6931 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6933 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
6934 rel
.r_addend
= (h
->root
.u
.def
.value
6935 + h
->root
.u
.def
.section
->output_section
->vma
6936 + h
->root
.u
.def
.section
->output_offset
);
6940 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
6941 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
6945 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
6946 ((Elf32_External_Rela
*) srel
->contents
6947 + srel
->reloc_count
));
6948 ++srel
->reloc_count
;
6951 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6954 Elf_Internal_Rela rel
;
6956 /* This symbol needs a copy reloc. Set it up. */
6958 BFD_ASSERT (h
->dynindx
!= -1
6959 && (h
->root
.type
== bfd_link_hash_defined
6960 || h
->root
.type
== bfd_link_hash_defweak
));
6962 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
6964 BFD_ASSERT (s
!= NULL
);
6966 rel
.r_offset
= (h
->root
.u
.def
.value
6967 + h
->root
.u
.def
.section
->output_section
->vma
6968 + h
->root
.u
.def
.section
->output_offset
);
6969 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
6971 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
6972 ((Elf32_External_Rela
*) s
->contents
6977 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6978 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6979 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
6980 sym
->st_shndx
= SHN_ABS
;
6985 /* Finish up the dynamic sections. */
6988 sh_elf_finish_dynamic_sections (output_bfd
, info
)
6990 struct bfd_link_info
*info
;
6992 struct elf_sh_link_hash_table
*htab
;
6997 htab
= sh_elf_hash_table (info
);
6998 dynobj
= htab
->root
.dynobj
;
7000 sgot
= htab
->sgotplt
;
7001 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7003 if (htab
->root
.dynamic_sections_created
)
7006 Elf32_External_Dyn
*dyncon
, *dynconend
;
7008 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7010 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7011 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7012 for (; dyncon
< dynconend
; dyncon
++)
7014 Elf_Internal_Dyn dyn
;
7016 #ifdef INCLUDE_SHMEDIA
7020 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7027 #ifdef INCLUDE_SHMEDIA
7029 name
= info
->init_function
;
7033 name
= info
->fini_function
;
7035 if (dyn
.d_un
.d_val
!= 0)
7037 struct elf_link_hash_entry
*h
;
7039 h
= elf_link_hash_lookup (&htab
->root
, name
,
7040 false, false, true);
7041 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7043 dyn
.d_un
.d_val
|= 1;
7044 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7051 s
= htab
->sgot
->output_section
;
7055 s
= htab
->srelplt
->output_section
;
7057 BFD_ASSERT (s
!= NULL
);
7058 dyn
.d_un
.d_ptr
= s
->vma
;
7059 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7063 s
= htab
->srelplt
->output_section
;
7064 BFD_ASSERT (s
!= NULL
);
7065 if (s
->_cooked_size
!= 0)
7066 dyn
.d_un
.d_val
= s
->_cooked_size
;
7068 dyn
.d_un
.d_val
= s
->_raw_size
;
7069 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7073 /* My reading of the SVR4 ABI indicates that the
7074 procedure linkage table relocs (DT_JMPREL) should be
7075 included in the overall relocs (DT_RELA). This is
7076 what Solaris does. However, UnixWare can not handle
7077 that case. Therefore, we override the DT_RELASZ entry
7078 here to make it not include the JMPREL relocs. Since
7079 the linker script arranges for .rela.plt to follow all
7080 other relocation sections, we don't have to worry
7081 about changing the DT_RELA entry. */
7082 if (htab
->srelplt
!= NULL
)
7084 s
= htab
->srelplt
->output_section
;
7085 if (s
->_cooked_size
!= 0)
7086 dyn
.d_un
.d_val
-= s
->_cooked_size
;
7088 dyn
.d_un
.d_val
-= s
->_raw_size
;
7090 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7095 /* Fill in the first entry in the procedure linkage table. */
7097 if (splt
&& splt
->_raw_size
> 0)
7101 if (elf_sh_pic_plt_entry
== NULL
)
7103 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7104 elf_sh_pic_plt_entry_be
:
7105 elf_sh_pic_plt_entry_le
);
7107 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7108 elf_sh_sizeof_plt (info
));
7112 if (elf_sh_plt0_entry
== NULL
)
7114 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7115 elf_sh_plt0_entry_be
:
7116 elf_sh_plt0_entry_le
);
7118 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7119 #ifdef INCLUDE_SHMEDIA
7120 movi_shori_putval (output_bfd
,
7121 sgot
->output_section
->vma
7122 + sgot
->output_offset
,
7124 + elf_sh_plt0_gotplt_offset (info
));
7126 bfd_put_32 (output_bfd
,
7127 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7128 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7129 bfd_put_32 (output_bfd
,
7130 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7131 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7135 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7136 really seem like the right value. */
7137 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7141 /* Fill in the first three entries in the global offset table. */
7142 if (sgot
&& sgot
->_raw_size
> 0)
7145 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7147 bfd_put_32 (output_bfd
,
7148 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7150 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7151 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7153 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7159 static enum elf_reloc_type_class
7160 sh_elf_reloc_type_class (rela
)
7161 const Elf_Internal_Rela
*rela
;
7163 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7166 return reloc_class_relative
;
7168 return reloc_class_plt
;
7170 return reloc_class_copy
;
7172 return reloc_class_normal
;
7177 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7178 #define TARGET_BIG_NAME "elf32-sh"
7179 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7180 #define TARGET_LITTLE_NAME "elf32-shl"
7181 #define ELF_ARCH bfd_arch_sh
7182 #define ELF_MACHINE_CODE EM_SH
7183 #define ELF_MAXPAGESIZE 128
7185 #define elf_symbol_leading_char '_'
7186 #endif /* ELF_ARCH */
7188 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7189 #define elf_info_to_howto sh_elf_info_to_howto
7190 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7191 #define elf_backend_relocate_section sh_elf_relocate_section
7192 #define bfd_elf32_bfd_get_relocated_section_contents \
7193 sh_elf_get_relocated_section_contents
7194 #define bfd_elf32_mkobject sh_elf_mkobject
7195 #define elf_backend_object_p sh_elf_object_p
7196 #define bfd_elf32_bfd_set_private_bfd_flags \
7197 sh_elf_set_private_flags
7198 #define bfd_elf32_bfd_copy_private_bfd_data \
7199 sh_elf_copy_private_data
7200 #define bfd_elf32_bfd_merge_private_bfd_data \
7201 sh_elf_merge_private_data
7203 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7204 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7205 #define elf_backend_check_relocs sh_elf_check_relocs
7206 #define elf_backend_copy_indirect_symbol \
7207 sh_elf_copy_indirect_symbol
7208 #define elf_backend_create_dynamic_sections \
7209 sh_elf_create_dynamic_sections
7210 #define bfd_elf32_bfd_link_hash_table_create \
7211 sh_elf_link_hash_table_create
7212 #define elf_backend_adjust_dynamic_symbol \
7213 sh_elf_adjust_dynamic_symbol
7214 #define elf_backend_size_dynamic_sections \
7215 sh_elf_size_dynamic_sections
7216 #define elf_backend_finish_dynamic_symbol \
7217 sh_elf_finish_dynamic_symbol
7218 #define elf_backend_finish_dynamic_sections \
7219 sh_elf_finish_dynamic_sections
7220 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7222 #define elf_backend_can_gc_sections 1
7223 #define elf_backend_can_refcount 1
7224 #define elf_backend_want_got_plt 1
7225 #define elf_backend_plt_readonly 1
7226 #define elf_backend_want_plt_sym 0
7227 #define elf_backend_got_header_size 12
7228 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
7230 #ifndef ELF32_SH_C_INCLUDED
7231 #include "elf32-target.h"